From 00837a435eab7026a4a023176e6a90283654c2d0 Mon Sep 17 00:00:00 2001 From: Homelab Cursor Date: Tue, 26 May 2026 11:06:56 +0200 Subject: [PATCH] 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. --- homelab-ai-bot/llm.py | 7 ++++--- homelab-ai-bot/telegram_bot.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/homelab-ai-bot/llm.py b/homelab-ai-bot/llm.py index 17f883594..397d2f98f 100644 --- a/homelab-ai-bot/llm.py +++ b/homelab-ai-bot/llm.py @@ -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: diff --git a/homelab-ai-bot/telegram_bot.py b/homelab-ai-bot/telegram_bot.py index 74f03a502..b8d6540f9 100644 --- a/homelab-ai-bot/telegram_bot.py +++ b/homelab-ai-bot/telegram_bot.py @@ -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")