atlasbot: guard open-ended LLM calls

This commit is contained in:
Brad Stein 2026-01-27 21:09:48 -03:00
parent 34c91c6d08
commit e486245aaf

View File

@ -2530,6 +2530,26 @@ def _open_ended_system() -> str:
) )
def _ollama_call_safe(
hist_key,
prompt: str,
*,
context: str,
fallback: str,
system_override: str | None = None,
) -> str:
try:
return _ollama_call(
hist_key,
prompt,
context=context,
use_history=False,
system_override=system_override,
)
except Exception:
return fallback
def _candidate_note(candidate: dict[str, Any]) -> str: def _candidate_note(candidate: dict[str, Any]) -> str:
claim = str(candidate.get("claim") or candidate.get("summary") or "") claim = str(candidate.get("claim") or candidate.get("summary") or "")
return claim[:160] + ("" if len(claim) > 160 else "") return claim[:160] + ("" if len(claim) > 160 else "")
@ -2569,11 +2589,11 @@ def _open_ended_fast(
f"Question: {prompt}" f"Question: {prompt}"
) )
context = _append_history_context(fact_pack, history_lines) context = _append_history_context(fact_pack, history_lines)
reply = _ollama_call( reply = _ollama_call_safe(
("fast", "open"), ("fast", "open"),
synthesis_prompt, synthesis_prompt,
context=context, context=context,
use_history=False, fallback="I don't have enough data to answer that.",
system_override=_open_ended_system(), system_override=_open_ended_system(),
) )
return _ensure_scores(reply) return _ensure_scores(reply)
@ -2690,11 +2710,11 @@ def _open_ended_deep(
f"Selected: {json.dumps(top, ensure_ascii=False)}" f"Selected: {json.dumps(top, ensure_ascii=False)}"
) )
context = _append_history_context(fact_pack, history_lines) context = _append_history_context(fact_pack, history_lines)
reply = _ollama_call( reply = _ollama_call_safe(
("deep", "open"), ("deep", "open"),
synth_prompt, synth_prompt,
context=context, context=context,
use_history=False, fallback="I don't have enough data to answer that.",
system_override=_open_ended_system(), system_override=_open_ended_system(),
) )
state.update("done", step=6) state.update("done", step=6)