From 77fc735c2f5fb1eae8f92eeb0236919a3e203bb1 Mon Sep 17 00:00:00 2001 From: Jan Kristinus Date: Thu, 3 Sep 2026 12:39:55 +0200 Subject: [PATCH] API-Key bei Ollama an die Platform durchreichen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getPlatform() rief OllamaFactory::create() nur mit der Basis-URL auf, obwohl die Factory den Key als zweites Argument annimmt und daraus einen Authorization-Header mit Bearer-Token baut. Ein extern erreichbarer, per Reverse Proxy abgesicherter Ollama-Server ließ sich damit nicht ansprechen; in der Profil-Oberfläche war das Feld für Ollama zusätzlich ausgeblendet. Ein leerer Key bleibt null, dann sendet die Platform keinen Header -- eine ungesicherte lokale Instanz verhält sich unverändert. --- README.md | 4 ++-- assets/profiles.js | 7 +++++-- lang/de_de.lang | 2 +- lang/en_gb.lang | 2 +- lib/Service.php | 1 + 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index be7f08c..d90a659 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Die **KI Platform** ist das zentrale AddOn fuer die Integration von KI-Diensten | **Google** | `gemini-2.5-flash`, `gemini-2.5-pro` | `text-embedding-004` | `gemini-2.0-flash-exp` | `gemini-2.5-flash`, `gemini-2.5-pro` | | **Ollama** | `llama3.2`, `mistral`, `deepseek-r1` u.a. | `nomic-embed-text`, `mxbai-embed-large` | - | `llava`, `llama3.2-vision` | -Bei Ollama wird kein API-Key benoetigt, nur die Basis-URL (Standard: `http://localhost:11434`). +Bei Ollama ist nur die Basis-URL Pflicht (Standard: `http://localhost:11434`). Der API-Key ist dort optional: bleibt er leer, wird kein `Authorization`-Header gesendet -- gesetzt, geht er als Bearer-Token mit, wie es ein per Reverse Proxy abgesicherter Ollama-Server erwartet. ## Installation @@ -47,7 +47,7 @@ Unter **KI Platform > Profile** werden Profile fuer jeden Anwendungsfall separat | **Profilname** | Eindeutiger Name, z.B. "Claude Text" oder "DALL-E Bilder" | | **Typ** | Text/Code, Embeddings, Bildgenerierung oder Bildverstaendnis | | **Provider** | OpenAI, Anthropic, Google, Ollama oder Replicate | -| **API-Key** | API-Schluessel (wird bei Ollama ausgeblendet) | +| **API-Key** | API-Schluessel; bei Ollama optional (Bearer-Token fuer abgesicherte Server) | | **Basis-URL** | Nur bei Ollama sichtbar (Standard: `http://localhost:11434`) | | **Modell** | Wird automatisch passend zum Provider und Typ vorausgefuellt | diff --git a/assets/profiles.js b/assets/profiles.js index d5c1107..35c4e96 100644 --- a/assets/profiles.js +++ b/assets/profiles.js @@ -23,13 +23,16 @@ $(document).on("rex:ready", function () { // Which provider-specific fields to show/hide // base_url: only Ollama - // api_key: everything except Ollama + // api_key: all providers -- optional for Ollama (empty means no Authorization + // header, as on a local instance), but needed as a bearer token for an Ollama + // server exposed behind a reverse proxy. OllamaFactory::create() takes it as + // its second argument; see Service::getPlatform(). // image_quality, image_style: only OpenAI (DALL-E specific) var providerFields = { openai: { api_key: true, base_url: false, image_quality: true, image_style: true }, anthropic: { api_key: true, base_url: false, image_quality: false, image_style: false }, google: { api_key: true, base_url: false, image_quality: false, image_style: false }, - ollama: { api_key: false, base_url: true, image_quality: false, image_style: false }, + ollama: { api_key: true, base_url: true, image_quality: false, image_style: false }, }; // Default models per provider+type diff --git a/lang/de_de.lang b/lang/de_de.lang index 50aa764..227cfdb 100644 --- a/lang/de_de.lang +++ b/lang/de_de.lang @@ -21,7 +21,7 @@ ai_platform_provider = Provider ai_platform_please_select = --- Bitte waehlen --- ai_platform_default = Standard ai_platform_api_key = API-Key -ai_platform_api_key_notice = Der API-Schluessel des Providers. Bei Ollama nicht erforderlich. +ai_platform_api_key_notice = Der API-Schluessel des Providers. Bei Ollama optional: leer lassen bei einer ungesicherten lokalen Instanz, sonst als Bearer-Token fuer einen abgesicherten Ollama-Server. ai_platform_base_url = Basis-URL ai_platform_base_url_notice = Nur fuer Ollama erforderlich (Standard: http://localhost:11434) ai_platform_model = Modell diff --git a/lang/en_gb.lang b/lang/en_gb.lang index 51390e5..4930b5f 100644 --- a/lang/en_gb.lang +++ b/lang/en_gb.lang @@ -21,7 +21,7 @@ ai_platform_provider = Provider ai_platform_please_select = --- Please select --- ai_platform_default = Default ai_platform_api_key = API Key -ai_platform_api_key_notice = The provider's API key. Not required for Ollama. +ai_platform_api_key_notice = The provider's API key. Optional for Ollama: leave empty for an unsecured local instance, or use it as a bearer token for a secured Ollama server. ai_platform_base_url = Base URL ai_platform_base_url_notice = Only required for Ollama (default: http://localhost:11434) ai_platform_model = Model diff --git a/lib/Service.php b/lib/Service.php index 8dc5d76..814d2bf 100644 --- a/lib/Service.php +++ b/lib/Service.php @@ -187,6 +187,7 @@ public function getPlatform(int $profileId): PlatformInterface 'google' => GeminiFactory::create($profile['api_key']), 'ollama' => OllamaFactory::create( $profile['base_url'] ?: 'http://localhost:11434', + '' !== (string) ($profile['api_key'] ?? '') ? $profile['api_key'] : null, ), default => throw new rex_exception('Unknown AI provider: ' . $profile['provider']), };