From 81f7bbff9055da8e032c0275c0f6c5dcb4231bae Mon Sep 17 00:00:00 2001 From: Homelab Cursor Date: Sat, 21 Mar 2026 02:13:38 +0100 Subject: [PATCH] bot: Passthrough fuer vorformatierte Tool-Ergebnisse Temperaturen/Energie/Heizung-Ausgaben werden direkt an den User weitergeleitet, ohne nochmal durch die LLM zu gehen. Behebt Umlaut-Verlust und Formatierungs-Aenderungen durch LLM. --- homelab-ai-bot/llm.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/homelab-ai-bot/llm.py b/homelab-ai-bot/llm.py index 0c460d48..3801affd 100644 --- a/homelab-ai-bot/llm.py +++ b/homelab-ai-bot/llm.py @@ -24,6 +24,8 @@ FALLBACK_MODEL = "qwen3:30b-a3b" MAX_TOOL_ROUNDS = 3 OLLAMA_MODELS = {VISION_MODEL, FALLBACK_MODEL} +PASSTHROUGH_TOOLS = {"get_temperaturen", "get_energie", "get_heizung"} + import datetime as _dt _TODAY = _dt.date.today() _3M_AGO = (_TODAY - _dt.timedelta(days=90)) @@ -338,6 +340,8 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None) - messages.append({"role": "user", "content": question}) + passthrough_result = None + try: for _round in range(MAX_TOOL_ROUNDS): data = _call_openrouter(messages, api_key, use_tools=True) @@ -347,6 +351,8 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None) - tool_calls = msg.get("tool_calls") if not tool_calls: content = msg.get("content") or "" + if passthrough_result: + return passthrough_result return content or "Keine Antwort vom LLM." messages.append(msg) @@ -368,12 +374,20 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None) - else: result = f"Unbekanntes Tool: {fn_name}" + result_str = str(result)[:3000] + + if fn_name in PASSTHROUGH_TOOLS and not result_str.startswith(("Fehler", "Keine")): + log.info("Passthrough-Tool %s: Ergebnis wird direkt weitergegeben", fn_name) + passthrough_result = result_str + messages.append({ "role": "tool", "tool_call_id": tc["id"], - "content": str(result)[:3000], + "content": result_str, }) + if passthrough_result: + return passthrough_result data = _call_openrouter(messages, api_key, use_tools=False) return data["choices"][0]["message"]["content"]