diff --git a/CHANGELOG.md b/CHANGELOG.md index fed2ef4..aa4a5cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # CHANGELOG +## 2026-10-12 · 单独测速改并发(版本 2.7.1 → 2.7.2) + +老板:「单独测速能异步测速不,不用等到上一个回来后才能测速其他的」→ 按助手建议落地。 + +**改法**(纯前端): + +- **单独测速(每行常驻的 ⚡ 按钮)改为并发**:状态从「单个 `latCurrentId`」换成 + 「`latRunning`(正在测的 id 集合)」,每行自己的加载图标、自己的按钮状态, + 互不阻塞 —— 不用等上一个回来就能点下一个。并发上限 **`SPEEDTEST_MAX_CONCURRENCY = 3`** + (别让手一抖把全部免费档一次轰出去);到上限时按钮置灰,悬浮说明「同时最多测 3 个,等一个回来再点」。 +- **一键测速保持串行**:这是老板定的口味(测一个显示一个),且并发会把免费额度瞬间打满 → + 上游 429 会把结果刷成一片「失败」。整轮在跑时单测按钮禁用;有单测在飞时一键测速按钮禁用(互斥,避免同一模型两边同时覆盖结果)。 +- 抽了一个 `probeOne(id)` 共用「一次探针 = 一个模型」的取数与出错处理(整轮 / 单测同一份逻辑)。 +- i18n 新增 `models.testOneRunning` / `models.testOneBusy`(中英对称),`models.speedtestHint` + 补上「每行 ⚡ 单测可同时跑 {n} 个」。 + +**后端零改动**:`POST /v1/models/speedtest` 本来就是 async 端点(传 `model` 只测一个), +单 uvicorn 进程下并发请求天然并行,`server.rate_limit_rps=null` 也不拦 → 卡点纯在前端。 + +**注意(版本号窗口期)**:版本号已升 2.7.2,但本轮**纯前端、未重启后端** → +控制台「网关版本」仍显示 2.7.1,下次重启后一致。 + +**验收**:线上实测——同一时刻点 3 行 ⚡,3 行**同时**出加载图标、各自独立回结果; +第 4 行按钮置灰(悬浮提示上限);有单测在飞时一键测速按钮置灰;整轮测速行为与改前一致。 + + ## 2026-09-30 · 模型切换挪到对话框左下角 + 去掉所有 QwenPaw 外链与内部提示(版本 2.6.0 → 2.6.1) 老板三条要求: diff --git a/README.md b/README.md index 54db036..55ce44f 100644 --- a/README.md +++ b/README.md @@ -799,6 +799,7 @@ curl "http://localhost:8808/v1/videos/?model=agnes-video-2.5-flash&wai x 轴标签上。新增 `src/lib/charts.ts` 统一 `legend(top:0)` / 类目轴截断+倾斜+hideOverlap / `grid.containLabel` 留白,仪表盘与指标页 4 类图全部接入。 - **模型与供应商页**(`/web/#/models`):指标卡(模型/文本/图像/视频/供应商)+ 模型清单(ID/类型/供应商/视觉/延迟,一键测速按模型自己的协议线探测),数据来自 `/v1/models` + `/health`。(第二十七轮:路由别名表已随功能删除) + - **测速两种用法**(2026-10-12):**一键测速**=整轮**串行**(测一个显示一个,避免把免费档额度瞬间打满 → 上游 429);每行的 **⚡ 单独测速可并发**(各测各的、不用等上一个回来,上限 3 个;与整轮互斥)。后端同一个探针端点 `POST /v1/models/speedtest`,传 `model` 即只测那一个。 (降级链逐 tag 展示、供应商数)+ 模型清单(ID/类型/供应商/Key 已配),数据来自 `/v1/models` + `/health`。 - **多语言(M5+)**:Vue I18n + `src/locales/zh|en.ts`,全站中英可切换;语言按钮在头部与登录页、设置页 (`settings.language`),存 `localStorage.gw_locale`、默认中文;Element Plus 语言包经 diff --git a/app/config.py b/app/config.py index d38c272..7ad267b 100644 --- a/app/config.py +++ b/app/config.py @@ -134,7 +134,9 @@ class ModelInfo: # 2026-09-21: 是否**免费模型**(官方价格表标 Free、不按 token 计费)。 # 纯标注用途:/v1/models 带出 `free` 字段,前端「能力」列打「免费」标签; # 不参与路由/限流/熔断,也不影响成本估算(额度由上游控制,网关无法感知)。 - # 配置写法:`models[]` 里加 `free: true`(OpenCode Go 当前只有 space-bunny-free)。 + # 配置写法:`models[]` 里加 `free: true`(2026-10-12 现网 OpenCode Go 是 + # longcat-2.5-preview-free / step-5-preview-free 两个;原 space-bunny-free 已被官方 + # 改名 space-bunny 并转收费,同步据此撤掉了标记)。 free: bool = False # 2026-09-24(老板要求:Agnes 也要标免费 / 限时免费): 免费是否**带期限**。 # 语义:`free: true` + `free_limited: false` → 免费;`free_limited: true` → 限时免费。 diff --git a/app/main.py b/app/main.py index d55830c..efd1f94 100644 --- a/app/main.py +++ b/app/main.py @@ -340,7 +340,7 @@ _docs_on = config.server.docs_enabled # 安全默认关(report: /docs、/ope # 2026-09-30: 2.6.1 → 2.7.0(按老板要求整个删除「火山方舟 Coding Plan」供应商:配置/模型/代码/文档/前端下拉/环境变量全清)。 # 2026-09-30: 2.7.0 → 2.7.1(界面提示白话化:熔断器→供应商自动保护、引擎→运行环境、slug→标识;删 120 个未引用死键)。 # ★ 版本号纪律:每次改动都要往上加,小改动加小版本号、大改动加大版本号(README 有专章)。 -VERSION = "2.7.1" +VERSION = "2.7.2" app = FastAPI( title="API Gateway", diff --git a/data/gateway.yaml b/data/gateway.yaml index 27687e6..4857a80 100644 --- a/data/gateway.yaml +++ b/data/gateway.yaml @@ -209,18 +209,6 @@ providers: context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护 max_output_tokens: 131072 # 最大输出(token) protocols: ["chat/completions"] - - id: "space-bunny-free" - display_name: "Space Bunny Free(免费)" - type: "text" - context_window: 1048576 # 第三十三轮(2026-09-24):上下文窗口(token),每日同步维护 - max_output_tokens: 524288 # 最大输出(token) - free: true # 前端「能力」列据此打「免费」标签;/v1/models 也会带出 free 字段 - # ★ 免费模型:官方文档价格表 Free / Free / Free,额度 Unlimited(限时)。 - # 接替已下线的 union-alpha(Union Alpha Free)。 - # 实测 chat 200、messages 200、responses 503 → 标两条线。 - # (models.dev 里另有个 ox-alpha-free 也是 cost 0,但上游 /models 与官方文档 - # 都没有它,故不收录。) - protocols: ["chat/completions", "messages"] # ── Chat + Messages 两条线都实测可用 ───────────────── - id: "kimi-k3" display_name: "Kimi K3" @@ -344,6 +332,31 @@ providers: # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) protocols: ["chat/completions"] free: true # 官方价格表标 Free + # 2026-10-07 自动同步:官方文档新增(scripts/sync_models.py) + - id: "space-bunny" + display_name: "Space Bunny" + type: "text" + context_window: 1048576 # 同步 2026-10-08(scripts/sync_models.py) + max_output_tokens: 524288 # 同步 2026-10-08(scripts/sync_models.py) + # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) + protocols: ["chat/completions"] + # 2026-10-08 自动同步:官方文档新增(scripts/sync_models.py) + - id: "claude-haiku-5-5" + display_name: "Claude Haiku 5 5" + type: "text" + context_window: 1000000 # 同步 2026-10-09(scripts/sync_models.py) + max_output_tokens: 128000 # 同步 2026-10-09(scripts/sync_models.py) + # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) + protocols: ["messages"] + # 2026-10-09 自动同步:官方文档新增(scripts/sync_models.py) + - id: "step-5-preview-free" + display_name: "Step 5 Preview Free" + type: "text" + context_window: 1000000 # 同步 2026-10-10(scripts/sync_models.py) + max_output_tokens: 65536 # 同步 2026-10-10(scripts/sync_models.py) + # 协议线取自官方 Endpoints 表,未逐线实测(现网其它模型是实测过的) + protocols: ["chat/completions"] + free: true # 官方价格表标 Free # ── Dots AI(小红书 Dots Studio,第三十六轮新增)────────────── # 官方文档:https://dots.ai/platform/docs(2026-09-28 通读) # · 基础地址 https://note3-prev-api.askdiandian.com,两条线: diff --git a/frontend/src/locales/en.ts b/frontend/src/locales/en.ts index 0577e8a..25954bd 100644 --- a/frontend/src/locales/en.ts +++ b/frontend/src/locales/en.ts @@ -513,11 +513,13 @@ export default { testing: 'Probing latency of every text model…', testingShort: 'Testing…', testOne: 'Test this model', + testOneRunning: 'Testing this model…', + testOneBusy: 'Up to {n} at a time — wait for one to finish', latency: 'Latency', failed: 'Failed', speedtestDone: 'Speed test done, {n} models', speedtestFail: 'Speed test failed', - speedtestHint: 'Latency probed per format', + speedtestHint: 'Latency probed per format; per-row ⚡ tests run {n} at a time', textModelCount: '{n} text models', // Round 27: the supported-formats column (three protocol lines). Line names are the // vendors' own endpoint names, so they are not translated. diff --git a/frontend/src/locales/zh.ts b/frontend/src/locales/zh.ts index 4498895..fc6bd84 100644 --- a/frontend/src/locales/zh.ts +++ b/frontend/src/locales/zh.ts @@ -518,11 +518,13 @@ export default { testing: '正在测试全部文本模型延迟…', testingShort: '测速中…', testOne: '单独测速', + testOneRunning: '正在测这一个…', + testOneBusy: '同时最多测 {n} 个,等一个回来再点', latency: '延迟', failed: '失败', speedtestDone: '测速完成,共 {n} 个模型', speedtestFail: '测速失败', - speedtestHint: '按模型自己的格式探测延迟', + speedtestHint: '按模型自己的格式探测延迟;每行 ⚡ 单测可同时跑 {n} 个', textModelCount: '{n} 个文本模型', // 第二十七轮:支持的格式列(三条协议线)。格式名直接用各家标准端点名,不译。 protocols: '支持的格式', diff --git a/frontend/src/views/Models.vue b/frontend/src/views/Models.vue index de03374..169f6e0 100644 --- a/frontend/src/views/Models.vue +++ b/frontend/src/views/Models.vue @@ -15,9 +15,12 @@
{{ t('models.allTextModels') }} - {{ t('models.speedtestHint') }} + {{ t('models.speedtestHint', { n: SPEEDTEST_MAX_CONCURRENCY }) }} - + + {{ latTesting ? t('models.testingShort') : t('models.speedtest') }}
@@ -43,11 +46,13 @@ {{ m.provider }} - + + {{ latText(m.id) }} -
@@ -228,13 +233,39 @@ function protocolsOf(row: any): string[] { // 每个格式标签的悬浮说明:这条线对应哪个端点(点进说明文档也是这个对应关系) function protoTitle(p: string): string { return `POST /v1/${p}` } +// ── 测速(2026-10-12:单独测速改为并发)────────────────────────── +// 两套状态分开记: +// · 一键测速(runSpeedtest):整轮**串行**——latTesting = 整轮在跑、latCurrentId = 整轮当前那一行。 +// 串行是老板定的口味(测一个显示一个),且并发会把免费额度瞬间打满 → 上游 429, +// 结果会刷成一片「失败」,反而失去参考价值。 +// · 单独测速(retestOne):**可并发**——每行独立(latRunning 记着正在测的 id), +// 不用等上一个回来才能点下一个。上限 SPEEDTEST_MAX_CONCURRENCY 是别让手一抖 +// 把全部免费档一次轰出去(免费档 429 同样会把结果刷成失败)。 +const SPEEDTEST_MAX_CONCURRENCY = 3 const latTesting = ref(false) -const latCurrentId = ref('') // 当前正在测的模型 id:该行延迟位显示加载图标 +const latCurrentId = ref('') // 整轮测速当前测到的模型 id:该行延迟位显示加载图标 +const latRunning = ref>({}) // 正在单独测的模型 id(可同时多个) +const latRunningCount = computed(() => Object.keys(latRunning.value).length) // protocol 由后端返回:探针**按模型自己的协议线**挑一条(优先级 chat → messages → responses), // 记下来才能在悬浮提示里说清「这次多少毫秒是走哪条线测的」——多线模型不写清楚会让人误解。 const latByModel = ref>({}) + +// 探一次 = 一个模型一次请求;出错不抛,统一回一行结果(整轮 / 单测共用) +async function probeOne(id: string) { + try { + const j = await api('/v1/models/speedtest', { method: 'POST', body: JSON.stringify({ model: id }) }) + const r: any[] = (j && j.results) || [] + const hit = r[0] + return hit + ? { ok: !!hit.ok, latency_ms: hit.latency_ms ?? null, error: hit.error || '', protocol: hit.protocol || '' } + : { ok: false, latency_ms: null, error: t('models.speedtestFail'), protocol: '' } + } catch (e: any) { + return { ok: false, latency_ms: null, error: (e && e.message) || String(e), protocol: '' } + } +} + async function runSpeedtest() { - if (latTesting.value) return + if (latTesting.value || latRunningCount.value) return // 整轮在跑 / 有单测在飞 → 不开整轮 // 逐个测速:按列表顺序,测一个立刻显示那一行、再测下一个;当前测的行显示加载图标。 // 串行天然不会把免费额度瞬间打满(并发时免费档供应商容易 429)。 const ids = textModelRows.value.map((m) => m.id) @@ -242,41 +273,39 @@ async function runSpeedtest() { latTesting.value = true for (const id of ids) { latCurrentId.value = id - let row: { ok: boolean; latency_ms: number | null; error: string; protocol: string } - try { - const j = await api('/v1/models/speedtest', { method: 'POST', body: JSON.stringify({ model: id }) }) - const r: any[] = (j && j.results) || [] - const hit = r[0] - row = hit - ? { ok: !!hit.ok, latency_ms: hit.latency_ms ?? null, error: hit.error || '', protocol: hit.protocol || '' } - : { ok: false, latency_ms: null, error: t('models.speedtestFail'), protocol: '' } - } catch (e: any) { - // 单个模型出错不中断整轮,标记失败后继续下一个 - row = { ok: false, latency_ms: null, error: (e && e.message) || String(e), protocol: '' } - } + const row = await probeOne(id) // 单个模型出错不中断整轮,标记失败后继续下一个 latByModel.value = { ...latByModel.value, [id]: row } // 响应式替换 → 该行即时更新 } latCurrentId.value = '' latTesting.value = false ElMessage.success(t('models.speedtestDone', { n: ids.length })) } -// 单个模型重新测速(失败行旁的「重新测速」按钮):只重测这一个,复用当前行加载图标 + +// 单个模型测速(每行常驻的 ⚡ 按钮):只测这一个;**并发** —— 各测各的,不等别人回来 async function retestOne(id: string) { - if (latTesting.value || latCurrentId.value) return // 整轮测速中 / 已有单测在跑 → 忽略,避免打架 - latCurrentId.value = id - try { - const j = await api('/v1/models/speedtest', { method: 'POST', body: JSON.stringify({ model: id }) }) - const r: any[] = (j && j.results) || [] - const hit = r[0] - const row = hit - ? { ok: !!hit.ok, latency_ms: hit.latency_ms ?? null, error: hit.error || '', protocol: hit.protocol || '' } - : { ok: false, latency_ms: null, error: t('models.speedtestFail'), protocol: '' } - latByModel.value = { ...latByModel.value, [id]: row } - } catch (e: any) { - latByModel.value = { ...latByModel.value, [id]: { ok: false, latency_ms: null, error: (e && e.message) || String(e), protocol: '' } } - } finally { - latCurrentId.value = '' + if (latTesting.value || latRunning.value[id]) return // 整轮测速中 / 这一个已经在测 → 忽略 + if (latRunningCount.value >= SPEEDTEST_MAX_CONCURRENCY) { + ElMessage.warning(t('models.testOneBusy', { n: SPEEDTEST_MAX_CONCURRENCY })) + return } + latRunning.value = { ...latRunning.value, [id]: true } + try { + const row = await probeOne(id) + latByModel.value = { ...latByModel.value, [id]: row } + } finally { + const next = { ...latRunning.value } + delete next[id] + latRunning.value = next + } +} + +// 单测按钮的悬浮说明:说清现在为什么点不了(正在测这一个 / 并发已满) +function testOneHint(m: { id: string }): string { + if (latRunning.value[m.id]) return t('models.testOneRunning') + if (latRunningCount.value >= SPEEDTEST_MAX_CONCURRENCY) { + return t('models.testOneBusy', { n: SPEEDTEST_MAX_CONCURRENCY }) + } + return t('models.testOne') } function latText(id: string): string { const row = latByModel.value[id] diff --git a/tests/test_gateway.py b/tests/test_gateway.py index 3f5582c..35a5163 100644 --- a/tests/test_gateway.py +++ b/tests/test_gateway.py @@ -1711,7 +1711,10 @@ def test_models_payload_marks_free_models(): client = TestClient(m.app) data = client.get("/v1/models").json()["data"] free_ids = [x["id"] for x in data if x.get("free")] - assert "space-bunny-free" in free_ids, f"免费模型没标出来:{free_ids}" + # 2026-10-12:样本从 space-bunny-free 换成 longcat-2.5-preview-free —— 前者已于 + # 2026-10-07 被官方改名成 space-bunny 并转收费(价格表 $0.15/$0.60), + # 每日同步据此去掉了它的 free 标记(现网免费位=longcat-2.5-preview-free / step-5-preview-free)。 + assert "longcat-2.5-preview-free" in free_ids, f"免费模型没标出来:{free_ids}" # 反向:付费模型必须是 free=false(不能因为字段缺失而误标) paid = next(x for x in data if x["id"] == "deepseek-v4.1-flash") assert paid["free"] is False, paid