mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
perf: Multi-thread web searching
This commit is contained in:
parent
48637893b1
commit
4b451b984b
@ -355,21 +355,20 @@ async def chat_web_search_handler(
|
|||||||
|
|
||||||
all_results = []
|
all_results = []
|
||||||
|
|
||||||
for searchQuery in queries:
|
await event_emitter(
|
||||||
await event_emitter(
|
{
|
||||||
{
|
"type": "status",
|
||||||
"type": "status",
|
"data": {
|
||||||
"data": {
|
"action": "web_search",
|
||||||
"action": "web_search",
|
"description": "Searching the web",
|
||||||
"description": 'Searching "{{searchQuery}}"',
|
"done": False,
|
||||||
"query": searchQuery,
|
},
|
||||||
"done": False,
|
}
|
||||||
},
|
)
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
web_search_tasks = [
|
||||||
results = await process_web_search(
|
asyncio.create_task(
|
||||||
|
process_web_search(
|
||||||
request,
|
request,
|
||||||
SearchForm(
|
SearchForm(
|
||||||
**{
|
**{
|
||||||
@ -378,6 +377,15 @@ async def chat_web_search_handler(
|
|||||||
),
|
),
|
||||||
user=user,
|
user=user,
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
for searchQuery in queries
|
||||||
|
]
|
||||||
|
gathered_results = await asyncio.gather(*web_search_tasks, return_exceptions=True)
|
||||||
|
|
||||||
|
for searchQuery, results in zip(queries, gathered_results):
|
||||||
|
try:
|
||||||
|
if isinstance(results, Exception):
|
||||||
|
raise Exception(f"Error searching {searchQuery}: {str(results)}")
|
||||||
|
|
||||||
if results:
|
if results:
|
||||||
all_results.append(results)
|
all_results.append(results)
|
||||||
|
Loading…
Reference in New Issue
Block a user