基于ChatGPT API的PHP组件
$ composer require savvym/chatgpt -vvv
在使用本扩展前,你需要去OpenAI获取应用的API key.
无上下文功能:
use Savvym\Chatgpt\ChatGPT;
$key = 'xxxxxxxxxxxxx';
$c = new ChatGPT($key);
带上下文功能:
use Savvym\Chatgpt\ChatGPT;
use Savvym\Chatgpt\History\FileHistory;
$key = 'xxxxxxxxxxxxx';
$history = new FileHistory('./data/cache.php');
$c = new ChatGPT($key, $history);
$res = $c->chat('做一首诗');
$res = $c->chat('翻译前面的话');
string chat(string $msg)
$msg
- 发送消息
- Redis history
- ...
MIT