feat: expose LLM error reason in /api/ask response and UI
- Add llm_error field to AskResponse so users know why AI summarisation was skipped - Show orange warning banner in frontend when LLM is not configured or call fails - Update AskEndpoint tests to assert llm_error presence
This commit is contained in:
@@ -272,16 +272,21 @@ async def ask_question(body: AskRequest, user: dict = Depends(require_auth)):
|
||||
events=[],
|
||||
query_info={"entity": entity, "start": start, "end": end, "event_count": 0},
|
||||
llm_used=False,
|
||||
llm_error="LLM not used — no events found." if not LLM_API_KEY else None,
|
||||
)
|
||||
|
||||
# Try LLM summarisation
|
||||
answer = ""
|
||||
llm_used = False
|
||||
if LLM_API_KEY:
|
||||
llm_error = None
|
||||
if not LLM_API_KEY:
|
||||
llm_error = "LLM_API_KEY is not configured. Set it in your .env to enable AI narrative summarisation."
|
||||
else:
|
||||
try:
|
||||
answer = await _call_llm(question, events)
|
||||
llm_used = True
|
||||
except Exception as exc:
|
||||
llm_error = f"LLM call failed: {exc}"
|
||||
logger.warning("LLM call failed, falling back to structured summary", error=str(exc))
|
||||
|
||||
# Fallback: structured summary if LLM unavailable or failed
|
||||
@@ -315,4 +320,5 @@ async def ask_question(body: AskRequest, user: dict = Depends(require_auth)):
|
||||
"mongo_query": json.dumps(query, default=str),
|
||||
},
|
||||
llm_used=llm_used,
|
||||
llm_error=llm_error,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user