Sanket22g
feat: Vera bot - FastAPI + Gemini 2.0 Flash, 4-context composer, auto-reply detection
69eb640 | title: Vera Bot - magicpin AI Challenge | |
| emoji: π€ | |
| colorFrom: indigo | |
| colorTo: purple | |
| sdk: docker | |
| pinned: true | |
| # Vera Bot β magicpin AI Challenge | |
| A high-quality merchant engagement bot built with **FastAPI + Gemini 2.0 Flash**. | |
| ## How It Works | |
| ### Core Architecture | |
| ``` | |
| POST /v1/context β In-memory store (scope, context_id) β {version, payload} | |
| POST /v1/tick β Compose messages using 4-context framework | |
| POST /v1/reply β Handle replies with routing logic | |
| GET /v1/healthz β Liveness probe | |
| GET /v1/metadata β Bot identity | |
| ``` | |
| ### Composition Strategy | |
| Every message follows the **4-Context Framework**: | |
| 1. **Category** β voice, peer stats, digest items, seasonal beats | |
| 2. **Merchant** β identity, performance, offers, signals | |
| 3. **Trigger** β why now (kind + urgency + payload) | |
| 4. **Customer** (optional) β for merchant-on-behalf sends | |
| ### Key Design Decisions | |
| - **Gemini 2.0 Flash** at temperature=0.1 for deterministic, grounded output | |
| - **In-memory state** for sub-millisecond context lookup (no external deps) | |
| - **Auto-reply detection** β exits after 2 consecutive auto-reply patterns | |
| - **Intent routing** β detects commitment signals β switches from pitch to action immediately | |
| - **Hostile message handling** β graceful exit with empathy | |
| - **Anti-repetition** β tracks sent bodies per conversation, modifies if repeat detected | |
| - **Trigger priority** β higher urgency triggers compose first | |
| ### Category Voice | |
| | Category | Voice | Key | | |
| |---|---|---| | |
| | Dentists | Clinical, peer-to-peer, technical OK | "Dr." prefix, no "cure/guaranteed" | | |
| | Salons | Warm, friendly, practical | Visual, service+price | | |
| | Restaurants | Operator-to-operator | Volume, timing, local | | |
| | Gyms | Coaching, motivational | Goals, retention | | |
| | Pharmacies | Trustworthy, precise | Compliance, supply alerts | | |
| ## API Endpoints | |
| ### GET /v1/healthz | |
| ```json | |
| { "status": "ok", "uptime_seconds": 1234, "contexts_loaded": {"category": 5, "merchant": 50, ...} } | |
| ``` | |
| ### GET /v1/metadata | |
| ```json | |
| { "team_name": "Vera-Flash", "model": "gemini-2.0-flash", ... } | |
| ``` | |
| ### POST /v1/context | |
| Push category/merchant/customer/trigger contexts. Idempotent by (scope, context_id, version). | |
| ### POST /v1/tick | |
| Returns proactive message actions for currently active triggers (up to 20/tick, sorted by urgency). | |
| ### POST /v1/reply | |
| Handles merchant/customer replies with: | |
| - Auto-reply detection β graceful exit after 2nd pattern | |
| - Hostile message detection β immediate end | |
| - Commitment detection β instant action mode | |
| - LLM reply composition for all other cases | |
| ## Tradeoffs | |
| - **In-memory vs Redis**: Faster reads, acceptable for 60-min test window. Would use Redis/Postgres for production. | |
| - **Gemini Flash vs Pro**: Flash is faster (sub-5s) and free-tier compatible. Pro would give marginally better quality on edge cases. | |
| - **Temperature 0.1**: Near-deterministic for same inputs. Slight variation intentional to avoid anti-repeat flags. | |