blessingmwiti commited on
Commit
ea20131
·
1 Parent(s): d4e1d86

Fix verifier async endpoint handling

Browse files
Files changed (4) hide show
  1. app.py +13 -7
  2. modal_backend/verifier.py +5 -6
  3. static/style.css +2 -1
  4. static/ui.js +1 -0
app.py CHANGED
@@ -193,6 +193,9 @@ window.applyVerification = function(verdictJson) {{
193
  if (verdict.verdict === "PASS") {{
194
  setVerifierStatus("PASS");
195
  setStatus("Verified clean", "success");
 
 
 
196
  }} else {{
197
  verdict.corrected_code = cleanGeneratedCode(verdict.corrected_code || "");
198
  rollbackAndReplace(verdict.corrected_code, verdict.reason || "Verifier supplied a correction", verdict.verdict);
@@ -214,13 +217,16 @@ async def verify_with_modal(prompt: str, draft_code: str, language: str) -> str:
214
  }
215
  )
216
 
217
- async with httpx.AsyncClient(timeout=90.0) as client:
218
- response = await client.post(
219
- verifier_url,
220
- json={"prompt": prompt, "draft_code": draft_code, "language": language.lower()},
221
- )
222
- response.raise_for_status()
223
- return response.text
 
 
 
224
 
225
 
226
  async def execute_in_sandbox(code: str) -> dict:
 
193
  if (verdict.verdict === "PASS") {{
194
  setVerifierStatus("PASS");
195
  setStatus("Verified clean", "success");
196
+ }} else if (verdict.verdict === "ERROR") {{
197
+ setVerifierStatus("ERROR");
198
+ setStatus(`Verifier failed: ${{verdict.reason || "unknown error"}}`, "warning");
199
  }} else {{
200
  verdict.corrected_code = cleanGeneratedCode(verdict.corrected_code || "");
201
  rollbackAndReplace(verdict.corrected_code, verdict.reason || "Verifier supplied a correction", verdict.verdict);
 
217
  }
218
  )
219
 
220
+ try:
221
+ async with httpx.AsyncClient(timeout=180.0) as client:
222
+ response = await client.post(
223
+ verifier_url,
224
+ json={"prompt": prompt, "draft_code": draft_code, "language": language.lower()},
225
+ )
226
+ response.raise_for_status()
227
+ return response.text
228
+ except Exception as exc:
229
+ return json.dumps({"verdict": "ERROR", "reason": str(exc)})
230
 
231
 
232
  async def execute_in_sandbox(code: str) -> dict:
modal_backend/verifier.py CHANGED
@@ -97,14 +97,13 @@ Respond ONLY with valid JSON. No markdown, no explanation outside the JSON."""
97
  return parsed
98
 
99
 
100
- web_image = llama_image
 
 
101
 
102
 
103
  @app.function(
104
- image=web_image,
105
- gpu="A10G",
106
- volumes={MODEL_DIR: model_volume},
107
- scaledown_window=300,
108
  )
109
  @modal.asgi_app()
110
  def verifier_endpoint():
@@ -127,7 +126,7 @@ def verifier_endpoint():
127
 
128
  @web_app.post("/verify")
129
  async def verify(req: VerifyRequest):
130
- return Verifier().verify.remote(req.prompt, req.draft_code, req.language)
131
 
132
  @web_app.get("/health")
133
  async def health():
 
97
  return parsed
98
 
99
 
100
+ api_image = modal.Image.debian_slim(python_version="3.11").pip_install(
101
+ "fastapi", "uvicorn", "pydantic"
102
+ )
103
 
104
 
105
  @app.function(
106
+ image=api_image,
 
 
 
107
  )
108
  @modal.asgi_app()
109
  def verifier_endpoint():
 
126
 
127
  @web_app.post("/verify")
128
  async def verify(req: VerifyRequest):
129
+ return await Verifier().verify.remote.aio(req.prompt, req.draft_code, req.language)
130
 
131
  @web_app.get("/health")
132
  async def health():
static/style.css CHANGED
@@ -175,7 +175,8 @@ footer {
175
 
176
  .status-warning,
177
  .verdict-fix,
178
- .verdict-rewrite {
 
179
  color: var(--accent-warn);
180
  }
181
 
 
175
 
176
  .status-warning,
177
  .verdict-fix,
178
+ .verdict-rewrite,
179
+ .verdict-error {
180
  color: var(--accent-warn);
181
  }
182
 
static/ui.js CHANGED
@@ -29,6 +29,7 @@ export function setVerifierStatus(verdict) {
29
  PASS: "Verified",
30
  FIX: "Fixed",
31
  REWRITE: "Rewritten",
 
32
  CHECKING: "Verifying...",
33
  };
34
  el.textContent = labels[verdict] || "";
 
29
  PASS: "Verified",
30
  FIX: "Fixed",
31
  REWRITE: "Rewritten",
32
+ ERROR: "Verifier error",
33
  CHECKING: "Verifying...",
34
  };
35
  el.textContent = labels[verdict] || "";