Ritesh Thawkar commited on
Commit
4aa0163
1 Parent(s): 2092d58

make some formatting changes

Browse files
Files changed (2) hide show
  1. app.py +2 -2
  2. templates/chat.html +11 -4
app.py CHANGED
@@ -90,8 +90,8 @@ Response Formatting Guidelines:
90
  - Apply <strong> for bold texts.
91
  - Organize content with ordered (<ol>) or unordered (<ul>) lists as needed.
92
  - Include line breaks (<br>) where appropriate for readability.
 
93
  - This is important - Wrap all English words, numbers, dates, or sentences in a <span dir="ltr"> tag to maintain left-to-right directionality.
94
- - Numbers with decimal values should be rounded off to two decimal places.
95
 
96
  Additional Instructions:
97
 
@@ -139,7 +139,7 @@ def handle_message(data):
139
  try:
140
  for chunk in rag_chain.stream(question):
141
  emit('response', chunk, room=request.sid)
142
- print(chunk)
143
  except Exception as e:
144
  emit('response', {"error": "An error occurred while processing your request."}, room=request.sid)
145
 
 
90
  - Apply <strong> for bold texts.
91
  - Organize content with ordered (<ol>) or unordered (<ul>) lists as needed.
92
  - Include line breaks (<br>) where appropriate for readability.
93
+ - This is important - Numbers with decimal values should be rounded off to two decimal places.
94
  - This is important - Wrap all English words, numbers, dates, or sentences in a <span dir="ltr"> tag to maintain left-to-right directionality.
 
95
 
96
  Additional Instructions:
97
 
 
139
  try:
140
  for chunk in rag_chain.stream(question):
141
  emit('response', chunk, room=request.sid)
142
+ # print(chunk)
143
  except Exception as e:
144
  emit('response', {"error": "An error occurred while processing your request."}, room=request.sid)
145
 
templates/chat.html CHANGED
@@ -510,12 +510,15 @@
510
  socket.emit('message', { question: question, session_id: 'abc123' });
511
  }
512
 
513
- function addLtrToEnglishContent(parentElement) {
514
  // Regular expression to detect English content (letters, numbers, punctuation)
515
  const englishOnlyRegex = /^[A-Za-z0-9.,%:\/\-\s]+$/;
516
 
517
  // Get all the elements inside the parent element
518
- const elements = parentElement.querySelectorAll('*');
 
 
 
519
 
520
  // Loop through each element and check its text content
521
  elements.forEach(function(element) {
@@ -557,6 +560,11 @@
557
 
558
  formatted_answer = addLtrAttribute(formatted_answer);
559
 
 
 
 
 
 
560
  if (lastElement.hasClass("response-block")) {
561
  $(".chat-container .chat-block:last-child").find(".message-content").html(formatted_answer);
562
  } else {
@@ -575,9 +583,8 @@
575
  </div>
576
  </div>
577
  `);
578
- const parentEle = document.querySelectorAll('.response-block .message-content')[-1];
579
- addLtrToEnglishContent(parentEle);
580
  }
 
581
 
582
  $(".chat-container").scrollTop($(".chat-container")[0].scrollHeight);
583
  }
 
510
  socket.emit('message', { question: question, session_id: 'abc123' });
511
  }
512
 
513
+ function addLtrToEnglishContent() {
514
  // Regular expression to detect English content (letters, numbers, punctuation)
515
  const englishOnlyRegex = /^[A-Za-z0-9.,%:\/\-\s]+$/;
516
 
517
  // Get all the elements inside the parent element
518
+ const parent = $('.message-content').last();
519
+ console.log(parent[0]);
520
+ let elements = $(parent[0]).find("*");
521
+ console.log(elements);
522
 
523
  // Loop through each element and check its text content
524
  elements.forEach(function(element) {
 
560
 
561
  formatted_answer = addLtrAttribute(formatted_answer);
562
 
563
+ // Replace numbers and round them to two decimal places
564
+ formatted_answer = formatted_answer.replace(/\d+\.\d+/g, function(match) {
565
+ return parseFloat(match).toFixed(2);
566
+ });
567
+
568
  if (lastElement.hasClass("response-block")) {
569
  $(".chat-container .chat-block:last-child").find(".message-content").html(formatted_answer);
570
  } else {
 
583
  </div>
584
  </div>
585
  `);
 
 
586
  }
587
+ // addLtrToEnglishContent();
588
 
589
  $(".chat-container").scrollTop($(".chat-container")[0].scrollHeight);
590
  }