跳过内容

Tavily 研究

TavilyToolSpec #

基类:BaseToolSpec

Tavily 工具规范。

源代码位于 llama-index-integrations/tools/llama-index-tools-tavily-research/llama_index/tools/tavily_research/base.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class TavilyToolSpec(BaseToolSpec):
    """Tavily tool spec."""

    spec_functions = [
        "search",
    ]

    def __init__(self, api_key: str) -> None:
        """Initialize with parameters."""
        from tavily import TavilyClient

        self.client = TavilyClient(api_key=api_key)

    def search(self, query: str, max_results: Optional[int] = 6) -> List[Document]:
        """
        Run query through Tavily Search and return metadata.

        Args:
            query: The query to search for.
            max_results: The maximum number of results to return.

        Returns:
            results: A list of dictionaries containing the results:
                url: The url of the result.
                content: The content of the result.

        """
        response = self.client.search(
            query, max_results=max_results, search_depth="advanced"
        )
        return [
            Document(text=result["content"], extra_info={"url": result["url"]})
            for result in response["results"]
        ]

搜索 #

search(query: str, max_results: Optional[int] = 6) -> List[Document]

通过 Tavily Search 运行查询并返回元数据。

参数

名称 类型 描述 默认值
query str

要搜索的查询。

必需
max_results 可选[整数]

要返回的最大结果数。

6

返回

名称 类型 描述
results 列表[文档]

包含结果的字典列表:url:结果的 URL。content:结果的内容。

源代码位于 llama-index-integrations/tools/llama-index-tools-tavily-research/llama_index/tools/tavily_research/base.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def search(self, query: str, max_results: Optional[int] = 6) -> List[Document]:
    """
    Run query through Tavily Search and return metadata.

    Args:
        query: The query to search for.
        max_results: The maximum number of results to return.

    Returns:
        results: A list of dictionaries containing the results:
            url: The url of the result.
            content: The content of the result.

    """
    response = self.client.search(
        query, max_results=max_results, search_depth="advanced"
    )
    return [
        Document(text=result["content"], extra_info={"url": result["url"]})
        for result in response["results"]
    ]