diff --git a/src/core/history.py b/src/core/history.py
index 6b9fbced..98faa01c 100644
--- a/src/core/history.py
+++ b/src/core/history.py
@@ -25,9 +25,13 @@ class HistoryManager():
self.add_ai(content)
return self.messages
- def get_history_with_msg(self, msg, role="user"):
+ def get_history_with_msg(self, msg, role="user", max_rounds=None):
"""Get history with new message, but not append it to history."""
- history = self.messages[:]
+ if max_rounds is None:
+ history = self.messages[:]
+ else:
+ history = self.messages[-(2*max_rounds):]
+
history.append({"role": role, "content": msg})
return history
diff --git a/src/views/common_view.py b/src/views/common_view.py
index 221264ad..d9445401 100644
--- a/src/views/common_view.py
+++ b/src/views/common_view.py
@@ -34,7 +34,7 @@ def chat():
new_query, refs = startup.retriever(query, history_manager.messages, meta)
- messages = history_manager.get_history_with_msg(new_query)
+ messages = history_manager.get_history_with_msg(new_query, max_rounds=meta.get('history_round'))
history_manager.add_user(query)
logger.debug(f"Web history: {history_manager}")
diff --git a/web/src/components/ChatComponent.vue b/web/src/components/ChatComponent.vue
index b7a7ac0c..e1cf86cc 100644
--- a/web/src/components/ChatComponent.vue
+++ b/web/src/components/ChatComponent.vue
@@ -43,7 +43,7 @@