From 3829ca8d01ea8f6cf0d66be1037421a88d6e9e6b Mon Sep 17 00:00:00 2001 From: Dani Date: Tue, 15 Apr 2025 13:12:40 -0400 Subject: [PATCH] Updated DayDream to let her dream more --- main.py | 2 ++ model.py | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 97585bd..085a087 100644 --- a/main.py +++ b/main.py @@ -65,6 +65,8 @@ class Ruby(discord.Client): for guild in self.guilds: for channel in guild.text_channels: if channel.permissions_for(guild.me).send_messages: + if not thought.endswith("."): + thought += "." await channel.send(f"(dreaming) {thought}") break break # only post to one server/channel diff --git a/model.py b/model.py index e1a51fd..915a467 100644 --- a/model.py +++ b/model.py @@ -2,7 +2,7 @@ import torch import torch.nn as nn import torch.nn.functional as F import os - +from datetime import datetime class MiniGPT(nn.Module): @@ -90,7 +90,7 @@ class RubyTrainer: print(f"[TRAIN] Tokens: {tokens} | Loss: {loss.item():.4f}") - def generate_reply(self, max_tokens=30, temperature=1.0, top_k=5): + def generate_reply(self, max_tokens=50, temperature=1.2, top_k=10): self.model.eval() input_ids = torch.tensor([[self.tokenizer.vocab[""]]], dtype=torch.long, device=self.device) @@ -112,6 +112,9 @@ class RubyTrainer: next_token = next_token.view(1, 1) input_ids = torch.cat([input_ids, next_token], dim=1) + if input_ids.size(1) < 5: # prevent ending too early + logits[0, self.tokenizer.vocab[""]] = float("-inf") + if next_token.item() == self.tokenizer.vocab[""]: break @@ -144,9 +147,14 @@ class RubyTrainer: def daydream(self, rounds=5, log_output="logs/dreams.log", say_thought=False): print("[DAYDREAM] Ruby is imagining new thoughts...") thoughts = [] - for _ in range(rounds): + max_attempts = rounds * 3 # allows retries for short/empty outputs + attempts = 0 + + while len(thoughts) < rounds and attempts < max_attempts: thought = self.generate_reply() - if thought.strip(): + attempts += 1 + + if thought and len(thought.strip().split()) >= 4: self.train_on_tokens_from_text(thought) thoughts.append(thought) @@ -154,10 +162,15 @@ class RubyTrainer: for t in thoughts: f.write(f"[DAYDREAM] {t}\n") - print(f"[DAYDREAM] Complete. {len(thoughts)} thoughts imagined.") + # Loop dreams back into message log (optional) + with open("logs/messages.log", "a", encoding="utf-8") as f: + for t in thoughts: + f.write(f"{datetime.utcnow().isoformat()} | Ruby | {t}\n") + + print(f"[DAYDREAM] Complete. {len(thoughts)} thoughts imagined (in {attempts} attempts).") if say_thought and thoughts: - return thoughts[-1] # last thought spoken aloud + return thoughts[-1] return None def reinforce_core_memory(self, log_output="logs/dreams.log"):