jack 3 hónapja
szülő
commit
b244749490
2 módosított fájl, 26 hozzáadás és 13 törlés
  1. 9 2
      app/libs/util.py
  2. 17 11
      app/providers/r2r.py

+ 9 - 2
app/libs/util.py

@@ -31,7 +31,14 @@ def random_uuid() -> str:
 
 
 def verify_jwt_expiration(token):
-    decoded_token = jwt.decode(token, options={"verify_signature": False, "verify_exp": False})
-    expiration_time = datetime.fromtimestamp(decoded_token['exp'])
+    decoded_token = jwt.decode(
+        token, options={"verify_signature": False, "verify_exp": False}
+    )
+    expiration_time = datetime.fromtimestamp(decoded_token["exp"])
     current_time = datetime.now()
+    print(
+        "time=>time=>time=>time=>time=>time=>time=>time=>time=>time=>time=>time=>time=>time=>time=>time=>time=>"
+    )
+    print(f"expiration_time: {expiration_time}")
+    print(f"expiration_time: {current_time}")
     return current_time < expiration_time

+ 17 - 11
app/providers/r2r.py

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