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 @@ 选项
-
+
知识库
@@ -65,21 +65,24 @@
-
+
图数据库
-
+
搜索引擎(Bing)
-
+
重写查询
-
+
流式输出
-
+
总结对话标题
+
+ 最大历史轮数 +
@@ -216,6 +219,7 @@ const meta = reactive(JSON.parse(localStorage.getItem('meta')) || { selectedKB: null, stream: true, summary_title: true, + history_round: 5, }) // 更多选项可以在 marked 文档中找到:https://marked.js.org/ @@ -517,9 +521,6 @@ watch( justify-content: space-between; align-items: center; gap: 10px; - } - - .graphbase { padding: 8px 16px; border-radius: 12px; cursor: pointer;