Ruby/model/memory.py
2025-04-24 13:23:54 -04:00

20 lines
549 B
Python

import json
import os
DREAM_LOG_PATH = "data/memory/dreams.json"
def load_dreams():
if not os.path.exists(DREAM_LOG_PATH):
return []
with open(DREAM_LOG_PATH, "r", encoding="utf-8") as f:
return json.load(f)
def save_dream(sentence: str, score: float):
dreams = load_dreams()
dreams.append({"sentence": sentence, "score": round(score, 2)})
dreams = sorted(dreams, key=lambda x: x["score"], reverse=True)[:100]
with open(DREAM_LOG_PATH, "w", encoding="utf-8") as f:
json.dump(dreams, f, indent=2)