Skip to content

Commit 9226e84

Browse files
committed
fix(webui) review 修复:错误 chunk 透传/评测子集键/克隆回填/迁移保留分桶
①streamChat:JSON.parse 单独包 try,错误 chunk 的 throw 移出只容半个 JSON 的裸 catch(原先被吞,透传修复是 no-op)。②评测子集下传键 subsets→subset_list:EvalScope BenchmarkMeta._update 对未知键静默丢弃,误键不报错地评全集;回显双键兼容旧存档。③模板克隆:adapters/model_name/model_author 并进 known 一起 setParams(整体替换会抹掉先前的单独 setParam)。④助手历史迁移保留原分桶:助手下拉列全部会话含首页对比会话,替换式落盘会删掉对比各列历史。tsc --noEmit 零错误。
1 parent 1e054b5 commit 9226e84

4 files changed

Lines changed: 63 additions & 54 deletions

File tree

‎webui/src/api/models.ts‎

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -474,48 +474,53 @@ export async function streamChat(
474474
done = true;
475475
break;
476476
}
477+
/* parse 单独包:下面的裸 catch 只容「半个 JSON」,业务错误(上游
478+
* 错误 chunk)若也在同一 try 里抛会被它吞掉,修复变 no-op */
479+
type Delta = { reasoning_content?: unknown; content?: unknown; tool_calls?: unknown };
480+
let chunk: { error?: unknown; choices?: { finish_reason?: unknown; delta?: Delta }[] };
477481
try {
478-
const chunk = JSON.parse(payload);
479-
/* OpenAI 形态的流式错误 chunk(上游模板/引擎错误经网关转成 {"error":{message,type}}):
480-
* 不在此抛出的话,它会因没有 choices 被当成空 chunk 静默吞掉,观感又是「空流」 */
481-
const errObj = (chunk as { error?: unknown }).error;
482-
if (errObj) {
483-
const msg = typeof errObj === 'object' && errObj !== null && 'message' in errObj
484-
? String((errObj as { message?: unknown }).message)
485-
: String(errObj);
486-
throw new Error(tStatic('api.upstreamStreamError', { msg }));
487-
}
488-
const choice = chunk.choices?.[0] ?? {};
489-
if (typeof choice.finish_reason === 'string' && choice.finish_reason) finishReason = choice.finish_reason;
490-
const delta = choice.delta ?? {};
491-
const reasoning = typeof delta.reasoning_content === 'string' ? delta.reasoning_content : '';
492-
const content = typeof delta.content === 'string' ? delta.content : '';
493-
/* 标准通道分片拼装(缺 index 的退化流一律当第 0 个调用) */
494-
if (Array.isArray(delta.tool_calls)) {
495-
for (const tc of delta.tool_calls as {
496-
index?: number;
497-
id?: unknown;
498-
function?: { name?: unknown; arguments?: unknown };
499-
}[]) {
500-
const idx = typeof tc.index === 'number' ? tc.index : 0;
501-
const slot = stdCalls.get(idx) ?? { id: '', name: '', args: '' };
502-
if (typeof tc.id === 'string' && tc.id) slot.id = tc.id;
503-
if (typeof tc.function?.name === 'string' && tc.function.name) slot.name = tc.function.name;
504-
if (typeof tc.function?.arguments === 'string') slot.args += tc.function.arguments;
505-
stdCalls.set(idx, slot);
506-
}
507-
}
508-
const parts = splitter.feed(reasoning, content);
509-
const tOut = toolSplitter.feed(parts.content);
510-
if (parts.reasoning || tOut.content) {
511-
onDelta({ content: tOut.content, reasoning: parts.reasoning });
512-
}
513-
if (tOut.toolCalls?.length) {
514-
toolCalls.push(...tOut.toolCalls);
515-
onDelta({ content: '', reasoning: '', toolCalls: tOut.toolCalls });
516-
}
482+
chunk = JSON.parse(payload);
517483
} catch {
518484
/* 半个 JSON 事件留在下一轮处理;非 JSON 的心跳行直接跳过 */
485+
continue;
486+
}
487+
/* OpenAI 形态的流式错误 chunk(上游模板/引擎错误经网关转成 {"error":{message,type}}):
488+
* 不在此抛出的话,它会因没有 choices 被当成空 chunk 静默吞掉,观感又是「空流」 */
489+
const errObj = chunk.error;
490+
if (errObj) {
491+
const msg = typeof errObj === 'object' && errObj !== null && 'message' in errObj
492+
? String((errObj as { message?: unknown }).message)
493+
: String(errObj);
494+
throw new Error(tStatic('api.upstreamStreamError', { msg }));
495+
}
496+
const choice: { finish_reason?: unknown; delta?: Delta } = chunk.choices?.[0] ?? {};
497+
if (typeof choice.finish_reason === 'string' && choice.finish_reason) finishReason = choice.finish_reason;
498+
const delta: Delta = choice.delta ?? {};
499+
const reasoning = typeof delta.reasoning_content === 'string' ? delta.reasoning_content : '';
500+
const content = typeof delta.content === 'string' ? delta.content : '';
501+
/* 标准通道分片拼装(缺 index 的退化流一律当第 0 个调用) */
502+
if (Array.isArray(delta.tool_calls)) {
503+
for (const tc of delta.tool_calls as {
504+
index?: number;
505+
id?: unknown;
506+
function?: { name?: unknown; arguments?: unknown };
507+
}[]) {
508+
const idx = typeof tc.index === 'number' ? tc.index : 0;
509+
const slot = stdCalls.get(idx) ?? { id: '', name: '', args: '' };
510+
if (typeof tc.id === 'string' && tc.id) slot.id = tc.id;
511+
if (typeof tc.function?.name === 'string' && tc.function.name) slot.name = tc.function.name;
512+
if (typeof tc.function?.arguments === 'string') slot.args += tc.function.arguments;
513+
stdCalls.set(idx, slot);
514+
}
515+
}
516+
const parts = splitter.feed(reasoning, content);
517+
const tOut = toolSplitter.feed(parts.content);
518+
if (parts.reasoning || tOut.content) {
519+
onDelta({ content: tOut.content, reasoning: parts.reasoning });
520+
}
521+
if (tOut.toolCalls?.length) {
522+
toolCalls.push(...tOut.toolCalls);
523+
onDelta({ content: '', reasoning: '', toolCalls: tOut.toolCalls });
519524
}
520525
}
521526
}

‎webui/src/pages/eval/EvalNewPage.tsx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ function itemSummary(items: EvalItem[]): string {
3131
.join(' ');
3232
}
3333

34-
/* 存档任务(datasetArgs 形态)→ 表单项(subsets 形态)的回显归一 */
34+
/* 存档任务(datasetArgs 形态)→ 表单项(subsets 形态)的回显归一。
35+
* 落盘键是 EvalScope 的 subset_list;旧误键 subsets 的存档也认(回显不丢)。 */
3536
function fromStoredItem(it: EvalItem): EvalItem {
36-
const inner = (it.datasetArgs as Record<string, { subsets?: unknown }> | undefined)?.[it.dataset];
37-
const subs = inner && Array.isArray(inner.subsets) ? inner.subsets.map(String) : undefined;
37+
const inner = (it.datasetArgs as Record<string, { subset_list?: unknown; subsets?: unknown }> | undefined)?.[it.dataset];
38+
const raw = inner?.subset_list ?? inner?.subsets;
39+
const subs = Array.isArray(raw) ? raw.map(String) : undefined;
3840
return {
3941
dataset: it.dataset,
4042
...(it.limit ? { limit: it.limit } : {}),
@@ -222,13 +224,14 @@ export function EvalNewPage() {
222224
setItems((prev) => prev.map((it) => (it.dataset === name ? { ...it, subsets: undefined } : it)));
223225

224226
/*
225-
* 部分勾选子集时的 dataset_args 形态(EvalScope 的 {dataset: {subsets: [...]}})。
226-
* 全选不传——整集评测与显式列全部子集在 EvalScope 语义上等价,省一个参数。
227+
* 部分勾选子集时的 dataset_args 形态(EvalScope 的 {dataset: {subset_list: [...]}})。
228+
* 键名必须是 subset_list:BenchmarkMeta._update 对未知键静默丢弃,写 subsets
229+
* 会不报错地评全集。全选不传——整集评测与显式列全部子集语义等价,省一个参数。
227230
*/
228231
const argsOf = (it: EvalItem): Record<string, unknown> | undefined => {
229232
const all = datasets.find((d) => d.name === it.dataset)?.subsets;
230233
if (it.subsets?.length && all && it.subsets.length < all.length) {
231-
return { [it.dataset]: { subsets: it.subsets } };
234+
return { [it.dataset]: { subset_list: it.subsets } };
232235
}
233236
return undefined;
234237
};

‎webui/src/pages/train/TrainNewPage.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ export function TrainNewPage() {
282282
}
283283
/* rl_type 是独立选择器管的,不进 params 表单面 */
284284
delete known.rl_type;
285-
/* adapters 是页面顶层字段(同 model/tuner),不进 ALL_PARAMS,单独回填 */
286-
if (typeof src.params.adapters === 'string' && src.params.adapters) setParam('adapters', src.params.adapters);
287-
/* 身份字段同 adapters(联动字段不在 ALL_PARAMS 清单里,模板克隆单独回填) */
288-
for (const k of ['model_name', 'model_author'] as const) {
289-
if (typeof src.params[k] === 'string' && src.params[k]) setParam(k, src.params[k]);
285+
/* adapters/model_name/model_author 是联动字段(不在 ALL_PARAMS 清单),
286+
* 必须并进 known 一起回填:setParams(known) 是整体替换,先单独 setParam
287+
* 会被它按批处理顺序抹掉。 */
288+
for (const k of ['adapters', 'model_name', 'model_author'] as const) {
289+
if (typeof src.params[k] === 'string' && src.params[k]) known[k] = src.params[k];
290290
}
291291
setParams(known);
292292
setExtraArgs(src.extraArgs ?? '');

‎webui/vite.config.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,8 @@ function publicEvalTask(t: EvalTask) {
13081308
* 结果缓存在模块变量里——注册表随安装版本固定,不需要每请求重探。
13091309
* description 截首个正文段(Overview 标题后的第一段,限 400 字);subsets 是
13101310
* 评测集的子集清单(如 ceval 的 52 个科目),供前端勾选后经 eval_dataset_args
1311-
* 的 {dataset: {subsets: [...]}} 形态下传。
1311+
* 的 {dataset: {subset_list: [...]}} 形态下传(键名必须是 subset_list,
1312+
* EvalScope 对未知键静默丢弃)。
13121313
*/
13131314
let evalDatasetsCache: { name: string; prettyName: string; tags: string[]; metrics: string[]; description?: string; subsets?: string[] }[] | null = null;
13141315

@@ -6504,8 +6505,8 @@ if (req.method === 'POST' && !seg0) {
65046505
/*
65056506
* 助手单流历史(与模型无关):读 '*' 桶;无 '*' 桶且有旧分桶时
65066507
* 一次性迁移——按插入序合并进 '*' 并落盘,助手续聊旧会话不丢
6507-
* 历史。只由助手侧调用(fetchConvHistory),首页对账不走这里,
6508-
* 对比模式的各列独立桶不会被误合并。多桶并存时合并顺序无时间戳
6508+
* 历史。原分桶必须保留:助手下拉列全部会话(含首页对比会话),
6509+
* 替换式落盘会把对比各列的历史删掉。多桶并存时合并顺序无时间戳
65096510
* 可依,取对象插入序(助手旧会话通常仅一个非空桶)。
65106511
*/
65116512
const current = readConvs();
@@ -6519,7 +6520,7 @@ if (req.method === 'POST' && !seg0) {
65196520
if (!buckets['*']?.length) {
65206521
const legacy = Object.entries(buckets).filter(([, msgs]) => msgs.length);
65216522
if (legacy.length) {
6522-
buckets = { '*': legacy.flatMap(([, msgs]) => msgs) };
6523+
buckets = { ...buckets, '*': legacy.flatMap(([, msgs]) => msgs) };
65236524
writeConvs(current.chats, { ...current.turns, [conv]: buckets });
65246525
}
65256526
}

0 commit comments

Comments
 (0)