A FastAPI application for collecting and storing LLM evaluation feedback in MongoDB.
- ✅ FastAPI endpoint for submitting evaluation data
- ✅ MongoDB integration for data persistence
- ✅ Pydantic validation for data integrity
- ✅ Automatic API documentation (Swagger UI)
- ✅ Health check endpoint
- ✅ Statistics endpoint
- ✅ CORS support
- Install dependencies:
pip install -r requirements.txt- (Optional) Create a
.envfile based on.env.exampleif you want to customize settings.
Start the server:
python app.pyOr use uvicorn directly:
uvicorn app:app --reload --host 0.0.0.0 --port 8000The API will be available at:
- API: http://localhost:8000
- Interactive Docs (Swagger): http://localhost:8000/docs
- Alternative Docs (ReDoc): http://localhost:8000/redoc
Submit LLM evaluation feedback
Request Body:
{
"chat_history": [
{"role": "user", "content": "Hello, how are you?"},
{"role": "assistant", "content": "I'm doing well, thank you!"}
],
"exact_turn": "I'm doing well, thank you!",
"thumbs": "up",
"user_id": "user_123",
"session_id": "session_456",
"chat_id": "chat_789",
"chat_created_at": "2025-11-12T10:30:00Z",
"thumbs_created_at": "2025-11-12T10:31:00Z"
}Response:
{
"success": true,
"message": "Evaluation feedback saved successfully",
"evaluation_id": "507f1f77bcf86cd799439011",
"timestamp": "2025-11-12T10:31:05.123456"
}Health check endpoint
Get basic statistics about stored evaluations
Root endpoint with API information
chat_history: List of chat messages (role, content)exact_turn: The specific turn being evaluatedthumbs: "up" or "down"user_id: User identifiersession_id: Session identifierchat_id: Chat identifierchat_created_at: Chat creation timestampthumbs_created_at: Feedback timestamp
The application connects to MongoDB using the connection string in config.py:
- Database: citrust
- Collection: evaluations
Data is automatically stored with ISO-formatted timestamps.
curl -X POST "http://localhost:8000/api/v1/evaluation" `
-H "Content-Type: application/json" `
-d '{
"chat_history": [{"role": "user", "content": "Hello"}],
"exact_turn": "Hello",
"thumbs": "up",
"user_id": "user_123",
"session_id": "session_456",
"chat_id": "chat_789",
"chat_created_at": "2025-11-12T10:30:00Z",
"thumbs_created_at": "2025-11-12T10:31:00Z"
}'The application includes:
- Automatic request validation
- Error handling and logging
- CORS middleware for cross-origin requests
- Connection pooling for MongoDB
- Proper startup/shutdown lifecycle management
MIT