Commit 72917a8a authored by Your Name's avatar Your Name

Fix: Parse JSON object inside <tool> tags

- Add pattern for <tool>{JSON}</tool> format
- Handles: <tool>{"name": "web_search", "arguments": {...}}</tool>
parent 625ea1d8
......@@ -1273,6 +1273,28 @@ class ToolCallParser:
}
})
# NEW: Pattern for <tool>{JSON}</tool> format
# Example: <tool>{"name": "web_search", "arguments": {"query": "test"}}</tool>
pattern_json_in_tool = r'<tool>\s*(\{.*?\})\s*</tool>'
matches_json_in_tool = re.findall(pattern_json_in_tool, text, re.DOTALL)
for json_str in matches_json_in_tool:
try:
data = json.loads(json_str.strip())
name = data.get('name') or data.get('function')
args = data.get('arguments') or data.get('args') or {}
if name:
tool_calls.append({
"id": f"call_{uuid.uuid4().hex[:16]}",
"type": "function",
"function": {
"name": name,
"arguments": json.dumps(args)
}
})
except json.JSONDecodeError:
pass
# NEW: Pattern for <tool_call><tool>TOOL_NAME>JSON</tool></tool_call>
# Example: <tool_call><tool>financial_data_fetcher>{"ticker": "MSFT"}</tool></tool_call>
pattern_short2 = r'<tool_call>\s*<tool>(\w+)>\s*(\{.*?\})\s*</tool>\s*</tool_call>'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment