Skip to content

Commit 6eca337

Browse files
okdshinhmellor
andauthored
Replace --expand-tools-even-if-tool-choice-none with --exclude-tools-when-tool-choice-none for v0.10.0 (#20544)
Signed-off-by: okada <kokuzen@gmail.com> Signed-off-by: okada shintarou <okada@preferred.jp> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
1 parent 85bda9e commit 6eca337

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

docs/features/tool_calling.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ When tool_choice='required' is set, the model is guaranteed to generate one or m
103103

104104
vLLM supports the `tool_choice='none'` option in the chat completion API. When this option is set, the model will not generate any tool calls and will respond with regular text content only, even if tools are defined in the request.
105105

106-
However, when `tool_choice='none'` is specified, vLLM includes tool definitions from the prompt.
106+
!!! note
107+
When tools are specified in the request, vLLM includes tool definitions in the prompt by default, regardless of the `tool_choice` setting. To exclude tool definitions when `tool_choice='none'`, use the `--exclude-tools-when-tool-choice-none` option.
107108

108109
## Automatic Function Calling
109110

vllm/entrypoints/openai/api_server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,8 @@ async def init_app_state(
16461646
chat_template_content_format=args.chat_template_content_format,
16471647
return_tokens_as_token_ids=args.return_tokens_as_token_ids,
16481648
enable_auto_tools=args.enable_auto_tool_choice,
1649+
exclude_tools_when_tool_choice_none=args.
1650+
exclude_tools_when_tool_choice_none,
16491651
tool_parser=args.tool_call_parser,
16501652
reasoning_parser=args.reasoning_parser,
16511653
enable_prompt_tokens_details=args.enable_prompt_tokens_details,

vllm/entrypoints/openai/cli_args.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class FrontendArgs:
133133
"""If specified, API server will add X-Request-Id header to responses.
134134
Caution: this hurts performance at high QPS."""
135135
enable_auto_tool_choice: bool = False
136+
"""If specified, exclude tool definitions in prompts when
137+
tool_choice='none'."""
138+
exclude_tools_when_tool_choice_none: bool = False
136139
"""Enable auto tool choice for supported models. Use `--tool-call-parser`
137140
to specify which parser to use."""
138141
tool_call_parser: Optional[str] = None

vllm/entrypoints/openai/serving_chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(
6363
return_tokens_as_token_ids: bool = False,
6464
reasoning_parser: str = "",
6565
enable_auto_tools: bool = False,
66+
exclude_tools_when_tool_choice_none: bool = False,
6667
tool_parser: Optional[str] = None,
6768
enable_prompt_tokens_details: bool = False,
6869
enable_force_include_usage: bool = False,
@@ -111,6 +112,8 @@ def __init__(
111112
raise TypeError("Error: --enable-auto-tool-choice requires "
112113
f"tool_parser:'{tool_parser}' which has not "
113114
"been registered") from e
115+
self.exclude_tools_when_tool_choice_none = (
116+
exclude_tools_when_tool_choice_none)
114117

115118
self.enable_prompt_tokens_details = enable_prompt_tokens_details
116119
self.enable_force_include_usage = enable_force_include_usage
@@ -174,7 +177,9 @@ async def create_chat_completion(
174177
"--enable-auto-tool-choice and --tool-call-parser to be set"
175178
)
176179

177-
if request.tools is None:
180+
if (request.tools is None
181+
or (request.tool_choice == "none"
182+
and self.exclude_tools_when_tool_choice_none)):
178183
tool_dicts = None
179184
else:
180185
tool_dicts = [tool.model_dump() for tool in request.tools]

0 commit comments

Comments
 (0)