Spaces:
Paused
Paused
Download test_xml_parse.py from adityaxess/deepseek-proxy: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/spaces/adityaxess/deepseek-proxy/resolve/main/test_xml_parse.py
- Command line
-
hf download hf://spaces/adityaxess/deepseek-proxy/test_xml_parse.py
-
curl -L -o test_xml_parse.py https://huggingface.co/spaces/adityaxess/deepseek-proxy/resolve/main/test_xml_parse.py
2.03 kB
| import json, re | |
| def detect_all_tool_calls(response_text: str) -> list: | |
| tool_calls = [] | |
| pattern0 = re.compile(r'<tool_calls?\s+name=["\']([^"\']+)["\']\s*>(.*?)(?:</tool_calls?>|$)', re.DOTALL | re.IGNORECASE) | |
| matches0 = pattern0.findall(response_text) | |
| for name, body in matches0: | |
| name = name.strip() | |
| body_str = body.strip() | |
| args = {} | |
| parsed_json = None | |
| try: | |
| parsed_json = json.loads(body_str) | |
| except Exception: | |
| start = body_str.find("{") | |
| end = body_str.rfind("}") | |
| if start != -1 and end != -1: | |
| try: | |
| parsed_json = json.loads(body_str[start:end+1]) | |
| except Exception: | |
| pass | |
| if parsed_json and isinstance(parsed_json, dict): | |
| args = parsed_json | |
| else: | |
| child_pattern = re.compile(r'<([a-zA-Z0-9_-]+)[^>]*>(.*?)(?:</\1>|$)', re.DOTALL) | |
| child_matches = child_pattern.findall(body_str) | |
| for tag, val in child_matches: | |
| val_clean = val.strip() | |
| val_clean = re.sub(r'</?[a-zA-Z0-9_-]+[^>]*>$', '', val_clean).strip() | |
| args[tag.strip()] = val_clean | |
| if name: | |
| tool_calls.append((name, args)) | |
| return tool_calls | |
| text = """ | |
| <tool_call name="Bash"> | |
| <command>echo "=== Shell/Command Execution ===" && echo "OK: Shell execution works" && echo "" && echo "=== System Info ===" && uname -a && echo "Current user: $(whoami)" && echo "Working dir: $(pwd)"</command> | |
| <description>Test shell execution tool</description> | |
| </tool_call> | |
| <tool_call name="Write"> | |
| <file_path>/tmp/claude_tool_test.txt</file_path> | |
| <content>Tool test file - created at 2026-07-22 | |
| This tests the Write tool functionality.</content> | |
| </tool_call> | |
| """ | |
| calls = detect_all_tool_calls(text) | |
| print("Extracted tool calls:") | |
| for name, args in calls: | |
| print("NAME:", name) | |
| print("ARGS:", json.dumps(args, indent=2)) | |