easydel.inference.tools.parsers.mistral_tool_parser#
- class easydel.inference.tools.parsers.mistral_tool_parser.MistralToolCall(*, id: str = <factory>, type: str = 'function', function: ~easydel.inference.openai_api_modules.FunctionCall, **extra_data: ~typing.Any)[source]#
Bases:
ToolCall- id: str#
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class easydel.inference.tools.parsers.mistral_tool_parser.MistralToolParser(tokenizer: AutoTokenizer)[source]#
Bases:
ToolParserTool call parser for Mistral models (7B Instruct v0.3+).
Designed for use with: - [mistral_common](mistralai/mistral-common) - the examples/tool_chat_template_mistral.jinja template
Handles Mistral’s specific tool call format with [TOOL_CALLS] token and JSON array of function calls. Supports both standard JSON parsing and regex-based parsing for function names with v11+ tokenizers.
Features: - Automatic tool ID generation (9-character alphanumeric) - Support for multiple tool calls in single response - Streaming with incremental argument parsing - Compatibility with different Mistral tokenizer versions
Used when –enable-auto-tool-choice –tool-call-parser mistral are set.
- adjust_request(request: ChatCompletionRequest) ChatCompletionRequest[source]#
Adjust request parameters for model-specific requirements.
Override this method to modify request parameters like system prompts, tool definitions, or formatting before processing. Default implementation returns the request unchanged.
- Parameters
request – Original chat completion request
- Returns
Potentially modified request
- Return type
Example
Some models may need to reformat tool definitions or add specific system instructions for proper tool calling.
- extract_tool_calls(model_output: str, request: ChatCompletionRequest) ExtractedToolCallInformation[source]#
Extract tool calls from complete Mistral model response.
Parses the [TOOL_CALLS] token followed by JSON array or function call patterns. Handles both standard JSON format and regex-based extraction for newer tokenizer versions.
- Parameters
model_output – Complete model output with tool calls
request – Original request (unused)
- Returns
Extracted tool information with MistralToolCall objects
Note
Tool call arguments should avoid quotes as parser may need to replace single quotes with double quotes.
- 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.