mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-19 13:23:16 +08:00
动态更新Prompt中的知识库描述信息,使大模型更容易判断使用哪个知识库。 (#4121)
* 1、修改知识库列表接口,返回全量属性字段,同时修改受影响的相关代码。 2、run_in_process_pool改为run_in_thread_pool,解决兼容性问题。 3、poetry配置文件修复。 * 1、动态更新Prompt中的知识库描述信息,使大模型更容易判断使用哪个知识库。
This commit is contained in:
parent
bc6832bc7f
commit
7acbbeb2be
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user