syntaxhacker commited on
Commit ·
87285c1
1
Parent(s): 8630c76
fix XML tool call parser for malformed key-value pairs
Browse files- app/main.py +7 -7
app/main.py
CHANGED
|
@@ -21,13 +21,13 @@ def parse_xml_tool_calls(content: str) -> list[dict]:
|
|
| 21 |
name = match.group(1)
|
| 22 |
body = match.group(2).strip()
|
| 23 |
args = {}
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
return calls
|
| 32 |
|
| 33 |
# Lazy imports to avoid blocking startup
|
|
|
|
| 21 |
name = match.group(1)
|
| 22 |
body = match.group(2).strip()
|
| 23 |
args = {}
|
| 24 |
+
pair_pattern = r'<longcat_arg_key>(\w+)</longcat_arg_key>\s*(?:<longcat_arg_value>(.*?)</longcat_arg_value>)?'
|
| 25 |
+
for pair_match in re.finditer(pair_pattern, body, re.DOTALL):
|
| 26 |
+
key = pair_match.group(1)
|
| 27 |
+
value = pair_match.group(2)
|
| 28 |
+
if value is not None:
|
| 29 |
+
args[key] = value.strip()
|
| 30 |
+
calls.append({"name": name, **args})
|
| 31 |
return calls
|
| 32 |
|
| 33 |
# Lazy imports to avoid blocking startup
|