This commit is contained in:
Timothy Jaeryang Baek 2024-12-24 17:56:46 -07:00
parent 6b25139d4f
commit 95da0734b6
2 changed files with 18 additions and 10 deletions

View File

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

View File

@ -9,6 +9,7 @@ import random
import json
import inspect
from uuid import uuid4
from concurrent.futures import ThreadPoolExecutor
from fastapi import Request
@ -412,7 +413,13 @@ async def chat_web_search_handler(
)
try:
results = await process_web_search(
# 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(
**{
@ -420,6 +427,7 @@ async def chat_web_search_handler(
}
),
user,
),
)
if results: