From 633a2b6be2625a97275f36539e4be2aa767650ed Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sun, 26 Feb 2023 00:43:12 -0300 Subject: [PATCH] Don't regenerate/remove last message if the chat is empty --- modules/chat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/chat.py b/modules/chat.py index 8bc42dd1..82e21d6f 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -164,7 +164,7 @@ def cai_chatbot_wrapper(text, max_new_tokens, do_sample, temperature, top_p, typ yield generate_chat_html(_history, name1, name2, shared.character) def regenerate_wrapper(text, max_new_tokens, do_sample, temperature, top_p, typical_p, repetition_penalty, top_k, min_length, no_repeat_ngram_size, num_beams, penalty_alpha, length_penalty, early_stopping, name1, name2, context, check, chat_prompt_size, chat_generation_attempts=1): - if shared.character != 'None' and len(shared.history['visible']) == 1: + if (shared.character != 'None' and len(shared.history['visible']) == 1) or len(shared.history['internal']) == 0: if shared.args.cai_chat: yield generate_chat_html(shared.history['visible'], name1, name2, shared.character) else: @@ -182,7 +182,7 @@ def regenerate_wrapper(text, max_new_tokens, do_sample, temperature, top_p, typi yield shared.history['visible'] def remove_last_message(name1, name2): - if not shared.history['internal'][-1][0] == '<|BEGIN-VISIBLE-CHAT|>': + if len(shared.history['visible']) > 0 and not shared.history['internal'][-1][0] == '<|BEGIN-VISIBLE-CHAT|>': last = shared.history['visible'].pop() shared.history['internal'].pop() else: