From 928dea7a799798d1dbac81583e28e84da9ebc656 Mon Sep 17 00:00:00 2001 From: liunux4odoo Date: Thu, 19 Oct 2023 21:24:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=20-=20history=5Flen?= =?UTF-8?q?=3D0=20=E6=97=B6=E4=BC=9A=E5=B8=A6=E5=85=A51=E6=9D=A1=E4=B8=8D?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E7=9A=84=E5=8E=86=E5=8F=B2=E6=B6=88=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4LLM=E9=94=99=E8=AF=AF=20-=20?= =?UTF-8?q?=E5=BD=93=E5=AF=B9=E8=AF=9D=E8=BD=AE=E6=95=B0=20=E8=BE=BE?= =?UTF-8?q?=E5=88=B0history=5Flen=E6=97=B6=EF=BC=8C=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E7=9A=84=E5=8E=86=E5=8F=B2=E6=B6=88=E6=81=AF=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- streamlit_chatbox/messages.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 2c3f878..d47ee8e 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def readme(): setuptools.setup( name='streamlit-chatbox', - version='1.1.9', + version='1.1.10', author='liunux', author_email='liunux@qq.com', description='A chat box and some helpful tools used to build chatbot app with streamlit', diff --git a/streamlit_chatbox/messages.py b/streamlit_chatbox/messages.py index 9375bcb..aee1fcf 100644 --- a/streamlit_chatbox/messages.py +++ b/streamlit_chatbox/messages.py @@ -115,9 +115,9 @@ def default_filter(msg, index=None): "content": "\n\n".join(content), } - def default_stop(history): + def default_stop(r): if isinstance(history_len, int): - user_count = len([x for x in history if x["role"] == "user"]) + user_count = len([x for x in r if x["role"] == "user"]) return user_count >= history_len else: return False @@ -131,7 +131,10 @@ def default_stop(history): result = [] args_len = len(inspect.signature(filter).parameters) history = self.other_history(chat_name) + for i, msg in enumerate(history[-1::-1]): + if stop(result): + break if args_len == 1: filtered = filter(msg) else: @@ -139,9 +142,6 @@ def default_stop(history): if filtered is not None: result.insert(0, filtered) - if stop(history): - break - return result def export2md(