Revert "[Bugfix] Fix Qwen3CoderToolParser anyOf/oneOf type resolution for nullable params (#37831)" (#38751)

This commit is contained in:
Kevin H. Luu
2026-04-02 06:34:28 +08:00
committed by GitHub
parent 54500546ac
commit 1785dc5501
2 changed files with 14 additions and 254 deletions
+14 -52
View File
@@ -131,58 +131,11 @@ class Qwen3CoderToolParser(ToolParser):
logger.debug("Tool '%s' is not defined in the tools list.", func_name)
return {}
@staticmethod
def _first_non_null_type(type_value: Any) -> str | None:
"""Extract the first non-null type from a type value.
Handles both scalar types ("integer") and type-as-array
(["integer", "null"]) per JSON Schema spec.
"""
if isinstance(type_value, list):
return next(
(
str(t).strip().lower()
for t in type_value
if t is not None and str(t).lower() != "null"
),
None,
)
if type_value is not None and str(type_value).lower() != "null":
return str(type_value).strip().lower()
return None
def _resolve_param_type(self, param_def: dict) -> str:
"""Resolve the effective type string from a parameter definition.
Handles direct "type" fields (including type-as-array),
anyOf/oneOf schemas emitted by Pydantic v2 for Optional[T],
and $ref schemas from Pydantic model inputs.
"""
if "type" in param_def:
resolved = self._first_non_null_type(param_def["type"])
return resolved or "string"
if "anyOf" in param_def or "oneOf" in param_def:
variants = param_def.get("anyOf") or param_def.get("oneOf", [])
for v in variants:
if not isinstance(v, dict):
continue
resolved = self._first_non_null_type(v.get("type"))
if resolved:
return resolved
# $ref points to a schema definition (e.g. a Pydantic model).
# The referenced type is almost always an object, so treat it
# as such to route through json.loads.
if "$ref" in param_def:
return "object"
return "string"
def _convert_param_value(
self, param_value: str, param_name: str, param_config: dict, func_name: str
) -> Any:
"""Convert parameter value based on its type in the schema."""
# Handle null value for any type
if param_value.lower() == "null":
return None
@@ -197,10 +150,19 @@ class Qwen3CoderToolParser(ToolParser):
)
return param_value
if not isinstance(param_config[param_name], dict):
return param_value
param_type = self._resolve_param_type(param_config[param_name])
if (
isinstance(param_config[param_name], dict)
and "type" in param_config[param_name]
):
param_type = str(param_config[param_name]["type"]).strip().lower()
elif (
isinstance(param_config[param_name], dict)
and "anyOf" in param_config[param_name]
):
# anyOf has no top-level "type"; treat as object to trigger json.loads.
param_type = "object"
else:
param_type = "string"
if param_type in ["string", "str", "text", "varchar", "char", "enum"]:
return param_value
elif (