pvanand commited on
Commit
f029274
1 Parent(s): 788373a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -11
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, excess quotes, and excessive whitespace
438
- cleaned_text = re.sub(r'\[|\]|"+|\s+', ' ', input_text).strip()
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).strip()
444
 
445
- # Remove tool and interact content from combined_response
446
- combined_response = re.sub(r'<(tool|interact)>.*?</\1>', '', combined_response, flags=re.DOTALL).strip()
447
 
448
  parsed_interacts = []
449
  parsed_tools = []
450
 
451
  # Parse interacts and tools
452
- blocks = re.finditer(r'<(interact|tool)>(.*?)</\1>', cleaned_text, re.DOTALL)
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].strip()
463
- options = [opt.strip() 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 == 'tool':
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).strip()
470
- option = tool_match.group(2).strip()
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