跳转到内容

去中心化搜索

研究工具规范 #

基类:EventBaseToolSpec

研究工具规格。

workflows/handler.py 中的源代码llama_index/tools/desearch/base.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
class DesearchToolSpec(BaseToolSpec):
    """Desearch tool spec."""

    spec_functions = [
        "ai_search_tool",
        "twitter_search_tool",
        "web_search_tool",
    ]

    def __init__(self, api_key: str) -> None:
        """Initialize with parameters."""
        self.client = Desearch(api_key=api_key)

    def ai_search_tool(
        self,
        prompt: str = Field(description="The search prompt or query."),
        tool: List[
            Literal[
                "web",
                "hackernews",
                "reddit",
                "wikipedia",
                "youtube",
                "twitter",
                "arxiv",
            ]
        ] = Field(description="List of tools to use. Must include at least one tool."),
        model: str = Field(
            default="NOVA",
            description="The model to use for the search. Value should 'NOVA', 'ORBIT' or 'HORIZON'",
        ),
        date_filter: Optional[str] = Field(
            default=None, description="Date filter for the search."
        ),
    ) -> str | dict:
        """
        Perform a search using Desearch.

        Args:
            prompt (str): The search prompt or query.
            tool (List[Literal["web", "hackernews", "reddit", "wikipedia", "youtube", "twitter", "arxiv"]]): List of tools to use. Must include at least one tool.
            model (str, optional): The model to use for the search. Defaults to "NOVA".
            date_filter (Optional[str], optional): Date filter for the search. Defaults to None.

        Returns:
            str | dict: The search result or an error string.

        """
        try:
            return self.client.search(
                prompt,
                tool,
                model,
                date_filter,
            )
        except Exception as e:
            return str(e)

    def twitter_search_tool(
        self,
        query: str = Field(description="The Twitter search query."),
        sort: str = Field(default="Top", description="Sort order for the results."),
        count: int = Field(default=10, description="Number of results to return."),
    ) -> BasicTwitterSearchResponse:
        """
        Perform a basic Twitter search using the Exa API.

        Args:
            query (str, optional): The Twitter search query. Defaults to None.
            sort (str, optional): Sort order for the results. Defaults to "Top".
            count (int, optional): Number of results to return. Defaults to 10.

        Returns:
            BasicTwitterSearchResponse: The search results.

        Raises:
            Exception: If an error occurs when calling the API.

        """
        try:
            return self.client.basic_twitter_search(query, sort, count)
        except Exception as e:
            return str(e)

    def web_search_tool(
        self,
        query: str = Field(description="The search query."),
        num: int = Field(default=10, description="Number of results to return."),
        start: int = Field(
            default=1, description="The starting index for the search results."
        ),
    ) -> List[WebSearchResult]:
        """
        Perform a basic web search using the Exa API.

        Args:
            query (str, optional): The search query. Defaults to None.
            num (int, optional): Number of results to return. Defaults to 10.
            start (int, optional): The starting index for the search results. Defaults to 1.

        Returns:
            List[WebSearchResult]: The search results.

        Raises:
            Exception: If an error occurs when calling the API.

        """
        try:
            return self.client.basic_web_search(query, num, start)
        except Exception as e:
            return str(e)

ai_search_tool #

ai_search_tool(prompt: str = Field(description='The search prompt or query.'), tool: List[Literal['web', 'hackernews', 'reddit', 'wikipedia', 'youtube', 'twitter', 'arxiv']] = Field(description='List of tools to use. Must include at least one tool.'), model: str = Field(default='NOVA', description="The model to use for the search. Value should 'NOVA', 'ORBIT' or 'HORIZON'"), date_filter: Optional[str] = Field(default=None, description='Date filter for the search.')) -> str | dict

使用 Desearch 执行搜索。

参数:

名称 类型 描述 默认
prompt str

搜索提示或查询。

Field(description='The search prompt or query.')
tool List[Literal['web', 'hackernews', 'reddit', 'wikipedia', 'youtube', 'twitter', 'arxiv']]

要使用的工具列表。必须至少包含一个工具。

Field(description='List of tools to use. Must include at least one tool.')
model str

用于搜索的模型。默认为 "NOVA"。

Field(default='NOVA', description="The model to use for the search. Value should 'NOVA', 'ORBIT' or 'HORIZON'")
date_filter Optional[str]

搜索的日期过滤器。默认为无。

Field(default=None, description='Date filter for the search.')

返回:

类型 描述
str | dict

字符串 | 字典:搜索结果或错误字符串。

workflows/handler.py 中的源代码llama_index/tools/desearch/base.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
def ai_search_tool(
    self,
    prompt: str = Field(description="The search prompt or query."),
    tool: List[
        Literal[
            "web",
            "hackernews",
            "reddit",
            "wikipedia",
            "youtube",
            "twitter",
            "arxiv",
        ]
    ] = Field(description="List of tools to use. Must include at least one tool."),
    model: str = Field(
        default="NOVA",
        description="The model to use for the search. Value should 'NOVA', 'ORBIT' or 'HORIZON'",
    ),
    date_filter: Optional[str] = Field(
        default=None, description="Date filter for the search."
    ),
) -> str | dict:
    """
    Perform a search using Desearch.

    Args:
        prompt (str): The search prompt or query.
        tool (List[Literal["web", "hackernews", "reddit", "wikipedia", "youtube", "twitter", "arxiv"]]): List of tools to use. Must include at least one tool.
        model (str, optional): The model to use for the search. Defaults to "NOVA".
        date_filter (Optional[str], optional): Date filter for the search. Defaults to None.

    Returns:
        str | dict: The search result or an error string.

    """
    try:
        return self.client.search(
            prompt,
            tool,
            model,
            date_filter,
        )
    except Exception as e:
        return str(e)

twitter_search_tool #

twitter_search_tool(query: str = Field(description='The Twitter search query.'), sort: str = Field(default='Top', description='Sort order for the results.'), count: int = Field(default=10, description='Number of results to return.')) -> BasicTwitterSearchResponse

使用Exa API执行基本的Twitter搜索。

参数:

名称 类型 描述 默认
query str

Twitter搜索查询。默认为None。

Field(description='The Twitter search query.')
sort str

结果的排序方式。默认为"置顶"。

Field(default='Top', description='Sort order for the results.')
count int

返回的结果数量。默认为10。

Field(default=10, description='Number of results to return.')

返回:

名称 类型 描述
BasicTwitterSearchResponse BasicTwitterSearchResponse

搜索结果。

引发:

类型 描述
Exception

如果在调用API时发生错误。

workflows/handler.py 中的源代码llama_index/tools/desearch/base.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
def twitter_search_tool(
    self,
    query: str = Field(description="The Twitter search query."),
    sort: str = Field(default="Top", description="Sort order for the results."),
    count: int = Field(default=10, description="Number of results to return."),
) -> BasicTwitterSearchResponse:
    """
    Perform a basic Twitter search using the Exa API.

    Args:
        query (str, optional): The Twitter search query. Defaults to None.
        sort (str, optional): Sort order for the results. Defaults to "Top".
        count (int, optional): Number of results to return. Defaults to 10.

    Returns:
        BasicTwitterSearchResponse: The search results.

    Raises:
        Exception: If an error occurs when calling the API.

    """
    try:
        return self.client.basic_twitter_search(query, sort, count)
    except Exception as e:
        return str(e)

web_search_tool #

web_search_tool(query: str = Field(description='The search query.'), num: int = Field(default=10, description='Number of results to return.'), start: int = Field(default=1, description='The starting index for the search results.')) -> List[WebSearchResult]

使用 Exa API 执行基础网页搜索。

参数:

名称 类型 描述 默认
query str

搜索查询。默认为 None。

Field(description='The search query.')
num int

返回的结果数量。默认为10。

Field(default=10, description='Number of results to return.')
start int

搜索结果的起始索引。默认为 1。

Field(default=1, description='The starting index for the search results.')

返回:

类型 描述
List[WebSearchResult]

List[WebSearchResult]: 搜索结果。

引发:

类型 描述
Exception

如果在调用API时发生错误。

workflows/handler.py 中的源代码llama_index/tools/desearch/base.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
def web_search_tool(
    self,
    query: str = Field(description="The search query."),
    num: int = Field(default=10, description="Number of results to return."),
    start: int = Field(
        default=1, description="The starting index for the search results."
    ),
) -> List[WebSearchResult]:
    """
    Perform a basic web search using the Exa API.

    Args:
        query (str, optional): The search query. Defaults to None.
        num (int, optional): Number of results to return. Defaults to 10.
        start (int, optional): The starting index for the search results. Defaults to 1.

    Returns:
        List[WebSearchResult]: The search results.

    Raises:
        Exception: If an error occurs when calling the API.

    """
    try:
        return self.client.basic_web_search(query, num, start)
    except Exception as e:
        return str(e)

选项: 成员:- DesearchToolSpec