debug: show raw Gemini vision response in Telegram when JSON parse fails
This commit is contained in:
@@ -76,8 +76,14 @@ class GeminiVisionService
|
|||||||
|
|
||||||
$inputTokens = $response->json('usageMetadata.promptTokenCount', 0);
|
$inputTokens = $response->json('usageMetadata.promptTokenCount', 0);
|
||||||
$outputTokens = $response->json('usageMetadata.candidatesTokenCount', 0);
|
$outputTokens = $response->json('usageMetadata.candidatesTokenCount', 0);
|
||||||
$text = $response->json('candidates.0.content.parts.0.text', '');
|
|
||||||
$resultado = $this->parseRespuesta($text);
|
// Collect text from ALL parts (newer models may put JSON in parts[1] if thinking is in parts[0])
|
||||||
|
$parts = $response->json('candidates.0.content.parts', []);
|
||||||
|
$text = implode("\n", array_column(array_filter($parts, fn($p) => isset($p['text'])), 'text'));
|
||||||
|
|
||||||
|
Log::info('[Gemini Vision] raw response: ' . substr($text, 0, 500));
|
||||||
|
|
||||||
|
$resultado = $this->parseRespuesta($text);
|
||||||
|
|
||||||
AiUsageLog::registrar([
|
AiUsageLog::registrar([
|
||||||
'servicio' => 'gemini_vision',
|
'servicio' => 'gemini_vision',
|
||||||
@@ -89,9 +95,14 @@ class GeminiVisionService
|
|||||||
'resultado' => $resultado ? 'ok' : 'error',
|
'resultado' => $resultado ? 'ok' : 'error',
|
||||||
'detalle' => $resultado
|
'detalle' => $resultado
|
||||||
? ['banco' => $resultado['banco'], 'valor' => $resultado['valor']]
|
? ['banco' => $resultado['banco'], 'valor' => $resultado['valor']]
|
||||||
: ['raw' => substr($text, 0, 200), 'modelo' => $this->model],
|
: ['raw' => substr($text, 0, 400), 'modelo' => $this->model],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// If parse failed, return debug info so caller can show it
|
||||||
|
if (! $resultado) {
|
||||||
|
return ['__parse_error' => substr($text, 0, 300)];
|
||||||
|
}
|
||||||
|
|
||||||
return $resultado;
|
return $resultado;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,12 @@ class TelegramBotService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($datosPago['__error'])) {
|
if (isset($datosPago['__error'])) {
|
||||||
$this->send($chatId, "⚠️ Error al analizar el comprobante:\n`" . $datosPago['__error'] . "`");
|
$this->send($chatId, "⚠️ Error de API:\n`" . $datosPago['__error'] . "`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($datosPago['__parse_error'])) {
|
||||||
|
$this->send($chatId, "⚠️ Gemini respondió pero no es JSON válido:\n`" . $datosPago['__parse_error'] . "`");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user