Backend – FastAPI¶
File: API/python/app/app.py¶
Startup and Configuration¶
The application is loaded with uvicorn via START_CHATBOT_v2.ps1:
Environment variables are loaded from the .env file specified by the ENV_PATH environment variable (default: API/chatbot/.env).
Key Variables (from .env)¶
| Variable | Description |
|---|---|
GEMINI_API_KEY |
Google Gemini API key |
CACHE_DIR |
Path to JSON cache folder |
LOG_DIR |
Path to log folder |
ALLOWED_TENANT_ID |
⚠️ Hardcoded to "SKI" in code |
Known limitation
ALLOWED_TENANT_ID = "SKI" is hardcoded at line 20 in app.py. All requests with a different tenant_id are rejected with HTTP 403. This must be removed for full multitenant support.
Endpoints¶
POST /api/chat¶
Receives a chat message and returns an AI reply.
Request model:
class ChatRequest(BaseModel):
tenant_id: str
message: str
history: list[dict] # [{"role": "user"|"assistant", "content": "..."}]
Response model:
Error codes:
| Code | Reason |
|---|---|
| 403 | tenant_id does not match ALLOWED_TENANT_ID |
| 404 | No cache file found for tenant |
| 500 | Gemini error or internal server error |
GET /health¶
Returns a simple health status:
System Prompt¶
build_system_prompt(tenant_id) reads cache/{tenant_id}_context.json and constructs a system message for Gemini containing:
- Club name and basic info
- Relevant data from all synced tables (news, activities, course info, etc.)
- Instruction to reply in the same language as the guest
- Instruction to limit answers to club-relevant information
Logging¶
log_interaction(tenant_id, message, reply) writes to {LOG_DIR}/{tenant_id}_chat.jsonl:
Logs do not contain IP addresses or personally identifiable information.
File: API/chatbot/requirements.txt¶
File: API/chatbot/.env.example¶
The template used to create .env during installation. Never contains real values – see .gitignore.