easydel.inference.tools.parsers.kimi_k2_tool_parser#
- class easydel.inference.tools.parsers.kimi_k2_tool_parser.KimiK2ToolParser(tokenizer: AutoTokenizer)[source]#
Bases:
ToolParserTool parser for Kimi K2 models.
Handles tool calls with hierarchical token structure: - Tool calls section: <|tool_calls_section_begin|> … <|tool_calls_section_end|> - Individual calls: <|tool_call_begin|> … <|tool_call_end|> - Arguments after <|tool_call_argument_begin|>
Features: - Hierarchical token-based parsing - Tool ID extraction from format: namespace.function:id - Streaming with state tracking for nested structures - Regex patterns for structured extraction
Format: <|tool_calls_section_begin|> <|tool_call_begin|>namespace.function:123<|tool_call_argument_begin|>{…}<|tool_call_end|> <|tool_calls_section_end|>
- 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
- 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
- Raises
NotImplementedError – Must be implemented by subclasses
Note
This method is stateful - it uses instance variables to track parsing progress across streaming chunks.