diff --git a/app/Http/Livewire/Chat/ShowConfiguracionChat.php b/app/Http/Livewire/Chat/ShowConfiguracionChat.php index 3443975..58a2581 100755 --- a/app/Http/Livewire/Chat/ShowConfiguracionChat.php +++ b/app/Http/Livewire/Chat/ShowConfiguracionChat.php @@ -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')); diff --git a/resources/views/livewire/chat/show-configuracion-chat.blade.php b/resources/views/livewire/chat/show-configuracion-chat.blade.php index c60d7d6..e8b8d6c 100755 --- a/resources/views/livewire/chat/show-configuracion-chat.blade.php +++ b/resources/views/livewire/chat/show-configuracion-chat.blade.php @@ -82,6 +82,21 @@ class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-emerald-500 outline-none resize-none" placeholder="Ej: Solo vendemos streaming. No ofrecemos juegos."> +
+ + @if($geminiResult) +

+ {{ $geminiResult }} +

+ @endif +