From caa2883a66b3776da8484dca75f32c3bdf1be6c1 Mon Sep 17 00:00:00 2001 From: orbitalo Date: Fri, 27 Mar 2026 12:36:38 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20Ollama=20native=20API=20nutzen=20statt?= =?UTF-8?q?=20OpenAI-compat=20f=C3=BCr=20Enricher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Qwen3 via /v1/chat/completions verbraucht max_tokens fürs Reasoning und liefert leeren Content. Umstellung auf /api/chat mit think=false löst das Problem. --- homelab-ai-bot/savetv_enrich.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/homelab-ai-bot/savetv_enrich.py b/homelab-ai-bot/savetv_enrich.py index 06e31293..5a37103f 100644 --- a/homelab-ai-bot/savetv_enrich.py +++ b/homelab-ai-bot/savetv_enrich.py @@ -58,25 +58,28 @@ def _is_enriched(entry: dict) -> bool: def _call_ollama(prompt: str, model: str = MODEL) -> str: + """Ruft Ollama via native /api/chat auf (kein OpenAI-compat).""" payload = { "model": model, "messages": [ {"role": "system", "content": ( "Du bist eine Filmdatenbank. Antworte NUR mit validem JSON, " - "kein Markdown, keine Erklärungen. /no_think" + "kein Markdown, keine Erklärungen." )}, - {"role": "user", "content": prompt + " /no_think"}, + {"role": "user", "content": prompt}, ], - "max_tokens": 800, "stream": False, + "think": False, + "options": {"num_predict": 1024}, } try: r = requests.post( - f"{OLLAMA_BASE}/v1/chat/completions", - json=payload, timeout=120, + f"{OLLAMA_BASE}/api/chat", + json=payload, timeout=180, ) r.raise_for_status() - text = r.json()["choices"][0]["message"]["content"].strip() + data = r.json() + text = data.get("message", {}).get("content", "").strip() if text.startswith("```"): text = re.sub(r"^```\w*\n?", "", text) text = re.sub(r"\n?```$", "", text)