php调用chatgpd接口输出

admin2年前php499
<?php
$url = 'https://api.openai.com/v1/completions';
$data = array("model"=> "text-davinci-003",
          "prompt"=> "帮我用C#开发一个生成二维码的程序",
          "temperature"=> 0.7,
          "max_tokens"=> 256,
          "top_p"=> 1,
          "frequency_penalty"=> 0,
          "presence_penalty"=> 0);
$data_string = json_encode($data);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: Bearer apikey',
    'Content-Length: ' . strlen($data_string))
);

$result = json_decode(curl_exec($ch),true);

curl_close($ch);

print_r($result);
 
echo  $result["choices"][0]["text"];


 ?>


相关文章

php提示Notice: Undefined index解决方法与php未定义的变量提示错误的解决方法

在php.ini配置文件里设置把error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT修改成error_reporting = E_AL...

php设置cookie方法,php销毁cookie方法,php输出cookie方法,php输出cookie数量的方法

<?php //设置cookie setcookie("user_name", "frank", time()+3600); /...

php替换ASCIII码空格字符的方法

需要用到PHP自带函数chr()方法如下:$string=str_replace(chr(0x01),"",$string);...

mysql批量添加数据

$conn=new sqlhelper;for ($i = 0; $i <1000 ; $i++) {$sql="insert into system_user(user_shenfe...

面向过程的php sqlhelp

<?php $servername = "localhost"; $username = "root"; $...

php post undefined index,PHP 中提示undefined index的解决方案

声明为空isset($_POST['user_email']),或者,empty($_POST['user_email'])在php.ini中设置error_repor...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。