跳到内容

pydantic_ai.common_tools

duckduckgo_search_tool

duckduckgo_search_tool(
    duckduckgo_client: DDGS | None = None,
    max_results: int | None = None,
)

创建一个 DuckDuckGo 搜索工具。

参数

名称 类型 描述 默认值
duckduckgo_client DDGS | None

DuckDuckGo 搜索客户端。

None
max_results int | None

最大结果数。如果为 None,则仅返回来自第一个响应的结果。

None
源代码位于 pydantic_ai_slim/pydantic_ai/common_tools/duckduckgo.py
62
63
64
65
66
67
68
69
70
71
72
73
def duckduckgo_search_tool(duckduckgo_client: DDGS | None = None, max_results: int | None = None):
    """Creates a DuckDuckGo search tool.

    Args:
        duckduckgo_client: The DuckDuckGo search client.
        max_results: The maximum number of results. If None, returns results only from the first response.
    """
    return Tool(
        DuckDuckGoSearchTool(client=duckduckgo_client or DDGS(), max_results=max_results).__call__,
        name='duckduckgo_search',
        description='Searches DuckDuckGo for the given query and returns the results.',
    )

tavily_search_tool

tavily_search_tool(api_key: str)

创建一个 Tavily 搜索工具。

参数

名称 类型 描述 默认值
api_key str

Tavily API 密钥。

您可以通过访问 https://app.tavily.com/home 注册获取一个。

必需
源代码位于 pydantic_ai_slim/pydantic_ai/common_tools/tavily.py
71
72
73
74
75
76
77
78
79
80
81
82
83
def tavily_search_tool(api_key: str):
    """Creates a Tavily search tool.

    Args:
        api_key: The Tavily API key.

            You can get one by signing up at [https://app.tavily.com/home](https://app.tavily.com/home).
    """
    return Tool(
        TavilySearchTool(client=AsyncTavilyClient(api_key)).__call__,
        name='tavily_search',
        description='Searches Tavily for the given query and returns the results.',
    )