From 433f6350bc794e0a904e1a34abaffe49a106a484 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Mar 2023 21:21:30 -0800 Subject: [PATCH 1/3] Load and save character files in UTF-8 --- modules/chat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/chat.py b/modules/chat.py index f40f8299..a0cae949 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -332,7 +332,7 @@ def load_character(_character, name1, name2): shared.history['visible'] = [] if _character != 'None': shared.character = _character - data = json.loads(open(Path(f'characters/{_character}.json'), 'r').read()) + data = json.loads(open(Path(f'characters/{_character}.json'), 'r', encoding='utf-8').read()) name2 = data['char_name'] if 'char_persona' in data and data['char_persona'] != '': context += f"{data['char_name']}'s Persona: {data['char_persona']}\n" @@ -372,7 +372,7 @@ def upload_character(json_file, img, tavern=False): i += 1 if tavern: outfile_name = f'TavernAI-{outfile_name}' - with open(Path(f'characters/{outfile_name}.json'), 'w') as f: + with open(Path(f'characters/{outfile_name}.json'), 'w', encoding='utf-8') as f: f.write(json_file) if img is not None: img = Image.open(io.BytesIO(img)) From 3baf5fc700c603182456e7b4c3ac4c0f5e9748e8 Mon Sep 17 00:00:00 2001 From: Aleksey Smolenchuk Date: Sat, 11 Mar 2023 21:40:01 -0800 Subject: [PATCH 2/3] Load and save chat history in utf-8 --- modules/chat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/chat.py b/modules/chat.py index a0cae949..8a221526 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -291,7 +291,7 @@ def save_history(timestamp=True): fname = f"{prefix}persistent.json" if not Path('logs').exists(): 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)) return Path(f'logs/{fname}') @@ -321,7 +321,7 @@ def load_history(file, name1, name2): def load_default_history(name1, name2): 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: shared.history['internal'] = [] shared.history['visible'] = [] @@ -355,7 +355,7 @@ def load_character(_character, name1, name2): name2 = shared.settings['name2_pygmalion'] 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: return name2, context, generate_chat_html(shared.history['visible'], name1, name2, shared.character) From 3f7c3d6559a51a3b95667b3ff74d048ffb722484 Mon Sep 17 00:00:00 2001 From: Aleksey Smolenchuk Date: Sat, 11 Mar 2023 22:10:57 -0800 Subject: [PATCH 3/3] No need to set encoding on binary read --- modules/chat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/chat.py b/modules/chat.py index 8a221526..ab5dbc2d 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -321,7 +321,7 @@ def load_history(file, name1, name2): def load_default_history(name1, name2): if Path('logs/persistent.json').exists(): - load_history(open(Path('logs/persistent.json'), 'rb', encoding='utf-8').read(), name1, name2) + load_history(open(Path('logs/persistent.json'), 'rb').read(), name1, name2) else: shared.history['internal'] = [] shared.history['visible'] = [] @@ -355,7 +355,7 @@ def load_character(_character, name1, name2): name2 = shared.settings['name2_pygmalion'] if Path(f'logs/{shared.character}_persistent.json').exists(): - load_history(open(Path(f'logs/{shared.character}_persistent.json'), 'rb', encoding='utf-8').read(), name1, name2) + load_history(open(Path(f'logs/{shared.character}_persistent.json'), 'rb').read(), name1, name2) if shared.args.cai_chat: return name2, context, generate_chat_html(shared.history['visible'], name1, name2, shared.character)