Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -434,22 +434,22 @@ def parse_followup_response(input_text):
|
|
434 |
import re
|
435 |
|
436 |
def parse_followup_and_tools(input_text):
|
437 |
-
# Remove extra brackets
|
438 |
-
cleaned_text = re.sub(r'\[|\]|"
|
439 |
|
440 |
# Extract response content
|
441 |
response_pattern = re.compile(r'<response>(.*?)</response>', re.DOTALL)
|
442 |
response_parts = response_pattern.findall(cleaned_text)
|
443 |
-
combined_response = ' '.join(response_parts)
|
444 |
|
445 |
-
#
|
446 |
-
combined_response =
|
447 |
|
448 |
parsed_interacts = []
|
449 |
parsed_tools = []
|
450 |
|
451 |
# Parse interacts and tools
|
452 |
-
blocks = re.finditer(r'<(interact|
|
453 |
for block in blocks:
|
454 |
block_type, content = block.groups()
|
455 |
content = content.strip()
|
@@ -459,15 +459,15 @@ def parse_followup_and_tools(input_text):
|
|
459 |
for qblock in question_blocks:
|
460 |
parts = re.split(r'\s*options:\s*', qblock, maxsplit=1)
|
461 |
if len(parts) == 2:
|
462 |
-
question = parts[0].
|
463 |
-
options = [opt.
|
464 |
parsed_interacts.append({'question': question, 'options': options})
|
465 |
|
466 |
-
elif block_type == '
|
467 |
tool_match = re.search(r'text:\s*(.*?)\s*options:\s*-\s*(.*)', content, re.DOTALL)
|
468 |
if tool_match:
|
469 |
-
tool_name = tool_match.group(1).
|
470 |
-
option = tool_match.group(2).
|
471 |
parsed_tools.append({'name': tool_name, 'input': option})
|
472 |
|
473 |
return combined_response, parsed_interacts, parsed_tools
|
|
|
434 |
import re
|
435 |
|
436 |
def parse_followup_and_tools(input_text):
|
437 |
+
# Remove extra brackets and excess quotes
|
438 |
+
cleaned_text = re.sub(r'\[|\]|"+', ' ', input_text)
|
439 |
|
440 |
# Extract response content
|
441 |
response_pattern = re.compile(r'<response>(.*?)</response>', re.DOTALL)
|
442 |
response_parts = response_pattern.findall(cleaned_text)
|
443 |
+
combined_response = ' '.join(response_parts)
|
444 |
|
445 |
+
# Normalize spaces in the combined response
|
446 |
+
combined_response = ' '.join(combined_response.split())
|
447 |
|
448 |
parsed_interacts = []
|
449 |
parsed_tools = []
|
450 |
|
451 |
# Parse interacts and tools
|
452 |
+
blocks = re.finditer(r'<(interact|tools)>(.*?)</\1>', cleaned_text, re.DOTALL)
|
453 |
for block in blocks:
|
454 |
block_type, content = block.groups()
|
455 |
content = content.strip()
|
|
|
459 |
for qblock in question_blocks:
|
460 |
parts = re.split(r'\s*options:\s*', qblock, maxsplit=1)
|
461 |
if len(parts) == 2:
|
462 |
+
question = ' '.join(parts[0].split()) # Normalize spaces
|
463 |
+
options = [' '.join(opt.split()) for opt in re.split(r'\s*-\s*', parts[1]) if opt.strip()]
|
464 |
parsed_interacts.append({'question': question, 'options': options})
|
465 |
|
466 |
+
elif block_type == 'tools':
|
467 |
tool_match = re.search(r'text:\s*(.*?)\s*options:\s*-\s*(.*)', content, re.DOTALL)
|
468 |
if tool_match:
|
469 |
+
tool_name = ' '.join(tool_match.group(1).split()) # Normalize spaces
|
470 |
+
option = ' '.join(tool_match.group(2).split()) # Normalize spaces
|
471 |
parsed_tools.append({'name': tool_name, 'input': option})
|
472 |
|
473 |
return combined_response, parsed_interacts, parsed_tools
|