From ca47e016b4f1651824ad5631a4dcf05ed0f5de4c Mon Sep 17 00:00:00 2001 From: Vladimir Belitskiy Date: Mon, 20 Mar 2023 12:55:57 -0400 Subject: [PATCH 1/4] Do not display empty user messages in chat mode. There doesn't seem to be much value to them - they just take up space while also making it seem like there's still some sort of pseudo-dialogue going on, instead of a monologue by the bot. --- modules/html_generator.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/modules/html_generator.py b/modules/html_generator.py index 940d5486..f8cff6d8 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -142,22 +142,23 @@ def generate_chat_html(history, name1, name2, character): """ - if not (i == len(history)-1 and len(row[0]) == 0): - output += f""" -
-
- {img_me} -
-
-
- {name1} -
-
- {row[0]} -
-
+ if not row[0]: # don't display empty user messages + continue + output += f""" +
+
+ {img_me} +
+
+
+ {name1}
- """ +
+ {row[0]} +
+
+
+ """ output += "
" return output From e96687b1d619bc3bb149cca0011adba01274963a Mon Sep 17 00:00:00 2001 From: Vladimir Belitskiy Date: Mon, 20 Mar 2023 14:16:48 -0400 Subject: [PATCH 2/4] Do not send empty user input as part of the prompt. However, if extensions modify the empty prompt to be non-empty, it'l still work as before. --- modules/chat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/chat.py b/modules/chat.py index 36265990..c1e55ac4 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -33,12 +33,14 @@ def generate_chat_prompt(user_input, max_new_tokens, name1, name2, context, chat i = len(shared.history['internal'])-1 while i >= 0 and len(encode(''.join(rows), max_new_tokens)[0]) < max_length: rows.insert(1, f"{name2}: {shared.history['internal'][i][1].strip()}\n") - if not (shared.history['internal'][i][0] == '<|BEGIN-VISIBLE-CHAT|>'): + prev_user_input = shared.history['internal'][i][0] + if prev_user_input and not shared.history['internal'][i][0] == '<|BEGIN-VISIBLE-CHAT|>': rows.insert(1, f"{name1}: {shared.history['internal'][i][0].strip()}\n") i -= 1 if not impersonate: - rows.append(f"{name1}: {user_input}\n") + if user_input: + rows.append(f"{name1}: {user_input}\n") rows.append(apply_extensions(f"{name2}:", "bot_prefix")) limit = 3 else: From ffb0187e83043ddbbc7ab1b29e843a1ee6107b54 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Fri, 24 Mar 2023 17:17:29 -0300 Subject: [PATCH 3/4] Update chat.py --- modules/chat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/chat.py b/modules/chat.py index c1e55ac4..0dc5c922 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -34,12 +34,12 @@ def generate_chat_prompt(user_input, max_new_tokens, name1, name2, context, chat while i >= 0 and len(encode(''.join(rows), max_new_tokens)[0]) < max_length: rows.insert(1, f"{name2}: {shared.history['internal'][i][1].strip()}\n") prev_user_input = shared.history['internal'][i][0] - if prev_user_input and not shared.history['internal'][i][0] == '<|BEGIN-VISIBLE-CHAT|>': - rows.insert(1, f"{name1}: {shared.history['internal'][i][0].strip()}\n") + if len(prev_user_input) > 0 and prev_user_input != '<|BEGIN-VISIBLE-CHAT|>': + rows.insert(1, f"{name1}: {prev_user_input.strip()}\n") i -= 1 if not impersonate: - if user_input: + if len(user_input) > 0: rows.append(f"{name1}: {user_input}\n") rows.append(apply_extensions(f"{name2}:", "bot_prefix")) limit = 3 From 6e1b16c2aa87d167ed9893e800c199408ba946d3 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Fri, 24 Mar 2023 17:18:27 -0300 Subject: [PATCH 4/4] Update html_generator.py --- modules/html_generator.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/html_generator.py b/modules/html_generator.py index f8cff6d8..ff18c913 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -119,13 +119,13 @@ def load_html_image(paths): def generate_chat_html(history, name1, name2, character): output = f'
' - + img_bot = load_html_image([f"characters/{character}.{ext}" for ext in ['png', 'jpg', 'jpeg']] + ["img_bot.png","img_bot.jpg","img_bot.jpeg"]) img_me = load_html_image(["img_me.png", "img_me.jpg", "img_me.jpeg"]) for i,_row in enumerate(history[::-1]): row = [convert_to_markdown(entry) for entry in _row] - + output += f"""
@@ -142,8 +142,9 @@ def generate_chat_html(history, name1, name2, character):
""" - if not row[0]: # don't display empty user messages + if len(row[0]) == 0: # don't display empty user messages continue + output += f"""