import os import time from model.trainer import train_on_message import random JOURNAL_PATH = "data/memory/journal.txt" def record_to_journal(thought: str): os.makedirs(os.path.dirname(JOURNAL_PATH), exist_ok=True) with open(JOURNAL_PATH, "a", encoding="utf-8") as f: f.write(f"{time.strftime('%Y-%m-%d %H:%M:%S')} | {thought.strip()}\n") def read_journal_entries(): if not os.path.exists(JOURNAL_PATH): return [] with open(JOURNAL_PATH, "r", encoding="utf-8") as f: lines = f.readlines() return [line.split("|", 1)[-1].strip() for line in lines if "|" in line] def replay_journal(): entries = read_journal_entries() for entry in random.sample(entries, min(5, len(entries))): train_on_message(entry)