|
@@ -8,8 +8,10 @@ from config.llm import tool_settings
|
|
import nest_asyncio
|
|
import nest_asyncio
|
|
import asyncio
|
|
import asyncio
|
|
|
|
|
|
|
|
+# Apply nest_asyncio to allow nested event loops
|
|
nest_asyncio.apply()
|
|
nest_asyncio.apply()
|
|
|
|
|
|
|
|
+
|
|
class R2R:
|
|
class R2R:
|
|
client: R2RClient
|
|
client: R2RClient
|
|
|
|
|
|
@@ -22,7 +24,7 @@ class R2R:
|
|
return loop.create_task(self._login()) # 在现有事件循环中运行异步任务
|
|
return loop.create_task(self._login()) # 在现有事件循环中运行异步任务
|
|
else:
|
|
else:
|
|
return asyncio.run(self._login()) # 如果没有事件循环则创建一个新的
|
|
return asyncio.run(self._login()) # 如果没有事件循环则创建一个新的
|
|
- #loop.create_task(self._login())
|
|
|
|
|
|
+ # loop.create_task(self._login())
|
|
|
|
|
|
def ingest_file(self, file_path: str, metadata: Optional[dict]):
|
|
def ingest_file(self, file_path: str, metadata: Optional[dict]):
|
|
self._check_login()
|
|
self._check_login()
|
|
@@ -33,7 +35,9 @@ class R2R:
|
|
|
|
|
|
def search(self, query: str, filters: dict[str, Any]):
|
|
def search(self, query: str, filters: dict[str, Any]):
|
|
self._check_login()
|
|
self._check_login()
|
|
- print("aaaaaaacccccccccccccccccccccccccccccccccccccccccvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
|
|
|
|
|
|
+ print(
|
|
|
|
+ "aaaaaaacccccccccccccccccccccccccccccccccccccccccvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
|
|
|
|
+ )
|
|
print(filters)
|
|
print(filters)
|
|
print(tool_settings.R2R_SEARCH_LIMIT)
|
|
print(tool_settings.R2R_SEARCH_LIMIT)
|
|
search_response = self.client.retrieval.search(
|
|
search_response = self.client.retrieval.search(
|
|
@@ -47,15 +51,20 @@ class R2R:
|
|
print(search_response)
|
|
print(search_response)
|
|
return search_response.get("results").get("chunk_search_results")
|
|
return search_response.get("results").get("chunk_search_results")
|
|
|
|
|
|
- #@pytest.fixture(scope="session")
|
|
|
|
|
|
+ # @pytest.fixture(scope="session")
|
|
async def _login(self):
|
|
async def _login(self):
|
|
if not self.auth_enabled:
|
|
if not self.auth_enabled:
|
|
return
|
|
return
|
|
|
|
+ print(
|
|
|
|
+ "client=>client=>client=>client=>client=>client=>client=>client=>client=>client=>client=>client=>client=>client=>client=>client=>client=>client=>"
|
|
|
|
+ )
|
|
|
|
+ print(self.client)
|
|
if not self.client:
|
|
if not self.client:
|
|
self.client = R2RClient(tool_settings.R2R_BASE_URL)
|
|
self.client = R2RClient(tool_settings.R2R_BASE_URL)
|
|
- result = self.client.users.login(tool_settings.R2R_USERNAME, tool_settings.R2R_PASSWORD) # 同步调用异步函数
|
|
|
|
- #self.client.users.login(tool_settings.R2R_USERNAME, tool_settings.R2R_PASSWORD)
|
|
|
|
- #return self.client
|
|
|
|
|
|
+ result = await self.client.users.login(
|
|
|
|
+ tool_settings.R2R_USERNAME, tool_settings.R2R_PASSWORD
|
|
|
|
+ ) # 同步调用异步函数
|
|
|
|
+ # return self.client
|
|
|
|
|
|
def _check_login(self):
|
|
def _check_login(self):
|
|
if not self.auth_enabled:
|
|
if not self.auth_enabled:
|
|
@@ -68,13 +77,10 @@ class R2R:
|
|
return loop.create_task(self._login()) # 在现有事件循环中运行异步任务
|
|
return loop.create_task(self._login()) # 在现有事件循环中运行异步任务
|
|
else:
|
|
else:
|
|
return asyncio.run(self._login()) # 如果没有事件循环则创建一个新的
|
|
return asyncio.run(self._login()) # 如果没有事件循环则创建一个新的
|
|
- #loop.create_task(self._login())
|
|
|
|
- #self._login()
|
|
|
|
|
|
+ # loop.create_task(self._login())
|
|
|
|
+ # self._login()
|
|
|
|
|
|
|
|
|
|
r2r = R2R()
|
|
r2r = R2R()
|
|
|
|
|
|
-#async def run_async():
|
|
|
|
r2r.init() # 运行异步函数
|
|
r2r.init() # 运行异步函数
|
|
-
|
|
|
|
-#asyncio.run(run_async())
|
|
|