|
@@ -1,8 +1,8 @@
|
|
|
"""
|
|
|
@author: luojunhui
|
|
|
"""
|
|
|
-
|
|
|
import time
|
|
|
+import datetime
|
|
|
import traceback
|
|
|
|
|
|
from pymysql.cursors import DictCursor
|
|
@@ -21,13 +21,15 @@ def generate_prompt(text):
|
|
|
生成prompt
|
|
|
"""
|
|
|
prompt = f"""
|
|
|
- 你是1个优秀的公众号文章写作大师,我对你有以下要求
|
|
|
- 文章: {text}
|
|
|
- 1.请仔细阅读以上公众号文章,挑选文章中最吸引人的情节或话题,总结为100字左右文章精彩总结(字数计算包括标点符号)。
|
|
|
- 句子段落之间以悬念承接,可以吸引读者往下读第二句。
|
|
|
- 2.在这100字内容的结尾处,增加1-2句话的引导,引导大家去观看上面的视频了解详情。注意是点击上面的视频,不是下面的视频。
|
|
|
-
|
|
|
- 你最终输出一段总结内容,不用加标题或者主题,也不用写第几段、多少字这样的话。整体的语言风格要口语化、直接点,要让60岁以上的老年人能看懂、能共情。人的名字尽量用全名,不用简称。
|
|
|
+ 你是1个优秀的公众号文章写作大师,我对你有以下要求
|
|
|
+ 视频总结:{text}
|
|
|
+
|
|
|
+ 第一个要求:请仔细阅读以上视频总结,挑选其中最吸引人的情节或话题,总结为100字左右文章精彩总结(字数计算包括标点符号),这部分内容为段落1。
|
|
|
+ 句子段落之间以悬念承接,可以吸引读者往下读第二句。
|
|
|
+
|
|
|
+ 第二个要求:在这100字内容的结尾处,增加1-2句话的引导,引导大家去观看上面的视频了解详情,可以加一些emoji表情。注意是点击上面的视频,不是下面的视频。这部分内容为段落2。
|
|
|
+
|
|
|
+ 你最终输出一段总结内容,将第一段和第二段之间空格一行,并且对所有文字进行加粗处理。不用加标题或者主题,也不用写第几段、多少字这样的话。整体的语言风格要口语化、直接点,要让60岁以上的老年人能看懂、能共情。人的名字尽量用全名,不用简称。
|
|
|
"""
|
|
|
return prompt
|
|
|
|
|
@@ -38,12 +40,6 @@ class ArticleSummaryTask(object):
|
|
|
"""
|
|
|
|
|
|
def __init__(self):
|
|
|
- self.db_client = None
|
|
|
-
|
|
|
- def connect_db(self):
|
|
|
- """
|
|
|
- 连接数据库
|
|
|
- """
|
|
|
self.db_client = DatabaseConnector(db_config=long_articles_config)
|
|
|
self.db_client.connect()
|
|
|
|
|
@@ -54,7 +50,7 @@ class ArticleSummaryTask(object):
|
|
|
select_sql = f"""
|
|
|
select id, video_text
|
|
|
from video_content_understanding
|
|
|
- where summary_status = {const.SUMMARY_INIT_STATUS} and status = {const.VIDEO_UNDERSTAND_SUCCESS_STATUS}
|
|
|
+ where summary_status = {const.INIT_STATUS} and understanding_status = {const.SUCCESS_STATUS}
|
|
|
limit {const.SUMMARY_BATCH_SIZE};
|
|
|
"""
|
|
|
task_list = self.db_client.fetch(select_sql, cursor_type=DictCursor)
|
|
@@ -69,7 +65,7 @@ class ArticleSummaryTask(object):
|
|
|
update_sql = f"""
|
|
|
update video_content_understanding
|
|
|
set summary_status = %s
|
|
|
- where summary_status = %s and status_update_timestamp < %s;
|
|
|
+ where summary_status = %s and summary_status_ts < %s;
|
|
|
"""
|
|
|
rollback_rows = self.db_client.save(
|
|
|
query=update_sql,
|
|
@@ -87,7 +83,7 @@ class ArticleSummaryTask(object):
|
|
|
|
|
|
# Lock Task
|
|
|
affected_rows = self.update_task_status(
|
|
|
- task_id, const.SUMMARY_INIT_STATUS, const.SUMMARY_LOCK
|
|
|
+ task_id, const.INIT_STATUS, const.PROCESSING_STATUS
|
|
|
)
|
|
|
if not affected_rows:
|
|
|
return
|
|
@@ -104,14 +100,14 @@ class ArticleSummaryTask(object):
|
|
|
else:
|
|
|
# set as fail
|
|
|
self.update_task_status(
|
|
|
- task_id, const.SUMMARY_LOCK, const.SUMMARY_FAIL_STATUS
|
|
|
+ task_id, const.PROCESSING_STATUS, const.FAIL_STATUS
|
|
|
)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
print(traceback.format_exc())
|
|
|
# set as fail
|
|
|
self.update_task_status(
|
|
|
- task_id, const.SUMMARY_LOCK, const.SUMMARY_FAIL_STATUS
|
|
|
+ task_id, const.PROCESSING_STATUS, const.FAIL_STATUS
|
|
|
)
|
|
|
|
|
|
def set_summary_text_for_task(self, task_id, text):
|
|
@@ -120,17 +116,17 @@ class ArticleSummaryTask(object):
|
|
|
"""
|
|
|
update_sql = f"""
|
|
|
update video_content_understanding
|
|
|
- set summary_status = %s, summary_text = %s, status_update_timestamp = %s
|
|
|
+ set summary_status = %s, summary_text = %s, understanding_status_ts = %s
|
|
|
where id = %s and summary_status = %s;
|
|
|
"""
|
|
|
affected_rows = self.db_client.save(
|
|
|
query=update_sql,
|
|
|
params=(
|
|
|
- const.SUMMARY_SUCCESS_STATUS,
|
|
|
+ const.SUCCESS_STATUS,
|
|
|
text,
|
|
|
- int(time.time()),
|
|
|
+ datetime.datetime.now(),
|
|
|
task_id,
|
|
|
- const.SUMMARY_LOCK,
|
|
|
+ const.PROCESSING_STATUS
|
|
|
),
|
|
|
)
|
|
|
return affected_rows
|
|
@@ -141,11 +137,11 @@ class ArticleSummaryTask(object):
|
|
|
"""
|
|
|
update_sql = f"""
|
|
|
update video_content_understanding
|
|
|
- set summary_status = %s, status_update_timestamp = %s
|
|
|
+ set summary_status = %s, summary_status_ts = %s
|
|
|
where id = %s and summary_status = %s;
|
|
|
"""
|
|
|
update_rows = self.db_client.save(
|
|
|
- update_sql, (new_status, int(time.time()), task_id, ori_status)
|
|
|
+ update_sql, (new_status, datetime.datetime.now(), task_id, ori_status)
|
|
|
)
|
|
|
return update_rows
|
|
|
|