debug: add /api/debug/vllm-direct endpoint
Browse files355 unmodified lines356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419355 unmodified lines return JSONResponse(out)
@app.get("/api/debug/vllm-direct")def api_debug_vllm_direct(): """Direct diagnostic: calls vLLM with a reconciler-style request, bypassing LiteLLM Router, to surface the raw HTTP status and error.""" import traceback import httpx
vllm_base = os.environ.get("RIPRAP_LLM_BASE_URL", "").rstrip("/") vllm_key = os.environ.get("RIPRAP_LLM_API_KEY", "") or "EMPTY" if not vllm_base: return JSONResponse({"error": "RIPRAP_LLM_BASE_URL not set"}, status_code=400)
# Minimal reconciler-style payload: 2 documents + system + user. payload = { "model": os.environ.get("RIPRAP_LLM_VLLM_8B_NAME", "granite4.1:3b"), "messages": [ {"role": "system", "content": "You are a flood risk analyst."}, {"role": "user", "content": "Write the cited paragraph now."}, ], "max_tokens": 64, "temperature": 0, "stream": False, "chat_template_kwargs": { "documents": [ {"doc_id": "noaa_tides", "text": "Current tide at Battery Park: 4.14 ft MLLW."}, {"doc_id": "microtopo", "text": "Elevation 1.37 m, 80th pct 200m radius."}, ] }, "documents": [ {"doc_id": "noaa_tides", "text": "Current tide at Battery Park: 4.14 ft MLLW."}, {"doc_id": "microtopo", "text": "Elevation 1.37 m, 80th pct 200m radius."}, ], } try: with httpx.Client(timeout=30.0) as c: r = c.post( f"{vllm_base}/chat/completions", headers={"Authorization": f"Bearer {vllm_key}", "Content-Type": "application/json"}, json=payload, ) try: body = r.json() except Exception: body = r.text[:500] return JSONResponse({ "status": r.status_code, "body": body, "model_used": payload["model"], "vllm_base": vllm_base, }) except Exception as e: return JSONResponse({ "error": str(e), "tb": traceback.format_exc().splitlines()[-5:], }, status_code=500)
@app.get("/api/backend")async def api_backend(): """Live LLM-backend descriptor for the UI's hardware badge.web/main.py+58