1
0
Fork 0
forked from zovos/bot_tg

fix: fall back to secondary LLM when the primary call raises

Primary model errors (HTTP 4xx/5xx, connection failures) raised out of
_call_llm uncaught, skipping the fallback branch entirely — fallback
only ran when the primary returned an empty/"can't answer" string.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
zovos 2026-09-02 11:32:46 +00:00
parent 0cfa67e85f
commit 47ef30800f

View file

@ -614,17 +614,21 @@ async def _call_llm(
) -> str:
disable_thinking = FORCE_DISABLE_THINKING if disable_thinking is None else disable_thinking
result = await _call_single_model(
messages,
api_url=LLAMA_API_URL,
api_key=LLAMA_API_KEY,
model=LLAMA_MODEL,
max_tokens=max_tokens,
temperature=temperature,
top_p=top_p,
disable_thinking=disable_thinking,
reasoning_budget=reasoning_budget,
)
try:
result = await _call_single_model(
messages,
api_url=LLAMA_API_URL,
api_key=LLAMA_API_KEY,
model=LLAMA_MODEL,
max_tokens=max_tokens,
temperature=temperature,
top_p=top_p,
disable_thinking=disable_thinking,
reasoning_budget=reasoning_budget,
)
except Exception:
logger.exception("Primary model call failed")
result = ""
# Если основная модель не смогла ответить — пробуем fallback
if LLAMA_FALLBACK_API_URL and (not result or _CANT_ANSWER_RE.search(result)):