Fix: strip markdown backticks from OpenAI JSON response

Vorher: preg_match mit Capture-Group schlug fehl wenn ``` am Ende fehlt.
Nachher: zwei preg_replace entfernen öffnendes ```json und schließendes ```
unabhängig voneinander — robuster gegen unvollständige Codeblöcke.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
main
boban 2026-04-19 08:09:44 +02:00
parent 9beb8c15a3
commit 7d50647f39
1 changed files with 4 additions and 4 deletions

View File

@ -677,11 +677,11 @@ PROMPT;
return self::fallback(); return self::fallback();
} }
// Markdown-Codeblocks entfernen (```json ... ``` oder ``` ... ```) // Markdown-Backticks entfernen — auch wenn schließendes ``` fehlt
$cleaned = trim($text); $cleaned = trim($text);
if (preg_match('/```(?:json)?\s*([\s\S]*?)```/', $cleaned, $matches)) { $cleaned = preg_replace('/^```(?:json)?\s*/i', '', $cleaned);
$cleaned = trim($matches[1]); $cleaned = preg_replace('/\s*```$/', '', $cleaned);
} $cleaned = trim($cleaned);
$json = json_decode($cleaned, true); $json = json_decode($cleaned, true);