PHPackages                             onekb/chat-gpt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. onekb/chat-gpt

ActiveLibrary[API Development](/categories/api)

onekb/chat-gpt
==============

ChatGPT for PHP，和简易终端实现。Using OpenAI GPT3.5 model API.

3.5.0(3y ago)8052723MITPHP

Since Dec 7Pushed 3y ago4 watchersCompare

[ Source](https://github.com/onekb/ChatGPT)[ Packagist](https://packagist.org/packages/onekb/chat-gpt)[ RSS](/packages/onekb-chat-gpt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (0)

onekb/ChatGPT
=============

[](#onekbchatgpt)

**采用OpenAI GPT3.5模型API[（参考）](https://platform.openai.com/docs/guides/chat)**

**Using OpenAI GPT3.5 model API [(reference)](https://platform.openai.com/docs/guides/chat)**

[![](./screenshots/conch.jpeg)](./screenshots/conch.jpeg)[![](./screenshots/demo.png)](./screenshots/demo.png)

Installing
==========

[](#installing)

```
composer require onekb/chat-gpt
```

Usage
=====

[](#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
==================

[](#️-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

> 你可以在这里找到参数值 👉 [教程](#%E5%85%B6%E4%BB%96other)

> You can find parameter values here 👉 [tutorial](#%E5%85%B6%E4%BB%96other)

**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
=======

[](#其他other)

获取API Key Get API Key

登录你的OpenAI账户，访问  获取你的API Key Log in to your OpenAI account and visit  to get your API Key

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Total

6

Last Release

1168d ago

Major Versions

1.0.5 → 2.0.02023-02-28

2.0.x-dev → 3.5.02023-03-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/2dd22bce5121cc4cf36876caf143f65734f04c8dc962385887ba9df2ba518e08?d=identicon)[1kb](/maintainers/1kb)

---

Top Contributors

[![onekb](https://avatars.githubusercontent.com/u/16450084?v=4)](https://github.com/onekb "onekb (17 commits)")

---

Tags

chatbotChatGptchat gpt

### Embed Badge

![Health badge](/badges/onekb-chat-gpt/health.svg)

```
[![Health](https://phpackages.com/badges/onekb-chat-gpt/health.svg)](https://phpackages.com/packages/onekb-chat-gpt)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[casperlaitw/laravel-fb-messenger

A Laravel Package to Integrate Facebook Messenger API

10631.5k](/packages/casperlaitw-laravel-fb-messenger)[tgallice/wit-php

Wit.ai php sdk

7325.2k1](/packages/tgallice-wit-php)[creativecrafts/laravel-ai-assistant

A handy package to access and interact with OpenAi endpoint

141.1k](/packages/creativecrafts-laravel-ai-assistant)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
