From 9d96329391d124881d246602f7f310047cfb5d49 Mon Sep 17 00:00:00 2001 From: Baize Date: Tue, 4 Apr 2023 15:54:35 +0000 Subject: [PATCH] Update app_modules/utils.py --- app_modules/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app_modules/utils.py b/app_modules/utils.py index 0f0e27a..5d00444 100644 --- a/app_modules/utils.py +++ b/app_modules/utils.py @@ -289,15 +289,17 @@ def generate_prompt_with_history(text,history,tokenizer,max_length=2048): history = ["\n[|Human|]{}\n[|AI|]{}".format(x[0],x[1]) for x in history] history.append("\n[|Human|]{}\n[|AI|]".format(text)) history_text = "" - + flag = False for x in history[::-1]: if tokenizer(prompt+history_text+x, return_tensors="pt")['input_ids'].size(-1) <= max_length: history_text = x + history_text flag = True + else: + break if flag: return prompt+history_text,tokenizer(prompt+history_text, return_tensors="pt") else: - return False + return None def is_stop_word_or_prefix(s: str, stop_words: list) -> bool: