Merge pull request #142 from xerrors/fix-tavily_api_key-error

只有当启用搜索的时候才会加载网络搜索
This commit is contained in:
Wenjie Zhang 2025-04-08 00:37:12 +08:00 committed by GitHub
commit 0ea587f8f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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: