gpt-3收费成本可以接受,生成的内容对话有点不太聪明的样子,gpt-3.5-turbo收费相对来说低,生成文本质量还是蛮高的,虽然有可能存在一点废话,但是不影响,git-4对不起用不起哈,等模型训练会不会下带升级之后这个收费较低我在说吧gpt-3收费成本可以接受,生成的内容对话有点不太聪明的样子,gpt-3.5-turbo收费相对来说低,生成文本质量还是蛮高的,虽然有可能存在一点废话,但是不影响,git-4对不起用不起哈,等模型训练会不会下带升级之后这个收费较低我在说吧 php调用对
php调用对话接口
https://api.openai.com/v1/chat/completions
各种三个demo测试$msg是你需要传入的对话
第二段是屏蔽部分首次进入加入
$data = array(
'model' => 'gpt-3.5-turbo',
'messages' => [
['role' => 'user', 'content' => $msg],
],
// 'messages' => array(
// array('role' => 'system', 'content' => '你好,有什么可以帮助您'),
// array('role' => 'user', 'content' => '生成介绍API文章')
// ),
//'max_tokens' => 1000,
// 'model' => 'gpt-3.5-turbo',
//'prompt' => '生成关于ai绘画介绍的详细文章,讲述所涉及到知识点',
);
再就是curl,请求了这种直接使用chatGPT生成的代码改动一下就可以
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
curl_setopt($ch, CURLOPT_PROXY, env('gpt.proxy')); //代理服务器地址
curl_setopt($ch, CURLOPT_PROXYPORT, env('gpt.proxyport')); //代理服务器端口
if(!empty(env('gpt.proxyuserpwd'))){
curl_setopt($ch, CURLOPT_PROXYUSERPWD, env('gpt.proxyuserpwd')); //http代理认证帐号,username:password的格式
}
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey
));
$result = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($responseCode == 200 || $result === false) {
$response = json_decode($result, true);
// dd($response);
Log::info("chat GPT:---------------------------");
Log::info("内容:".$result);
// Log::info("status:".$response['choices'][0]['finish_reason']);
// print_r($response['choices']);
//Log::info(htmlspecialchars($html));
return $response;
//$generatedText = $response['choices'][0]['text'];
// print_r($generatedText);
} else {
$response = json_decode($result, true);
if(is_array($response)){
return "Error sending request: " . $result;
return $response['error']['type'].":".$response['error']['message'];
}else{
return "Error sending request: " . curl_error($ch);
}
// 处理请求错误
}
沃梦达教程
本文标题为:php使用chatGPT生成一些东西做一个记录
基础教程推荐
猜你喜欢
- PHP实现抽奖系统的示例代码 2023-06-26
- 设定php简写功能的方法 2023-03-17
- php实现构建排除当前元素的乘积数组方法 2022-11-23
- PHP实现文件下载【实例分享】 2024-04-27
- PHP判断一个字符串是否是回文字符串的方法 2024-01-31
- PHP+MySQL+sphinx+scws实现全文检索功能详解 2023-01-31
- php实现数组筛选奇数和偶数示例 2024-02-05
- php数组函数序列之array_sum() – 计算数组元素值之和 2024-01-15
- PHP手机短信验证码实现流程详解 2022-10-18
- Yii框架连表查询操作示例 2023-02-13
