rohitsar567 commited on
Commit
bd7ade9
·
verified ·
1 Parent(s): 127f4e7

Deploy v1 — single-Docker FastAPI + Next.js + RAG + voice + faithfulness

Browse files
backend/providers/groq_llm.py CHANGED
@@ -55,9 +55,25 @@ class GroqLLM(LLMProvider):
55
  "Content-Type": "application/json",
56
  }
57
 
 
 
 
58
  async with httpx.AsyncClient(timeout=self.timeout) as client:
59
- resp = await client.post(url, headers=headers, json=body)
60
- resp.raise_for_status()
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  payload = resp.json()
62
 
63
  choice = payload["choices"][0]
 
55
  "Content-Type": "application/json",
56
  }
57
 
58
+ import asyncio
59
+ # Groq free tier rate-limits aggressively (~30 req/min). Retry on 429
60
+ # with exponential backoff; also retry transient 5xx.
61
  async with httpx.AsyncClient(timeout=self.timeout) as client:
62
+ attempts = 4
63
+ delay = 1.5
64
+ for attempt in range(attempts):
65
+ resp = await client.post(url, headers=headers, json=body)
66
+ if resp.status_code == 429 or (500 <= resp.status_code < 600):
67
+ if attempt == attempts - 1:
68
+ resp.raise_for_status()
69
+ # Honor Retry-After if Groq sends one; else exponential
70
+ ra = resp.headers.get("Retry-After")
71
+ wait = float(ra) if ra and ra.replace(".", "").isdigit() else delay
72
+ await asyncio.sleep(wait)
73
+ delay *= 2
74
+ continue
75
+ resp.raise_for_status()
76
+ break
77
  payload = resp.json()
78
 
79
  choice = payload["choices"][0]
eval/run.py CHANGED
@@ -125,13 +125,44 @@ Grade now."""
125
 
126
 
127
  async def run_one(gold: dict) -> EvalRecord:
128
- turn = await handle_turn(
129
- user_text=gold["question"],
130
- chat_history=[],
131
- user_profile={},
132
- policy_filter_ids=[gold["policy_id"]],
133
- )
134
- factual, citation, score, reason = await grade_one(gold, turn.reply_text, turn.blocked)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  return EvalRecord(
136
  id=gold["id"],
137
  policy_id=gold["policy_id"],
 
125
 
126
 
127
  async def run_one(gold: dict) -> EvalRecord:
128
+ """Single gold-question evaluation. Guarded so transient API errors (Groq
129
+ rate limit, network timeout) don't kill the whole sweep — the question
130
+ is recorded as failed and we move on."""
131
+ try:
132
+ turn = await handle_turn(
133
+ user_text=gold["question"],
134
+ chat_history=[],
135
+ user_profile={},
136
+ policy_filter_ids=[gold["policy_id"]],
137
+ )
138
+ except Exception as e: # noqa: BLE001
139
+ msg = f"{type(e).__name__}: {str(e)[:200]}"
140
+ return EvalRecord(
141
+ id=gold["id"],
142
+ policy_id=gold["policy_id"],
143
+ question=gold["question"],
144
+ expected_answer=gold["expected_answer"],
145
+ bot_answer=f"[ORCHESTRATOR ERROR] {msg}",
146
+ factual_match=False,
147
+ citation_present=False,
148
+ judge_score=0.0,
149
+ judge_reason=f"orchestrator_error: {msg}",
150
+ expected_refusal=gold["expected_refusal"],
151
+ question_type=gold["question_type"],
152
+ difficulty=gold["difficulty"],
153
+ blocked=False,
154
+ faithfulness_passed=False,
155
+ faithfulness_reasons=[f"orchestrator_error: {msg}"],
156
+ brain_used="error",
157
+ latency_ms=0,
158
+ )
159
+ try:
160
+ factual, citation, score, reason = await grade_one(gold, turn.reply_text, turn.blocked)
161
+ except Exception as e: # noqa: BLE001
162
+ factual = False
163
+ citation = bool(turn.citations) if hasattr(turn, "citations") else False
164
+ score = 0.0
165
+ reason = f"grader_error: {type(e).__name__}: {str(e)[:160]}"
166
  return EvalRecord(
167
  id=gold["id"],
168
  policy_id=gold["policy_id"],
tools/upload_to_hf.py CHANGED
@@ -41,6 +41,13 @@ IGNORE = [
41
  "logs/**",
42
  "*.log",
43
  ".dockerignore", # only needed at build time; HF doesn't use it
 
 
 
 
 
 
 
44
  ]
45
 
46
 
 
41
  "logs/**",
42
  "*.log",
43
  ".dockerignore", # only needed at build time; HF doesn't use it
44
+ # Storage savings — HF Space free tier is 1GB. These regenerate at boot:
45
+ "rag/vectors/**", # ~90MB Chroma DB; entrypoint.sh re-runs ingest
46
+ "rag/extracted/**", # raw extraction transcripts; bot only reads .json
47
+ ".playwright-mcp/**", # Browser snapshots from local Playwright sessions
48
+ "eval/results.json", # Regenerated by eval runs
49
+ "eval/chunk_*.json", # Sweep artifacts
50
+ "kb/calculations/chunk_*", # Sweep markdown
51
  ]
52
 
53