Discutez avec Chat FAFPT !
“gpt-3.5-turbo”, “messages” => [ [“role” => “system”, “content” => $context], [“role” => “user”, “content” => $message] ], “max_tokens” => 100, “temperature” => 0.7 ]; $headers = [ “Content-Type: application/json”, “Authorization: Bearer ” . $openai_token ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $openai_endpoint); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); curl_close($ch); return json_decode($response, true); } if (isset($_POST[‘message’]) && !empty($_POST[‘message’])) { $message = htmlspecialchars($_POST[‘message’]); $response = callOpenAI($message, $openai_token); if ($response && isset($response[‘choices’][0][‘message’][‘content’])) { echo “” . $response[‘choices’][0][‘message’][‘content’] . “
“; } else { echo “Erreur de réponse de l’API.
“; } } ?>