feat: enhance tool call parsing robustness, authentication flexibility, and streaming output for tool content

This commit is contained in:
CJACK
2026-02-16 01:24:52 +08:00
parent bd788a12b1
commit 57f2041edb
14 changed files with 1753 additions and 1519 deletions

115
DEPLOY.md
View File

@@ -1,55 +1,102 @@
# DS2API 部署指南Go 版本
# DS2API 部署指南Go
语言 / Language: [中文](DEPLOY.md) | [English](DEPLOY.en.md)
## 目录
本指南基于当前 Go 代码库。
- Vercel 部署
- Docker 部署
- 本地运行
- systemd 部署
## 部署方式
## Vercel 部署
- 本地运行:`go run ./cmd/ds2api`
- Docker`docker-compose up -d`
- Vercel`api/index.go` serverless 入口
- Linux 服务化systemd
1. 导入仓库到 Vercel
2. 设置环境变量(至少):
- `DS2API_ADMIN_KEY`
- `DS2API_CONFIG_JSON`JSON 或 Base64
3. 部署后访问 `/admin` 管理界面
## 0. 前置要求
说明:项目使用 `api/index.go` 作为 Serverless 入口,配置见 `vercel.json`
- Go 1.25+
- Node.js 20+(仅在需要本地构建 WebUI 时)
- `config.json``DS2API_CONFIG_JSON`
## Docker 部署
## 1. 本地运行
```bash
git clone https://github.com/CJackHwang/ds2api.git
cd ds2api
cp config.example.json config.json
# 编辑 config.json
go run ./cmd/ds2api
```
默认监听 `5001`,可通过 `PORT` 覆盖。
构建 WebUI可选仅当 `/admin` 缺少静态文件时):
```bash
./scripts/build-webui.sh
```
## 2. Docker 部署
```bash
cp .env.example .env
# 编辑 .env
docker-compose up -d
docker-compose logs -f
```
更新后重建
更新镜像
```bash
docker-compose up -d --build
```
## 本地运行
说明:
```bash
cp config.example.json config.json
# 编辑配置
- `Dockerfile` 使用多阶段构建WebUI + Go 二进制)
- 容器内默认启动命令:`/usr/local/bin/ds2api`
go run ./cmd/ds2api
## 3. Vercel 部署
- serverless 入口:`api/index.go`
- 路由与缓存头:`vercel.json`
至少配置环境变量:
- `DS2API_ADMIN_KEY`
- `DS2API_CONFIG_JSON`JSON 或 Base64
可选:
- `VERCEL_TOKEN`
- `VERCEL_PROJECT_ID`
- `VERCEL_TEAM_ID`
部署后建议先访问:
- `/healthz`
- `/v1/models`
- `/admin`
## 4. 反向代理Nginx
如果在 Nginx 后挂载,建议关闭缓冲以保证 SSE
```nginx
location / {
proxy_pass http://127.0.0.1:5001;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding on;
tcp_nodelay on;
}
```
默认端口 `5001`,可通过 `PORT` 环境变量覆盖。
## systemd 部署Linux
示例服务文件:
## 5. systemd 示例Linux
```ini
[Unit]
@@ -61,7 +108,7 @@ Type=simple
WorkingDirectory=/opt/ds2api
Environment=PORT=5001
Environment=DS2API_CONFIG_PATH=/opt/ds2api/config.json
Environment=DS2API_ADMIN_KEY=your-admin-secret-key
Environment=DS2API_ADMIN_KEY=admin
ExecStart=/opt/ds2api/ds2api
Restart=always
RestartSec=5
@@ -78,3 +125,17 @@ sudo systemctl enable ds2api
sudo systemctl start ds2api
sudo systemctl status ds2api
```
## 6. 部署后检查
```bash
curl -s http://127.0.0.1:5001/healthz
curl -s http://127.0.0.1:5001/readyz
curl -s http://127.0.0.1:5001/v1/models
```
如果你依赖管理台接口,再检查:
```bash
curl -s http://127.0.0.1:5001/admin
```