Skip to content

Commit

Permalink
动态更新Prompt中的知识库描述信息,使大模型更容易判断使用哪个知识库。 (#4121)
Browse files Browse the repository at this point in the history
* 1、修改知识库列表接口,返回全量属性字段,同时修改受影响的相关代码。
2、run_in_process_pool改为run_in_thread_pool,解决兼容性问题。
3、poetry配置文件修复。

* 1、动态更新Prompt中的知识库描述信息,使大模型更容易判断使用哪个知识库。
  • Loading branch information
srszzw committed Jun 2, 2024
1 parent bc6832b commit 7acbbeb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions libs/chatchat-server/chatchat/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7acbbeb

Please sign in to comment.