[Bugfix][Tool Parser] Preserve whitespace in parameter values (MiniMax M2, Qwen3, MiniCPM5 XML) (#48846)
Signed-off-by: mosya415 <263250241+mosya415@users.noreply.github.com> Signed-off-by: Ben Browning <56071+bbrowning@users.noreply.github.com> Co-authored-by: mosya415 <263250241+mosya415@users.noreply.github.com> Co-authored-by: Ben Browning <56071+bbrowning@users.noreply.github.com>
This commit is contained in:
co-authored by
mosya415
Ben Browning
parent
877dae9c68
commit
11d291511a
@@ -69,7 +69,9 @@ def _minimax_m2_arg_converter(raw_args: str, partial: bool) -> str:
|
||||
).strip()
|
||||
if not name:
|
||||
continue
|
||||
params[name] = match.group("value").strip()
|
||||
# Keep the value verbatim (like the glm47 converter): it is inline
|
||||
# between `>` and `</parameter>`, so surrounding whitespace is data.
|
||||
params[name] = match.group("value")
|
||||
|
||||
if partial:
|
||||
remaining = _PARAM_RE.sub("", raw_args)
|
||||
@@ -82,7 +84,8 @@ def _minimax_m2_arg_converter(raw_args: str, partial: bool) -> str:
|
||||
or ""
|
||||
).strip()
|
||||
if name:
|
||||
params[name] = match.group("value").strip()
|
||||
# Verbatim, same as the complete-match loop above.
|
||||
params[name] = match.group("value")
|
||||
|
||||
return json.dumps(params, ensure_ascii=False)
|
||||
|
||||
|
||||
+11
-2
@@ -56,13 +56,22 @@ _PARAM_RE = re.compile(
|
||||
_PARTIAL_PARAM_RE = re.compile(r"<\s*parameter\s*=\s*([^>]+)>(.*)$", re.DOTALL)
|
||||
|
||||
|
||||
def _trim_wrapping_newlines(value: str) -> str:
|
||||
"""Strip one leading and one trailing newline (the Qwen3 template markup)."""
|
||||
if value.startswith("\n"):
|
||||
value = value[1:]
|
||||
if value.endswith("\n"):
|
||||
value = value[:-1]
|
||||
return value
|
||||
|
||||
|
||||
def _qwen3_arg_converter(raw_args: str, partial: bool) -> str:
|
||||
params: dict[str, object] = {}
|
||||
|
||||
for match in _PARAM_RE.finditer(raw_args):
|
||||
name = match.group(1)
|
||||
value = match.group(2)
|
||||
params[name] = value.strip()
|
||||
params[name] = _trim_wrapping_newlines(value)
|
||||
|
||||
if partial:
|
||||
remaining = _PARAM_RE.sub("", raw_args)
|
||||
@@ -71,7 +80,7 @@ def _qwen3_arg_converter(raw_args: str, partial: bool) -> str:
|
||||
name = m.group(1)
|
||||
value = m.group(2)
|
||||
if name:
|
||||
params[name] = value.strip()
|
||||
params[name] = _trim_wrapping_newlines(value)
|
||||
|
||||
return json.dumps(params, ensure_ascii=False)
|
||||
|
||||
|
||||
@@ -360,7 +360,7 @@ def _parse_function_block(
|
||||
if not key:
|
||||
has_invalid_param = True
|
||||
break
|
||||
val_text = (param.text or "").strip()
|
||||
val_text = param.text or ""
|
||||
if not _add_argument(
|
||||
func_name or "",
|
||||
key,
|
||||
@@ -392,7 +392,8 @@ def _parse_function_block(
|
||||
val_text = pm.group(2) or ""
|
||||
if val_text.startswith("<![CDATA[") and val_text.endswith("]]>"):
|
||||
val_text = val_text[len("<![CDATA[") : -len("]]>")]
|
||||
val_text = val_text.strip()
|
||||
else:
|
||||
val_text = val_text.strip()
|
||||
if not _add_argument(
|
||||
func_name or "",
|
||||
key,
|
||||
@@ -445,7 +446,8 @@ def _parse_partial_params(
|
||||
val_text = pm.group(2) or ""
|
||||
if val_text.startswith("<![CDATA[") and val_text.endswith("]]>"):
|
||||
val_text = val_text[len("<![CDATA[") : -len("]]>")]
|
||||
val_text = val_text.strip()
|
||||
else:
|
||||
val_text = val_text.strip()
|
||||
_add_argument(
|
||||
func_name,
|
||||
key,
|
||||
|
||||
Reference in New Issue
Block a user