import random from model.memory import load_dreams from model.trainer import train_on_message from model.dynamic_expand import expand_model_if_needed from context.context import load_context def replay_dreams(): expand_model_if_needed() dreams = load_dreams() context = load_context() if not dreams or not context: return selected_dreams = random.sample(dreams, min(len(dreams), 5)) selected_contexts = random.sample(context, min(len(context), 5)) # Mix dreams and past contexts into a chaotic dream all_sources = [d["sentence"] for d in selected_dreams] + [c["text"] for c in selected_contexts] random.shuffle(all_sources) mixed_sentence = " ".join(random.sample(all_sources, min(len(all_sources), 3))) if mixed_sentence: train_on_message(mixed_sentence, source="dream")