[None][fix] use tool parser for named tool choice responses#12052
[None][fix] use tool parser for named tool choice responses#12052youngzheng-oss wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
Route named tool choice through the same parser flow as auto tool choice so tool-call arguments and finish reasons stay consistent. Signed-off-by: Young Zheng <young.zheng@baseten.co> Made-with: Cursor
📝 WalkthroughWalkthroughThe pull request consolidates tool-call handling across streaming and non-streaming post-processing paths in a single file. Tool parsing is now applied uniformly regardless of tool_choice type, and tool_call_id generation is restricted to first chunks only. Duplicate branching logic is eliminated in favor of a single, consistent flow for both functions. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tensorrt_llm/serve/postprocess_handlers.py`:
- Around line 219-250: apply_tool_parser currently lacks access to
args.tool_choice so when a forced named tool
(ChatCompletionNamedToolChoiceParam) is used and the model emits only argument
deltas, resulting calls lose their function name (call.name is None) and
streaming/non-streaming behavior breaks; fix by updating apply_tool_parser to
accept the forced tool name (extract from args.tool_choice when it is a
ChatCompletionNamedToolChoiceParam) and propagate it into returned call objects,
or if you prefer minimal changes, after apply_tool_parser returns, inspect calls
in the postprocess flow (the loop building DeltaToolCall/DeltaFunctionCall) and
if call_item.name is missing but args.tool_choice is a named tool, restore
function_name from args.tool_choice before creating the DeltaFunctionCall so
DeltaToolCall.id/name are preserved.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0a5bb47d-6e2d-4266-9f34-0b2844115b36
📒 Files selected for processing (1)
tensorrt_llm/serve/postprocess_handlers.py
|
Hi @LinPoly , could you review this PR as it is related to tool parser code? Thanks! |
Description
apply_tool_parserfor parity with auto tool choiceTest coverage
Summary by CodeRabbit