A production-ready RAG-based Chatbot API built with FastAPI, LangChain, and Azure Cosmos DB.
- FastAPI: High-performance async API.
- LangChain: Orchestration for LLM interactions.
- Azure Cosmos DB: Scalable chat history storage with
/sessionIdpartitioning. - Streaming Responses: Real-time token streaming for better UX.
- API Security: API Key authentication middleware.
- RAG Architecture: Ready for Retrieval-Augmented Generation (currently using placeholder context).
- Production Ready: Structured logging, Docker support, and CI/CD workflows.
- Python 3.13+
- uv (for dependency management)
- Azure Cosmos DB Account
- OpenAI API Key
-
Clone the repository:
git clone <repository-url> cd ai-chatbot-template
-
Install dependencies:
uv sync
-
Configure Environment: Create a
.envfile in the root directory:OPENAI_API_KEY=your-openai-key COSMOS_ENDPOINT=your-cosmos-endpoint COSMOS_KEY=your-cosmos-key COSMOS_DATABASE_NAME=ChatBotDB COSMOS_CONTAINER_NAME=ChatHistory API_AUTH_KEY=your-secret-api-key # Optional: Protects the API
Start the server with hot reload:
uv run uvicorn src.main:app --reloadAccess the API documentation at http://localhost:8000/docs.
Run the test suite:
uv run pytestBuild and run the container locally:
docker build -t ai-chatbot .
docker run -p 8000:8000 --env-file .env ai-chatbotThe project includes Bicep files for Azure deployment in infra/.
-
Login to Azure:
az login
-
Deploy Infrastructure:
az deployment group create --resource-group <your-rg> --template-file infra/main.bicep
-
CI/CD: The
.github/workflows/deploy.ymlworkflow automatically builds and deploys to Azure Web Apps on push tomain. Ensure you set theAZURE_WEBAPP_PUBLISH_PROFILEsecret in GitHub.