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:
@@ -457,7 +457,7 @@ PROMPT;
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if ($engine === 'nova_lite') {
|
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') {
|
} elseif ($engine === 'azure_full') {
|
||||||
$response = $this->azure->withDeployment('gpt-4o')->chat($messages, $chatOptions);
|
$response = $this->azure->withDeployment('gpt-4o')->chat($messages, $chatOptions);
|
||||||
} else {
|
} else {
|
||||||
@@ -470,6 +470,11 @@ PROMPT;
|
|||||||
$onProgress && $onProgress("Parsing events\u{2026}");
|
$onProgress && $onProgress("Parsing events\u{2026}");
|
||||||
|
|
||||||
$raw = (string)($response['choices'][0]['message']['content'] ?? '');
|
$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);
|
$json = $this->azure->decodeJsonObject($raw);
|
||||||
if (!$json) {
|
if (!$json) {
|
||||||
dbnToolsAbort('The selected engine did not return valid structured JSON.', 502, 'llm_invalid_json');
|
dbnToolsAbort('The selected engine did not return valid structured JSON.', 502, 'llm_invalid_json');
|
||||||
|
|||||||
Reference in New Issue
Block a user