easydel.inference.tools.parsers.granite_tool_parser#

class easydel.inference.tools.parsers.granite_tool_parser.GraniteToolParser(tokenizer: AutoTokenizer)[source]#

Bases: ToolParser

Tool call parser for Granite 3.0 models.

Intended for use with the examples/tool_chat_template_granite.jinja template. Handles JSON array format with optional bot tokens.

Features: - Supports <|tool_call|> and <tool_call> token markers - Parses JSON array of tool calls - Handles partial JSON for streaming - Tracks argument completion state

Format: <|tool_call|>[{“name”: “func”, “arguments”: {…}}, …]

Used when –enable-auto-tool-choice –tool-call-parser granite are all set.

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

Extract tool calls from complete model output (batch mode).

Parses the entire model response to identify and extract tool/function calls. This method is used for non-streaming responses where the complete output is available.

Parameters
  • model_output – Complete text generated by the model

  • request – Original request containing tool definitions

Returns

Parsed tool calls and remaining content

Return type

ExtractedToolCallInformation

Raises

NotImplementedError – Must be implemented by subclasses

Note

This method is stateless - it doesn’t use instance state. Each parser implements model-specific extraction logic.

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

Extract tool calls from streaming model output.

Processes incremental model output to identify partial tool calls and emit appropriate streaming updates. Maintains state across calls to handle incomplete JSON/XML structures.

Parameters
  • previous_text – Text accumulated up to previous call

  • current_text – Text accumulated including current chunk

  • delta_text – New text in current chunk

  • previous_token_ids – Token IDs up to previous call

  • current_token_ids – Token IDs including current chunk

  • delta_token_ids – New token IDs in current chunk

  • request – Original request with tool definitions

Returns

Incremental tool call update, or None if no update

Return type

DeltaMessage

Raises

NotImplementedError – Must be implemented by subclasses

Note

This method is stateful - it uses instance variables to track parsing progress across streaming chunks.