guanhui07/chat-gpt

PHP版本的ChatGPT,以及简易终端实现。使用OpenAI GPT3.5模型API。

维护者

详细信息

github.com/guanhui07/ChatGPT

源代码

安装: 0

依赖: 0

建议: 0

安全: 0

星标: 0

关注者: 0

分支: 26

dev-main 2024-09-19 09:59 UTC

This package is auto-updated.

Last update: 2024-09-19 09:59:22 UTC


README

采用OpenAI GPT3.5模型API(参考)

使用OpenAI GPT3.5模型API (参考)

安装

composer require guanhui07/chat-gpt

使用

// 你的key
// your key
$apiKey = 'sk-PXxxxxxxxx';

// 最大提交聊天记录数,内容太多会消耗更多tokens
// The maximum number of submitted chat records, too much content will consume more tokens
$limit = 10;

$chatGPT=new \Onekb\ChatGpt\ChatGpt($apiKey, $limit);

// 简单使用
var_dump($chatGPT->ask('你好'));

// 设置代理
\Onekb\ChatGpt\Di::set('proxy', 'http://127.0.0.1:8899');

// 重新发起对话 Reinitiate a conversation
// $chatGpt->clearHistory();

// 自定义聊天记录 Custom chat history
//$chatGpt->history = [
//    [
//        'role' => 'user',
//        'content' => '你好',
//    ],
//    [
//        'role' => 'assistant',
//        'content' => '你好',
//    ],
//];

⚡️ 开始使用

步骤 1. 将本项目克隆到本地

git clone https://github.com/onekb/ChatGPT.git

步骤 2. 配置你的环境变量

首先,将start.php文件中的$apiKey字段替换成你自己的OpenAI API Key

首先,在start.php文件中将$apiKey字段替换成你自己的OpenAI API Key

你可以在以下位置找到参数值 👉 教程

你可以在以下位置找到参数值 👉 教程

步骤 3. Hello world!

最后,你的电脑必须有PHP环境,然后在项目根目录下执行以下命令

最后,你的电脑需要有PHP环境,然后在项目根目录下执行以下命令

composer install --no-dev
php start.php

就这样,准备起飞 🚀

full stop,准备起飞 🚀

更新日志

3.5.0 2023-03-03

  • 改为使用官方gpt-3.5-turbo模型API接口
  • 问:为什么版本直接跳到V3.5?答:我喜欢

2.0.0 2023-02-28

  • 重构代码
  • 变更获取方式
  • 英文readme

1.0.5 2022-12-13

  • 修复cloudflare拦截问题,需补全验证信息

1.0.3 2022-12-09

  • 将cookie交给CookieJar维护
  • 优化Di管理方式
  • 返回谈话ID
  • 支持设置谈话参数(继续会话)
  • 支持设置代理

1.0.1 2022-12-07

  • 初版

其他other

获取API Key 获取API Key

登录你的OpenAI账户,访问 https://platform.openai.com/account/api-keys 获取你的API Key