vllm_mlx.tool_parsers.gemma4_tool_parser¶
Gemma 4 tool call parser for vllm-mlx.
View the complete module source at #L1-L513.
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.gemma4_tool_parser
¶
Gemma 4 tool call parser for vllm-mlx.
Handles Gemma 4's native tool call format:
<|tool_call>call:func_name{<|"|>key<|"|>: <|"|>value<|"|>, num: 42}
Gemma 4 uses special tokens instead of JSON:
- <|tool_call> /
Fallback forms (issue #80): under long system prompts + multi-turn + several
tools, Gemma 4 frequently abandons the canonical brace form and instead emits
its call as plain text in content, using Python-style call syntax:
e4b: <|tool_call>call:radarr_get_movies(search="Dune")
e2b: tool_code
radarr_get_movies(search="Dune")
e2b: tool_code = radarr_get_movies(search="Dune")
print(tool_code)
These are parsed by a fallback layer (ast-based) when the canonical parse finds no calls, so the host can still dispatch the tool.
Reference: mlx-lm PR #1105, vllm PR #38837
vllm_mlx.tool_parsers.gemma4_tool_parser.logger
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser.TOOL_CALL_START
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser.TOOL_CALL_END
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._PLACEHOLDER_RE
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._STRING_DELIM_RE
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._CALL_PREFIX
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._BARE_KEY
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._BARE_VALUE
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._JSON_LITERALS
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._MAX_ARG_BLOCK_LEN
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._CALL_PAREN_RE
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._TOOL_CODE_FENCE_RE
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._TOOL_CODE_ASSIGN_RE
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser._FALLBACK_MARKER_RE
module-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser
¶
Bases: ToolParser
Tool call parser for Gemma 4 models.
Parses: <|tool_call>call:func{<|"|>key<|"|>: <|"|>val<|"|>}
Used when --enable-auto-tool-choice --tool-call-parser gemma4 are set.
Source code in vllm_mlx/tool_parsers/abstract_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser.extra_stop_tokens
class-attribute
instance-attribute
¶
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser.extract_tool_calls
¶
extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
Extract tool calls from a complete Gemma 4 model response.
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser._extract_canonical
¶
Parse the canonical <|tool_call>call:fn{...}
Returns (tool_calls, content_before). tool_calls is empty when the canonical markers/braces aren't present.
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser._extract_fallback
¶
_extract_fallback(cleaned: str) -> ExtractedToolCallInformation | None
Parse the Python-style fallback forms (issue #80).
Handles tool_code blocks (bare fn(...) calls) and the
parenthesized call:fn(...) form. Returns None if neither is present.
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser._format_streaming
¶
_format_streaming(result: ExtractedToolCallInformation) -> dict[str, Any]
Render extracted tool calls into the streaming delta shape.
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser.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 Gemma 4 model output.
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser._find_balanced_brace
¶
Find the index of the closing } that balances the { at start.
Before counting braces, <|"|>-delimited strings are conceptually opaque -- we skip over <|"|>...<|"|> regions so that braces inside string values (e.g. code snippets) don't affect depth counting.
Parameters:
-
text(str) –The string to search (may contain <|"|> tokens)
-
start(int) –Index of the opening {
Returns:
-
int–Index of the matching } in the ORIGINAL text, or -1 if not found
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser._find_balanced_paren
¶
Find the index of the closing ) that balances the ( at start.
Python string literals ('...'/"...") are treated as opaque so that parens inside string argument values don't affect depth counting.
Returns the index of the matching ) in text, or -1 if not found.
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser._quote_bare_value
¶
Substitution callback for _BARE_VALUE — quotes bare identifiers that are not JSON literals (true/false/null).
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser._gemma4_args_to_json
¶
Convert Gemma 4 tool call args to valid JSON.
Four-step conversion (ORDER MATTERS): 1. Extract <|"|>-delimited strings into numbered \x00N\x00 placeholders. This protects string contents from step 2's bare-key quoting -- without this, a string value like "key: value" would be corrupted. 2. Quote bare keys (word: -> "word":) now that strings are safe. 3. Quote bare string VALUES that the template emitted without <|"|> wrappers. Happens with nullable/enum schemas where the STRING branch of the template isn't taken. 4. Restore placeholders as properly JSON-escaped strings via json.dumps(). Uses a single re.sub pass (O(len(text))) instead of per-placeholder replace.
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser._call_node_to_tool
¶
Map a Python ast.Call node to (function_name, kwargs_dict).
Only keyword arguments are mapped (Gemma emits its tool calls as kwargs); positional args are ignored because the parameter names aren't recoverable. Returns None if the name or any argument value isn't a plain literal.
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser._parse_python_call
¶
Parse a single fn(...) Python call expression into (name, kwargs).
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser._parse_calls_from_code
¶
Parse every top-level fn(...) call statement in a code-fence body.
Source code in vllm_mlx/tool_parsers/gemma4_tool_parser.py
vllm_mlx.tool_parsers.gemma4_tool_parser._strip_spans
¶
Remove the given [start, end) spans from text (handles overlaps).
Source code in vllm_mlx/tool_parsers/gemma4_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.gemma4_tool_parser._find_balanced_brace · function
Find the index of the closing } that balances the { at start.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
The string to search (may contain <|"|> tokens) |
start |
int |
yes |
none |
Index of the opening { |
Returns
- Type:
int - Direct return expressions:
-1;i
Exceptions and behavior
Function _find_balanced_brace calls len, text.startswith; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser._find_balanced_paren · function
Find the index of the closing ) that balances the ( at start.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Required positional or keyword input. |
start |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
-1;i
Exceptions and behavior
Function _find_balanced_paren calls len; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser._quote_bare_value · function
Substitution callback for _BARE_VALUE — quotes bare identifiers that are not JSON literals (true/false/null).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
m |
re.Match |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
m.group(0);f'{ws}"{word}"'
Exceptions and behavior
Function _quote_bare_value calls m.group; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser._gemma4_args_to_json · function
Convert Gemma 4 tool call args to valid JSON.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
text
Exceptions and behavior
Function _gemma4_args_to_json calls _STRING_DELIM_RE.sub, _BARE_KEY.sub, _BARE_VALUE.sub, _PLACEHOLDER_RE.sub; returns text.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser._gemma4_args_to_json._capture · nested function
Nested Function _gemma4_args_to_json._capture calls strings.append, m.group, len; returns f'\x00{len(strings) - 1}\x00'.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
m |
re.Match |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
f'\x00{len(strings) - 1}\x00'
Exceptions and behavior
Nested Function _gemma4_args_to_json._capture calls strings.append, m.group, len; returns f'\x00{len(strings) - 1}\x00'.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser._gemma4_args_to_json._restore · nested function
Nested Function _gemma4_args_to_json._restore calls int, m.group, len, json.dumps; returns json.dumps(strings[idx]) if idx < len(strings) else m.group(0).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
m |
re.Match |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
json.dumps(strings[idx]) if idx < len(strings) else m.group(0)
Exceptions and behavior
Nested Function _gemma4_args_to_json._restore calls int, m.group, len, json.dumps; returns json.dumps(strings[idx]) if idx < len(strings) else m.group(0).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser._call_node_to_tool · function
vllm_mlx.tool_parsers.gemma4_tool_parser._call_node_to_tool(call: ast.Call) -> tuple[str, dict[str, Any]] | None
Map a Python ast.Call node to (function_name, kwargs_dict).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
call |
ast.Call |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
tuple[str, dict[str, Any]] | None - Direct return expressions:
None;(name, args)
Exceptions and behavior
Function _call_node_to_tool calls isinstance, ast.literal_eval; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser._parse_python_call · function
vllm_mlx.tool_parsers.gemma4_tool_parser._parse_python_call(src: str) -> tuple[str, dict[str, Any]] | None
Parse a single fn(...) Python call expression into (name, kwargs).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
src |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
tuple[str, dict[str, Any]] | None - Direct return expressions:
None;_call_node_to_tool(node.body)
Exceptions and behavior
Function _parse_python_call calls ast.parse, src.strip, isinstance, _call_node_to_tool; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser._parse_calls_from_code · function
vllm_mlx.tool_parsers.gemma4_tool_parser._parse_calls_from_code(code: str) -> list[tuple[str, dict[str, Any]]]
Parse every top-level fn(...) call statement in a code-fence body.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
code |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[tuple[str, dict[str, Any]]] - Direct return expressions:
results
Exceptions and behavior
Function _parse_calls_from_code calls ast.parse, textwrap.dedent(code).strip, textwrap.dedent, isinstance; returns results.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser._strip_spans · function
vllm_mlx.tool_parsers.gemma4_tool_parser._strip_spans(text: str, spans: list[tuple[int, int]]) -> str
Remove the given [start, end) spans from text (handles overlaps).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
text |
str |
yes |
none |
Required positional or keyword input. |
spans |
list[tuple[int, int]] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
text;''.join(out)
Exceptions and behavior
Function _strip_spans calls sorted, max, out.append, ''.join; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_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.gemma4_tool_parser.Gemma4ToolParser · class
Tool call parser for Gemma 4 models.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser
Exceptions and behavior
Class Gemma4ToolParser derives from ToolParser and declares 5 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser.extract_tool_calls · method
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
Extract tool calls from a complete Gemma 4 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=content_before);fallback;ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=model_output)
Exceptions and behavior
Method Gemma4ToolParser.extract_tool_calls calls self.strip_think_tags, self._extract_canonical, ExtractedToolCallInformation, self._extract_fallback; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser._extract_canonical · method
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser._extract_canonical(cleaned: str) -> tuple[list[dict[str, Any]], str | None]
Parse the canonical <|tool_call>call:fn{...}
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cleaned |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
tuple[list[dict[str, Any]], str | None] - Direct return expressions:
([], None);(tool_calls, content_before)
Exceptions and behavior
Method Gemma4ToolParser._extract_canonical calls cleaned.find, cleaned[:start_idx].strip, len, _CALL_PREFIX.search; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser._extract_fallback · method
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser._extract_fallback(cleaned: str) -> ExtractedToolCallInformation | None
Parse the Python-style fallback forms (issue #80).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cleaned |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
ExtractedToolCallInformation | None - Direct return expressions:
None;ExtractedToolCallInformation(tools_called=True, tool_calls=tool_calls, content=content)
Exceptions and behavior
Method Gemma4ToolParser._extract_fallback calls _TOOL_CODE_FENCE_RE.finditer, _parse_calls_from_code, m.group, tool_calls.append; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser._format_streaming · method
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser._format_streaming(result: ExtractedToolCallInformation) -> dict[str, Any]
Render extracted tool calls into the streaming delta shape.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
result |
ExtractedToolCallInformation |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, Any] - Direct return expressions:
{'tool_calls': [{'index': i, 'id': tc['id'], 'type': 'function', 'function': {'name': tc['name'], 'arguments': tc['argu…
Exceptions and behavior
Method Gemma4ToolParser._format_streaming calls enumerate; returns {'tool_calls': [{'index': i, 'id': tc['id'], 'type': 'function', 'function': {'name': tc['name'], 'arguments': tc['argu….
No direct raise statement appears in this definition.
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser.extract_tool_calls_streaming · method
vllm_mlx.tool_parsers.gemma4_tool_parser.Gemma4ToolParser.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 Gemma 4 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};self._format_streaming(result);None
Exceptions and behavior
Method Gemma4ToolParser.extract_tool_calls_streaming calls bool, _FALLBACK_MARKER_RE.search, self.extract_tool_calls, self._format_streaming; has 3 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 |
|---|---|---|---|---|
_find_balanced_brace |
function | _find_balanced_brace(text: str, start: int) -> int |
Find the index of the closing } that balances the { at start. |
#L92-L125 |
_find_balanced_paren |
function | _find_balanced_paren(text: str, start: int) -> int |
Find the index of the closing ) that balances the ( at start. |
#L128-L159 |
_quote_bare_value |
function | _quote_bare_value(m: re.Match) -> str |
Substitution callback for _BARE_VALUE — quotes bare identifiers that are not JSON literals (true/false/null). | #L162-L168 |
_gemma4_args_to_json |
function | _gemma4_args_to_json(text: str) -> str |
Convert Gemma 4 tool call args to valid JSON. | #L171-L207 |
_gemma4_args_to_json._capture |
nested function | _gemma4_args_to_json._capture(m: re.Match) -> str |
Nested Function _gemma4_args_to_json._capture calls strings.append, m.group, len; returns f'\x00{len(strings) - 1}\x00'. |
#L187-L189 |
_gemma4_args_to_json._restore |
nested function | _gemma4_args_to_json._restore(m: re.Match) -> str |
Nested Function _gemma4_args_to_json._restore calls int, m.group, len, json.dumps; returns json.dumps(strings[idx]) if idx < len(strings) else m.group(0). |
#L201-L203 |
_call_node_to_tool |
function | _call_node_to_tool(call: ast.Call) -> tuple[str, dict[str, Any]] \| None |
Map a Python ast.Call node to (function_name, kwargs_dict). |
#L210-L233 |
_parse_python_call |
function | _parse_python_call(src: str) -> tuple[str, dict[str, Any]] \| None |
Parse a single fn(...) Python call expression into (name, kwargs). |
#L236-L244 |
_parse_calls_from_code |
function | _parse_calls_from_code(code: str) -> list[tuple[str, dict[str, Any]]] |
Parse every top-level fn(...) call statement in a code-fence body. |
#L247-L259 |
_strip_spans |
function | _strip_spans(text: str, spans: list[tuple[int, int]]) -> str |
Remove the given [start, end) spans from text (handles overlaps). |
#L262-L275 |
generate_tool_id |
function | generate_tool_id() -> str |
Generate a unique tool call ID. | #L278-L280 |
Gemma4ToolParser |
class | Gemma4ToolParser() |
Tool call parser for Gemma 4 models. | #L284-L513 |
Gemma4ToolParser.extract_tool_calls |
method | Gemma4ToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] \| None = None) -> ExtractedToolCallInformation |
Extract tool calls from a complete Gemma 4 model response. | #L300-L324 |
Gemma4ToolParser._extract_canonical |
method | Gemma4ToolParser._extract_canonical(cleaned: str) -> tuple[list[dict[str, Any]], str \| None] |
Parse the canonical <|tool_call>call:fn{...} |
#L326-L382 |
Gemma4ToolParser._extract_fallback |
method | Gemma4ToolParser._extract_fallback(cleaned: str) -> ExtractedToolCallInformation \| None |
Parse the Python-style fallback forms (issue #80). | #L384-L463 |
Gemma4ToolParser._format_streaming |
method | Gemma4ToolParser._format_streaming(result: ExtractedToolCallInformation) -> dict[str, Any] |
Render extracted tool calls into the streaming delta shape. | #L465-L480 |
Gemma4ToolParser.extract_tool_calls_streaming |
method | Gemma4ToolParser.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 Gemma 4 model output. | #L482-L513 |