Fixed Reader so it does more lines
Added a memory re-wirer updated the dream_replay
This commit is contained in:
parent
8af477957c
commit
684bf33675
2
main.py
2
main.py
@ -9,6 +9,7 @@ from model.cleanup import full_cleanup
|
|||||||
from model.dream_replay import replay_dreams
|
from model.dream_replay import replay_dreams
|
||||||
from model.rehearsal import simulate_conversation
|
from model.rehearsal import simulate_conversation
|
||||||
from model.scheduler import set_next_action
|
from model.scheduler import set_next_action
|
||||||
|
from model.reweaver import memory_reweaver_loop
|
||||||
from reader.reader import read_books_forever
|
from reader.reader import read_books_forever
|
||||||
from dashboard.dashboard import run_dashboard
|
from dashboard.dashboard import run_dashboard
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ def start_brain_loops():
|
|||||||
loop.create_task(dream_replay_loop())
|
loop.create_task(dream_replay_loop())
|
||||||
loop.create_task(background_cleanup_loop())
|
loop.create_task(background_cleanup_loop())
|
||||||
loop.create_task(rehearsal_loop())
|
loop.create_task(rehearsal_loop())
|
||||||
|
loop.create_task(memory_reweaver_loop())
|
||||||
|
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
|
|
||||||
|
@ -2,17 +2,26 @@ import random
|
|||||||
from model.memory import load_dreams
|
from model.memory import load_dreams
|
||||||
from model.trainer import train_on_message
|
from model.trainer import train_on_message
|
||||||
from model.dynamic_expand import expand_model_if_needed
|
from model.dynamic_expand import expand_model_if_needed
|
||||||
|
from context.context import load_context
|
||||||
|
|
||||||
|
|
||||||
def replay_dreams():
|
def replay_dreams():
|
||||||
expand_model_if_needed()
|
expand_model_if_needed()
|
||||||
|
|
||||||
dreams = load_dreams()
|
dreams = load_dreams()
|
||||||
if not dreams:
|
context = load_context()
|
||||||
|
|
||||||
|
if not dreams or not context:
|
||||||
return
|
return
|
||||||
|
|
||||||
selected = random.sample(dreams, min(len(dreams), 5))
|
selected_dreams = random.sample(dreams, min(len(dreams), 5))
|
||||||
for dream in selected:
|
selected_contexts = random.sample(context, min(len(context), 5))
|
||||||
text = dream["sentence"]
|
|
||||||
if text:
|
# Mix dreams and past contexts into a chaotic dream
|
||||||
train_on_message(text)
|
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")
|
||||||
|
20
model/reweaver.py
Normal file
20
model/reweaver.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import random
|
||||||
|
from context.context import load_context
|
||||||
|
from model.trainer import train_on_message
|
||||||
|
from model.dynamic_expand import expand_model_if_needed
|
||||||
|
|
||||||
|
|
||||||
|
async def memory_reweaver_loop():
|
||||||
|
while True:
|
||||||
|
await asyncio.sleep(600) # every 10 minutes
|
||||||
|
expand_model_if_needed()
|
||||||
|
|
||||||
|
context = load_context()
|
||||||
|
if not context:
|
||||||
|
return
|
||||||
|
|
||||||
|
selected = random.sample(context, min(len(context), 10))
|
||||||
|
combined_text = " ".join([s["text"] for s in selected])
|
||||||
|
|
||||||
|
if combined_text:
|
||||||
|
train_on_message(combined_text, source="reweaver")
|
@ -29,6 +29,8 @@ def save_progress(prog):
|
|||||||
async def read_books_forever():
|
async def read_books_forever():
|
||||||
books = get_books()
|
books = get_books()
|
||||||
progress = load_progress()
|
progress = load_progress()
|
||||||
|
buffered_lines = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for book in books:
|
for book in books:
|
||||||
path = os.path.join(BOOK_DIR, book)
|
path = os.path.join(BOOK_DIR, book)
|
||||||
@ -46,6 +48,19 @@ async def read_books_forever():
|
|||||||
save_progress(progress)
|
save_progress(progress)
|
||||||
|
|
||||||
if is_valid_line(line):
|
if is_valid_line(line):
|
||||||
train_on_message(line, source="book")
|
buffered_lines.append(line)
|
||||||
|
|
||||||
|
# If we have enough lines buffered, combine and train
|
||||||
|
if len(buffered_lines) >= 3:
|
||||||
|
combined_text = " ".join(buffered_lines)
|
||||||
|
train_on_message(combined_text, source="book")
|
||||||
|
buffered_lines.clear()
|
||||||
|
|
||||||
set_next_action(READ_DELAY, "Reading")
|
set_next_action(READ_DELAY, "Reading")
|
||||||
await asyncio.sleep(READ_DELAY)
|
await asyncio.sleep(READ_DELAY)
|
||||||
|
|
||||||
|
# End of a book: train whatever lines are left buffered
|
||||||
|
if buffered_lines:
|
||||||
|
combined_text = " ".join(buffered_lines)
|
||||||
|
train_on_message(combined_text, source="book")
|
||||||
|
buffered_lines.clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user