罗俊辉 11 hónapja
szülő
commit
a608244a26
4 módosított fájl, 83 hozzáadás és 56 törlés
  1. 4 3
      applications/async_mysql.py
  2. 41 38
      applications/pipeline.py
  3. 35 13
      deal/matchArticle_deal.py
  4. 3 2
      va_task.py

+ 4 - 3
applications/async_mysql.py

@@ -25,7 +25,7 @@ class AsyncMySQLClient(object):
             db='piaoquan-crawler',
             db='piaoquan-crawler',
             charset='utf8mb4'
             charset='utf8mb4'
         )
         )
-        print("mysql init successfully")
+        print("数据库初始化完成......")
 
 
     async def close_pool(self):
     async def close_pool(self):
         """
         """
@@ -47,13 +47,14 @@ class AsyncMySQLClient(object):
                 result = await cursor.fetchall()
                 result = await cursor.fetchall()
                 return result
                 return result
 
 
-    async def async_insert(self, sql):
+    async def async_insert(self, sql, params):
         """
         """
         insert and update method
         insert and update method
+        :param params:
         :param sql:
         :param sql:
         :return:
         :return:
         """
         """
         async with self.app.mysql_pool.acquire() as coon:
         async with self.app.mysql_pool.acquire() as coon:
             async with coon.cursor() as cursor:
             async with coon.cursor() as cursor:
-                await cursor.execute(sql)
+                await cursor.execute(sql, params)
                 await coon.commit()
                 await coon.commit()

+ 41 - 38
applications/pipeline.py

@@ -89,44 +89,47 @@ def summary_articles(materials):
     :param materials:
     :param materials:
     :return:
     :return:
     """
     """
-    materials_ = json.loads(materials.replace("\n", "").replace("#", ""))
-    keys = []
-    for key in materials_:
-        keys.append(key)
+    if materials:
+        materials_ = json.loads(materials.replace("\\", ""))
+        keys = []
+        for key in materials_:
+            keys.append(key)
 
 
-    prompt = f"""
-    # Role:信息萃取师
-    - 介绍:作为信息萃取师,我拥有从海量信息源中进行细致分析的能力,能找出最核心的信息点,并对其真实性进行评估。我对复杂问题的处理方式是逻辑思考者的方式,依据事实证据而非容易出错的直觉来形成结论。此外,我擅长以专业的写作技巧,有条理地组织思想和观点,确保所写内容引人入胜,并且绝不枯燥。
- 
-    ## Task:
-    - 背景:用户有各种问题想通过搜索引擎获取答案,但网络世界大量信息往往含有噪音,比如虚假、夸大、不准确等情况。
-    - 目标:筛选出可信信息源,并对用户的问题进行准确、专业、有效的结构化回复,且不会忽略查询的任何细节。
+        prompt = f"""
+        # Role:信息萃取师
+        - 介绍:作为信息萃取师,我拥有从海量信息源中进行细致分析的能力,能找出最核心的信息点,并对其真实性进行评估。我对复杂问题的处理方式是逻辑思考者的方式,依据事实证据而非容易出错的直觉来形成结论。此外,我擅长以专业的写作技巧,有条理地组织思想和观点,确保所写内容引人入胜,并且绝不枯燥。
      
      
-    ## Skills:
-    - 信息分析:根据用户的问题,从大量信息源中筛选出最关键的信息,并对其真实性进行评估。
-    - 逻辑思考:以事实证据为依据,而非直觉,对复杂问题进行推理和得出结论。
-    - 专业写作:有条理地组织思想和特殊性,确保所写内容引人入胜,语言流畅而不乏味。
- 
-    ## Rules:
-    - 操作指南:根据用户的问题,使用中文编写清晰、简洁且准确的回答。
-    - 限制要求:不要忽略问题的任何细节,从给定的参考资料中引述的信息需要经过论证并且不能照搬原话。
-    - 工作流程:
-     1. 根据给定的参考资料(以数字索引表示)进行阅读和分析:
-        材料1 标题: '{keys[0]}', 材料: '{materials_[keys[0]]}' ,
-        材料1 标题: '{keys[1]}', 材料: '{materials_[keys[1]]}' ,
-        材料1 标题: '{keys[2]}', 材料: '{materials_[keys[2]]}' , 
-        材料1 标题: '{keys[3]}', 材料: '{materials_[keys[3]]}' ,
-        材料1 标题: '{keys[4]}', 材料: '{materials_[keys[4]]}'
-     2. 创作回答:依照专业的写作技巧,使用汉语有条理地组织思想,写出高质量的文章
+        ## Task:
+        - 背景:用户有各种问题想通过搜索引擎获取答案,但网络世界大量信息往往含有噪音,比如虚假、夸大、不准确等情况。
+        - 目标:筛选出可信信息源,并对用户的问题进行准确、专业、有效的结构化回复,且不会忽略查询的任何细节。
+         
+        ## Skills:
+        - 信息分析:根据用户的问题,从大量信息源中筛选出最关键的信息,并对其真实性进行评估。
+        - 逻辑思考:以事实证据为依据,而非直觉,对复杂问题进行推理和得出结论。
+        - 专业写作:有条理地组织思想和特殊性,确保所写内容引人入胜,语言流畅而不乏味。
      
      
-    ## OutputFormat:
-    返回json格式,key, value如下
-    "title": 总结上述材料的标题,
-    "text":  编写的文章
-    """
-    response = kimi_ai(prompt=prompt)
-    try:
-        response = json.loads(response.replace("\n", ""))
-    except:
-        response = json.loads(response.replace("'", '"'))
-    return response['title'].replace("'", ""), response['text'].replace("'", '')
+        ## Rules:
+        - 操作指南:根据用户的问题,使用中文编写清晰、简洁且准确的回答。
+        - 限制要求:不要忽略问题的任何细节,从给定的参考资料中引述的信息需要经过论证并且不能照搬原话。
+        - 工作流程:
+         1. 根据给定的参考资料(以数字索引表示)进行阅读和分析:
+            材料1 标题: '{keys[0]}', 材料: '{materials_[keys[0]]}' ,
+            材料1 标题: '{keys[1]}', 材料: '{materials_[keys[1]]}' ,
+            材料1 标题: '{keys[2]}', 材料: '{materials_[keys[2]]}' , 
+            材料1 标题: '{keys[3]}', 材料: '{materials_[keys[3]]}' ,
+            材料1 标题: '{keys[4]}', 材料: '{materials_[keys[4]]}'
+         2. 创作回答:依照专业的写作技巧,使用汉语有条理地组织思想,写出高质量的文章
+         
+        ## OutputFormat:
+        返回json格式,key, value如下
+        "title": 总结上述材料的标题,
+        "text":  编写的文章
+        """
+        response = kimi_ai(prompt=prompt)
+        try:
+            response = json.loads(response.replace("\n", ""))
+        except:
+            response = json.loads(response.replace("'", '"'))
+        return response['title'], response['text']
+    else:
+        return "ai_title", "ai_text"

+ 35 - 13
deal/matchArticle_deal.py

@@ -45,17 +45,21 @@ class MatchArticlesTask(object):
             :param mysql_client:
             :param mysql_client:
             :return:
             :return:
             """
             """
-            w_response = whisper(video_id)
+            try:
+                w_response = whisper(video_id)
+            except:
+                w_response = {"text": "whisper failed"}
             print(w_response)
             print(w_response)
             text = w_response['text'].replace("'", "")
             text = w_response['text'].replace("'", "")
             update_sql = f"""
             update_sql = f"""
             UPDATE {db_config}
             UPDATE {db_config}
             SET 
             SET 
-                video_text = '{text}',
-                status_code = 1
-            WHERE video_id = {video_id};
+                video_text = %s,
+                status_code = %s
+            WHERE video_id = %s;
             """
             """
-            await mysql_client.async_insert(sql=update_sql)
+            print(update_sql)
+            await mysql_client.async_insert(sql=update_sql, params=(text, 1, video_id))
 
 
         for vid in video_list:
         for vid in video_list:
             await whisper_and_update(video_id=vid[0], mysql_client=self.mysql_client)
             await whisper_and_update(video_id=vid[0], mysql_client=self.mysql_client)
@@ -82,11 +86,11 @@ class MatchArticlesTask(object):
             material_result = json.dumps(material_dict, ensure_ascii=False)
             material_result = json.dumps(material_dict, ensure_ascii=False)
             update_sql = f"""
             update_sql = f"""
             UPDATE {db_config}
             UPDATE {db_config}
-            SET materials = '{material_result}', status_code = 2
-            WHERE task_id = '{task_id}';
+            SET materials = %s, status_code = %s
+            WHERE task_id = %s;
             """
             """
             print(update_sql)
             print(update_sql)
-            await mysql_client.async_insert(sql=update_sql)
+            await mysql_client.async_insert(sql=update_sql, params=(material_result, 2, task_id))
 
 
         for task in task_list:
         for task in task_list:
             await find_material(task, self.mysql_client)
             await find_material(task, self.mysql_client)
@@ -105,11 +109,21 @@ class MatchArticlesTask(object):
             imgs = get_img_list(video_title)
             imgs = get_img_list(video_title)
             update_sql = f"""
             update_sql = f"""
             UPDATE {db_config}
             UPDATE {db_config}
-            SET ai_text = '{ai_text}', ai_title = '{ai_title}', cover = '{imgs[0]}',img_list = '{json.dumps(imgs, ensure_ascii=False)}',status_code = 3
-            WHERE task_id = '{task_id}';
+            SET ai_text = %s, ai_title = %s, cover = %s, img_list = %s, status_code = %s
+            WHERE task_id = %s;
             """
             """
             print(update_sql)
             print(update_sql)
-            await mysql_client.async_insert(sql=update_sql)
+            await mysql_client.async_insert(
+                sql=update_sql,
+                params=(
+                    ai_text,
+                    ai_title,
+                    imgs[0],
+                    json.dumps(imgs, ensure_ascii=False),
+                    3,
+                    task_id
+                )
+            )
 
 
         for task in task_list:
         for task in task_list:
             await ai_generate_text(task, self.mysql_client)
             await ai_generate_text(task, self.mysql_client)
@@ -153,9 +167,17 @@ class MatchArticlesV1(object):
             INSERT INTO {db_config}
             INSERT INTO {db_config}
                 (video_id, task_id, video_title, request_time)
                 (video_id, task_id, video_title, request_time)
             VALUES
             VALUES
-                ({self.video_id}, '{request_id}', '{self.title}', {request_time})
+                (%s, %s, %s, %s)
         """
         """
-        await self.mysql_client.async_insert(sql=insert_sql)
+        await self.mysql_client.async_insert(
+            sql=insert_sql,
+            params=(
+                self.video_id,
+                request_id,
+                self.title,
+                request_time
+            )
+        )
         return request_id
         return request_id
 
 
     async def deal(self):
     async def deal(self):

+ 3 - 2
va_task.py

@@ -53,15 +53,16 @@ class TaskMySQLClient(object):
                 result = await cursor.fetchall()
                 result = await cursor.fetchall()
                 return result
                 return result
 
 
-    async def async_insert(self, sql):
+    async def async_insert(self, sql, params):
         """
         """
         insert and update method
         insert and update method
+        :param params:
         :param sql:
         :param sql:
         :return:
         :return:
         """
         """
         async with self.mysql_pool.acquire() as coon:
         async with self.mysql_pool.acquire() as coon:
             async with coon.cursor() as cursor:
             async with coon.cursor() as cursor:
-                await cursor.execute(sql)
+                await cursor.execute(sql, params)
                 await coon.commit()
                 await coon.commit()