Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

CLI AI Chatbot using Ollama

A local AI-powered CLI chatbot built using Python and Ollama with persistent memory support.

This chatbot:

  • runs completely offline
  • stores conversation history
  • supports multi-turn conversations
  • uses local LLMs through Ollama
  • requires no API key

Features

Local AI Chatbot

Runs AI models locally using Ollama.

Persistent Memory

Conversation history is stored in memory.json so the chatbot remembers previous chats.

Multi-turn Conversations

The chatbot maintains context across messages.

Offline Usage

No internet or API key required after model download.

Lightweight CLI Interface

Simple terminal-based chatbot.


Tech Stack

Technology Purpose
Python Programming language
Ollama Local LLM runtime
JSON Persistent memory storage

Project Structure

CLI_Chatbot/
│
├── main.py
├── memory.json
├── requirements.txt
├── README.md
└── .gitignore

Requirements

Install Python

Download Python: https://www.python.org/downloads/


Install Ollama

Download Ollama: https://ollama.com/download


Install Dependencies

pip install -r requirements.txt

Download a Model

Example:

ollama run llama3.2:3b

This downloads the model locally.

You can also use:

  • llama3
  • mistral
  • gemma:2b

Run the Chatbot

python main.py

Example Usage

Chat Started...
Type 'exit' to end the conversation.

You: Hello
Assistant: Hi! How can I help you today?

You: My name is Aditya
Assistant: Nice to meet you, Aditya!

You: What is my name?
Assistant: Your name is Aditya.

How Memory Works

Conversation history is stored inside:

memory.json

Every message:

  1. gets added to conversation history
  2. is sent to the AI model
  3. gets saved permanently

This allows the chatbot to remember previous conversations even after restarting.


Main Concepts Used

System Role

Defines chatbot behavior.

Example:

{
    "role": "system",
    "content": "You are a helpful assistant."
}

User Role

Stores user messages.

Example:

{
    "role": "user",
    "content": "Hello"
}

Assistant Role

Stores chatbot replies.

Example:

{
    "role": "assistant",
    "content": "Hi!"
}

Future Improvements

Possible upgrades:

  • Streaming responses
  • Semantic memory
  • SQLite database
  • Voice assistant
  • Rich terminal UI
  • Tool usage
  • GUI interface
  • Vector databases

Resume Value

This project demonstrates:

  • Python development
  • Conversational AI systems
  • Local LLM integration
  • Persistent memory handling
  • CLI application development
  • Context management

.gitignore

Recommended .gitignore:

venv/
__pycache__/
*.pyc
memory.json

License

This project is open-source and intended for educational purposes.


Author

Built by Aditya Jhinjha

About

A local AI-powered CLI chatbot built with Python and Ollama featuring persistent memory and multi-turn conversational context.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages