A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 3, 04:15 UTC
[Refactor] Use shared coerce_to_schema_type in Seed-OSS tool parser (#43140)
Signed-off-by: sfeng33 <4florafeng@gmail.com>
Flora Feng committed
May 21, 2026 at 00:24 UTC
6441cf4a44856f4eb4dce7d19a51fd69e1b423cf
1 file changed
+8
-125
vllm/tool_parsers/seed_oss_tool_parser.py
+8
-125
@@ -3,11 +3,9 @@
3
# Adapted from qwen3coder xml parser, All rights reserved.
4
# ruff: noqa: E501
5
6
-import ast
6
import json
7
import uuid
8
from collections.abc import Sequence
10
-from typing import Any
9
10
import regex as re
11
@@ -28,6 +26,11 @@ from vllm.tool_parsers.abstract_tool_parser import (
26
Tool,
27
ToolParser,
28
)
29
+from vllm.tool_parsers.utils import (
30
+ coerce_to_schema_type,
31
+ extract_types_from_schema,
32
+ find_tool_properties,
33
+)
34
35
logger = init_logger(__name__)
36
@@ -111,129 +114,10 @@ class SeedOssToolParser(ToolParser):
114
def _parse_xml_function_call(
115
self, function_call_str: str, tools: list[Tool] | None
116
) -> ToolCall | None:
114
- def get_arguments_config(func_name: str) -> dict:
115
- if tools is None:
116
- return {}
117
- for config in tools:
118
- if not hasattr(config, "type") or not (
119
- hasattr(config, "function") and hasattr(config.function, "name")
120
- ):
121
- continue
122
- if config.type == "function" and config.function.name == func_name:
123
- if not hasattr(config.function, "parameters"):
124
- return {}
125
- params = config.function.parameters
126
- if isinstance(params, dict) and "properties" in params:
127
- return params["properties"]
128
- elif isinstance(params, dict):
129
- return params
130
- else:
131
- return {}
132
- logger.warning("Tool '%s' is not defined in the tools list.", func_name)
133
- return {}
134
-
135
- def convert_param_value(
136
- param_value: str, param_name: str, param_config: dict, func_name: str
137
- ) -> Any:
138
- # Handle null value for any type
139
- if param_value.lower() == "null":
140
- return None
141
-
142
- if param_name not in param_config:
143
- if param_config != {}:
144
- logger.warning(
145
- "Parsed parameter '%s' is not defined in "
146
- "the tool parameters for tool '%s', "
147
- "directly returning the string value.",
148
- param_name,
149
- func_name,
150
- )
151
- return param_value
152
-
153
- if (
154
- isinstance(param_config[param_name], dict)
155
- and "type" in param_config[param_name]
156
- ):
157
- param_type = str(param_config[param_name]["type"]).strip().lower()
158
- else:
159
- param_type = "string"
160
- if param_type in ["string", "str", "text", "varchar", "char", "enum"]:
161
- return param_value
162
- elif (
163
- param_type.startswith("int")
164
- or param_type.startswith("uint")
165
- or param_type.startswith("long")
166
- or param_type.startswith("short")
167
- or param_type.startswith("unsigned")
168
- ):
169
- try:
170
- param_value = int(param_value) # type: ignore
171
- except (ValueError, TypeError):
172
- logger.warning(
173
- "Parsed value '%s' of parameter '%s' is not an integer in tool "
174
- "'%s', degenerating to string.",
175
- param_value,
176
- param_name,
177
- func_name,
178
- )
179
- return param_value
180
- elif param_type.startswith("num") or param_type.startswith("float"):
181
- try:
182
- float_param_value = float(param_value)
183
- param_value = (
184
- float_param_value # type: ignore
185
- if float_param_value - int(float_param_value) != 0
186
- else int(float_param_value) # type: ignore
187
- )
188
- except (ValueError, TypeError):
189
- logger.warning(
190
- "Parsed value '%s' of parameter '%s' is not a float in tool "
191
- "'%s', degenerating to string.",
192
- param_value,
193
- param_name,
194
- func_name,
195
- )
196
- return param_value
197
- elif param_type in ["boolean", "bool", "binary"]:
198
- param_value = param_value.lower()
199
- if param_value not in ["true", "false"]:
200
- logger.warning(
201
- "Parsed value '%s' of parameter '%s' is not a boolean "
202
- "(`true` of `false`) in tool '%s', degenerating to false.",
203
- param_value,
204
- param_name,
205
- func_name,
206
- )
207
- return param_value == "true"
208
- else:
209
- if param_type == "object" or param_type.startswith("dict"):
210
- try:
211
- param_value = json.loads(param_value)
212
- return param_value
213
- except (ValueError, TypeError, json.JSONDecodeError):
214
- logger.warning(
215
- "Parsed value '%s' of parameter '%s' is not a valid JSON "
216
- "object in tool '%s', will try other methods to parse it.",
217
- param_value,
218
- param_name,
219
- func_name,
220
- )
221
- try:
222
- param_value = ast.literal_eval(param_value)
223
- except (ValueError, SyntaxError):
224
- logger.warning(
225
- "Parsed value '%s' of parameter '%s' cannot be converted via "
226
- "Python `ast.literal_eval()` in tool '%s', degenerating to string.",
227
- param_value,
228
- param_name,
229
- func_name,
230
- )
231
- return param_value
232
-
117
# Extract function name
118
end_index = function_call_str.index(">")
119
function_name = function_call_str[:end_index]
236
- param_config = get_arguments_config(function_name)
120
+ tool_properties = find_tool_properties(tools, function_name)
121
parameters = function_call_str[end_index + 1 :]
122
param_dict = {}
123
for match in self.tool_call_parameter_regex.findall(parameters):
@@ -247,9 +131,8 @@ class SeedOssToolParser(ToolParser):
131
if param_value.endswith("\n"):
132
param_value = param_value[:-1]
133
250
- param_dict[param_name] = convert_param_value(
251
- param_value, param_name, param_config, function_name
252
- )
134
+ param_types = extract_types_from_schema(tool_properties.get(param_name, {}))
135
+ param_dict[param_name] = coerce_to_schema_type(param_value, param_types)
136
return ToolCall(
137
type="function",
138
function=FunctionCall(