Skip to content

gabrielizalo/simple-python-cli-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 Simple Python CLI Chat

Simple Python CLI Chat Header
Python OpenAI License

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.

✨ Features

  • 💬 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

🛠️ Technologies Used

  • Python 3.13
  • OpenAI API (GPT-3.5-turbo or GPT-4-turbo-preview)
  • python-dotenv for environment management

📋 Prerequisites

🚀 Installation

  1. Clone the repository

    git clone https://github.com/gabrielizalo/simple-python-cli-chat.git
    cd simple-python-cli-chat
  2. Create a virtual environment (recommended)

    python -m venv venv
    # On Windows
    venv\Scripts\activate
    # On macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. 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

💻 Usage

Run the chatbot:

python main.py

Conversation example:

Conversation example

To exit naturally say goodbye (AI will detect and call end_conversation).

🧠 Key Concepts Demonstrated

  1. OpenAI Chat Completions API: Making requests with system/user/assistant roles
  2. Function Calling: Defining and handling tool calls from the model
  3. Conversation State Management: Maintaining message history for context
  4. Cost Calculation: Tracking input/output tokens and computing costs
  5. Environment Configuration: Secure API key management with dotenv

🎓 About This Project

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

📝 License

This project is open source and available under the MIT LICENSE.

👤 Author

Gabriel Porras

About

A conversational AI chatbot built with Python and OpenAI's GPT-3.5 API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages