$model, 'messages' => array( array('role' => 'system', 'content' => 'Eres un redactor SEO experto en e-commerce.'), array('role' => 'user', 'content' => $prompt) ), 'temperature' => 0.6, 'max_tokens' => 1200 ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Authorization: Bearer ' . $apiKey )); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); $result = curl_exec($ch); if (curl_errno($ch)) { return "⚠️ Error de conexión: " . curl_error($ch); } $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($http_status !== 200) { return "⚠️ Error HTTP $http_status — el servidor no respondió correctamente."; } $response = json_decode($result, true); if (isset($response['choices'][0]['message']['content'])) { return $response['choices'][0]['message']['content']; } else { return "⚠️ No se pudo generar respuesta. Detalle:\n" . json_encode($response, JSON_PRETTY_PRINT); } } ?>
Generando contenido...