onekb/chat-gpt
Composer 安装命令:
composer require onekb/chat-gpt
包简介
ChatGPT for PHP,和简易终端实现。Using OpenAI GPT3.5 model API.
README 文档
README
采用OpenAI GPT3.5模型API(参考)
Using OpenAI GPT3.5 model API (reference)
Installing
composer require onekb/chat-gpt
Usage
// 你的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' => '你好', // ], //];
⚡️ Getting Started
Step 1. 克隆本项目到本地 Clone this project to local
git clone https://github.com/onekb/ChatGPT.git
Step 2. 配置你的环境变量 Configure your environment variables
首先,将 start.php 文件中的 $apiKey 字段替换成你自己的 OpenAI API Key
First, replace the $apiKey field in the start.php file with your own OpenAI API Key
你可以在这里找到参数值 👉 教程
You can find parameter values here 👉 tutorial
Step 3. Hello world!
最后,你的电脑必须有 PHP 环境,然后在项目根目录下执行以下命令
Finally, your computer must have a PHP environment, and then execute the following command in the project root directory
composer install --no-dev
php start.php
就酱,准备好起飞 🚀
full stop, ready to take off 🚀
更新日志
3.5.0 2023-03-03
- 改用官方gpt-3.5-turbo模型API接口
- Q:为什么版本直接跳到V3.5? A:我乐意
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 Get API Key
登录你的OpenAI账户,访问 https://platform.openai.com/account/api-keys 获取你的API Key Log in to your OpenAI account and visit https://platform.openai.com/account/api-keys to get your API Key
onekb/chat-gpt 适用场景与选型建议
onekb/chat-gpt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 536 次下载、GitHub Stars 达 79, 最近一次更新时间为 2022 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「chatbot」 「ChatGpt」 「chat-gpt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 onekb/chat-gpt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 onekb/chat-gpt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 onekb/chat-gpt 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
TokenizerX calculates required tokens for given prompt
OpenAI 应用 ChatGPT
T3AI – TYPO3 AI Integration Extension
AI-powered helper for PHP errors, warnings and exceptions: practical, context-aware explanations and suggestions via local or API LLMs.
A library for interacting with ChatGPT and Claude AI
TokenizerX calculates required tokens for given prompt
统计信息
- 总下载量: 536
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 80
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-07

