Skip to content

About

LLM-powered chat API with authentication, streaming responses, and conversation history built using FastAPI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

LLM Chat API

A minimal backend API for an AI chat assistant built with FastAPI.
It supports user authentication, streaming chat responses, and conversation history.


Features

  • User registration and login (JWT authentication)
  • Streaming chat responses (Server-Sent Events)
  • Conversation history stored in a database
  • Multiple conversations per user
  • Mock LLM (default) with optional HuggingFace integration
  • Docker support for easy setup

Tech Stack

  • FastAPI
  • SQLAlchemy
  • SQLite
  • JWT (python-jose)
  • passlib (bcrypt)
  • Docker / docker-compose

Project Structure

app/
  main.py
  database.py
  models.py
  schemas.py
  security.py
  dependencies.py
  routers/
    auth.py
    chat.py
  services/
    llm_service.py

How to Run

Option 1 — Docker (recommended)

Create a .env file:

copy .env.example .env   # Windows
cp .env.example .env     # Mac/Linux

Then run:

docker-compose up --build

Open: http://localhost:8000/docs


Option 2 — Local

python -m venv .venv
.venv\Scripts\activate   # Windows

pip install -r requirements.txt
uvicorn app.main:app --reload

Open: http://localhost:8000/docs


Authentication

Register

POST /auth/register

{
  "email": "test@example.com",
  "password": "test123"
}

Login

POST /auth/login

Use the returned token in Swagger:

Bearer <your_token>

Chat

POST /chat

{
  "message": "What is a string in programming?"
}
  • Requires authentication
  • Streams response
  • Stores messages

Chat History

GET /chat/history

  • Requires authentication
  • Returns stored conversations

LLM

Mock (default)

  • No API key required
  • Simulates streaming responses

HuggingFace (optional)

  • Requires HF_TOKEN in .env
  • Uses HuggingFace Inference API

Environment Variables

SECRET_KEY=your_secret_key
HF_TOKEN=your_huggingface_token
LLM_PROVIDER=mock

The app works without a HuggingFace key by default.


Trade-offs

  • SQLite for simplicity
  • Mock LLM to avoid external dependency
  • No migrations (kept minimal)
  • Limited test coverage

Notes

  • API-only (no frontend)
  • Designed for clarity and extensibility

About

LLM-powered chat API with authentication, streaming responses, and conversation history built using FastAPI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages