Native support for tekken/mistral #363
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Mistral Tokenizer Support for Tool Calling
Summary
This PR adds basic support for Mistral tokenizers in MLX-LM, with a focus on tool calling functionality. The implementation includes optional
mistral-commonintegration and practical examples to help users work with Mistral models for function calling.Changes Made
Core Tokenizer Integration
mistral-commonas an optional dependencyapply_chat_template()with automatic OpenAI-to-Mistral format conversionMistralStreamingDetokenizerfor proper special token handlingExamples and Documentation
mistral_tool_use.py: Multi-turn tool calling example with weather and math functionsmistral_parallel_tool_use.py: Example showing parallel tool callsKey Features
[TOOL_CALLS]format with robust parsingmistral-commoninstalledtekken.jsonfile along with the model filesUsage Example
Dependencies
Added optional
mistralextra insetup.py:pip install mlx-lm[mistral] # Includes mistral-commonFiles Modified
mlx_lm/tokenizer_utils.py- Core tokenizer wrapper enhancementsmlx_lm/examples/mistral_*.py- New tool calling examplesTOOL_CALLING_TUTORIAL.md- Tutorial documentationsetup.py- Optional mistral dependencyThis is a first step toward better Mistral integration in MLX-LM. The implementation is straightforward but should provide a good foundation for users wanting to experiment with Mistral tool calling.