From 9669cd3454fd2b259bff86e59ef5b7cf5f71de0c Mon Sep 17 00:00:00 2001 From: Youggls Date: Thu, 17 Apr 2025 17:23:20 +0800 Subject: [PATCH] fix: use run_in_threadpool for search_web to prevent blocking Used fastapi's run_in_threadpool function to execute the search_web function, preventing the synchronous function from blocking the entire web search process. --- backend/open_webui/routers/retrieval.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py index 13f012483..ce79503db 100644 --- a/backend/open_webui/routers/retrieval.py +++ b/backend/open_webui/routers/retrieval.py @@ -1477,8 +1477,11 @@ async def process_web_search( logging.info( f"trying to web search with {request.app.state.config.WEB_SEARCH_ENGINE, form_data.query}" ) - web_results = search_web( - request, request.app.state.config.WEB_SEARCH_ENGINE, form_data.query + web_results = await run_in_threadpool( + search_web, + request, + request.app.state.config.WEB_SEARCH_ENGINE, + form_data.query, ) except Exception as e: log.exception(e)