fix: веб не падает 500 при недоступном LLM-бэкенде (claude в контейнере)
В контейнере нет CLI claude → ClaudeCliLLM кидал FileNotFoundError → голый HTTP 500. Теперь: ClaudeCliLLM при отсутствии бинаря даёт понятную ошибку; /api/ask и /api/review ловят сбой LLM → HTTP 503 с detail; фронт показывает текст причины вместо «HTTP 500». Тесты +2. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+10
-4
@@ -85,16 +85,22 @@ def create_app(index=None, llm=None, resolver=None,
|
||||
@app.post("/api/ask")
|
||||
def ask(req: AskReq):
|
||||
from rag.agent import answer
|
||||
res = answer(req.query, _lazy_index(app), _lazy_llm(app, req.backend),
|
||||
k=req.k, layer=req.layer)
|
||||
try:
|
||||
res = answer(req.query, _lazy_index(app), _lazy_llm(app, req.backend),
|
||||
k=req.k, layer=req.layer)
|
||||
except Exception as e: # LLM/сервис недоступен → 503 с текстом,
|
||||
raise HTTPException(503, detail=str(e)) # а не голый 500 (UI покажет причину)
|
||||
return {"answer": res.text,
|
||||
"sources": _enrich(res.sources, _lazy_resolver(app))}
|
||||
|
||||
@app.post("/api/review")
|
||||
def review_ep(req: ReviewReq):
|
||||
from rag.agent import review
|
||||
res = review(req.design, _lazy_index(app), _lazy_llm(app, req.backend),
|
||||
k=req.k)
|
||||
try:
|
||||
res = review(req.design, _lazy_index(app), _lazy_llm(app, req.backend),
|
||||
k=req.k)
|
||||
except Exception as e:
|
||||
raise HTTPException(503, detail=str(e))
|
||||
return {"parsed": res.parsed, "raw": res.raw,
|
||||
"violations": res.violations, "safety_warnings": res.safety_warnings,
|
||||
"sources": _enrich(res.sources, _lazy_resolver(app))}
|
||||
|
||||
Reference in New Issue
Block a user