只有当启用搜索的时候才会加载网络搜索

This commit is contained in:
Wenjie Zhang 2025-04-08 00:35:29 +08:00
parent c83e5818bb
commit 1084d62891
2 changed files with 5 additions and 3 deletions

View File

@ -8,7 +8,7 @@ from pydantic import BaseModel, Field
from langchain_core.tools import tool, BaseTool, StructuredTool
from langchain_community.tools.tavily_search import TavilySearchResults
from src import graph_base, knowledge_base
from src import graph_base, knowledge_base, config
# refs https://github.com/chatchat-space/LangGraph-Chatchat chatchat-server/chatchat/server/agent/tools_factory/tools_registry.py
def regist_tool(
@ -136,6 +136,8 @@ def get_knowledge_graph(query: Annotated[str, "The query to get knowledge graph.
_TOOLS_REGISTRY = {
"calculator": calculator,
"TavilySearchResults": TavilySearchResults(max_results=10),
"get_knowledge_graph": get_knowledge_graph,
}
if config.enable_web_search:
_TOOLS_REGISTRY["TavilySearchResults"] = TavilySearchResults(max_results=10)

View File

@ -120,7 +120,7 @@ class Retriever:
def query_web(self, query, history, refs):
"""查询网络"""
if not (refs["meta"].get("use_web") and config.enable_web_search):
if not (refs["meta"].get("use_web") or not config.enable_web_search):
return {"results": [], "message": "Web search is disabled"}
try: