Hi,
Asking to chatgpt it recommended to use this API endpoint for chatting purposes:
https://api.openai.com/v1/engines/davinci/versions/latest/chat
I didn’t find any information about it, but exists, got this answer:
{
"error": {
"message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://beta.openai.com.",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Tried to connect using PHP in this way, get, post, with or without headers, with or without data, but just get an empty string or bool(true)
$headers = [
'Authorization' => 'Bearer ' . 'sk-A_KEY',
'Content-Type' => 'application/json',
];
$data = [
'prompt' => "hola qué tal?",
'max_tokens' => 100,
'temperature' => 0.7
//'top_p' => (float)env('GPT_TOP_P'),
//'n' => (int)env('GPT_N'),
];
$url='https://api.openai.com/v1/engines/davinci/versions/latest/chat';
$response = sendPostRequest($url, $headers, $data);
var_dump($response);
function sendPostRequest($url, $headers, $data) {
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'OPTIONS');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute cURL request and get response
$response = curl_exec($ch);
// Close cURL session
curl_close($ch);
return $response;
}
Any idea about how to connect to that?
And if you know a working approach to try to chat, please share.
Thanks
Jose