Spaces:
Sleeping
Sleeping
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
- Fork this Space
- Modify
model_nameandadapter_pathinapp.pyif needed - 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