Fix nova-lite JSON: drop response_format, strip markdown fences

nova-lite ignores json_object constraint and returns {} empty; without
it, it wraps output in ```json fences. Strip fences before decodeJsonObject.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-25 10:51:24 +02:00
parent f00d3d68e5
commit 983c423740
+6 -1
View File
@@ -457,7 +457,7 @@ PROMPT;
try {
if ($engine === 'nova_lite') {
$response = dbnToolsCallGpuLlm($messages, ['model' => 'nova-lite', 'json' => true, 'max_tokens' => $maxTokens, 'temperature' => 0.1, 'timeout' => 120]);
$response = dbnToolsCallGpuLlm($messages, ['model' => 'nova-lite', 'max_tokens' => $maxTokens, 'temperature' => 0.1, 'timeout' => 120]);
} elseif ($engine === 'azure_full') {
$response = $this->azure->withDeployment('gpt-4o')->chat($messages, $chatOptions);
} else {
@@ -470,6 +470,11 @@ PROMPT;
$onProgress && $onProgress("Parsing events\u{2026}");
$raw = (string)($response['choices'][0]['message']['content'] ?? '');
if ($engine === 'nova_lite') {
$raw = (string)preg_replace('/^```(?:json)?\s*\n?/m', '', $raw);
$raw = (string)preg_replace('/\n?```\s*$/m', '', $raw);
$raw = trim($raw);
}
$json = $this->azure->decodeJsonObject($raw);
if (!$json) {
dbnToolsAbort('The selected engine did not return valid structured JSON.', 502, 'llm_invalid_json');