<?php
function fetch_chat_gpt_response($message) {
$api_key = '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';
$url = 'https://api.openai.com/v1/engines/davinci-codex/completions';
$headers = array(
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
);
$data = array(
'prompt' => $message,
'max_tokens' => 60
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
$response_data = json_decode($response, true);
return $response_data['choices'][0]['text'];
}
Health AIakchirpy2023-06-16T04:28:06+00:00