From c174c3159ea2ba730db9890897bc8c4242155296 Mon Sep 17 00:00:00 2001 From: Dani <dsapelli@yahoo.com> Date: Tue, 15 Apr 2025 19:32:25 -0400 Subject: [PATCH] Fixed an issue with the dream mechanic being broken --- trainer.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/trainer.py b/trainer.py index a6a891c..967ff67 100644 --- a/trainer.py +++ b/trainer.py @@ -1,6 +1,7 @@ import torch import torch.nn.functional as F from datetime import datetime +import os from model import MiniGPT @@ -113,6 +114,26 @@ class RubyTrainer: new_tokens = input_ids.squeeze(0).tolist()[1:] return self.tokenizer.detokenize([t for t in new_tokens if t != self.tokenizer.vocab["<END>"]]) + + def dream(self, log_path="logs/messages.log", max_lines=50): + print("[DREAM] Ruby is dreaming...") + + if not os.path.exists(log_path): + print("[DREAM] No memory to dream from.") + return + + with open(log_path, "r", encoding="utf-8") as f: + lines = f.readlines()[-max_lines:] + + learned = 0 + for line in lines: + parts = line.strip().split("|") + if len(parts) >= 3: + text = parts[2].strip() + self.train_on_tokens_from_text(text) + learned += 1 + + print(f"[DREAM] Dream complete. Trained on {learned} memories.") def daydream(self, rounds=5, log_output="logs/dreams.log", say_thought=False): print("[DAYDREAM] Ruby is imagining new thoughts...")