Add Python tool call parser and use it for LFM2 models#93
Add Python tool call parser and use it for LFM2 models#93atdrendel wants to merge 3 commits intoml-explore:mainfrom
Conversation
|
Oh, look at that, I pushed this without realizing that there was a similar pull request already open: #91 I'm fine with either one, of course. Feel free to close this one, if you want. |
There was a problem hiding this comment.
Pull request overview
This pull request adds a PythonToolCallParser to correctly parse LFM2 model outputs, which generate Python-style function calls rather than JSON. Previously, LFM2 models were incorrectly configured to use JSONToolCallParser, which couldn't parse the Python-style syntax, resulting in all tool calls being silently ignored.
Changes:
- Implemented
PythonToolCallParserto parse Python-style function calls with support for both single and double quotes, escape sequences, numeric types, booleans, and null values - Updated
ToolCallFormat.swiftto usePythonToolCallParserinstead ofJSONToolCallParserfor LFM2 format - Replaced outdated LFM2 tests that verified JSON parsing with comprehensive new tests for Python-style parsing
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Libraries/MLXLMCommon/Tool/Parsers/PythonToolCallParser.swift | New parser implementation for Python-style function calls with comprehensive string, number, and type handling |
| Libraries/MLXLMCommon/Tool/ToolCallFormat.swift | Updated LFM2 format to use PythonToolCallParser and corrected comment to reflect Python-style format |
| Tests/MLXLMTests/ToolTests.swift | Removed obsolete JSON-based LFM2 tests and added comprehensive Python-style parser tests covering edge cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
The problem solved by this pull request has already been addressed by #91. So, I'll close this one. |
Proposed changes
LFM2 models write LFM2 writes Pythonic function calls, not JSON tool calls. This pull request adds
PythonToolCallParserand uses it for LFM2 models.Before these changes were applied
Prior to these changes,
testLFM2EndToEndToolCallGenerationalways succeeded, but it succeeded becausetoolCallswas always empty sinceJSONToolCallParsercould never parse the tool calls.After these changes are applied
Now,
testLFM2EndToEndToolCallGenerationsucceeds and does recognize the tool calls correctly. Here's the output of one of the runs I did on my Mac.Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes