magpie-model-speedtest 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Magpie 模型测速
2
2
 
3
- 在 Magpie 的「模型测速」页面点「开始测速」,逐个测量当前网关启用的文本模型。每轮都要求抄写同一段英文,最多请求 256 个输出 token。测速会消耗模型额度。
3
+ 在 Magpie 的「模型测速」页面点「开始测速」,逐个测量当前网关启用的文本模型。每轮都要求抄写同一段英文,最多请求 256 个输出 token。全新 Impeccable 界面设计,同时呈现**端到端速度**与**正文流速**,支持搜索过滤、动态排序与一键导出。测速会消耗模型额度。
4
4
 
5
5
  ```sh
6
6
  magpie plugin add magpie-model-speedtest
@@ -8,9 +8,12 @@ magpie plugin add magpie-model-speedtest
8
8
 
9
9
  本地开发可用 `magpie plugin add ./magpie-model-speedtest`。页面服务默认监听 `127.0.0.1:3487`,可在插件选项中修改 `port`。网关端口从 Magpie 的 `gateway.json` 读取,插件用调用方标识 `magpie-model-speedtest` 访问本机网关。无需另外配置供应商密钥。
10
10
 
11
- - 默认每个实体模型测一次,按正文 token/s 排序。路由组可单独勾选,命中模型以网关报告为准。
11
+ - **端到端速度 (E2E Throughput)**:综合网络建连、排队、Prompt 预填充、内部思考(Reasoning)与正文输出的全局总耗时计算的 token/s,直观反映发出请求到完整拿到结果的真实体验。
12
+ - **正文流速 (Streaming Speed)**:排除首字等待与思考延迟,仅统计首个可见字符到达至最后一个字符到达之间的打字机喷发流速。
13
+ - **首字延迟 (TTFT)**:从发出请求到收到第一段可见正文的等待时间,支持智能色阶标注。
14
+ - 默认每个实体模型测一次,按端到端速度排序(点击表头可自由切换任意列排序)。路由组可单独勾选,命中模型以网关报告为准。
12
15
  - 下拉选择一个模型或组可测三轮,三个有效速度样本齐全后显示中位数。
13
- - 首字延迟包含排队和推理,计时到收到第一段可见正文。正文速度按首末两次正文到达之间的时间计算,排除首批正文。网关或供应商缓冲会影响读数。
14
- - 供应商同时报告输出和推理用量时,以两者之差作为正文 token 数。首批 token 按其在正文中的字节比例折算,因此速度标 `≈`。缺少推理明细时,按英文正文平均 4 个 UTF-8 字节估算一个 token。用量统计可能含协议开销。
15
- - 正文集中在 10 毫秒以内到达或整段返回时,显示延迟与总耗时,速度留空。只有推理、流中断、HTTP 错误和单请求超过 60 秒都会逐行标明,队列继续。支持时使用模型公开的最低推理档位。
16
+ - 支持按模型名称或供应商实时搜索过滤,支持一键复制标准 Markdown 表格或导出完整 JSON。
17
+ - 供应商同时报告输出和推理用量时,以两者之差作为正文 token 数。缺少推理明细时,按英文正文平均 4 个 UTF-8 字节估算一个 token。
18
+ - 正文集中在 10 毫秒以内到达或整段返回时,端到端速度正常计算,正文流速留空。只有推理、流中断、HTTP 错误和单请求超过 60 秒都会逐行标明,队列继续。支持时使用模型公开的最低推理档位。
16
19
  - 停止会取消当前请求和后续队列。已完成的结果在本次服务进程内保留到下次测速。
package/app/app.js CHANGED
@@ -1,50 +1,322 @@
1
1
  const byId = id => document.getElementById(id)
2
2
  const token = document.querySelector('meta[name="session"]').content
3
- const target = byId("target"), groups = byId("groups")
4
- let models = [], busy = false, pending = false
3
+ const target = byId("target"), groups = byId("groups"), filterInput = byId("filter")
4
+ const startBtn = byId("start"), stopBtn = byId("stop")
5
+
6
+ let models = []
7
+ let busy = false
8
+ let pending = false
9
+ let latestState = { rows: [], count: 0, completed: 0, running: false }
10
+ let sortColumn = "e2eSpeed"
11
+ let sortAscending = false
12
+
5
13
  async function api(path, params = {}) {
6
- const response = await fetch(path, { method: "POST", body: JSON.stringify({ ...params, token }), signal: AbortSignal.timeout(15000) })
14
+ const response = await fetch(path, {
15
+ method: "POST",
16
+ headers: { "Content-Type": "application/json" },
17
+ body: JSON.stringify({ ...params, token }),
18
+ signal: AbortSignal.timeout(15000)
19
+ })
7
20
  const data = await response.json()
8
21
  if (response.status === 403 && data.reload) location.reload()
9
22
  if (!response.ok) throw new Error(data.error || `服务返回 HTTP ${response.status},请刷新页面`)
10
23
  return data
11
24
  }
12
- function controls() {
13
- const count = target.value ? 3 : models.filter(model => groups.checked || !model.group).length
14
- byId("start").disabled = pending || busy || !count
15
- byId("stop").hidden = !busy
25
+
26
+ function showToast(message) {
27
+ const toast = byId("toast")
28
+ toast.textContent = message
29
+ toast.classList.add("show")
30
+ setTimeout(() => toast.classList.remove("show"), 2200)
31
+ }
32
+
33
+ function updateControls() {
34
+ const count = target.value ? 3 : models.filter(m => groups.checked || !m.group).length
35
+ startBtn.disabled = pending || busy || !count
36
+ stopBtn.hidden = !busy
16
37
  target.disabled = busy || pending
17
38
  groups.disabled = !!target.value || busy || pending
18
- byId("plan").textContent = `预计 ${count} 次请求 · 串行执行 · 每次最多 256 输出 token`
39
+ byId("plan-text").textContent = `预计 ${count} 次请求 · 串行测试 · 每次上限 256 输出 token`
40
+ }
41
+
42
+ function formatMs(ms) {
43
+ if (ms == null) return "—"
44
+ if (ms < 1000) return `${Math.round(ms)} ms`
45
+ return `${(ms / 1000).toFixed(2)} s`
46
+ }
47
+
48
+ function parseProvider(id) {
49
+ const parts = id.split("/")
50
+ if (parts.length > 1) {
51
+ const p = parts[0].toLowerCase()
52
+ if (p === "group") return { tag: "group", label: "路由组", name: parts.slice(1).join("/") }
53
+ if (p.includes("grok")) return { tag: "grok", label: "Grok", name: parts.slice(1).join("/") }
54
+ if (p.includes("deepseek")) return { tag: "deepseek", label: "DeepSeek", name: parts.slice(1).join("/") }
55
+ if (p.includes("google")) return { tag: "google", label: "Google", name: parts.slice(1).join("/") }
56
+ if (p.includes("codex")) return { tag: "codex", label: "Codex", name: parts.slice(1).join("/") }
57
+ return { tag: "provider", label: parts[0], name: parts.slice(1).join("/") }
58
+ }
59
+ return { tag: "model", label: "模型", name: id }
60
+ }
61
+
62
+ function computeE2eSpeed(row) {
63
+ if (row.e2eSpeed != null) return row.e2eSpeed
64
+ if (row.total > 0 && row.tokens > 0) return (row.tokens * 1000) / row.total
65
+ return null
66
+ }
67
+
68
+ function updateKpis(rows, state) {
69
+ byId("kpi-count").textContent = state.count ? `${state.completed} / ${state.count}` : (models.length ? `${models.length} 款` : "—")
70
+ byId("kpi-count-sub").textContent = busy ? `正在测试: ${state.current || "准备中"}` : (state.completed ? (state.stopped ? "测试已停止" : "全部测试完成") : "就绪")
71
+
72
+ const validE2e = rows.filter(r => computeE2eSpeed(r) != null).sort((a, b) => computeE2eSpeed(b) - computeE2eSpeed(a))
73
+ const validStream = rows.filter(r => r.speed != null).sort((a, b) => b.speed - a.speed)
74
+ const validTtft = rows.filter(r => r.ttft != null).sort((a, b) => a.ttft - b.ttft)
75
+
76
+ if (validE2e.length) {
77
+ const top = validE2e[0]
78
+ byId("kpi-top-e2e").textContent = `${computeE2eSpeed(top).toFixed(1)} tok/s`
79
+ byId("kpi-top-e2e-name").textContent = top.id
80
+ } else {
81
+ byId("kpi-top-e2e").textContent = "—"
82
+ byId("kpi-top-e2e-name").textContent = "等待测速数据"
83
+ }
84
+
85
+ if (validStream.length) {
86
+ const top = validStream[0]
87
+ byId("kpi-top-stream").textContent = `${top.speed.toFixed(1)} tok/s`
88
+ byId("kpi-top-stream-name").textContent = top.id
89
+ } else {
90
+ byId("kpi-top-stream").textContent = "—"
91
+ byId("kpi-top-stream-name").textContent = "等待测速数据"
92
+ }
93
+
94
+ if (validTtft.length) {
95
+ const best = validTtft[0]
96
+ byId("kpi-best-ttft").textContent = formatMs(best.ttft)
97
+ byId("kpi-best-ttft-name").textContent = best.id
98
+ } else {
99
+ byId("kpi-best-ttft").textContent = "—"
100
+ byId("kpi-best-ttft-name").textContent = "等待测速数据"
101
+ }
19
102
  }
20
- function seconds(ms) { return ms == null ? "—" : `${(ms / 1000).toFixed(2)} s` }
103
+
104
+ function renderTable() {
105
+ const rows = [...latestState.rows]
106
+ const filter = (filterInput.value || "").trim().toLowerCase()
107
+ const filtered = filter ? rows.filter(r => r.id.toLowerCase().includes(filter) || (r.actual && r.actual.toLowerCase().includes(filter))) : rows
108
+
109
+ // Sort
110
+ filtered.sort((a, b) => {
111
+ let valA, valB
112
+ switch (sortColumn) {
113
+ case "id":
114
+ valA = a.id; valB = b.id
115
+ return sortAscending ? valA.localeCompare(valB) : valB.localeCompare(valA)
116
+ case "e2eSpeed":
117
+ valA = computeE2eSpeed(a) ?? -1
118
+ valB = computeE2eSpeed(b) ?? -1
119
+ break
120
+ case "speed":
121
+ valA = a.speed ?? -1
122
+ valB = b.speed ?? -1
123
+ break
124
+ case "ttft":
125
+ valA = a.ttft ?? 999999
126
+ valB = b.ttft ?? 999999
127
+ break
128
+ case "tokens":
129
+ valA = a.tokens ?? -1
130
+ valB = b.tokens ?? -1
131
+ break
132
+ case "total":
133
+ valA = a.total ?? 999999
134
+ valB = b.total ?? 999999
135
+ break
136
+ default:
137
+ valA = computeE2eSpeed(a) ?? -1
138
+ valB = computeE2eSpeed(b) ?? -1
139
+ }
140
+ return sortAscending ? valA - valB : valB - valA
141
+ })
142
+
143
+ const maxE2e = Math.max(...rows.map(r => computeE2eSpeed(r) || 0), 1)
144
+ const maxStream = Math.max(...rows.map(r => r.speed || 0), 1)
145
+
146
+ const tbody = byId("table-body")
147
+ tbody.replaceChildren()
148
+
149
+ if (!filtered.length) {
150
+ const tr = tbody.insertRow()
151
+ const td = tr.insertCell()
152
+ td.colSpan = 7
153
+ td.style.textAlign = "center"
154
+ td.style.padding = "36px"
155
+ td.style.color = "var(--text-muted)"
156
+ td.textContent = rows.length ? "未匹配到符合过滤条件的模型" : "暂无测试结果,点击上方「开始测速」运行基准。"
157
+ return
158
+ }
159
+
160
+ for (const row of filtered) {
161
+ const tr = tbody.insertRow()
162
+ tr.className = "model-row"
163
+ if (busy && latestState.current === row.id) tr.classList.add("active-measuring")
164
+
165
+ // Col 1: Model & Provider
166
+ const tdModel = tr.insertCell()
167
+ const parsed = parseProvider(row.id)
168
+ const modelCell = document.createElement("div")
169
+ modelCell.className = "model-cell"
170
+
171
+ const tag = document.createElement("span")
172
+ tag.className = `provider-tag ${parsed.tag}`
173
+ tag.textContent = parsed.label
174
+
175
+ const nameWrap = document.createElement("div")
176
+ const name = document.createElement("span")
177
+ name.className = "model-name"
178
+ name.textContent = parsed.name
179
+ nameWrap.appendChild(name)
180
+
181
+ const metas = []
182
+ if (row.round > 1) metas.push(`第 ${row.round} 轮`)
183
+ if (row.actual && row.actual !== row.id) metas.push(`↳ 命中: ${row.actual}`)
184
+ if (metas.length) {
185
+ const meta = document.createElement("span")
186
+ meta.className = "model-meta"
187
+ meta.textContent = metas.join(" · ")
188
+ nameWrap.appendChild(meta)
189
+ }
190
+
191
+ modelCell.append(tag, nameWrap)
192
+ tdModel.appendChild(modelCell)
193
+
194
+ // Col 2: End-to-End Speed
195
+ const tdE2e = tr.insertCell()
196
+ tdE2e.className = "num"
197
+ const e2e = computeE2eSpeed(row)
198
+ if (e2e != null) {
199
+ const speedWrap = document.createElement("div")
200
+ speedWrap.className = "speed-cell"
201
+ const num = document.createElement("span")
202
+ num.className = "speed-num"
203
+ num.style.color = "var(--brand-purple)"
204
+ num.textContent = `${e2e.toFixed(1)} tok/s`
205
+ const track = document.createElement("div")
206
+ track.className = "speed-track"
207
+ const fill = document.createElement("div")
208
+ fill.className = "speed-fill-e2e"
209
+ fill.style.width = `${Math.min(100, Math.round((e2e / maxE2e) * 100))}%`
210
+ track.appendChild(fill)
211
+ speedWrap.append(num, track)
212
+ tdE2e.appendChild(speedWrap)
213
+ } else {
214
+ tdE2e.textContent = "—"
215
+ tdE2e.style.color = "var(--text-muted)"
216
+ }
217
+
218
+ // Col 3: Streaming Speed
219
+ const tdStream = tr.insertCell()
220
+ tdStream.className = "num"
221
+ if (row.speed != null) {
222
+ const speedWrap = document.createElement("div")
223
+ speedWrap.className = "speed-cell"
224
+ const num = document.createElement("span")
225
+ num.className = "speed-num"
226
+ num.style.color = "var(--brand-teal)"
227
+ num.textContent = `${row.speed.toFixed(1)} tok/s`
228
+ const track = document.createElement("div")
229
+ track.className = "speed-track"
230
+ const fill = document.createElement("div")
231
+ fill.className = "speed-fill-stream"
232
+ fill.style.width = `${Math.min(100, Math.round((row.speed / maxStream) * 100))}%`
233
+ track.appendChild(fill)
234
+ speedWrap.append(num, track)
235
+ tdStream.appendChild(speedWrap)
236
+ } else {
237
+ tdStream.textContent = "—"
238
+ tdStream.style.color = "var(--text-muted)"
239
+ }
240
+
241
+ // Col 4: TTFT
242
+ const tdTtft = tr.insertCell()
243
+ tdTtft.className = "num"
244
+ if (row.ttft != null) {
245
+ const span = document.createElement("span")
246
+ span.className = row.ttft < 1000 ? "ttft-fast" : (row.ttft < 2500 ? "ttft-med" : "ttft-slow")
247
+ span.textContent = formatMs(row.ttft)
248
+ tdTtft.appendChild(span)
249
+ } else {
250
+ tdTtft.textContent = "—"
251
+ }
252
+
253
+ // Col 5: Tokens
254
+ const tdTokens = tr.insertCell()
255
+ tdTokens.className = "num"
256
+ tdTokens.style.fontFamily = "var(--font-mono)"
257
+ if (row.tokens != null) {
258
+ tdTokens.textContent = `${row.exact ? "" : "≈ "}${row.tokens}`
259
+ } else {
260
+ tdTokens.textContent = "—"
261
+ }
262
+
263
+ // Col 6: Total Time
264
+ const tdTotal = tr.insertCell()
265
+ tdTotal.className = "num"
266
+ tdTotal.style.fontFamily = "var(--font-mono)"
267
+ tdTotal.textContent = formatMs(row.total)
268
+
269
+ // Col 7: Status / Note
270
+ const tdStatus = tr.insertCell()
271
+ const badge = document.createElement("span")
272
+ if (row.error) {
273
+ badge.className = "status-badge badge-error"
274
+ badge.textContent = `⚠ ${row.error}`
275
+ } else if (row.speed != null) {
276
+ badge.className = "status-badge badge-ok"
277
+ badge.textContent = "✓ 成功"
278
+ } else {
279
+ badge.className = "status-badge badge-warn"
280
+ badge.textContent = row.note || "整段返回"
281
+ }
282
+ tdStatus.appendChild(badge)
283
+ }
284
+
285
+ // Median summary for 3-round single model test
286
+ const samples = rows.filter(r => r.speed != null)
287
+ const isSingleModelRounds = !busy && samples.length === 3 && new Set(samples.map(r => r.id)).size === 1
288
+ if (isSingleModelRounds) {
289
+ const sortedE2e = [...samples].map(r => computeE2eSpeed(r)).sort((a, b) => a - b)
290
+ const sortedStream = [...samples].map(r => r.speed).sort((a, b) => a - b)
291
+ const sortedTtft = [...samples].map(r => r.ttft).sort((a, b) => a - b)
292
+ byId("median-summary").textContent = `三轮中位数:端到端 ≈ ${sortedE2e[1].toFixed(1)} tok/s · 正文流速 ≈ ${sortedStream[1].toFixed(1)} tok/s · 首字 ≈ ${formatMs(sortedTtft[1])}`
293
+ } else {
294
+ byId("median-summary").textContent = ""
295
+ }
296
+ }
297
+
21
298
  function draw(state) {
299
+ latestState = state
22
300
  busy = state.running
23
- controls()
24
- byId("status").textContent = busy ? `${state.completed} / ${state.count} · 正在测 ${state.current}` :
25
- state.count ? `${state.stopped ? "已停止" : "已完成"} · ${state.completed} / ${state.count}` : "就绪"
26
- byId("progress").hidden = !state.count
27
- byId("progress").max = state.count || 1
28
- byId("progress").value = state.completed
29
- const rows = [...state.rows].sort((left, right) => (right.speed ?? -1) - (left.speed ?? -1))
30
- const body = document.querySelector("tbody")
31
- body.replaceChildren()
32
- for (const row of rows) {
33
- const tr = body.insertRow()
34
- const label = tr.insertCell()
35
- label.textContent = row.id
36
- if (row.id.startsWith("group/") || row.round > 1 || row.actual && row.actual !== row.id) {
37
- const detail = document.createElement("small")
38
- detail.textContent = `第 ${row.round} 轮` + (row.actual && row.actual !== row.id ? ` · ${row.actual}` : row.id.startsWith("group/") ? " · 未报告实际模型" : "")
39
- label.append(detail)
40
- }
41
- for (const value of [row.speed == null ? "—" : `≈${row.speed.toFixed(1)}`, seconds(row.ttft),
42
- row.tokens == null ? "—" : `${row.exact ? "" : "≈"}${row.tokens}`, seconds(row.total), row.error || row.note]) tr.insertCell().textContent = value
301
+ updateControls()
302
+
303
+ const progressContainer = byId("progress-container")
304
+ if (busy || state.count > 0) {
305
+ progressContainer.hidden = false
306
+ byId("status").textContent = busy ? `[${state.completed} / ${state.count}] 正在测 ${state.current || "..."}` : (state.stopped ? "测试已停止" : "测速已完成")
307
+ const pct = state.count ? Math.round((state.completed / state.count) * 100) : 0
308
+ byId("progress-bar").style.width = `${pct}%`
309
+ } else {
310
+ progressContainer.hidden = true
43
311
  }
44
- const samples = rows.filter(row => row.speed != null)
45
- byId("summary").textContent = !busy && samples.length === 3 && new Set(samples.map(row => row.id)).size === 1 ?
46
- `三轮正文速度中位数 ≈${samples[1].speed.toFixed(1)} token/s` : ""
312
+
313
+ byId("target-summary").textContent = busy ? "测速中" : (state.completed ? "已完成" : "就绪")
314
+ byId("table-summary-info").textContent = `已采集 ${state.rows.length} 条测试记录 · 点击表头可切换排序`
315
+
316
+ updateKpis(state.rows, state)
317
+ renderTable()
47
318
  }
319
+
48
320
  async function loadModels() {
49
321
  models = await api("models")
50
322
  const previous = target.value
@@ -52,29 +324,109 @@ async function loadModels() {
52
324
  for (const group of [false, true]) {
53
325
  const section = document.createElement("optgroup")
54
326
  section.label = group ? "路由组 · 单项复测 3 轮" : "单模型复测 · 3 轮"
55
- for (const model of models.filter(item => item.group === group)) section.append(new Option(model.id, model.id))
327
+ for (const model of models.filter(item => item.group === group)) {
328
+ section.append(new Option(model.id, model.id))
329
+ }
56
330
  target.append(section)
57
331
  }
58
332
  target.value = previous
333
+ updateControls()
334
+ }
335
+
336
+ function copyMarkdown() {
337
+ const rows = [...latestState.rows]
338
+ if (!rows.length) {
339
+ showToast("当前暂无数据可复制")
340
+ return
341
+ }
342
+ let md = "| 模型 / 供应商 | 端到端速度 | 正文流速 | 首字延迟 | 正文 Tokens | 总耗时 | 状态 |\n"
343
+ md += "|---|---:|---:|---:|---:|---:|---|\n"
344
+ for (const r of rows) {
345
+ const e2e = computeE2eSpeed(r)
346
+ const e2eStr = e2e != null ? `${e2e.toFixed(1)} tok/s` : "—"
347
+ const streamStr = r.speed != null ? `${r.speed.toFixed(1)} tok/s` : "—"
348
+ const ttftStr = formatMs(r.ttft)
349
+ const tokStr = r.tokens != null ? `${r.exact ? "" : "≈"}${r.tokens}` : "—"
350
+ const totalStr = formatMs(r.total)
351
+ const statusStr = r.error ? `错误: ${r.error}` : (r.note || "成功")
352
+ md += `| \`${r.id}\` | ${e2eStr} | ${streamStr} | ${ttftStr} | ${tokStr} | ${totalStr} | ${statusStr} |\n`
353
+ }
354
+ navigator.clipboard.writeText(md).then(() => {
355
+ showToast("✓ 已复制 Markdown 表格到剪贴板")
356
+ }).catch(() => {
357
+ showToast("复制失败,请手动导出")
358
+ })
59
359
  }
60
- function report(error) { byId("notice").textContent = error.message }
61
- target.onchange = groups.onchange = controls
62
- byId("start").onclick = async () => {
360
+
361
+ function exportJson() {
362
+ const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(latestState, null, 2))
363
+ const downloadAnchor = document.createElement("a")
364
+ downloadAnchor.setAttribute("href", dataStr)
365
+ downloadAnchor.setAttribute("download", `magpie-benchmark-${new Date().toISOString().slice(0, 10)}.json`)
366
+ document.body.appendChild(downloadAnchor)
367
+ downloadAnchor.click()
368
+ downloadAnchor.remove()
369
+ showToast("✓ 已导出 JSON 数据")
370
+ }
371
+
372
+ // Event Listeners
373
+ target.onchange = groups.onchange = updateControls
374
+ filterInput.oninput = renderTable
375
+
376
+ document.querySelectorAll("th[data-col]").forEach(th => {
377
+ th.onclick = () => {
378
+ const col = th.getAttribute("data-col")
379
+ if (sortColumn === col) {
380
+ sortAscending = !sortAscending
381
+ } else {
382
+ sortColumn = col
383
+ sortAscending = (col === "ttft" || col === "total" || col === "id")
384
+ }
385
+ document.querySelectorAll("th[data-col]").forEach(h => {
386
+ h.classList.remove("sort-active")
387
+ h.removeAttribute("data-sort-arrow")
388
+ })
389
+ th.classList.add("sort-active")
390
+ th.setAttribute("data-sort-arrow", sortAscending ? "▲" : "▼")
391
+ renderTable()
392
+ }
393
+ })
394
+
395
+ startBtn.onclick = async () => {
63
396
  pending = true
64
397
  const id = target.value
65
- controls()
398
+ updateControls()
66
399
  try {
67
400
  await loadModels()
68
401
  draw(await api("start", { id, groups: groups.checked }))
69
- } catch (error) { report(error) }
70
- finally { pending = false; controls() }
402
+ } catch (error) {
403
+ showToast(`启动失败: ${error.message}`)
404
+ } finally {
405
+ pending = false
406
+ updateControls()
407
+ }
71
408
  }
72
- byId("stop").onclick = async () => { try { await api("stop") } catch (error) { report(error) } }
409
+
410
+ stopBtn.onclick = async () => {
411
+ try {
412
+ await api("stop")
413
+ showToast("已发送停止请求")
414
+ } catch (error) {
415
+ showToast(`停止失败: ${error.message}`)
416
+ }
417
+ }
418
+
419
+ byId("btn-copy-md").onclick = copyMarkdown
420
+ byId("btn-export-json").onclick = exportJson
421
+
73
422
  async function poll() {
74
423
  try {
75
424
  if (!models.length) await loadModels()
76
425
  if (!pending) draw(await api("state"))
77
- } catch (error) { report(error) }
78
- setTimeout(poll, busy ? 500 : 1800)
426
+ } catch (error) {
427
+ console.error("Poll error:", error)
428
+ }
429
+ setTimeout(poll, busy ? 600 : 2000)
79
430
  }
431
+
80
432
  poll()
package/app/index.html CHANGED
@@ -1,30 +1,689 @@
1
1
  <!doctype html>
2
2
  <html lang="zh-CN">
3
- <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
4
- <meta name="session" content="__SESSION__">
5
- <title>模型测速</title>
6
- <style>
7
- :root {color-scheme:light dark;font:15px/1.55 system-ui,sans-serif;color:CanvasText;background:Canvas}
8
- body {max-width:1160px;margin:clamp(20px,5vw,64px) auto;padding:0 20px}
9
- h1 {font-size:clamp(28px,4vw,44px);letter-spacing:-.035em;margin:0}
10
- header p,small {color:GrayText} .controls {display:flex;align-items:center;gap:12px;flex-wrap:wrap;margin:24px 0}
11
- select,button {font:inherit;border:1px solid GrayText;border-radius:7px;padding:7px 12px;color:inherit;background:Canvas}
12
- #start {background:#086151;border-color:#086151;color:white;font-weight:600} button:disabled {opacity:.5}
13
- select {max-width:100%} progress {width:100%;accent-color:#138273;height:6px}
14
- .scroll {overflow-x:auto} table {width:100%;border-collapse:collapse;font-variant-numeric:tabular-nums}
15
- th,td {text-align:right;padding:10px 8px;border-bottom:1px solid color-mix(in srgb,CanvasText 16%,transparent);white-space:nowrap}
16
- th {font-size:13px;color:GrayText} td:first-child,th:first-child,td:last-child,th:last-child {text-align:left}
17
- small {display:block} #notice {color:#b05917} #summary {font-weight:600}
18
- </style>
19
- <header><h1>模型测速</h1><p>比较可见正文的输出速度与首字延迟。测速会使用模型额度。</p></header>
20
- <div class="controls">
21
- <select id="target" aria-label="选择测速范围"><option value="">全部模型 · 1 轮</option></select>
22
- <label><input type="checkbox" id="groups"> 包含路由组</label>
23
- <button id="start" disabled>开始测速</button><button id="stop" hidden>停止</button>
24
- </div>
25
- <p id="plan"></p><p id="status" role="status">正在读取模型…</p>
26
- <progress id="progress" value="0" max="1" hidden></progress>
27
- <p id="notice" role="alert"></p><p id="summary"></p>
28
- <div class="scroll"><table><thead><tr><th>供应商 / 模型</th><th>正文 token/s</th><th>首字</th><th>正文 token</th><th>总耗时</th><th>状态</th></tr></thead><tbody></tbody></table></div>
29
- <script src="app.js"></script>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <meta name="session" content="__SESSION__">
7
+ <title>Magpie 模型测速基准</title>
8
+ <style>
9
+ :root {
10
+ --bg-canvas: #0a0d14;
11
+ --bg-surface: #121722;
12
+ --bg-surface-elevated: #182030;
13
+ --bg-surface-hover: #1f293d;
14
+ --border-subtle: rgba(255, 255, 255, 0.08);
15
+ --border-focus: rgba(20, 184, 166, 0.5);
16
+ --text-primary: #f8fafc;
17
+ --text-secondary: #94a3b8;
18
+ --text-muted: #64748b;
19
+ --brand-teal: #14b8a6;
20
+ --brand-teal-dim: rgba(20, 184, 166, 0.12);
21
+ --brand-purple: #8b5cf6;
22
+ --brand-purple-dim: rgba(139, 92, 246, 0.14);
23
+ --brand-blue: #38bdf8;
24
+ --brand-emerald: #10b981;
25
+ --brand-amber: #f59e0b;
26
+ --brand-rose: #f43f5e;
27
+ --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
28
+ --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
29
+ --radius-sm: 6px;
30
+ --radius-md: 10px;
31
+ --radius-lg: 14px;
32
+ --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
33
+ --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
34
+ --shadow-glow: 0 0 20px rgba(20, 184, 166, 0.2);
35
+ }
36
+
37
+ @media (prefers-color-scheme: light) {
38
+ :root {
39
+ --bg-canvas: #f8fafc;
40
+ --bg-surface: #ffffff;
41
+ --bg-surface-elevated: #f1f5f9;
42
+ --bg-surface-hover: #e2e8f0;
43
+ --border-subtle: rgba(0, 0, 0, 0.08);
44
+ --border-focus: rgba(13, 148, 136, 0.5);
45
+ --text-primary: #0f172a;
46
+ --text-secondary: #475569;
47
+ --text-muted: #94a3b8;
48
+ --brand-teal: #0d9488;
49
+ --brand-teal-dim: rgba(13, 148, 136, 0.08);
50
+ --brand-purple: #7c3aed;
51
+ --brand-purple-dim: rgba(124, 58, 237, 0.08);
52
+ --brand-blue: #0284c7;
53
+ --brand-emerald: #059669;
54
+ --brand-amber: #d97706;
55
+ --brand-rose: #e11d48;
56
+ --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
57
+ --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.07);
58
+ --shadow-glow: 0 0 20px rgba(13, 148, 136, 0.12);
59
+ }
60
+ }
61
+
62
+ * { box-sizing: border-box; margin: 0; padding: 0; }
63
+ body {
64
+ font-family: var(--font-sans);
65
+ font-size: 14px;
66
+ line-height: 1.5;
67
+ color: var(--text-primary);
68
+ background-color: var(--bg-canvas);
69
+ min-height: 100vh;
70
+ padding: clamp(20px, 3vw, 40px) 24px;
71
+ -webkit-font-smoothing: antialiased;
72
+ }
73
+
74
+ .app-container {
75
+ max-width: 1240px;
76
+ margin: 0 auto;
77
+ display: flex;
78
+ flex-direction: column;
79
+ gap: 20px;
80
+ }
81
+
82
+ /* Header */
83
+ header {
84
+ display: flex;
85
+ align-items: flex-start;
86
+ justify-content: space-between;
87
+ flex-wrap: wrap;
88
+ gap: 16px;
89
+ }
90
+ .brand-wrap {
91
+ display: flex;
92
+ align-items: center;
93
+ gap: 12px;
94
+ }
95
+ .brand-icon {
96
+ width: 40px;
97
+ height: 40px;
98
+ border-radius: var(--radius-md);
99
+ background: linear-gradient(135deg, var(--brand-teal), var(--brand-purple));
100
+ display: flex;
101
+ align-items: center;
102
+ justify-content: center;
103
+ color: white;
104
+ font-size: 20px;
105
+ box-shadow: var(--shadow-glow);
106
+ flex-shrink: 0;
107
+ }
108
+ .header-text h1 {
109
+ font-size: clamp(20px, 2.5vw, 26px);
110
+ font-weight: 700;
111
+ letter-spacing: -0.03em;
112
+ line-height: 1.2;
113
+ color: var(--text-primary);
114
+ }
115
+ .header-text p {
116
+ font-size: 13px;
117
+ color: var(--text-secondary);
118
+ margin-top: 3px;
119
+ }
120
+ .badge-pill {
121
+ display: inline-flex;
122
+ align-items: center;
123
+ gap: 5px;
124
+ padding: 3px 9px;
125
+ border-radius: 999px;
126
+ font-size: 11px;
127
+ font-weight: 600;
128
+ background: var(--bg-surface-elevated);
129
+ border: 1px solid var(--border-subtle);
130
+ color: var(--text-secondary);
131
+ }
132
+
133
+ /* KPI Stats Bar */
134
+ .kpi-grid {
135
+ display: grid;
136
+ grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
137
+ gap: 12px;
138
+ }
139
+ .kpi-card {
140
+ background: var(--bg-surface);
141
+ border: 1px solid var(--border-subtle);
142
+ border-radius: var(--radius-md);
143
+ padding: 14px 18px;
144
+ display: flex;
145
+ flex-direction: column;
146
+ justify-content: space-between;
147
+ box-shadow: var(--shadow-sm);
148
+ transition: transform 0.15s ease, border-color 0.15s ease;
149
+ }
150
+ .kpi-card:hover {
151
+ border-color: rgba(255, 255, 255, 0.16);
152
+ }
153
+ .kpi-label {
154
+ font-size: 12px;
155
+ font-weight: 500;
156
+ color: var(--text-secondary);
157
+ display: flex;
158
+ align-items: center;
159
+ justify-content: space-between;
160
+ }
161
+ .kpi-val {
162
+ font-size: 26px;
163
+ font-weight: 700;
164
+ letter-spacing: -0.02em;
165
+ font-family: var(--font-mono);
166
+ margin-top: 4px;
167
+ color: var(--text-primary);
168
+ }
169
+ .kpi-sub {
170
+ font-size: 11px;
171
+ color: var(--text-muted);
172
+ margin-top: 2px;
173
+ white-space: nowrap;
174
+ overflow: hidden;
175
+ text-overflow: ellipsis;
176
+ }
177
+ .kpi-val.purple { color: var(--brand-purple); }
178
+ .kpi-val.teal { color: var(--brand-teal); }
179
+ .kpi-val.blue { color: var(--brand-blue); }
180
+
181
+ /* Control Center Card */
182
+ .control-card {
183
+ background: var(--bg-surface);
184
+ border: 1px solid var(--border-subtle);
185
+ border-radius: var(--radius-lg);
186
+ padding: 16px 20px;
187
+ box-shadow: var(--shadow-md);
188
+ display: flex;
189
+ flex-direction: column;
190
+ gap: 14px;
191
+ }
192
+ .control-row {
193
+ display: flex;
194
+ align-items: center;
195
+ justify-content: space-between;
196
+ flex-wrap: wrap;
197
+ gap: 12px;
198
+ }
199
+ .control-left, .control-right {
200
+ display: flex;
201
+ align-items: center;
202
+ flex-wrap: wrap;
203
+ gap: 10px;
204
+ }
205
+
206
+ /* Inputs & Selects */
207
+ select, input[type="text"] {
208
+ font-family: var(--font-sans);
209
+ font-size: 13px;
210
+ color: var(--text-primary);
211
+ background: var(--bg-surface-elevated);
212
+ border: 1px solid var(--border-subtle);
213
+ border-radius: var(--radius-sm);
214
+ padding: 7px 12px;
215
+ outline: none;
216
+ transition: border-color 0.15s ease, box-shadow 0.15s ease;
217
+ }
218
+ select:focus, input[type="text"]:focus {
219
+ border-color: var(--border-focus);
220
+ box-shadow: 0 0 0 2px var(--brand-teal-dim);
221
+ }
222
+ select {
223
+ cursor: pointer;
224
+ max-width: 260px;
225
+ }
226
+ input[type="text"] {
227
+ min-width: 170px;
228
+ }
229
+
230
+ /* Checkbox Label Pill */
231
+ .checkbox-pill {
232
+ display: inline-flex;
233
+ align-items: center;
234
+ gap: 7px;
235
+ padding: 6px 12px;
236
+ background: var(--bg-surface-elevated);
237
+ border: 1px solid var(--border-subtle);
238
+ border-radius: var(--radius-sm);
239
+ cursor: pointer;
240
+ user-select: none;
241
+ font-size: 13px;
242
+ color: var(--text-secondary);
243
+ transition: all 0.15s ease;
244
+ }
245
+ .checkbox-pill:hover {
246
+ background: var(--bg-surface-hover);
247
+ color: var(--text-primary);
248
+ }
249
+ .checkbox-pill input[type="checkbox"] {
250
+ accent-color: var(--brand-teal);
251
+ cursor: pointer;
252
+ }
253
+
254
+ /* Buttons */
255
+ button {
256
+ font-family: var(--font-sans);
257
+ font-size: 13px;
258
+ font-weight: 600;
259
+ border-radius: var(--radius-sm);
260
+ padding: 7px 15px;
261
+ cursor: pointer;
262
+ display: inline-flex;
263
+ align-items: center;
264
+ gap: 6px;
265
+ border: 1px solid transparent;
266
+ transition: all 0.15s ease;
267
+ white-space: nowrap;
268
+ }
269
+ button:disabled {
270
+ opacity: 0.45;
271
+ cursor: not-allowed;
272
+ }
273
+ .btn-primary {
274
+ background: var(--brand-teal);
275
+ color: #ffffff;
276
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
277
+ }
278
+ .btn-primary:not(:disabled):hover {
279
+ filter: brightness(1.1);
280
+ transform: translateY(-1px);
281
+ box-shadow: 0 4px 10px rgba(20, 184, 166, 0.3);
282
+ }
283
+ .btn-stop {
284
+ background: var(--brand-rose);
285
+ color: white;
286
+ }
287
+ .btn-stop:hover {
288
+ filter: brightness(1.1);
289
+ }
290
+ .btn-ghost {
291
+ background: var(--bg-surface-elevated);
292
+ color: var(--text-secondary);
293
+ border: 1px solid var(--border-subtle);
294
+ }
295
+ .btn-ghost:not(:disabled):hover {
296
+ background: var(--bg-surface-hover);
297
+ color: var(--text-primary);
298
+ }
299
+
300
+ /* Status and Progress */
301
+ .progress-section {
302
+ display: flex;
303
+ flex-direction: column;
304
+ gap: 6px;
305
+ }
306
+ .status-row {
307
+ display: flex;
308
+ align-items: center;
309
+ justify-content: space-between;
310
+ font-size: 12px;
311
+ color: var(--text-secondary);
312
+ }
313
+ .live-status {
314
+ display: flex;
315
+ align-items: center;
316
+ gap: 7px;
317
+ font-weight: 500;
318
+ }
319
+ .dot-live {
320
+ width: 8px;
321
+ height: 8px;
322
+ border-radius: 50%;
323
+ background: var(--brand-emerald);
324
+ animation: pulse 1.4s infinite;
325
+ }
326
+ @keyframes pulse {
327
+ 0% { transform: scale(0.9); opacity: 0.7; }
328
+ 50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 8px var(--brand-emerald); }
329
+ 100% { transform: scale(0.9); opacity: 0.7; }
330
+ }
331
+ .custom-progress {
332
+ width: 100%;
333
+ height: 5px;
334
+ background: var(--bg-surface-elevated);
335
+ border-radius: 999px;
336
+ overflow: hidden;
337
+ position: relative;
338
+ }
339
+ .custom-progress-bar {
340
+ height: 100%;
341
+ background: linear-gradient(90deg, var(--brand-teal), var(--brand-purple));
342
+ border-radius: 999px;
343
+ width: 0%;
344
+ transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
345
+ }
346
+
347
+ /* Table Card */
348
+ .table-card {
349
+ background: var(--bg-surface);
350
+ border: 1px solid var(--border-subtle);
351
+ border-radius: var(--radius-lg);
352
+ box-shadow: var(--shadow-sm);
353
+ overflow: hidden;
354
+ }
355
+ .table-toolbar {
356
+ padding: 12px 18px;
357
+ display: flex;
358
+ align-items: center;
359
+ justify-content: space-between;
360
+ border-bottom: 1px solid var(--border-subtle);
361
+ font-size: 12px;
362
+ color: var(--text-secondary);
363
+ flex-wrap: wrap;
364
+ gap: 8px;
365
+ }
366
+ .table-scroll {
367
+ overflow-x: auto;
368
+ }
369
+ table {
370
+ width: 100%;
371
+ border-collapse: collapse;
372
+ font-variant-numeric: tabular-nums;
373
+ text-align: left;
374
+ }
375
+ th {
376
+ background: var(--bg-surface-elevated);
377
+ font-size: 11px;
378
+ font-weight: 600;
379
+ text-transform: uppercase;
380
+ letter-spacing: 0.04em;
381
+ color: var(--text-muted);
382
+ padding: 11px 14px;
383
+ white-space: nowrap;
384
+ cursor: pointer;
385
+ user-select: none;
386
+ border-bottom: 1px solid var(--border-subtle);
387
+ transition: color 0.15s ease;
388
+ }
389
+ th:hover {
390
+ color: var(--text-primary);
391
+ }
392
+ th.sort-active {
393
+ color: var(--brand-teal);
394
+ }
395
+ th.sort-active::after {
396
+ content: " " attr(data-sort-arrow);
397
+ font-size: 10px;
398
+ }
399
+ th.num, td.num {
400
+ text-align: right;
401
+ }
402
+ td {
403
+ padding: 11px 14px;
404
+ border-bottom: 1px solid var(--border-subtle);
405
+ font-size: 13px;
406
+ color: var(--text-primary);
407
+ vertical-align: middle;
408
+ white-space: nowrap;
409
+ }
410
+ tr:last-child td {
411
+ border-bottom: none;
412
+ }
413
+ tr.model-row:hover td {
414
+ background: var(--bg-surface-hover);
415
+ }
416
+ tr.active-measuring td {
417
+ background: var(--brand-teal-dim);
418
+ }
419
+
420
+ /* Model Name Cell & Badges */
421
+ .model-cell {
422
+ display: flex;
423
+ align-items: center;
424
+ gap: 8px;
425
+ }
426
+ .provider-tag {
427
+ display: inline-block;
428
+ font-size: 10px;
429
+ font-family: var(--font-mono);
430
+ font-weight: 600;
431
+ text-transform: uppercase;
432
+ padding: 2px 6px;
433
+ border-radius: var(--radius-sm);
434
+ background: var(--bg-surface-elevated);
435
+ color: var(--text-secondary);
436
+ border: 1px solid var(--border-subtle);
437
+ letter-spacing: 0.02em;
438
+ }
439
+ .provider-tag.grok { color: #f43f5e; background: rgba(244, 63, 94, 0.1); border-color: rgba(244, 63, 94, 0.2); }
440
+ .provider-tag.deepseek { color: #3b82f6; background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.2); }
441
+ .provider-tag.google { color: #10b981; background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.2); }
442
+ .provider-tag.codex { color: #a855f7; background: rgba(168, 85, 247, 0.1); border-color: rgba(168, 85, 247, 0.2); }
443
+ .provider-tag.group { color: #f59e0b; background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.2); }
444
+
445
+ .model-name {
446
+ font-weight: 600;
447
+ font-size: 13px;
448
+ color: var(--text-primary);
449
+ }
450
+ .model-meta {
451
+ display: block;
452
+ font-size: 11px;
453
+ color: var(--text-muted);
454
+ margin-top: 1px;
455
+ }
456
+
457
+ /* Throughput Speed Bars */
458
+ .speed-cell {
459
+ display: flex;
460
+ flex-direction: column;
461
+ align-items: flex-end;
462
+ gap: 3px;
463
+ min-width: 110px;
464
+ }
465
+ .speed-num {
466
+ font-family: var(--font-mono);
467
+ font-weight: 700;
468
+ font-size: 13px;
469
+ }
470
+ .speed-track {
471
+ width: 100%;
472
+ height: 4px;
473
+ background: var(--bg-surface-elevated);
474
+ border-radius: 99px;
475
+ overflow: hidden;
476
+ }
477
+ .speed-fill-e2e {
478
+ height: 100%;
479
+ background: linear-gradient(90deg, #6366f1, #8b5cf6);
480
+ border-radius: 99px;
481
+ }
482
+ .speed-fill-stream {
483
+ height: 100%;
484
+ background: linear-gradient(90deg, #0d9488, #14b8a6);
485
+ border-radius: 99px;
486
+ }
487
+
488
+ /* Status Badges */
489
+ .status-badge {
490
+ display: inline-flex;
491
+ align-items: center;
492
+ gap: 4px;
493
+ padding: 2px 7px;
494
+ border-radius: var(--radius-sm);
495
+ font-size: 11px;
496
+ font-weight: 500;
497
+ }
498
+ .badge-ok { background: rgba(16, 185, 129, 0.12); color: var(--brand-emerald); }
499
+ .badge-warn { background: rgba(245, 158, 11, 0.12); color: var(--brand-amber); }
500
+ .badge-error { background: rgba(244, 63, 94, 0.12); color: var(--brand-rose); }
501
+
502
+ /* TTFT Color Highlights */
503
+ .ttft-fast { color: var(--brand-emerald); font-weight: 600; font-family: var(--font-mono); }
504
+ .ttft-med { color: var(--text-primary); font-family: var(--font-mono); }
505
+ .ttft-slow { color: var(--brand-amber); font-family: var(--font-mono); }
506
+
507
+ /* Toast */
508
+ .toast {
509
+ position: fixed;
510
+ bottom: 24px;
511
+ right: 24px;
512
+ background: var(--bg-surface-elevated);
513
+ border: 1px solid var(--border-subtle);
514
+ box-shadow: var(--shadow-md);
515
+ padding: 10px 18px;
516
+ border-radius: var(--radius-md);
517
+ font-size: 13px;
518
+ font-weight: 500;
519
+ color: var(--text-primary);
520
+ display: flex;
521
+ align-items: center;
522
+ gap: 8px;
523
+ opacity: 0;
524
+ transform: translateY(10px);
525
+ transition: all 0.2s ease;
526
+ pointer-events: none;
527
+ z-index: 1000;
528
+ }
529
+ .toast.show {
530
+ opacity: 1;
531
+ transform: translateY(0);
532
+ }
533
+
534
+ /* Explanation card */
535
+ .info-footer {
536
+ display: grid;
537
+ grid-template-columns: 1fr 1fr;
538
+ gap: 16px;
539
+ font-size: 12px;
540
+ color: var(--text-secondary);
541
+ line-height: 1.6;
542
+ margin-top: 8px;
543
+ }
544
+ @media (max-width: 768px) {
545
+ .info-footer { grid-template-columns: 1fr; }
546
+ }
547
+ .info-box {
548
+ background: var(--bg-surface);
549
+ border: 1px solid var(--border-subtle);
550
+ border-radius: var(--radius-md);
551
+ padding: 14px 16px;
552
+ }
553
+ .info-box strong {
554
+ color: var(--text-primary);
555
+ display: block;
556
+ margin-bottom: 4px;
557
+ }
558
+ </style>
559
+ </head>
560
+ <body>
561
+ <div class="app-container">
562
+ <!-- Header -->
563
+ <header>
564
+ <div class="brand-wrap">
565
+ <div class="brand-icon">⚡</div>
566
+ <div class="header-text">
567
+ <h1>模型测速基准</h1>
568
+ <p>对比可见正文流式输出速率与端到端综合吞吐量 · 串行实测</p>
569
+ </div>
570
+ </div>
571
+ <div class="header-right">
572
+ <span class="badge-pill" id="target-summary">就绪</span>
573
+ </div>
574
+ </header>
575
+
576
+ <!-- KPI Dashboard Cards -->
577
+ <section class="kpi-grid">
578
+ <div class="kpi-card">
579
+ <div class="kpi-label">已测模型 / 进度</div>
580
+ <div class="kpi-val" id="kpi-count">— / —</div>
581
+ <div class="kpi-sub" id="kpi-count-sub">等待开始</div>
582
+ </div>
583
+ <div class="kpi-card">
584
+ <div class="kpi-label">最高端到端速度 (E2E)</div>
585
+ <div class="kpi-val purple" id="kpi-top-e2e">—</div>
586
+ <div class="kpi-sub" id="kpi-top-e2e-name">综合排队/思考/首字与正文</div>
587
+ </div>
588
+ <div class="kpi-card">
589
+ <div class="kpi-label">最高正文流速 (Stream)</div>
590
+ <div class="kpi-val teal" id="kpi-top-stream">—</div>
591
+ <div class="kpi-sub" id="kpi-top-stream-name">纯正文吐字窗口速率</div>
592
+ </div>
593
+ <div class="kpi-card">
594
+ <div class="kpi-label">最佳首字延迟 (TTFT)</div>
595
+ <div class="kpi-val blue" id="kpi-best-ttft">—</div>
596
+ <div class="kpi-sub" id="kpi-best-ttft-name">从发起到首个正文字符</div>
597
+ </div>
598
+ </section>
599
+
600
+ <!-- Controls Card -->
601
+ <section class="control-card">
602
+ <div class="control-row">
603
+ <div class="control-left">
604
+ <select id="target" aria-label="选择测速范围">
605
+ <option value="">全部模型 · 1 轮</option>
606
+ </select>
607
+ <label class="checkbox-pill">
608
+ <input type="checkbox" id="groups">
609
+ <span>包含路由组</span>
610
+ </label>
611
+ <button id="start" class="btn-primary" disabled>
612
+ <span>▶ 开始测速</span>
613
+ </button>
614
+ <button id="stop" class="btn-stop" hidden>
615
+ <span>⏹ 停止</span>
616
+ </button>
617
+ </div>
618
+
619
+ <div class="control-right">
620
+ <input type="text" id="filter" placeholder="🔍 搜索模型或供应商…" aria-label="搜索模型">
621
+ <button id="btn-copy-md" class="btn-ghost" title="复制当前数据为 Markdown 表格">
622
+ <span>📋 复制表格</span>
623
+ </button>
624
+ <button id="btn-export-json" class="btn-ghost" title="导出测试结果为 JSON">
625
+ <span>💾 导出 JSON</span>
626
+ </button>
627
+ </div>
628
+ </div>
629
+
630
+ <!-- Progress & Live Status -->
631
+ <div class="progress-section" id="progress-container" hidden>
632
+ <div class="status-row">
633
+ <div class="live-status">
634
+ <span class="dot-live"></span>
635
+ <span id="status">正在测速…</span>
636
+ </div>
637
+ <span id="plan-text">预计 23 次请求 · 每次最多 256 输出 token</span>
638
+ </div>
639
+ <div class="custom-progress">
640
+ <div class="custom-progress-bar" id="progress-bar"></div>
641
+ </div>
642
+ </div>
643
+ </section>
644
+
645
+ <!-- Benchmark Data Table Card -->
646
+ <section class="table-card">
647
+ <div class="table-toolbar">
648
+ <span id="table-summary-info">点击任意表头可快速排序</span>
649
+ <span id="median-summary" style="font-weight: 600; color: var(--brand-teal);"></span>
650
+ </div>
651
+ <div class="table-scroll">
652
+ <table id="benchmark-table">
653
+ <thead>
654
+ <tr>
655
+ <th data-col="id" style="min-width: 200px;">模型 / 供应商</th>
656
+ <th data-col="e2eSpeed" class="num sort-active" data-sort-arrow="▼" style="min-width: 140px;">端到端速度</th>
657
+ <th data-col="speed" class="num" style="min-width: 140px;">正文流速</th>
658
+ <th data-col="ttft" class="num" style="min-width: 90px;">首字延迟</th>
659
+ <th data-col="tokens" class="num" style="min-width: 90px;">正文 Token</th>
660
+ <th data-col="total" class="num" style="min-width: 90px;">总耗时</th>
661
+ <th data-col="status" style="min-width: 120px;">状态 / 备注</th>
662
+ </tr>
663
+ </thead>
664
+ <tbody id="table-body">
665
+ <tr>
666
+ <td colspan="7" style="text-align: center; color: var(--text-muted); padding: 36px;">正在连接模型服务并读取配置…</td>
667
+ </tr>
668
+ </tbody>
669
+ </table>
670
+ </div>
671
+ </section>
672
+
673
+ <!-- Footnote: Impeccable metrics explanation -->
674
+ <footer class="info-footer">
675
+ <div class="info-box">
676
+ <strong>端到端速度 (Tokens / Total Duration)</strong>
677
+ 包含了网络建立、队列排队、Prompt 预填充、模型内部思考(Reasoning)以及正文输出的完整耗时。反映从发出指令到完整拿到答案的真实综合速率。
678
+ </div>
679
+ <div class="info-box">
680
+ <strong>正文流速 (Tokens / Streaming Window)</strong>
681
+ 排除了首字等待与思考延迟,仅统计首个可见字符到达至最后一个字符到达之间的打字机喷发流速。Fast 类投机采样模型在此项往往极高。
682
+ </div>
683
+ </footer>
684
+ </div>
685
+
686
+ <div class="toast" id="toast">已复制到剪贴板</div>
687
+ <script src="app.js"></script>
688
+ </body>
30
689
  </html>
package/benchmark.mjs CHANGED
@@ -32,7 +32,12 @@ export async function measure(base, model, signal) {
32
32
  const reply = await response.json()
33
33
  if (reply.error || !reply.choices?.[0]?.message?.content) throw new Error("网关未返回可见正文")
34
34
  const total = performance.now() - started
35
- return { actual: routed || reply.model, total, ttft: total, speed: null, tokens: null, note: "整段返回" }
35
+ const text = reply.choices[0].message.content
36
+ const reasoning = reply.usage?.completion_tokens_details?.reasoning_tokens
37
+ const exact = Number.isInteger(reasoning) && reasoning >= 0 && Number.isInteger(reply.usage?.completion_tokens) && reply.usage.completion_tokens > reasoning
38
+ const tokens = exact ? reply.usage.completion_tokens - reasoning : Math.max(1, Math.round(Buffer.byteLength(text) / 4))
39
+ const e2eSpeed = total >= 10 && tokens > 0 ? tokens * 1000 / total : null
40
+ return { actual: routed || reply.model, total, ttft: total, speed: null, e2eSpeed, tokens, exact, note: "整段返回" }
36
41
  }
37
42
  return readStream(response.body, started, routed)
38
43
  }
@@ -72,6 +77,8 @@ export async function readStream(body, started, routed, now = () => performance.
72
77
  const tokens = exact ? usage.completion_tokens - reasoning : Math.max(1, Math.round(bytes / 4))
73
78
  const window = last - first
74
79
  const speed = window >= 10 ? tokens * (1 - firstBytes / bytes) * 1000 / window : null
75
- return { actual: routed || model, total: now() - started, ttft: first - started, speed, tokens, exact,
80
+ const total = now() - started
81
+ const e2eSpeed = total >= 10 && tokens > 0 ? tokens * 1000 / total : null
82
+ return { actual: routed || model, total, ttft: first - started, speed, e2eSpeed, tokens, exact,
76
83
  note: speed === null ? "正文集中到达" : exact ? "用量计数,速率为估算" : "按英文正文约 4 字节/token 估算" }
77
84
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "magpie-model-speedtest",
3
- "version": "0.1.0",
4
- "description": "One-click streaming token speed and first-text latency benchmarks for models in your Magpie gateway.",
3
+ "version": "0.2.0",
4
+ "description": "One-click end-to-end throughput, streaming token speed, and first-text latency benchmarks for models in your Magpie gateway.",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",
7
7
  "files": ["index.mjs", "benchmark.mjs", "page", "app", "README.md"],
@@ -16,6 +16,6 @@
16
16
  },
17
17
  "options": {"port": 3487},
18
18
  "permissions": [],
19
- "summary": {"zh": "一键比较模型正文输出速度和首字延迟,可选路由组和三轮复测。", "en": "Benchmark streaming throughput and time to first text across enabled models."}
19
+ "summary": {"zh": "一键比较模型端到端综合速度、正文输出速度和首字延迟,可选路由组和三轮复测。", "en": "Benchmark end-to-end throughput, streaming token speed, and time to first text across enabled models."}
20
20
  }
21
21
  }