Fix: Handle multiple description candidates from Gemini
This commit is contained in:
parent
76045d30da
commit
023b08eea2
1 changed files with 13 additions and 2 deletions
|
|
@ -74,7 +74,17 @@ $log = implode("\n", $out_lines);
|
||||||
$gfile = dirname($jobdir) . '/' . basename($jobdir) . '.json';
|
$gfile = dirname($jobdir) . '/' . basename($jobdir) . '.json';
|
||||||
if (is_file($gfile)) {
|
if (is_file($gfile)) {
|
||||||
$raw = @file_get_contents($gfile);
|
$raw = @file_get_contents($gfile);
|
||||||
$json = @json_decode($raw, true);
|
$json_data = @json_decode($raw, true);
|
||||||
|
|
||||||
|
// Handle case where Gemini returns an array of candidates or a single object.
|
||||||
|
// We will always take the first valid description object we can find.
|
||||||
|
$json = null;
|
||||||
|
if (is_array($json_data) && isset($json_data[0]) && is_array($json_data[0])) {
|
||||||
|
$json = $json_data[0]; // It's an array of descriptions, take the first.
|
||||||
|
} elseif (is_array($json_data)) {
|
||||||
|
$json = $json_data; // It's already a single description object.
|
||||||
|
}
|
||||||
|
|
||||||
$description = '';
|
$description = '';
|
||||||
$teaser = '';
|
$teaser = '';
|
||||||
$tags = [];
|
$tags = [];
|
||||||
|
|
@ -83,12 +93,13 @@ if (is_file($gfile)) {
|
||||||
$teaser = isset($json['teaser']) ? (string)$json['teaser'] : '';
|
$teaser = isset($json['teaser']) ? (string)$json['teaser'] : '';
|
||||||
$tags = isset($json['tags']) && is_array($json['tags']) ? $json['tags'] : [];
|
$tags = isset($json['tags']) && is_array($json['tags']) ? $json['tags'] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'status' => 'ok',
|
'status' => 'ok',
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'teaser' => $teaser,
|
'teaser' => $teaser,
|
||||||
'tags' => $tags,
|
'tags' => $tags,
|
||||||
'raw_json' => $json,
|
'raw_json' => $json_data, // Send original raw data back for reference
|
||||||
'log' => $log,
|
'log' => $log,
|
||||||
'rc' => $rc,
|
'rc' => $rc,
|
||||||
], JSON_UNESCAPED_UNICODE);
|
], JSON_UNESCAPED_UNICODE);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue