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51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
---
title: Go Chatgpt Api
emoji: 💩
colorFrom: green
colorTo: indigo
sdk: docker
pinned: false
app_port: 8080

# go-chatgpt-api

### [English Doc](README_en.md)

## 一个尝试绕过 `Cloudflare 403` 和 `Access denied` 的正向代理程序

### 实验性质项目,不保证稳定性和向后兼容,使用风险自负

---

### 使用的过程中遇到问题应该如何解决

汇总贴:https://github.com/linweiyuan/go-chatgpt-api/issues/74

---

### 支持的 API(URL 和参数基本保持着和官网一致,部分接口有些许改动)

---

### ChatGPT APIs

---

- `ChatGPT` 登录(返回 `accessToken`)(目前仅支持 `ChatGPT` 账号,谷歌或微软账号没有测试)

`POST /chatgpt/login`

<details>

```json
{
  "username": "email",
  "password": "password"
}
```

</details>

---

- 获取对话列表(历史记录)

`GET /chatgpt/conversations?offset=0&limit=20`

`offset` 不传默认为 0, `limit` 不传默认为 20 (最大为 100)

---

- 获取对话内容

`GET /chatgpt/conversation/{conversationID}`

---

- 新建对话

`POST /chatgpt/conversation`

<details>

```json
{
  "action": "next",
  "messages": [
    {
      "id": "message id",
      "author": {
        "role": "user"
      },
      "content": {
        "content_type": "text",
        "parts": [
          "Hello World"
        ]
      }
    }
  ],
  "parent_message_id": "parent message id",
  "conversation_id": "conversation id",
  "model": "text-davinci-002-render-sha",
  "timezone_offset_min": -480,
  "history_and_training_disabled": false
}
```

</details>

---

- 生成对话标题

`POST /chatgpt/conversation/gen_title/{conversationID}`

<details>

```json
{
  "message_id": "role assistant response message id"
}
```

</details>

---

- 重命名对话标题

`PATCH /chatgpt/conversation/{conversationID}`

<details>

```json
{
  "title": "new title"
}
```

</details>

---

- 删除单个对话

`PATCH /chatgpt/conversation/{conversationID}`

<details>

```json
{
  "is_visible": false
}
```

</details>

---

- 删除所有对话

`PATCH /chatgpt/conversations`

<details>

```json
{
  "is_visible": false
}
```

</details>

---

- 消息反馈

`POST /chatgpt/conversation/message_feedback`

<details>

```json
{
  "message_id": "message id",
  "conversation_id": "conversation id",
  "rating": "thumbsUp/thumbsDown"
}
```

</details>

---

### Platform APIs

---

- `platform` 登录(返回 `sessionKey``POST /platform/login`

<details>

```json
{
  "username": "email",
  "password": "password"
}
```

</details>

---

- [List models](https://platform.openai.com/docs/api-reference/models/list)

`GET /platform/v1/models`

---

- [Retrieve model](https://platform.openai.com/docs/api-reference/models/retrieve)

`GET /platform/v1/models/{model}`

---

- [Create completion](https://platform.openai.com/docs/api-reference/completions/create)

`POST /platform/v1/completions`

<details>

```json
{
  "model": "text-davinci-003",
  "prompt": "Say this is a test",
  "max_tokens": 7,
  "temperature": 0,
  "stream": true
}
```

</details>

---

- [Create chat completion](https://platform.openai.com/docs/api-reference/chat/create)

`POST /platform/v1/chat/completions`

<details>

```json
{
  "messages": [
    {
      "role": "user",
      "content": "Hello World"
    }
  ],
  "model": "gpt-3.5-turbo",
  "stream": true
}
```

</details>

---

- [Create edit](https://platform.openai.com/docs/api-reference/edits/create)

`POST /platform/v1/edits`

<details>

```json
{
  "model": "text-davinci-edit-001",
  "input": "What day of the wek is it?",
  "instruction": "Fix the spelling mistakes"
}
```

</details>

---

- [Create image](https://platform.openai.com/docs/api-reference/images/create)

`POST /platform/v1/images/generations`

<details>

```json
{
  "prompt": "A cute dog",
  "n": 2,
  "size": "1024x1024"
}
```

</details>

---

- [Create embeddings](https://platform.openai.com/docs/api-reference/embeddings/create)

`POST /platform/v1/embeddings`

<details>

```json
{
  "model": "text-embedding-ada-002",
  "input": "The food was delicious and the waiter..."
}
```

</details>

---

- [Create moderations](https://platform.openai.com/docs/api-reference/moderations/create)

`POST /platform/v1/moderations`

<details>

```json
{
  "model": "text-moderation-stable",
  "input": "I want to kill them."
}
```

</details>

---

- [List files](https://platform.openai.com/docs/api-reference/files/list)

`GET /platform/v1/files`

---

- 获取 `credit grants` (只能传 `sessionKey``GET /platform/dashboard/billing/credit_grants`

---

- 获取 `subscription` (只能传 `sessionKey``GET /platform/dashboard/billing/subscription`

---

- 获取 `api keys` (只能传 `sessionKey``GET /platform/dashboard/user/api_keys`

---

如需设置代理,可以设置环境变量 `GO_CHATGPT_API_PROXY`,比如 `GO_CHATGPT_API_PROXY=http://127.0.0.1:20171`
或者 `GO_CHATGPT_API_PROXY=socks5://127.0.0.1:20170`,注释掉或者留空则不启用

如需配合 `warp` 使用:`GO_CHATGPT_API_PROXY=socks5://chatgpt-proxy-server-warp:65535`,因为需要设置 `warp`
的场景已经默认可以直接访问 `ChatGPT` 官网,因此共用一个变量不冲突

---

`docker-compose` 配置文件:

```yaml
services:
  go-chatgpt-api:
    container_name: go-chatgpt-api
    image: linweiyuan/go-chatgpt-api
    ports:
      - 8080:8080
    environment:
      - GO_CHATGPT_API_PROXY=
    restart: unless-stopped
```

我仅仅在 `Arch Linux` 上进行开发和测试,这是一个滚动更新的版本,意味着系统上所有东西都是最新的,如果你在使用的过程中 `yaml`
报错了,则可以加上 `version: '3'``services:` 前面

如果遇到 `Access denied`,但是你的服务器确实在[被支持的国家或地区](https://platform.openai.com/docs/supported-countries)
,尝试一下这个配置(不保证能解决问题,比如你的服务器在 A 地区,但 A 地不在支持列表内,即使用上了 `warp` 后是 `Cloudflare IP`
,结果也会是 `403`):

```yaml
services:
  go-chatgpt-api:
    container_name: go-chatgpt-api
    image: linweiyuan/go-chatgpt-api
    ports:
      - 8080:8080
    environment:
      - GO_CHATGPT_API_PROXY=socks5://chatgpt-proxy-server-warp:65535
    depends_on:
      - chatgpt-proxy-server-warp
    restart: unless-stopped

  chatgpt-proxy-server-warp:
    container_name: chatgpt-proxy-server-warp
    image: linweiyuan/chatgpt-proxy-server-warp
    environment:
      - LOG_LEVEL=OFF
    restart: unless-stopped
```

如果你知道什么是 `teams-enroll-token`,可以通过环境变量 `TEAMS_ENROLL_TOKEN` 设置它的值

然后利用这条命令来检查是否生效:

`docker-compose exec chatgpt-proxy-server-warp warp-cli --accept-tos account | awk 'NR==1'`

```
Account type: Free (没有生效)

Account type: Team (设置正常)
```

---

如果要让运行的镜像总是保持最新,可以配合这个一起使用:

```yaml
services:
  watchtower:
    container_name: watchtower
    image: containrrr/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: --interval 3600
    restart: unless-stopped
```

<details>

<summary>广告位</summary>

`Vultr` 推荐链接:https://www.vultr.com/?ref=7372562

---

个人微信(没有验证,谁都能加,添加即通过,不用打招呼,直接把问题发出来,日常和私人问题不聊,不进群;可以解答程序使用问题,但最好自己要有一定的基础;可以远程调试,仅限 `SSH``ToDesk`,但不保证能解决):

![](https://linweiyuan.github.io/about/mmqrcode.png)

---

微信赞赏码(经济条件允许的可以考虑支持下):

![](https://linweiyuan.github.io/about/mm_reward_qrcode.png)

</details>