Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ AGENTS.md

# Git cache
git_cache/

# Agent process docs
.ckcoding/
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@

## 快速开始

当前服务器部署信息见:

- [部署文档](docs/deployment.md)
- [服务器部署说明](docs/server-deployment-notes.md)

已发布镜像支持 `linux/amd64` 与 `linux/arm64`,在 x86 服务器和 Apple Silicon / ARM Linux 设备上都会自动拉取匹配架构的版本。

### Docker 运行
Expand Down Expand Up @@ -403,4 +408,3 @@ curl http://localhost:8000/v1/responses \
## 友情链接

- [LINUX DO - 新的理想型社区](https://linux.do/)

209 changes: 209 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
# 部署文档

本文记录当前服务器上的两个 ChatGPT2API 部署实例,以及本仓库对应的部署方式。

## 服务器信息

| 项 | 值 |
| --- | --- |
| 服务器 IP | `8.220.241.231` |
| SSH 用户 | `root` |
| SSH 密码 | `Chai962464` |
| 管理后台 / API Bearer Key | `Chai962464` |

## 当前部署矩阵

| 端口 | 地址 | 项目 | 服务器目录 | 容器名 | 镜像 | 说明 |
| --- | --- | --- | --- | --- | --- | --- |
| 80 | `http://8.220.241.231` | `https://github.com/RemotePinee/ChatGPT2API` | `/opt/remote-chatgpt2api` | `remote-chatgpt2api` | `remote-chatgpt2api:local` | 本仓库,已加入图片账号失败后自动注册重试 |
| 666 | `http://8.220.241.231:666` | `https://github.com/ckcoding/chatgpt2api` | `/root/chatgpt2api-mod` | `chatgpt2api-mod` | `chatgpt2api:local` | 之前部署的修改版项目 |

## 本仓库部署实例

本仓库部署在服务器 80 端口:

```text
URL: http://8.220.241.231
API: http://8.220.241.231/v1
Web: http://8.220.241.231
Authorization: Bearer Chai962464
```

服务器目录:

```bash
cd /opt/remote-chatgpt2api
```

启动和重建:

```bash
docker-compose -f /opt/remote-chatgpt2api/docker-compose.yml build app
docker-compose -f /opt/remote-chatgpt2api/docker-compose.yml up -d app
```

查看状态:

```bash
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Ports}}\t{{.Status}}"
docker logs -f remote-chatgpt2api
```

## 80 端口配置

主配置文件:

```text
/opt/remote-chatgpt2api/config.json
```

关键配置:

```json
{
"auth-key": "Chai962464",
"base_url": "http://8.220.241.231",
"image_account_concurrency": 3,
"auto_remove_invalid_accounts": true,
"auto_remove_rate_limited_accounts": false
}
```

注册邮箱配置文件:

```text
/opt/remote-chatgpt2api/data/register.json
```

邮箱配置:

```json
{
"mail": {
"request_timeout": 15,
"wait_timeout": 30,
"wait_interval": 3,
"providers": [
{
"enable": true,
"type": "gptmail",
"api_key": "sk-72hz1Sy4MB5V",
"domain": [],
"default_domain": ""
}
]
},
"proxy": "",
"total": 2,
"threads": 1,
"fixed_password": "",
"mode": "quota",
"target_quota": 10,
"target_available": 10,
"check_interval": 5,
"enabled": true
}
```

## 666 端口配置

666 是之前部署的 `ckcoding/chatgpt2api` 修改版,不是本仓库。

```text
URL: http://8.220.241.231:666
API: http://8.220.241.231:666/v1
Web: http://8.220.241.231:666
Authorization: Bearer Chai962464
```

服务器目录:

```text
/root/chatgpt2api-mod
```

关键配置:

```json
{
"auth-key": "Chai962464",
"refresh_account_interval_minute": 5,
"image_account_concurrency": 3,
"image_parallel_generation": true,
"auto_remove_invalid_accounts": true,
"auto_remove_rate_limited_accounts": false
}
```

注册邮箱配置:

```json
{
"mail": {
"request_timeout": 30,
"wait_timeout": 30,
"wait_interval": 2,
"api_use_register_proxy": true,
"providers": [
{
"enable": true,
"type": "gptmail",
"api_base": "",
"admin_email": "",
"admin_password": "",
"domain": [],
"subdomain": [],
"email_prefix": "",
"api_key": "sk-72hz1Sy4MB5V",
"default_domain": ""
}
]
},
"proxy": "",
"total": 10,
"threads": 1,
"mode": "quota",
"target_quota": 10,
"target_available": 10,
"check_interval": 5,
"enabled": false
}
```

## 定时更新

服务器 crontab:

```cron
0 * * * * /opt/remote-chatgpt2api/auto-update.sh
```

要求:以后的定时任务只更新 `https://github.com/RemotePinee/ChatGPT2API` 对应的 80 端口部署。

`/opt/remote-chatgpt2api/auto-update.sh` 只操作:

- `/opt/remote-chatgpt2api`
- 容器 `remote-chatgpt2api`
- 镜像 `remote-chatgpt2api:local`
- 端口 `80`

它不操作 666 的 `/root/chatgpt2api-mod`、`chatgpt2api-mod` 或 `chatgpt2api:local`。

## 本次变更说明

本仓库 80 端口部署加入了图片账号失败和文本 token 失效后的自动注册重试:

- 没有可用图片账号时,不再秒返回 `no available image quota`。
- 会调用注册机 `openai_register.worker()` 自动注册账号。
- 注册失败会最多重试 3 次,或受 `register.json.total` 限制。
- 注册成功且新账号进入号池后,原图片请求继续拿新账号生成。
- `/api/chat/stream`、`/v1/chat/completions` 等文本通道遇到 `token_invalidated` / `token_revoked` 且尚未输出内容时,会删除失效账号、同步注册新账号,并用新账号重试当前请求。
- 缺少邮箱 provider 时记录 `自动注册跳过`。
- 注册补号、成功、失败、跳过、耗尽都会写入账号业务日志。

本地验证命令:

```bash
uv run python -m unittest test.test_account_image_capabilities
uv run python -m compileall services/account_service.py services/protocol/conversation.py test/test_account_image_capabilities.py
```
33 changes: 33 additions & 0 deletions docs/server-deployment-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 服务器部署说明

当前服务器 `8.220.241.231` 同时跑两个项目:

| 项 | 80 端口 | 666 端口 |
| --- | --- | --- |
| URL | `http://8.220.241.231` | `http://8.220.241.231:666` |
| GitHub 项目 | `https://github.com/RemotePinee/ChatGPT2API` | `https://github.com/ckcoding/chatgpt2api` |
| 服务器路径 | `/opt/remote-chatgpt2api` | `/root/chatgpt2api-mod` |
| 容器 | `remote-chatgpt2api` | `chatgpt2api-mod` |
| 镜像 | `remote-chatgpt2api:local` | `chatgpt2api:local` |
| 后台密钥 | `Chai962464` | `Chai962464` |
| 邮箱 provider | `gptmail` | `gptmail` |
| 邮箱 API key | `sk-72hz1Sy4MB5V` | `sk-72hz1Sy4MB5V` |

SSH 登录:

```bash
ssh root@8.220.241.231
# password: Chai962464
```

检查两个容器:

```bash
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Ports}}\t{{.Status}}"
```

当前约定:

- 80 端口是 RemotePinee/ChatGPT2API,部署自动注册重试修复。
- 666 端口是之前修改版 chatgpt2api,继续保留给旧部署使用。
- 定时任务只更新 80 端口的 RemotePinee/ChatGPT2API。
Loading