I am attempting to interact with the OpenAI API, but I’m facing issues specifically related to GPT-4. While my code executes perfectly with the gpt-3.5-turbo model, I encounter problems when I attempt to implement the GPT-4 models.
$input_text = "Can you tell me about dogs?";
// Set up cURL for making a request to OpenAI
$curl_instance = curl_init();
curl_setopt($curl_instance, CURLOPT_URL, 'https://api.openai.com/v1/chat/completions');
curl_setopt($curl_instance, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_instance, CURLOPT_POST, true);
$request_headers = array();
$request_headers[] = 'Content-Type: application/json';
$request_headers[] = 'Authorization: Bearer [YOUR-API-KEY]';
curl_setopt($curl_instance, CURLOPT_HTTPHEADER, $request_headers);
$request_payload = json_encode(array(
'model' => 'gpt-4',
'messages' => array(
array('role' => 'system', 'content' => 'You are a knowledgeable assistant'),
array('role' => 'user', 'content' => $input_text)
)
));
curl_setopt($curl_instance, CURLOPT_POSTFIELDS, $request_payload);
$response_data = curl_exec($curl_instance);
echo $response_data . "<br>";
if (curl_errno($curl_instance)) {
echo 'cURL Error: ' . curl_error($curl_instance) . "<br>";
} else {
echo "Successfully completed the request<br>";
echo "Response content:<br>";
print_r(json_decode($response_data, true));
}
curl_close($curl_instance);
$parsed_response = json_decode($response_data, true);
$generated_output = $parsed_response['choices'][0]['message']['content'];
echo "AI Output: " . $generated_output . "<br>";
When I try to use the gpt-4 model, the following error message appears:
Processing input: what will the weather be like in Newcastle?
{
"error": {
"message": "The model: `gpt-4` does not exist",
"type": "invalid_request_error",
"param": null,
"code": "model_not_found"
}
}
I have also tried using gpt-4-0613 and encountered the same issue. The models based on gpt-3.5-turbo seem to work without any issues. What could be the reason for this?