执行摘要
PR #47883 为 Rust 前端 chat parser 新增 3 组 roundtrip 测试 fixture,覆盖 MiniMax-M3、GLM-4.5 和 Nemotron V3 的推理与工具调用格式。在 reviewer 建议下移除了格式重复的 GLM-4.6 用例。全部变更仅涉及单测试文件,无生产代码改动,风险极低,值得快速合并。
功能与动机
为什么做? PR body 明确说明:为已有的 parser 路由补充 roundtrip 测试覆盖。具体涉及四个模型变体(原始计划包含 GLM-4.6):
MiniMaxAI/MiniMax-M3:推理 + 工具调用
zai-org/GLM-4.5:推理 + 工具调用
zai-org/GLM-4.6:推理 + 工具调用(后被移除)
nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16:推理
这些模型已经由上游 parser 支持,但缺少 roundtrip 回归测试,本次 PR 填补了这一空白。
实现拆解
-
新增 fixture 定义:在 rust/src/chat/tests/roundtrip.rs 的 RoundtripCase impl 块中新增三个构造方法:
minimax_m3():使用 MiniMaxAI/MiniMax-M3,<mm:think> 推理标签,ThinkingBehavior::Always。
glm45():使用 zai-org/GLM-4.5,空 assistant_stop_suffix,ThinkingBehavior::Toggleable 默认开启。
nemotron_v3():使用 nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16,<|im_end|>\n 作为 stop token,ThinkingBehavior::Always。
-
注册到宏:在 roundtrip_tests! 宏调用中注册每个 fixture 参与的测试场景:
minimax_m3 → reasoning_and_content + tool_call_mix
glm45 → reasoning_and_content + tool_call_mix
nemotron_v3 → reasoning_and_content(不参与工具调用,因为当前 parser 对 Nemotron V3 的工具调用处理尚不完整)
-
移除冗余用例:原作者最初包含 glm46 fixture,但 reviewer BugenZhao 指出其格式与 glm45 高度重复,作者同意移除。该操作通过后续 commit 完成。
rust/src/chat/tests/roundtrip.rs
唯一变更文件,新增 3 组测试 fixture 并注册到宏中,同时移除了冗余的 GLM-4.6 用例。
// 文件:rust/src/chat/tests/roundtrip.rs
// 新增的三个 fixture 定义,遵循已有模式:使用 ParserSelection::Auto
// 让测试框架自动选择合适的 parser,分别验证不同模型变体的推理标签和工具调用格式
/// MiniMax M3 invoke format with `<mm:think>` reasoning tags.
fn minimax_m3() -> Self {
Self {
model_id: "MiniMaxAI/MiniMax-M3",
assistant_stop_suffix: "[e~[\n",
tool_call_parser: ParserSelection::Auto,
reasoning_parser: ParserSelection::Auto,
// MiniMax 系列总是启用思考行为
thinking_behavior: ThinkingBehavior::Always { value: true },
json_fmt: compact_json_fmt(),
sort_json_keys: false,
}
}
/// GLM-4.5 XML-like argument format with `<think>` reasoning tags.
fn glm45() -> Self {
Self {
model_id: "zai-org/GLM-4.5",
assistant_stop_suffix: "", // GLM 系列没有专门的 assistant stop token
tool_call_parser: ParserSelection::Auto,
reasoning_parser: ParserSelection::Auto,
// 可切换的思考行为,默认开启
thinking_behavior: ThinkingBehavior::Toggleable { default: true },
json_fmt: compact_json_fmt(),
sort_json_keys: false,
}
}
/// Nemotron V3 with `<think>` / `</think>` reasoning tags.
fn nemotron_v3() -> Self {
Self {
model_id: "nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16",
assistant_stop_suffix: "<|im_end|>\n",
tool_call_parser: ParserSelection::Auto,
reasoning_parser: ParserSelection::Auto,
// Nemotron 总是启用思考行为
thinking_behavior: ThinkingBehavior::Always { value: true },
json_fmt: compact_json_fmt(),
sort_json_keys: false,
}
}
// 在 roundtrip_tests! 宏调用中注册新增的 fixture
// minimax_m3 和 glm45 参与两种测试场景,nemotron_v3 仅参与 reasoning + content
roundtrip_tests! {
// ... 已有条目 ...
minimax_m3 => [reasoning_and_content, tool_call_mix],
glm45 => [reasoning_and_content, tool_call_mix],
nemotron_v3 => [reasoning_and_content],
// ... 其他条目 ...
}
评论区精华
BugenZhao(reviewer):"I think the format for GLM-4.6 is mostly the same as GLM-4.5 so it may not be necessary to have that."
reidliu41(作者):"Makes sense, thanks."
这是一次典型的“少即是多”讨论。reviewer 敏锐地发现 GLM-4.6 与 GLM-4.5 在 parser 配置上几乎完全一致,添加独立测试只会增加维护负担而不提供额外价值。作者迅速接受反馈并在后续提交中移除了该用例,体现了良好的协作习惯。
风险与影响
风险:几乎为零。PR 仅修改测试文件,不涉及任何生产代码、配置或 API。新增 fixture 使用的 parser 配置(Auto、ThinkingBehavior、compact_json_fmt)均在已有 fixture 中验证过,因此不会引入新的失败模式。
影响:
- 正面:提升了对 MiniMax-M3、GLM-4.5、Nemotron V3 的回归防护能力,有助于在 parser 重构时及早发现问题。
- 负面:无。
关联脉络
本 PR 属于 Rust 前端 parser 测试覆盖的持续改进工作,与近期同仓库的 PR #47959(Rust 前端集成视频多模态并重构模态架构)属于同一工程方向——增强 Rust 前端 parser 的质量基础设施。后续可以考虑将 roundtrip fixture 作为新增 parser 路由的强制前置条件。
参与讨论