cha

OpenAI(ChatGPT)对接的php代码

代码如下:

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL => 'https://api.openai.com/v1/engines/davinci/completions',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $api_key
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'prompt' => 'Hello, how are you today?',
        'model' => 'text-davinci-002',
        'max_tokens' => 128,
        'temperature' => 0.5    ])
]);
$response = curl_exec($curl);
curl_close($curl);



您可能还会对下面的文章感兴趣:

登录 注册 退出