Ruby/model/dreams.py
Dani a8b3129806 Redid the dashboard home page into more of a status page.
Fixed the weird desync/threading issue that was stopping ruby from working.
2025-04-29 23:04:53 -04:00

24 lines
672 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 []
try:
with open(DREAM_LOG_PATH, "r", encoding="utf-8") as f:
return json.load(f)
except json.JSONDecodeError:
print("[Dreams] Failed to parse dreams.json.")
return []
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)