Skip to content

Commit e7e006e

Browse files
authored
fix: use admin-configured WEB_SEARCH_RESULT_COUNT as default (open-webui#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 open-webui#23485
1 parent 803d833 commit e7e006e

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

backend/open_webui/tools/builtin.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ async def calculate_timestamp(
149149

150150
async def search_web(
151151
query: str,
152-
count: int = 5,
152+
count: Optional[int] = None,
153153
__request__: Request = None,
154154
__user__: dict = None,
155155
) -> str:
@@ -158,7 +158,7 @@ async def search_web(
158158
or topics not covered in internal documents.
159159
160160
:param query: The search query to look up
161-
:param count: Number of results to return (default: 5)
161+
:param count: Number of results to return (default: admin-configured value)
162162
:return: JSON with search results containing title, link, and snippet for each result
163163
"""
164164
if __request__ is None:
@@ -168,12 +168,9 @@ async def search_web(
168168
engine = __request__.app.state.config.WEB_SEARCH_ENGINE
169169
user = UserModel(**__user__) if __user__ else None
170170

171-
# Enforce maximum result count from config to prevent abuse
172-
count = (
173-
count
174-
if count < __request__.app.state.config.WEB_SEARCH_RESULT_COUNT
175-
else __request__.app.state.config.WEB_SEARCH_RESULT_COUNT
176-
)
171+
configured = __request__.app.state.config.WEB_SEARCH_RESULT_COUNT
172+
max_count = 5 if configured is None else configured
173+
count = max(1, min(count, max_count)) if count is not None else max_count
177174

178175
results = await asyncio.to_thread(_search_web, __request__, engine, query, user)
179176

0 commit comments

Comments
 (0)