This example shows how to use the Vercel AI SDK with Next.js, LangChain, and Ollama to create a ChatGPT-like AI-powered streaming chat bot.
NOTE: Ollama needs to be deployed separately.
Deploy the example using Vercel:
Execute create-next-app
with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example https://github.com/brunnolou/next-langchain-rag-ollama
yarn create next-app --example https://github.com/brunnolou/next-langchain-rag-ollama
pnpm create next-app --example https://github.com/brunnolou/next-langchain-rag-ollama
To run the example locally you need to:
- Download Ollama and install it locally.
- run
ollama run mistral
to download and install the model locally (Requires 4.1GB and 8GB of RAM) - Open http://localhost:11434 to check if Ollama is running.
- Run
docker pull qdrant/qdrant
anddocker run -p 6333:6333 qdrant/qdrant
- Open the console dashboard
localhost:6333/dashboard#/console
. - Create a new collection running this:
PUT collections/swiss-or
{
"vectors": {
"size": 384,
"distance": "Cosine"
}
}
- Download the snapshot file
- Unzip the file using the terminal (
⚠️ not with Finder on Mac⚠️ ) withunzip ...
- Upload the file using the following command. Adapt the fields accordingly and run it from the same directory, as where your snapshot lies.
curl -X POST 'http://localhost:6333/collections/swiss-or/snapshots/upload' \
-H 'Content-Type:multipart/form-data' \
-F 'snapshot=@swiss-code-of-obligations-articles-gte-small-2023-10-18-12-13-25.snapshot'
yarn install
to install the required dependencies.- Copy the file
.env.local.example
in the project and rename it to.env
. Verify if all environment variables are correct. yarn dev
to launch the development server.- Go to
http://localhost:3000
and try out the app.
To learn more about LangChain, OpenAI, Next.js, and the Vercel AI SDK take a look at the following resources:
- Vercel AI SDK docs - learn mode about the Vercel AI SDK
- LangChain Documentation - learn about LangChain
- Ollama - learn about Ollama features, models, and API.
- Next.js Documentation - learn about Next.js features and API.
- Qdrant Documentation - learn about Next.js features and API.