Load and save chat history in utf-8

This commit is contained in:
Aleksey Smolenchuk 2023-03-11 21:40:01 -08:00 committed by GitHub
parent 433f6350bc
commit 3baf5fc700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -291,7 +291,7 @@ def save_history(timestamp=True):
fname = f"{prefix}persistent.json" fname = f"{prefix}persistent.json"
if not Path('logs').exists(): if not Path('logs').exists():
Path('logs').mkdir() Path('logs').mkdir()
with open(Path(f'logs/{fname}'), 'w') as f: with open(Path(f'logs/{fname}'), 'w', encoding='utf-8') as f:
f.write(json.dumps({'data': shared.history['internal'], 'data_visible': shared.history['visible']}, indent=2)) f.write(json.dumps({'data': shared.history['internal'], 'data_visible': shared.history['visible']}, indent=2))
return Path(f'logs/{fname}') return Path(f'logs/{fname}')
@ -321,7 +321,7 @@ def load_history(file, name1, name2):
def load_default_history(name1, name2): def load_default_history(name1, name2):
if Path('logs/persistent.json').exists(): if Path('logs/persistent.json').exists():
load_history(open(Path('logs/persistent.json'), 'rb').read(), name1, name2) load_history(open(Path('logs/persistent.json'), 'rb', encoding='utf-8').read(), name1, name2)
else: else:
shared.history['internal'] = [] shared.history['internal'] = []
shared.history['visible'] = [] shared.history['visible'] = []
@ -355,7 +355,7 @@ def load_character(_character, name1, name2):
name2 = shared.settings['name2_pygmalion'] name2 = shared.settings['name2_pygmalion']
if Path(f'logs/{shared.character}_persistent.json').exists(): if Path(f'logs/{shared.character}_persistent.json').exists():
load_history(open(Path(f'logs/{shared.character}_persistent.json'), 'rb').read(), name1, name2) load_history(open(Path(f'logs/{shared.character}_persistent.json'), 'rb', encoding='utf-8').read(), name1, name2)
if shared.args.cai_chat: if shared.args.cai_chat:
return name2, context, generate_chat_html(shared.history['visible'], name1, name2, shared.character) return name2, context, generate_chat_html(shared.history['visible'], name1, name2, shared.character)