A simple AI chatbot built using LangChain and Ollama (qwen2.5:0.5b) with support for multiple independent chat sessions.
- Chat with qwen2.5:0.5b locally using Ollama
- Maintains conversation history
- Create multiple chat sessions
- Switch between sessions
- View all available sessions
- View the current session
- Each session has its own independent memory
- Python
- LangChain
- Ollama
- qwen2.5:0.5b
The chatbot uses RunnableWithMessageHistory to manage conversation history.
Each session has a unique session_id, and the conversation history is stored separately for each session.
User
↓
Chatbot
↓
Session ID
↓
Chat History
↓
qwen2.5:0.5b
↓
Response
| Command | Description |
|---|---|
1 |
Create a new session |
2 |
Show all sessions |
3 |
Show current session |
4 |
Switch session |
break |
Exit chatbot |
You: my name is Vignesh
Bot: Nice to meet you, Vignesh!
1
Enter a new session_id: user2
You: my name is Kumar
Bot: Nice to meet you, Kumar!
4
Give the session_id to change: user1
You: what is my name?
Bot: Your name is Vignesh.
Each session maintains its own conversation history.
Install the required packages:
pip install langchain langchain-core langchain-ollamaMake sure Ollama is installed and the Llama 3.1 model is available:
ollama pull qwen2.5:0.5bRun the Python program:
python chatbot.pychatbot/
│
├── chatbot.py
└── README.md
This project demonstrates:
- LangChain prompts
- Chat message history
- Session management
RunnableWithMessageHistory- Local LLM integration
- Ollama
- Conversation memory