Update app_modules/utils.py
This commit is contained in:
parent
ac92dbd6eb
commit
9d96329391
|
@ -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 = ["\n[|Human|]{}\n[|AI|]{}".format(x[0],x[1]) for x in history]
|
||||||
history.append("\n[|Human|]{}\n[|AI|]".format(text))
|
history.append("\n[|Human|]{}\n[|AI|]".format(text))
|
||||||
history_text = ""
|
history_text = ""
|
||||||
|
flag = False
|
||||||
for x in history[::-1]:
|
for x in history[::-1]:
|
||||||
if tokenizer(prompt+history_text+x, return_tensors="pt")['input_ids'].size(-1) <= max_length:
|
if tokenizer(prompt+history_text+x, return_tensors="pt")['input_ids'].size(-1) <= max_length:
|
||||||
history_text = x + history_text
|
history_text = x + history_text
|
||||||
flag = True
|
flag = True
|
||||||
|
else:
|
||||||
|
break
|
||||||
if flag:
|
if flag:
|
||||||
return prompt+history_text,tokenizer(prompt+history_text, return_tensors="pt")
|
return prompt+history_text,tokenizer(prompt+history_text, return_tensors="pt")
|
||||||
else:
|
else:
|
||||||
return False
|
return None
|
||||||
|
|
||||||
|
|
||||||
def is_stop_word_or_prefix(s: str, stop_words: list) -> bool:
|
def is_stop_word_or_prefix(s: str, stop_words: list) -> bool:
|
||||||
|
|
Loading…
Reference in New Issue