fix: corregir pipeline de validación de pagos
- GeminiVisionService: eliminar thinkingConfig (rompe modelos flash), reducir maxOutputTokens 8192→512, timeout 20→40s, default gemini-2.0-flash - PublicChat: detectar correctamente errores de Gemini (__error/__parse_error) que antes pasaban el guard if(!$datosPago) por ser arrays truthy - PagoValidadorService: tolerancia de hora 0→3 min, remitente >=2→>=1 palabra - CorreoImapService: break→continue en correos fuera de ventana (IMAP no garantiza orden cronológico), fetchSize *4→*2 para evitar timeout Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
fc17e57624
commit
d88f67ab5b
@@ -23,6 +23,7 @@ use App\Models\Tarifas;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -563,8 +564,10 @@ class PublicChat extends Component
|
||||
|
||||
$datosPago = app(\App\Services\GeminiVisionService::class)->extraerPago($base64, $mimeType);
|
||||
|
||||
if (! $datosPago) {
|
||||
$this->guardarMensajeBot($this->convId, "No pude leer el comprobante. Intenta con una foto mas clara.");
|
||||
if (! $datosPago || isset($datosPago['__error']) || isset($datosPago['__parse_error'])) {
|
||||
$detalle = $datosPago['__error'] ?? ($datosPago['__parse_error'] ?? '');
|
||||
Log::warning('[PublicChat] Gemini error: ' . $detalle);
|
||||
$this->guardarMensajeBot($this->convId, "No pude leer el comprobante. Intenta con una foto mas clara o con mejor iluminación.");
|
||||
$this->cargarMensajes();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class CorreoImapService
|
||||
}
|
||||
|
||||
// Descargar un lote suficiente para cubrir la ventana de tiempo.
|
||||
$fetchSize = min($total, max($limit * 4, 20));
|
||||
$fetchSize = min($total, max($limit * 2, 20));
|
||||
$from = max(1, $total - $fetchSize + 1);
|
||||
$set = "{$from}:{$total}";
|
||||
|
||||
@@ -67,9 +67,9 @@ class CorreoImapService
|
||||
foreach ($emails as $email) {
|
||||
$ts = $email['date'] ? @strtotime($email['date']) : false;
|
||||
|
||||
// Correo más antiguo que la ventana → parar
|
||||
// Correo más antiguo que la ventana → saltar (no parar, pueden haber más nuevos)
|
||||
if ($ts !== false && $ts < $cutoff) {
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = $email;
|
||||
|
||||
@@ -15,7 +15,7 @@ class GeminiVisionService
|
||||
public function __construct()
|
||||
{
|
||||
$this->apiKey = ChatConfig::get('gemini_api_key', '');
|
||||
$this->model = ChatConfig::get('gemini_model', 'gemini-3.5-flash');
|
||||
$this->model = ChatConfig::get('gemini_model', 'gemini-2.0-flash');
|
||||
}
|
||||
|
||||
public function extraerPago(string $base64, string $mimeType, ?int $usuarioId = null, string $canal = 'telegram'): ?array
|
||||
@@ -36,8 +36,7 @@ class GeminiVisionService
|
||||
'contents' => $contents,
|
||||
'generationConfig' => [
|
||||
'temperature' => 0.1,
|
||||
'maxOutputTokens' => 8192,
|
||||
'thinkingConfig' => ['thinkingBudget' => 0],
|
||||
'maxOutputTokens' => 512,
|
||||
],
|
||||
];
|
||||
|
||||
@@ -49,7 +48,7 @@ class GeminiVisionService
|
||||
$url = "https://generativelanguage.googleapis.com/{$ver}/models/{$this->model}:generateContent";
|
||||
try {
|
||||
$resp = Http::withHeaders(['Content-Type' => 'application/json'])
|
||||
->timeout(20)
|
||||
->timeout(40)
|
||||
->post("{$url}?key={$this->apiKey}", $body);
|
||||
|
||||
if ($resp->successful()) {
|
||||
|
||||
@@ -122,7 +122,7 @@ class PagoValidadorService
|
||||
|
||||
// ── 3. Hora exacta ───────────────────────────────────────
|
||||
if ($horaIA && ($datosCorreo['hora'] ?? '')) {
|
||||
if (! $this->horaProxima($horaIA, $datosCorreo['hora'], 0)) {
|
||||
if (! $this->horaProxima($horaIA, $datosCorreo['hora'], 3)) {
|
||||
Log::info("[PagoValidador] Correo #{$i}: hora no coincide (ia={$horaIA} correo={$datosCorreo['hora']})");
|
||||
continue;
|
||||
}
|
||||
@@ -265,6 +265,6 @@ class PagoValidadorService
|
||||
$coincidencias++;
|
||||
}
|
||||
}
|
||||
return $coincidencias >= 2;
|
||||
return $coincidencias >= 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user