chore: 移除智谱 GLM 供应商(GLM 模型 + CogView/CogVideoX 媒体 + 契约代码/前端/文档/测试全清)
This commit is contained in:
1 parent
44fc4a5e50
commit
520200c005
16 files changed
+71
-280
No files matched your search
@@ -4,6 +4,29 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 2026-09-17 · 移除智谱 GLM(bigmodel)供应商
|
||||||
|
|
||||||
|
**一句话**:老板要求删除智谱供应商,代码/配置/文档/测试/前端全清——覆盖上上轮新增的 6 个 GLM 文本模型(含 3 视觉)、CogView-3-Flash 文生图、CogVideoX-Flash 文生视频及配套的媒体契约代码。
|
||||||
|
|
||||||
|
### 改动清单(除 CHANGELOG 历史条目外全部清零)
|
||||||
|
- **`data/gateway.yaml`**:删 `providers.bigmodel` 整块(`GLM-4.7-Flash`/`GLM-4-Flash-250414`/`GLM-Z1-Flash`/`GLM-4.6V-Flash`/`GLM-4V-Flash`/`GLM-4.1V-Thinking-Flash` 6 文本 + `cogview-3-flash` 图像 + `cogvideox-flash` 视频 + 整套 media 配置);`download.allowed_hosts` 删智谱 CDN 项(`maas-watermark-prod-new.cn-wlcb.ufileos.com`);头注释供应商列表 → `Agnes / 火山方舟 Coding`。`routes.wjd`、`pricing` 本就不含智谱,无需动。
|
||||||
|
- **`data/.env`**:删 `ZHIPU_API_KEY`。
|
||||||
|
- **`app/config.py`**:`MediaConfig` 删 `video_style` / `video_default_size` 两个字段及其解析(智谱视频契约专用)。
|
||||||
|
- **`app/main.py`**:`_ZHIPU_VIDEO_SIZES` 常量删;`_validate_video_request` 删 zhipu 分支、恢复单参数 `(req)`、docstring 去"接入其它视频供应商";`videos_create` 恢复"先入站校验后解析"原顺序(去掉按供应商媒体契约分流);`_video_status` 改通用描述(去智谱词,状态优先级 status/state/task_status);`description` → `(Agnes / 火山方舟)`。
|
||||||
|
- **`app/settings.py`**:面板 `MEDIA_KEYS` 删 `video_style` / `video_default_size`。
|
||||||
|
- **`app/adapters/{__init__,openai_compat}.py`**:docstring「三家」→「两家」;`create_video` / `poll_video` 删 zhipu 分支(恢复纯 Agnes 风格);删 `urllib.parse.quote` 导入。
|
||||||
|
- **前端**:`Settings.vue` `TEXT_MODELS` 去 6 个 GLM;`Videos.vue` 删智谱视频专用表单/状态/`watch`/create 分支,恢复 Agnes 表单;`Images.vue` 删 cogview 像素档/`isZhipu`/参考图与 ratio 的 `v-if`;`locales/{zh,en}.ts` 删 `videos.z*`(7 键/语言);`media.ts` `findVideoUrl` 优先键去 `video_result`。
|
||||||
|
- **`README.md`** / **`docs/frontend-design.md`**:供应商改两家,删智谱供应商表行、`.env` 说明去 `ZHIPU_API_KEY`。
|
||||||
|
- **`tests/test_gateway.py`**:`test_load_config_providers` 账号集合→`{agnes,volc_engine}`、删智谱媒体断言;速度排序测试用 `[ark-code-latest,agnes-3.0-flash]` 两模型演示(删 GLM);`test_vision_first` 用 `agnes-3.0-flash`(vision)当视觉样例;媒体路由别名测试/配置写回测试/视频轮询测试改用真实模型或恢复原样。
|
||||||
|
|
||||||
|
### 验证 / 上线
|
||||||
|
- 单测 **155 passed / 0 failed**;全项目 grep `智谱|bigmodel|GLM|cogview|cogvideox|ufileos|ZHIPU|zhipu|video_style|_ZHIPU` 除 CHANGELOG 历史外**全部清零**。
|
||||||
|
- 前端 `npm run build` 过(typecheck + i18n 对称),新入口 `index-BynIw5Ue.js`。
|
||||||
|
- 配置校验:providers `[agnes,volc_engine]`、模型 `agnes[3] + volc[1]`、`routes.wjd` 2 项、下载白名单仅 Agnes。
|
||||||
|
- `supervisorctl restart api-gateway:api-gateway_00` 上线(`description`/适配器/校验等属代码改动,需重启)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 2026-09-17 · 移除 b.ai 供应商
|
## 2026-09-17 · 移除 b.ai 供应商
|
||||||
|
|
||||||
**一句话**:老板要求删除 b.ai 供应商及其两个模型(`qwen3.8-flash`、`hy3`),代码、配置、文档、测试全清。
|
**一句话**:老板要求删除 b.ai 供应商及其两个模型(`qwen3.8-flash`、`hy3`),代码、配置、文档、测试全清。
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# API Gateway
|
# API Gateway
|
||||||
|
|
||||||
统一多供应商 LLM 接入网关,纯后端 FastAPI,配置驱动。支持 **Agnes AI**、**火山方舟 Coding Plan**、**智谱 GLM** 三个供应商,全部走 OpenAI 兼容协议。v2.4 已集成熔断、限流、图像/视频、指标、成本估算、热加载、测试等完整能力。
|
统一多供应商 LLM 接入网关,纯后端 FastAPI,配置驱动。支持 **Agnes AI**、**火山方舟 Coding Plan** 两个供应商,全部走 OpenAI 兼容协议。v2.4 已集成熔断、限流、图像/视频、指标、成本估算、热加载、测试等完整能力。
|
||||||
|
|
||||||
## 特性
|
## 特性
|
||||||
|
|
||||||
@@ -45,7 +45,6 @@ api-gateway/
|
|||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| Agnes AI | `https://api.agnes-ai.cn/v1` | Bearer | `agnes-3.0-flash`(text)、`agnes-image-2.5-flash`(image)、`agnes-video-2.5-flash`(video) |
|
| Agnes AI | `https://api.agnes-ai.cn/v1` | Bearer | `agnes-3.0-flash`(text)、`agnes-image-2.5-flash`(image)、`agnes-video-2.5-flash`(video) |
|
||||||
| 火山方舟 Coding | `https://ark.cn-beijing.volces.com/api/coding/v3` | Bearer | `ark-code-latest`(text) |
|
| 火山方舟 Coding | `https://ark.cn-beijing.volces.com/api/coding/v3` | Bearer | `ark-code-latest`(text) |
|
||||||
| 智谱 GLM | `https://open.bigmodel.cn/api/paas/v4` | Bearer | 文本:`GLM-4.7-Flash`、`GLM-4-Flash-250414`、`GLM-Z1-Flash`、`GLM-4.6V-Flash`、`GLM-4V-Flash`、`GLM-4.1V-Thinking-Flash`(其中 3 个 V 型号支持图像输入);图像:`cogview-3-flash`;视频:`cogvideox-flash`(文生视频,异步 `/videos/generations` + `/async-result/{id}` 轮询) |
|
|
||||||
|
|
||||||
> Agnes 的图像/视频走自有端点,通过供应商配置里的 `media` 段指定。
|
> Agnes 的图像/视频走自有端点,通过供应商配置里的 `media` 段指定。
|
||||||
|
|
||||||
@@ -297,7 +296,7 @@ python run.py # 默认读 data/gateway.yaml,端口 8808
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
# 编辑 .env 填入 AGNES_API_KEY / VOLC_API_KEY / ZHIPU_API_KEY
|
# 编辑 .env 填入 AGNES_API_KEY / VOLC_API_KEY
|
||||||
python run.py # 启动时自动读取 .env
|
python run.py # 启动时自动读取 .env
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ def create_adapter(
|
|||||||
) -> BaseAdapter:
|
) -> BaseAdapter:
|
||||||
"""根据供应商配置创建对应适配器。
|
"""根据供应商配置创建对应适配器。
|
||||||
|
|
||||||
当前三个供应商(Agnes / 火山方舟 / 智谱 GLM)均为 OpenAI 兼容协议,
|
当前两个供应商(Agnes / 火山方舟)均为 OpenAI 兼容协议,
|
||||||
统一使用 OpenAICompatAdapter,通过 base_url 和 extra_headers 区分。
|
统一使用 OpenAICompatAdapter,通过 base_url 和 extra_headers 区分。
|
||||||
图像/视频端点通过 media 配置覆盖(Agnes 走 /videos + /agnesapi)。
|
图像/视频端点通过 media 配置覆盖(Agnes 走 /videos + /agnesapi)。
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""OpenAI 兼容协议适配器。
|
"""OpenAI 兼容协议适配器。
|
||||||
|
|
||||||
Agnes / 火山方舟 / 智谱 GLM 三家均使用 OpenAI 兼容 API
|
Agnes / 火山方舟 两家均使用 OpenAI 兼容 API
|
||||||
(POST {base_url}/chat/completions),本适配器统一处理。
|
(POST {base_url}/chat/completions),本适配器统一处理。
|
||||||
|
|
||||||
图像/视频端点可通过 media 配置覆盖:
|
图像/视频端点可通过 media 配置覆盖:
|
||||||
@@ -12,7 +12,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
from typing import Any, AsyncIterator
|
from typing import Any, AsyncIterator
|
||||||
from urllib.parse import quote
|
|
||||||
|
|
||||||
|
|
||||||
from app.adapters.base import BaseAdapter, json_or_raise
|
from app.adapters.base import BaseAdapter, json_or_raise
|
||||||
@@ -185,26 +184,7 @@ class OpenAICompatAdapter(BaseAdapter):
|
|||||||
size: str = "720P",
|
size: str = "720P",
|
||||||
extra: dict[str, Any] | None = None,
|
extra: dict[str, Any] | None = None,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
# 智谱视频契约:POST /videos/generations(异步)——参数为 quality/with_audio/fps/像素 size,
|
# ── Agnes 风格:POST {base}/videos,seconds/mode/size/aspect_ratio/n ──
|
||||||
# 不需要 agnes 的 seconds/mode/aspect_ratio/n。
|
|
||||||
if self.media.video_style == "zhipu":
|
|
||||||
endpoint = self.media.video_create_endpoint or "/videos/generations"
|
|
||||||
x = extra or {}
|
|
||||||
payload: dict[str, Any] = {
|
|
||||||
"model": model,
|
|
||||||
"prompt": prompt,
|
|
||||||
"size": size or self.media.video_default_size or "1920x1080",
|
|
||||||
"quality": x.get("quality") or "speed",
|
|
||||||
"fps": int(x.get("fps") or 30),
|
|
||||||
"with_audio": bool(x.get("with_audio") or False),
|
|
||||||
}
|
|
||||||
async with self._lease() as client:
|
|
||||||
resp = await client.post(endpoint, json=payload, headers=self._headers)
|
|
||||||
resp.raise_for_status()
|
|
||||||
data = json_or_raise(resp)
|
|
||||||
return {"video_id": data.get("id") or data.get("request_id") or data.get("task_id"),
|
|
||||||
"raw": data}
|
|
||||||
# ── Agnes 风格(默认):POST {base}/videos,seconds/mode/size/aspect_ratio/n ──
|
|
||||||
endpoint = self.media.video_create_endpoint or "/videos"
|
endpoint = self.media.video_create_endpoint or "/videos"
|
||||||
payload: dict[str, Any] = {
|
payload: dict[str, Any] = {
|
||||||
"model": model,
|
"model": model,
|
||||||
@@ -232,17 +212,6 @@ class OpenAICompatAdapter(BaseAdapter):
|
|||||||
|
|
||||||
# ── 视频轮询 ────────────────────────────────────
|
# ── 视频轮询 ────────────────────────────────────
|
||||||
async def poll_video(self, video_id: str, model: str = "", extra: dict[str, Any] | None = None) -> dict[str, Any]:
|
async def poll_video(self, video_id: str, model: str = "", extra: dict[str, Any] | None = None) -> dict[str, Any]:
|
||||||
# 智谱视频异步查询:GET {poll_base}/async-result/{video_id}(路径参数,无 query)
|
|
||||||
if self.media.video_style == "zhipu":
|
|
||||||
pb = (self.media.video_poll_base or self.base_url).rstrip("/")
|
|
||||||
pp = (self.media.video_poll_path or "/async-result").rstrip("/")
|
|
||||||
url = f"{pb}{pp}/{quote(str(video_id), safe='')}"
|
|
||||||
async with self._lease() as client:
|
|
||||||
resp = await client.get(url, headers=self._headers)
|
|
||||||
resp.raise_for_status()
|
|
||||||
data = json_or_raise(resp)
|
|
||||||
return {"raw": data}
|
|
||||||
|
|
||||||
mname = self.media.video_model_name or model or ""
|
mname = self.media.video_model_name or model or ""
|
||||||
poll_base = self.media.video_poll_base or self.base_url
|
poll_base = self.media.video_poll_base or self.base_url
|
||||||
poll_path = self.media.video_poll_path or "/agnesapi"
|
poll_path = self.media.video_poll_path or "/agnesapi"
|
||||||
|
|||||||
+1
-5
@@ -54,9 +54,7 @@ class MediaConfig:
|
|||||||
video_create_endpoint: str | None = None # 相对 base_url,默认 /videos
|
video_create_endpoint: str | None = None # 相对 base_url,默认 /videos
|
||||||
video_poll_base: str | None = None # 绝对 base(视频查询,默认同 base_url 去掉 /v1)
|
video_poll_base: str | None = None # 绝对 base(视频查询,默认同 base_url 去掉 /v1)
|
||||||
video_poll_path: str | None = None # 默认 /agnesapi(Agnes)
|
video_poll_path: str | None = None # 默认 /agnesapi(Agnes)
|
||||||
video_model_name: str | None = None # 轮询用的 model_name 参数(Agnes)
|
video_model_name: str | None = None # 轮询用的 model_name 参数
|
||||||
video_style: str | None = None # 视频契约风格:"zhipu"=智谱异步(videos/generations + /async-result/{id});None=Agnes 风格
|
|
||||||
video_default_size: str | None = None # 视频默认尺寸(智谱为像素串如 1920x1080;Agnes 用 size 档位)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supports_image(self) -> bool:
|
def supports_image(self) -> bool:
|
||||||
@@ -306,8 +304,6 @@ def _parse_media(pval: dict[str, Any]) -> MediaConfig:
|
|||||||
video_poll_base=m.get("video_poll_base"),
|
video_poll_base=m.get("video_poll_base"),
|
||||||
video_poll_path=m.get("video_poll_path"),
|
video_poll_path=m.get("video_poll_path"),
|
||||||
video_model_name=m.get("video_model_name"),
|
video_model_name=m.get("video_model_name"),
|
||||||
video_style=m.get("video_style"),
|
|
||||||
video_default_size=m.get("video_default_size"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+7
-42
@@ -307,7 +307,7 @@ VERSION = "2.4.0"
|
|||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="API Gateway",
|
title="API Gateway",
|
||||||
description="统一多供应商 LLM 接入网关(Agnes / 火山方舟 / 智谱 GLM)",
|
description="统一多供应商 LLM 接入网关(Agnes / 火山方舟)",
|
||||||
version=VERSION,
|
version=VERSION,
|
||||||
lifespan=lifespan,
|
lifespan=lifespan,
|
||||||
default_response_class=UTF8JSONResponse,
|
default_response_class=UTF8JSONResponse,
|
||||||
@@ -1767,11 +1767,11 @@ _VIDEO_ASPECTS = ("21:9", "16:9", "4:3", "1:1", "3:4", "9:16")
|
|||||||
def _video_status(raw: dict | None) -> str:
|
def _video_status(raw: dict | None) -> str:
|
||||||
"""视频原始返回的状态取法(统一小写)。
|
"""视频原始返回的状态取法(统一小写)。
|
||||||
|
|
||||||
智谱异步结果是 task_status(PROCESSING/SUCCESS/FAIL),Agnes 用 status / state。
|
Agnes 轮询返回用 status / state;保留 task_status 兼容(未来其它视频供应商可能用到)。
|
||||||
"""
|
"""
|
||||||
if not raw:
|
if not raw:
|
||||||
return ""
|
return ""
|
||||||
return str(raw.get("task_status") or raw.get("status") or raw.get("state") or "").lower()
|
return str(raw.get("status") or raw.get("state") or raw.get("task_status") or "").lower()
|
||||||
|
|
||||||
|
|
||||||
def _video_terminal(status: str) -> bool:
|
def _video_terminal(status: str) -> bool:
|
||||||
@@ -1781,46 +1781,12 @@ def _video_terminal(status: str) -> bool:
|
|||||||
"failed", "fail", "error", "cancelled", "canceled")
|
"failed", "fail", "error", "cancelled", "canceled")
|
||||||
|
|
||||||
|
|
||||||
# 智谱 CogVideoX-Flash 支持的分辨率(像素串),与 Agnes 的 720P 档位语义不同。
|
def _validate_video_request(req) -> None:
|
||||||
_ZHIPU_VIDEO_SIZES = {
|
|
||||||
"720x480", "1024x1024", "1280x960", "960x1280",
|
|
||||||
"1920x1080", "1080x1920", "2048x1080",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _validate_video_request(req, media=None) -> None:
|
|
||||||
"""第十一轮 #3:按 Agnes Video 2.5 契约做**入站校验**,把明显不合法的 mode/媒体/时长
|
"""第十一轮 #3:按 Agnes Video 2.5 契约做**入站校验**,把明显不合法的 mode/媒体/时长
|
||||||
组合在网关挡下并回**干净 400**(不再白发上游浪费限流额度,也不进熔断)。
|
组合在网关挡下并回**干净 400**(不再白发上游浪费限流额度,也不进熔断)。
|
||||||
第十三轮补齐 size / aspect_ratio / n / videos 四项(文档「Flash 专属错误」与
|
第十三轮补齐 size / aspect_ratio / n / videos 四项(文档「Flash 专属错误」与
|
||||||
「生成模式规则」里明确列出的限制),并保留原有 mode/媒体/时长校验。
|
「生成模式规则」里明确列出的限制),并保留原有 mode/媒体/时长校验。
|
||||||
目前只有 Agnes 配了视频,字段语义按它的文档来;接入其它视频供应商时需按各家契约放宽。"""
|
目前只有 Agnes 配了视频,字段语义按它的文档来。"""
|
||||||
|
|
||||||
# ── 智谱 CogVideoX(CogVideoX-Flash):仅 text 文生视频;quality/fps/with_audio 走 req.extra ──
|
|
||||||
if media is not None and media.video_style == "zhipu":
|
|
||||||
if (req.mode or "text") != "text":
|
|
||||||
raise HTTPException(400, "智谱视频(CogVideoX)仅支持 text 文生视频模式")
|
|
||||||
if int(req.n or 1) != 1:
|
|
||||||
raise HTTPException(400, "视频接口一次只提交 1 个任务(n 必须为 1,收到 %s)" % req.n)
|
|
||||||
if req.videos or req.images or req.audios or req.first_frame or req.last_frame:
|
|
||||||
raise HTTPException(400, "智谱视频不支持首尾帧 / 参考图 / 参考音频(文生视频只填 prompt)")
|
|
||||||
if req.size and req.size not in _ZHIPU_VIDEO_SIZES:
|
|
||||||
raise HTTPException(400, "智谱视频 size 仅支持 %s,收到 %r" %
|
|
||||||
("/".join(sorted(_ZHIPU_VIDEO_SIZES)), req.size))
|
|
||||||
_x = req.extra or {}
|
|
||||||
_q = _x.get("quality")
|
|
||||||
if _q is not None and _q not in ("speed", "quality"):
|
|
||||||
raise HTTPException(400, "智谱视频 quality 仅支持 speed / quality,收到 %r" % _q)
|
|
||||||
_f = _x.get("fps")
|
|
||||||
if _f is not None:
|
|
||||||
try:
|
|
||||||
_fi = int(_f)
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
_fi = -1
|
|
||||||
if _fi not in (30, 60):
|
|
||||||
raise HTTPException(400, "智谱视频 fps 仅支持 30 / 60,收到 %r" % _f)
|
|
||||||
return
|
|
||||||
|
|
||||||
# ── Agnes 契约(默认)───────────────────────────────
|
|
||||||
mode = req.mode or "text"
|
mode = req.mode or "text"
|
||||||
if mode not in _VIDEO_MODES:
|
if mode not in _VIDEO_MODES:
|
||||||
raise HTTPException(400, f"视频 mode 仅支持 {'/'.join(_VIDEO_MODES)},收到 {mode!r}")
|
raise HTTPException(400, f"视频 mode 仅支持 {'/'.join(_VIDEO_MODES)},收到 {mode!r}")
|
||||||
@@ -1862,13 +1828,12 @@ async def videos_create(request: Request, req: VideoCreateRequestExtended, _auth
|
|||||||
cfg = _cfg()
|
cfg = _cfg()
|
||||||
rid = getattr(request.state, "rid", "-")
|
rid = getattr(request.state, "rid", "-")
|
||||||
caller = getattr(request.state, "caller", "anonymous")
|
caller = getattr(request.state, "caller", "anonymous")
|
||||||
# Bug 4: 支持路由别名(如 wjd)→ 解析到第一个 type==video 的模型。
|
_validate_video_request(req) # 第十一轮 #3:入站按 Agnes 契约校验 mode/媒体/时长
|
||||||
# 解析放在入站校验之前,好让 _validate_video_request 按供应商媒体契约(Agnes / 智谱)分流。
|
# Bug 4: 支持路由别名(如 wjd)→ 解析到第一个 type==video 的模型
|
||||||
resolved = _resolve_media_model(cfg, req.model, "video")
|
resolved = _resolve_media_model(cfg, req.model, "video")
|
||||||
if resolved is None:
|
if resolved is None:
|
||||||
raise HTTPException(404, f"未知视频模型/路由: {req.model}(没有可用的 video 类型模型)")
|
raise HTTPException(404, f"未知视频模型/路由: {req.model}(没有可用的 video 类型模型)")
|
||||||
pkey, pconfig, minfo, token, real_model = resolved
|
pkey, pconfig, minfo, token, real_model = resolved
|
||||||
_validate_video_request(req, pconfig.media) # 入站按供应商媒体契约校验
|
|
||||||
# 顺序修复(本轮):先能力检查(501),再校验回调地址(400),最后限流 —— 避免无效请求白扣 token。
|
# 顺序修复(本轮):先能力检查(501),再校验回调地址(400),最后限流 —— 避免无效请求白扣 token。
|
||||||
if not pconfig.media.supports_video:
|
if not pconfig.media.supports_video:
|
||||||
raise HTTPException(501, f"供应商 {pconfig.name} 不支持视频创建")
|
raise HTTPException(501, f"供应商 {pconfig.name} 不支持视频创建")
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ MEDIA_KEYS = (
|
|||||||
"video_poll_base",
|
"video_poll_base",
|
||||||
"video_poll_path",
|
"video_poll_path",
|
||||||
"video_model_name",
|
"video_model_name",
|
||||||
"video_style",
|
|
||||||
"video_default_size",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
MODEL_TYPES = ("text", "image", "video")
|
MODEL_TYPES = ("text", "image", "video")
|
||||||
|
|||||||
+1
-55
@@ -1,5 +1,5 @@
|
|||||||
# AI 网关配置文件(data/ 目录)
|
# AI 网关配置文件(data/ 目录)
|
||||||
# 供应商:Agnes / 火山方舟 Coding / 智谱 GLM(bigmodel)
|
# 供应商:Agnes / 火山方舟 Coding
|
||||||
# 密钥统一走 token_env 指向的环境变量(本机见 data/.env),不再在 yaml 存明文
|
# 密钥统一走 token_env 指向的环境变量(本机见 data/.env),不再在 yaml 存明文
|
||||||
# 端口默认 8808
|
# 端口默认 8808
|
||||||
#
|
#
|
||||||
@@ -45,59 +45,6 @@ providers:
|
|||||||
- id: "ark-code-latest"
|
- id: "ark-code-latest"
|
||||||
display_name: "火山方舟 ark-code-latest"
|
display_name: "火山方舟 ark-code-latest"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
|
||||||
# ── 智谱 GLM(OpenAI 兼容 /chat/completions)──────────
|
|
||||||
# 密钥走 token_env(data/.env → ZHIPU_API_KEY),不在 yaml 存明文。
|
|
||||||
# Flash 系文本模型免费档可用;GLM-4V/4.6V/4.1V 系支持「图像输入」:
|
|
||||||
# 已用 200×200 红图真图实测 4V-Flash 与 4.1V-Thinking-Flash 均认出「红色」;
|
|
||||||
# 4.6V-Flash 实侧遇上游瞬时过载(1305)未取到视觉结果,型号带 V 故仍标 vision。
|
|
||||||
bigmodel:
|
|
||||||
name: "智谱 GLM"
|
|
||||||
base_url: "https://open.bigmodel.cn/api/paas/v4"
|
|
||||||
auth:
|
|
||||||
token_env: "ZHIPU_API_KEY"
|
|
||||||
extra_headers: {}
|
|
||||||
# 智谱媒体生成(openai 兼容 + 异步查询):
|
|
||||||
# - 图像 cogview-3-flash:POST /images/generations,size 为像素档,返回 data[].url
|
|
||||||
# - 视频 cogvideox-flash:POST /videos/generations(异步),GET /async-result/{id} 轮询;
|
|
||||||
# 完成时 task_status=SUCCESS、video_result[].url。
|
|
||||||
# video_style: zhipu 让适配器按智谱契约构造视频 payload 与轮询路径(不走 agnes 那套 seconds/mode/aspect)。
|
|
||||||
media:
|
|
||||||
image_endpoint: "/images/generations"
|
|
||||||
image_default_size: "1024x1024"
|
|
||||||
video_create_endpoint: "/videos/generations"
|
|
||||||
video_poll_base: "https://open.bigmodel.cn/api/paas/v4"
|
|
||||||
video_poll_path: "/async-result"
|
|
||||||
video_style: "zhipu"
|
|
||||||
video_default_size: "1920x1080"
|
|
||||||
models:
|
|
||||||
- id: "GLM-4.7-Flash"
|
|
||||||
display_name: "GLM-4.7-Flash"
|
|
||||||
type: "text"
|
|
||||||
- id: "GLM-4-Flash-250414"
|
|
||||||
display_name: "GLM-4-Flash-250414"
|
|
||||||
type: "text"
|
|
||||||
- id: "GLM-Z1-Flash"
|
|
||||||
display_name: "GLM-Z1-Flash"
|
|
||||||
type: "text"
|
|
||||||
- id: "GLM-4.6V-Flash"
|
|
||||||
display_name: "GLM-4.6V-Flash"
|
|
||||||
type: "text"
|
|
||||||
vision: true
|
|
||||||
- id: "GLM-4V-Flash"
|
|
||||||
display_name: "GLM-4V-Flash"
|
|
||||||
type: "text"
|
|
||||||
vision: true
|
|
||||||
- id: "GLM-4.1V-Thinking-Flash"
|
|
||||||
display_name: "GLM-4.1V-Thinking-Flash"
|
|
||||||
type: "text"
|
|
||||||
vision: true
|
|
||||||
- id: "cogview-3-flash"
|
|
||||||
display_name: "CogView-3-Flash"
|
|
||||||
type: "image"
|
|
||||||
- id: "cogvideox-flash"
|
|
||||||
display_name: "CogVideoX-Flash"
|
|
||||||
type: "video"
|
|
||||||
server:
|
server:
|
||||||
host: "127.0.0.1"
|
host: "127.0.0.1"
|
||||||
port: 8808
|
port: 8808
|
||||||
@@ -151,7 +98,6 @@ pricing:
|
|||||||
download:
|
download:
|
||||||
allowed_hosts:
|
allowed_hosts:
|
||||||
- "cos-platform-outputs.agnes-ai.cn" # Agnes 图像/视频产物 CDN
|
- "cos-platform-outputs.agnes-ai.cn" # Agnes 图像/视频产物 CDN
|
||||||
- "maas-watermark-prod-new.cn-wlcb.ufileos.com" # 智谱 CogView 图像 / CogVideoX 视频产物 CDN(UCloud)
|
|
||||||
max_bytes: 67108864 # 单文件上限 64MB
|
max_bytes: 67108864 # 单文件上限 64MB
|
||||||
|
|
||||||
# ── 网关入口鉴权 ─────────────────────────────────────
|
# ── 网关入口鉴权 ─────────────────────────────────────
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
## 1. 背景与目标
|
## 1. 背景与目标
|
||||||
|
|
||||||
网关是一个 OpenAI 兼容的多供应商 LLM 统一接入层(Agnes / 火山方舟 / 智谱 GLM),已具备完整 REST 能力(对话/图像/视频/批量/模型/指标/日志/健康)。当前**只能通过 curl / 二次开发调用,没有可视化界面**。
|
网关是一个 OpenAI 兼容的多供应商 LLM 统一接入层(Agnes / 火山方舟),已具备完整 REST 能力(对话/图像/视频/批量/模型/指标/日志/健康)。当前**只能通过 curl / 二次开发调用,没有可视化界面**。
|
||||||
|
|
||||||
本前端目标是给这台网关做一个**单页管理台(SPA)**:
|
本前端目标是给这台网关做一个**单页管理台(SPA)**:
|
||||||
1. 「用」—— 对话、图像、视频、批量,测试各种模型与降级行为;
|
1. 「用」—— 对话、图像、视频、批量,测试各种模型与降级行为;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export function findVideoUrl(obj: any): string {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
if (typeof obj === 'object') {
|
if (typeof obj === 'object') {
|
||||||
for (const k of ['video_result', 'video_url', 'play_url', 'url', 'html_url', 'video', 'media_url', 'result', 'data', 'mp4']) {
|
for (const k of ['video_url', 'play_url', 'url', 'html_url', 'video', 'media_url', 'result', 'data', 'mp4']) {
|
||||||
if (k in obj) { const u = findVideoUrl(obj[k]); if (u) return u }
|
if (k in obj) { const u = findVideoUrl(obj[k]); if (u) return u }
|
||||||
}
|
}
|
||||||
for (const v of Object.values(obj)) { const u = findVideoUrl(v); if (u) return u }
|
for (const v of Object.values(obj)) { const u = findVideoUrl(v); if (u) return u }
|
||||||
|
|||||||
@@ -303,13 +303,6 @@ export default {
|
|||||||
videos: {
|
videos: {
|
||||||
taskTitle: 'Tasks',
|
taskTitle: 'Tasks',
|
||||||
fixed: 'Fixed',
|
fixed: 'Fixed',
|
||||||
zSize: 'Resolution',
|
|
||||||
zQuality: 'Quality',
|
|
||||||
zSpeed: 'Speed first',
|
|
||||||
zQualityHigh: 'Quality first',
|
|
||||||
zFps: 'FPS',
|
|
||||||
zAudio: 'Audio',
|
|
||||||
zTip: 'Zhipu CogVideoX supports text-to-video only (text mode); generation takes a while, please wait.',
|
|
||||||
title: 'Video generation',
|
title: 'Video generation',
|
||||||
model: 'Video model',
|
model: 'Video model',
|
||||||
mode: 'Scenario',
|
mode: 'Scenario',
|
||||||
|
|||||||
@@ -303,13 +303,6 @@ export default {
|
|||||||
videos: {
|
videos: {
|
||||||
taskTitle: '任务列表',
|
taskTitle: '任务列表',
|
||||||
fixed: '固定',
|
fixed: '固定',
|
||||||
zSize: '分辨率',
|
|
||||||
zQuality: '质量',
|
|
||||||
zSpeed: '速度优先',
|
|
||||||
zQualityHigh: '质量优先',
|
|
||||||
zFps: '帧率',
|
|
||||||
zAudio: '配音',
|
|
||||||
zTip: '智谱 CogVideoX 仅支持文生视频(text 模式);生成耗时较长,请耐心等待。',
|
|
||||||
title: '视频生成',
|
title: '视频生成',
|
||||||
model: '视频模型',
|
model: '视频模型',
|
||||||
mode: '场景',
|
mode: '场景',
|
||||||
|
|||||||
@@ -14,10 +14,10 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<label>{{ t('images.size') }}</label>
|
<label>{{ t('images.size') }}</label>
|
||||||
<el-select v-model="size" class="fill">
|
<el-select v-model="size" class="fill">
|
||||||
<el-option v-for="s in displaySizes" :key="s" :value="s" :label="s" />
|
<el-option v-for="s in sizes" :key="s" :value="s" :label="s" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!isZhipu" class="field">
|
<div class="field">
|
||||||
<label>{{ t('images.ratio') }}</label>
|
<label>{{ t('images.ratio') }}</label>
|
||||||
<el-select v-model="ratio" class="fill">
|
<el-select v-model="ratio" class="fill">
|
||||||
<el-option v-for="r in ratios" :key="r" :value="r" :label="r" />
|
<el-option v-for="r in ratios" :key="r" :value="r" :label="r" />
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="!isZhipu" class="field mb-field">
|
<div class="field mb-field">
|
||||||
<label>{{ t('images.refsLabel') }}</label>
|
<label>{{ t('images.refsLabel') }}</label>
|
||||||
<!-- 第十三轮:图生图 / 多图合成 —— 支持直接上传(浏览器内压成 data URI),也支持粘 URL -->
|
<!-- 第十三轮:图生图 / 多图合成 —— 支持直接上传(浏览器内压成 data URI),也支持粘 URL -->
|
||||||
<div class="ref-btns">
|
<div class="ref-btns">
|
||||||
@@ -166,22 +166,8 @@ const models = ref<any[]>([])
|
|||||||
const model = ref('')
|
const model = ref('')
|
||||||
const sizes = ['1K', '2K', '3K', '4K']
|
const sizes = ['1K', '2K', '3K', '4K']
|
||||||
const ratios = ['1:1', '3:4', '4:3', '16:9', '9:16', '2:3', '3:2', '21:9']
|
const ratios = ['1:1', '3:4', '4:3', '16:9', '9:16', '2:3', '3:2', '21:9']
|
||||||
// 智谱 CogView-3-Flash:文生图,size 用像素档、天然无 ratio、不支持参考图(图生图)
|
|
||||||
const zhipuSizes = ['1024x1024', '768x1344', '864x1152', '1344x768', '1152x864', '1440x720', '720x1440']
|
|
||||||
const isZhipu = computed(() => models.value.find((m: any) => m.id === model.value)?.provider === 'bigmodel')
|
|
||||||
const displaySizes = computed(() => (isZhipu.value ? zhipuSizes : sizes))
|
|
||||||
const size = ref('1K')
|
const size = ref('1K')
|
||||||
const ratio = ref('1:1')
|
const ratio = ref('1:1')
|
||||||
watch(model, (m) => {
|
|
||||||
const mo = models.value.find((x: any) => x.id === m)
|
|
||||||
const z = mo?.provider === 'bigmodel'
|
|
||||||
if (z) {
|
|
||||||
if (!zhipuSizes.includes(size.value)) size.value = '1024x1024'
|
|
||||||
ratio.value = '' // cogview 的宽高由 size 像素档决定,无 ratio
|
|
||||||
} else if (ratio.value === '') {
|
|
||||||
ratio.value = '1:1'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const count = ref(1) // 逐张生成:每张一次请求(上游 n 必须为 1)
|
const count = ref(1) // 逐张生成:每张一次请求(上游 n 必须为 1)
|
||||||
const prompt = ref('')
|
const prompt = ref('')
|
||||||
// 参考图(图生图 / 多图合成):上传的走 data URI,URL 的直接透传,两类可混用
|
// 参考图(图生图 / 多图合成):上传的走 data URI,URL 的直接透传,两类可混用
|
||||||
@@ -288,8 +274,8 @@ async function generate() {
|
|||||||
progress.value = i
|
progress.value = i
|
||||||
const t0 = performance.now()
|
const t0 = performance.now()
|
||||||
// 上游图像接口的 n 必须为 1:多张就在这里逐张调用,每张出来就上屏(进度可见)
|
// 上游图像接口的 n 必须为 1:多张就在这里逐张调用,每张出来就上屏(进度可见)
|
||||||
const body: any = { model: model.value, prompt: prompt.value, size: size.value, ratio: isZhipu.value ? '' : ratio.value, n: 1 }
|
const body: any = { model: model.value, prompt: prompt.value, size: size.value, ratio: ratio.value, n: 1 }
|
||||||
if (list.length && !isZhipu.value) body.image = list // 图生图 / 多图合成(网关转成上游的 extra_body.image)
|
if (list.length) body.image = list // 图生图 / 多图合成(网关转成上游的 extra_body.image)
|
||||||
const j = await api('/v1/images/generations', { method: 'POST', body: JSON.stringify(body) })
|
const j = await api('/v1/images/generations', { method: 'POST', body: JSON.stringify(body) })
|
||||||
const ms = (performance.now() - t0) | 0
|
const ms = (performance.now() - t0) | 0
|
||||||
providerName.value = j.provider_name || j.provider || ''
|
providerName.value = j.provider_name || j.provider || ''
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ const err = ref('')
|
|||||||
const { t, locale } = useI18n()
|
const { t, locale } = useI18n()
|
||||||
const { theme, followSystem, setTheme, setFollowSystem } = useTheme()
|
const { theme, followSystem, setTheme, setFollowSystem } = useTheme()
|
||||||
|
|
||||||
const TEXT_MODELS = ['wjd', 'agnes-3.0-flash', 'ark-code-latest', 'GLM-4.7-Flash', 'GLM-4-Flash-250414', 'GLM-Z1-Flash', 'GLM-4.6V-Flash', 'GLM-4V-Flash', 'GLM-4.1V-Thinking-Flash']
|
const TEXT_MODELS = ['wjd', 'agnes-3.0-flash', 'ark-code-latest']
|
||||||
const textModels = ref<string[]>(TEXT_MODELS)
|
const textModels = ref<string[]>(TEXT_MODELS)
|
||||||
|
|
||||||
function pickTheme(id: ThemeId) {
|
function pickTheme(id: ThemeId) {
|
||||||
|
|||||||
@@ -10,8 +10,6 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 智谱 CogVideoX-Flash / Agnes 两种视频契约:Agnes 用模式+时长+720P;智谱用 quality/fps/audio/像素 size -->
|
|
||||||
<template v-if="!isZhipu">
|
|
||||||
<!-- 第十一轮 #3:场景模式(对齐 Agnes Video 契约 text/keyframe/reference) -->
|
<!-- 第十一轮 #3:场景模式(对齐 Agnes Video 契约 text/keyframe/reference) -->
|
||||||
<div class="field mb-field">
|
<div class="field mb-field">
|
||||||
<label>{{ t('videos.mode') }}</label>
|
<label>{{ t('videos.mode') }}</label>
|
||||||
@@ -56,39 +54,6 @@
|
|||||||
:placeholder="t('videos.seedPH')" class="fill" />
|
:placeholder="t('videos.seedPH')" class="fill" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
|
||||||
<!-- 智谱 CogVideoX-Flash:文生视频专用(quality/fps/with_audio/像素 size,固定 text 模式) -->
|
|
||||||
<template v-else>
|
|
||||||
<div class="form-row mb-field">
|
|
||||||
<div class="field">
|
|
||||||
<label>{{ t('videos.zSize') }}</label>
|
|
||||||
<el-select v-model="zsize" class="fill">
|
|
||||||
<el-option v-for="s in zhipuSizes" :key="s" :value="s" :label="s" />
|
|
||||||
</el-select>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<label>{{ t('videos.zQuality') }}</label>
|
|
||||||
<el-select v-model="zquality" class="fill">
|
|
||||||
<el-option value="speed" :label="t('videos.zSpeed')" />
|
|
||||||
<el-option value="quality" :label="t('videos.zQualityHigh')" />
|
|
||||||
</el-select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row mb-field">
|
|
||||||
<div class="field">
|
|
||||||
<label>{{ t('videos.zFps') }}</label>
|
|
||||||
<el-select v-model="zfps" class="fill">
|
|
||||||
<el-option :value="30" label="30fps" />
|
|
||||||
<el-option :value="60" label="60fps" />
|
|
||||||
</el-select>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<label>{{ t('videos.zAudio') }}</label>
|
|
||||||
<el-switch v-model="zaudio" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="hint tip">{{ t('videos.zTip') }}</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<div class="field mb-field">
|
<div class="field mb-field">
|
||||||
<label>{{ t('videos.promptRow') }}</label>
|
<label>{{ t('videos.promptRow') }}</label>
|
||||||
@@ -255,7 +220,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
@@ -291,13 +256,6 @@ const router = useRouter()
|
|||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const models = ref<any[]>([])
|
const models = ref<any[]>([])
|
||||||
const model = ref('')
|
const model = ref('')
|
||||||
// 所选视频模型是否智谱 CogVideoX(文生视频专用表单)
|
|
||||||
const isZhipu = computed(() => models.value.find((m: any) => m.id === model.value)?.provider === 'bigmodel')
|
|
||||||
// 切到智谱视频模型时强制 text 文生视频模式(智谱无 keyframe/reference)
|
|
||||||
watch(model, (m) => {
|
|
||||||
const mo = models.value.find((x: any) => x.id === m)
|
|
||||||
if (mo?.provider === 'bigmodel') mode.value = 'text'
|
|
||||||
})
|
|
||||||
const prompt = ref('')
|
const prompt = ref('')
|
||||||
const seconds = ref('5')
|
const seconds = ref('5')
|
||||||
const aspect = ref('16:9')
|
const aspect = ref('16:9')
|
||||||
@@ -305,12 +263,6 @@ const quality = ref('720P')
|
|||||||
const seed = ref<number | null>(null)
|
const seed = ref<number | null>(null)
|
||||||
// 第十一轮 #3:场景模式与对应素材
|
// 第十一轮 #3:场景模式与对应素材
|
||||||
const mode = ref<'text' | 'keyframe' | 'reference'>('text')
|
const mode = ref<'text' | 'keyframe' | 'reference'>('text')
|
||||||
// 智谱 CogVideoX-Flash:text 文生视频专用参数(quality/fps/with_audio/像素 size)
|
|
||||||
const zhipuSizes = ['720x480', '1024x1024', '1280x960', '960x1280', '1920x1080', '1080x1920', '2048x1080']
|
|
||||||
const zsize = ref('1920x1080')
|
|
||||||
const zquality = ref<'speed' | 'quality'>('speed')
|
|
||||||
const zfps = ref(30)
|
|
||||||
const zaudio = ref(true)
|
|
||||||
const frameEl = ref<HTMLInputElement | null>(null)
|
const frameEl = ref<HTMLInputElement | null>(null)
|
||||||
const refImgEl = ref<HTMLInputElement | null>(null)
|
const refImgEl = ref<HTMLInputElement | null>(null)
|
||||||
const refAudEl = ref<HTMLInputElement | null>(null)
|
const refAudEl = ref<HTMLInputElement | null>(null)
|
||||||
@@ -514,17 +466,14 @@ async function create() {
|
|||||||
const t0 = Date.now()
|
const t0 = Date.now()
|
||||||
const summary = mediaSummary()
|
const summary = mediaSummary()
|
||||||
try {
|
try {
|
||||||
const body: any = { model: model.value, prompt: prompt.value }
|
const body: any = {
|
||||||
if (isZhipu.value) {
|
model: model.value,
|
||||||
// 智谱 CogVideoX-Flash:text 文生视频;quality/fps/with_audio 走 extra(后端透传给上游)
|
prompt: prompt.value,
|
||||||
body.size = zsize.value
|
seconds: seconds.value,
|
||||||
body.mode = 'text'
|
size: quality.value,
|
||||||
body.extra = { quality: zquality.value, fps: zfps.value, with_audio: zaudio.value }
|
aspect_ratio: aspect.value,
|
||||||
} else {
|
mode: mode.value,
|
||||||
body.seconds = seconds.value
|
}
|
||||||
body.size = quality.value
|
|
||||||
body.aspect_ratio = aspect.value
|
|
||||||
body.mode = mode.value
|
|
||||||
if (seed.value != null) body.seed = seed.value
|
if (seed.value != null) body.seed = seed.value
|
||||||
if (mode.value === 'keyframe') {
|
if (mode.value === 'keyframe') {
|
||||||
if (firstFrame.value) body.first_frame = firstFrame.value
|
if (firstFrame.value) body.first_frame = firstFrame.value
|
||||||
@@ -533,7 +482,6 @@ async function create() {
|
|||||||
if (imageList.value.length) body.images = imageList.value
|
if (imageList.value.length) body.images = imageList.value
|
||||||
if (audioList.value.length) body.audios = audioList.value
|
if (audioList.value.length) body.audios = audioList.value
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!stream.value) body.wait = true // 同步等结果
|
if (!stream.value) body.wait = true // 同步等结果
|
||||||
const j = await api('/v1/videos', { method: 'POST', body: JSON.stringify(body) })
|
const j = await api('/v1/videos', { method: 'POST', body: JSON.stringify(body) })
|
||||||
const task: VTask = {
|
const task: VTask = {
|
||||||
|
|||||||
+17
-42
@@ -89,31 +89,8 @@ def _login_admin_session(client=None):
|
|||||||
# ── 配置加载 ──
|
# ── 配置加载 ──
|
||||||
def test_load_config_providers():
|
def test_load_config_providers():
|
||||||
cfg = load_config(CONFIG)
|
cfg = load_config(CONFIG)
|
||||||
assert set(cfg.providers.keys()) == {"agnes", "volc_engine", "bigmodel"}
|
assert set(cfg.providers.keys()) == {"agnes", "volc_engine"}
|
||||||
assert cfg.providers["agnes"].models[0].id == "agnes-3.0-flash"
|
assert cfg.providers["agnes"].models[0].id == "agnes-3.0-flash"
|
||||||
# 智谱:base_url + token_env + 6 个模型 + V 型号视觉标记
|
|
||||||
assert cfg.providers["bigmodel"].base_url == "https://open.bigmodel.cn/api/paas/v4"
|
|
||||||
assert cfg.providers["bigmodel"].auth.token_env == "ZHIPU_API_KEY"
|
|
||||||
bm = cfg.providers["bigmodel"]
|
|
||||||
text_ids = [m.id for m in bm.models if m.type == "text"]
|
|
||||||
assert text_ids == ["GLM-4.7-Flash", "GLM-4-Flash-250414", "GLM-Z1-Flash",
|
|
||||||
"GLM-4.6V-Flash", "GLM-4V-Flash", "GLM-4.1V-Thinking-Flash"]
|
|
||||||
# 智谱媒体模型:cogview-3-flash(图像)、cogvideox-flash(视频)
|
|
||||||
assert [m.id for m in bm.models if m.type == "image"] == ["cogview-3-flash"]
|
|
||||||
assert [m.id for m in bm.models if m.type == "video"] == ["cogvideox-flash"]
|
|
||||||
for m in bm.models:
|
|
||||||
if m.type != "text":
|
|
||||||
continue
|
|
||||||
want = m.id in ("GLM-4.6V-Flash", "GLM-4V-Flash", "GLM-4.1V-Thinking-Flash")
|
|
||||||
assert m.vision is want, f"{m.id} vision 应为 {want}"
|
|
||||||
# 智谱媒体契约(图像像素档 + 视频 zhipu 异步风格)
|
|
||||||
md = bm.media
|
|
||||||
assert md.supports_image and md.supports_video
|
|
||||||
assert md.image_default_size == "1024x1024"
|
|
||||||
assert md.video_style == "zhipu"
|
|
||||||
assert md.video_default_size == "1920x1080"
|
|
||||||
assert md.video_create_endpoint == "/videos/generations"
|
|
||||||
assert md.video_poll_path == "/async-result"
|
|
||||||
|
|
||||||
|
|
||||||
def test_load_config_routes():
|
def test_load_config_routes():
|
||||||
@@ -333,7 +310,7 @@ def test_resolve_media_model_via_route_alias():
|
|||||||
# wjd 路由链里第 2 个是 agnes-3.0-flash(text),但 image 模型不在这条链 → 走别名找不到 image
|
# wjd 路由链里第 2 个是 agnes-3.0-flash(text),但 image 模型不在这条链 → 走别名找不到 image
|
||||||
# 单独构造一条指向 image 的路由来验证别名解析逻辑
|
# 单独构造一条指向 image 的路由来验证别名解析逻辑
|
||||||
from app.config import RouteInfo
|
from app.config import RouteInfo
|
||||||
cfg.routes["img"] = RouteInfo(name="img", models=["GLM-4.1V-Thinking-Flash", "agnes-image-2.5-flash"])
|
cfg.routes["img"] = RouteInfo(name="img", models=["agnes-3.0-flash", "agnes-image-2.5-flash"])
|
||||||
res = m._resolve_media_model(cfg, "img", "image")
|
res = m._resolve_media_model(cfg, "img", "image")
|
||||||
assert res is not None and res[4] == "agnes-image-2.5-flash"
|
assert res is not None and res[4] == "agnes-image-2.5-flash"
|
||||||
|
|
||||||
@@ -2256,9 +2233,8 @@ def test_video_polls_merged_into_one_log_row_with_response():
|
|||||||
"prompt": "x", "aspect_ratio": "16:9"}, headers=ah)
|
"prompt": "x", "aspect_ratio": "16:9"}, headers=ah)
|
||||||
assert r.status_code == 200, r.text
|
assert r.status_code == 200, r.text
|
||||||
vid = r.json()["video_id"]
|
vid = r.json()["video_id"]
|
||||||
poll_q = f"/v1/videos/{vid}?model=agnes-video-2.5-flash" # 多视频供应商(agnes+智谱)时必须显式指定 model
|
client.get(f"/v1/videos/{vid}", headers=ah) # 第 1 次轮询 processing
|
||||||
client.get(poll_q, headers=ah) # 第 1 次轮询 processing
|
client.get(f"/v1/videos/{vid}", headers=ah) # 第 2 次轮询 completed
|
||||||
client.get(poll_q, headers=ah) # 第 2 次轮询 completed
|
|
||||||
logs = client.get("/logs?n=200", headers=ah).json()["entries"]
|
logs = client.get("/logs?n=200", headers=ah).json()["entries"]
|
||||||
rows = [e for e in logs if e.get("video_id") == vid]
|
rows = [e for e in logs if e.get("video_id") == vid]
|
||||||
assert len(rows) == 1, f"轮询应合成到创建那条里(实际 {len(rows)} 行): {[r['path'] for r in logs]}"
|
assert len(rows) == 1, f"轮询应合成到创建那条里(实际 {len(rows)} 行): {[r['path'] for r in logs]}"
|
||||||
@@ -2318,7 +2294,7 @@ def test_wjd_route_orders_by_availability_and_speed():
|
|||||||
from app.config import RouteInfo
|
from app.config import RouteInfo
|
||||||
from app.circuit import CircuitBreakerRegistry
|
from app.circuit import CircuitBreakerRegistry
|
||||||
import app.main as m
|
import app.main as m
|
||||||
saved = {k: os.environ.get(k) for k in ("AGNES_API_KEY", "VOLC_API_KEY", "ZHIPU_API_KEY")}
|
saved = {k: os.environ.get(k) for k in ("AGNES_API_KEY", "VOLC_API_KEY")}
|
||||||
for k in saved:
|
for k in saved:
|
||||||
os.environ[k] = "test-token"
|
os.environ[k] = "test-token"
|
||||||
orig_m, orig_c = m._metrics, m._circuits
|
orig_m, orig_c = m._metrics, m._circuits
|
||||||
@@ -2328,22 +2304,21 @@ def test_wjd_route_orders_by_availability_and_speed():
|
|||||||
cfg = m._cfg()
|
cfg = m._cfg()
|
||||||
cfg.routes["wjd_speedtest"] = RouteInfo(
|
cfg.routes["wjd_speedtest"] = RouteInfo(
|
||||||
name="wjd_speedtest",
|
name="wjd_speedtest",
|
||||||
models=["ark-code-latest", "agnes-3.0-flash", "GLM-4.7-Flash"], # 配置优先级 volc>agnes>bigmodel
|
models=["ark-code-latest", "agnes-3.0-flash"], # 配置优先级 volc>agnes
|
||||||
retry=1)
|
retry=1)
|
||||||
try:
|
try:
|
||||||
# 冷启动:没有任何延迟样本 → 保持配置顺序
|
# 冷启动:没有任何延迟样本 → 保持配置顺序
|
||||||
assert m._route_chain(cfg, "wjd_speedtest")[0] == [
|
assert m._route_chain(cfg, "wjd_speedtest")[0] == [
|
||||||
"ark-code-latest", "agnes-3.0-flash", "GLM-4.7-Flash"]
|
"ark-code-latest", "agnes-3.0-flash"]
|
||||||
# 喂速度:agnes 最快、bigmodel 次之、volc 最慢 → 完全重排
|
# 喂速度:agnes 快、volc 慢 → 完全重排
|
||||||
m._metrics.record_latency("agnes-3.0-flash", 0.5)
|
m._metrics.record_latency("agnes-3.0-flash", 0.5)
|
||||||
m._metrics.record_latency("GLM-4.7-Flash", 1.5)
|
|
||||||
m._metrics.record_latency("ark-code-latest", 4.0)
|
m._metrics.record_latency("ark-code-latest", 4.0)
|
||||||
assert m._route_chain(cfg, "wjd_speedtest")[0] == [
|
assert m._route_chain(cfg, "wjd_speedtest")[0] == [
|
||||||
"agnes-3.0-flash", "GLM-4.7-Flash", "ark-code-latest"]
|
"agnes-3.0-flash", "ark-code-latest"]
|
||||||
# 最快那个供应商熔断开 → 排到最后,次快上位(未测速的可用模型才用探测位兜底)
|
# 最快那个供应商熔断开 → 排到最后,次快上位(未测速的可用模型才用探测位兜底)
|
||||||
m._circuits.get("agnes")._state = "open"
|
m._circuits.get("agnes")._state = "open"
|
||||||
chain2 = m._route_chain(cfg, "wjd_speedtest")[0]
|
chain2 = m._route_chain(cfg, "wjd_speedtest")[0]
|
||||||
assert chain2[0] == "GLM-4.7-Flash", chain2
|
assert chain2[0] == "ark-code-latest", chain2
|
||||||
assert chain2[-1] == "agnes-3.0-flash", chain2
|
assert chain2[-1] == "agnes-3.0-flash", chain2
|
||||||
finally:
|
finally:
|
||||||
m._metrics, m._circuits = orig_m, orig_c
|
m._metrics, m._circuits = orig_m, orig_c
|
||||||
@@ -2556,9 +2531,9 @@ def test_vision_first_reorders_only_when_vision_exists():
|
|||||||
"""带图请求:链上有视觉模型才重排(提到最前),一个都没有就别动(不掩盖能力缺失)。"""
|
"""带图请求:链上有视觉模型才重排(提到最前),一个都没有就别动(不掩盖能力缺失)。"""
|
||||||
import app.main as m
|
import app.main as m
|
||||||
cfg = load_config(CONFIG)
|
cfg = load_config(CONFIG)
|
||||||
assert m._vision_first(cfg, ["ark-code-latest", "agnes-3.0-flash", "GLM-Z1-Flash"]) == \
|
assert m._vision_first(cfg, ["ark-code-latest", "agnes-3.0-flash"]) == \
|
||||||
["agnes-3.0-flash", "ark-code-latest", "GLM-Z1-Flash"], "视觉模型提到最前,其余保持相对顺序"
|
["agnes-3.0-flash", "ark-code-latest"], "视觉模型提到最前,其余保持相对顺序"
|
||||||
assert m._vision_first(cfg, ["ark-code-latest", "GLM-Z1-Flash"]) == ["ark-code-latest", "GLM-Z1-Flash"]
|
assert m._vision_first(cfg, ["ark-code-latest"]) == ["ark-code-latest"]
|
||||||
|
|
||||||
|
|
||||||
def test_messages_have_images_detects_vision_blocks():
|
def test_messages_have_images_detects_vision_blocks():
|
||||||
@@ -3564,7 +3539,7 @@ def test_config_save_applies_without_restart():
|
|||||||
view["server"]["timeout"] = 95
|
view["server"]["timeout"] = 95
|
||||||
view["server"]["retry"] = 2
|
view["server"]["retry"] = 2
|
||||||
view["observability"]["access_log_maxlen"] = 777
|
view["observability"]["access_log_maxlen"] = 777
|
||||||
view["routes"]["wjd"]["models"] = ["GLM-4.1V-Thinking-Flash", "ark-code-latest"]
|
view["routes"]["wjd"]["models"] = ["agnes-3.0-flash", "ark-code-latest"]
|
||||||
view["providers"]["volc_engine"]["models"].append(
|
view["providers"]["volc_engine"]["models"].append(
|
||||||
{"id": "ark-code-mini", "display_name": "迷你", "type": "text", "vision": False})
|
{"id": "ark-code-mini", "display_name": "迷你", "type": "text", "vision": False})
|
||||||
view["pricing"]["per_model"]["ark-code-mini"] = {"input": 0.1, "output": 0.2}
|
view["pricing"]["per_model"]["ark-code-mini"] = {"input": 0.1, "output": 0.2}
|
||||||
@@ -3578,17 +3553,17 @@ def test_config_save_applies_without_restart():
|
|||||||
assert m.config.server.timeout == 95
|
assert m.config.server.timeout == 95
|
||||||
assert m.config.server.retry == 2
|
assert m.config.server.retry == 2
|
||||||
assert m.config.observability.access_log_maxlen == 777
|
assert m.config.observability.access_log_maxlen == 777
|
||||||
assert m.config.routes["wjd"].models == ["GLM-4.1V-Thinking-Flash", "ark-code-latest"]
|
assert m.config.routes["wjd"].models == ["agnes-3.0-flash", "ark-code-latest"]
|
||||||
assert m.config.find_provider_for_model("ark-code-mini")[0] == "volc_engine"
|
assert m.config.find_provider_for_model("ark-code-mini")[0] == "volc_engine"
|
||||||
assert m._access._max == 777, "访问日志容量应就地调整"
|
assert m._access._max == 777, "访问日志容量应就地调整"
|
||||||
# 盘上也变了,且旧文件有备份
|
# 盘上也变了,且旧文件有备份
|
||||||
on_disk = _yaml.safe_load(cfg_path.read_text(encoding="utf-8"))
|
on_disk = _yaml.safe_load(cfg_path.read_text(encoding="utf-8"))
|
||||||
assert on_disk["server"]["timeout"] == 95
|
assert on_disk["server"]["timeout"] == 95
|
||||||
assert on_disk["routes"]["wjd"]["models"] == ["GLM-4.1V-Thinking-Flash", "ark-code-latest"]
|
assert on_disk["routes"]["wjd"]["models"] == ["agnes-3.0-flash", "ark-code-latest"]
|
||||||
assert (P(tmp.name) / "gateway.yaml.bak").exists(), "保存前应备份原文件"
|
assert (P(tmp.name) / "gateway.yaml.bak").exists(), "保存前应备份原文件"
|
||||||
# 路由链顺序变更后,/v1/models 立刻跟着变(页面/调用方看到的就是新顺序)
|
# 路由链顺序变更后,/v1/models 立刻跟着变(页面/调用方看到的就是新顺序)
|
||||||
lm = client.get("/v1/models", headers=ah).json()
|
lm = client.get("/v1/models", headers=ah).json()
|
||||||
assert [x for x in lm["data"] if x["type"] == "route"][0]["models"][:2] == ["GLM-4.1V-Thinking-Flash", "ark-code-latest"]
|
assert [x for x in lm["data"] if x["type"] == "route"][0]["models"][:2] == ["agnes-3.0-flash", "ark-code-latest"]
|
||||||
|
|
||||||
# ② 改"需重启"的键:能保存,但要明确回提示(不能假装已生效)
|
# ② 改"需重启"的键:能保存,但要明确回提示(不能假装已生效)
|
||||||
assert _yaml.safe_load(cfg_path.read_text(encoding="utf-8"))["server"]["port"] == 8808
|
assert _yaml.safe_load(cfg_path.read_text(encoding="utf-8"))["server"]["port"] == 8808
|
||||||
|
|||||||
Reference in new issue
Block a user