Pijush2023 commited on
Commit
463a37c
·
verified ·
1 Parent(s): e283093

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -52
app.py CHANGED
@@ -486,65 +486,17 @@ import re
486
 
487
  # return final_response
488
 
489
- # def clean_response(response_text):
490
- # # Remove system and user tags
491
- # response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
492
- # response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
493
- # response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
494
-
495
- # # Extract the document name and page number
496
- # document_match = re.search(r"Document\(metadata=\{'source':'(.+?)','page':(\d+)\}", response_text)
497
- # document_match = re.search(r"Document\(metadata=\{'source':'(.+?)','page':(\d+)\}", response_text)
498
- # if document_match:
499
- # document_name = document_match.group(1).split('/')[-1] # Get the document name
500
- # page_number = document_match.group(2) # Get the page number
501
- # else:
502
- # document_name = "Unknown"
503
- # page_number = "Unknown"
504
-
505
- # # Remove the entire 'Document(metadata=...' and any mention of it from the response
506
- # response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
507
-
508
- # # Remove any mention of "Document:" in the response
509
- # response_text = re.sub(r'- Document:.*', '', response_text)
510
-
511
- # # Remove any unwanted escape characters like \u and \u00
512
- # response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
513
-
514
- # # Ensure proper spacing between words and dates
515
- # response_text = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', response_text)
516
- # response_text = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', response_text)
517
-
518
- # # Remove the phrase "Sure! The Responses are as follows:" from the actual content
519
- # response_text = re.sub(r'Sure! The Responses are as follows:', '', response_text).strip()
520
-
521
- # # Clean up the text by removing extra whitespace
522
- # cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
523
-
524
- # # Format the final response with bullet points
525
- # final_response = f"""
526
- # Sure! Here is the response for your Query:
527
- # • Document name - {document_name}
528
- # • Page No - {page_number}
529
- # • Response - {cleaned_response}
530
- # """
531
-
532
- # return final_response
533
-
534
-
535
- import re
536
-
537
  def clean_response(response_text):
538
  # Remove system and user tags
539
  response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
540
  response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
541
  response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
542
 
543
- # Adjusted regex pattern to extract document name and page number
544
- document_match = re.search(r"(\d{6}_\d{12}_V\d+\.pdf),page:(\d+)", response_text)
545
-
546
  if document_match:
547
- document_name = document_match.group(1) # Get the document name
548
  page_number = document_match.group(2) # Get the page number
549
  else:
550
  document_name = "Unknown"
@@ -580,6 +532,9 @@ Sure! Here is the response for your Query:
580
  return final_response
581
 
582
 
 
 
 
583
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
584
  gpt4o_mini_template_details = f"""
585
  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.
 
486
 
487
  # return final_response
488
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
  def clean_response(response_text):
490
  # Remove system and user tags
491
  response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
492
  response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
493
  response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
494
 
495
+ # Extract the document name and page number
496
+ document_match = re.search(r"Document\(metadata=\{'source':'(.+?)','page':(\d+)\}", response_text)
497
+ document_match = re.search(r"Document\(metadata=\{'source':'(.+?)','page':(\d+)\}", response_text)
498
  if document_match:
499
+ document_name = document_match.group(1).split('/')[-1] # Get the document name
500
  page_number = document_match.group(2) # Get the page number
501
  else:
502
  document_name = "Unknown"
 
532
  return final_response
533
 
534
 
535
+
536
+
537
+
538
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
539
  gpt4o_mini_template_details = f"""
540
  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.