From 5134878344ced8cfb42bd56ff6dbd357935370f3 Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Sat, 5 Aug 2023 10:53:54 -0600 Subject: [PATCH] Fix chat message order (#3461) --- css/chat.css | 5 ++ modules/html_generator.py | 104 ++++++++++++++++++-------------------- 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/css/chat.css b/css/chat.css index 67bbe512..677d86db 100644 --- a/css/chat.css +++ b/css/chat.css @@ -79,6 +79,11 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { padding-top: 1px; } +.chat > .messages { + display: flex; + flex-direction: column; +} + .message-body li { margin-top: 0.5em !important; margin-bottom: 0.5em !important; diff --git a/modules/html_generator.py b/modules/html_generator.py index c6ca13b6..15c731c3 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -168,10 +168,21 @@ def get_image_cache(path): def generate_instruct_html(history): - output = f'
' - for i, _row in enumerate(history[::-1]): + output = f'
' + for i, _row in enumerate(history): row = [convert_to_markdown(entry) for entry in _row] + if row[0]: # don't display empty user messages + output += f""" +
+
+
+ {row[0]} +
+
+
+ """ + output += f"""
@@ -182,34 +193,38 @@ def generate_instruct_html(history):
""" - if len(row[0]) == 0: # don't display empty user messages - continue - - output += f""" -
-
-
- {row[0]} -
-
-
- """ - - output += "
" + output += "
" return output def generate_cai_chat_html(history, name1, name2, style, reset_cache=False): - output = f'
' + output = f'
' # We use ?name2 and ?time.time() to force the browser to reset caches img_bot = f'' if Path("cache/pfp_character.png").exists() else '' img_me = f'' if Path("cache/pfp_me.png").exists() else '' - for i, _row in enumerate(history[::-1]): + for i, _row in enumerate(history): row = [convert_to_markdown(entry) for entry in _row] + if row[0]: # don't display empty user messages + output += f""" +
+
+ {img_me} +
+
+
+ {name1} +
+
+ {row[0]} +
+
+
+ """ + output += f"""
@@ -226,49 +241,18 @@ def generate_cai_chat_html(history, name1, name2, style, reset_cache=False):
""" - if len(row[0]) == 0: # don't display empty user messages - continue - - output += f""" -
-
- {img_me} -
-
-
- {name1} -
-
- {row[0]} -
-
-
- """ - - output += "
" + output += "
" return output def generate_chat_html(history, name1, name2, reset_cache=False): - output = f'
' + output = f'
' - for i, _row in enumerate(history[::-1]): + for i, _row in enumerate(history): row = [convert_to_markdown(entry) for entry in _row] - output += f""" -
-
-
- {row[1]} -
-
-
- """ - - if len(row[0]) == 0: # don't display empty user messages - continue - - output += f""" + if row[0]: # don't display empty user messages + output += f"""
@@ -278,7 +262,17 @@ def generate_chat_html(history, name1, name2, reset_cache=False):
""" - output += "
" + output += f""" +
+
+
+ {row[1]} +
+
+
+ """ + + output += "
" return output