easydel.inference.tools.parsers.glm4_moe_tool_parser#

class easydel.inference.tools.parsers.glm4_moe_tool_parser.Glm4MoeModelToolParser(tokenizer: AutoTokenizer)[source]#

Bases: ToolParser

Tool parser for GLM-4 MoE (Mixture of Experts) models.

Handles the GLM-4 specific tool call format which uses XML-like tags: - Tool calls wrapped in <tool_call> and </tool_call> - Arguments wrapped in <arg_key> and <arg_value> tags - Supports automatic type conversion based on tool parameter definitions

The parser maintains streaming state and can handle incremental generation of tool calls during streaming responses.

extract_tool_calls(model_output: str, request: ChatCompletionRequest) ExtractedToolCallInformation[source]#

Extract tool calls from complete GLM-4 model output.

Parses XML-like structured format with tool names and key-value argument pairs. Automatically deserializes argument values based on tool parameter type definitions.

Parameters
  • model_output – Complete text from the model

  • request – Chat request containing tool definitions

Returns

Extracted tool call information with parsed functions

extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int], current_token_ids: Sequence[int], delta_token_ids: Sequence[int], request: ChatCompletionRequest) easydel.inference.openai_api_modules.DeltaMessage | None[source]#

Handle streaming extraction of GLM-4 tool calls.

Uses a buffer-based approach to accumulate partial tool calls and emit complete tool information when boundaries are detected.

Parameters
  • previous_text – Previously generated text

  • current_text – All text generated so far

  • delta_text – New text in this chunk

  • previous_token_ids – Previous token IDs

  • current_token_ids – All token IDs

  • delta_token_ids – New token IDs

  • request – Original request

Returns

Delta message with tool updates or None