Commit 54f5e03

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-07-25 03:34:14
chore(subtitle): improve prompt
1 parent 29b5f38
Changed files (2)
src
preview
subtitles
src/preview/utils.py
@@ -183,7 +183,7 @@ async def bilibili_subtitle_and_summary(url_or_vid: int | str) -> dict:
         if summary:
             final["summary"] = summary.strip()
         if summary and subtitles:
-            final["full"] = f"Bilibili官方生成的AI总结:\n{summary}\n\n\nBilibili原视频提供的字幕:\n{subtitles}".strip()
+            final["full"] = f"AI总结(B站版):\n{summary}\n\n\n外挂字幕(B站版):\n{subtitles}".strip()  # noqa: RUF001
     except Exception as e:
         logger.error(e)
         return {"error": "下载B站AI总结失败"}
src/subtitles/subtitle.py
@@ -79,7 +79,7 @@ async def get_subtitle(
     res = await fetch_subtitle(url, youtube_subtitle_provider)
     subtitle_file_sent = False
     subtitle_msg = None
-    status_msg = None
+    status_msg = kwargs.get("progress")
     subtitles = ""
     # API failed
     if error := res.get("error", ""):
@@ -135,18 +135,19 @@ async def get_subtitle(
 
     if ai_summary and isinstance(subtitle_msg, Message):
         # use real subtitle (without AI summary by Bilibili)
-        subtitles = re.sub(r"(.*?)Bilibili原视频提供的字幕:", "", subtitles, flags=re.DOTALL).strip()
-        prompt = f"节目标题: {vinfo['title']}\n发布日期: {vinfo['date']:%Y-%m-%d %H:%M:%S}\n节目简介: {description}\n"
-        prompt += f"\n这是{matched['platform'].title()}视频作者【{vinfo['author']}】的一期节目详情, 请解读本期节目内容。"
-        prompt += "\n注意: 不要复述节目标题、作者、日期、简介等基本信息, 不要进行任何寒暄与问候, 直接输出节目内容解读。"
+        subtitles = re.sub(r"(.*?)AI总结(B站版):", "", subtitles, flags=re.DOTALL).strip()  # noqa: RUF001
+        prompt = f"以上是{matched['platform'].title()}视频作者【{vinfo['author']}】的一期节目的文字稿。该期节目详情如下:\n"
+        prompt += f"节目标题: {vinfo['title']}\n发布日期: {vinfo['date']:%Y-%m-%d %H:%M:%S}\n"
+        if description.strip():
+            prompt += f"节目简介: {description}\n"
+        prompt += "\n请解读本期节目内容。要求: 直接输出节目内容解读, 以“该节目讲述了”开头"
         ai_cmd = next((x.strip() for x in PREFIX.GPT.split(",") if x.strip()), "")
         # Construct a message to call GPT
         ai_msg = Message(
             id=subtitle_msg.id,
             chat=subtitle_msg.chat,
             text=Str(f"{ai_cmd} {prompt}"),
-            from_user=message.from_user,
-            reply_to_message=Message(id=rand_number(), chat=subtitle_msg.chat, from_user=message.from_user, text=Str(subtitles)),
+            reply_to_message=Message(id=rand_number(), chat=subtitle_msg.chat, text=Str(subtitles)),
         )
         kwargs["include_thoughts"] = False
         await gpt_response(client, ai_msg, **kwargs)