debug: add /api/debug/vllm-direct endpoint
Browse files- web/main.py +58 -0
web/main.py
CHANGED
|
@@ -356,6 +356,64 @@ def api_debug_eo():
|
|
| 356 |
return JSONResponse(out)
|
| 357 |
|
| 358 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
@app.get("/api/backend")
|
| 360 |
async def api_backend():
|
| 361 |
"""Live LLM-backend descriptor for the UI's hardware badge.
|
|
|
|
| 356 |
return JSONResponse(out)
|
| 357 |
|
| 358 |
|
| 359 |
+
@app.get("/api/debug/vllm-direct")
|
| 360 |
+
def api_debug_vllm_direct():
|
| 361 |
+
"""Direct diagnostic: calls vLLM with a reconciler-style request,
|
| 362 |
+
bypassing LiteLLM Router, to surface the raw HTTP status and error."""
|
| 363 |
+
import traceback
|
| 364 |
+
import httpx
|
| 365 |
+
|
| 366 |
+
vllm_base = os.environ.get("RIPRAP_LLM_BASE_URL", "").rstrip("/")
|
| 367 |
+
vllm_key = os.environ.get("RIPRAP_LLM_API_KEY", "") or "EMPTY"
|
| 368 |
+
if not vllm_base:
|
| 369 |
+
return JSONResponse({"error": "RIPRAP_LLM_BASE_URL not set"}, status_code=400)
|
| 370 |
+
|
| 371 |
+
# Minimal reconciler-style payload: 2 documents + system + user.
|
| 372 |
+
payload = {
|
| 373 |
+
"model": os.environ.get("RIPRAP_LLM_VLLM_8B_NAME", "granite4.1:3b"),
|
| 374 |
+
"messages": [
|
| 375 |
+
{"role": "system", "content": "You are a flood risk analyst."},
|
| 376 |
+
{"role": "user", "content": "Write the cited paragraph now."},
|
| 377 |
+
],
|
| 378 |
+
"max_tokens": 64,
|
| 379 |
+
"temperature": 0,
|
| 380 |
+
"stream": False,
|
| 381 |
+
"chat_template_kwargs": {
|
| 382 |
+
"documents": [
|
| 383 |
+
{"doc_id": "noaa_tides", "text": "Current tide at Battery Park: 4.14 ft MLLW."},
|
| 384 |
+
{"doc_id": "microtopo", "text": "Elevation 1.37 m, 80th pct 200m radius."},
|
| 385 |
+
]
|
| 386 |
+
},
|
| 387 |
+
"documents": [
|
| 388 |
+
{"doc_id": "noaa_tides", "text": "Current tide at Battery Park: 4.14 ft MLLW."},
|
| 389 |
+
{"doc_id": "microtopo", "text": "Elevation 1.37 m, 80th pct 200m radius."},
|
| 390 |
+
],
|
| 391 |
+
}
|
| 392 |
+
try:
|
| 393 |
+
with httpx.Client(timeout=30.0) as c:
|
| 394 |
+
r = c.post(
|
| 395 |
+
f"{vllm_base}/chat/completions",
|
| 396 |
+
headers={"Authorization": f"Bearer {vllm_key}",
|
| 397 |
+
"Content-Type": "application/json"},
|
| 398 |
+
json=payload,
|
| 399 |
+
)
|
| 400 |
+
try:
|
| 401 |
+
body = r.json()
|
| 402 |
+
except Exception:
|
| 403 |
+
body = r.text[:500]
|
| 404 |
+
return JSONResponse({
|
| 405 |
+
"status": r.status_code,
|
| 406 |
+
"body": body,
|
| 407 |
+
"model_used": payload["model"],
|
| 408 |
+
"vllm_base": vllm_base,
|
| 409 |
+
})
|
| 410 |
+
except Exception as e:
|
| 411 |
+
return JSONResponse({
|
| 412 |
+
"error": str(e),
|
| 413 |
+
"tb": traceback.format_exc().splitlines()[-5:],
|
| 414 |
+
}, status_code=500)
|
| 415 |
+
|
| 416 |
+
|
| 417 |
@app.get("/api/backend")
|
| 418 |
async def api_backend():
|
| 419 |
"""Live LLM-backend descriptor for the UI's hardware badge.
|