Есть функция API скрипт chatGPT но он утсарел , нужно более новую версию преписать
function chatGP($message){
// Your OpenAI API Key
$apiKey = "
// The endpoint for the OpenAI Davinci API
$endpoint = "https://api.openai.com/v1/completions";
// The request body, containing the parameters for your request
$requestBody = [
"model" => "text-davinci-003",
"prompt" => "$message",
"temperature" => 0.1,
"max_tokens" => 500,
"top_p" => 1,
"frequency_penalty" => 0.0,
"presence_penalty" => 0.0
];
// Encode the request body as JSON
$requestBodyJson = json_encode($requestBody);
// Initialize the cURL session
$curl = curl_init();
// Set the cURL options
curl_setopt($curl, CURLOPT_URL, $endpoint);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Authorization: Bearer " . $apiKey
]);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBodyJson);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Make the request
$response = curl_exec($curl);
// Check for errors
if (curl_errno($curl)) {
echo "cURL Error: " . curl_error($curl);
exit;
}
Что бы вывдвал ответ при отправке запроса