vllm_mlx.tool_parsers.qwen_tool_parser¶
Qwen tool call parser for vllm-mlx.
View the complete module source at #L1-L351.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
vllm_mlx.tool_parsers.qwen_tool_parser
¶
Qwen tool call parser for vllm-mlx.
Handles Qwen's tool calling formats:
- XML style:
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser
¶
Bases: ToolParser
Tool call parser for Qwen models.
Supports multiple Qwen tool call formats:
- XML:
Used when --enable-auto-tool-choice --tool-call-parser qwen are set.
Source code in vllm_mlx/tool_parsers/abstract_tool_parser.py
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.SUPPORTS_NATIVE_TOOL_FORMAT
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.XML_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.BRACKET_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.FUNCTION_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.PARAM_PATTERN
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.EMPTY_TOOL_CALL
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser._PARTIAL_MARKERS
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.extract_tool_calls
¶
extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
Extract tool calls from a complete Qwen model response.
Source code in vllm_mlx/tool_parsers/qwen_tool_parser.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser._strip_unclosed_markup
staticmethod
¶
Strip a trailing unclosed tool-call marker (truncated output).
When generation hits max_tokens mid-tool-call, a partial
<tool_call>/<function=/[Calling tool: marker remains
in the cleaned text. We locate the earliest such unclosed marker
and drop everything from there to the end so the API response
never carries raw markup.
Source code in vllm_mlx/tool_parsers/qwen_tool_parser.py
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser._has_partial_marker
¶
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser._get_partial_marker_len
¶
Return the length of a partial tool call marker suffix at end of text.
Source code in vllm_mlx/tool_parsers/qwen_tool_parser.py
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser._was_buffering
¶
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.extract_tool_calls_streaming
¶
extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] | None = None, current_token_ids: Sequence[int] | None = None, delta_token_ids: Sequence[int] | None = None, request: dict[str, Any] | None = None) -> dict[str, Any] | None
Extract tool calls from streaming Qwen model output.
Source code in vllm_mlx/tool_parsers/qwen_tool_parser.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
vllm_mlx.tool_parsers.qwen_tool_parser._parse_param_value
¶
Parse a parameter value, handling JSON literals and plain strings.
Source code in vllm_mlx/tool_parsers/qwen_tool_parser.py
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
vllm_mlx.tool_parsers.qwen_tool_parser._parse_param_value · function
Parse a parameter value, handling JSON literals and plain strings.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
val |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Any - Direct return expressions:
json.loads(val);val;python_val
Exceptions and behavior
Function _parse_param_value calls json.loads, ast.literal_eval, isinstance, sorted; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen_tool_parser.generate_tool_id · function
Generate a unique tool call ID.
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
f'call_{uuid.uuid4().hex[:8]}'
Exceptions and behavior
Function generate_tool_id calls uuid.uuid4; returns f'call_{uuid.uuid4().hex[:8]}'.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser · class
Tool call parser for Qwen models.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser
Exceptions and behavior
Class QwenToolParser derives from ToolParser and declares 6 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.extract_tool_calls · method
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
Extract tool calls from a complete Qwen model response.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_output |
str |
yes |
none |
Required positional or keyword input. |
request |
dict[str, Any] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
ExtractedToolCallInformation - Direct return expressions:
ExtractedToolCallInformation(tools_called=True, tool_calls=tool_calls, content=cleaned_text if cleaned_text else None);ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=stripped)
Exceptions and behavior
Method QwenToolParser.extract_tool_calls calls self.strip_think_tags, self.BRACKET_PATTERN.findall, json.loads, tool_calls.append; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser._strip_unclosed_markup · method
Strip a trailing unclosed tool-call marker (truncated output).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
text;text[:earliest].rstrip()
Exceptions and behavior
Method QwenToolParser._strip_unclosed_markup calls len, text.rfind, min, text[:earliest].rstrip; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser._has_partial_marker · method
Check if text ends with an incomplete tool call marker prefix.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
self._get_partial_marker_len(text) > 0
Exceptions and behavior
Method QwenToolParser._has_partial_marker calls self._get_partial_marker_len; returns self._get_partial_marker_len(text) > 0.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser._get_partial_marker_len · method
Return the length of a partial tool call marker suffix at end of text.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
best
Exceptions and behavior
Method QwenToolParser._get_partial_marker_len calls range, len, tail.endswith; returns best.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser._was_buffering · method
Check if the previous call was buffering a partial marker.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
previous_text |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
self._has_partial_marker(previous_text)
Exceptions and behavior
Method QwenToolParser._was_buffering calls self._has_partial_marker; returns self._has_partial_marker(previous_text).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.extract_tool_calls_streaming · method
vllm_mlx.tool_parsers.qwen_tool_parser.QwenToolParser.extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] | None = None, current_token_ids: Sequence[int] | None = None, delta_token_ids: Sequence[int] | None = None, request: dict[str, Any] | None = None) -> dict[str, Any] | None
Extract tool calls from streaming Qwen model output.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
previous_text |
str |
yes |
none |
Required positional or keyword input. |
current_text |
str |
yes |
none |
Required positional or keyword input. |
delta_text |
str |
yes |
none |
Required positional or keyword input. |
previous_token_ids |
Sequence[int] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
current_token_ids |
Sequence[int] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
delta_token_ids |
Sequence[int] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
request |
dict[str, Any] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
dict[str, Any] | None - Direct return expressions:
{'content': delta_text[:safe_chars]};None;{'content': prefix + delta_text};{'content': delta_text};{'tool_calls': [{'index': prev_func_close + i, 'id': tc['id'], 'type': 'function', 'function': {'name': tc['name'], 'ar…;{'tool_calls': [{'index': i, 'id': tc['id'], 'type': 'function', 'function': {'name': tc['name'], 'arguments': tc['argu…
Exceptions and behavior
Method QwenToolParser.extract_tool_calls_streaming calls self._has_partial_marker, self._get_partial_marker_len, len, self._was_buffering; has 6 explicit return paths.
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
_parse_param_value |
function | _parse_param_value(val: str) -> Any |
Parse a parameter value, handling JSON literals and plain strings. | #L25-L40 |
generate_tool_id |
function | generate_tool_id() -> str |
Generate a unique tool call ID. | #L43-L45 |
QwenToolParser |
class | QwenToolParser() |
Tool call parser for Qwen models. | #L49-L351 |
QwenToolParser.extract_tool_calls |
method | QwenToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] \| None = None) -> ExtractedToolCallInformation |
Extract tool calls from a complete Qwen model response. | #L78-L197 |
QwenToolParser._strip_unclosed_markup |
method | QwenToolParser._strip_unclosed_markup(text: str) -> str |
Strip a trailing unclosed tool-call marker (truncated output). | #L200-L228 |
QwenToolParser._has_partial_marker |
method | QwenToolParser._has_partial_marker(text: str) -> bool |
Check if text ends with an incomplete tool call marker prefix. | #L235-L237 |
QwenToolParser._get_partial_marker_len |
method | QwenToolParser._get_partial_marker_len(text: str) -> int |
Return the length of a partial tool call marker suffix at end of text. | #L239-L248 |
QwenToolParser._was_buffering |
method | QwenToolParser._was_buffering(previous_text: str) -> bool |
Check if the previous call was buffering a partial marker. | #L250-L252 |
QwenToolParser.extract_tool_calls_streaming |
method | QwenToolParser.extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] \| None = None, current_token_ids: Sequence[int] \| None = None, delta_token_ids: Sequence[int] \| None = None, request: dict[str, Any] \| None = None) -> dict[str, Any] \| None |
Extract tool calls from streaming Qwen model output. | #L254-L351 |