[Bugfix] Handle parenthesized Gemma4 tool calls (#53657)
Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
This commit is contained in:
+10
-1
@@ -285,7 +285,7 @@ def _parse_gemma4_array(arr_str: str, *, partial: bool = False) -> list:
|
|||||||
def _gemma4_arg_converter(raw_args: str, partial: bool) -> str:
|
def _gemma4_arg_converter(raw_args: str, partial: bool) -> str:
|
||||||
"""Convert Gemma4 custom arg format to a JSON string."""
|
"""Convert Gemma4 custom arg format to a JSON string."""
|
||||||
text = raw_args.strip()
|
text = raw_args.strip()
|
||||||
if text.endswith("}"):
|
if text.endswith("}") or text.endswith(")") and text.count("(") < text.count(")"):
|
||||||
text = text[:-1]
|
text = text[:-1]
|
||||||
|
|
||||||
parsed = _parse_gemma4_args(text, partial=partial)
|
parsed = _parse_gemma4_args(text, partial=partial)
|
||||||
@@ -304,6 +304,7 @@ def gemma4_config() -> ParserEngineConfig:
|
|||||||
"TOOL_END": TOOL_CALL_END,
|
"TOOL_END": TOOL_CALL_END,
|
||||||
"CALL_PREFIX": "call:",
|
"CALL_PREFIX": "call:",
|
||||||
"OPEN_BRACE": "{",
|
"OPEN_BRACE": "{",
|
||||||
|
"OPEN_PAREN": "(",
|
||||||
},
|
},
|
||||||
token_id_terminals={
|
token_id_terminals={
|
||||||
"THINK_START": CHANNEL_START,
|
"THINK_START": CHANNEL_START,
|
||||||
@@ -351,6 +352,14 @@ def gemma4_config() -> ParserEngineConfig:
|
|||||||
ParserState.TOOL_ARGS,
|
ParserState.TOOL_ARGS,
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
|
(ParserState.TOOL_NAME, "OPEN_PAREN"): Transition(
|
||||||
|
ParserState.TOOL_ARGS,
|
||||||
|
(),
|
||||||
|
),
|
||||||
|
(ParserState.TOOL_NAME, "TOOL_END"): Transition(
|
||||||
|
ParserState.CONTENT,
|
||||||
|
(EventType.TOOL_CALL_END,),
|
||||||
|
),
|
||||||
(ParserState.TOOL_ARGS, "TOOL_END"): Transition(
|
(ParserState.TOOL_ARGS, "TOOL_END"): Transition(
|
||||||
ParserState.CONTENT,
|
ParserState.CONTENT,
|
||||||
(EventType.TOOL_CALL_END,),
|
(EventType.TOOL_CALL_END,),
|
||||||
|
|||||||
Reference in New Issue
Block a user