Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -511,15 +511,63 @@ import re
|
|
511 |
|
512 |
# return final_response
|
513 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
514 |
def clean_response(response_text):
|
515 |
# Remove system and user tags
|
516 |
response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
517 |
response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
518 |
response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
|
519 |
|
520 |
-
# Extract the document name and page number
|
521 |
-
document_match = re.search(r"Document\(metadata=\{'source':'(.+?)','page':(\d+)\}", response_text)
|
522 |
-
|
523 |
if document_match:
|
524 |
document_name = document_match.group(1).split('/')[-1] # Get the document name
|
525 |
page_number = document_match.group(2) # Get the page number
|
@@ -551,15 +599,13 @@ def clean_response(response_text):
|
|
551 |
Sure! Here is the response for your Query:
|
552 |
• Document name - {document_name}
|
553 |
• Page No - {page_number}
|
554 |
-
•
|
555 |
"""
|
556 |
|
557 |
return final_response
|
558 |
|
559 |
|
560 |
|
561 |
-
|
562 |
-
|
563 |
# Define a new template specifically for GPT-4o-mini in VDB Details mode
|
564 |
gpt4o_mini_template_details = f"""
|
565 |
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.
|
|
|
511 |
|
512 |
# return final_response
|
513 |
|
514 |
+
# def clean_response(response_text):
|
515 |
+
# # Remove system and user tags
|
516 |
+
# response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
517 |
+
# response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
518 |
+
# response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
|
519 |
+
|
520 |
+
# # Extract the document name and page number
|
521 |
+
# document_match = re.search(r"Document\(metadata=\{'source':'(.+?)','page':(\d+)\}", response_text)
|
522 |
+
# # document_match = re.search(r"Document\(metadata=\{'source':'(.+?)','page':(\d+)\}", response_text)
|
523 |
+
# if document_match:
|
524 |
+
# document_name = document_match.group(1).split('/')[-1] # Get the document name
|
525 |
+
# page_number = document_match.group(2) # Get the page number
|
526 |
+
# else:
|
527 |
+
# document_name = "Unknown"
|
528 |
+
# page_number = "Unknown"
|
529 |
+
|
530 |
+
# # Remove the entire 'Document(metadata=...' and any mention of it from the response
|
531 |
+
# response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
|
532 |
+
|
533 |
+
# # Remove any mention of "Document:" in the response
|
534 |
+
# response_text = re.sub(r'- Document:.*', '', response_text)
|
535 |
+
|
536 |
+
# # Remove any unwanted escape characters like \u and \u00
|
537 |
+
# response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
|
538 |
+
|
539 |
+
# # Ensure proper spacing between words and dates
|
540 |
+
# response_text = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', response_text)
|
541 |
+
# response_text = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', response_text)
|
542 |
+
|
543 |
+
# # Remove the phrase "Sure! The Responses are as follows:" from the actual content
|
544 |
+
# response_text = re.sub(r'Sure! The Responses are as follows:', '', response_text).strip()
|
545 |
+
|
546 |
+
# # Clean up the text by removing extra whitespace
|
547 |
+
# cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
|
548 |
+
|
549 |
+
# # Format the final response with bullet points
|
550 |
+
# final_response = f"""
|
551 |
+
# Sure! Here is the response for your Query:
|
552 |
+
# • Document name - {document_name}
|
553 |
+
# • Page No - {page_number}
|
554 |
+
# • Responses - {cleaned_response}
|
555 |
+
# """
|
556 |
+
|
557 |
+
# return final_response
|
558 |
+
|
559 |
+
|
560 |
+
import re
|
561 |
+
|
562 |
def clean_response(response_text):
|
563 |
# Remove system and user tags
|
564 |
response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
565 |
response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
566 |
response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
|
567 |
|
568 |
+
# Extract the document name and page number from updated pattern
|
569 |
+
document_match = re.search(r"Document\(metadata=\{'source': '(.+?)', 'page': (\d+)\}", response_text)
|
570 |
+
|
571 |
if document_match:
|
572 |
document_name = document_match.group(1).split('/')[-1] # Get the document name
|
573 |
page_number = document_match.group(2) # Get the page number
|
|
|
599 |
Sure! Here is the response for your Query:
|
600 |
• Document name - {document_name}
|
601 |
• Page No - {page_number}
|
602 |
+
• Responses - {cleaned_response}
|
603 |
"""
|
604 |
|
605 |
return final_response
|
606 |
|
607 |
|
608 |
|
|
|
|
|
609 |
# Define a new template specifically for GPT-4o-mini in VDB Details mode
|
610 |
gpt4o_mini_template_details = f"""
|
611 |
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.
|