Spaces:
Sleeping
Sleeping
File size: 870 Bytes
76cd8d1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import re
def parse_response(text: str):
first_line = next((line.strip() for line in text.strip().splitlines() if line.strip()), "")
final_match = re.match(r"FINAL:\s*(.+)", first_line, re.IGNORECASE)
if final_match:
return "final", final_match.group(1).strip()
action_match = re.match(r"ACTION:\s*(\w+)\(([^)]*)\)", first_line, re.IGNORECASE)
if action_match:
tool_name = action_match.group(1).strip()
raw_args = [a.strip() for a in action_match.group(2).split(",") if a.strip()]
args = []
for a in raw_args:
if "=" in a:
a = a.split("=", 1)[1].strip()
a = a.strip("\"'")
try:
args.append(float(a))
except ValueError:
args.append(a)
return "action", (tool_name, args)
return "unknown", first_line
|