33
44from mlx_lm .tool_parsers import (
55 function_gemma ,
6+ gemma4 ,
67 glm47 ,
78 json_tools ,
89 kimi_k2 ,
@@ -18,6 +19,7 @@ class TestToolParsing(unittest.TestCase):
1819 def test_parsers (self ):
1920 test_cases = [
2021 ("call:multiply{a:12234585,b:48838483920}" , function_gemma ),
22+ ("call:multiply{a:12234585,b:48838483920}" , gemma4 ),
2123 (
2224 '{"name": "multiply", "arguments": {"a": 12234585, "b": 48838483920}}' ,
2325 glm47 ,
@@ -89,6 +91,10 @@ def test_parsers(self):
8991 "call:get_current_temperature{location:<escape>London<escape>}" ,
9092 function_gemma ,
9193 ),
94+ (
95+ 'call:get_current_temperature{location:<|"|>London<|"|>}' ,
96+ gemma4 ,
97+ ),
9298 (
9399 'get_current_temperature<arg_key>location</arg_key><arg_value>"London"</arg_value>' ,
94100 glm47 ,
@@ -191,6 +197,31 @@ def test_qwen3_coder_single_quoted_params(self):
191197 self .assertEqual (tool_call ["arguments" ]["filters" ], {"category" : "books" })
192198 self .assertEqual (tool_call ["arguments" ]["tags" ], ["fiction" , "new" ])
193199
200+ def test_gemma4 (self ):
201+ # Nested object
202+ test_case = 'call:configure{settings:{enabled:true,name:<|"|>test<|"|>}}'
203+ tool_call = gemma4 .parse_tool_call (test_case , None )
204+ self .assertEqual (tool_call ["name" ], "configure" )
205+ self .assertEqual (
206+ tool_call ["arguments" ],
207+ {"settings" : {"enabled" : True , "name" : "test" }},
208+ )
209+
210+ # Array of strings
211+ test_case = 'call:tag{items:[<|"|>foo<|"|>,<|"|>bar<|"|>]}'
212+ tool_call = gemma4 .parse_tool_call (test_case , None )
213+ self .assertEqual (tool_call ["name" ], "tag" )
214+ self .assertEqual (tool_call ["arguments" ], {"items" : ["foo" , "bar" ]})
215+
216+ # Mixed types
217+ test_case = 'call:search{query:<|"|>hello world<|"|>,limit:10,verbose:false}'
218+ tool_call = gemma4 .parse_tool_call (test_case , None )
219+ self .assertEqual (tool_call ["name" ], "search" )
220+ self .assertEqual (
221+ tool_call ["arguments" ],
222+ {"query" : "hello world" , "limit" : 10 , "verbose" : False },
223+ )
224+
194225 def test_kimi_k2 (self ):
195226 # Single tool call
196227 test_case = (
0 commit comments