From 7c5728af3673868222ded6f06bb02f6f6d9cf03a Mon Sep 17 00:00:00 2001 From: Arjun Verma Date: Tue, 23 Jul 2024 01:33:25 +0530 Subject: [PATCH] #391 Chat Ordering based upon the order of interaction (#445) Co-authored-by: Blake R --- ragna/deploy/_ui/left_sidebar.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ragna/deploy/_ui/left_sidebar.py b/ragna/deploy/_ui/left_sidebar.py index ab8bc1c0..379acef5 100644 --- a/ragna/deploy/_ui/left_sidebar.py +++ b/ragna/deploy/_ui/left_sidebar.py @@ -1,3 +1,5 @@ +from datetime import datetime + import panel as pn import param @@ -59,6 +61,14 @@ def refresh(self): @pn.depends("refresh_counter", "chats", "current_chat_id", on_init=True) def __panel__(self): + epoch = datetime(1970, 1, 1) + self.chats.sort( + key=lambda chat: ( + epoch if not chat["messages"] else chat["messages"][-1]["timestamp"] + ), + reverse=True, + ) + self.chat_buttons = [] for chat in self.chats: button = pn.widgets.Button(