project-baize commited on
Commit
9d96329
1 Parent(s): ac92dbd

Update app_modules/utils.py

Browse files
Files changed (1) hide show
  1. app_modules/utils.py +4 -2
app_modules/utils.py CHANGED
@@ -289,15 +289,17 @@ def generate_prompt_with_history(text,history,tokenizer,max_length=2048):
289
  history = ["\n[|Human|]{}\n[|AI|]{}".format(x[0],x[1]) for x in history]
290
  history.append("\n[|Human|]{}\n[|AI|]".format(text))
291
  history_text = ""
292
-
293
  for x in history[::-1]:
294
  if tokenizer(prompt+history_text+x, return_tensors="pt")['input_ids'].size(-1) <= max_length:
295
  history_text = x + history_text
296
  flag = True
 
 
297
  if flag:
298
  return prompt+history_text,tokenizer(prompt+history_text, return_tensors="pt")
299
  else:
300
- return False
301
 
302
 
303
  def is_stop_word_or_prefix(s: str, stop_words: list) -> bool:
 
289
  history = ["\n[|Human|]{}\n[|AI|]{}".format(x[0],x[1]) for x in history]
290
  history.append("\n[|Human|]{}\n[|AI|]".format(text))
291
  history_text = ""
292
+ flag = False
293
  for x in history[::-1]:
294
  if tokenizer(prompt+history_text+x, return_tensors="pt")['input_ids'].size(-1) <= max_length:
295
  history_text = x + history_text
296
  flag = True
297
+ else:
298
+ break
299
  if flag:
300
  return prompt+history_text,tokenizer(prompt+history_text, return_tensors="pt")
301
  else:
302
+ return None
303
 
304
 
305
  def is_stop_word_or_prefix(s: str, stop_words: list) -> bool: