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 []