From 59de3e3a49089777780010ca34942aa79eed4b9e Mon Sep 17 00:00:00 2001 From: Cursor Date: Sat, 21 Mar 2026 00:16:41 +0100 Subject: [PATCH] fix(bot): bei Bild+Preisfrage erzwinge web_search statt Bild-Extraktion, max_tokens 4000 --- homelab-ai-bot/llm.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/homelab-ai-bot/llm.py b/homelab-ai-bot/llm.py index 5cb826a1..338e43da 100644 --- a/homelab-ai-bot/llm.py +++ b/homelab-ai-bot/llm.py @@ -355,6 +355,19 @@ def ask_with_image(image_base64: str, caption: str, tool_handlers: dict, session "Wenn es ein normales Bild ist: Beschreibe strukturiert was du siehst." ) prompt_text = caption if caption else default_prompt + + _price_kw = ["preis", "kostet", "kosten", "price", "teuer", "guenstig", "billig", + "bestpreis", "angebot", "euro", "eur", "kaufen"] + _is_price_q = any(kw in (caption or "").lower() for kw in _price_kw) + if _is_price_q: + prompt_text = ( + "WICHTIG: Der User fragt nach einem aktuellen Preis. " + "Du MUSST zuerst web_search aufrufen um den aktuellen Marktpreis zu ermitteln. " + "Nutze das Bild nur als Kontext, NICHT als Preisquelle — Bilder koennen veraltet sein. " + "Erst NACH der web_search darfst du antworten.\n\n" + + prompt_text + ) + user_content = [ {"type": "text", "text": prompt_text}, {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_base64}", "detail": "high"}}, @@ -384,7 +397,7 @@ def ask_with_image(image_base64: str, caption: str, tool_handlers: dict, session try: for _round in range(MAX_TOOL_ROUNDS): data = _call_openrouter(messages, api_key, use_tools=True, - model=VISION_MODEL, max_tokens=1200) + model=VISION_MODEL, max_tokens=4000) choice = data["choices"][0] msg = choice["message"] @@ -418,7 +431,7 @@ def ask_with_image(image_base64: str, caption: str, tool_handlers: dict, session }) data = _call_openrouter(messages, api_key, use_tools=False, - model=VISION_MODEL, max_tokens=1200) + model=VISION_MODEL, max_tokens=4000) return data["choices"][0]["message"]["content"] except Exception as e: