Pijush2023 commited on
Commit
9ade06a
·
verified ·
1 Parent(s): 2170fb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -11
app.py CHANGED
@@ -439,20 +439,53 @@ def bot(history, choice, tts_choice, retrieval_mode, model_choice):
439
 
440
  import re
441
 
442
- def clean_response(response_text):
443
- # Remove system and user tags
444
- response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
445
- response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
446
- response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
 
 
 
 
 
 
 
 
 
 
 
 
 
447
 
448
- # Clean up the text by removing extra whitespace
449
- cleaned_response = response_text.strip()
450
- cleaned_response = re.sub(r'\s+', ' ', cleaned_response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
 
452
- # Ensure the response is conversational and organized
453
- cleaned_response = cleaned_response.replace('1.', '\n1.').replace('2.', '\n2.').replace('3.', '\n3.').replace('4.', '\n4.').replace('5.', '\n5.')
454
 
455
- return cleaned_response
456
 
457
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
458
  gpt4o_mini_template_details = f"""
 
439
 
440
  import re
441
 
442
+ # def clean_response(response_text):
443
+ # # Remove system and user tags
444
+ # response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
445
+ # response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
446
+ # response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
447
+
448
+ # # Clean up the text by removing extra whitespace
449
+ # cleaned_response = response_text.strip()
450
+ # cleaned_response = re.sub(r'\s+', ' ', cleaned_response)
451
+
452
+ # # Ensure the response is conversational and organized
453
+ # cleaned_response = cleaned_response.replace('1.', '\n1.').replace('2.', '\n2.').replace('3.', '\n3.').replace('4.', '\n4.').replace('5.', '\n5.')
454
+
455
+ # return cleaned_response
456
+
457
+
458
+
459
+ import re
460
 
461
+ def clean_response(response_text):
462
+ """
463
+ This function removes metadata and unnecessary symbols from the document response
464
+ and formats the output in a readable way.
465
+ """
466
+ # Remove metadata section from the response
467
+ response_text = re.sub(r'Document\(metadata=.*?,page_content="', '', response_text)
468
+
469
+ # Replace encoded characters
470
+ response_text = response_text.replace('\\u2019', "'") # replace unicode apostrophe
471
+ response_text = response_text.replace('\\u00e8', 'è') # replace accented characters
472
+ response_text = response_text.replace('\\u00e0', 'à')
473
+ response_text = response_text.replace('\\n', '\n') # newline characters
474
+ response_text = response_text.replace('\\\\', '\\') # backslashes
475
+
476
+ # Remove any trailing document information
477
+ response_text = re.sub(r'\\.*$', '', response_text)
478
+
479
+ # Ensure proper spacing for better readability
480
+ response_text = re.sub(r'([a-z])([A-Z])', r'\1 \2', response_text) # Add spaces between words joined together
481
+
482
+ # Properly format new lines and spacing
483
+ response_text = response_text.strip() # Remove leading/trailing whitespace
484
+ response_text = re.sub(r' +', ' ', response_text) # Replace multiple spaces with a single space
485
+ response_text = re.sub(r'\n+', '\n', response_text) # Replace multiple newlines with a single newline
486
 
487
+ return response_text
 
488
 
 
489
 
490
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
491
  gpt4o_mini_template_details = f"""