Skip to content

Commit 7ea1e9c

Browse files
fix: Prefer model-provided web search result count over admin default (open-webui#22577)
* Prefer model-provided web search result count over admin default Update `search_web` to prioritize the model-provided `count` parameter before falling back to the admin-configured `WEB_SEARCH_RESULT_COUNT`, and finally defaulting to 5. Changes: - Set `count` default to `None` instead of `5`. - Adjust fallback order to: model-provided `count` → admin-configured value → `5`. - Update comment to reflect the new precedence logic. This ensures explicit model requests for result count are respected while preserving sensible defaults. * Enforce maximum web search result count from config Update `search_web` to cap the model-provided `count` parameter at the admin-configured `WEB_SEARCH_RESULT_COUNT` to prevent excessive result requests. Changes: - Set default `count` parameter to `5`. - Replace fallback logic with enforcement logic that limits `count` to the configured maximum. - Update comment to reflect that the result count is now capped to prevent abuse. This ensures web search requests cannot exceed the configured limit while maintaining a sensible default.
1 parent e34ed72 commit 7ea1e9c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

backend/open_webui/tools/builtin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ async def search_web(
168168
engine = __request__.app.state.config.WEB_SEARCH_ENGINE
169169
user = UserModel(**__user__) if __user__ else None
170170

171-
# Use admin-configured result count if configured, falling back to model-provided count of provided, else default to 5
172-
count = __request__.app.state.config.WEB_SEARCH_RESULT_COUNT or count
171+
# Enforce maximum result count from config to prevent abuse
172+
count = count if count < __request__.app.state.config.WEB_SEARCH_RESULT_COUNT else __request__.app.state.config.WEB_SEARCH_RESULT_COUNT
173173

174174
results = await asyncio.to_thread(_search_web, __request__, engine, query, user)
175175

0 commit comments

Comments
 (0)