# QuitSure AI Support

In-house AI assistant that answers user support queries inside the QuitSure app and
hands off to a human coach when needed. Replaces Freshchat's manual-first flow with an
**AI-first** flow (AI answers → escalate to coach only when required).

- **Model:** Google Gemini Flash (we have Gemini credits)
- **Knowledge:** curated docs + Ram's program docs + the coach common-questions Excel.
  **We do NOT train on raw Freshchat coach transcripts** — they dilute the AI's reasoning (Ram's call).
- **Scope:** we build ONLY this API. The app team owns the chat UI, calling this endpoint,
  and routing escalations into Freshchat. See [`docs/API.md`](docs/API.md).
- **Status:** KB built (483 Q&A from the Excel); service code written; needs `GEMINI_API_KEY`
  to build the embedding index and run. Architecture in [`docs/PLAN.md`](docs/PLAN.md).

## Folder layout
```
quitsure-support-ai/
├── knowledge/      ← SOURCE MATERIAL. Drop the coach-questions Excel + docs here.
├── docs/           ← PLAN.md and design notes
├── scripts/        ← index builder, data prep (added once the Excel lands)
├── data/           ← generated vector index (gitignored)
└── app.py          ← FastAPI service (added once knowledge + decisions are locked)
```

## Run
```
pip install -r requirements.txt
cp .env.example .env              # add GEMINI_API_KEY
python3 scripts/build_kb.py       # Excel -> data/kb.json  (483 entries)
python3 scripts/build_index.py    # embed KB -> data/index.npz   (needs API key)
uvicorn app:app --port 8082
```
Then: `curl -X POST localhost:8082/chat -H 'content-type: application/json' -d '{"message":"how do I cancel my subscription?"}'`
