From 3440b8fc5d4045be0aa0116a9a7394dfd3ff9705 Mon Sep 17 00:00:00 2001 From: "info@pi-farm.de" Date: Thu, 5 Mar 2026 20:31:26 +0000 Subject: [PATCH] main.py aktualisiert --- main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 0b23f18..427fc1f 100644 --- a/main.py +++ b/main.py @@ -75,12 +75,20 @@ async def get_ai_response(user_input, system_prompt): try: if AI_PROVIDER == "openai" or AI_PROVIDER == "ollama": - # Für OpenAI / Ollama messages = [{"role": "system", "content": system_prompt}] + chat_history - url = OLLAMA_BASE_URL if AI_PROVIDER == "ollama" else None - key = "ollama" if AI_PROVIDER == "ollama" else OPENAI_API_KEY - model_to_use = OLLAMA_MODEL if AI_PROVIDER == "ollama" else OPENAI_MODEL + # Sicherstellen, dass die URL für Ollama korrekt endet + if AI_PROVIDER == "ollama": + url = OLLAMA_BASE_URL + if not url.endswith('/v1') and not url.endswith('/v1/'): + url = url.rstrip('/') + '/v1' + key = "ollama" + model_to_use = OLLAMA_MODEL + else: + url = None # Benutzt Standard OpenAI URL + key = OPENAI_API_KEY + model_to_use = OPENAI_MODEL + client = openai.OpenAI(base_url=url, api_key=key) response = client.chat.completions.create( model=model_to_use,