| 
					
				 | 
			
			
				@@ -10,6 +10,7 @@ from uuid import uuid4 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from applications.config import db_config 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from applications.functions import whisper 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from applications.pipeline import question_fission, search_materials, summary_articles 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class MatchArticlesTask(object): 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -35,7 +36,6 @@ class MatchArticlesTask(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         select_sql = f"""SELECT video_id FROM {db_config} WHERE status_code = 0 ORDER BY id ASC limit 10;""" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         video_list = await self.mysql_client.select(select_sql) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print(video_list) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async def whisper_and_update(video_id, mysql_client): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             """ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -68,7 +68,13 @@ class MatchArticlesTask(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async def find_material(task_tuple, mysql_client): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             task_id, title, text = task_tuple 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            material_result = json.dumps({}, ensure_ascii=False) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            # 先用视频标题作为query, 后续可逐步优化 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            question_dict = question_fission(title) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            material_list = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for question_key in question_dict: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                material = search_materials(question=question_dict[question_key]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                material_list.append(material) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            material_result = json.dumps(material_list, ensure_ascii=False) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             update_sql = f""" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             UPDATE {db_config} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             SET materials = '{material_result}', status_code = 2 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -89,12 +95,11 @@ class MatchArticlesTask(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async def ai_generate_text(task_tuple, mysql_client): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             task_id, video_title, materials = task_tuple 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ai_text = "ai_text" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ai_title = "ai_title" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            imgs, ai_title, ai_text = summary_articles(materials) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             update_sql = f""" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             UPDATE {db_config} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            SET ai_text = '{ai_text}', ai_title = '{ai_title}', status_code = 3 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            WHERE task_id = '{task_id}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            SET ai_text = '{ai_text}', ai_title = '{ai_title}', img_list = '{json.dumps(imgs, ensure_ascii=False)}',status_code = 3 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            WHERE task_id = '{task_id}'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for task in task_list: 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -216,19 +221,19 @@ class MatchArticlesV2(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         match status_code: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             case 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "taskId": self.task_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "task_id": self.task_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "code": 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "msg": "未处理" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             case 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "taskId": self.task_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "task_id": self.task_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "code": 1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "msg": "处理中, 已经用whisper生成视频文本" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             case 2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    "taskId": self.task_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "task_id": self.task_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "code": 2, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "msg": "处理中, 已经用AI搜索生成资料" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -242,4 +247,8 @@ class MatchArticlesV2(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         self.get_basic_video_info(video_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return result 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                response = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "status": "success", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "article": result 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return response 
			 |