A simple chat bot made with vercel's Ai toolkit and ollama
demo.mp4
This project relies on Ollama to work. It should be installed on your system.
-
Download Ollama for your operating system
-
Download Meta's Llama 3 model (≈4GB) by running
ollama run llama3in your terminalNode: If the responses are slow you may switch to a faster model. Check out the FAQ at the end.
- Run
pnpm ito install all dependencies - Run
pnpm devto start dev server orpnpm build-previewfor productioin server - Open
localhost:3000/on your browser
- NextJS
- Typescript
- React
- Vercel's Ai Toolkit
- Ollama
- Meta's llama3 model
- Tailwind
- NextUI
-
Single User Assumption: Design the application for a single user; there is no need to implement authentication or a user management system.
-
Session Memory: The application must be capable of recalling messages from previous sessions with the user. (use sqlite as database)
-
User Feedback Implementation: Incorporate a like/dislike button for each message from the AI. The application should record this feedback in a database and display it alongside the messages in subsequent sessions.
Bonus Task:
- Enhanced Formatting: Implement the capability for the AI to deliver responses in Markdown format.
How do I change the LLM model?
You need to download one of many available models from Ollama's library and then make the following changes to /app/api/v1/chat/route.ts
Note: I am using llama3 just as an example
const result = await streamText({
-- model: ollama("llama3"), // Slower but better model
++ model: ollama("phi3"), // Faster but older less capable model
messages,
})Why did I use Ollama?
Because it runs locally and is free. Unlinke APIs from OpenAi, Athropic, etc.