From b2ab77187b4f7f1f32d4f5b057a43710ce22e345 Mon Sep 17 00:00:00 2001 From: Mustafa Olmez Date: Sat, 21 Dec 2024 02:46:53 +0300 Subject: [PATCH 1/2] adding time_period parameter for SearchAPI News --- .../builtin/searchapi/tools/google_news.py | 12 +++++-- .../builtin/searchapi/tools/google_news.yaml | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/api/core/tools/provider/builtin/searchapi/tools/google_news.py b/api/core/tools/provider/builtin/searchapi/tools/google_news.py index c8b3ccda05e195..3b31fdb7078c5e 100644 --- a/api/core/tools/provider/builtin/searchapi/tools/google_news.py +++ b/api/core/tools/provider/builtin/searchapi/tools/google_news.py @@ -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: @@ -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": diff --git a/api/core/tools/provider/builtin/searchapi/tools/google_news.yaml b/api/core/tools/provider/builtin/searchapi/tools/google_news.yaml index ff34af34cc9f5c..bde8d58572ead3 100644 --- a/api/core/tools/provider/builtin/searchapi/tools/google_news.yaml +++ b/api/core/tools/provider/builtin/searchapi/tools/google_news.yaml @@ -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 From 0ce416d1fa7a6b0f92d2b46f47a403fe574ec128 Mon Sep 17 00:00:00 2001 From: Mustafa Olmez <62564479+mmustafaolmez@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:58:21 +0300 Subject: [PATCH 2/2] Update google_news.py --- api/core/tools/provider/builtin/searchapi/tools/google_news.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/core/tools/provider/builtin/searchapi/tools/google_news.py b/api/core/tools/provider/builtin/searchapi/tools/google_news.py index 3b31fdb7078c5e..d8c5d09d99848a 100644 --- a/api/core/tools/provider/builtin/searchapi/tools/google_news.py +++ b/api/core/tools/provider/builtin/searchapi/tools/google_news.py @@ -90,7 +90,7 @@ 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") + time_period = tool_parameters.get("time_period", "last_month") api_key = self.runtime.credentials["searchapi_api_key"] result = SearchAPI(api_key).run(