How deepakindresh/mhai-backend works
MHAI-Backend is a FastAPI mental-health chat backend. The documented entry point is deepSeek.py; /chat gathers profile, assessment, and semantically relevant conversation context, constructs a prompt, generates a response, and stores the exchange. The files also expose message-editing and alternate chat behavior, while main.py contains a parallel chat implementation. Supabase provides profile, assessment, and message data; the Unsloth-loaded model generates replies and embeddings. The excerpts show the retrieval and persistence details, but omit parts of both chat handlers, so some documented integration links are cited to the README.
Main entry points: deepSeek.py Chat orchestration · main.py Alternate Chat API
Components 15
API Layer
- Chat API
deepSeek.py - Alternate Chat API
main.py - Chat orchestration
deepSeek.py - Message operations
deepSeek.py
Conversation Context
- Profile lookup
deepSeek.py - Assessment lookup
deepSeek.py - Relevant history
deepSeek.py - Severity summary
deepSeek.py
Model Inference
- Embedding generation
deepSeek.py - Unsloth model
deepSeek.py
Data Services
- Supabase
- Chat messages
- User profiles
- Assessments
Other components
- Application client
Connections 22
- Application client → Chat API: sends requests
README.md - Chat API → Chat orchestration: routes chat
deepSeek.py - Chat API → Message operations: routes edits
deepSeek.py - Chat orchestration → Profile lookup: fetches profile
deepSeek.py - Chat orchestration → Assessment lookup: fetches assessment
deepSeek.py - Chat orchestration → Relevant history: retrieves history
deepSeek.py - Chat orchestration → Severity summary: formats severity
deepSeek.py - Profile lookup → Supabase: queries profiles
deepSeek.py - Assessment lookup → Supabase: queries assessments
deepSeek.py - Relevant history → Embedding generation: embeds message
deepSeek.py - Relevant history → Supabase: matches messages
deepSeek.py - Embedding generation → Unsloth model: embeds text
deepSeek.py - Chat orchestration → Unsloth model: generates reply
README.md - Chat orchestration → Embedding generation: embeds exchange
deepSeek.py - Chat orchestration → Supabase: stores exchange
deepSeek.py - Message operations → Embedding generation: embeds edited text
deepSeek.py - Message operations → Supabase: updates message
deepSeek.py - Supabase → User profiles: reads
- Supabase → Assessments: reads
- Supabase → Chat messages: reads and writes
- Application client → Alternate Chat API: sends requests
README.md - Alternate Chat API → Chat orchestration: parallel chat flow