Local LangChain with FastChat
LangChain is a library that facilitates the development of applications by leveraging large language models (LLMs) and enabling their composition with other sources of computation or knowledge. FastChat’s OpenAI-compatible API server enables using LangChain with open models seamlessly.
Launch RESTful API Server
Here are the steps to launch a local OpenAI API server for LangChain.
First, launch the controller
LangChain uses OpenAI model names by default, so we need to assign some faux OpenAI model names to our local model.
Here, we use Vicuna as an example and use it for three endpoints: chat completion, completion, and embedding.
--model-path
can be a local folder or a Hugging Face repo name.
See a full list of supported models here.
Finally, launch the RESTful API server
Set OpenAI Environment
You can set your environment with the following commands.
Set OpenAI base url
Set OpenAI API key
If you meet the following OOM error while creating embeddings, please set a smaller batch size by using environment variables.
You can try export FASTCHAT_WORKER_API_EMBEDDING_BATCH_SIZE=1
.
Try local LangChain
Here is a question answerting example.
Download a text file.
Run LangChain.