Add 'anyOf' schema support for qwen3_coder tool call parser (#30832)

Co-authored-by: Xinyuan Tong <115166877+JustinTong0323@users.noreply.github.com>
Co-authored-by: Liangsheng Yin <hnyls2002@gmail.com>
Co-authored-by: Alex Nails <alex.nails@radixark.ai>
This commit is contained in:
ilyasher-harmonic
2026-07-22 14:14:47 -07:00
committed by GitHub
co-authored by Xinyuan Tong Liangsheng Yin Alex Nails
parent e7511141ea
commit c20c48b8fd
3 changed files with 159 additions and 7 deletions
@@ -11,6 +11,7 @@ from sglang.srt.function_call.core_types import (
ToolCallItem,
_GetInfoFunc,
)
from sglang.srt.function_call.utils import infer_type_from_json_schema
logger = logging.getLogger(__name__)
@@ -86,6 +87,13 @@ class Qwen3CoderDetector(BaseFormatDetector):
logger.warning(f"Tool '{func_name}' is not defined in the tools list.")
return {}
def _get_param_type(self, param_schema: Any) -> str:
"""Infer the parser conversion type from a JSON schema parameter."""
inferred_type = infer_type_from_json_schema(param_schema)
if inferred_type is None:
return "string"
return str(inferred_type).strip().lower()
def _convert_param_value(
self, param_value: str, param_name: str, param_config: dict, func_name: str
) -> Any:
@@ -102,13 +110,7 @@ class Qwen3CoderDetector(BaseFormatDetector):
)
return param_value
if (
isinstance(param_config[param_name], dict)
and "type" in param_config[param_name]
):
param_type = str(param_config[param_name]["type"]).strip().lower()
else:
param_type = "string"
param_type = self._get_param_type(param_config[param_name])
if param_type in ["string", "str", "text", "varchar", "char", "enum"]:
return param_value
elif (
+3
View File
@@ -320,6 +320,9 @@ def infer_type_from_json_schema(schema: Dict[str, Any]) -> Optional[str]:
# If all types are the same, return unified type
if len(set(types)) == 1:
return types[0]
# If it's an optional type, return original type.
if len(set(types)) == 2 and "null" in types:
return [t for t in types if t != "null"][0]
# When types differ, prioritize string (safest)
if "string" in types:
return "string"