A command-line chatbot powered by Google's Gemini API with streaming responses and a beautiful terminal interface.
- Interactive chat with Google Gemini AI models
- Real-time streaming responses
- Conversation history (AI remembers context)
- Beautiful terminal UI with Rich
- Easy configuration via
.envfile
- Python 3.12 or higher
- A Google Gemini API key (Get one here)
-
Clone the repository
git clone https://github.com/SajalDevX/ai_chat_bot_cli.git cd ai_chat_bot_cli -
Create a virtual environment
python -m venv .venv source .venv/bin/activate # Linux/macOS # or .venv\Scripts\activate # Windows
-
Install dependencies
# Using uv (recommended) uv pip install -e . # Or using pip pip install -e .
-
Configure your API key
Create a
.envfile in the project root:cp .env.example .env
Edit
.envand add your Gemini API key:GEMINI_API_KEY=your_api_key_here GEMINI_MODEL=gemini-2.0-flash MAX_TOKENS=1000 TEMPERATURE=0.7
Run the chatbot:
# Using the CLI command
ai-chat-bot
# Or using Python module
python -m ai_chat_bot.main
# Or with uv
uv run python -m ai_chat_bot.mainExample session:
╭─────────────────────────────────────────────────────────╮
│ AI Chatbot │
│ Type your message and press Enter. │
│ Commands: /help, /clear, /quit │
╰─────────────────────────────────────────────────────────╯
✅ Connected to Gemini API!
ℹ️ Model: gemini-2.0-flash
ℹ️ Streaming enabled
You: Hello! What can you help me with?
🤖 Assistant:
Hello! I can help you with a wide range of tasks...
| Command | Description |
|---|---|
/help |
Show help information |
/clear |
Clear conversation history |
/quit |
Exit the chatbot |
| Variable | Description | Default |
|---|---|---|
GEMINI_API_KEY |
Your Google Gemini API key | Required |
GEMINI_MODEL |
Gemini model to use | gemini-2.0-flash |
MAX_TOKENS |
Maximum tokens in response | 1000 |
TEMPERATURE |
Response creativity (0.0-2.0) | 0.7 |
TIMEOUT |
API request timeout (seconds) | 30.0 |
gemini-2.0-flash- Fast and efficient (recommended)gemini-2.5-flash- Latest flash modelgemini-2.5-pro- Most capable model
chat_bot_cli/
├── src/
│ └── ai_chat_bot/
│ ├── __init__.py
│ ├── main.py # Entry point and ChatBot class
│ ├── config.py # Settings configuration
│ ├── clients/
│ │ ├── __init__.py
│ │ └── gemini.py # Gemini API client
│ ├── models/
│ │ ├── __init__.py
│ │ └── messages.py # Message and Conversation models
│ ├── ui/
│ │ ├── __init__.py
│ │ └── display.py # Terminal display utilities
│ └── utils/
│ ├── __init__.py
│ └── exceptions.py # Custom exceptions
├── .env # Environment variables (create this)
├── pyproject.toml
└── README.md
- Check your API quota at https://ai.dev/usage
- Try using
gemini-2.0-flashmodel (more generous limits) - Wait a few minutes and try again
- Verify your API key at https://aistudio.google.com/apikey
- Make sure the
.envfile is in the project root - Check that the key is correctly copied (no extra spaces)
- Update to a supported model (e.g.,
gemini-2.0-flash) - Check available models at https://ai.google.dev/gemini-api/docs/models
This project is licensed under the MIT License - see the LICENSE file for details.
SajalDevX - SajalDevX