pvanand commited on
Commit
66cde55
1 Parent(s): 8456762

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +2 -59
main.py CHANGED
@@ -376,63 +376,6 @@ class FollowupQueryModel(BaseModel):
376
 
377
  import re
378
 
379
- def parse_followup_response(input_text):
380
- # Define patterns for response and interact
381
- response_pattern = re.compile(r'<response>(.*?)<\/response>', re.DOTALL)
382
- interact_pattern = re.compile(r'<interact>(.*?)<\/interact>', re.DOTALL)
383
-
384
- # Find all matches for response and interact
385
- response_matches = response_pattern.finditer(input_text)
386
- interact_matches = interact_pattern.finditer(input_text)
387
-
388
- # Initialize variables to keep track of the position
389
- last_end = 0
390
- combined_response = ""
391
- parsed_interacts = []
392
-
393
- # Combine responses and capture everything in between
394
- for response_match in response_matches:
395
- # Capture text before the current response tag
396
- combined_response += input_text[last_end:response_match.start()].strip() + "\n"
397
- # Add the response content
398
- combined_response += response_match.group(1).strip() + "\n"
399
- # Update the last end position
400
- last_end = response_match.end()
401
-
402
- # Check for interacts and parse them
403
- for interact_match in interact_matches:
404
- # Capture text before the current interact tag
405
- combined_response += input_text[last_end:interact_match.start()].strip() + "\n"
406
- # Process the interact block
407
- interact_text = interact_match.group(1).strip()
408
- if interact_text:
409
- # Split by "text:" to separate each question block
410
- question_blocks = interact_text.split("- text:")
411
-
412
- # Loop through each block and extract the question and its options
413
- for block in question_blocks[1:]:
414
- # Extract the question using regex (up to the "options:" part)
415
- question_match = re.search(r'^(.*?)\s*options:', block, re.DOTALL)
416
- if question_match:
417
- question = question_match.group(1).strip().strip('"')
418
-
419
- # Extract the options using regex
420
- options_match = re.search(r'options:\s*(.*?)$', block, re.DOTALL)
421
- if options_match:
422
- options = [option.strip().strip('"') for option in options_match.group(1).split('-') if option.strip()]
423
-
424
- # Add the parsed question and options to the list
425
- parsed_interacts.append({'question': question, 'options': options})
426
- # Update the last end position
427
- last_end = interact_match.end()
428
-
429
- # Capture any remaining text after the last tag
430
- combined_response += input_text[last_end:].strip()
431
-
432
- return combined_response.strip(), parsed_interacts
433
-
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)
@@ -498,7 +441,7 @@ async def followup_agent(query: FollowupQueryModel, background_tasks: Background
498
  yield content
499
 
500
  logger.info(f"LLM RAW response for query: {query.query}: {full_response}")
501
- response_content, interact = parse_followup_response(full_response)
502
 
503
  result = {
504
  "response": response_content,
@@ -541,7 +484,7 @@ async def followup_agent(query: FollowupQueryModel, background_tasks: Background
541
  yield content
542
 
543
  logger.info(f"LLM RAW response for query: {query.query}: {full_response}")
544
- response_content, interact = parse_followup_response(full_response)
545
 
546
  result = {
547
  "clarification": interact
 
376
 
377
  import re
378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  def parse_followup_and_tools(input_text):
380
  # Remove extra brackets and excess quotes
381
  cleaned_text = re.sub(r'\[|\]|"+', ' ', input_text)
 
441
  yield content
442
 
443
  logger.info(f"LLM RAW response for query: {query.query}: {full_response}")
444
+ response_content, interact,tools = parse_followup_and_tools(full_response)
445
 
446
  result = {
447
  "response": response_content,
 
484
  yield content
485
 
486
  logger.info(f"LLM RAW response for query: {query.query}: {full_response}")
487
+ response_content, interact,tools = parse_followup_and_tools(full_response)
488
 
489
  result = {
490
  "clarification": interact