Skip to content

Commit c5795f3

Browse files
authored
Remove unofficial api (#596)
* refactor: remove unofficial api support Signed-off-by: Bob Du <[email protected]> * refactor: use openai-ts sdk Signed-off-by: Bob Du <[email protected]> * docs: update readme remove unofficial api support Signed-off-by: Bob Du <[email protected]> --------- Signed-off-by: Bob Du <[email protected]>
1 parent 10bd45e commit c5795f3

File tree

12 files changed

+385
-648
lines changed

12 files changed

+385
-648
lines changed

README.en.md

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,15 @@ Some unique features have been added:
7979

8080
## Introduction
8181

82-
Supports dual models, provides two unofficial `ChatGPT API` methods:
82+
Uses the official `OpenAI API` to access `ChatGPT`:
8383

84-
| Method | Free? | Reliability | Quality |
85-
| --------------------------------------------- | ------ | ----------- | ------- |
86-
| `ChatGPTAPI(gpt-3.5-turbo-0301)` | No | Reliable | Relatively clumsy |
87-
| `ChatGPTUnofficialProxyAPI(Web accessToken)` | Yes | Relatively unreliable | Smart |
88-
89-
Comparison:
90-
1. `ChatGPTAPI` uses `gpt-3.5-turbo-0301` to simulate `ChatGPT` through the official `OpenAI` completion `API` (the most reliable method, but it is not free and does not use models specifically tuned for chat).
91-
2. `ChatGPTUnofficialProxyAPI` accesses `ChatGPT`'s backend `API` via an unofficial proxy server to bypass `Cloudflare` (uses the real `ChatGPT`, is very lightweight, but depends on third-party servers and has rate limits).
84+
`ChatGPTAPI` uses `gpt-4.1` through the official `OpenAI` completion `API` (requires an API key).
9285

9386
[Details](https://github.com/Chanzhaoyu/chatgpt-web/issues/138)
9487

95-
Switching Methods:
88+
Setup:
9689
1. Go to the `service/.env.example` file and copy the contents to the `service/.env` file.
97-
2. For `OpenAI API Key`, fill in the `OPENAI_API_KEY` field [(Get apiKey)](https://platform.openai.com/overview).
98-
3. For `Web API`, fill in the `OPENAI_ACCESS_TOKEN` field [(Get accessToken)](https://chat.openai.com/api/auth/session).
99-
4. When both are present, `OpenAI API Key` takes precedence.
100-
101-
Reverse Proxy:
102-
103-
Available when using `ChatGPTUnofficialProxyAPI`.[Details](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)
104-
105-
```shell
106-
# service/.env
107-
API_REVERSE_PROXY=
108-
```
90+
2. Fill in the `OPENAI_API_KEY` field with your OpenAI API Key [(Get apiKey)](https://platform.openai.com/overview).
10991

11092
Environment Variables:
11193

@@ -152,18 +134,15 @@ If you have not installed `pnpm` before:
152134
npm install pnpm -g
153135
```
154136

155-
### Fill in the Keys
137+
### Fill in the API Key
156138

157-
Get `Openai Api Key` or `accessToken` and fill in the local environment variables [jump](#introduction)
139+
Get your `OpenAI API Key` and fill in the local environment variables [jump](#introduction)
158140

159141
```
160142
# service/.env file
161143
162144
# OpenAI API Key - https://platform.openai.com/overview
163145
OPENAI_API_KEY=
164-
165-
# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
166-
OPENAI_ACCESS_TOKEN=
167146
```
168147

169148
## Install Dependencies
@@ -205,11 +184,9 @@ pnpm dev
205184

206185
#### Docker Parameter Example
207186

208-
- `OPENAI_API_KEY` one of two
209-
- `OPENAI_ACCESS_TOKEN` one of two, `OPENAI_API_KEY` takes precedence when both are present
187+
- `OPENAI_API_KEY` required
210188
- `OPENAI_API_BASE_URL` optional, available when `OPENAI_API_KEY` is set
211-
- `OPENAI_API_MODEL` `ChatGPTAPI` OR `ChatGPTUnofficialProxyAPI`
212-
- `API_REVERSE_PROXY` optional, available when `OPENAI_ACCESS_TOKEN` is set [Reference](#introduction)
189+
- `OPENAI_API_MODEL` optional, specify the model to use
213190
- `AUTH_SECRET_KEY` Access Password,optional
214191
- `TIMEOUT_MS` timeout, in milliseconds, optional
215192
- `SOCKS_PROXY_HOST` optional, effective with SOCKS_PROXY_PORT

README.md

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,17 @@
8080
- [License](#license)
8181
## 介绍
8282

83-
支持双模型,提供了两种非官方 `ChatGPT API` 方法
83+
使用官方 `OpenAI API` 访问 `ChatGPT`
8484

85-
| 方式 | 免费? | 可靠性 | 质量 |
86-
| --------------------------------------------- | ------ | ---------- | ---- |
87-
| `ChatGPTAPI(gpt-3.5-turbo-0301)` || 可靠 | 相对较笨 |
88-
| `ChatGPTUnofficialProxyAPI(网页 accessToken)` || 相对不可靠 | 聪明 |
89-
90-
对比:
91-
1. `ChatGPTAPI` 使用 `gpt-3.5-turbo` 通过 `OpenAI` 官方 `API` 调用 `ChatGPT`
92-
2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`(依赖于第三方服务器,并且有速率限制)
85+
`ChatGPTAPI` 使用 `gpt-4.1` 通过 `OpenAI` 官方 `API` 调用 `ChatGPT`(需要 API 密钥)。
9386

9487
警告:
95-
1. 你应该首先使用 `API` 方式
96-
2. 使用 `API` 时,如果网络不通,那是国内被墙了,你需要自建代理,绝对不要使用别人的公开代理,那是危险的。
97-
3. 使用 `accessToken` 方式时反向代理将向第三方暴露您的访问令牌,这样做应该不会产生任何不良影响,但在使用这种方法之前请考虑风险。
98-
4. 使用 `accessToken` 时,不管你是国内还是国外的机器,都会使用代理。默认代理为 [pengzhile](https://github.com/pengzhile) 大佬的 `https://ai.fakeopen.com/api/conversation`,这不是后门也不是监听,除非你有能力自己翻过 `CF` 验证,用前请知悉。[社区代理](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)(注意:只有这两个是推荐,其他第三方来源,请自行甄别)
99-
5. 把项目发布到公共网络时,你应该设置 `AUTH_SECRET_KEY` 变量添加你的密码访问权限,你也应该修改 `index.html` 中的 `title`,防止被关键词搜索到。
88+
1. 使用 `API` 时,如果网络不通,那是国内被墙了,你需要自建代理,绝对不要使用别人的公开代理,那是危险的。
89+
2. 把项目发布到公共网络时,你应该设置 `AUTH_SECRET_KEY` 变量添加你的密码访问权限,你也应该修改 `index.html` 中的 `title`,防止被关键词搜索到。
10090

101-
切换方式
91+
设置方式
10292
1. 进入 `service/.env.example` 文件,复制内容到 `service/.env` 文件
103-
2. 使用 `OpenAI API Key` 请填写 `OPENAI_API_KEY` 字段 [(获取 apiKey)](https://platform.openai.com/overview)
104-
3. 使用 `Web API` 请填写 `OPENAI_ACCESS_TOKEN` 字段 [(获取 accessToken)](https://chat.openai.com/api/auth/session)
105-
4. 同时存在时以 `OpenAI API Key` 优先
93+
2. 填写 `OPENAI_API_KEY` 字段 [(获取 apiKey)](https://platform.openai.com/overview)
10694

10795
环境变量:
10896

@@ -149,17 +137,14 @@ node -v
149137
npm install pnpm -g
150138
```
151139

152-
### 填写密钥
153-
获取 `Openai Api Key``accessToken` 并填写本地环境变量 [跳转](#介绍)
140+
### 填写API密钥
141+
获取 `OpenAI API Key` 并填写本地环境变量 [跳转](#介绍)
154142

155143
```
156144
# service/.env 文件
157145
158146
# OpenAI API Key - https://platform.openai.com/overview
159147
OPENAI_API_KEY=
160-
161-
# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
162-
OPENAI_ACCESS_TOKEN=
163148
```
164149

165150
## 安装依赖
@@ -199,15 +184,10 @@ pnpm dev
199184

200185
`API` 可用:
201186

202-
- `OPENAI_API_KEY` `OPENAI_ACCESS_TOKEN` 二选一
187+
- `OPENAI_API_KEY` 必填
203188
- `OPENAI_API_BASE_URL` 设置接口地址,可选,默认:`https://api.openai.com`
204189
- `OPENAI_API_DISABLE_DEBUG` 设置接口关闭 debug 日志,可选,默认:empty 不关闭
205190

206-
`ACCESS_TOKEN` 可用:
207-
208-
- `OPENAI_ACCESS_TOKEN``OPENAI_API_KEY` 二选一,同时存在时,`OPENAI_API_KEY` 优先
209-
- `API_REVERSE_PROXY` 设置反向代理,可选,默认:`https://ai.fakeopen.com/api/conversation`[社区](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)(注意:只有这两个是推荐,其他第三方来源,请自行甄别)
210-
211191
通用:
212192

213193
- `AUTH_SECRET_KEY` 访问权限密钥,可选
@@ -223,6 +203,17 @@ pnpm dev
223203

224204
#### Docker 参数示例
225205

206+
- `OPENAI_API_KEY` 必填
207+
- `OPENAI_API_BASE_URL` 可选,设置接口地址,默认:`https://api.openai.com`
208+
- `OPENAI_API_MODEL` 可选,指定使用的模型
209+
- `AUTH_SECRET_KEY` 访问密码,可选
210+
- `TIMEOUT_MS` 超时,单位毫秒,可选
211+
- `SOCKS_PROXY_HOST` 可选,与 SOCKS_PROXY_PORT 一起使用
212+
- `SOCKS_PROXY_PORT` 可选,与 SOCKS_PROXY_HOST 一起使用
213+
- `SOCKS_PROXY_USERNAME` 可选,与 SOCKS_PROXY_HOST 和 SOCKS_PROXY_PORT 一起使用
214+
- `SOCKS_PROXY_PASSWORD` 可选,与 SOCKS_PROXY_HOST 和 SOCKS_PROXY_PORT 一起使用
215+
- `HTTPS_PROXY` 可选,支持 http,https, socks5
216+
226217
![docker](./docs/docker.png)
227218

228219
#### Docker build & Run

service/package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"scripts": {
1919
"start": "tsx ./src/index.ts",
20-
"dev": "tsx watch ./src/index.ts",
20+
"dev": "tsx watch --inspect ./src/index.ts",
2121
"prod": "node --import tsx/esm ./build/index.js",
2222
"prod-node18": "node --loader tsx/esm ./build/index.js",
2323
"build": "pnpm clean && tsc && pnpm copy",
@@ -29,22 +29,19 @@
2929
},
3030
"dependencies": {
3131
"axios": "^1.8.4",
32-
"chatgpt": "npm:@chatgptweb/[email protected]",
3332
"dayjs": "^1.11.7",
3433
"dotenv": "^16.0.3",
3534
"express": "^5.1.0",
3635
"express-rate-limit": "^6.7.0",
3736
"file-type": "^19.0.0",
38-
"gpt-token": "^0.0.5",
39-
"https-proxy-agent": "^5.0.1",
37+
"https-proxy-agent": "^7.0.6",
4038
"jsonwebtoken": "^9.0.0",
41-
"jwt-decode": "^3.1.2",
4239
"mongodb": "^6.6.2",
4340
"multer": "1.4.5-lts.1",
4441
"node-fetch": "^3.3.0",
4542
"nodemailer": "^6.9.13",
43+
"openai": "^4.96.0",
4644
"request-ip": "^3.3.0",
47-
"socks-proxy-agent": "^7.0.0",
4845
"speakeasy": "^2.0.0",
4946
"tsx": "^4.7.0"
5047
},
@@ -53,7 +50,7 @@
5350
"@types/express": "^5.0.1",
5451
"@types/jsonwebtoken": "^9.0.5",
5552
"@types/multer": "^1.4.11",
56-
"@types/node": "^18.14.6",
53+
"@types/node": "^22.15.3",
5754
"@types/nodemailer": "^6.4.14",
5855
"@types/request-ip": "^0.0.41",
5956
"@types/speakeasy": "^2.0.10",

0 commit comments

Comments
 (0)