Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -463,17 +463,43 @@ def bot(history, choice, tts_choice, retrieval_mode, model_choice):
|
|
463 |
|
464 |
import re
|
465 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
def clean_response(response_text):
|
467 |
# Remove system and user tags
|
468 |
response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
469 |
response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
470 |
response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
|
471 |
-
|
|
|
|
|
|
|
|
|
472 |
response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
|
|
|
473 |
# Add spaces between words and dates (e.g., "born04/04/1963" becomes "born 04/04/1963")
|
474 |
response_text = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', response_text)
|
475 |
response_text = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', response_text)
|
476 |
-
|
477 |
# Clean up the text by removing extra whitespace
|
478 |
cleaned_response = response_text.strip()
|
479 |
cleaned_response = re.sub(r'\s+', ' ', cleaned_response)
|
@@ -485,6 +511,7 @@ def clean_response(response_text):
|
|
485 |
|
486 |
|
487 |
|
|
|
488 |
# Define a new template specifically for GPT-4o-mini in VDB Details mode
|
489 |
gpt4o_mini_template_details = f"""
|
490 |
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.
|
|
|
463 |
|
464 |
import re
|
465 |
|
466 |
+
# def clean_response(response_text):
|
467 |
+
# # Remove system and user tags
|
468 |
+
# response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
469 |
+
# response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
470 |
+
# response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
|
471 |
+
# #-------
|
472 |
+
# response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
|
473 |
+
# # Add spaces between words and dates (e.g., "born04/04/1963" becomes "born 04/04/1963")
|
474 |
+
# response_text = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', response_text)
|
475 |
+
# response_text = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', response_text)
|
476 |
+
# #--------
|
477 |
+
# # Clean up the text by removing extra whitespace
|
478 |
+
# cleaned_response = response_text.strip()
|
479 |
+
# cleaned_response = re.sub(r'\s+', ' ', cleaned_response)
|
480 |
+
|
481 |
+
# # Ensure the response is conversational and organized
|
482 |
+
# cleaned_response = cleaned_response.replace('1.', '\n1.').replace('2.', '\n2.').replace('3.', '\n3.').replace('4.', '\n4.').replace('5.', '\n5.')
|
483 |
+
|
484 |
+
# return cleaned_response
|
485 |
+
|
486 |
+
|
487 |
def clean_response(response_text):
|
488 |
# Remove system and user tags
|
489 |
response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
490 |
response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
491 |
response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
|
492 |
+
|
493 |
+
# Remove 'Document(metadata=...' part
|
494 |
+
response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
|
495 |
+
|
496 |
+
# Remove any unwanted escape characters like \u and \u00
|
497 |
response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
|
498 |
+
|
499 |
# Add spaces between words and dates (e.g., "born04/04/1963" becomes "born 04/04/1963")
|
500 |
response_text = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', response_text)
|
501 |
response_text = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', response_text)
|
502 |
+
|
503 |
# Clean up the text by removing extra whitespace
|
504 |
cleaned_response = response_text.strip()
|
505 |
cleaned_response = re.sub(r'\s+', ' ', cleaned_response)
|
|
|
511 |
|
512 |
|
513 |
|
514 |
+
|
515 |
# Define a new template specifically for GPT-4o-mini in VDB Details mode
|
516 |
gpt4o_mini_template_details = f"""
|
517 |
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.
|