CoolFace
Apppublic

anslem19/llm-fastapi-boilerplate

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

โšก LLM FastAPI Boilerplate

A robust backend service for deploying GGUF language models using FastAPI and Docker.

๐ŸŽฏ Overview

This boilerplate provides a production-ready API for serving Large Language Models, with focus on type safety, easy deployment, and standardized interfaces.

โœจ Key Features

  • โ€”Type-Safe Backend: FastAPI with comprehensive request/response typing
  • โ€”Model Support: GGUF format via llama-cpp-python
  • โ€”Production Ready: CORS support, health checks, and Docker deployment
  • โ€”Flexible: Configurable inference parameters (temperature, topp, topk)
  • โ€”Developer Friendly: OpenAPI documentation included

๐Ÿ“‚ Project Structure

.
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ main.py        # FastAPI application and routes
โ”‚   โ”œโ”€โ”€ schemas.py     # Pydantic data models
โ”‚   โ”œโ”€โ”€ llm_utils.py   # LLM inference engine
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ requirements.txt   # Dependencies
โ”œโ”€โ”€ Dockerfile        # Container configuration
โ””โ”€โ”€ README.md

๐Ÿš€ Getting Started

Local Development

bash
git clone https://github.com/Anslemakadu/llm-fastapi-boilerplate
cd llm-fastapi-boilerplate
pip install -r requirements.txt
uvicorn app.main:app --reload --host 0.0.0.0 --port 7860

API documentation available at: http://localhost:7860/docs

Docker Deployment

bash
docker build -t llm-fastapi-boilerplate .
docker run -p 7860:7860 llm-fastapi-boilerplate

๐Ÿ”— API Endpoints

EndpointMethodDescription
/healthGETSystem status and model information
/generatePOSTSingle-turn text generation
/chatPOSTMulti-turn conversation

โš™๏ธ Configuration

Environment VariableDescriptionDefault
MODEL_REPOHugging Face model repositoryTheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF
MODEL_FILENAMEGGUF model filetinyllama-1.1b-chat-v1.0.Q4KM.gguf
BATCH_SIZEInference batch size16
N_THREADSCPU thread countSystem CPU count
N_CTXContext window size1024
HF_HUB_TOKENHuggingFace API token (optional)None

๐Ÿ“ Example Usage

bash
curl -X POST "https://anslem19-llm-fastapi-boilerplate.hf.space/chat" \
-H "Content-Type: application/json" \
-d '{
  "session_id": "demo",
  "message": "Hello LLM Boilerplate!"
}'

๐Ÿ“„ License

MIT License ยฉ 2025 Anslem Akadu