From bb7ce601fcce7cca48ba8ffd1a7f7822234cc726 Mon Sep 17 00:00:00 2001 From: liunux4odoo Date: Sun, 17 Sep 2023 13:56:57 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=90=9C=E7=B4=A2=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E9=97=AE=E7=AD=94=E6=94=AF=E6=8C=81=E5=8E=86=E5=8F=B2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=EF=BC=9B=202.=20=E4=BF=AE=E5=A4=8D=E7=9F=A5=E8=AF=86?= =?UTF-8?q?=E5=BA=93=E9=97=AE=E7=AD=94=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=BC=A0=E5=8F=82=E9=94=99=E8=AF=AF=EF=BC=9A=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E8=A2=AB=E4=BC=A0=E5=85=A5history=EF=BC=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=87=BA=E5=9C=A8webui=E4=B8=AD=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E8=8E=B7=E5=8F=96=E5=8E=86=E5=8F=B2=E6=B6=88=E6=81=AF?= =?UTF-8?q?=EF=BC=8Capi=E7=9F=A5=E8=AF=86=E5=BA=93=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=B9=B6=E6=97=A0=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/chat/knowledge_base_chat.py | 3 --- webui_pages/dialogue/dialogue.py | 2 +- webui_pages/utils.py | 2 ++ 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/server/chat/knowledge_base_chat.py b/server/chat/knowledge_base_chat.py index 7316e5e8..4c461aa6 100644 --- a/server/chat/knowledge_base_chat.py +++ b/server/chat/knowledge_base_chat.py @@ -58,9 +58,6 @@ async def knowledge_base_chat(query: str = Body(..., description="用户输入", prompt_template = get_prompt_template(prompt_name) input_msg = History(role="user", content=prompt_template).to_msg_template(False) - # 用户最后一个问题会进入PROMPT_TEMPLATE,不用再作为history 了 - if len(history) >= 1: - history.pop() chat_prompt = ChatPromptTemplate.from_messages( [i.to_msg_template() for i in history] + [input_msg]) diff --git a/webui_pages/dialogue/dialogue.py b/webui_pages/dialogue/dialogue.py index 17555362..a90d3c04 100644 --- a/webui_pages/dialogue/dialogue.py +++ b/webui_pages/dialogue/dialogue.py @@ -167,7 +167,6 @@ def dialogue_page(api: ApiRequest): chat_box.update_msg(text, streaming=False) # 更新最终的字符串,去除光标 elif dialogue_mode == "知识库问答": - history = get_messages_history(history_len) chat_box.ai_say([ f"正在查询知识库 `{selected_kb}` ...", Markdown("...", in_expander=True, title="知识库匹配结果"), @@ -196,6 +195,7 @@ def dialogue_page(api: ApiRequest): for d in api.search_engine_chat(prompt, search_engine_name=search_engine, top_k=se_top_k, + history=history, model=llm_model, temperature=temperature): if error_msg := check_error_msg(d): # check whether error occured diff --git a/webui_pages/utils.py b/webui_pages/utils.py index 4095437d..176dbb4f 100644 --- a/webui_pages/utils.py +++ b/webui_pages/utils.py @@ -429,6 +429,7 @@ class ApiRequest: query: str, search_engine_name: str, top_k: int = SEARCH_ENGINE_TOP_K, + history: List[Dict] = [], stream: bool = True, model: str = LLM_MODEL, temperature: float = TEMPERATURE, @@ -445,6 +446,7 @@ class ApiRequest: "query": query, "search_engine_name": search_engine_name, "top_k": top_k, + "history": history, "stream": stream, "model_name": model, "temperature": temperature,