chatgpt开发包
这里我用的是orhanerday/open-ai
composer 包安装
composer require orhanerday/open-ai
简单调用实例
<?php
require __DIR__ . '/vendor/autoload.php'; // remove this line if you use a PHP Framework.
use Orhanerday\OpenAi\OpenAi;
$open_ai_key = getenv('OPENAI_API_KEY');
$open_ai = new OpenAi($open_ai_key);
$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,
]);
var_dump($complete);
集成到项目
思路一 websoket方式
- 后台开启websoket
采用wokerman GatewayWorker 启动websoket服务
protected function configure()
{
// 指令配置
$this->setName('chat:server')
->addArgument('action', Argument::OPTIONAL, "start|stop|restart|reload|status|connections", 'start'