Skip to content

Commit

Permalink
adding time_period parameter for SearchAPI News
Browse files Browse the repository at this point in the history
  • Loading branch information
mmustafaolmez committed Dec 20, 2024
1 parent f53741c commit b2ab771
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
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

0 comments on commit b2ab771

Please sign in to comment.