From 25280e0cea19c21205c431c0bfb2192c5c49b188 Mon Sep 17 00:00:00 2001 From: liunux4odoo Date: Wed, 9 Aug 2023 14:11:10 +0800 Subject: [PATCH] update webui: use history_len as pairs of conversation --- webui_pages/dialogue/dialogue.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/webui_pages/dialogue/dialogue.py b/webui_pages/dialogue/dialogue.py index 87ac9ee..f82cc8a 100644 --- a/webui_pages/dialogue/dialogue.py +++ b/webui_pages/dialogue/dialogue.py @@ -19,8 +19,15 @@ def get_messages_history(history_len: int) -> List[Dict]: "role": msg["role"], "content": content[0] if content else "", } - history = chat_box.filter_history(history_len, filter) - return history + history = chat_box.filter_history(100000, filter) # workaround before upgrading streamlit-chatbox. + user_count = 0 + i = 1 + for i in range(1, len(history) + 1): + if history[-i]["role"] == "user": + user_count += 1 + if user_count >= history_len: + break + return history[-i:] def dialogue_page(api: ApiRequest):