Update the export/load chat history functions

This commit is contained in:
oobabooga 2023-01-27 02:16:05 -03:00
parent 6b5dcd46c5
commit 70e034589f

View File

@ -443,7 +443,7 @@ if args.chat or args.cai_chat:
if not Path('logs').exists(): if not Path('logs').exists():
Path('logs').mkdir() Path('logs').mkdir()
with open(Path('logs/conversation.json'), 'w') as f: with open(Path('logs/conversation.json'), 'w') as f:
f.write(json.dumps({'data': history['internal']}, indent=2)) f.write(json.dumps({'data': history['internal'], 'data_visible': history['visible']}))
return Path('logs/conversation.json') return Path('logs/conversation.json')
def upload_history(file, name1, name2): def upload_history(file, name1, name2):
@ -453,6 +453,10 @@ if args.chat or args.cai_chat:
j = json.loads(file) j = json.loads(file)
if 'data' in j: if 'data' in j:
history['internal'] = j['data'] history['internal'] = j['data']
if 'data_visible' in j:
history['visible'] = j['data_visible']
else:
history['visible'] = history['internal']
# Compatibility with Pygmalion AI's official web UI # Compatibility with Pygmalion AI's official web UI
elif 'chat' in j: elif 'chat' in j:
history['internal'] = [':'.join(x.split(':')[1:]).strip() for x in j['chat']] history['internal'] = [':'.join(x.split(':')[1:]).strip() for x in j['chat']]
@ -462,6 +466,7 @@ if args.chat or args.cai_chat:
history['internal'] = [[history['internal'][i], history['internal'][i+1]] for i in range(0, len(history['internal'])-1, 2)] history['internal'] = [[history['internal'][i], history['internal'][i+1]] for i in range(0, len(history['internal'])-1, 2)]
except: except:
history['internal'] = tokenize_dialogue(file, name1, name2) history['internal'] = tokenize_dialogue(file, name1, name2)
history['visible'] = history['internal']
def load_character(_character, name1, name2): def load_character(_character, name1, name2):
global history, character global history, character