Fix L0 JSON output routing for reasoning models#32
Open
Xinyue-QwQc wants to merge 1 commit intoRT15548:mainfrom
Open
Fix L0 JSON output routing for reasoning models#32Xinyue-QwQc wants to merge 1 commit intoRT15548:mainfrom
Xinyue-QwQc wants to merge 1 commit intoRT15548:mainfrom
Conversation
Collaborator
|
感谢这次的 PR,也谢谢你把思路和根因分析写得这么完整,我这边看得很清楚。 这次里面关于 reasoning / thinking 模型输出路由的判断方向,我觉得是有价值的,尤其你提到的这类现象,在一些模型上确实会出现。 不过这版我这边暂时不会直接合,主要还是 我们在 所以这次从通用性考虑, 不过还是很感谢你认真拆这个问题,也谢谢你把 PR 整理得这么完整。像里面 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI 说明
此 Pull Request 由 AI 代表 fork 维护者发起并提交。
下面的代码修改与说明文字由 AI 辅助整理后,作为一次聚焦于根因修复的改动提交到上游仓库。
摘要
这个 PR 修复的是:在支持 reasoning / thinking 的模型上,L0 锚点提取有时会失败的根本原因。
具体问题是什么
在部分 L0 提取场景里,模型实际上已经完成了任务,但返回结果会变成:
message.content是空的reasoning_content或 thinking 输出里于是最终表现出来就是:
根因分析
这个问题本质上是一个“输出路由(output routing)问题”,而不只是一个 JSON 解析问题。
当前的 L0 提取请求只向模型发送了:
system指令<round>内容的user消息这种请求形态实际上仍然把“如何回答”这件事交给了模型自己决定。
对于支持 reasoning / thinking 的模型或供应商接口,常见行为会变成:
assistant.content留空,或者只留下不完整内容也就是说,虽然 prompt 里要求了“只输出 JSON”,但请求结构本身并没有足够强地约束模型必须把 JSON 通过正常的
assistant.content通道输出出来。为什么这个 PR 是从根上修
1. 重新引入 assistant JSON prefill
这个 PR 在生成前重新加入了一段 assistant 预填充:
{"anchors":[这样做的意义是:
对于 chat-completions 风格接口来说,这种约束更强。
这样可以明显降低模型把内容先路由到 reasoning 通道里的概率,并把输出重新拉回到提取逻辑原本期待的
assistant.content中。换句话说,这不是在事后容错,而是在生成阶段就把模型引导回正确的输出路径。
2. 让
Qwen3的 thinking 关闭判断变成大小写无关当前代码只有在模型名包含精确大小写
Qwen3时,才会发送enable_thinking = false。但真实使用场景里,模型名可能来自:
这些地方给出的模型标识不一定总是相同大小写。
所以把这个判断改成大小写无关后,可以更稳定地对 qwen3 变体关闭 thinking,进一步减少它走 reasoning-first 输出路径的概率。
为什么这个 PR 不包含
reasoning_content解析兼容因为那更像是“针对症状做兜底”,而不是“修掉根因”。
解析
reasoning_content当然可以在某些下游场景里提升兼容性,但如果在上游直接这么做,会带来几个问题:所以从上游角度看,更干净的修法是:
assistant.content通道因此,这个 PR 有意只包含“根因修复”:
并且不包含
reasoning_content的解析兜底逻辑。验证
npm run lint补充说明
这是我第一次向上游项目提交 PR,所以可能还没有完全符合项目习惯或维护者预期。如果这个 PR 的内容、格式或处理方式有需要调整的地方,我会非常愿意继续修改。感谢阅读和包容。