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..d8c5d09d99848a 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