Skip to content

Commit 9f68fe3

Browse files
committed
Address content and code feedback
1 parent 5585eea commit 9f68fe3

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

docs/components/action/tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ admin = Admin(
2727

2828
### 2. SearchApi Search
2929

30-
[SearchApi.io](https://searchapi.io/) provides a real-time API to access search results from Google (default), Google Scholar, Bing, Baidu, and other search engines.
30+
[SearchApi.io](https://searchapi.io/) provides a real-time API to access search results from Google (default), Google Scholar, Bing, Baidu, and other search engines. Any existing or upcoming SERP engine that returns `organic_results` is supported. The default web search engine is `google`, but it can be changed to `bing`, `baidu`, `google_news`, `bing_news`, `google_scholar`, `google_patents`, and others.
3131

3232
#### Setup API
3333

src/openagi/actions/tools/searchapi_search.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,17 @@
44
from urllib.parse import urlencode
55
from typing import Any
66

7-
from pydantic import Field, field_validator
7+
from pydantic import Field
88

99
from openagi.actions.base import BaseAction
1010
from openagi.exception import OpenAGIException
1111

1212

1313
class SearchApiSearch(BaseAction):
14-
"""SearchApi provides an easy to use API for querying web search engines and much more."""
14+
"""SearchApi.io provides a real-time API to access search results from Google (default), Google Scholar, Bing, Baidu, and other search engines."""
1515
query: str = Field(
1616
..., description="User query of type string used to fetch web search results from a search engine."
1717
)
18-
max_results: Any = Field(
19-
default=10,
20-
description="Total results, an integer, to be executed from the search. Defaults to 10",
21-
)
22-
23-
@field_validator("max_results")
24-
@classmethod
25-
def actions_validator(cls, max_results):
26-
if not max_results or not isinstance(max_results, int):
27-
logging.warning("Max Results set to 10(default).")
28-
max_results = 10
29-
return max_results
3018

3119
def execute(self):
3220
base_url = "https://www.searchapi.io/api/v1/search"
@@ -47,11 +35,10 @@ def execute(self):
4735

4836
logging.debug(json_response)
4937

50-
results = sorted(
51-
json_response.get("organic_results", []), key=lambda x: x.get("position", 0)
52-
)
38+
organic_results = json_response.get("organic_results", [])
39+
5340
meta_data = ""
54-
for info in results[:self.max_results]:
55-
meta_data += f"CONTEXT: {info['title']} \ {info['snippet']}"
56-
meta_data += f"Reference URL: {info['link']}\n"
41+
for organic_result in organic_results:
42+
meta_data += f"CONTEXT: {organic_result['title']} \ {organic_result['snippet']}"
43+
meta_data += f"Reference URL: {organic_result['link']}\n"
5744
return meta_data

0 commit comments

Comments
 (0)