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(