Parcourir la source

2024-0514-搜索策略实验上线

罗俊辉 il y a 1 an
Parent
commit
588f84e9ef
2 fichiers modifiés avec 11 ajouts et 10 suppressions
  1. 1 1
      applications/routes.py
  2. 10 9
      applications/schedule/main_schedule.py

+ 1 - 1
applications/routes.py

@@ -116,5 +116,5 @@ async def delay_response():
     # 从请求体中解析 JSON 数据
     data = await request.get_json()
     A = AskForInfo(data)
-    res = A.schedule()
+    res = await A.schedule()
     return jsonify(res)

+ 10 - 9
applications/schedule/main_schedule.py

@@ -6,6 +6,7 @@
 @author: luojunhui
 """
 import time
+import asyncio
 import requests
 
 
@@ -17,7 +18,7 @@ class AskForInfo:
         self.params = params
         self.base_url = "http://localhost:8111"
 
-    def search_request(self):
+    async def search_request(self):
         """
         请求下载外部视频
         :return:
@@ -31,7 +32,7 @@ class AskForInfo:
         res = requests.post(url, json=body, timeout=120)
         return res.json()
 
-    def check_out_videos(self, trace_id):
+    async def check_out_videos(self, trace_id):
         """
         :return:
         """
@@ -42,7 +43,7 @@ class AskForInfo:
         res = requests.post(url, json=body, timeout=120)
         return res.json()
 
-    def ask_for_info(self, res_obj, kt):
+    async def ask_for_info(self, res_obj, kt):
         """
         :param kt:
         :param res_obj:
@@ -64,13 +65,13 @@ class AskForInfo:
         res = requests.post(url, json=body, timeout=120)
         return res.json()
 
-    def schedule(self):
+    async def schedule(self):
         """
 
         :return:
         """
         a = time.time()
-        res = self.search_request()
+        res = await self.search_request()
         b = time.time()
         print("search_time")
         print(b - a)
@@ -78,15 +79,15 @@ class AskForInfo:
             trace_id = res["trace_id"]
             kimi_title = res['kimi_title']
             c = time.time()
-            res_obj = self.check_out_videos(trace_id=trace_id)
+            res_obj = await self.check_out_videos(trace_id=trace_id)
             d = time.time()
             print("recall time")
             print(d - c)
             time.sleep(2)
-            final_obj = self.ask_for_info(res_obj=res_obj, kt=kimi_title)
+            final_obj = await self.ask_for_info(res_obj=res_obj, kt=kimi_title)
             e = time.time()
-            print("ask time")
-            print(e - d)
+            print("Rank and Return Time")
+            print(e - d - 2)
             return final_obj
         elif res['code'] == 1:
             return {