报错
pydantic_core._pydantic_core.ValidationError: 1 validation error for TavilySearchAPIWrapper
Value error, Did not find tavily_api_key, please add an environment variable `TAVILY_API_KEY` which contains it, or pass `tavily_api_key` as a named parameter. [type=value_error, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.10/v/value_error
需要自己配置环境变量
import os
from langchain_community.tools.tavily_search import TavilySearchResults
# 设置Tavily API密钥为环境变量,确保工具能获取到
os.environ["TAVILY_API_KEY"] = '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'#用自己的
tool = TavilySearchResults(max_results=2)
tools = [tool]
result = tool.invoke("What's a 'node' in LangGraph?")
print(result)
这种也能调用
from tavily import TavilyClient
TAVILY_API_KEY = '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'
# Step 1. Instantiating your TavilyClient
tavily_client = TavilyClient(api_key=TAVILY_API_KEY)
# Step 2. Executing a simple search query
response = tavily_client.search("今天成都的天气怎么样?")
# Step 3. That's it! You've done a Tavily Search!
print(response)
我的key当然不能用