update sth at 2025-10-16 15:35:47
Browse files- app/admin/api.py +1 -1
- app/core/config.py +1 -1
- deploy/.env.example +1 -1
- deploy/Dockerfile +1 -1
- deploy/NGINX_SETUP.md +8 -8
- deploy/docker-compose.yml +2 -2
- deploy/nginx.conf.example +3 -3
- xREADME.md +5 -5
app/admin/api.py
CHANGED
|
@@ -194,7 +194,7 @@ async def save_config(request: Request):
|
|
| 194 |
"",
|
| 195 |
"# ========== 服务器配置 ==========",
|
| 196 |
f"SERVICE_NAME={form_data.get('service_name', 'Z.AI2API')}",
|
| 197 |
-
f"LISTEN_PORT={form_data.get('listen_port', '
|
| 198 |
f"DEBUG_LOGGING={'true' if 'debug_logging' in form_data else 'false'}",
|
| 199 |
"",
|
| 200 |
"# ========== 认证配置 ==========",
|
|
|
|
| 194 |
"",
|
| 195 |
"# ========== 服务器配置 ==========",
|
| 196 |
f"SERVICE_NAME={form_data.get('service_name', 'Z.AI2API')}",
|
| 197 |
+
f"LISTEN_PORT={form_data.get('listen_port', '7860')}",
|
| 198 |
f"DEBUG_LOGGING={'true' if 'debug_logging' in form_data else 'false'}",
|
| 199 |
"",
|
| 200 |
"# ========== 认证配置 ==========",
|
app/core/config.py
CHANGED
|
@@ -54,7 +54,7 @@ class Settings(BaseSettings):
|
|
| 54 |
}
|
| 55 |
|
| 56 |
# Server Configuration
|
| 57 |
-
LISTEN_PORT: int = int(os.getenv("LISTEN_PORT", "
|
| 58 |
DEBUG_LOGGING: bool = os.getenv("DEBUG_LOGGING", "true").lower() == "true"
|
| 59 |
SERVICE_NAME: str = os.getenv("SERVICE_NAME", "z-ai2api-server")
|
| 60 |
ROOT_PATH: str = os.getenv("ROOT_PATH", "") # For Nginx reverse proxy path prefix, e.g., "/api" or "/path-prefix"
|
|
|
|
| 54 |
}
|
| 55 |
|
| 56 |
# Server Configuration
|
| 57 |
+
LISTEN_PORT: int = int(os.getenv("LISTEN_PORT", "7860"))
|
| 58 |
DEBUG_LOGGING: bool = os.getenv("DEBUG_LOGGING", "true").lower() == "true"
|
| 59 |
SERVICE_NAME: str = os.getenv("SERVICE_NAME", "z-ai2api-server")
|
| 60 |
ROOT_PATH: str = os.getenv("ROOT_PATH", "") # For Nginx reverse proxy path prefix, e.g., "/api" or "/path-prefix"
|
deploy/.env.example
CHANGED
|
@@ -32,4 +32,4 @@ TOKEN_RECOVERY_TIMEOUT=300
|
|
| 32 |
|
| 33 |
# 服务配置
|
| 34 |
SERVICE_NAME=Z.AI_API_Server
|
| 35 |
-
LISTEN_PORT=
|
|
|
|
| 32 |
|
| 33 |
# 服务配置
|
| 34 |
SERVICE_NAME=Z.AI_API_Server
|
| 35 |
+
LISTEN_PORT=7860
|
deploy/Dockerfile
CHANGED
|
@@ -18,7 +18,7 @@ COPY . .
|
|
| 18 |
ENV DB_PATH=/app/data/tokens.db
|
| 19 |
|
| 20 |
# Expose port
|
| 21 |
-
EXPOSE
|
| 22 |
|
| 23 |
# Run the application
|
| 24 |
CMD ["python", "main.py"]
|
|
|
|
| 18 |
ENV DB_PATH=/app/data/tokens.db
|
| 19 |
|
| 20 |
# Expose port
|
| 21 |
+
EXPOSE 7860
|
| 22 |
|
| 23 |
# Run the application
|
| 24 |
CMD ["python", "main.py"]
|
deploy/NGINX_SETUP.md
CHANGED
|
@@ -69,10 +69,10 @@ services:
|
|
| 69 |
image: z-ai2api:latest
|
| 70 |
environment:
|
| 71 |
- ROOT_PATH=/ai2api
|
| 72 |
-
- LISTEN_PORT=
|
| 73 |
# ... 其他环境变量
|
| 74 |
ports:
|
| 75 |
-
- "
|
| 76 |
```
|
| 77 |
|
| 78 |
### 4. 重启服务
|
|
@@ -110,7 +110,7 @@ ROOT_PATH=/api
|
|
| 110 |
**Nginx 配置**:
|
| 111 |
```nginx
|
| 112 |
location /api {
|
| 113 |
-
proxy_pass http://127.0.0.1:
|
| 114 |
# ... 其他配置
|
| 115 |
}
|
| 116 |
```
|
|
@@ -127,7 +127,7 @@ ROOT_PATH=
|
|
| 127 |
**Nginx 配置**:
|
| 128 |
```nginx
|
| 129 |
location / {
|
| 130 |
-
proxy_pass http://127.0.0.1:
|
| 131 |
# ... 其他配置
|
| 132 |
}
|
| 133 |
```
|
|
@@ -144,7 +144,7 @@ ROOT_PATH=/services/ai/chat
|
|
| 144 |
**Nginx 配置**:
|
| 145 |
```nginx
|
| 146 |
location /services/ai/chat {
|
| 147 |
-
proxy_pass http://127.0.0.1:
|
| 148 |
# ... 其他配置
|
| 149 |
}
|
| 150 |
```
|
|
@@ -257,9 +257,9 @@ server {
|
|
| 257 |
|
| 258 |
```nginx
|
| 259 |
upstream ai2api_backend {
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
}
|
| 264 |
|
| 265 |
server {
|
|
|
|
| 69 |
image: z-ai2api:latest
|
| 70 |
environment:
|
| 71 |
- ROOT_PATH=/ai2api
|
| 72 |
+
- LISTEN_PORT=7860
|
| 73 |
# ... 其他环境变量
|
| 74 |
ports:
|
| 75 |
+
- "7860:7860"
|
| 76 |
```
|
| 77 |
|
| 78 |
### 4. 重启服务
|
|
|
|
| 110 |
**Nginx 配置**:
|
| 111 |
```nginx
|
| 112 |
location /api {
|
| 113 |
+
proxy_pass http://127.0.0.1:7860;
|
| 114 |
# ... 其他配置
|
| 115 |
}
|
| 116 |
```
|
|
|
|
| 127 |
**Nginx 配置**:
|
| 128 |
```nginx
|
| 129 |
location / {
|
| 130 |
+
proxy_pass http://127.0.0.1:7860;
|
| 131 |
# ... 其他配置
|
| 132 |
}
|
| 133 |
```
|
|
|
|
| 144 |
**Nginx 配置**:
|
| 145 |
```nginx
|
| 146 |
location /services/ai/chat {
|
| 147 |
+
proxy_pass http://127.0.0.1:7860;
|
| 148 |
# ... 其他配置
|
| 149 |
}
|
| 150 |
```
|
|
|
|
| 257 |
|
| 258 |
```nginx
|
| 259 |
upstream ai2api_backend {
|
| 260 |
+
server 127.0.0.1:7860;
|
| 261 |
+
server 127.0.0.1:7861;
|
| 262 |
+
server 127.0.0.1:7862;
|
| 263 |
}
|
| 264 |
|
| 265 |
server {
|
deploy/docker-compose.yml
CHANGED
|
@@ -5,7 +5,7 @@ services:
|
|
| 5 |
dockerfile: deploy/Dockerfile
|
| 6 |
container_name: z-ai-api-server
|
| 7 |
ports:
|
| 8 |
-
- "
|
| 9 |
volumes:
|
| 10 |
# 数据库持久化存储
|
| 11 |
- ./data:/app/data
|
|
@@ -29,7 +29,7 @@ services:
|
|
| 29 |
- DB_PATH=/app/data/tokens.db
|
| 30 |
restart: unless-stopped
|
| 31 |
healthcheck:
|
| 32 |
-
test: ["CMD", "curl", "-f", "http://localhost:
|
| 33 |
interval: 30s
|
| 34 |
timeout: 10s
|
| 35 |
retries: 3
|
|
|
|
| 5 |
dockerfile: deploy/Dockerfile
|
| 6 |
container_name: z-ai-api-server
|
| 7 |
ports:
|
| 8 |
+
- "7860:7860"
|
| 9 |
volumes:
|
| 10 |
# 数据库持久化存储
|
| 11 |
- ./data:/app/data
|
|
|
|
| 29 |
- DB_PATH=/app/data/tokens.db
|
| 30 |
restart: unless-stopped
|
| 31 |
healthcheck:
|
| 32 |
+
test: ["CMD", "curl", "-f", "http://localhost:7860/v1/models"]
|
| 33 |
interval: 30s
|
| 34 |
timeout: 10s
|
| 35 |
retries: 3
|
deploy/nginx.conf.example
CHANGED
|
@@ -12,7 +12,7 @@ server {
|
|
| 12 |
rewrite ^(/ai2api)$ $1/ permanent;
|
| 13 |
|
| 14 |
# Proxy to the backend service
|
| 15 |
-
proxy_pass http://127.0.0.1:
|
| 16 |
|
| 17 |
# Pass original host and IP information
|
| 18 |
proxy_set_header Host $host;
|
|
@@ -47,7 +47,7 @@ server {
|
|
| 47 |
|
| 48 |
location /api/chat {
|
| 49 |
# Proxy configuration
|
| 50 |
-
proxy_pass http://127.0.0.1:
|
| 51 |
|
| 52 |
# Headers
|
| 53 |
proxy_set_header Host $host;
|
|
@@ -75,7 +75,7 @@ server {
|
|
| 75 |
ssl_certificate_key /path/to/key.pem;
|
| 76 |
|
| 77 |
location /ai2api {
|
| 78 |
-
proxy_pass http://127.0.0.1:
|
| 79 |
|
| 80 |
proxy_set_header Host $host;
|
| 81 |
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
| 12 |
rewrite ^(/ai2api)$ $1/ permanent;
|
| 13 |
|
| 14 |
# Proxy to the backend service
|
| 15 |
+
proxy_pass http://127.0.0.1:7860;
|
| 16 |
|
| 17 |
# Pass original host and IP information
|
| 18 |
proxy_set_header Host $host;
|
|
|
|
| 47 |
|
| 48 |
location /api/chat {
|
| 49 |
# Proxy configuration
|
| 50 |
+
proxy_pass http://127.0.0.1:7860;
|
| 51 |
|
| 52 |
# Headers
|
| 53 |
proxy_set_header Host $host;
|
|
|
|
| 75 |
ssl_certificate_key /path/to/key.pem;
|
| 76 |
|
| 77 |
location /ai2api {
|
| 78 |
+
proxy_pass http://127.0.0.1:7860;
|
| 79 |
|
| 80 |
proxy_set_header Host $host;
|
| 81 |
proxy_set_header X-Real-IP $remote_addr;
|
xREADME.md
CHANGED
|
@@ -51,8 +51,8 @@ uv run python main.py # 或 python main.py
|
|
| 51 |
|
| 52 |
**首次运行会自动初始化数据库**,访问以下地址:
|
| 53 |
- API 文档:http://localhost:8080/docs
|
| 54 |
-
- 管理后台:http://localhost:
|
| 55 |
-
- Token 管理:http://localhost:
|
| 56 |
|
| 57 |
> ⚠️ **重要**:
|
| 58 |
> - 请妥善保管 `AUTH_TOKEN`,不要泄露给他人
|
|
@@ -154,7 +154,7 @@ logs/ # 日志文件存储目录
|
|
| 154 |
|--------|--------|------|
|
| 155 |
| `AUTH_TOKEN` | `sk-your-api-key` | 客户端访问密钥(必填) |
|
| 156 |
| `ADMIN_PASSWORD` | `admin123` | 管理后台登录密码(**强烈建议修改**) |
|
| 157 |
-
| `LISTEN_PORT` | `
|
| 158 |
| `DEBUG_LOGGING` | `false` | 调试日志(支持热重载) |
|
| 159 |
| `ANONYMOUS_MODE` | `true` | Z.AI 匿名模式 |
|
| 160 |
| `TOOL_SUPPORT` | `true` | Function Call 开关 |
|
|
@@ -175,7 +175,7 @@ logs/ # 日志文件存储目录
|
|
| 175 |
|
| 176 |
### 首次登录
|
| 177 |
|
| 178 |
-
1. 启动服务后访问:http://localhost:
|
| 179 |
2. 自动跳转到登录页面
|
| 180 |
3. 输入管理密码(默认:`admin123`)
|
| 181 |
4. 登录成功后进入仪表盘
|
|
@@ -212,7 +212,7 @@ ADMIN_PASSWORD=Your_Secure_Password_2025!
|
|
| 212 |
python main.py
|
| 213 |
|
| 214 |
# 访问 Web 管理后台
|
| 215 |
-
http://localhost:
|
| 216 |
```
|
| 217 |
|
| 218 |
### 管理后台功能
|
|
|
|
| 51 |
|
| 52 |
**首次运行会自动初始化数据库**,访问以下地址:
|
| 53 |
- API 文档:http://localhost:8080/docs
|
| 54 |
+
- 管理后台:http://localhost:7860/admin(**需要登录**)
|
| 55 |
+
- Token 管理:http://localhost:7860/admin/tokens
|
| 56 |
|
| 57 |
> ⚠️ **重要**:
|
| 58 |
> - 请妥善保管 `AUTH_TOKEN`,不要泄露给他人
|
|
|
|
| 154 |
|--------|--------|------|
|
| 155 |
| `AUTH_TOKEN` | `sk-your-api-key` | 客户端访问密钥(必填) |
|
| 156 |
| `ADMIN_PASSWORD` | `admin123` | 管理后台登录密码(**强烈建议修改**) |
|
| 157 |
+
| `LISTEN_PORT` | `7860` | 服务监听端口 |
|
| 158 |
| `DEBUG_LOGGING` | `false` | 调试日志(支持热重载) |
|
| 159 |
| `ANONYMOUS_MODE` | `true` | Z.AI 匿名模式 |
|
| 160 |
| `TOOL_SUPPORT` | `true` | Function Call 开关 |
|
|
|
|
| 175 |
|
| 176 |
### 首次登录
|
| 177 |
|
| 178 |
+
1. 启动服务后访问:http://localhost:7860/admin
|
| 179 |
2. 自动跳转到登录页面
|
| 180 |
3. 输入管理密码(默认:`admin123`)
|
| 181 |
4. 登录成功后进入仪表盘
|
|
|
|
| 212 |
python main.py
|
| 213 |
|
| 214 |
# 访问 Web 管理后台
|
| 215 |
+
http://localhost:7860/admin
|
| 216 |
```
|
| 217 |
|
| 218 |
### 管理后台功能
|