php调用chatgpd接口输出

admin3年前php558
<?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设置16位的md5加密方法

用substr函数实现substr(md5(变量),8,16);就可以实现默认的md5(变量)输出的是32位加密方法...

php过滤emod与特殊字符

<?php  function xml_entities($string) { //过滤emod $ts_zifu= json_encode($st...

php的function函数内部只能有一个return

php的function函数内部只能有一个return,之后的代码就都全部运行不正常了...

PHP生成json,javascript解析json

生成json<?php $arr=array();  //定义空数组 $one="111"; $two="222"; arra...

php数组元素的增加删除修改操作方法

增加$arr[$iy]["pr_count"]+=$pr_count;减少$arr[$iy]["pr_count"]-=$pr_count;删除unset($a...

php.ini 7.3设置

date.timezone = PRCdisplay_errors = On网络保存图片,以及微信获取手机号码: windows下的PHP,只需要到php.ini中把前面的&nb...

发表评论    

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