第三十三轮:模型接口加入上下文参数(context_window / max_output_tokens)
老板 2026-09-24 要求:「文档里有写明支持上下文多少吗?有的话就修改 ai 网关, 接口加入上下文参数」+「Agnes 先加上,opencode go 看下 v2/docs/console/go/ 文档, 没有的话就看接口里有没有,这个也要加入同步脚本里」。 数据来源(逐一核查过): - Agnes:官方**每个文本模型详情页**的「限制与价格」表写明 `上下文窗口` / `最大输出` (定价页没有这两项)。3.0-flash = 512K/65,536、2.5-flash = 512K/65.5K、 2.5-pro 与 2.5-pro-beta = 1M/65,536。图片/视频页无此表 → 留 0。 - OpenCode:官方文档(Zen 页、v2/docs/console/go/)**都不写**上下文;`/zen/go/v1/models` 实测只回 id/object/created/owned_by(单模型详情 404、include 参数被忽略)。 唯一机器可读来源是 **models.dev**(OpenCode 团队维护),其 `opencode-go` / `opencode` 两供应商每条模型都带 `limit.context` / `limit.output`。 口径(老板拍板):只用于**更新网关已有模型**,不拿它当增删依据(models.dev 收录 比官方 Go 文档多,含 omen-alpha 等未收录的);跨源不一致时取**保守下限** (minimax-m3 Go 1M / Zen 512K → 512,000;qwen3.6-plus → 262,144)。 改动: - app/config.py:ModelInfo 新增 context_window / max_output_tokens(默认 0 = 未标注), 解析 + to_dict 序列化一并带上。 - app/main.py:GET /models 与 /v1/models 输出这两个字段;别名继承目标模型的值。 - app/settings.py:「供应商与模型」面板往返不丢字段(默认 0 → 未配置的模型不会被 补出 `context_window: 0` 污染 YAML);提交了就以此为准,没提交则沿用文件原文。 - data/gateway.yaml:37 个模型落盘(33 OpenCode + 4 Agnes 文本),文本级插入保住 全部手写注释(注释行 162 → 236)。 - scripts/sync_models.py:新增 fetch_models_dev()(拉失败返回 None → 只跳过上下文 同步、不当成漂移)、fetch_agnes_context()(逐模型页解析「限制与价格」表)、 diff() 产出 ctx_drift、build_plan/apply_plan(_set_context 块内改值,保留行尾注释、 幂等)、verify() 回读校验、render_plan/render 显示漂移;_DRIFT_KEYS 与 plan_is_empty 认 ctx_set。 - tests:新增 3 个(models.dev 保守下限合并 + 抓失败返回 None;_set_context 幂等与 保注释;/models 带出字段且未标注不瞎补)→ **201 passed / 0 failed**;ci_check.sh 全绿。 上线:supervisorctl restart api-gateway:api-gateway_00(pid 3492804)后实测 /v1/models 45 个模型、38 个带 context_window(含 wjd 别名继承 = 1,000,000/384,000), 图片模型正确为 0。
This commit is contained in:
1 parent
f6c1ecc4af
commit
4dc41e04e7
6 files changed
+428
-7
No files matched your search
@@ -138,6 +138,16 @@ class ModelInfo:
|
|||||||
# 由 scripts/sync_models.py 按文档自动维护(撤标注时整行删掉)。
|
# 由 scripts/sync_models.py 按文档自动维护(撤标注时整行删掉)。
|
||||||
# 同样只是标注:/v1/models 带出、前端标签文案据此切换,不参与路由/限流/计费。
|
# 同样只是标注:/v1/models 带出、前端标签文案据此切换,不参与路由/限流/计费。
|
||||||
free_limited: bool = False
|
free_limited: bool = False
|
||||||
|
# 第三十三轮(2026-09-24,老板要求:接口加入上下文参数): 模型的**上下文窗口**
|
||||||
|
# 与**最大输出**(单位 token)。0 = 未知/未标注(非文本模型天然没有)。
|
||||||
|
# 来源与维护:
|
||||||
|
# · Agnes 文本模型 → 官方文档每个模型页「限制与价格」表(权威值);
|
||||||
|
# · OpenCode Go → models.dev 的 `opencode-go` 供应商 `limit.context` / `limit.output`
|
||||||
|
# (OpenCode 官方文档与 /models 接口都不给这两个数,models.dev 是唯一可用来源);
|
||||||
|
# · 同名模型跨源不一致时取**保守下限**(宁可早压缩,不能超窗口)。
|
||||||
|
# 由 scripts/sync_models.py 每日同步;不参与路由/限流,仅作展示与调用方参考。
|
||||||
|
context_window: int = 0
|
||||||
|
max_output_tokens: int = 0
|
||||||
# 第二十五轮(模型参数硬约束): 该模型**必须用**的上游参数,发送前强制覆盖客户端传值。
|
# 第二十五轮(模型参数硬约束): 该模型**必须用**的上游参数,发送前强制覆盖客户端传值。
|
||||||
# 背景:OpenCode Go 的 kimi-k2.7-code 只接受 temperature=1,客户端传 0(含一键测速的
|
# 背景:OpenCode Go 的 kimi-k2.7-code 只接受 temperature=1,客户端传 0(含一键测速的
|
||||||
# 探针,它固定发 temperature=0)会被上游 400:
|
# 探针,它固定发 temperature=0)会被上游 400:
|
||||||
@@ -401,6 +411,10 @@ class GatewayConfig:
|
|||||||
# 2026-09-24: 「免费」还是「限时免费」—— 前端标签文案据此切换
|
# 2026-09-24: 「免费」还是「限时免费」—— 前端标签文案据此切换
|
||||||
# (免费 / 限时免费),也带进 /v1/models 让接口调用方知道优惠可能到期。
|
# (免费 / 限时免费),也带进 /v1/models 让接口调用方知道优惠可能到期。
|
||||||
"free_limited": bool(m.free_limited),
|
"free_limited": bool(m.free_limited),
|
||||||
|
# 第三十三轮(2026-09-24): 上下文窗口 / 最大输出(token)。0 = 未标注。
|
||||||
|
# 前端「能力」列与 /v1/models 均带出,调用方据此决定单次请求塞多长的对话。
|
||||||
|
"context_window": int(m.context_window or 0),
|
||||||
|
"max_output_tokens": int(m.max_output_tokens or 0),
|
||||||
"provider": pkey,
|
"provider": pkey,
|
||||||
"provider_name": pconfig.name,
|
"provider_name": pconfig.name,
|
||||||
# 第二十五轮: 暴露模型级强制参数(如 {"temperature": 1})。
|
# 第二十五轮: 暴露模型级强制参数(如 {"temperature": 1})。
|
||||||
@@ -793,6 +807,8 @@ def parse_config(raw: dict[str, Any]) -> GatewayConfig:
|
|||||||
type=m.get("type", "text"), vision=_opt_bool(m.get("vision"), "providers.*.models.*.vision", False),
|
type=m.get("type", "text"), vision=_opt_bool(m.get("vision"), "providers.*.models.*.vision", False),
|
||||||
free=_opt_bool(m.get("free"), "providers.*.models.*.free", False),
|
free=_opt_bool(m.get("free"), "providers.*.models.*.free", False),
|
||||||
free_limited=_opt_bool(m.get("free_limited"), "providers.*.models.*.free_limited", False),
|
free_limited=_opt_bool(m.get("free_limited"), "providers.*.models.*.free_limited", False),
|
||||||
|
context_window=_opt_int(m.get("context_window"), "providers.*.models.*.context_window", 0),
|
||||||
|
max_output_tokens=_opt_int(m.get("max_output_tokens"), "providers.*.models.*.max_output_tokens", 0),
|
||||||
params=_parse_model_params(
|
params=_parse_model_params(
|
||||||
m.get("params"), f"providers.{pkey}.models[{idx}].params"),
|
m.get("params"), f"providers.{pkey}.models[{idx}].params"),
|
||||||
protocols=_parse_protocols(
|
protocols=_parse_protocols(
|
||||||
|
|||||||
@@ -1229,6 +1229,10 @@ def _models_payload():
|
|||||||
"free": bool(m.get("free")),
|
"free": bool(m.get("free")),
|
||||||
# 2026-09-24: 免费是否带期限(限时免费)—— 前端标签文案据此切换
|
# 2026-09-24: 免费是否带期限(限时免费)—— 前端标签文案据此切换
|
||||||
"free_limited": bool(m.get("free_limited")),
|
"free_limited": bool(m.get("free_limited")),
|
||||||
|
# 第三十三轮(2026-09-24): 上下文窗口 / 最大输出(token)。0 = 未标注
|
||||||
|
# (非文本模型、或上游/文档都没给这个数)。调用方据此规划单次请求规模。
|
||||||
|
"context_window": int(m.get("context_window") or 0),
|
||||||
|
"max_output_tokens": int(m.get("max_output_tokens") or 0),
|
||||||
# 第二十五轮: 暴露模型级强制参数(如 {"temperature": 1})。前端据此标挂锁,
|
# 第二十五轮: 暴露模型级强制参数(如 {"temperature": 1})。前端据此标挂锁,
|
||||||
# API 调用方也能提前知道自己传的采样参数会被上游要求覆盖。
|
# API 调用方也能提前知道自己传的采样参数会被上游要求覆盖。
|
||||||
"params": dict(m.get("params") or {}),
|
"params": dict(m.get("params") or {}),
|
||||||
@@ -1259,6 +1263,9 @@ def _models_payload():
|
|||||||
# 2026-09-21: 免费位随目标继承(与 vision / params 同一份事实来源)
|
# 2026-09-21: 免费位随目标继承(与 vision / params 同一份事实来源)
|
||||||
"free": bool(aminfo.free),
|
"free": bool(aminfo.free),
|
||||||
"free_limited": bool(aminfo.free_limited),
|
"free_limited": bool(aminfo.free_limited),
|
||||||
|
# 第三十三轮: 上下文窗口 / 最大输出随目标继承(与 vision / params 同一份事实来源)
|
||||||
|
"context_window": int(aminfo.context_window or 0),
|
||||||
|
"max_output_tokens": int(aminfo.max_output_tokens or 0),
|
||||||
"params": dict(aminfo.params or {}),
|
"params": dict(aminfo.params or {}),
|
||||||
"protocols": list(ALIAS_PROTOCOLS),
|
"protocols": list(ALIAS_PROTOCOLS),
|
||||||
"alias_of": aminfo.id, "alias_note": spec.note})
|
"alias_of": aminfo.id, "alias_note": spec.note})
|
||||||
|
|||||||
+20
-1
@@ -111,7 +111,12 @@ def config_to_view(cfg: GatewayConfig) -> dict[str, Any]:
|
|||||||
# 第二十七轮: 模型能走哪几条协议线。这一项**面板可编辑**
|
# 第二十七轮: 模型能走哪几条协议线。这一项**面板可编辑**
|
||||||
# (「供应商与模型」页给每个模型打格式标签),所以两处都要认:
|
# (「供应商与模型」页给每个模型打格式标签),所以两处都要认:
|
||||||
# 读回给页面显示、写盘时以页面提交的为准。
|
# 读回给页面显示、写盘时以页面提交的为准。
|
||||||
"protocols": list(m.protocols)}
|
"protocols": list(m.protocols),
|
||||||
|
# 第三十三轮(2026-09-24): 上下文窗口 / 最大输出。面板不提供编辑入口
|
||||||
|
# (由 scripts/sync_models.py 每日同步),但必须一路带着走 ——
|
||||||
|
# 否则管理员在页面上随手保存一次,这两个值就被静默清成 0。
|
||||||
|
"context_window": int(m.context_window or 0),
|
||||||
|
"max_output_tokens": int(m.max_output_tokens or 0)}
|
||||||
for m in p.models
|
for m in p.models
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -224,6 +229,11 @@ _MODEL_KEY_DEFAULTS: dict[str, Any] = {
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"vision": False,
|
"vision": False,
|
||||||
"protocols": list(DEFAULT_PROTOCOLS), # 不写 = 自动走默认线(chat/completions)
|
"protocols": list(DEFAULT_PROTOCOLS), # 不写 = 自动走默认线(chat/completions)
|
||||||
|
# 第三十三轮(2026-09-24): 未标注的模型(图片/视频、或上游没给数的)**不写**这两个键。
|
||||||
|
# 默认 0 与 ModelInfo 一致 → _prune_defaults 会把面板补出来的 0 丢掉,
|
||||||
|
# 只有 sync_models.py 明确写入的非 0 值才留在文件里。
|
||||||
|
"context_window": 0,
|
||||||
|
"max_output_tokens": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -343,6 +353,15 @@ def view_to_raw(cfg: GatewayConfig, raw: dict[str, Any], view: dict[str, Any]) -
|
|||||||
"type": str(m.get("type") or "text").strip(),
|
"type": str(m.get("type") or "text").strip(),
|
||||||
"vision": bool(m.get("vision", False)),
|
"vision": bool(m.get("vision", False)),
|
||||||
})
|
})
|
||||||
|
# 第三十三轮(2026-09-24): 上下文窗口 / 最大输出由 sync_models.py 维护,
|
||||||
|
# 面板不提供编辑入口 —— 提交了就以此为准,没提交则沿用文件原文
|
||||||
|
# (旧前端/脚本提交时不至于把这两个值清成 0)。
|
||||||
|
for _k in ("context_window", "max_output_tokens"):
|
||||||
|
if m.get(_k) is not None:
|
||||||
|
try:
|
||||||
|
item[_k] = int(m.get(_k) or 0)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
pass
|
||||||
# 第二十七轮: 协议线由面板管理(每个模型的格式标签),提交了就以此为准;
|
# 第二十七轮: 协议线由面板管理(每个模型的格式标签),提交了就以此为准;
|
||||||
# 没提交则沿用文件原文里的值(避免旧前端/脚本提交时把 protocols 清空)。
|
# 没提交则沿用文件原文里的值(避免旧前端/脚本提交时把 protocols 清空)。
|
||||||
if m.get("protocols"):
|
if m.get("protocols"):
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ providers:
|
|||||||
- id: "agnes-3.0-flash"
|
- id: "agnes-3.0-flash"
|
||||||
display_name: "Agnes 3.0 Flash"
|
display_name: "Agnes 3.0 Flash"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 512000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 65536 # 最大输出(token)
|
||||||
free: true # 2026-09-24 自动同步:文档「当前优惠」写当前免费(scripts/sync_models.py)
|
free: true # 2026-09-24 自动同步:文档「当前优惠」写当前免费(scripts/sync_models.py)
|
||||||
# 第十三轮: Agnes 3.0 Flash 文档「输入模态:文本、图像 URL」→ 支持视觉(对话带图)。
|
# 第十三轮: Agnes 3.0 Flash 文档「输入模态:文本、图像 URL」→ 支持视觉(对话带图)。
|
||||||
# 实测 data:image/png;base64,... 也能识别。
|
# 实测 data:image/png;base64,... 也能识别。
|
||||||
@@ -34,6 +36,8 @@ providers:
|
|||||||
- id: "agnes-2.5-flash"
|
- id: "agnes-2.5-flash"
|
||||||
display_name: "Agnes 2.5 Flash"
|
display_name: "Agnes 2.5 Flash"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 512000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 65500 # 最大输出(token)
|
||||||
free: true # 2026-09-24 自动同步:文档「当前优惠」写当前免费(scripts/sync_models.py)
|
free: true # 2026-09-24 自动同步:文档「当前优惠」写当前免费(scripts/sync_models.py)
|
||||||
# Agnes 2.5 Flash(2.0 升级版):OpenAI 兼容 /v1/chat/completions,支持图像 URL 输入与工具调用,
|
# Agnes 2.5 Flash(2.0 升级版):OpenAI 兼容 /v1/chat/completions,支持图像 URL 输入与工具调用,
|
||||||
# 上下文 512K / 最大输出 65.5K;当前定价暂免(¥0/百万)。参见官方文档 agnes-25-flash。
|
# 上下文 512K / 最大输出 65.5K;当前定价暂免(¥0/百万)。参见官方文档 agnes-25-flash。
|
||||||
@@ -51,11 +55,15 @@ providers:
|
|||||||
- id: "agnes-2.5-pro"
|
- id: "agnes-2.5-pro"
|
||||||
display_name: "Agnes 2.5 Pro"
|
display_name: "Agnes 2.5 Pro"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 65536 # 最大输出(token)
|
||||||
# 文档现价 ¥3/M 输入、¥6/M 输出
|
# 文档现价 ¥3/M 输入、¥6/M 输出
|
||||||
# 2026-09-24 自动同步:官方文档新增(scripts/sync_models.py)
|
# 2026-09-24 自动同步:官方文档新增(scripts/sync_models.py)
|
||||||
- id: "agnes-2.5-pro-beta"
|
- id: "agnes-2.5-pro-beta"
|
||||||
display_name: "Agnes 2.5 Pro Beta"
|
display_name: "Agnes 2.5 Pro Beta"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 65536 # 最大输出(token)
|
||||||
# 文档现价 ¥0.7/M 输入、¥2.1/M 输出
|
# 文档现价 ¥0.7/M 输入、¥2.1/M 输出
|
||||||
# 2026-09-24 自动同步:官方文档新增(scripts/sync_models.py)
|
# 2026-09-24 自动同步:官方文档新增(scripts/sync_models.py)
|
||||||
- id: "agnes-image-2.0-flash"
|
- id: "agnes-image-2.0-flash"
|
||||||
@@ -146,22 +154,32 @@ providers:
|
|||||||
- id: "glm-5.3-flash"
|
- id: "glm-5.3-flash"
|
||||||
display_name: "GLM-5.3-Flash"
|
display_name: "GLM-5.3-Flash"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "glm-5.3"
|
- id: "glm-5.3"
|
||||||
display_name: "GLM-5.3"
|
display_name: "GLM-5.3"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "glm-5.2"
|
- id: "glm-5.2"
|
||||||
display_name: "GLM-5.2"
|
display_name: "GLM-5.2"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "glm-5.1"
|
- id: "glm-5.1"
|
||||||
display_name: "GLM-5.1"
|
display_name: "GLM-5.1"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 202752 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 32768 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "kimi-k2.7-code"
|
- id: "kimi-k2.7-code"
|
||||||
display_name: "Kimi K2.7 Code"
|
display_name: "Kimi K2.7 Code"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 262144 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 262144 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
# 上游硬约束:该模型**只接受 temperature=1**,传 0 / 0.7 等一律 400
|
# 上游硬约束:该模型**只接受 temperature=1**,传 0 / 0.7 等一律 400
|
||||||
# "invalid temperature: only 1 is allowed for this model"。
|
# "invalid temperature: only 1 is allowed for this model"。
|
||||||
@@ -172,40 +190,58 @@ providers:
|
|||||||
- id: "kimi-k2.6"
|
- id: "kimi-k2.6"
|
||||||
display_name: "Kimi K2.6"
|
display_name: "Kimi K2.6"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 262144 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 65536 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "longcat-2.0"
|
- id: "longcat-2.0"
|
||||||
display_name: "LongCat 2.0"
|
display_name: "LongCat 2.0"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "mimo-v2.5"
|
- id: "mimo-v2.5"
|
||||||
display_name: "MiMo V2.5"
|
display_name: "MiMo V2.5"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 128000 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "mimo-v2.5-pro"
|
- id: "mimo-v2.5-pro"
|
||||||
display_name: "MiMo V2.5 Pro"
|
display_name: "MiMo V2.5 Pro"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 128000 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "hy4-preview"
|
- id: "hy4-preview"
|
||||||
display_name: "Hy4 Preview"
|
display_name: "Hy4 Preview"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1024000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 64000 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "hy3"
|
- id: "hy3"
|
||||||
display_name: "Hy3"
|
display_name: "Hy3"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 256000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 128000 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
# ── 2026-09-21 按上游 /models + 官方文档表补录 ──────────
|
# ── 2026-09-21 按上游 /models + 官方文档表补录 ──────────
|
||||||
- id: "mimo-v2.6-flash"
|
- id: "mimo-v2.6-flash"
|
||||||
display_name: "MiMo V2.6 Flash"
|
display_name: "MiMo V2.6 Flash"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
# 实测:chat 200;messages / responses 都是 503「Endpoint is unavailable」
|
# 实测:chat 200;messages / responses 都是 503「Endpoint is unavailable」
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "mimo-v2.6-pro"
|
- id: "mimo-v2.6-pro"
|
||||||
display_name: "MiMo V2.6 Pro"
|
display_name: "MiMo V2.6 Pro"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
protocols: ["chat/completions"]
|
protocols: ["chat/completions"]
|
||||||
- id: "space-bunny-free"
|
- id: "space-bunny-free"
|
||||||
display_name: "Space Bunny Free(免费)"
|
display_name: "Space Bunny Free(免费)"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 524288 # 最大输出(token)
|
||||||
free: true # 前端「能力」列据此打「免费」标签;/v1/models 也会带出 free 字段
|
free: true # 前端「能力」列据此打「免费」标签;/v1/models 也会带出 free 字段
|
||||||
# ★ 免费模型:官方文档价格表 Free / Free / Free,额度 Unlimited(限时)。
|
# ★ 免费模型:官方文档价格表 Free / Free / Free,额度 Unlimited(限时)。
|
||||||
# 接替已下线的 union-alpha(Union Alpha Free)。
|
# 接替已下线的 union-alpha(Union Alpha Free)。
|
||||||
@@ -217,60 +253,86 @@ providers:
|
|||||||
- id: "kimi-k3"
|
- id: "kimi-k3"
|
||||||
display_name: "Kimi K3"
|
display_name: "Kimi K3"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages"]
|
protocols: ["chat/completions", "messages"]
|
||||||
- id: "minimax-m3"
|
- id: "minimax-m3"
|
||||||
display_name: "MiniMax M3"
|
display_name: "MiniMax M3"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 512000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 128000 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages"]
|
protocols: ["chat/completions", "messages"]
|
||||||
- id: "minimax-m2.5"
|
- id: "minimax-m2.5"
|
||||||
display_name: "MiniMax M2.5"
|
display_name: "MiniMax M2.5"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 204800 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 65536 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages"]
|
protocols: ["chat/completions", "messages"]
|
||||||
- id: "qwen3.8-max"
|
- id: "qwen3.8-max"
|
||||||
display_name: "Qwen3.8 Max"
|
display_name: "Qwen3.8 Max"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages"]
|
protocols: ["chat/completions", "messages"]
|
||||||
- id: "qwen3.8-flash"
|
- id: "qwen3.8-flash"
|
||||||
display_name: "Qwen3.8 Flash"
|
display_name: "Qwen3.8 Flash"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages"]
|
protocols: ["chat/completions", "messages"]
|
||||||
- id: "qwen3.7-max"
|
- id: "qwen3.7-max"
|
||||||
display_name: "Qwen3.7 Max"
|
display_name: "Qwen3.7 Max"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 65536 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages"]
|
protocols: ["chat/completions", "messages"]
|
||||||
- id: "qwen3.7-plus"
|
- id: "qwen3.7-plus"
|
||||||
display_name: "Qwen3.7 Plus"
|
display_name: "Qwen3.7 Plus"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 65536 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages"]
|
protocols: ["chat/completions", "messages"]
|
||||||
- id: "qwen3.6-plus"
|
- id: "qwen3.6-plus"
|
||||||
display_name: "Qwen3.6 Plus"
|
display_name: "Qwen3.6 Plus"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 262144 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 65536 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages"]
|
protocols: ["chat/completions", "messages"]
|
||||||
# ── 三条线全通(实测 chat / messages / responses 均 200,
|
# ── 三条线全通(实测 chat / messages / responses 均 200,
|
||||||
# 非文档线另经流式 + 工具调用复核) ────────────────
|
# 非文档线另经流式 + 工具调用复核) ────────────────
|
||||||
- id: "deepseek-v4.1-flash"
|
- id: "deepseek-v4.1-flash"
|
||||||
display_name: "DeepSeek V4.1 Flash"
|
display_name: "DeepSeek V4.1 Flash"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 384000 # 最大输出(token)
|
||||||
vision: true # 2026-09-18 实测确认多模态:data:image/png;base64 红/蓝/绿三色均识别正确;
|
vision: true # 2026-09-18 实测确认多模态:data:image/png;base64 红/蓝/绿三色均识别正确;
|
||||||
# 同一带图请求打到纯文本模型 deepseek-v4-flash 会被上游 400 拒(对照有效)。
|
# 同一带图请求打到纯文本模型 deepseek-v4-flash 会被上游 400 拒(对照有效)。
|
||||||
protocols: ["chat/completions", "messages", "responses"]
|
protocols: ["chat/completions", "messages", "responses"]
|
||||||
- id: "deepseek-v4-pro"
|
- id: "deepseek-v4-pro"
|
||||||
display_name: "DeepSeek V4 Pro"
|
display_name: "DeepSeek V4 Pro"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 384000 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages", "responses"]
|
protocols: ["chat/completions", "messages", "responses"]
|
||||||
- id: "deepseek-v4-flash"
|
- id: "deepseek-v4-flash"
|
||||||
display_name: "DeepSeek V4 Flash"
|
display_name: "DeepSeek V4 Flash"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 384000 # 最大输出(token)
|
||||||
protocols: ["chat/completions", "messages", "responses"]
|
protocols: ["chat/completions", "messages", "responses"]
|
||||||
- id: "deepseek-v4-flash-vision-exp"
|
- id: "deepseek-v4-flash-vision-exp"
|
||||||
display_name: "DeepSeek V4 Flash Vision Exp"
|
display_name: "DeepSeek V4 Flash Vision Exp"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1000000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 384000 # 最大输出(token)
|
||||||
vision: true # 官方标 Vision,支持图像转 token 输入
|
vision: true # 官方标 Vision,支持图像转 token 输入
|
||||||
protocols: ["chat/completions", "messages", "responses"]
|
protocols: ["chat/completions", "messages", "responses"]
|
||||||
# ── Anthropic Messages 线(文档主推这条)─────────────
|
# ── Anthropic Messages 线(文档主推这条)─────────────
|
||||||
- id: "minimax-m2.7"
|
- id: "minimax-m2.7"
|
||||||
display_name: "MiniMax M2.7"
|
display_name: "MiniMax M2.7"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 204800 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
# 实测:messages 线 200,chat / responses 都是 500 → 只标 messages
|
# 实测:messages 线 200,chat / responses 都是 500 → 只标 messages
|
||||||
protocols: ["messages"]
|
protocols: ["messages"]
|
||||||
# 2026-09-21:`union-alpha`(Union Alpha Free)已从上游 Go 计划下线(/models 不再返回,
|
# 2026-09-21:`union-alpha`(Union Alpha Free)已从上游 Go 计划下线(/models 不再返回,
|
||||||
@@ -280,25 +342,35 @@ providers:
|
|||||||
- id: "grok-4.6"
|
- id: "grok-4.6"
|
||||||
display_name: "Grok 4.6"
|
display_name: "Grok 4.6"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 500000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 500000 # 最大输出(token)
|
||||||
# 实测:responses 200;chat / messages 都是 401 "not supported for format"
|
# 实测:responses 200;chat / messages 都是 401 "not supported for format"
|
||||||
protocols: ["responses"]
|
protocols: ["responses"]
|
||||||
- id: "grok-4.7"
|
- id: "grok-4.7"
|
||||||
display_name: "Grok 4.7"
|
display_name: "Grok 4.7"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 500000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 500000 # 最大输出(token)
|
||||||
# 2026-09-21 新增;实测 responses 200,chat / messages 都是 503「Endpoint is unavailable」
|
# 2026-09-21 新增;实测 responses 200,chat / messages 都是 503「Endpoint is unavailable」
|
||||||
protocols: ["responses"]
|
protocols: ["responses"]
|
||||||
- id: "gpt-5.6-luna"
|
- id: "gpt-5.6-luna"
|
||||||
display_name: "GPT 5.6 Luna"
|
display_name: "GPT 5.6 Luna"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1050000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 128000 # 最大输出(token)
|
||||||
protocols: ["responses"]
|
protocols: ["responses"]
|
||||||
- id: "gpt-6-luna"
|
- id: "gpt-6-luna"
|
||||||
display_name: "GPT 6 Luna"
|
display_name: "GPT 6 Luna"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1050000 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 128000 # 最大输出(token)
|
||||||
# 2026-09-21 新增;实测 responses 200(官方文档表同样标 responses)
|
# 2026-09-21 新增;实测 responses 200(官方文档表同样标 responses)
|
||||||
protocols: ["responses"]
|
protocols: ["responses"]
|
||||||
- id: "muse-spark-1.3-contributor"
|
- id: "muse-spark-1.3-contributor"
|
||||||
display_name: "Muse Spark 1.3 Contributor"
|
display_name: "Muse Spark 1.3 Contributor"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
# 实测三条线都 403 DataPolicyError:该模型会拿数据训练,需要先在
|
# 实测三条线都 403 DataPolicyError:该模型会拿数据训练,需要先在
|
||||||
# OpenCode 控制台**显式同意数据条款**才能调用(当前工作区未同意)。
|
# OpenCode 控制台**显式同意数据条款**才能调用(当前工作区未同意)。
|
||||||
# 先收录并标好线:老板去控制台点了同意就能直接用,不用再改网关。
|
# 先收录并标好线:老板去控制台点了同意就能直接用,不用再改网关。
|
||||||
@@ -306,6 +378,8 @@ providers:
|
|||||||
- id: "muse-spark-1.2-contributor"
|
- id: "muse-spark-1.2-contributor"
|
||||||
display_name: "Muse Spark 1.2 Contributor"
|
display_name: "Muse Spark 1.2 Contributor"
|
||||||
type: "text"
|
type: "text"
|
||||||
|
context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护
|
||||||
|
max_output_tokens: 131072 # 最大输出(token)
|
||||||
protocols: ["responses"]
|
protocols: ["responses"]
|
||||||
# ── 虚拟模型 id(别名,第三十一轮)──────────────────────────
|
# ── 虚拟模型 id(别名,第三十一轮)──────────────────────────
|
||||||
# 客户端固定写 model: wjd,实际转发到哪个真实模型由**管理员在模型页选**(也可以改这里)。
|
# 客户端固定写 model: wjd,实际转发到哪个真实模型由**管理员在模型页选**(也可以改这里)。
|
||||||
|
|||||||
+207
-6
@@ -107,6 +107,50 @@ def fetch_opencode() -> dict[str, dict]:
|
|||||||
return models
|
return models
|
||||||
|
|
||||||
|
|
||||||
|
# ── models.dev(上下文窗口 / 最大输出)──────────────────────────
|
||||||
|
# 第三十三轮(2026-09-24 老板要求:接口加入上下文参数):
|
||||||
|
# OpenCode 官方文档(Zen / Go / v2)**都不写**上下文长度,`/zen/go/v1/models`
|
||||||
|
# 也只回 id/object/created/owned_by(实测:单模型详情 404、include 参数被忽略)。
|
||||||
|
# 唯一可用的机器可读来源是 models.dev(OpenCode 团队维护的模型目录),其
|
||||||
|
# `opencode-go` / `opencode` 两个供应商的每条模型都带 `limit.context` / `limit.output`。
|
||||||
|
# 口径(老板拍板):
|
||||||
|
# · 只用于**更新网关已有模型**的这两个字段,不拿它当增删依据
|
||||||
|
# (增删仍以官方 Go 文档表为准 —— models.dev 收录更多,含 omen-alpha 等文档未收的);
|
||||||
|
# · 同名模型在两个供应商下不一致时(如 minimax-m3:Go 1M / Zen 512K)取**保守下限**
|
||||||
|
# (宁可早压缩,不能超窗口);
|
||||||
|
# · models.dev 挂了/改版 → 只跳过上下文同步,不影响增删判定(返回 None)。
|
||||||
|
MD_DEV_URL = "https://models.dev/api.json"
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_models_dev() -> dict[str, dict] | None:
|
||||||
|
"""返回 {model_id: {"context": int, "output": int}}(两供应商合并取保守下限)。
|
||||||
|
|
||||||
|
拉不到就返回 None —— 调用方据此跳过上下文同步,不当成漂移。
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
raw = _get(MD_DEV_URL, timeout=60)
|
||||||
|
data = json.loads(raw)
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
print(f"[warn] models.dev 拉取失败,跳过上下文同步:{exc}", file=sys.stderr)
|
||||||
|
return None
|
||||||
|
merged: dict[str, dict] = {}
|
||||||
|
for prov in ("opencode-go", "opencode"):
|
||||||
|
for mid, m in ((data.get(prov) or {}).get("models") or {}).items():
|
||||||
|
lim = (m or {}).get("limit") or {}
|
||||||
|
ctx, out = lim.get("context"), lim.get("output")
|
||||||
|
if not ctx:
|
||||||
|
continue
|
||||||
|
cur = merged.get(mid) or {"context": ctx, "output": out or 0}
|
||||||
|
cur["context"] = min(cur["context"], ctx) # 保守下限
|
||||||
|
if out:
|
||||||
|
cur["output"] = min(cur["output"] or out, out) if cur["output"] else out
|
||||||
|
merged[mid] = cur
|
||||||
|
if not merged:
|
||||||
|
print("[warn] models.dev 解析出 0 个模型,跳过上下文同步", file=sys.stderr)
|
||||||
|
return None
|
||||||
|
return merged
|
||||||
|
|
||||||
|
|
||||||
# ── Agnes ──────────────────────────────────────────────────────
|
# ── Agnes ──────────────────────────────────────────────────────
|
||||||
_MODEL_ID_RE = re.compile(r"[a-z][a-z0-9.\-]*[0-9][a-z0-9.\-]*")
|
_MODEL_ID_RE = re.compile(r"[a-z][a-z0-9.\-]*[0-9][a-z0-9.\-]*")
|
||||||
|
|
||||||
@@ -208,6 +252,62 @@ def fetch_agnes() -> dict[str, dict]:
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
# ── Agnes 上下文窗口(模型详情页「限制与价格」表)──────────────────
|
||||||
|
# 第三十三轮(2026-09-24): Agnes 官方**每个文本模型页**都有一张「限制与价格」表,
|
||||||
|
# 写明 `上下文窗口`(如 `512K` / `1M tokens`)与 `最大输出`(如 `65,536 Token`)。
|
||||||
|
# 定价页没有这两项 —— 所以要去逐个模型页抓。图片/视频模型页无此表 → 抓不到 = 留空。
|
||||||
|
AGNES_MODEL_PAGES = {
|
||||||
|
"agnes-3.0-flash": "https://www.agnes-ai.cn/zh-Hans/docs/agnes-30-flash",
|
||||||
|
"agnes-2.5-flash": "https://www.agnes-ai.cn/zh-Hans/docs/agnes-25-flash",
|
||||||
|
"agnes-2.5-pro": "https://www.agnes-ai.cn/zh-Hans/docs/agnes-25-pro",
|
||||||
|
"agnes-2.5-pro-beta": "https://www.agnes-ai.cn/zh-Hans/docs/agnes-25-pro-beta",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_tokens(cell: str) -> int | None:
|
||||||
|
"""`512K` / `1M tokens` / `65,536 Token` / `65536` → 整数 token 数。"""
|
||||||
|
s = _strip_tags(cell).lower().replace(",", "").replace(" ", "")
|
||||||
|
m = re.search(r"([0-9.]+)\s*([km])?", s)
|
||||||
|
if not m:
|
||||||
|
return None
|
||||||
|
val = float(m.group(1))
|
||||||
|
unit = m.group(2)
|
||||||
|
if unit == "k":
|
||||||
|
val *= 1000
|
||||||
|
elif unit == "m":
|
||||||
|
val *= 1_000_000
|
||||||
|
return int(val)
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_agnes_context() -> dict[str, dict]:
|
||||||
|
"""逐个 Agnes 文本模型页抓 `上下文窗口` / `最大输出` → {id: {context, output}}。
|
||||||
|
|
||||||
|
单页抓失败只跳过该模型(不抛)—— 上下文同步是增量能力,不该拖垮整个同步任务。
|
||||||
|
"""
|
||||||
|
out: dict[str, dict] = {}
|
||||||
|
for mid, url in AGNES_MODEL_PAGES.items():
|
||||||
|
try:
|
||||||
|
html = _get(url)
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
print(f"[warn] Agnes 模型页抓取失败 {mid}: {exc}", file=sys.stderr)
|
||||||
|
continue
|
||||||
|
ctx = out_tok = None
|
||||||
|
for row in re.findall(r"<tr>(.*?)</tr>", html, re.S):
|
||||||
|
cells = [_strip_tags(c) for c in re.findall(r"<t[dh][^>]*>(.*?)</t[dh]>", row, re.S)]
|
||||||
|
if len(cells) < 2:
|
||||||
|
continue
|
||||||
|
label = cells[0].replace(" ", "")
|
||||||
|
if "上下文窗口" in label:
|
||||||
|
ctx = _parse_tokens(cells[1])
|
||||||
|
elif "最大输出" in label:
|
||||||
|
out_tok = _parse_tokens(cells[1])
|
||||||
|
if ctx:
|
||||||
|
out[mid] = {"context": ctx, "output": out_tok or 0}
|
||||||
|
if not out:
|
||||||
|
print("[warn] Agnes 模型页一个上下文都没解析出来(页面可能改版)", file=sys.stderr)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
# ── 比对 ───────────────────────────────────────────────────────
|
# ── 比对 ───────────────────────────────────────────────────────
|
||||||
def _references(cfg: dict) -> dict[str, str]:
|
def _references(cfg: dict) -> dict[str, str]:
|
||||||
"""被别名 / media 指向的模型 id → 引用原因。删这些会直接打断功能,故永不自动删。"""
|
"""被别名 / media 指向的模型 id → 引用原因。删这些会直接打断功能,故永不自动删。"""
|
||||||
@@ -251,7 +351,9 @@ def _split_removed(prov: str, cur: dict, doc: dict, refs: dict) -> tuple[list[st
|
|||||||
return drop, keep
|
return drop, keep
|
||||||
|
|
||||||
|
|
||||||
def diff(cfg: dict, oc_doc: dict, agnes_doc: dict) -> dict:
|
def diff(cfg: dict, oc_doc: dict, agnes_doc: dict,
|
||||||
|
md_dev: dict[str, dict] | None = None,
|
||||||
|
ag_ctx: dict[str, dict] | None = None) -> dict:
|
||||||
providers = cfg.get("providers", {})
|
providers = cfg.get("providers", {})
|
||||||
pricing = (cfg.get("pricing") or {}).get("per_model") or {}
|
pricing = (cfg.get("pricing") or {}).get("per_model") or {}
|
||||||
refs = _references(cfg)
|
refs = _references(cfg)
|
||||||
@@ -270,6 +372,19 @@ def diff(cfg: dict, oc_doc: dict, agnes_doc: dict) -> dict:
|
|||||||
for mid, meta in sorted(oc_doc.items())
|
for mid, meta in sorted(oc_doc.items())
|
||||||
if mid in oc_cur and meta["free"] != bool(oc_cur[mid].get("free"))]
|
if mid in oc_cur and meta["free"] != bool(oc_cur[mid].get("free"))]
|
||||||
oc_drop, oc_keep = _split_removed("opencode", oc_cur, oc_doc, refs)
|
oc_drop, oc_keep = _split_removed("opencode", oc_cur, oc_doc, refs)
|
||||||
|
# 第三十三轮: 上下文窗口漂移(models.dev 现值 vs 网关现值)。
|
||||||
|
# 只比对**网关已有模型**(不拿 models.dev 当增删依据);md_dev 为 None(拉取失败)
|
||||||
|
# 时留空 → 不产生漂移、不写盘。
|
||||||
|
oc_ctx_drift = []
|
||||||
|
for mid, m in sorted(oc_cur.items()):
|
||||||
|
want = (md_dev or {}).get(mid)
|
||||||
|
if not want or not want.get("context"):
|
||||||
|
continue
|
||||||
|
have_ctx = int(m.get("context_window") or 0)
|
||||||
|
have_out = int(m.get("max_output_tokens") or 0)
|
||||||
|
if have_ctx != want["context"] or (want.get("output") and have_out != want["output"]):
|
||||||
|
oc_ctx_drift.append({"id": mid, "cfg_ctx": have_ctx, "doc_ctx": want["context"],
|
||||||
|
"cfg_out": have_out, "doc_out": want.get("output") or have_out})
|
||||||
report["opencode"] = {
|
report["opencode"] = {
|
||||||
"doc_count": len(oc_doc), "cfg_count": len(oc_cur),
|
"doc_count": len(oc_doc), "cfg_count": len(oc_cur),
|
||||||
"added": [{"id": k, "name": v["name"], "protocol": v["protocol"], "free": v["free"]}
|
"added": [{"id": k, "name": v["name"], "protocol": v["protocol"], "free": v["free"]}
|
||||||
@@ -278,6 +393,7 @@ def diff(cfg: dict, oc_doc: dict, agnes_doc: dict) -> dict:
|
|||||||
"protected": oc_keep,
|
"protected": oc_keep,
|
||||||
"protocol_drift": proto_drift,
|
"protocol_drift": proto_drift,
|
||||||
"free_drift": free_drift,
|
"free_drift": free_drift,
|
||||||
|
"ctx_drift": oc_ctx_drift,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Agnes
|
# Agnes
|
||||||
@@ -291,8 +407,20 @@ def diff(cfg: dict, oc_doc: dict, agnes_doc: dict) -> dict:
|
|||||||
if have != want:
|
if have != want:
|
||||||
price_drift.append({"id": mid, "cfg": have, "doc": want})
|
price_drift.append({"id": mid, "cfg": have, "doc": want})
|
||||||
ag_drop, ag_keep = _split_removed("agnes", ag_cur, agnes_doc, refs)
|
ag_drop, ag_keep = _split_removed("agnes", ag_cur, agnes_doc, refs)
|
||||||
|
# 第三十三轮: Agnes 上下文漂移(模型详情页 vs 网关现值),同 opencode 口径。
|
||||||
|
ag_ctx_drift = []
|
||||||
|
for mid, want in sorted((ag_ctx or {}).items()):
|
||||||
|
m = ag_cur.get(mid)
|
||||||
|
if not m or not want.get("context"):
|
||||||
|
continue
|
||||||
|
have_ctx = int(m.get("context_window") or 0)
|
||||||
|
have_out = int(m.get("max_output_tokens") or 0)
|
||||||
|
if have_ctx != want["context"] or (want.get("output") and have_out != want["output"]):
|
||||||
|
ag_ctx_drift.append({"id": mid, "cfg_ctx": have_ctx, "doc_ctx": want["context"],
|
||||||
|
"cfg_out": have_out, "doc_out": want.get("output") or have_out})
|
||||||
report["agnes"] = {
|
report["agnes"] = {
|
||||||
"doc_count": len(agnes_doc), "cfg_count": len(ag_cur),
|
"doc_count": len(agnes_doc), "cfg_count": len(ag_cur),
|
||||||
|
"ctx_drift": ag_ctx_drift,
|
||||||
"added": [{"id": k, "section": v["section"], "type": v["type"],
|
"added": [{"id": k, "section": v["section"], "type": v["type"],
|
||||||
"display_name": pretty_name(k), "input": v["input"], "output": v["output"]}
|
"display_name": pretty_name(k), "input": v["input"], "output": v["output"]}
|
||||||
for k, v in sorted(agnes_doc.items()) if k not in ag_cur],
|
for k, v in sorted(agnes_doc.items()) if k not in ag_cur],
|
||||||
@@ -343,7 +471,12 @@ def render(report: dict) -> str:
|
|||||||
if oc["free_drift"]:
|
if oc["free_drift"]:
|
||||||
lines.append(" 免费标记漂移 → 落盘时更新:")
|
lines.append(" 免费标记漂移 → 落盘时更新:")
|
||||||
lines += [f" ~ {d['id']} 文档={d['doc_free']} 网关={d['cfg_free']}" for d in oc["free_drift"]]
|
lines += [f" ~ {d['id']} 文档={d['doc_free']} 网关={d['cfg_free']}" for d in oc["free_drift"]]
|
||||||
if not any(oc[k] for k in ("added", "removed", "protocol_drift", "free_drift")):
|
if oc.get("ctx_drift"):
|
||||||
|
lines.append(" 上下文窗口漂移(models.dev vs 网关)→ 落盘更新:")
|
||||||
|
lines += [f" ~ {d['id']} 网关={d['cfg_ctx']:,}/{d['cfg_out']:,}"
|
||||||
|
f" 来源={d['doc_ctx']:,}/{d['doc_out']:,}" for d in oc["ctx_drift"]]
|
||||||
|
if not any(oc[k] for k in ("added", "removed", "protocol_drift", "free_drift",
|
||||||
|
"ctx_drift")):
|
||||||
lines.append(" 无漂移 ✓")
|
lines.append(" 无漂移 ✓")
|
||||||
|
|
||||||
lines.append("")
|
lines.append("")
|
||||||
@@ -369,6 +502,10 @@ def render(report: dict) -> str:
|
|||||||
label = {True: "免费", "limited": "限时免费", None: "(无标注)"}
|
label = {True: "免费", "limited": "限时免费", None: "(无标注)"}
|
||||||
lines += [f" ~ {d['id']} 网关={label.get(d['cfg'], d['cfg'])}"
|
lines += [f" ~ {d['id']} 网关={label.get(d['cfg'], d['cfg'])}"
|
||||||
f" 文档={label.get(d['doc'], d['doc'])}" for d in ag["free_drift"]]
|
f" 文档={label.get(d['doc'], d['doc'])}" for d in ag["free_drift"]]
|
||||||
|
if ag.get("ctx_drift"):
|
||||||
|
lines.append(" 上下文窗口漂移(Agnes 模型页 vs 网关)→ 落盘更新:")
|
||||||
|
lines += [f" ~ {d['id']} 网关={d['cfg_ctx']:,}/{d['cfg_out']:,}"
|
||||||
|
f" 文档={d['doc_ctx']:,}/{d['doc_out']:,}" for d in ag["ctx_drift"]]
|
||||||
vd = ag.get("video_default") or {}
|
vd = ag.get("video_default") or {}
|
||||||
if vd.get("cfg"):
|
if vd.get("cfg"):
|
||||||
mark = ("✓ 文档里还在" if vd.get("in_doc")
|
mark = ("✓ 文档里还在" if vd.get("in_doc")
|
||||||
@@ -381,7 +518,8 @@ def render(report: dict) -> str:
|
|||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
_DRIFT_KEYS = ("added", "removed", "protocol_drift", "free_drift", "price_drift")
|
_DRIFT_KEYS = ("added", "removed", "protocol_drift", "free_drift", "price_drift",
|
||||||
|
"ctx_drift")
|
||||||
|
|
||||||
|
|
||||||
def has_drift(report: dict) -> bool:
|
def has_drift(report: dict) -> bool:
|
||||||
@@ -558,6 +696,37 @@ def _set_free(seg: list[str], want: bool, date: str) -> list[str]:
|
|||||||
_AGNES_FREE_LINE_RE = re.compile(r"^\s*(free|free_limited):\s*")
|
_AGNES_FREE_LINE_RE = re.compile(r"^\s*(free|free_limited):\s*")
|
||||||
|
|
||||||
|
|
||||||
|
_CTX_KEY_RE = re.compile(r"^\s*(context_window|max_output_tokens):")
|
||||||
|
|
||||||
|
|
||||||
|
def _set_context(seg: list[str], ctx: int, out_tok: int, date: str) -> list[str]:
|
||||||
|
"""块内设置 context_window / max_output_tokens(第三十三轮)。
|
||||||
|
|
||||||
|
· 已有该行 → 只改值,保留行尾注释;
|
||||||
|
· 没有 → 插在 `type:` 行之后(与手工插入的位置一致)。
|
||||||
|
只动这两行,其余原文(含手写注释)不动。
|
||||||
|
"""
|
||||||
|
want = {"context_window": ctx, "max_output_tokens": out_tok}
|
||||||
|
seen: set[str] = set()
|
||||||
|
for i, ln in enumerate(seg):
|
||||||
|
m = _CTX_KEY_RE.match(ln)
|
||||||
|
if not m:
|
||||||
|
continue
|
||||||
|
key = m.group(1)
|
||||||
|
seen.add(key)
|
||||||
|
tail = ln.split("#", 1)[1] if "#" in ln else f" # 同步 {date}(scripts/sync_models.py)"
|
||||||
|
seg[i] = f" {key}: {want[key]} #{tail}"
|
||||||
|
missing = [k for k in want if k not in seen]
|
||||||
|
if missing:
|
||||||
|
for i, ln in enumerate(seg):
|
||||||
|
if re.match(r'^\s{8}type:\s*"', ln):
|
||||||
|
extra = [f" {k}: {want[k]} # 同步 {date}(scripts/sync_models.py)\n"
|
||||||
|
for k in missing]
|
||||||
|
seg[i + 1:i + 1] = extra
|
||||||
|
break
|
||||||
|
return seg
|
||||||
|
|
||||||
|
|
||||||
def _set_agnes_free(seg: list[str], want: object, date: str) -> list[str]:
|
def _set_agnes_free(seg: list[str], want: object, date: str) -> list[str]:
|
||||||
"""按文档写 Agnes 模型的免费标注(2026-09-24 老板要求 Agnes 也要标)。
|
"""按文档写 Agnes 模型的免费标注(2026-09-24 老板要求 Agnes 也要标)。
|
||||||
|
|
||||||
@@ -589,7 +758,7 @@ def build_plan(report: dict, cfg: dict, oc_doc: dict, agnes_doc: dict) -> dict:
|
|||||||
docs = {"opencode": oc_doc, "agnes": agnes_doc}
|
docs = {"opencode": oc_doc, "agnes": agnes_doc}
|
||||||
pricing = (cfg.get("pricing") or {}).get("per_model") or {}
|
pricing = (cfg.get("pricing") or {}).get("per_model") or {}
|
||||||
plan: dict = {"add": {}, "remove": {}, "price_set": {}, "price_add": {},
|
plan: dict = {"add": {}, "remove": {}, "price_set": {}, "price_add": {},
|
||||||
"proto_add": {}, "free_set": {}, "agnes_free": {}}
|
"proto_add": {}, "free_set": {}, "agnes_free": {}, "ctx_set": {}}
|
||||||
for prov in SYNC_PROVIDERS:
|
for prov in SYNC_PROVIDERS:
|
||||||
plan["add"][prov] = {m["id"]: m for m in report[prov]["added"]}
|
plan["add"][prov] = {m["id"]: m for m in report[prov]["added"]}
|
||||||
plan["remove"][prov] = list(report[prov]["removed"])
|
plan["remove"][prov] = list(report[prov]["removed"])
|
||||||
@@ -597,6 +766,9 @@ def build_plan(report: dict, cfg: dict, oc_doc: dict, agnes_doc: dict) -> dict:
|
|||||||
plan["free_set"] = {d["id"]: d["doc_free"] for d in report["opencode"]["free_drift"]}
|
plan["free_set"] = {d["id"]: d["doc_free"] for d in report["opencode"]["free_drift"]}
|
||||||
# Agnes 的免费标注(True / "limited" / None)单独一条 plan,走 _set_agnes_free
|
# Agnes 的免费标注(True / "limited" / None)单独一条 plan,走 _set_agnes_free
|
||||||
plan["agnes_free"] = {d["id"]: d["doc"] for d in report["agnes"]["free_drift"]}
|
plan["agnes_free"] = {d["id"]: d["doc"] for d in report["agnes"]["free_drift"]}
|
||||||
|
# 第三十三轮: 上下文窗口 / 最大输出(models.dev + Agnes 文档)→ 块内改值
|
||||||
|
plan["ctx_set"] = {d["id"]: {"context": d["doc_ctx"], "output": d["doc_out"]}
|
||||||
|
for d in report["opencode"]["ctx_drift"] + report["agnes"]["ctx_drift"]}
|
||||||
for mid, meta in sorted(agnes_doc.items()):
|
for mid, meta in sorted(agnes_doc.items()):
|
||||||
if meta["input"] is None: # 图片/视频模型文档没给单价
|
if meta["input"] is None: # 图片/视频模型文档没给单价
|
||||||
continue
|
continue
|
||||||
@@ -621,7 +793,8 @@ def plan_is_empty(plan: dict) -> bool:
|
|||||||
if plan["add"].get(prov) or plan["remove"].get(prov):
|
if plan["add"].get(prov) or plan["remove"].get(prov):
|
||||||
return False
|
return False
|
||||||
return not any(plan.get(k) for k in
|
return not any(plan.get(k) for k in
|
||||||
("price_set", "price_add", "proto_add", "free_set", "agnes_free"))
|
("price_set", "price_add", "proto_add", "free_set", "agnes_free",
|
||||||
|
"ctx_set"))
|
||||||
|
|
||||||
|
|
||||||
def render_plan(plan: dict, date: str) -> str:
|
def render_plan(plan: dict, date: str) -> str:
|
||||||
@@ -638,6 +811,8 @@ def render_plan(plan: dict, date: str) -> str:
|
|||||||
_flabel = {True: "免费", "limited": "限时免费", None: "撤掉标注"}
|
_flabel = {True: "免费", "limited": "限时免费", None: "撤掉标注"}
|
||||||
for mid, want in sorted(plan.get("agnes_free", {}).items()):
|
for mid, want in sorted(plan.get("agnes_free", {}).items()):
|
||||||
lines.append(f" 免费标注 agnes/{mid} → {_flabel.get(want, want)}")
|
lines.append(f" 免费标注 agnes/{mid} → {_flabel.get(want, want)}")
|
||||||
|
for mid, spec in sorted(plan.get("ctx_set", {}).items()):
|
||||||
|
lines.append(f" 上下文 {mid} → {spec['context']:,} 输入 / {spec['output']:,} 输出")
|
||||||
for mid, spec in sorted(plan["price_set"].items()):
|
for mid, spec in sorted(plan["price_set"].items()):
|
||||||
lines.append(f" 改价 {mid} {spec['old']} → {spec['new']}")
|
lines.append(f" 改价 {mid} {spec['old']} → {spec['new']}")
|
||||||
for mid, want in sorted(plan["price_add"].items()):
|
for mid, want in sorted(plan["price_add"].items()):
|
||||||
@@ -704,6 +879,16 @@ def apply_plan(text: str, plan: dict, date: str) -> str:
|
|||||||
s, e = blocks[mid]
|
s, e = blocks[mid]
|
||||||
lines[s:e] = _set_agnes_free(lines[s:e], plan["agnes_free"][mid], date)
|
lines[s:e] = _set_agnes_free(lines[s:e], plan["agnes_free"][mid], date)
|
||||||
|
|
||||||
|
# 3c) 上下文窗口 / 最大输出(第三十三轮)——同一套倒序处理,字段插在块的 type: 之后。
|
||||||
|
if plan.get("ctx_set"):
|
||||||
|
for prov in SYNC_PROVIDERS:
|
||||||
|
blocks = _find_model_blocks(lines, prov)
|
||||||
|
mids = [m for m in plan["ctx_set"] if m in blocks]
|
||||||
|
for mid in sorted(mids, key=lambda m: blocks[m][0], reverse=True):
|
||||||
|
s, e = blocks[mid]
|
||||||
|
spec = plan["ctx_set"][mid]
|
||||||
|
lines[s:e] = _set_context(lines[s:e], spec["context"], spec["output"], date)
|
||||||
|
|
||||||
# 4) 定价:改价 / 补价 / 删掉被删模型的价
|
# 4) 定价:改价 / 补价 / 删掉被删模型的价
|
||||||
gone = {m for prov in SYNC_PROVIDERS for m in plan["remove"].get(prov) or []}
|
gone = {m for prov in SYNC_PROVIDERS for m in plan["remove"].get(prov) or []}
|
||||||
span = _pricing_span(lines)
|
span = _pricing_span(lines)
|
||||||
@@ -779,6 +964,18 @@ def verify(new_text: str, cfg_before: dict, plan: dict) -> list[str]:
|
|||||||
problems.append(f"免费标记 {mid} 没改成 {want}")
|
problems.append(f"免费标记 {mid} 没改成 {want}")
|
||||||
# Agnes 的免费标注:True(免费)/ "limited"(限时免费)/ None(该没有标注)
|
# Agnes 的免费标注:True(免费)/ "limited"(限时免费)/ None(该没有标注)
|
||||||
ag2 = {m["id"]: m for m in (cfg2.get("providers", {}).get("agnes") or {}).get("models", [])}
|
ag2 = {m["id"]: m for m in (cfg2.get("providers", {}).get("agnes") or {}).get("models", [])}
|
||||||
|
# 第三十三轮: 上下文窗口 / 最大输出真写进去了
|
||||||
|
for prov, table in (("opencode", oc2), ("agnes", ag2)):
|
||||||
|
for mid, spec in plan.get("ctx_set", {}).items():
|
||||||
|
m = table.get(mid)
|
||||||
|
if m is None:
|
||||||
|
continue # 该模型属于另一个 provider
|
||||||
|
got_ctx = int(m.get("context_window") or 0)
|
||||||
|
got_out = int(m.get("max_output_tokens") or 0)
|
||||||
|
if got_ctx != spec["context"] or got_out != spec["output"]:
|
||||||
|
problems.append(
|
||||||
|
f"上下文 {prov}/{mid} 没写成 {spec['context']}/{spec['output']}"
|
||||||
|
f"(实际 {got_ctx}/{got_out})")
|
||||||
for mid, want in plan.get("agnes_free", {}).items():
|
for mid, want in plan.get("agnes_free", {}).items():
|
||||||
got = _cfg_free_state(ag2.get(mid, {}))
|
got = _cfg_free_state(ag2.get(mid, {}))
|
||||||
if got != want:
|
if got != want:
|
||||||
@@ -874,7 +1071,11 @@ def main() -> int:
|
|||||||
_append_log(args.log, msg, 2)
|
_append_log(args.log, msg, 2)
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
report = diff(cfg, oc_doc, agnes_doc)
|
# 第三十三轮: 上下文来源(拉不到 = None/空 dict,只跳过上下文同步,不产生漂移)
|
||||||
|
md_dev = fetch_models_dev()
|
||||||
|
ag_ctx = fetch_agnes_context()
|
||||||
|
|
||||||
|
report = diff(cfg, oc_doc, agnes_doc, md_dev, ag_ctx)
|
||||||
plan = build_plan(report, cfg, oc_doc, agnes_doc)
|
plan = build_plan(report, cfg, oc_doc, agnes_doc)
|
||||||
drift = has_drift(report)
|
drift = has_drift(report)
|
||||||
code = 1 if drift else 0
|
code = 1 if drift else 0
|
||||||
|
|||||||
@@ -5099,6 +5099,110 @@ def test_sync_plan_is_empty_drills_into_provider_buckets():
|
|||||||
assert sm.plan_is_empty({**empty, "price_set": {"m": {"old": None, "new": None}}}) is False
|
assert sm.plan_is_empty({**empty, "price_set": {"m": {"old": None, "new": None}}}) is False
|
||||||
assert sm.plan_is_empty({**empty, "proto_add": {"m": "messages"}}) is False
|
assert sm.plan_is_empty({**empty, "proto_add": {"m": "messages"}}) is False
|
||||||
assert sm.plan_is_empty({**empty, "free_set": {"m": True}}) is False
|
assert sm.plan_is_empty({**empty, "free_set": {"m": True}}) is False
|
||||||
|
# 第三十三轮: ctx_set 也必须是真动作(否则上下文漂移不会被落盘)
|
||||||
|
assert sm.plan_is_empty({**empty, "ctx_set": {"m": {"context": 1, "output": 2}}}) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_sync_models_dev_context_merges_conservatively(monkeypatch=None):
|
||||||
|
"""models.dev 上下文合并:两供应商同名模型取**保守下限**(第三十三轮)。
|
||||||
|
|
||||||
|
背景:minimax-m3 在 opencode-go 是 1M、opencode(Zen) 是 512K;qwen3.6-plus
|
||||||
|
Go 1M / Zen 262144。同一模型跨源不一致时取小的那个 —— 宁可早压缩,不能超窗口。
|
||||||
|
"""
|
||||||
|
sys.path.insert(0, str(_ROOT / "scripts"))
|
||||||
|
import sync_models as sm
|
||||||
|
|
||||||
|
fake = json.dumps({
|
||||||
|
"opencode-go": {"models": {
|
||||||
|
"minimax-m3": {"limit": {"context": 1_000_000, "output": 131_072}},
|
||||||
|
"qwen3.6-plus": {"limit": {"context": 1_000_000, "output": 65_536}},
|
||||||
|
"only-in-go": {"limit": {"context": 500_000, "output": 128_000}},
|
||||||
|
}},
|
||||||
|
"opencode": {"models": {
|
||||||
|
"minimax-m3": {"limit": {"context": 512_000, "output": 128_000}},
|
||||||
|
"qwen3.6-plus": {"limit": {"context": 262_144, "output": 65_536}},
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
monkey_ok = lambda url, timeout=30: fake # noqa: E731
|
||||||
|
orig = sm._get
|
||||||
|
sm._get = monkey_ok
|
||||||
|
try:
|
||||||
|
got = sm.fetch_models_dev()
|
||||||
|
finally:
|
||||||
|
sm._get = orig
|
||||||
|
assert got is not None
|
||||||
|
assert got["minimax-m3"]["context"] == 512_000 # 保守下限
|
||||||
|
assert got["qwen3.6-plus"]["context"] == 262_144
|
||||||
|
assert got["only-in-go"]["context"] == 500_000 # 单源照样收
|
||||||
|
# 抓不到时必须返回 None(调用方据此跳过上下文同步,而不是当成"全部漂移")
|
||||||
|
sm._get = lambda url, timeout=60: (_ for _ in ()).throw(RuntimeError("boom"))
|
||||||
|
try:
|
||||||
|
assert sm.fetch_models_dev() is None
|
||||||
|
finally:
|
||||||
|
sm._get = orig
|
||||||
|
|
||||||
|
|
||||||
|
def test_sync_context_apply_is_idempotent_and_keeps_comments():
|
||||||
|
"""上下文写盘:插在 type: 之后、保住手写注释、重复执行不叠加(第三十三轮)。"""
|
||||||
|
sys.path.insert(0, str(_ROOT / "scripts"))
|
||||||
|
import sync_models as sm
|
||||||
|
|
||||||
|
text = (
|
||||||
|
'providers:\n'
|
||||||
|
' opencode:\n'
|
||||||
|
' name: "OpenCode Go"\n'
|
||||||
|
' models:\n'
|
||||||
|
' - id: "glm-5.3"\n'
|
||||||
|
' display_name: "GLM-5.3"\n'
|
||||||
|
' type: "text"\n'
|
||||||
|
' protocols: ["chat/completions"]\n'
|
||||||
|
)
|
||||||
|
seg = text.splitlines(keepends=True)[4:] # 从这个模型块起
|
||||||
|
once = sm._set_context(list(seg), 1_000_000, 131_072, "2026-09-24")
|
||||||
|
joined = "".join(once)
|
||||||
|
assert "context_window: 1000000" in joined
|
||||||
|
assert "max_output_tokens: 131072" in joined
|
||||||
|
# 插在 type: 之后、protocols 之前
|
||||||
|
assert joined.index("type:") < joined.index("context_window") < joined.index("protocols")
|
||||||
|
# 幂等:再跑一次值不变、不叠加第二组
|
||||||
|
twice = sm._set_context(list(once), 1_000_000, 131_072, "2026-09-24")
|
||||||
|
assert "".join(twice).count("context_window:") == 1
|
||||||
|
# 改值:旧值被替换、不新增行
|
||||||
|
changed = sm._set_context(list(once), 512_000, 128_000, "2026-09-25")
|
||||||
|
cj = "".join(changed)
|
||||||
|
assert cj.count("context_window:") == 1 and "context_window: 512000" in cj
|
||||||
|
assert cj.count("max_output_tokens:") == 1 and "max_output_tokens: 128000" in cj
|
||||||
|
|
||||||
|
|
||||||
|
def test_models_payload_exposes_context_window():
|
||||||
|
"""GET /models 与 /v1/models 必须带出 context_window / max_output_tokens。
|
||||||
|
|
||||||
|
第三十三轮(老板要求「接口加入上下文参数」):上下文窗口不只在 YAML 里,
|
||||||
|
客户端读接口时也得能看到,否则这个字段等于白加。
|
||||||
|
"""
|
||||||
|
import app.main as m
|
||||||
|
from app.config import ModelInfo, ProviderConfig, AuthConfig
|
||||||
|
|
||||||
|
cfg = m._cfg()
|
||||||
|
key = "__ctx_test__"
|
||||||
|
try:
|
||||||
|
cfg.providers[key] = ProviderConfig(
|
||||||
|
key=key, name="CTX", base_url="https://example.com/v1", auth=AuthConfig(),
|
||||||
|
models=[
|
||||||
|
ModelInfo(id="ctx-with", type="text",
|
||||||
|
context_window=1_000_000, max_output_tokens=131_072),
|
||||||
|
ModelInfo(id="ctx-without", type="image"), # 未标注 → 0
|
||||||
|
])
|
||||||
|
m._state.pop("_models_cache", None) # 绕开目录缓存
|
||||||
|
rows = {x["id"]: x for x in m._models_payload()["data"]}
|
||||||
|
assert rows["ctx-with"]["context_window"] == 1_000_000
|
||||||
|
assert rows["ctx-with"]["max_output_tokens"] == 131_072
|
||||||
|
# 未标注的模型不得瞎补数字(图片/视频模型天然没有上下文)
|
||||||
|
assert rows["ctx-without"]["context_window"] == 0
|
||||||
|
assert rows["ctx-without"]["max_output_tokens"] == 0
|
||||||
|
finally:
|
||||||
|
cfg.providers.pop(key, None)
|
||||||
|
m._state.pop("_models_cache", None)
|
||||||
|
|
||||||
|
|
||||||
def test_agnes_free_map_rules():
|
def test_agnes_free_map_rules():
|
||||||
|
|||||||
Reference in new issue
Block a user