Updated DayDream to let her dream more

This commit is contained in:
Dani 2025-04-15 13:12:40 -04:00
parent 3020e230ff
commit 3829ca8d01
2 changed files with 21 additions and 6 deletions

View File

@ -65,6 +65,8 @@ class Ruby(discord.Client):
for guild in self.guilds: for guild in self.guilds:
for channel in guild.text_channels: for channel in guild.text_channels:
if channel.permissions_for(guild.me).send_messages: if channel.permissions_for(guild.me).send_messages:
if not thought.endswith("."):
thought += "."
await channel.send(f"(dreaming) {thought}") await channel.send(f"(dreaming) {thought}")
break break
break # only post to one server/channel break # only post to one server/channel

View File

@ -2,7 +2,7 @@ import torch
import torch.nn as nn import torch.nn as nn
import torch.nn.functional as F import torch.nn.functional as F
import os import os
from datetime import datetime
class MiniGPT(nn.Module): class MiniGPT(nn.Module):
@ -90,7 +90,7 @@ class RubyTrainer:
print(f"[TRAIN] Tokens: {tokens} | Loss: {loss.item():.4f}") 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() self.model.eval()
input_ids = torch.tensor([[self.tokenizer.vocab["<START>"]]], dtype=torch.long, device=self.device) input_ids = torch.tensor([[self.tokenizer.vocab["<START>"]]], dtype=torch.long, device=self.device)
@ -112,6 +112,9 @@ class RubyTrainer:
next_token = next_token.view(1, 1) next_token = next_token.view(1, 1)
input_ids = torch.cat([input_ids, next_token], dim=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["<END>"]] = float("-inf")
if next_token.item() == self.tokenizer.vocab["<END>"]: if next_token.item() == self.tokenizer.vocab["<END>"]:
break break
@ -144,9 +147,14 @@ class RubyTrainer:
def daydream(self, rounds=5, log_output="logs/dreams.log", say_thought=False): def daydream(self, rounds=5, log_output="logs/dreams.log", say_thought=False):
print("[DAYDREAM] Ruby is imagining new thoughts...") print("[DAYDREAM] Ruby is imagining new thoughts...")
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() thought = self.generate_reply()
if thought.strip(): attempts += 1
if thought and len(thought.strip().split()) >= 4:
self.train_on_tokens_from_text(thought) self.train_on_tokens_from_text(thought)
thoughts.append(thought) thoughts.append(thought)
@ -154,10 +162,15 @@ class RubyTrainer:
for t in thoughts: for t in thoughts:
f.write(f"[DAYDREAM] {t}\n") 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: if say_thought and thoughts:
return thoughts[-1] # last thought spoken aloud return thoughts[-1]
return None return None
def reinforce_core_memory(self, log_output="logs/dreams.log"): def reinforce_core_memory(self, log_output="logs/dreams.log"):