动态更新Prompt中的知识库描述信息,使大模型更容易判断使用哪个知识库。 (#4121)

* 1、修改知识库列表接口,返回全量属性字段,同时修改受影响的相关代码。
2、run_in_process_pool改为run_in_thread_pool,解决兼容性问题。
3、poetry配置文件修复。

* 1、动态更新Prompt中的知识库描述信息,使大模型更容易判断使用哪个知识库。
This commit is contained in:
srszzw 2024-06-02 18:37:39 +08:00 committed by GitHub
parent bc6832bc7f
commit 7acbbeb2be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 informationOnly 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: