diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py index e31d5c01d..4444581f5 100644 --- a/backend/open_webui/routers/retrieval.py +++ b/backend/open_webui/routers/retrieval.py @@ -1238,7 +1238,7 @@ def search_web(request: Request, engine: str, query: str) -> list[SearchResult]: @router.post("/process/web/search") -async def process_web_search( +def process_web_search( request: Request, form_data: SearchForm, user=Depends(get_verified_user) ): try: diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 078c1e07e..9e55596da 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -9,6 +9,7 @@ import random import json import inspect from uuid import uuid4 +from concurrent.futures import ThreadPoolExecutor from fastapi import Request @@ -412,15 +413,22 @@ async def chat_web_search_handler( ) try: - results = await process_web_search( - request, - SearchForm( - **{ - "query": searchQuery, - } - ), - user, - ) + + # Offload process_web_search to a separate thread + loop = asyncio.get_running_loop() + with ThreadPoolExecutor() as executor: + results = await loop.run_in_executor( + executor, + lambda: process_web_search( + request, + SearchForm( + **{ + "query": searchQuery, + } + ), + user, + ), + ) if results: await event_emitter(