new Chat API calls gpt-3.5-turbo
https://openai.com/blog/introducing-chatgpt-and-whisper-apis
https://platform.openai.com/docs/guides/chat
rate 8.6 (out of max 9) Mar 19, 2023 a user
visible when you logged in
comments below more
_php
$ch = curl_init();
$url = 'https://api.openai.com/v1/chat/completions';
$api_key = 'sk-xxxxxxxxxxxxxxxxxxxx';
$query = 'What is the capital city of England?';
$post_fields = array(
"model" => "gpt-3.5-turbo",
"messages" => array(
array(
"role" => "user",
"content" => $query
)
),
"max_tokens" => 12,
"temperature" => 0
);
$header = [
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
}
curl_close($ch);
$response = json_decode($result);
var_dump($response->choices[0]->message->content);
?>
Mar 11, 2023
rated 9 by a user
visible when you logged in
php sample in
https://stackoverflow.com/questions/75614444/openai-chatgpt-gpt-3-5-turbo-api-why-am-i-getting-null-response
while chatgpt could not get it right as the format is new
Mar 11, 2023
rated 9 by a user
visible when you logged in
more like chat now
Mar 11, 2023
rated 9 by a user
visible when you logged in
more comments