
LANGCHAIN — TypeScript Support
The computer was born to solve problems that did not exist before. — Bill Gates
TypeScript support for LangChain is finally here! This means that all your favorite prompts, chains, and agents are now recreatable in TypeScript natively. Both the Python version and TypeScript version utilize the same serializable format, allowing artifacts to seamlessly be shared between languages. Let’s dive into what TypeScript support entails and how to utilize it.
Why TypeScript?
Initially, the crowd playing with language models was more research-oriented and preferred Python. However, with the quick success of ChatGPT, there has been a surge of interest from developers who prefer using JavaScript. Hence, the development of a JavaScript native version of LangChain became necessary.
What’s in this package?
The TypeScript package includes all the same abstractions as the Python package:
Prompts
import { PromptTemplate } from 'langchain';
// Create a prompt
const prompt = new PromptTemplate();LLMs (Large Language Models)
import { OpenAI } from 'langchain';
// Create an instance of an LLM
const openAIModel = new OpenAI();Text Splitters
import { TextSplitter } from 'langchain';
// Utilize a text splitter
const textSplitter = new TextSplitter();Embeddings
import { Embeddings } from 'langchain';
// Create embeddings
const embeddings = new Embeddings();Vectorstores
import { Vectorstore } from 'langchain';
// Work with vectorstores
const vectorstore = new Vectorstore();Chains
import { LLMChain } from 'langchain';
// Use a chain
const chain = new LLMChain();Agents
import { Agents } from 'langchain';
// Interact with agents
const agent = new Agents();Memory
import { BufferMemory } from 'langchain';
// Manage memory
const bufferMemory = new BufferMemory();Relationship to the Python package
The TypeScript package aims to mirror the Python package closely. The serialized format introduced for prompts, chains, and agents in Python also works for the TypeScript version. This ensures that artifacts are shareable between languages, enabling community adoption and sharing of best prompts, chains, and agents.
Conclusion
TypeScript support for LangChain opens up new possibilities for developers who prefer using JavaScript. With the same abstractions available in both the Python and TypeScript packages, it becomes easier to transition between the two languages. As the TypeScript package continues to grow, more features aimed at facilitating web development will be included. This evolution reflects the different priorities and use cases within each community and allows for a wider range of applications.






