A conversational AI chatbot built with Python and OpenAI's GPT-3.5 API. This CLI application demonstrates function calling, conversation management, and token cost tracking.
- 💬 Interactive Chat Interface: Continuous conversation loop with context retention
- 🔧 Function Calling: Intelligent conversation termination using OpenAI's function calling
- 💰 Cost Tracking: Real-time token usage and cost calculation
- 🎯 Smart Exit: Both manual (
exit/quit) and AI-detected conversation ending
- Python 3.13
- OpenAI API (GPT-3.5-turbo or GPT-4-turbo-preview)
- python-dotenv for environment management
- Python 3.13 or higher
- OpenAI API key (Get one here)
-
Clone the repository
git clone https://github.com/gabrielizalo/simple-python-cli-chat.git cd simple-python-cli-chat -
Create a virtual environment (recommended)
python -m venv venv
# On Windows venv\Scripts\activate
# On macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
# Copy the example file cp .env.example .env # Edit .env and add your OpenAI API and HYPERSKILL BASE URL keys # OPENAI_API_KEY=sk-your-actual-key-here # HYPERSKILL_BASE_URL=https://api.openai.com/v1
Run the chatbot:
python main.pyConversation example:
To exit naturally say goodbye (AI will detect and call end_conversation).
- OpenAI Chat Completions API: Making requests with system/user/assistant roles
- Function Calling: Defining and handling tool calls from the model
- Conversation State Management: Maintaining message history for context
- Cost Calculation: Tracking input/output tokens and computing costs
- Environment Configuration: Secure API key management with dotenv
This project was developed as part of the AI Engineer Bootcamp curriculum, demonstrating foundational skills in:
- Working with LLM APIs
- Implementing function calling
- Building conversational AI applications
- Managing API costs and tokens
This project is open source and available under the MIT LICENSE.
Gabriel Porras
- GitHub: https://github.com/gabrielizalo
- LinkedIn: https://linkedin.com/in/gabrielizalo
- Header Robot by Mohamed Nohassi on Unsplash
- Header Background by Conny Schneider on Unsplash


