[feat] Add SGLANG_TOOL_STRICT_LEVEL for tool-call behavior control (#12423)
Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ from sglang.srt.entrypoints.openai.protocol import (
|
||||
ToolCallConstraint,
|
||||
ToolChoice,
|
||||
)
|
||||
from sglang.srt.environ import ToolStrictLevel, envs
|
||||
from sglang.srt.function_call.base_format_detector import BaseFormatDetector
|
||||
from sglang.srt.function_call.core_types import ToolCallItem
|
||||
from sglang.srt.function_call.deepseekv3_detector import DeepSeekV3Detector
|
||||
@@ -62,6 +63,7 @@ class FunctionCallParser:
|
||||
|
||||
self.detector = detector
|
||||
self.tools = tools
|
||||
self.tool_strict_level = envs.SGLANG_TOOL_STRICT_LEVEL.get()
|
||||
|
||||
def has_tool_call(self, text: str) -> bool:
|
||||
"""
|
||||
@@ -142,7 +144,10 @@ class FunctionCallParser:
|
||||
info = get_structure_info(name)
|
||||
|
||||
# accept all if not strict, otherwise only accept the schema
|
||||
schema = function.parameters if function.strict else {}
|
||||
is_strict = (
|
||||
function.strict or self.tool_strict_level >= ToolStrictLevel.PARAMETER
|
||||
)
|
||||
schema = function.parameters if is_strict else {}
|
||||
|
||||
tool_structures.append(
|
||||
StructuresResponseFormat(
|
||||
@@ -180,7 +185,10 @@ class FunctionCallParser:
|
||||
if (
|
||||
self.detector.supports_structural_tag()
|
||||
and tool_choice == "auto"
|
||||
and any(tool.function.strict for tool in self.tools)
|
||||
and (
|
||||
any(tool.function.strict for tool in self.tools)
|
||||
or self.tool_strict_level >= ToolStrictLevel.FUNCTION
|
||||
)
|
||||
):
|
||||
tag = self.get_structure_tag()
|
||||
return ("structural_tag", tag)
|
||||
|
||||
Reference in New Issue
Block a user