Add direct download for session/chat history JSONs

This commit is contained in:
oobabooga 2023-08-02 18:50:13 -07:00
parent 32a2bbee4a
commit 0e8f9354b5
5 changed files with 66 additions and 63 deletions

View file

@ -412,23 +412,6 @@ def load_history(file, history):
return history
def save_history_at_user_request(history, character, mode):
def make_timestamp_path(character=None):
return f"logs/{character or ''}{'_' if character else ''}{datetime.now().strftime('%Y%m%d-%H%M%S')}.json"
path = None
if mode in ['chat', 'chat-instruct'] and character not in ['', 'None', None]:
path = make_timestamp_path(character)
else:
# Try to use mode as the file name, otherwise just use the timestamp
try:
path = make_timestamp_path(mode.capitalize())
except:
path = make_timestamp_path()
return save_history(history, path)
def save_persistent_history(history, character, mode):
if mode in ['chat', 'chat-instruct'] and character not in ['', 'None', None] and not shared.args.multi_user:
save_history(history, path=Path(f'logs/{character}_persistent.json'))

View file

@ -15,6 +15,8 @@ with open(Path(__file__).resolve().parent / '../css/main.js', 'r') as f:
main_js = f.read()
with open(Path(__file__).resolve().parent / '../css/chat.js', 'r') as f:
chat_js = f.read()
with open(Path(__file__).resolve().parent / '../css/save_files.js', 'r') as f:
save_files_js = f.read()
refresh_symbol = '🔄'
delete_symbol = '🗑️'
@ -145,9 +147,6 @@ def gather_interface_values(*args):
if not shared.args.multi_user:
shared.persistent_interface_state = output
Path('logs').mkdir(exist_ok=True)
with open(Path(f'logs/session_{shared.get_mode()}_autosave.json'), 'w') as f:
f.write(json.dumps(output, indent=4))
return output