feat: add Gemini connection test button in config panel

probarGemini() sends a minimal prompt to gemini-1.5-flash and reports
latency + trimmed response text, or the error message from the API.
Mirrors the existing Whisper test button pattern.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro
2026-07-14 19:35:16 +00:00
co-authored by Claude Sonnet 4.6
parent 30fc8c0f1b
commit 13386f5b49
2 changed files with 53 additions and 0 deletions
@@ -17,6 +17,7 @@ class ShowConfiguracionChat extends Component
public string $mensaje_transferencia = '';
public string $webhookResult = '';
public string $whisperResult = '';
public string $geminiResult = '';
// ── Gemini IA ─────────────────────────────────────────────
public string $gemini_api_key = '';
@@ -86,6 +87,43 @@ class ShowConfiguracionChat extends Component
$this->alert('success', 'Configuracion guardada correctamente.');
}
public function probarGemini(): void
{
$key = trim($this->gemini_api_key ?: \App\Models\ChatConfig::get('gemini_api_key'));
if (! $key) {
$this->geminiResult = '⚠️ La API Key de Gemini está vacía.';
return;
}
$url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent';
try {
$inicio = microtime(true);
$response = Http::timeout(10)
->withHeaders(['Content-Type' => 'application/json'])
->post("{$url}?key={$key}", [
'contents' => [['parts' => [['text' => 'Responde solo "ok"']]]],
'generationConfig' => ['maxOutputTokens' => 5, 'temperature' => 0],
]);
$ms = (int) ((microtime(true) - $inicio) * 1000);
$data = $response->json();
if (! $response->successful() || isset($data['error'])) {
$msg = $data['error']['message'] ?? ('HTTP ' . $response->status());
$this->geminiResult = "❌ Gemini respondió con error: {$msg}";
return;
}
$texto = $data['candidates'][0]['content']['parts'][0]['text'] ?? '(sin texto)';
$this->geminiResult = "✅ Gemini OK ({$ms}ms) — respuesta: \"{$texto}\"";
} catch (\Throwable $e) {
$this->geminiResult = '❌ No se pudo conectar con Gemini: ' . $e->getMessage();
}
}
public function resetearWhisper(): void
{
$url = trim($this->whisper_url ?: ChatConfig::get('whisper_url'));