Skip to content

[Cherry-Pick][BugFix] fix tool call parser(#7369)#7418

Merged
Jiang-Jia-Jun merged 1 commit intoPaddlePaddle:release/2.5from
EmmonsCurse:cherry-pick/7369/release/2.5
Apr 16, 2026
Merged

[Cherry-Pick][BugFix] fix tool call parser(#7369)#7418
Jiang-Jia-Jun merged 1 commit intoPaddlePaddle:release/2.5from
EmmonsCurse:cherry-pick/7369/release/2.5

Conversation

@EmmonsCurse
Copy link
Copy Markdown
Collaborator

Cherry-pick of #7369 (authored by @luukunn) to release/2.5.

devPR:#7369


Motivation

  • 修复 extract_tool_callstools_calledtool_calls 为空时仍返回 True 的问题
  • 修复空字典 {} 被误判为无参数的问题
  • 修复流式输出结束处理中 '"}' 检查过于严格导致数字/布尔值结尾的参数无法正确流式传输的问题

Modifications

  • tools_called=True 改为 tools_called=len(tool_calls) > 0
  • if diff: 改为 if diff is not None:,正确处理空字典
  • if '"}' not in delta_text: 改为 if "}" not in delta_text:,并使用 rindex("}") 获取正确位置
  • 将所有 if not cur_arguments 改为 if cur_arguments is None,避免空字典误判
  • 新增回归测试覆盖空参数、数字/布尔值结尾参数、嵌套对象等边界情况

Usage or Command

Accuracy Tests

Checklist

  • Add at least a tag in the PR title.
  • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
  • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 15, 2026

Thanks for your contribution!

* fix tool call parser

* add unit test

* fix unit test

* add unit test
Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review | 2026-04-15

📋 Review 摘要

PR 概述:修复 ErnieX1ToolParser 中的 3 个 bug:tools_called 错误判断、空字典 {} 误判、流式输出结束处理过于严格

变更范围fastdeploy/entrypoints/openai/tool_parsers/ernie_x1_tool_parser.py

影响面 Tag[APIServer]

问题

级别 文件 概述
- 未发现阻塞性问题

总体评价

这是一个高质量的 bug 修复 PR。变更正确地修复了以下问题:

  1. tools_called 判断修复(Line 113):异常情况下 tool_calls 为空列表时,正确返回 False
  2. 空字典处理修复(Lines 184, 252, 256, 260, 304):将 if diff:/if not cur_arguments 改为显式 is None 检查,避免 {} 被误判
  3. 流式结束处理修复(Lines 185-190):将 '"}' 改为 '}',支持数字/布尔值结尾的参数
  4. 参数处理增强(Lines 274-281):新增处理正则过度捕获的情况

测试用例新增充分,覆盖了空参数、数字结尾、布尔值结尾、嵌套对象等边界场景。Cherry-Pick 到 release/2.5 分支合理。

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/2.5@f3fb7e0). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...points/openai/tool_parsers/ernie_x1_tool_parser.py 77.77% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.5    #7418   +/-   ##
==============================================
  Coverage               ?   69.62%           
==============================================
  Files                  ?      390           
  Lines                  ?    54387           
  Branches               ?     8579           
==============================================
  Hits                   ?    37868           
  Misses                 ?    13805           
  Partials               ?     2714           
Flag Coverage Δ
GPU 69.62% <77.77%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Jiang-Jia-Jun Jiang-Jia-Jun merged commit 12e4fff into PaddlePaddle:release/2.5 Apr 16, 2026
34 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants