fix: Handle stray quotes in tag names and enforce parameter tags in prompt

This commit is contained in:
0xallam
2026-02-20 08:26:44 -08:00
committed by Ahmed Allam
parent b9dcf7f63d
commit 027cea2f25
2 changed files with 12 additions and 7 deletions
+4 -7
View File
@@ -6,8 +6,7 @@ from typing import Any
_INVOKE_OPEN = re.compile(r'<invoke\s+name=["\']([^"\']+)["\']>')
_PARAM_NAME_ATTR = re.compile(r'<parameter\s+name=["\']([^"\']+)["\']>')
_FUNCTION_CALLS_TAG = re.compile(r"</?function_calls>")
_QUOTED_FUNCTION = re.compile(r"""<function\s*=\s*['"]([^"']+)['"]\s*>""")
_QUOTED_PARAMETER = re.compile(r"""<parameter\s*=\s*['"]([^"']+)['"]\s*>""")
_STRIP_TAG_QUOTES = re.compile(r"<(function|parameter)\s*=\s*([^>]*?)>")
def normalize_tool_format(content: str) -> str:
@@ -27,11 +26,9 @@ def normalize_tool_format(content: str) -> str:
content = _PARAM_NAME_ATTR.sub(r"<parameter=\1>", content)
content = content.replace("</invoke>", "</function>")
content = _QUOTED_FUNCTION.sub(r"<function=\1>", content)
content = _QUOTED_PARAMETER.sub(r"<parameter=\1>", content)
content = re.sub(r"<function=\s+", "<function=", content)
return re.sub(r"<parameter=\s+", "<parameter=", content)
return _STRIP_TAG_QUOTES.sub(
lambda m: f"<{m.group(1)}={m.group(2).strip().strip(chr(34) + chr(39))}>", content
)
STRIX_MODEL_MAP: dict[str, str] = {