Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Contextual Chatbot API

A production-ready RAG-based Chatbot API built with FastAPI, LangChain, and Azure Cosmos DB.

Features

  • FastAPI: High-performance async API.
  • LangChain: Orchestration for LLM interactions.
  • Azure Cosmos DB: Scalable chat history storage with /sessionId partitioning.
  • 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.

Prerequisites

  • Python 3.13+
  • uv (for dependency management)
  • Azure Cosmos DB Account
  • OpenAI API Key

Setup

  1. Clone the repository:

    git clone <repository-url>
    cd ai-chatbot-template
  2. Install dependencies:

    uv sync
  3. Configure Environment: Create a .env file 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

Running the Application

Start the server with hot reload:

uv run uvicorn src.main:app --reload

Access the API documentation at http://localhost:8000/docs.

Testing

Run the test suite:

uv run pytest

Deployment

Docker

Build and run the container locally:

docker build -t ai-chatbot .
docker run -p 8000:8000 --env-file .env ai-chatbot

Azure

The project includes Bicep files for Azure deployment in infra/.

  1. Login to Azure:

    az login
  2. Deploy Infrastructure:

    az deployment group create --resource-group <your-rg> --template-file infra/main.bicep
  3. CI/CD: The .github/workflows/deploy.yml workflow automatically builds and deploys to Azure Web Apps on push to main. Ensure you set the AZURE_WEBAPP_PUBLISH_PROFILE secret in GitHub.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages