feat(chat): robust thread support (complex)
This commit is contained in:
1 parent
c588a12160
commit
73b789b586
3 files changed
+81
-20
No files matched your search
@@ -17,6 +17,17 @@ def message_json(msg):
|
||||
"threadId": msg.thread_id,
|
||||
}
|
||||
|
||||
def thread_json(it):
|
||||
return {
|
||||
'id': it.id,
|
||||
'parentId': it.parent_id,
|
||||
'name': it.name,
|
||||
'description': it.description,
|
||||
'firstMessageId': it.first_message_id,
|
||||
'lastMessageId': it.last_message_id,
|
||||
'messageCount': it.message_count,
|
||||
}
|
||||
|
||||
async def aggregate_thread(thread_id):
|
||||
print(f"aggregate {thread_id}")
|
||||
query = db.Message.filter(thread_id=thread_id)
|
||||
@@ -126,15 +137,7 @@ class ChatMixin:
|
||||
|
||||
async def get_chat_threads(self, chat_id):
|
||||
threads = await db.Thread.filter(chat_id=chat_id).all()
|
||||
return [{
|
||||
'id': it.id,
|
||||
'parentId': it.parent_id,
|
||||
'name': it.name,
|
||||
'description': it.description,
|
||||
'firstMessageId': it.first_message_id,
|
||||
'lastMessageId': it.last_message_id,
|
||||
'messageCount': it.message_count,
|
||||
} for it in threads]
|
||||
return [thread_json(it) for it in threads]
|
||||
|
||||
async def get_thread_messages(self, chat_id, thread_id, limit_message_id=None):
|
||||
chat = await self.get_chat(chat_id)
|
||||
@@ -171,6 +174,16 @@ class ChatMixin:
|
||||
for msg in messages:
|
||||
self.notify_message_to_user(chat.user_id, msg, True)
|
||||
|
||||
|
||||
# Manually notify thread updates
|
||||
if chat.user_id in self.user_connections:
|
||||
children = await db.Thread.filter(parent_id=new_id).all()
|
||||
packets = [dict(thread_json(it), action='thread-update') for it in children]
|
||||
|
||||
for channel in self.user_connections[chat.user_id]:
|
||||
for packet in packets:
|
||||
asyncio.create_task(channel.put(packet))
|
||||
|
||||
return new_id
|
||||
|
||||
async def add_agent_to_chat(self, chat_id, agent_id):
|
||||
|
||||
@@ -154,7 +154,7 @@ async def chat_completion(app,
|
||||
agent_run=None
|
||||
):
|
||||
# TESTING OVERRIDE
|
||||
return await mock_completion(app, agent_run)
|
||||
# return await mock_completion(app, agent_run)
|
||||
db_model = (await app.get_model(model_id)).value
|
||||
|
||||
model_engine = db_model['engine']
|
||||
|
||||
Reference in new issue
Block a user