Repository navigation
Conversation
- GemmaFunctionParser: support both Gemma 3 (<start_function_call>)
and Gemma 4 (<|tool_call>) tag formats with correct escape markers
- ToolCallFormat: use hasPrefix("gemma") to match all gemma variants
- Update test to use Gemma 4 format tags
| public let startTag: String? = "<start_function_call>" | ||
| public let endTag: String? = "<end_function_call>" | ||
| // Gemma 4 format tags (primary, as Gemma 4 is the current model) | ||
| public let startTag: String? = "<|tool_call>" |
There was a problem hiding this comment.
Changing startTag to only the Gemma 4 marker breaks streamed Gemma 3 tool calls. ToolCallProcessor uses parser.startTag as the sole trigger, so <start_function_call>...<end_function_call> output will now pass through as regular text even though parse(content:) can handle it directly. Since this PR also maps gemma3/gemma3n to .gemma, please either keep streaming detection compatible with both start tags or split Gemma 3 and Gemma 4 into distinct parser formats.
| var stripped = text | ||
| stripped = stripped.replacingOccurrences(of: Self.gemma3StartTag, with: "") | ||
| stripped = stripped.replacingOccurrences(of: Self.gemma3EndTag, with: "") | ||
| return (false, stripped) |
There was a problem hiding this comment.
This fallback mis-detects unterminated Gemma 4 calls during processEOS(). The default ToolCallParser.parseEOS splits the buffer on startTag before calling parse, so a buffered value like <|tool_call>call:search{query:<|"|>hello, world<|"|>} reaches detectFormat without either Gemma 4 wrapper tag. It then falls back to the Gemma 3 escape marker and splits the escaped string at the comma. Please override parseEOS for Gemma or otherwise preserve the detected Gemma 4 format after splitting.
aleroot
left a comment
There was a problem hiding this comment.
Thanks for adding this. I’m interested in Gemma 4 tool calling support as well, and the general direction looks good. I think this needs a couple of adjustments before merging. Once those are covered with processor-level regression tests for both formats, this should be merged.
|
I've addressed the parsing problems in this library in Swift LM Response Parser, which parses reasoning and tool-use output from all models implemented in MLX Swift LM and emits a stream of Open Responses events. I created a demo of it in this PR in MLX Swift Examples and submitted a proposal for how it could be used with MLX Swift LM. If you're able to test it for your use case, please post your feedback here or in an issue in the repo. |
Integrate an isolated non-serving model correction with its regression assertions. Preserve concurrent main changes and promote the resolved recording checks to ordinary assertions. No deployment or serving dependency update.
GemmaFunctionParserfor both Gemma 3 (<start_function_call>/<end_function_call>) and Gemma 4 (<|tool_call>/<tool_call|>) formatsToolCallFormat.infer()to usehasPrefix("gemma")instead of exact match, enabling tool calling forgemma2,gemma3,gemma3n,gemma4,gemma4_textmodel variants