-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[releases/v0.18.0][Platform][BugFix] Guard forced tool choice with empty content #8400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zzzzwwjj
merged 3 commits into
vllm-project:releases/v0.18.0
from
QwertyJack:fix/tool-choice-none-content-v018
Apr 23, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
tests/ut/patch/platform/test_patch_tool_choice_none_content.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest | ||
| from vllm.entrypoints.openai.engine.serving import OpenAIServing | ||
| from vllm.entrypoints.openai.responses.protocol import ResponsesRequest | ||
| from vllm.parser.abstract_parser import DelegatingParser | ||
|
|
||
| from vllm_ascend.patch.platform import patch_tool_choice_none_content # noqa: F401 | ||
|
|
||
|
|
||
| class _DummyDelegatingParser(DelegatingParser): | ||
| def is_reasoning_end(self, input_ids: list[int]) -> bool: | ||
| return False | ||
|
|
||
| def extract_content_ids(self, input_ids: list[int]) -> list[int]: | ||
| return input_ids | ||
|
|
||
| def extract_reasoning(self, model_output: str, request): | ||
| return None, model_output | ||
|
|
||
| def extract_reasoning_streaming( | ||
| self, | ||
| previous_text: str, | ||
| current_text: str, | ||
| delta_text: str, | ||
| previous_token_ids: list[int], | ||
| current_token_ids: list[int], | ||
| delta_token_ids: list[int], | ||
| ): | ||
| return None | ||
|
|
||
| def extract_tool_calls(self, model_output: str, request): | ||
| return None | ||
|
|
||
|
|
||
| def test_parse_tool_calls_from_content_allows_named_tool_choice_with_none_content(): | ||
| request = ChatCompletionRequest.model_validate( | ||
| { | ||
| "model": "test-model", | ||
| "messages": [{"role": "user", "content": "test"}], | ||
| "tools": [ | ||
| { | ||
| "type": "function", | ||
| "function": { | ||
| "name": "get_weather", | ||
| "parameters": {"type": "object", "properties": {}}, | ||
| }, | ||
| } | ||
| ], | ||
| "tool_choice": {"type": "function", "function": {"name": "get_weather"}}, | ||
| } | ||
| ) | ||
|
|
||
| tool_calls, content = OpenAIServing._parse_tool_calls_from_content( | ||
| request=request, | ||
| tokenizer=None, | ||
| enable_auto_tools=True, | ||
| tool_parser_cls=None, | ||
| content=None, | ||
| ) | ||
|
|
||
| assert content is None | ||
| assert tool_calls is not None | ||
| assert len(tool_calls) == 1 | ||
| assert tool_calls[0].name == "get_weather" | ||
| assert tool_calls[0].arguments == "" | ||
|
|
||
|
|
||
| def test_responses_parser_allows_named_tool_choice_with_none_content(): | ||
| request = ResponsesRequest.model_validate( | ||
| { | ||
| "model": "test-model", | ||
| "input": "test", | ||
| "tools": [ | ||
| { | ||
| "type": "function", | ||
| "name": "get_weather", | ||
| "parameters": {"type": "object", "properties": {}}, | ||
| } | ||
| ], | ||
| "tool_choice": {"type": "function", "name": "get_weather"}, | ||
| } | ||
| ) | ||
| parser = _DummyDelegatingParser(tokenizer=None) | ||
|
|
||
| tool_calls, content = parser._parse_tool_calls( | ||
| request=request, | ||
| content=None, | ||
| enable_auto_tools=False, | ||
| ) | ||
|
|
||
| assert content is None | ||
| assert len(tool_calls) == 1 | ||
| assert tool_calls[0].name == "get_weather" | ||
| assert tool_calls[0].arguments == "" |
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
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
86 changes: 86 additions & 0 deletions
86
vllm_ascend/patch/platform/patch_tool_choice_none_content.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # | ||
| # Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. | ||
| # This file is a part of the vllm-ascend project. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # OpenAI forced tool choice: tolerate None content after reasoning extraction. | ||
| # | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from openai.types.responses import ToolChoiceFunction | ||
| from vllm.entrypoints.openai.chat_completion.protocol import ( | ||
| ChatCompletionNamedToolChoiceParam, | ||
| ) | ||
| from vllm.entrypoints.openai.engine.serving import OpenAIServing | ||
| from vllm.parser.abstract_parser import DelegatingParser | ||
|
|
||
|
|
||
| def _normalize_tool_choice_content( | ||
| request, | ||
| content: str | None, | ||
| ) -> str | None: | ||
| if content is not None: | ||
| return content | ||
|
|
||
| tool_choice = getattr(request, "tool_choice", None) | ||
| if isinstance( | ||
| tool_choice, | ||
| (ToolChoiceFunction, ChatCompletionNamedToolChoiceParam), | ||
| ): | ||
| return "" | ||
| return content | ||
|
|
||
|
|
||
| _original_parse_tool_calls_from_content = OpenAIServing._parse_tool_calls_from_content | ||
|
|
||
|
|
||
| def _patched_parse_tool_calls_from_content( | ||
| request, | ||
| tokenizer, | ||
| enable_auto_tools: bool, | ||
| tool_parser_cls, | ||
| content: str | None = None, | ||
| ): | ||
| content = _normalize_tool_choice_content(request, content) | ||
| return _original_parse_tool_calls_from_content( | ||
| request=request, | ||
| tokenizer=tokenizer, | ||
| enable_auto_tools=enable_auto_tools, | ||
| tool_parser_cls=tool_parser_cls, | ||
| content=content, | ||
| ) | ||
|
|
||
|
|
||
| OpenAIServing._parse_tool_calls_from_content = staticmethod(_patched_parse_tool_calls_from_content) | ||
|
|
||
| _original_delegating_parse_tool_calls = DelegatingParser._parse_tool_calls | ||
|
|
||
|
|
||
| def _patched_delegating_parse_tool_calls( | ||
| self, | ||
| request, | ||
| content: str | None, | ||
| enable_auto_tools: bool, | ||
| ): | ||
| content = _normalize_tool_choice_content(request, content) | ||
| return _original_delegating_parse_tool_calls( | ||
| self, | ||
| request, | ||
| content, | ||
| enable_auto_tools, | ||
| ) | ||
|
|
||
|
|
||
| DelegatingParser._parse_tool_calls = _patched_delegating_parse_tool_calls |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.