improved gemma toolcall handling

This commit is contained in:
Concedo 2026-04-25 09:51:29 +08:00
parent 4e07c90eca
commit 4090400dff

View file

@ -3346,10 +3346,11 @@ def toolcall_to_normalized_json(text,start_tag,end_tag): #convert weird formats
def parse_gemma4(text: str) -> str:
if text.startswith("call:"):
text = text[len("call:"):]
text = text.replace('<|"|>', '!$$REAL_QUOTE$$!')
text = text.replace('\\', '\\\\')
text = text.replace('"', '\\"')
text = text.replace('!$$REAL_QUOTE$$!','"')
if '<|"|>' in text:
text = text.replace('<|"|>', '!$$REAL_QUOTE$$!')
text = text.replace('\\', '\\\\')
text = text.replace('"', '\\"')
text = text.replace('!$$REAL_QUOTE$$!','"')
fn_match = re.match(r'^([a-zA-Z_][a-zA-Z0-9_]*)\{(.*)\}$', text.strip(), re.DOTALL) # extract fn name
if not fn_match:
return text