'gpt-3.5-turbo', 'messages' => [ ['role' => 'system', 'content' => 'You are a helpful assistant.'], ['role' => 'user', 'content' => $myQue] ] ]; $payload = json_encode($data); $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . $openaiKey)); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if ($response === false) { $error = curl_error($ch); // Handle error echo "Error: " . $error; } else { $result = json_decode($response, true); //$result = json_decode($response, true); $reply = $result['choices'][0]['message']['content']; echo '
'.$reply.'
'; //var_dump($reply); } curl_close($ch); } ?>