I have code as below, it works perfect with model gpt-3.5-turbo
but not with gpt-4
:
$your_prompt = "Prompt...."
// GPT-4 API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/chat/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer [API-KEY]';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = json_encode(array('model' => 'gpt-3.5-turbo',
'messages' => array(
array('role' => 'system', 'content' => 'Your system message here'),
array('role' => 'user', 'content' => $your_prompt))));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
echo $result."<br>";
if (curl_errno($ch)) {
echo 'Curl Error:' . curl_error($ch) . "\n<br>";
} else {
echo "API call successful.\n<br>";
echo "API response: \n<br>";
print_r(json_decode($result, true));
echo "\n";
}
curl_close($ch);
$response = json_decode($result, true);
$text = $response['choices'][0]['message']['content'];
echo "OutputGPT" . $text . "\n<br>";
When I'm using gpt-4
I get:
Processing prompt: what is a wether today in Warsaw Poland
{ "error": { "message": "The model: `gpt-4` does not exist", "type": "invalid_request_error", "param": null, "code": "model_not_found" } }
API call successful.
API response:
Array ( [error] => Array ( [message] => The model: `gpt-4` does not exist [type] => invalid_request_error [param] => [code] => model_not_found ) ) OutputGPT
I have tried also with others models like gpt-3.5-turbo-0613
and it works to, but not for gpt-4
as well as for gpt-4-0613
. Nevertheless it should based on https://platform.openai.com/docs/models/gpt-4