File size: 402 Bytes
e394327 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import json
import os
SAVE_DIR = "logs/"
def save_conversation(session_id, history):
os.makedirs(SAVE_DIR, exist_ok=True)
with open(f"{SAVE_DIR}/{session_id}.json", "w") as f:
json.dump(history, f)
def load_conversation(session_id):
try:
with open(f"{SAVE_DIR}/{session_id}.json", "r") as f:
return json.load(f)
except FileNotFoundError:
return [] |