Commit 8988356b authored by Your Name's avatar Your Name

Add generic tool_call parsing to stream mode

Add Format 3 to parse_tool_calls_from_content:
- Parse <tool_call><tool><name>...</name><arguments>JSON</arguments></tool></tool_call>
- Also handles incomplete closing tags
parent 64908dd5
...@@ -785,6 +785,27 @@ class CoderClient: ...@@ -785,6 +785,27 @@ class CoderClient:
} }
}) })
# Format 3: Generic <tool_call><tool><name>...</name><arguments>JSON</arguments></tool></tool_call>
# Also handles incomplete closing tags like <tool_call> without </tool_call>
generic_pattern = r'<tool_call>\s*<tool>\s*<name>(.*?)</name>\s*<arguments>(.*?)</arguments>\s*</tool>\s*(?:</tool_call>)?'
for match in re.finditer(generic_pattern, text, re.DOTALL | re.IGNORECASE):
name = match.group(1).strip()
args_str = match.group(2).strip()
if not name:
continue
try:
args = json.loads(args_str) if args_str else {}
except json.JSONDecodeError:
args = {}
parsed.append({
'id': f'call_{len(parsed)}',
'type': 'function',
'function': {
'name': name,
'arguments': json.dumps(args)
}
})
return parsed return parsed
# Process streaming response line by line # Process streaming response line by line
......
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