汇成软件 Create the world!!!

php调用chatgpd接口输出

<?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"];


 ?>


作者:admin 分类:php 浏览:264 评论:0
留言列表
发表评论
来宾的头像