[Frontend] Skip structural tags for auto tool_choice without strict mode (#45600)
Signed-off-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
@@ -84,6 +84,17 @@ def register_vllm_structural_tag(model: str):
|
||||
return decorator
|
||||
|
||||
|
||||
def _any_tool_strict(
|
||||
tools: Sequence[ChatCompletionToolsParam | ResponsesTool],
|
||||
) -> bool:
|
||||
for tool in tools:
|
||||
if isinstance(tool, FunctionTool) and tool.strict is True:
|
||||
return True
|
||||
if isinstance(tool, ChatCompletionToolsParam) and tool.function.strict is True:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_model_structural_tag(
|
||||
model: str,
|
||||
tools: Sequence[ChatCompletionToolsParam | ResponsesTool] | None,
|
||||
@@ -95,6 +106,9 @@ def get_model_structural_tag(
|
||||
if not tools or tool_choice == "none":
|
||||
return None
|
||||
|
||||
if tool_choice == "auto" and not _any_tool_strict(tools):
|
||||
return None
|
||||
|
||||
dumped_tools = [_dump_tool_for_xgrammar(tool) for tool in tools]
|
||||
dumped_tool_choice = _dump_tool_choice_for_xgrammar(tool_choice)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user