fix(bot): Systemvorhersage bei OpenRouter-404 nicht als Erfolg senden
Fallback auf gpt-4o-mini wenn grok fehlschlaegt; klare Fehlermeldung statt rohem LLM-Fehler-String in Telegram.
This commit is contained in:
parent
4829b012a7
commit
00837a435e
2 changed files with 26 additions and 3 deletions
|
|
@ -341,7 +341,7 @@ def ask(question: str, context: str) -> str:
|
|||
return f"LLM-Fehler: {e}"
|
||||
|
||||
|
||||
def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None, document_mode: bool = False) -> str:
|
||||
def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None, document_mode: bool = False, model_override: str = None) -> str:
|
||||
"""Freitext-Frage mit automatischem Routing und Tool-Calling.
|
||||
|
||||
Routing:
|
||||
|
|
@ -573,11 +573,12 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None, d
|
|||
return f"Online-Suche Fehler: {e}"
|
||||
|
||||
# --- Lokal: Tool-Calling mit allen Tools ---
|
||||
local_model = model_override or MODEL_LOCAL
|
||||
passthrough_result = None
|
||||
|
||||
try:
|
||||
for _round in range(MAX_TOOL_ROUNDS):
|
||||
data = _call_api(messages, api_key, use_tools=True, model=MODEL_LOCAL)
|
||||
data = _call_api(messages, api_key, use_tools=True, model=local_model)
|
||||
choice = data["choices"][0]
|
||||
msg = choice["message"]
|
||||
|
||||
|
|
@ -623,7 +624,7 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None, d
|
|||
|
||||
if passthrough_result:
|
||||
return passthrough_result
|
||||
data = _call_api(messages, api_key, use_tools=False, model=MODEL_LOCAL)
|
||||
data = _call_api(messages, api_key, use_tools=False, model=local_model)
|
||||
return data["choices"][0]["message"]["content"]
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -1016,6 +1016,28 @@ async def _send_daily_forecast(job_context):
|
|||
session_id=None,
|
||||
document_mode=False,
|
||||
)
|
||||
if (analysis or "").startswith(("LLM-Fehler:", "Vision-LLM-Fehler:")):
|
||||
log.error("Systemvorhersage LLM-Fehler: %s", analysis[:200])
|
||||
analysis = await asyncio.to_thread(
|
||||
llm.ask_with_tools,
|
||||
prompt,
|
||||
handlers,
|
||||
session_id=None,
|
||||
document_mode=False,
|
||||
model_override=llm.MODEL_VISION,
|
||||
)
|
||||
if (analysis or "").startswith(("LLM-Fehler:", "Vision-LLM-Fehler:")):
|
||||
await bot.send_message(
|
||||
chat_id=CHAT_ID,
|
||||
text=(
|
||||
"🔭 *Taegliche Systemvorhersage*\n\n"
|
||||
"⚠️ Analyse fehlgeschlagen (OpenRouter). "
|
||||
"Bitte spaeter erneut versuchen."
|
||||
),
|
||||
parse_mode="Markdown",
|
||||
)
|
||||
log.error("Systemvorhersage endgueltig fehlgeschlagen: %s", analysis[:200])
|
||||
return
|
||||
msg = "🔭 *Taegliche Systemvorhersage*\n\n" + analysis
|
||||
await bot.send_message(chat_id=CHAT_ID, text=msg, parse_mode="Markdown")
|
||||
log.info("Taegl. Systemvorhersage gesendet")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue