Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add parameter for SearchAPI #11921

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions api/core/tools/provider/builtin/searchapi/tools/google_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ def results(self, query: str, **kwargs: Any) -> dict:

def get_params(self, query: str, **kwargs: Any) -> dict[str, str]:
"""Get parameters for SearchAPI."""
return {
params = {
"engine": "google_news",
"q": query,
**{key: value for key, value in kwargs.items() if value not in {None, ""}},
}
# Add all non-empty parameters
for key, value in kwargs.items():
if value not in {None, ""}:
params[key] = value
return params

@staticmethod
def _process_response(res: dict, type: str) -> str:
Expand Down Expand Up @@ -86,10 +90,12 @@ def _invoke(
gl = tool_parameters.get("gl", "us")
hl = tool_parameters.get("hl", "en")
location = tool_parameters.get("location")
time_period = tool_parameters.get("time_period", "last_month")

api_key = self.runtime.credentials["searchapi_api_key"]
result = SearchAPI(api_key).run(
query, result_type=result_type, num=num, google_domain=google_domain, gl=gl, hl=hl, location=location
query, result_type=result_type, num=num, google_domain=google_domain, gl=gl, hl=hl, location=location,
time_period=time_period
)

if result_type == "text":
Expand Down
33 changes: 33 additions & 0 deletions api/core/tools/provider/builtin/searchapi/tools/google_news.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1920,3 +1920,36 @@ parameters:
pt_BR: Specifies the number of results to display per page. Default is 10. Max number - 100, min - 1.
llm_description: Specifies the num of results to display per page.
form: llm
- name: time_period
type: select
required: false
options:
- value: last_hour
label:
en_US: Last Hour
zh_Hans: 最近一小时
- value: last_day
label:
en_US: Last 24 Hours
zh_Hans: 最近24小时
- value: last_week
label:
en_US: Last Week
zh_Hans: 最近一周
- value: last_month
label:
en_US: Last Month
zh_Hans: 最近一个月
- value: last_year
label:
en_US: Last Year
zh_Hans: 最近一年
default: last_month
label:
en_US: Time Period
zh_Hans: 时间段
human_description:
en_US: Filter results by time period
zh_Hans: 按时间段筛选结果
llm_description: Filter results by time period (last_hour, last_day, last_week, last_month, last_year)
form: form