VidurAGI/user_wellbeing_Dossier
0
Sattvastha Data Generation API
FastAPI service that generates a structured wellbeing dossier (data.json-style payload) for a Sattvastha user. Pulls assessments, mood check-ins, journal entries, and chat history from MongoDB, then uses Groq to produce schema-conforming weekly wellbeing frames. The result is upserted into the userdossiers collection (one document per user, frames merged by calendar week).
Endpoints
Example request
curl -X POST https://<your-space>.hf.space/generate \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"weeks": 8,
"conversations": 6,
"persist": true,
"include_payload": true
}'Example response
{
"email": "user@example.com",
"generated_at": "2026-05-19T03:14:15.000000+00:00",
"duration_seconds": 42.18,
"weeks_generated": 8,
"chat_turns": 12,
"schema_valid": true,
"schema_errors": [],
"mongo_persisted": true,
"total_frames_in_mongo": 8,
"new_or_updated_frames": 8,
"payload": { "personal_memory": { ... }, "recent_chat_memory": [ ... ], "wellbeing_frames": [ ... ] }
}Environment variables
Set these as Secrets in your Hugging Face Space settings (Settings → Variables and secrets → New secret):
Persistence semantics
Each call to POST /generate upserts a single document into userdossiers keyed by user_id (the email).
personal_memory— replaced every run.recent_chat_memory— replaced every run.wellbeing_frames— merged byweek_start_date. If a calendar week already exists in the document, the new frame replaces it (latest analysis wins). Weeks not in the new batch are preserved. Running the pipeline weekly grows the dossier by ~1 frame per run.
To wipe a user's dossier and start over:
db["userdossiers"].delete_one({"user_id": "user@example.com"})Local development
pip install -r requirements.txt
export GROQ_API_KEY=...
export MONGO_CONNECTION_STRING=...
uvicorn data_generation_api:app --host 0.0.0.0 --port 7860 --reloadThen open http://localhost:7860/docs for the Swagger UI.
Notes
- A single
/generatecall takes ~30–60 s due to multiple Groq calls (sentiment + wellbeing frames). - The pipeline anchors weekly buckets on the user's most recent activity, not on today — so a user who hasn't logged in for 2 weeks still gets relevant frames.
- Groq's
openai/gpt-oss-120bhas tight TPM limits on the ondemand tier. If you hit rate-limit errors on the frame-generation call, switch to `llama-3.3-70b-versatile` by editing `GROQFRAMEMODEL` in `datageneration_pipeline.py`.
