From 8ef89730a58af8a697468822e8c3b6b670a355be Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 4 Apr 2023 23:09:28 -0300 Subject: [PATCH] Try to better handle browser image cache --- modules/chat.py | 2 +- modules/html_generator.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/chat.py b/modules/chat.py index 9af2d684..1fbda6b6 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -390,7 +390,7 @@ def load_character(character, name1, name2): shared.history['visible'] += [['', apply_extensions(greeting, "output")]] if shared.args.cai_chat: - return name1, name2, picture, greeting, context, generate_chat_html(shared.history['visible'], name1, name2) + return name1, name2, picture, greeting, context, generate_chat_html(shared.history['visible'], name1, name2, reset_cache=True) else: return name1, name2, picture, greeting, context, shared.history['visible'] diff --git a/modules/html_generator.py b/modules/html_generator.py index 98a536f8..e1c085a6 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -117,12 +117,13 @@ def get_image_cache(path): return image_cache[path][1] -def generate_chat_html(history, name1, name2): +def generate_chat_html(history, name1, name2, reset_cache=False): output = f'
' # The time.time() is to prevent the brower from caching the image - img_bot = f'' if Path("cache/pfp_character.png").exists() else '' - img_me = f'' if Path("cache/pfp_me.png").exists() else '' + suffix = f"?{time.time()}" if reset_cache else '' + 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]): row = [convert_to_markdown(entry) for entry in _row]