Files
compute-engine/README.云超服.md
T

88 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# compute-engine(算力引擎 new-api)— 云超服微服务
> 定位:云超服后端服务群中的**算力引擎微服务**。提供 OpenAI 兼容 `/v1` 模型中继 + 额度/令牌/token 流水。
> **仅作服务被消费**(relay /v1 + 程序化管理 API);**其自带的 web 管理页面 / 用户页面不使用**,算力相关管理全部在云超服 admin管理平台(自研)。
> 部署形态:随服务群部署、**不做本地推理**,全部渠道为云厂商代理(OpenAI / DeepSeek / 通义千问 / Claude / Gemini 等),无需 GPU 主机。
> 📍 原位于 `reference/new-api/`,已迁移为本微服务。上游:QuantumNous/new-api(AGPLv3,One API fork)。
---
## 一、启动命令
### 方式 1 · Docker Compose(推荐,含 Redis + 数据库)
```bash
cd code/compute-engine
# 1) 配置(必改:SESSION_SECRET 随机串;生产改 postgres/redis 密码)
cp .env.example .env
# 2) 编辑 docker-compose.yml:
# - ports 改为 "127.0.0.1:3000:3000"(仅本机,不对外暴露)
# - 取消注释 SESSION_SECRET 并填随机值
# - 生产修改 postgres/redis 默认密码
# 3) 启动
docker compose up -d
# 4) 验证
curl http://127.0.0.1:3000/api/status
```
### 方式 2 · SQLite 单容器(开发 / 最小部署)
```bash
cd code/compute-engine
mkdir -p data
docker run --name compute-engine -d --restart always \
-p 127.0.0.1:3000:3000 \
-e TZ=Asia/Shanghai \
-e SESSION_SECRET="$(openssl rand -hex 32)" \
-v "$(pwd)/data:/data" \
calciumion/new-api:latest
```
### 方式 3 · 源码编译(Go 1.22+)
```bash
cd code/compute-engine
go build -o bin/new-api main.go
SQLITE_PATH=./data/new-api.db SESSION_SECRET="$(openssl rand -hex 32)" ./bin/new-api --port 3000
```
---
## 二、server-core 对接
- **算力服务**(server-core 的 `compute_client`,规划中)经 **loopback** 调本引擎:
- 模型中继:`http://127.0.0.1:3000/v1/*`(OpenAI 兼容)
- 管理 API:`http://127.0.0.1:3000/api/*`(建号 / 发 token / 额度调整 / 日志,程序化,管理令牌)
- 引擎不直接暴露给公网 / 前端;前端算力页面经 server-core → 算力服务 → 引擎。
## 三、首次配置(一次性)
引擎首次启动后,需建立初始管理员并添加云厂商渠道(由算力服务程序化完成,或临时用管理 API):
```bash
# 初始化管理员(示例)
curl -X POST http://127.0.0.1:3000/api/setup -H 'Content-Type: application/json' \
-d '{"username":"admin","password":"<强密码>"}'
# 添加渠道(示例:DeepSeek;渠道类型、Key 由算力服务统一管理)
# POST /api/channel 见 docs/
```
> 说明:按「仅服务」原则,云超服不暴露 new-api 自带面板;渠道/额度/用户全部由自研算力服务 + admin管理平台接管。
## 四、环境变量要点
| 变量 | 说明 |
|------|------|
| `SESSION_SECRET` | 鉴权签名密钥,必填(多机需一致) |
| `SQL_DSN` / `SQLITE_PATH` | 主库连接(默认 SQLite) |
| `REDIS_CONN_STRING` | 缓存(推荐开启) |
| `PORT` | 监听端口(默认 3000) |
完整配置见 `.env.example`。