A production-ready, lightweight Python backend for building local or cloud-based chatbots using FastAPI and LangChain.
- 🚀 FastAPI Backend: High-performance async API
- 🤖 Multi-LLM Support: OpenAI, Anthropic Claude, Ollama (local models)
- 💾 Conversation Memory: Persistent chat history with SQLite/PostgreSQL
- 🔐 Authentication: JWT-based auth with API key support
- ⚡ WebSocket Streaming: Real-time streaming responses
- 🛡️ Rate Limiting: Protect your API from abuse
- 🐳 Docker Ready: Easy deployment with Docker/Docker Compose
- 📊 Monitoring: Health checks and observability
- 🧪 Comprehensive Tests: Unit and integration tests included
- 📚 OpenAPI Docs: Auto-generated interactive API documentation
- Python 3.9+
- Docker (optional)
- Clone the repository:
git clone <repository-url>
cd LLM-Chatbot-Framework- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Configure environment:
cp .env.example .env
# Edit .env with your API keys and settings- Run the application:
uvicorn app.main:app --reloadVisit http://localhost:8000/docs for interactive API documentation.
docker-compose up --buildKey environment variables in .env:
OPENAI_API_KEY: OpenAI API keyANTHROPIC_API_KEY: Anthropic API keyDATABASE_URL: Database connection stringSECRET_KEY: JWT secret keyRATE_LIMIT_PER_MINUTE: API rate limit
POST /api/v1/chat/message- Send a messagePOST /api/v1/chat/stream- Stream responses (WebSocket)GET /api/v1/chat/history/{conversation_id}- Get conversation historyDELETE /api/v1/chat/conversation/{conversation_id}- Delete conversation
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- LoginPOST /api/v1/auth/refresh- Refresh token
GET /health- Health checkGET /metrics- Prometheus metrics
app/
├── api/ # API routes and endpoints
├── core/ # Core configuration and settings
├── models/ # Database models
├── schemas/ # Pydantic schemas
├── services/ # Business logic
├── middleware/ # Custom middleware
└── utils/ # Utility functions
{
"provider": "openai",
"model": "gpt-4",
"temperature": 0.7
}{
"provider": "anthropic",
"model": "claude-3-5-sonnet-20241022",
"temperature": 0.7
}{
"provider": "ollama",
"model": "llama2",
"base_url": "http://localhost:11434"
}Run tests:
pytest
pytest --cov=app tests/ # With coverage- Fork the repository
- Create a feature branch
- Make your changes
- Write tests
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions, please open a GitHub issue.