A modern chatbot application built with LlamaIndex, FastAPI, MongoDB, and OpenAI. Features a beautiful web interface with real-time streaming chat capabilities.
- 🚀 Fast & Modern: Built with FastAPI for high performance
- 🧠 AI-Powered: Uses OpenAI GPT models via LlamaIndex
- 💬 Real-time Chat: Streaming responses for instant interaction
- 📚 Memory: Persistent chat history with MongoDB
- 🎨 Beautiful UI: Modern, responsive web interface
- 🐳 Docker Ready: Easy deployment with Docker Compose
- ⚡ Session Management: Multiple concurrent chat sessions
- 🔍 Health Monitoring: Built-in health checks and status monitoring
- Backend: FastAPI, Python 3.11
- AI/LLM: LlamaIndex, OpenAI GPT-4o-mini
- Database: MongoDB
- Frontend: HTML5, CSS3, JavaScript (Vanilla)
- Deployment: Docker, Docker Compose
- Docker and Docker Compose installed
- OpenAI API key
-
Clone and navigate to the project:
cd /path/to/chatbox -
Set up environment variables:
cp .env.example .env # Edit .env and add your OpenAI API key -
Start the application:
docker-compose up -d
-
Access the application:
- Chatbox: http://localhost:8000
- MongoDB Express (DB Admin): http://localhost:8081
- API Docs: http://localhost:8000/docs
Create a .env file with:
OPENAI_API_KEY=your_openai_api_key_herePOST /api/chat- Send a message (non-streaming)POST /api/chat/stream- Send a message (streaming)GET /api/sessions/{session_id}- Get chat historyDELETE /api/sessions/{session_id}- Delete chat session
GET /- Web interfaceGET /health- Health checkGET /docs- API documentation
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f chatbox
# Stop all services
docker-compose down
# Rebuild and restart
docker-compose up --build -d
# Remove everything (including data)
docker-compose down -v-
Install Python dependencies:
pip install -r requirements.txt
-
Start MongoDB:
docker-compose up -d mongodb
-
Set environment variables:
export OPENAI_API_KEY="your_key_here" export MONGODB_URL="mongodb://admin:password123@localhost:27017/chatbox?authSource=admin"
-
Run the application:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
chatbox/
├── main.py # FastAPI application
├── requirements.txt # Python dependencies
├── Dockerfile # Container configuration
├── docker-compose.yml # Multi-service setup
├── init-mongo.js # MongoDB initialization
├── .env.example # Environment template
├── templates/
│ └── index.html # Web interface
└── README.md # This file
Visit /health to check service status:
{
"status": "healthy",
"mongodb": "connected",
"openai": "connected",
"version": "1.0.0"
}Access MongoDB Express at http://localhost:8081:
- Username:
admin - Password:
admin123
- Modern Design: Beautiful gradient UI with smooth animations
- Responsive: Works on desktop and mobile devices
- Real-time: Streaming chat with typing indicators
- Session Persistence: Chat history saved automatically
- Status Indicators: Connection status and health monitoring
- Streaming Chat: Real-time response streaming
- Session Management: Unique session IDs for each conversation
- Error Handling: Comprehensive error handling and logging
- Health Monitoring: Built-in health checks
- API Documentation: Auto-generated OpenAPI docs
- Persistent Storage: Chat history stored in MongoDB
- Indexing: Optimized queries with proper indexing
- Session Tracking: Efficient session management
- Scalable: Ready for horizontal scaling
- Environment variables for sensitive data
- Input validation and sanitization
- Rate limiting ready (can be added)
- CORS configuration available
- Database authentication enabled
For production deployment:
- Use environment-specific configurations
- Set up proper logging and monitoring
- Configure SSL/TLS certificates
- Set up database backups
- Use production-grade web server (nginx)
- Implement rate limiting
- Set up health checks and alerts
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
If you have any questions or issues, please open an issue on the repository.
Built with ❤️ using LlamaIndex, FastAPI, and OpenAI