bethanie05 commited on
Commit
bc4367d
·
verified ·
1 Parent(s): 3d4b454

Add logic to keep only the last paragraph of frobot responses.

Browse files
Files changed (1) hide show
  1. chat_application/main.py +14 -0
chat_application/main.py CHANGED
@@ -300,6 +300,12 @@ def replace_semicolons(text, probability=0.80):
300
  modified_text.append(char)
301
  return ''.join(modified_text)
302
 
 
 
 
 
 
 
303
  def get_response_delay(response):
304
  baseDelay = 5 # standard delay for thinking
305
  randFactor = np.random.uniform(0,30, len(response) // 4)
@@ -376,6 +382,14 @@ def ask_bot(room_id, bot, bot_display_name, initial_prompt, instruct_prompt):
376
  parsed_response = re.sub(r"\b"
377
  + aliases[bot_display_name]
378
  + r"\b:\s?", '', parsed_response)
 
 
 
 
 
 
 
 
379
 
380
  # Check for if the bot passed (i.e. response = "(pass)")
381
  if ("(pass)" in parsed_response) or (parsed_response == ""):
 
300
  modified_text.append(char)
301
  return ''.join(modified_text)
302
 
303
+ def get_last_paragraph(text):
304
+ text = text.strip()
305
+ if "\n" not in text:
306
+ return text
307
+ return text.rsplit("\n", 1)[-1].strip()
308
+
309
  def get_response_delay(response):
310
  baseDelay = 5 # standard delay for thinking
311
  randFactor = np.random.uniform(0,30, len(response) // 4)
 
382
  parsed_response = re.sub(r"\b"
383
  + aliases[bot_display_name]
384
  + r"\b:\s?", '', parsed_response)
385
+
386
+ # Only keep the last paragraph of frobot responses
387
+ if bot == frobot:
388
+ print("=========== OG FROBOT RESPONSE")
389
+ print(parsed_response)
390
+ parsed_response = get_last_paragraph(parsed_response)
391
+ print("=========== LAST PARAGRAPH")
392
+ print(parsed_response)
393
 
394
  # Check for if the bot passed (i.e. response = "(pass)")
395
  if ("(pass)" in parsed_response) or (parsed_response == ""):