Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Chatbot Application

A modern, web-based chatbot application powered by OpenAI's GPT-3.5-turbo model. Built with Flask and featuring a beautiful, responsive UI.

Features

  • πŸ€– Powered by OpenAI GPT-3.5-turbo
  • πŸ’¬ Real-time chat interface
  • 🎨 Modern, responsive design
  • πŸ“± Mobile-friendly
  • πŸ’Ύ Conversation history per session
  • πŸ—‘οΈ Clear chat functionality
  • ⚑ Fast and lightweight

Prerequisites

  • Python 3.7 or higher
  • OpenAI API key

Installation

  1. Clone or download the project files

  2. Install Python dependencies

    pip install -r requirements.txt
  3. Set up environment variables

    Create a .env file in the project root with the following content:

    # OpenAI API Configuration
    # Get your API key from: https://platform.openai.com/api-keys
    OPENAI_API_KEY=your_openai_api_key_here
    
    # Flask Secret Key (for session management)
    # Generate a random secret key for production
    SECRET_KEY=your-secret-key-here
    
  4. Get your OpenAI API key

    • Visit OpenAI Platform
    • Sign up or log in to your account
    • Create a new API key
    • Copy the key and paste it in your .env file

Usage

  1. Start the application

    python app.py
  2. Open your browser

    • Navigate to http://localhost:5000
    • You should see the chatbot interface
  3. Start chatting

    • Type your message in the input field
    • Press Enter or click Send
    • The AI will respond with helpful information

Project Structure

chatbot-app/
β”œβ”€β”€ app.py                 # Main Flask application
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ README.md             # This file
β”œβ”€β”€ templates/
β”‚   └── index.html        # Chat interface template
└── .env                  # Environment variables (create this)

API Endpoints

  • GET / - Main chat interface
  • POST /chat - Send a message and get AI response
  • POST /clear - Clear conversation history
  • GET /history - Get conversation history for current session

Configuration Options

You can modify the following settings in app.py:

  • Model: Change gpt-3.5-turbo to other OpenAI models
  • Max tokens: Adjust max_tokens=1000 for response length
  • Temperature: Modify temperature=0.7 for response creativity (0.0-1.0)
  • Port: Change port=5000 to use a different port

Troubleshooting

Common Issues

  1. "OpenAI API key not found"

    • Make sure you've created a .env file
    • Verify your API key is correct
    • Check that the .env file is in the same directory as app.py
  2. "Module not found" errors

    • Run pip install -r requirements.txt to install dependencies
    • Make sure you're using Python 3.7 or higher
  3. "Connection refused"

    • Check if the port 5000 is already in use
    • Try changing the port in app.py

Getting Help

  • Check the browser console for JavaScript errors
  • Look at the Flask application logs in the terminal
  • Verify your OpenAI API key has sufficient credits

Security Notes

  • Never commit your .env file to version control
  • Use a strong secret key in production
  • Consider rate limiting for production use
  • Monitor your OpenAI API usage and costs

License

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

Contributing

Feel free to submit issues, feature requests, or pull requests to improve this chatbot application.

About

Chat-Bot-API-Gpt-Flask A lightweight and scalable chatbot API built with Flask and powered by GPT models. This project provides a simple HTTP interface to interact with OpenAI's GPT API, enabling developers to integrate conversational AI into their own applications. Features: πŸ”Ή RESTful API endpoints for chat interaction πŸ”Ή Flask-based backend

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages