Iniciando Gerador...
Isso pode levar alguns segundos.
[["parts" => [["text" => $prompt]]]], "generationConfig" => [ "responseMimeType" => "application/json" ] ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Evita erros de SSL em alguns servidores WP $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode !== 200) { $errData = json_decode($response, true); $errMsg = $errData['error']['message'] ?? "Erro na API do Google (Código $httpCode)"; throw new Exception($errMsg); } // 6. Processa resposta $apiRes = json_decode($response, true); $rawText = $apiRes['candidates'][0]['content']['parts'][0]['text'] ?? ''; // Limpeza de segurança $cleanJson = trim($rawText); $cleanJson = str_replace(['```json', '```'], '', $cleanJson); ob_clean(); echo $cleanJson; } catch (Exception $e) { ob_clean(); http_response_code(400); echo json_encode([ 'error' => true, 'message' => $e->getMessage() ]); } exit; ?>