A modern, web-based chatbot application powered by OpenAI's GPT-3.5-turbo model. Built with Flask and featuring a beautiful, responsive UI.
- π€ 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
- Python 3.7 or higher
- OpenAI API key
-
Clone or download the project files
-
Install Python dependencies
pip install -r requirements.txt
-
Set up environment variables
Create a
.envfile 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 -
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
.envfile
-
Start the application
python app.py
-
Open your browser
- Navigate to
http://localhost:5000 - You should see the chatbot interface
- Navigate to
-
Start chatting
- Type your message in the input field
- Press Enter or click Send
- The AI will respond with helpful information
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)
GET /- Main chat interfacePOST /chat- Send a message and get AI responsePOST /clear- Clear conversation historyGET /history- Get conversation history for current session
You can modify the following settings in app.py:
- Model: Change
gpt-3.5-turboto other OpenAI models - Max tokens: Adjust
max_tokens=1000for response length - Temperature: Modify
temperature=0.7for response creativity (0.0-1.0) - Port: Change
port=5000to use a different port
-
"OpenAI API key not found"
- Make sure you've created a
.envfile - Verify your API key is correct
- Check that the
.envfile is in the same directory asapp.py
- Make sure you've created a
-
"Module not found" errors
- Run
pip install -r requirements.txtto install dependencies - Make sure you're using Python 3.7 or higher
- Run
-
"Connection refused"
- Check if the port 5000 is already in use
- Try changing the port in
app.py
- Check the browser console for JavaScript errors
- Look at the Flask application logs in the terminal
- Verify your OpenAI API key has sufficient credits
- Never commit your
.envfile to version control - Use a strong secret key in production
- Consider rate limiting for production use
- Monitor your OpenAI API usage and costs
This project is open source and available under the MIT License.
Feel free to submit issues, feature requests, or pull requests to improve this chatbot application.