Fix #55: Ollama-Erreichbarkeit aktiv prüfen, Fehler ins PHP-Log schreiben

This commit is contained in:
fds2610-bot 2026-04-26 13:07:04 +02:00
parent 491f5c6dc5
commit 02463e40d4
3 changed files with 43 additions and 7 deletions

View file

@ -2,6 +2,14 @@
--- ---
## 2026-04-26 – KI-Diagnose: Erreichbarkeitsprüfung und Fehlerlog für Ollama
### Geändert
- `src/Services/LlmService.php`: Neue Methode `isReachable()` für Diagnosezwecke; Fehlerlog in `callOllama()` bei cURL-Fehler oder leerer Antwort
- `src/Views/settings/form.php`: Einstellungsseite prüft jetzt aktiv, ob der Ollama-Server erreichbar ist (nicht nur ob er konfiguriert ist); zeigt bei Verbindungsfehler einen konkreten Hinweis auf `OLLAMA_HOST=0.0.0.0:11434`
---
## 2026-04-26 – Leistungszeitraum als freies Textfeld ## 2026-04-26 – Leistungszeitraum als freies Textfeld
### Geändert ### Geändert

View file

@ -93,6 +93,17 @@ class LlmService
return $data['message']['content'] ?? ''; return $data['message']['content'] ?? '';
} }
/**
* Prüft ohne Timeout-Kosten, ob der Provider überhaupt erreichbar ist.
* Nur für Diagnosezwecke (Einstellungsseite) – nicht im normalen Request-Pfad nutzen.
*/
public function isReachable(): bool
{
if ($this->mode === null) return false;
if ($this->mode === 'ollama') return $this->probeOllama($this->url);
return true; // OpenAI-Modus: kein schneller Probe verfügbar
}
private function detect(): void private function detect(): void
{ {
$ollamaUrl = getenv('OLLAMA_URL') ?: ($_ENV['OLLAMA_URL'] ?? ''); $ollamaUrl = getenv('OLLAMA_URL') ?: ($_ENV['OLLAMA_URL'] ?? '');
@ -147,7 +158,8 @@ class LlmService
'stream' => false, 'stream' => false,
]; ];
$ch = curl_init($this->url . '/api/generate'); $endpoint = $this->url . '/api/generate';
$ch = curl_init($endpoint);
curl_setopt_array($ch, [ curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
@ -157,9 +169,17 @@ class LlmService
]); ]);
$response = curl_exec($ch); $response = curl_exec($ch);
$err = curl_error($ch); $err = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch); curl_close($ch);
if ($err || !$response) return ''; if ($err) {
error_log("[Steuerkram] LlmService::callOllama() cURL-Fehler auf {$endpoint}: {$err}");
return '';
}
if (!$response) {
error_log("[Steuerkram] LlmService::callOllama() leere Antwort von {$endpoint} (HTTP {$httpCode})");
return '';
}
return json_decode($response, true)['response'] ?? ''; return json_decode($response, true)['response'] ?? '';
} }

View file

@ -142,12 +142,20 @@
<?php <?php
$llm = new \Steuerkram\Services\LlmService(); $llm = new \Steuerkram\Services\LlmService();
$providerLabel = $llm->getProviderLabel(); $providerLabel = $llm->getProviderLabel();
$reachable = $providerLabel !== null ? $llm->isReachable() : false;
$ollamaUrlEnv = getenv('OLLAMA_URL') ?: ($_ENV['OLLAMA_URL'] ?? '');
?> ?>
<p class="text-sm" style="margin:0 0 0 1.75rem;color:<?= $providerLabel ? 'var(--color-success,#16a34a)' : 'var(--color-muted,#6b7280)' ?>"> <p class="text-sm" style="margin:0 0 0 1.75rem;color:<?= $reachable ? 'var(--color-success,#16a34a)' : '#dc2626' ?>">
<?php if ($providerLabel): ?> <?php if ($reachable): ?>
✓ Provider erkannt: <?= $h($providerLabel) ?> ✓ Provider erreichbar: <?= $h($providerLabel) ?>
<?php elseif ($providerLabel): ?>
✗ Provider konfiguriert (<?= $h($providerLabel) ?>), aber Server nicht erreichbar.
Prüfe ob Ollama auf dem Host läuft und auf allen Interfaces hört (<code>OLLAMA_HOST=0.0.0.0:11434</code>).
Details im PHP-Fehlerlog des Webservers (<code>docker compose logs web</code>).
<?php elseif ($ollamaUrlEnv !== ''): ?>
✗ OLLAMA_URL gesetzt (<?= $h(rtrim($ollamaUrlEnv, '/')) ?>), aber kein Provider erkannt.
<?php else: ?> <?php else: ?>
— Kein LLM-Provider konfiguriert oder erreichbar (Auto-Discovery localhost:11434 fehlgeschlagen) — Kein LLM-Provider konfiguriert (Auto-Discovery localhost:11434 fehlgeschlagen)
<?php endif; ?> <?php endif; ?>
</p> </p>
</div> </div>