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.
This commit is contained in:
Youggls 2025-04-17 17:23:20 +08:00
parent a6ccc48d91
commit 9669cd3454

View File

@ -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)