composer 1.6.5以上
支持框架 Laravel、Symfony、Yii2、Cake PHP 或任何 PHP 框架,完备开源,支持OpenAI GPT-3 API接口。
谈天 - 谈天GPT API

模型 - 列出模型,检索模型
创建 - 创建完成
编辑 - 创建编辑
图片 - 创建图像,编辑图像
嵌入 - 创建嵌入
声音 - 创建转录,创建翻译
文件 - 列出文件,上传文件,删除文件,检索文件,检索内容
安装利用composer require orhanerday/open-ai
<?phpuse Orhanerday\OpenAi\OpenAi;$open_ai_key = ""; #openAI的key$open_ai = new OpenAi($open_ai_key); //类的实例化$chat = $open_ai->chat(['model' => 'gpt-3.5-turbo', //定义模型'messages' => [["role" => "system", //角色系统"content" => "You are a helpful assistant."],["role" => "user","content" => "Who won the world series in 2020?"],["role" => "assistant", //角色助理"content" => "The Los Angeles Dodgers won the World Series in 2020."],["role" => "user","content" => "Where was it played?"],],'temperature' => 1.0,'max_tokens' => 4000, //最大token'frequency_penalty' => 0,'presence_penalty' => 0,]);var_dump($chat);echo "<br>";echo "<br>";echo "<br>";// 解码相应$d = json_decode($chat);// 获取内容echo($d->choices[0]->message->content);
基本网址
利用 setBaseURL() 方法指定Origin URL;
$open_ai_key = getenv('OPENAI_API_KEY');$open_ai = new OpenAi($open_ai_key,$originURL);$open_ai->setBaseURL("https://ai.example.com/");
利用代理做事器
$open_ai->setProxy("http://127.0.0.1:1086");
设置标题
$open_ai->setHeader(["Connection"=>"keep-alive"]);
基于ChatGPT API 的谈天
$complete = $open_ai->chat(['model' => 'gpt-3.5-turbo','messages' => [["role" => "system","content" => "You are a helpful assistant."],["role" => "user","content" => "Who won the world series in 2020?"],["role" => "assistant","content" => "The Los Angeles Dodgers won the World Series in 2020."],["role" => "user","content" => "Where was it played?"],],'temperature' => 1.0,'max_tokens' => 4000,'frequency_penalty' => 0,'presence_penalty' => 0,]);
访问元素
<?php// Dummy Response For Chat API$j = '{"id":"chatcmpl-","object":"chat.completion","created":1679748856,"model":"gpt-3.5-turbo-0301","usage":{"prompt_tokens":9,"completion_tokens":10,"total_tokens":19},"choices":[{"message":{"role":"assistant","content":"This is a test of the AI language model."},"finish_reason":"length","index":0}]}';// decode response$d = json_decode($j);// Get Contentecho($d->choices[0]->message->content);
还有别的的用法,大家可以根据文档好好研究,我这里就不一一列举了。