Try to better handle browser image cache

This commit is contained in:
oobabooga 2023-04-04 23:09:28 -03:00
parent cc6c7a37f3
commit 8ef89730a5
2 changed files with 5 additions and 4 deletions

View File

@ -390,7 +390,7 @@ def load_character(character, name1, name2):
shared.history['visible'] += [['', apply_extensions(greeting, "output")]] shared.history['visible'] += [['', apply_extensions(greeting, "output")]]
if shared.args.cai_chat: 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: else:
return name1, name2, picture, greeting, context, shared.history['visible'] return name1, name2, picture, greeting, context, shared.history['visible']

View File

@ -117,12 +117,13 @@ def get_image_cache(path):
return image_cache[path][1] return image_cache[path][1]
def generate_chat_html(history, name1, name2): def generate_chat_html(history, name1, name2, reset_cache=False):
output = f'<style>{cai_css}</style><div class="chat" id="chat">' output = f'<style>{cai_css}</style><div class="chat" id="chat">'
# The time.time() is to prevent the brower from caching the image # The time.time() is to prevent the brower from caching the image
img_bot = f'<img src="file/cache/pfp_character.png?{time.time()}">' if Path("cache/pfp_character.png").exists() else '' suffix = f"?{time.time()}" if reset_cache else ''
img_me = f'<img src="file/cache/pfp_me.png?{time.time()}">' if Path("cache/pfp_me.png").exists() else '' img_bot = f'<img src="file/cache/pfp_character.png{suffix}">' if Path("cache/pfp_character.png").exists() else ''
img_me = f'<img src="file/cache/pfp_me.png{suffix}">' if Path("cache/pfp_me.png").exists() else ''
for i,_row in enumerate(history[::-1]): for i,_row in enumerate(history[::-1]):
row = [convert_to_markdown(entry) for entry in _row] row = [convert_to_markdown(entry) for entry in _row]