Pijush2023 commited on
Commit
b773d17
·
verified ·
1 Parent(s): 87009cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -58
app.py CHANGED
@@ -576,58 +576,13 @@ import re
576
 
577
  import re
578
 
579
- # def clean_response(response_text):
580
- # # Remove system and user tags
581
- # response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
582
- # response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
583
- # response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
584
-
585
- # # Extract the document name and page number from updated pattern
586
- # document_match = re.search(r"Document\(metadata=\{'source': '(.+?)', 'page': (\d+)\}", response_text)
587
-
588
- # if document_match:
589
- # document_name = document_match.group(1).split('/')[-1] # Get the document name
590
- # page_number = document_match.group(2) # Get the page number
591
- # else:
592
- # document_name = "Unknown"
593
- # page_number = "Unknown"
594
-
595
- # # Remove the entire 'Document(metadata=...' and any mention of it from the response
596
- # response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
597
-
598
- # # Remove any mention of "Document:" in the response
599
- # response_text = re.sub(r'- Document:.*', '', response_text)
600
-
601
- # # Remove any unwanted escape characters like \u and \u00
602
- # response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
603
-
604
- # # Ensure proper spacing between words and dates
605
- # response_text = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', response_text)
606
- # response_text = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', response_text)
607
-
608
- # # Remove the phrase "Sure! The Responses are as follows:" from the actual content
609
- # response_text = re.sub(r'Sure! The Responses are as follows:', '', response_text).strip()
610
-
611
- # # Clean up the text by removing extra whitespace
612
- # cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
613
-
614
- # # Format the final response with bullet points
615
- # final_response = f"""
616
- # Sure! Here is the response for your Query:
617
- # • Document name - {document_name}
618
- # • Page No - {page_number}
619
- # • Responses - {cleaned_response}
620
- # """
621
-
622
- # return final_response
623
-
624
  def clean_response(response_text):
625
  # Remove system and user tags
626
  response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
627
  response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
628
  response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
629
 
630
- # Extract the document name and page number
631
  document_match = re.search(r"Document\(metadata=\{'source': '(.+?)', 'page': (\d+)\}", response_text)
632
 
633
  if document_match:
@@ -639,9 +594,9 @@ def clean_response(response_text):
639
 
640
  # Remove the entire 'Document(metadata=...' and any mention of it from the response
641
  response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
642
-
643
- # Extract top 5 fetched results (assuming the top 5 results are the first 5 lines of content)
644
- top_results = response_text.split('\n')[:5] # Adjust this as per your actual data structure
645
 
646
  # Remove any unwanted escape characters like \u and \u00
647
  response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
@@ -657,15 +612,12 @@ def clean_response(response_text):
657
  cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
658
 
659
  # Format the final response with bullet points
660
- top_five_formatted = ''.join([f'{i+1}. {result.strip()}\n' for i, result in enumerate(top_results)])
661
-
662
- final_response = (
663
- f"Sure! Here is the response for your Query:\n"
664
- f"Document name - {document_name}\n"
665
- f"• Page No - {page_number}\n"
666
- f"• Top 5 Fetched Results:\n{top_five_formatted}"
667
- f"• Actual Response - {cleaned_response}"
668
- )
669
 
670
  return final_response
671
 
@@ -676,6 +628,8 @@ def clean_response(response_text):
676
 
677
 
678
 
 
 
679
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
680
  gpt4o_mini_template_details = f"""
681
  As a highly specialized assistant, I provide precise, detailed, and informative responses. On this bright day of {current_date}, I'm equipped to assist with all your queries about Birmingham, Alabama, offering detailed insights tailored to your needs.
 
576
 
577
  import re
578
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579
  def clean_response(response_text):
580
  # Remove system and user tags
581
  response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
582
  response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
583
  response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
584
 
585
+ # Extract the document name and page number from updated pattern
586
  document_match = re.search(r"Document\(metadata=\{'source': '(.+?)', 'page': (\d+)\}", response_text)
587
 
588
  if document_match:
 
594
 
595
  # Remove the entire 'Document(metadata=...' and any mention of it from the response
596
  response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
597
+
598
+ # Remove any mention of "Document:" in the response
599
+ response_text = re.sub(r'- Document:.*', '', response_text)
600
 
601
  # Remove any unwanted escape characters like \u and \u00
602
  response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
 
612
  cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
613
 
614
  # Format the final response with bullet points
615
+ final_response = f"""
616
+ Sure! Here is the response for your Query:
617
+ Document name - {document_name}
618
+ Page No - {page_number}
619
+ Responses - {cleaned_response}
620
+ """
 
 
 
621
 
622
  return final_response
623
 
 
628
 
629
 
630
 
631
+
632
+
633
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
634
  gpt4o_mini_template_details = f"""
635
  As a highly specialized assistant, I provide precise, detailed, and informative responses. On this bright day of {current_date}, I'm equipped to assist with all your queries about Birmingham, Alabama, offering detailed insights tailored to your needs.