写一个调用chatgpt的PHP源码
时间: 2023-10-30 07:07:49 浏览: 122
php开发Chatgpt源码.rar
<?php
$curl = curl_init();curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.openai.com/v1/engines/chatgpt/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array('prompt' => '你好', 'max_tokens' => '100'),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: multipart/form-data"
),
));$response = curl_exec($curl);curl_close($curl);
echo $response;
?>
阅读全文