A lightweight Python CLI chatbot powered by OpenAI (default: GPT‑3.5 Turbo).
Chat with an AI directly from your terminal in a simple interactive loop.
The OpenAI CLI Chatbot is a simple, terminal-based chatbot written in Python.
It connects to OpenAI’s API to generate responses, allowing you to hold a continuous conversation from the command line.
- 💬 Interactive CLI chat (conversation loop)
- 🔌 OpenAI API integration for high-quality responses
- 🛠️ Configurable settings via
config.json(model, temperature, max tokens) - 🐍 Pure Python and easy to run locally
- 🧼 Minimal setup (install deps → set API key → run)
- 🐍 Python (3.7+)
- 🤝 OpenAI API
- 📄 Config via JSON (
config.json)
Before you start, make sure you have:
- 🐍 Python 3.7 or higher
- 🔑 An OpenAI API key
Create one at: https://platform.openai.com/
git clone https://github.com/Achintha-999/openai-cli-chatbot.git
cd openai-cli-chatbotpip install -r requirements.txtexport OPENAI_API_KEY="your_api_key_here"setx OPENAI_API_KEY "your_api_key_here"📝 Note (Windows): After running
setx, restart your terminal so the variable is available.
Run the chatbot:
python app.pyThen type your message and press Enter.
To stop the program, use Ctrl + C (or follow any built-in exit prompt if your script provides one).
You can customize the chatbot by editing config.json:
- 🧠 model — Choose the model name (default: GPT‑3.5 Turbo)
- 🎛️ temperature — Controls creativity (higher = more creative)
- 📏 max_tokens — Controls max response length
🔁 After editing
config.json, re-runpython app.pyto apply changes.
You: Hello!
Bot: Hi! How can I help you today?
Check whether your key is available in the current terminal session:
echo $OPENAI_API_KEYIf nothing appears, set it again (see installation step 3).
If your machine uses python3 and pip3, try:
python3 --version
pip3 install -r requirements.txt
python3 app.py- 🧾 Save chat history to a file
- 🧠 System prompt / persona selector
- 🧰 CLI arguments (model, temperature, max tokens)
- 🌐 Support for multiple providers (optional)
Contributions are welcome and appreciated! 🙌
- 🍴 Fork the repo
- 🌿 Create a branch (
feature/my-change) - ✅ Commit your changes
- 🔁 Open a Pull Request
🪪 MIT License — see LICENSE
- 🤖 OpenAI for the models and API
- 🌍 The open-source community for tools and inspiration
⭐ If you like this project, consider starring the repository!