Skip to content

ExhumedCode/Simple-Python-CLI-Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Simple Python CLI Chatbot

A command-line interface chatbot application that uses OpenAI's GPT-4o-mini model to create an interactive AI assistant experience.

Project Overview

This project demonstrates a simple yet effective implementation of an AI chatbot using Python and the OpenAI API. The application allows users to have natural conversations with an AI assistant through a command-line interface.

Features

  • Real-time conversation with GPT-4o-mini
  • Conversation history tracking
  • Cost calculation for API usage
  • Graceful conversation ending

Requirements

  • Python 3.8+
  • OpenAI API key
  • python-dotenv package
  • openai package

Usage

  1. Clone this repository
  2. Create a .env file with your OpenAI API key:
    OPENAI_API_KEY=your_api_key_here
    
  3. Run the script:
    python main.py
    
  4. Start chatting with the AI assistant!
  5. Type "end conversation" to exit the program

Lessons Learned About AI in Software Development

1. API Integration and Security

Working with AI APIs requires careful handling of authentication credentials. This project demonstrates using environment variables for storing API keys securely.

2. Prompt Engineering

The way messages are constructed and passed to the model significantly impacts the quality of responses. The conversation history management shows how context can be maintained for more coherent interactions.

3. Cost Management

AI API calls can be expensive. The cost calculation function illustrates how to monitor and track usage costs, which is critical for production applications.

4. Function Calling

The project showcases OpenAI's function calling capability, demonstrating how to trigger specific application behaviors (like ending the conversation) through the AI interface.

5. Error Handling

When working with external AI services, robust error handling is essential for a good user experience, especially when network issues or rate limiting might occur.

6. Simplicity in Design

Effective AI integration doesn't require complex code. This project demonstrates how powerful functionality can be achieved with clean, well-organized code.

About

Chatbot using OpenAI API, implemented following Hyperskill's AI Engineering Bootcamp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages