Skip to content

behshadrhp/ShadBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChatBot with Ollama API

This is a simple Python-based chatbot using the Ollama API and the Qwen 3 1.7B model. The chatbot maintains conversation history and streams responses in real-time.


Features

  • Interactive command-line chat interface.
  • Uses Qwen 3 1.7B model via Ollama.
  • Streams responses as the model generates text.
  • Maintains full conversation history.
  • Easy exit with commands like exit or quit.

Requirements

  • Python 3.8 or higher
  • Ollama Python SDK
  • Internet connection (for Ollama API access, if not using local model)

Installation

  1. Clone the repository:
git clone https://github.com/behshadrhp/ShadBot.git
cd ShadBot
  1. Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate  # Linux/Mac
venv\Scripts\activate     # Windows
  1. Install dependencies:
pip install ollama
  1. Ensure Ollama CLI is installed and the model qwen3:1.7b is available:
# install ollama in linux
curl -fsSL https://ollama.com/install.sh | sh

# install model
ollama pull qwen3:1.7b

# list of models
ollama list

Usage

Run the chatbot script:

python main.py

Then interact in the terminal:

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

To exit the chatbot, type:

exit

or

quit

Code Overview

  • history: Stores all messages exchanged between the user and the bot.
  • ai_model: Model used (qwen3:1.7b).
  • Streaming: Messages from the bot are streamed in real-time for a responsive experience.
  • Conversation memory: Appends every user and bot message to history to maintain context.

Key Part of the Script:

response = ollama.chat(
    stream=True,
    model=ai_model,
    messages=history,
    think=False,
)
  • stream=True enables real-time streaming.
  • think=False disables the "thinking" animation.

Contributing

  1. Fork the repository.
  2. Create a branch (git checkout -b feature-name).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature-name).
  5. Open a pull request.

License

This project is licensed under the MIT License.


Notes

  • Make sure your Ollama CLI is set up correctly before running the script.
  • For large conversations, consider limiting history to improve performance.
  • This chatbot runs in the terminal and does not include a GUI by default.

About

Simple ChatBot with Ollama and Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages