chatbot-api / README.md
pierreramez's picture
Upload README.md
ce60d17 verified
metadata
title: Personalized Chatbot API
emoji: ๐Ÿค–
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit

Personalized Chatbot Backend

FastAPI backend for a personalized chatbot with Human-in-the-Loop (HITL) feedback.

Features

  • ๐Ÿš€ Fast inference with Llama 3.2
  • ๐Ÿ’พ Feedback collection for continuous learning
  • ๐Ÿ“Š Statistics tracking
  • ๐Ÿ”ง LoRA adapter support for finetuned models

API Endpoints

POST /chat

Generate chatbot response

Request:

{
  "message": "Hello, how are you?",
  "history": [],
  "max_length": 200,
  "temperature": 0.7
}

Response:

{
  "reply": "I'm doing well, thank you!",
  "timestamp": 1234567890.123
}

POST /feedback

Submit correction for model response

Request:

{
  "user_input": "What is the capital of France?",
  "model_reply": "The capital is Berlin",
  "user_correction": "The capital is Paris",
  "reason": "incorrect_answer"
}

GET /stats

Get feedback statistics

Response:

{
  "total_interactions": 100,
  "corrections": 15,
  "accepted": 85,
  "correction_rate": 0.15
}

GET /health

Health check endpoint

Configuration

The model is configured in the startup_event() function:

model_manager.initialize(
    model_name="meta-llama/Llama-3.2-1B-Instruct",
    adapter_path=None,  # Path to LoRA adapter if finetuned
    use_4bit=True       # Use 4-bit quantization
)

Usage

  1. Fork this Space
  2. Modify model_name and adapter_path in app.py if needed
  3. The API will be available at: https://YOUR-USERNAME-chatbot-api.hf.space

Local Development

pip install -r requirements.txt
python app.py

API will be available at: http://localhost:7860

License

MIT