From 7acbbeb2be983677140a53f4844def7d7ce96c80 Mon Sep 17 00:00:00 2001 From: srszzw <741992282@qq.com> Date: Sun, 2 Jun 2024 18:37:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=9B=B4=E6=96=B0Prompt?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E7=9F=A5=E8=AF=86=E5=BA=93=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BD=BF=E5=A4=A7=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=9B=B4=E5=AE=B9=E6=98=93=E5=88=A4=E6=96=AD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=93=AA=E4=B8=AA=E7=9F=A5=E8=AF=86=E5=BA=93=E3=80=82=20(#4121?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 1、修改知识库列表接口,返回全量属性字段,同时修改受影响的相关代码。 2、run_in_process_pool改为run_in_thread_pool,解决兼容性问题。 3、poetry配置文件修复。 * 1、动态更新Prompt中的知识库描述信息,使大模型更容易判断使用哪个知识库。 --- libs/chatchat-server/chatchat/server/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libs/chatchat-server/chatchat/server/utils.py b/libs/chatchat-server/chatchat/server/utils.py index 9fdcad52..a810c26f 100644 --- a/libs/chatchat-server/chatchat/server/utils.py +++ b/libs/chatchat-server/chatchat/server/utils.py @@ -710,12 +710,29 @@ def get_temp_dir(id: str = None) -> Tuple[str, str]: return path, id +# 动态更新知识库信息 +def update_search_local_knowledgebase_tool(): + import re + from chatchat.server.agent.tools_factory import tools_registry + from chatchat.server.db.repository.knowledge_base_repository import list_kbs_from_db + kbs=list_kbs_from_db() + template = "Use local knowledgebase from one or more of these:\n{KB_info}\n to get information,Only local data on this knowledge use this tool. The 'database' should be one of the above [{key}]." + KB_info_str = '\n'.join([f"{kb.kb_name}: {kb.kb_info}" for kb in kbs]) + KB_name_info_str = '\n'.join([f"{kb.kb_name}" for kb in kbs]) + template_knowledge = template.format(KB_info=KB_info_str, key=KB_name_info_str) + + search_local_knowledgebase_tool=tools_registry._TOOLS_REGISTRY.get("search_local_knowledgebase") + if search_local_knowledgebase_tool: + search_local_knowledgebase_tool.description = " ".join(re.split(r"\n+\s*", template_knowledge)) + + def get_tool(name: str = None) -> Union[BaseTool, Dict[str, BaseTool]]: import importlib from chatchat.server.agent import tools_factory importlib.reload(tools_factory) from chatchat.server.agent.tools_factory import tools_registry + update_search_local_knowledgebase_tool() if name is None: return tools_registry._TOOLS_REGISTRY else: