# `vllm_mlx.tool_parsers.glm47_tool_parser`

GLM-4.7 tool call parser for vllm-mlx.

[View the complete module source at #L1-L184](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L1-L184).

## 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.glm47_tool_parser
    options:
      members:
        - generate_tool_id
        - Glm47ToolParser
      filters: []
      show_if_no_docstring: true

## 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.

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.glm47_tool_parser.generate_tool_id" markdown="1">
<summary><code>vllm_mlx.tool_parsers.glm47_tool_parser.generate_tool_id</code> · function</summary>

```python
vllm_mlx.tool_parsers.glm47_tool_parser.generate_tool_id() -> str
```

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.

[View source #L22-L24](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L22-L24).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser" markdown="1">
<summary><code>vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser</code> · class</summary>

```python
vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser()
```

Tool call parser for GLM-4.7 and GLM-4.7-Flash models.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Constructs: `vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser`

**Exceptions and behavior**

Class `Glm47ToolParser` derives from `ToolParser` and declares 4 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L28-L184](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L28-L184).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser._deserialize" markdown="1">
<summary><code>vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser._deserialize</code> · method</summary>

```python
vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser._deserialize(value: str) -> Any
```

Convert string value to appropriate Python type.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `Any`
- Direct return expressions: `json.loads(value)`; `value`

**Exceptions and behavior**

Method `Glm47ToolParser._deserialize` calls `value.strip`, `json.loads`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L57-L67](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L57-L67).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser._get_tool_names" markdown="1">
<summary><code>vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser._get_tool_names</code> · method</summary>

```python
vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser._get_tool_names(request: dict[str, Any] | None) -> set[str]
```

Extract valid tool names from the request.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `request` | `dict[str, Any] \| None` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `set[str]`
- Direct return expressions: `set()`; `{t.get('function', {}).get('name', '') for t in request.get('tools', []) if isinstance(t, dict)}`

**Exceptions and behavior**

Method `Glm47ToolParser._get_tool_names` calls `set`, `t.get('function', {}).get`, `t.get`, `request.get`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L69-L77](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L69-L77).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser.extract_tool_calls" markdown="1">
<summary><code>vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser.extract_tool_calls</code> · method</summary>

```python
vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
```

Extract tool calls from a complete GLM-4.7 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=None)`; `ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=cleaned_text)`

**Exceptions and behavior**

Method `Glm47ToolParser.extract_tool_calls` calls `self.strip_think_tags`, `self._get_tool_names`, `self.FUNC_DETAIL_PATTERN.findall`, `match[0].strip`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L79-L137](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L79-L137).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser.extract_tool_calls_streaming" markdown="1">
<summary><code>vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser.extract_tool_calls_streaming</code> · method</summary>

```python
vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser.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 GLM-4.7 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: `None`; `{'tool_calls': [{'index': i, 'id': tc['id'], 'type': 'function', 'function': {'name': tc['name'], 'arguments': tc['argu…`; `{'content': clean_delta}`

**Exceptions and behavior**

Method `Glm47ToolParser.extract_tool_calls_streaming` calls `self.extract_tool_calls`, `enumerate`, `self.strip_think_tags`; has 3 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L139-L184](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L139-L184).

</details>

## 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 |
| --- | --- | --- | --- | --- |
| [`generate_tool_id`](#contract-vllm_mlx.tool_parsers.glm47_tool_parser.generate_tool_id) | function | `generate_tool_id() -> str` | Generate a unique tool call ID. | [#L22-L24](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L22-L24) |
| [`Glm47ToolParser`](#contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser) | class | `Glm47ToolParser()` | Tool call parser for GLM-4.7 and GLM-4.7-Flash models. | [#L28-L184](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L28-L184) |
| [`Glm47ToolParser._deserialize`](#contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser._deserialize) | method | `Glm47ToolParser._deserialize(value: str) -> Any` | Convert string value to appropriate Python type. | [#L57-L67](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L57-L67) |
| [`Glm47ToolParser._get_tool_names`](#contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser._get_tool_names) | method | `Glm47ToolParser._get_tool_names(request: dict[str, Any] \| None) -> set[str]` | Extract valid tool names from the request. | [#L69-L77](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L69-L77) |
| [`Glm47ToolParser.extract_tool_calls`](#contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser.extract_tool_calls) | method | `Glm47ToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] \| None = None) -> ExtractedToolCallInformation` | Extract tool calls from a complete GLM-4.7 model response. | [#L79-L137](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L79-L137) |
| [`Glm47ToolParser.extract_tool_calls_streaming`](#contract-vllm_mlx.tool_parsers.glm47_tool_parser.Glm47ToolParser.extract_tool_calls_streaming) | method | `Glm47ToolParser.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 GLM-4.7 model output. | [#L139-L184](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/glm47_tool_parser.py#L139-L184) |
