feat: 集成智谱 CogView-3-Flash 文生图 + CogVideoX-Flash 文生视频
This commit is contained in:
1 parent
b66c448d7a
commit
e0aa5522fb
13 files changed
+269
-40
No files matched your search
@@ -4,6 +4,35 @@
|
||||
|
||||
---
|
||||
|
||||
## 2026-09-16 · 集成智谱 CogView-3-Flash(文生图)+ CogVideoX-Flash(文生视频)
|
||||
|
||||
**一句话**:给上一轮的智谱供应商补上媒体生成——图像页用 `cogview-3-flash`、视频页用 `cogvideox-flash`,前后端按「选到的供应商」自动切到智谱契约(不动 Agnes)。
|
||||
|
||||
### 契约(官网 + 真 Key 实测确认)
|
||||
- **图像 cogview-3-flash**:`POST {base}/images/generations`,`{model, prompt, size}`(size 为像素档:1024x1024/768x1344/864x1152/1344x768/1152x864/1440x720/720x1440)→ 返回 `data[].url`;**无 ratio、不支持图生图**。
|
||||
- **视频 cogvideox-flash**:`POST {base}/videos/generations`(**异步**)`{model, prompt, quality, with_audio, size, fps:30/60}` → 返回 `task_status:PROCESSING`;再 `GET /async-result/{id}` 轮询到 `SUCCESS` 取 `video_result[].url`。仅文生视频。
|
||||
|
||||
### 后端
|
||||
- `data/gateway.yaml` bigmodel 加 `media`(图像端点+像素档、视频 `/videos/generations`+`/async-result/{id}`,新增 `video_style:"zhipu"`),并注册 `cogview-3-flash`(image)、`cogvideox-flash`(video)(顺带修复本轮早前编辑误吞的 `server:` 顶层键)。
|
||||
- `config.py`:`MediaConfig` 新增 `video_style` / `video_default_size`。
|
||||
- 适配器 `create_video` / `poll_video`:按 `video_style=="zhipu"` 走智谱异步契约(fps/quality/with_audio + 路径参数轮询);Agnes 分支不变(`__init__.py` docstring 改四家)。
|
||||
- `main.py`:新增 `_video_status`(兼容 `task_status`,智谱才识得 `SUCCESS/FAIL` 终态)与 `_video_terminal`,替换 3 处视频状态判定;`_validate_video_request` 按供应商分流(智谱仅 text 文生视频,size/quality/fps 合规校验,非法回干净 400 不进熔断);`videos_create` 改为先 `_resolve_media_model` 再按供应商校验。
|
||||
- `settings.py`:面板 `MEDIA_KEYS` 补 `video_style`/`video_default_size`(否则「网关配置」面板往返会丢这两个字段)。
|
||||
- 顺带修正 `DELETE /feedback` 过时 docstring(admin 可真删 admin_delete)。
|
||||
|
||||
### 前端(按所选模型 `provider==='bigmodel'` 自动切)
|
||||
- `Videos.vue`:选智谱视频模型显示专用表单(分辨率/质量 speed·quality/帧率 30·60/配音 switch,固定文生视频),body 用 `extra:{quality,fps,with_audio}`;选 Agnes 原表单不变;切智谱模型时强制 `mode='text'`。
|
||||
- `Images.vue`:选 cogview 时 size 换成像素档、隐藏 ratio 与参考图(cogview 无图生图)。
|
||||
- `media.ts`:`findVideoUrl` 优先键补 `video_result`。
|
||||
- i18n:新增 `videos.zSize/zQuality/zSpeed/zQualityHigh/zFps/zAudio/zTip` 7 键,中英对称。
|
||||
|
||||
### 验证
|
||||
- 单测:新增/修正 bigmodel 媒体契约断言、视频轮询必经 `?model=`(现两家视频供应商)、配置往返含新 media 键 → **155 passed / 0 failed**;前端 `npm run build` 过(typecheck + i18n 对称),新入口 `index-CxdHy_Sw.js`。
|
||||
- 真机隔离(uvicorn:8899 临时 users/history,连真实智谱):`/v1/models` 列出 8 个智谱模型;图像 → 200 `data[].url`;视频创建 → `video_id`+`task_status:PROCESSING`;轮询 → `status:processing`;非法参数(`mode=keyframe`)→ 400 干净拒绝。
|
||||
- 上线:`supervisorctl restart api-gateway:api-gateway_00`(代码改动需重启),前端 dist 已 build 覆盖。
|
||||
|
||||
---
|
||||
|
||||
## 2026-09-16 · 新增智谱 GLM(open.bigmodel.cn)供应商
|
||||
|
||||
**一句话**:接入智谱开放平台作为新的 OpenAI 兼容供应商,收录 6 个 Flash 模型(3 文本 + 3 视觉),密钥走 `data/.env` 的 `ZHIPU_API_KEY`,真图实测确认 3 个 V 型号支持图像输入。
|
||||
|
||||
@@ -46,7 +46,7 @@ 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) |
|
||||
| b.ai | `https://api.b.ai/v1` | Bearer | `qwen3.8-flash`、`hy3`(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`(text;其中 `GLM-4.6V-Flash`/`GLM-4V-Flash`/`GLM-4.1V-Thinking-Flash` 支持图像输入) |
|
||||
| 智谱 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` 段指定。
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any, AsyncIterator
|
||||
from urllib.parse import quote
|
||||
|
||||
|
||||
from app.adapters.base import BaseAdapter, json_or_raise
|
||||
@@ -184,6 +185,26 @@ class OpenAICompatAdapter(BaseAdapter):
|
||||
size: str = "720P",
|
||||
extra: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
# 智谱视频契约:POST /videos/generations(异步)——参数为 quality/with_audio/fps/像素 size,
|
||||
# 不需要 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"
|
||||
payload: dict[str, Any] = {
|
||||
"model": model,
|
||||
@@ -211,6 +232,17 @@ class OpenAICompatAdapter(BaseAdapter):
|
||||
|
||||
# ── 视频轮询 ────────────────────────────────────
|
||||
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 ""
|
||||
poll_base = self.media.video_poll_base or self.base_url
|
||||
poll_path = self.media.video_poll_path or "/agnesapi"
|
||||
|
||||
+5
-1
@@ -54,7 +54,9 @@ class MediaConfig:
|
||||
video_create_endpoint: str | None = None # 相对 base_url,默认 /videos
|
||||
video_poll_base: str | None = None # 绝对 base(视频查询,默认同 base_url 去掉 /v1)
|
||||
video_poll_path: str | None = None # 默认 /agnesapi(Agnes)
|
||||
video_model_name: str | None = None # 轮询用的 model_name 参数
|
||||
video_model_name: str | None = None # 轮询用的 model_name 参数(Agnes)
|
||||
video_style: str | None = None # 视频契约风格:"zhipu"=智谱异步(videos/generations + /async-result/{id});None=Agnes 风格
|
||||
video_default_size: str | None = None # 视频默认尺寸(智谱为像素串如 1920x1080;Agnes 用 size 档位)
|
||||
|
||||
@property
|
||||
def supports_image(self) -> bool:
|
||||
@@ -304,6 +306,8 @@ def _parse_media(pval: dict[str, Any]) -> MediaConfig:
|
||||
video_poll_base=m.get("video_poll_base"),
|
||||
video_poll_path=m.get("video_poll_path"),
|
||||
video_model_name=m.get("video_model_name"),
|
||||
video_style=m.get("video_style"),
|
||||
video_default_size=m.get("video_default_size"),
|
||||
)
|
||||
|
||||
|
||||
|
||||
+64
-12
@@ -1729,8 +1729,8 @@ async def _video_wait_and_callback(cfg, pkey, pconfig, pmodel_id, video_id, wait
|
||||
await asyncio.sleep(2)
|
||||
continue
|
||||
raw = final.get("raw") or {}
|
||||
status = raw.get("status") or raw.get("state")
|
||||
if status in ("completed", "failed", "succeeded", "success"):
|
||||
status = _video_status(raw)
|
||||
if _video_terminal(status):
|
||||
break
|
||||
await asyncio.sleep(2)
|
||||
# Webhook 回调
|
||||
@@ -1745,8 +1745,8 @@ async def _video_wait_and_callback(cfg, pkey, pconfig, pmodel_id, video_id, wait
|
||||
try:
|
||||
# Bug 2 修复: 按真实状态上报,failed 不再误标成 completed
|
||||
raw = (final.get("raw") if final else None) or {}
|
||||
status = str(raw.get("status") or raw.get("state") or "")
|
||||
if status not in ("completed", "failed", "succeeded", "success"):
|
||||
status = _video_status(raw)
|
||||
if not _video_terminal(status):
|
||||
status = "timeout"
|
||||
payload = {"video_id": video_id, "provider": pkey, "status": status,
|
||||
"result": raw, "x_request_id": rid}
|
||||
@@ -1764,12 +1764,63 @@ _VIDEO_SIZES = ("720P",)
|
||||
_VIDEO_ASPECTS = ("21:9", "16:9", "4:3", "1:1", "3:4", "9:16")
|
||||
|
||||
|
||||
def _validate_video_request(req) -> None:
|
||||
def _video_status(raw: dict | None) -> str:
|
||||
"""视频原始返回的状态取法(统一小写)。
|
||||
|
||||
智谱异步结果是 task_status(PROCESSING/SUCCESS/FAIL),Agnes 用 status / state。
|
||||
"""
|
||||
if not raw:
|
||||
return ""
|
||||
return str(raw.get("task_status") or raw.get("status") or raw.get("state") or "").lower()
|
||||
|
||||
|
||||
def _video_terminal(status: str) -> bool:
|
||||
"""是否已到终态(成功或失败),用于结束轮询。"""
|
||||
s = status.lower()
|
||||
return s in ("success", "succeeded", "completed", "done", "finished",
|
||||
"failed", "fail", "error", "cancelled", "canceled")
|
||||
|
||||
|
||||
# 智谱 CogVideoX-Flash 支持的分辨率(像素串),与 Agnes 的 720P 档位语义不同。
|
||||
_ZHIPU_VIDEO_SIZES = {
|
||||
"720x480", "1024x1024", "1280x960", "960x1280",
|
||||
"1920x1080", "1080x1920", "2048x1080",
|
||||
}
|
||||
|
||||
|
||||
def _validate_video_request(req, media=None) -> None:
|
||||
"""第十一轮 #3:按 Agnes Video 2.5 契约做**入站校验**,把明显不合法的 mode/媒体/时长
|
||||
组合在网关挡下并回**干净 400**(不再白发上游浪费限流额度,也不进熔断)。
|
||||
第十三轮补齐 size / aspect_ratio / n / videos 四项(文档「Flash 专属错误」与
|
||||
「生成模式规则」里明确列出的限制),并保留原有 mode/媒体/时长校验。
|
||||
目前只有 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"
|
||||
if mode not in _VIDEO_MODES:
|
||||
raise HTTPException(400, f"视频 mode 仅支持 {'/'.join(_VIDEO_MODES)},收到 {mode!r}")
|
||||
@@ -1811,12 +1862,13 @@ async def videos_create(request: Request, req: VideoCreateRequestExtended, _auth
|
||||
cfg = _cfg()
|
||||
rid = getattr(request.state, "rid", "-")
|
||||
caller = getattr(request.state, "caller", "anonymous")
|
||||
_validate_video_request(req) # 第十一轮 #3:入站按上游契约校验 mode/媒体/时长
|
||||
# Bug 4: 支持路由别名(如 wjd)→ 解析到第一个 type==video 的模型
|
||||
# Bug 4: 支持路由别名(如 wjd)→ 解析到第一个 type==video 的模型。
|
||||
# 解析放在入站校验之前,好让 _validate_video_request 按供应商媒体契约(Agnes / 智谱)分流。
|
||||
resolved = _resolve_media_model(cfg, req.model, "video")
|
||||
if resolved is None:
|
||||
raise HTTPException(404, f"未知视频模型/路由: {req.model}(没有可用的 video 类型模型)")
|
||||
pkey, pconfig, minfo, token, real_model = resolved
|
||||
_validate_video_request(req, pconfig.media) # 入站按供应商媒体契约校验
|
||||
# 顺序修复(本轮):先能力检查(501),再校验回调地址(400),最后限流 —— 避免无效请求白扣 token。
|
||||
if not pconfig.media.supports_video:
|
||||
raise HTTPException(501, f"供应商 {pconfig.name} 不支持视频创建")
|
||||
@@ -1872,7 +1924,7 @@ async def videos_create(request: Request, req: VideoCreateRequestExtended, _auth
|
||||
# 本轮修复: status 同时看 status/state(此前只看 status,而上游若用 state
|
||||
# 会被显示成 "pending" —— 即使其实已完成,与等待循环的判定不一致)
|
||||
raw_final = (final.get("raw") or {}) if final else {}
|
||||
resp["status"] = (raw_final.get("status") or raw_final.get("state") or "pending") if final else "submitted"
|
||||
resp["status"] = (_video_status(raw_final) or "pending") if final else "submitted"
|
||||
elif req.callback_url:
|
||||
# 第六轮修复: 此前只传 callback_url(不传 wait)时,_video_wait_and_callback 第一行
|
||||
# 就 `if not wait: return None` → **webhook 被静默丢弃、永不回调**,而 README 却把
|
||||
@@ -2026,8 +2078,8 @@ async def videos_poll(request: Request, video_id: str, model: str = "", wait: bo
|
||||
log.warning("[rid=%s] 轮询视频 %s 瞬时失败: %s", rid, _logsafe(video_id), e)
|
||||
await asyncio.sleep(2)
|
||||
continue
|
||||
status = (result.get("raw") or {}).get("status") or (result.get("raw") or {}).get("state")
|
||||
if status in ("completed", "failed", "succeeded", "success"):
|
||||
status = _video_status(result.get("raw"))
|
||||
if _video_terminal(status):
|
||||
break
|
||||
await asyncio.sleep(2)
|
||||
if result is None:
|
||||
@@ -2043,12 +2095,12 @@ async def videos_poll(request: Request, video_id: str, model: str = "", wait: bo
|
||||
# 第十轮: 轮询不单独占一行日志,改为按 video_id 快照累积,由 /logs 合成到创建那条里
|
||||
video_poll_push(video_id, {
|
||||
"ts": round(time.time(), 3), "ok": True,
|
||||
"status": (raw.get("status") or raw.get("state") or ""),
|
||||
"status": _video_status(raw),
|
||||
"progress": raw.get("progress"),
|
||||
"raw": json.dumps(raw, ensure_ascii=False)[:1200],
|
||||
})
|
||||
return {"video_id": video_id, "provider": pkey, "served_model": pmodel_id, "raw": raw,
|
||||
"status": raw.get("status") or raw.get("state"), "x_request_id": rid}
|
||||
"status": _video_status(raw), "x_request_id": rid}
|
||||
except AuthConfigError as e:
|
||||
cb.release_probe()
|
||||
raise HTTPException(503, f"供应商 {pconfig.name} 未配置可用凭证: {e}")
|
||||
|
||||
@@ -61,6 +61,8 @@ MEDIA_KEYS = (
|
||||
"video_poll_base",
|
||||
"video_poll_path",
|
||||
"video_model_name",
|
||||
"video_style",
|
||||
"video_default_size",
|
||||
)
|
||||
|
||||
MODEL_TYPES = ("text", "image", "video")
|
||||
|
||||
+19
-2
@@ -74,7 +74,19 @@ providers:
|
||||
auth:
|
||||
token_env: "ZHIPU_API_KEY"
|
||||
extra_headers: {}
|
||||
media: {}
|
||||
# 智谱媒体生成(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"
|
||||
@@ -97,7 +109,12 @@ providers:
|
||||
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:
|
||||
host: "127.0.0.1"
|
||||
port: 8808
|
||||
|
||||
@@ -26,7 +26,7 @@ export function findVideoUrl(obj: any): string {
|
||||
return ''
|
||||
}
|
||||
if (typeof obj === 'object') {
|
||||
for (const k of ['video_url', 'play_url', 'url', 'html_url', 'video', 'media_url', 'result', 'data', 'mp4']) {
|
||||
for (const k of ['video_result', '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 }
|
||||
}
|
||||
for (const v of Object.values(obj)) { const u = findVideoUrl(v); if (u) return u }
|
||||
|
||||
@@ -303,6 +303,13 @@ export default {
|
||||
videos: {
|
||||
taskTitle: 'Tasks',
|
||||
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',
|
||||
model: 'Video model',
|
||||
mode: 'Scenario',
|
||||
|
||||
@@ -303,6 +303,13 @@ export default {
|
||||
videos: {
|
||||
taskTitle: '任务列表',
|
||||
fixed: '固定',
|
||||
zSize: '分辨率',
|
||||
zQuality: '质量',
|
||||
zSpeed: '速度优先',
|
||||
zQualityHigh: '质量优先',
|
||||
zFps: '帧率',
|
||||
zAudio: '配音',
|
||||
zTip: '智谱 CogVideoX 仅支持文生视频(text 模式);生成耗时较长,请耐心等待。',
|
||||
title: '视频生成',
|
||||
model: '视频模型',
|
||||
mode: '场景',
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
<div class="field">
|
||||
<label>{{ t('images.size') }}</label>
|
||||
<el-select v-model="size" class="fill">
|
||||
<el-option v-for="s in sizes" :key="s" :value="s" :label="s" />
|
||||
<el-option v-for="s in displaySizes" :key="s" :value="s" :label="s" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div v-if="!isZhipu" class="field">
|
||||
<label>{{ t('images.ratio') }}</label>
|
||||
<el-select v-model="ratio" class="fill">
|
||||
<el-option v-for="r in ratios" :key="r" :value="r" :label="r" />
|
||||
@@ -44,7 +44,7 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="field mb-field">
|
||||
<div v-if="!isZhipu" class="field mb-field">
|
||||
<label>{{ t('images.refsLabel') }}</label>
|
||||
<!-- 第十三轮:图生图 / 多图合成 —— 支持直接上传(浏览器内压成 data URI),也支持粘 URL -->
|
||||
<div class="ref-btns">
|
||||
@@ -166,8 +166,22 @@ const models = ref<any[]>([])
|
||||
const model = ref('')
|
||||
const sizes = ['1K', '2K', '3K', '4K']
|
||||
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 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 prompt = ref('')
|
||||
// 参考图(图生图 / 多图合成):上传的走 data URI,URL 的直接透传,两类可混用
|
||||
@@ -274,8 +288,8 @@ async function generate() {
|
||||
progress.value = i
|
||||
const t0 = performance.now()
|
||||
// 上游图像接口的 n 必须为 1:多张就在这里逐张调用,每张出来就上屏(进度可见)
|
||||
const body: any = { model: model.value, prompt: prompt.value, size: size.value, ratio: ratio.value, n: 1 }
|
||||
if (list.length) body.image = list // 图生图 / 多图合成(网关转成上游的 extra_body.image)
|
||||
const body: any = { model: model.value, prompt: prompt.value, size: size.value, ratio: isZhipu.value ? '' : ratio.value, n: 1 }
|
||||
if (list.length && !isZhipu.value) body.image = list // 图生图 / 多图合成(网关转成上游的 extra_body.image)
|
||||
const j = await api('/v1/images/generations', { method: 'POST', body: JSON.stringify(body) })
|
||||
const ms = (performance.now() - t0) | 0
|
||||
providerName.value = j.provider_name || j.provider || ''
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<!-- 智谱 CogVideoX-Flash / Agnes 两种视频契约:Agnes 用模式+时长+720P;智谱用 quality/fps/audio/像素 size -->
|
||||
<template v-if="!isZhipu">
|
||||
<!-- 第十一轮 #3:场景模式(对齐 Agnes Video 契约 text/keyframe/reference) -->
|
||||
<div class="field mb-field">
|
||||
<label>{{ t('videos.mode') }}</label>
|
||||
@@ -54,6 +56,39 @@
|
||||
:placeholder="t('videos.seedPH')" class="fill" />
|
||||
</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">
|
||||
<label>{{ t('videos.promptRow') }}</label>
|
||||
@@ -220,7 +255,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
@@ -256,6 +291,13 @@ const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const models = ref<any[]>([])
|
||||
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 seconds = ref('5')
|
||||
const aspect = ref('16:9')
|
||||
@@ -263,6 +305,12 @@ const quality = ref('720P')
|
||||
const seed = ref<number | null>(null)
|
||||
// 第十一轮 #3:场景模式与对应素材
|
||||
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 refImgEl = ref<HTMLInputElement | null>(null)
|
||||
const refAudEl = ref<HTMLInputElement | null>(null)
|
||||
@@ -466,14 +514,17 @@ async function create() {
|
||||
const t0 = Date.now()
|
||||
const summary = mediaSummary()
|
||||
try {
|
||||
const body: any = {
|
||||
model: model.value,
|
||||
prompt: prompt.value,
|
||||
seconds: seconds.value,
|
||||
size: quality.value,
|
||||
aspect_ratio: aspect.value,
|
||||
mode: mode.value,
|
||||
}
|
||||
const body: any = { model: model.value, prompt: prompt.value }
|
||||
if (isZhipu.value) {
|
||||
// 智谱 CogVideoX-Flash:text 文生视频;quality/fps/with_audio 走 extra(后端透传给上游)
|
||||
body.size = zsize.value
|
||||
body.mode = 'text'
|
||||
body.extra = { quality: zquality.value, fps: zfps.value, with_audio: zaudio.value }
|
||||
} else {
|
||||
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 (mode.value === 'keyframe') {
|
||||
if (firstFrame.value) body.first_frame = firstFrame.value
|
||||
@@ -482,6 +533,7 @@ async function create() {
|
||||
if (imageList.value.length) body.images = imageList.value
|
||||
if (audioList.value.length) body.audios = audioList.value
|
||||
}
|
||||
}
|
||||
if (!stream.value) body.wait = true // 同步等结果
|
||||
const j = await api('/v1/videos', { method: 'POST', body: JSON.stringify(body) })
|
||||
const task: VTask = {
|
||||
|
||||
+22
-9
@@ -94,14 +94,26 @@ def test_load_config_providers():
|
||||
# 智谱: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_ids = [m.id for m in cfg.providers["bigmodel"].models]
|
||||
assert bm_ids == ["GLM-4.7-Flash", "GLM-4-Flash-250414", "GLM-Z1-Flash",
|
||||
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"]
|
||||
for m in cfg.providers["bigmodel"].models:
|
||||
if m.id in ("GLM-4.6V-Flash", "GLM-4V-Flash", "GLM-4.1V-Thinking-Flash"):
|
||||
assert m.vision is True
|
||||
else:
|
||||
assert m.vision is False
|
||||
# 智谱媒体模型: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():
|
||||
@@ -2244,8 +2256,9 @@ def test_video_polls_merged_into_one_log_row_with_response():
|
||||
"prompt": "x", "aspect_ratio": "16:9"}, headers=ah)
|
||||
assert r.status_code == 200, r.text
|
||||
vid = r.json()["video_id"]
|
||||
client.get(f"/v1/videos/{vid}", headers=ah) # 第 1 次轮询 processing
|
||||
client.get(f"/v1/videos/{vid}", headers=ah) # 第 2 次轮询 completed
|
||||
poll_q = f"/v1/videos/{vid}?model=agnes-video-2.5-flash" # 多视频供应商(agnes+智谱)时必须显式指定 model
|
||||
client.get(poll_q, headers=ah) # 第 1 次轮询 processing
|
||||
client.get(poll_q, headers=ah) # 第 2 次轮询 completed
|
||||
logs = client.get("/logs?n=200", headers=ah).json()["entries"]
|
||||
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]}"
|
||||
|
||||
Reference in new issue
Block a user