mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-26 07:14:47 +08:00
refactor: Refactors the retriever function to use async/await (#821)
* refactor: Refactors the retriever function to use async/await
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from typing import List, Optional
|
||||
from urllib.parse import urlparse
|
||||
@@ -98,6 +99,17 @@ class RAGFlowProvider(Retriever):
|
||||
|
||||
return list(docs.values())
|
||||
|
||||
async def query_relevant_documents_async(
|
||||
self, query: str, resources: list[Resource] = []
|
||||
) -> list[Document]:
|
||||
"""
|
||||
Asynchronous version of query_relevant_documents.
|
||||
Wraps the synchronous implementation in asyncio.to_thread() to avoid blocking the event loop.
|
||||
"""
|
||||
return await asyncio.to_thread(
|
||||
self.query_relevant_documents, query, resources
|
||||
)
|
||||
|
||||
def list_resources(self, query: str | None = None) -> list[Resource]:
|
||||
headers = {
|
||||
"Authorization": f"Bearer {self.api_key}",
|
||||
@@ -128,6 +140,13 @@ class RAGFlowProvider(Retriever):
|
||||
|
||||
return resources
|
||||
|
||||
async def list_resources_async(self, query: str | None = None) -> list[Resource]:
|
||||
"""
|
||||
Asynchronous version of list_resources.
|
||||
Wraps the synchronous implementation in asyncio.to_thread() to avoid blocking the event loop.
|
||||
"""
|
||||
return await asyncio.to_thread(self.list_resources, query)
|
||||
|
||||
|
||||
def parse_uri(uri: str) -> tuple[str, str]:
|
||||
parsed = urlparse(uri)
|
||||
|
||||
Reference in New Issue
Block a user