Full memory storing and retrieval for conversation agent. Update gral prompts. Add custom inference model.

This commit is contained in:
Shivering Ocelot committed 2025-06-28 00:59:56 -05:00
1 parent 3c3febb92d
commit e9ebb1378a
5 files changed
+196 -50

No files matched your search

+12 -12
View File
@@ -4,6 +4,8 @@ from sqlalchemy.sql.expression import select
import database as db
MESSAGE_PAGE_SIZE = 256
class Message:
def __init__(self, id, content, sender, time=None):
self.id = id
@@ -49,7 +51,7 @@ class ChatView:
self._earliest_message_id = None
self._load_basic_data()
self._load_next_messages(20)
self._load_next_messages(MESSAGE_PAGE_SIZE)
def _load_basic_data(self):
with self.app.sql_session() as session:
@@ -65,20 +67,22 @@ class ChatView:
def _load_next_messages(self, load_count):
with self.app.sql_session() as session:
records = session.execute(
records_rev = session.execute(
select(db.Message).where(
db.Message.chat_id == self.chat_id,
self._earliest_message_id == None or db.Message.id <= self._earliest_message_id
).order_by(db.Message.time.asc())
).order_by(db.Message.time.desc())
).scalars().fetchmany(load_count)
print(f"Loaded messages. Threads: {bool(self.threads)}, records: {bool(records)}")
if not self.threads and records:
print(f"Last Record: ", records[-1])
self.current_thread_id = records[-1].thread_id
# Update the earliest id for the next load operation
if records_rev:
self._earliest_message_id = records_rev[0].id
if not self.threads:
# current thread is the latest known
self.current_thread_id = records_rev[-1].thread_id
# Go over messages from newest to oldest
for record in reversed(records):
for record in records_rev:
if record.thread_id == None:
thread = self.default_thread
else:
@@ -90,10 +94,6 @@ class ChatView:
# This is the oldest message so far, add it to the start of the chat
message = Message(record.id, record.content, record.sender, record.time)
thread.messages.insert(0, message)
# Update the earliest id for the next load operation
if records:
self._earliest_message_id = records[0].id
def get_thread(self, thread_id):
if thread_id == None: