fix: MiniMax tool call normalization and thinking block handling

This commit is contained in:
Open Source Contributor 2026-04-18 00:06:56 -06:00
parent 15c95718e6
commit dba1a45c0e
2 changed files with 8 additions and 1 deletions

View file

@ -202,6 +202,13 @@ class LLM:
accumulated = normalize_tool_format(accumulated)
accumulated = fix_incomplete_tool_call(_truncate_to_first_function(accumulated))
thinking_content = ""
for match in re.finditer(r"<thinking[^>]*>(.*?)</thinking>", accumulated, re.DOTALL):
thinking_content += match.group(1) + "\n"
if thinking_content:
accumulated = accumulated.replace(thinking_content, "")
yield LLMResponse(
content=accumulated,
tool_invocations=parse_tool_invocations(accumulated),

View file

@ -20,7 +20,7 @@ def normalize_tool_format(content: str) -> str:
<function="X"> <function=X>
<parameter="X"> <parameter=X>
"""
if "<invoke" in content or "<function_calls" in content:
if "<invoke" in content or "<function_calls" in content or '<parameter name="' in content:
content = _FUNCTION_CALLS_TAG.sub("", content)
content = _INVOKE_OPEN.sub(r"<function=\1>", content)
content = _PARAM_NAME_ATTR.sub(r"<parameter=\1>", content)