From e7e006e78156288dc4308ea018dee1611019ac30 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 8 Apr 2026 22:13:44 +0200 Subject: [PATCH] fix: use admin-configured WEB_SEARCH_RESULT_COUNT as default (#23488) The built-in search_web tool hardcoded count=5 as the default, ignoring the admin-configured WEB_SEARCH_RESULT_COUNT setting. When the LLM did not specify a count, the tool always returned 5 results regardless of admin configuration. Now the tool defaults to the admin-configured value when the LLM omits the count parameter, while still capping LLM-requested values at the admin maximum to prevent abuse. Closes #23485 --- backend/open_webui/tools/builtin.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/tools/builtin.py b/backend/open_webui/tools/builtin.py index 3c63d318c..1823e71df 100644 --- a/backend/open_webui/tools/builtin.py +++ b/backend/open_webui/tools/builtin.py @@ -149,7 +149,7 @@ async def calculate_timestamp( async def search_web( query: str, - count: int = 5, + count: Optional[int] = None, __request__: Request = None, __user__: dict = None, ) -> str: @@ -158,7 +158,7 @@ async def search_web( or topics not covered in internal documents. :param query: The search query to look up - :param count: Number of results to return (default: 5) + :param count: Number of results to return (default: admin-configured value) :return: JSON with search results containing title, link, and snippet for each result """ if __request__ is None: @@ -168,12 +168,9 @@ async def search_web( engine = __request__.app.state.config.WEB_SEARCH_ENGINE user = UserModel(**__user__) if __user__ else None - # Enforce maximum result count from config to prevent abuse - count = ( - count - if count < __request__.app.state.config.WEB_SEARCH_RESULT_COUNT - else __request__.app.state.config.WEB_SEARCH_RESULT_COUNT - ) + configured = __request__.app.state.config.WEB_SEARCH_RESULT_COUNT + max_count = 5 if configured is None else configured + count = max(1, min(count, max_count)) if count is not None else max_count results = await asyncio.to_thread(_search_web, __request__, engine, query, user)