我的代码如下,它与模型完美配合gpt-3.5-turbo,但不适用于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>"; …Run Code Online (Sandbox Code Playgroud)