From e460859f4488f3fb7d7ff23dd99bb9a4517eb9c5 Mon Sep 17 00:00:00 2001 From: justlovemaki <274166795@qq.com> Date: Tue, 24 Jun 2025 17:56:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=97=A5=E6=8A=A5=E7=94=9F=E6=88=90):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E6=8A=A5=E6=91=98=E8=A6=81=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E5=B9=B6=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增第三步摘要生成功能,添加 summarizationPromptStepThree.js - 在日报内容中插入摘要部分和最小化标题 - 更新 wrangler.toml 配置添加 DAILY_TITLE_MIN 变量 - 优化 HTML 预览样式支持视频元素 - 更新 README 添加日报前端项目链接 - 修改脚注样式并更新图片链接 --- README.md | 4 ++- src/foot.js | 4 +-- src/handlers/genAIContent.js | 29 +++++++++++++++++++--- src/htmlGenerators.js | 2 +- src/prompt/summarizationPromptStepThree.js | 13 ++++++++++ wrangler.toml | 1 + 6 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 src/prompt/summarizationPromptStepThree.js diff --git a/README.md b/README.md index a219902..9108319 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ 我们的目标是成为您在瞬息万变的 AI 浪潮中保持领先的得力助手,让您高效获取最有价值的信息。 +> [!NOTE] +> 日报前端项目已发布2.0: [Hextra-AI-Insight-Daily](https://github.com/justlovemaki/Hextra-AI-Insight-Daily) ,基于 Hugo 加 Hextra主题 构建。 --- ## ✨ 核心特性 @@ -66,7 +68,7 @@ * **唯一主站点 (GitHub Pages)** > [https://ai.hubtoday.app/](https://ai.hubtoday.app/) > - > `✅ 推荐` `🚀 访问速度快` + > `✅ 推荐` `🚀 访问速度快` --- diff --git a/src/foot.js b/src/foot.js index b5036af..de6bf20 100644 --- a/src/foot.js +++ b/src/foot.js @@ -3,12 +3,12 @@ export function insertFoot() { --- -**收听语音版** +#### **收听语音版** | 🎙️ **小宇宙** | 📹 **抖音** | | --- | --- | | [来生小酒馆](https://www.xiaoyuzhoufm.com/podcast/683c62b7c1ca9cf575a5030e) | [来生情报站](https://www.douyin.com/user/MS4wLjABAAAAwpwqPQlu38sO38VyWgw9ZjDEnN4bMR5j8x111UxpseHR9DpB6-CveI5KRXOWuFwG)| -|  |  | +|  |  | `; } diff --git a/src/handlers/genAIContent.js b/src/handlers/genAIContent.js index 99850ba..ee1d6c2 100644 --- a/src/handlers/genAIContent.js +++ b/src/handlers/genAIContent.js @@ -4,8 +4,9 @@ import { getFromKV } from '../kv.js'; import { callChatAPIStream } from '../chatapi.js'; import { generateGenAiPageHtml } from '../htmlGenerators.js'; import { dataSources } from '../dataFetchers.js'; // Import dataSources -import { getSystemPromptSummarizationStepOne } from '../prompt/summarizationPromptStepOne.js'; -import { getSystemPromptSummarizationStepTwo } from '../prompt/summarizationPromptStepTwo.js'; +import { getSystemPromptSummarizationStepOne } from "../prompt/summarizationPromptStepOne"; +import { getSystemPromptSummarizationStepTwo } from "../prompt/summarizationPromptStepTwo"; +import { getSystemPromptSummarizationStepThree } from "../prompt/summarizationPromptStepThree"; import { getSystemPromptPodcastFormatting, getSystemPromptShortPodcastFormatting } from '../prompt/podcastFormattingPrompt.js'; import { getSystemPromptDailyAnalysis } from '../prompt/dailyAnalysisPrompt.js'; // Import new prompt import { insertFoot } from '../foot.js'; @@ -252,13 +253,33 @@ export async function handleGenAIContent(request, env) { if (fullPromptForCall2_System) promptsMarkdownContent += `### System Instruction\n\`\`\`\n${fullPromptForCall2_System}\n\`\`\`\n\n`; if (fullPromptForCall2_User) promptsMarkdownContent += `### User Input (Output of Call 1)\n\`\`\`\n${fullPromptForCall2_User}\n\`\`\`\n\n`; - let dailySummaryMarkdownContent = `# ${env.DAILY_TITLE} ${formatDateToChinese(dateStr)}\n\n${removeMarkdownCodeBlock(outputOfCall2)}`; + let dailySummaryMarkdownContent = `# ${env.DAILY_TITLE} ${formatDateToChinese(dateStr)}` + '\n\n'; + dailySummaryMarkdownContent += '> '+ env.DAILY_TITLE_MIN + '\n\n'; + let outputOfCall3 = null; + console.log("Call 3 to Chat (Processing Call 2 Output): User prompt length:", outputOfCall2.length); + try { + let processedChunks = []; + for await (const chunk of callChatAPIStream(env, outputOfCall2, getSystemPromptSummarizationStepThree())) { + processedChunks.push(chunk); + } + outputOfCall3 = processedChunks.join(''); + if (!outputOfCall3 || outputOfCall3.trim() === "") throw new Error("Chat processing call returned empty content."); + outputOfCall3 = removeMarkdownCodeBlock(outputOfCall3); // Clean the output + console.log("Call 3 (Processing Call 2 Output) successful. Output length:", outputOfCall3.length); + } catch (error) { + console.error("Error in Chat API Call 3 (Processing Call 2 Output):", error); + const errorHtml = generateGenAiPageHtml(env, '生成AI日报出错(摘要)', `
Failed during processing of summarized content: ${escapeHtml(error.message)}
${error.stack ? `${escapeHtml(error.stack)}` : ''}`, dateStr, true, selectedItemsParams, fullPromptForCall1_System, fullPromptForCall1_User, fullPromptForCall2_System, fullPromptForCall2_User);
+ return new Response(errorHtml, { status: 500, headers: { 'Content-Type': 'text/html; charset=utf-8' } });
+ }
+ dailySummaryMarkdownContent += '\n\n#### **AI内容摘要**\n\n```\n' + outputOfCall3 + '\n```\n\n';
+
+ dailySummaryMarkdownContent += `\n\n${removeMarkdownCodeBlock(outputOfCall2)}`;
if (env.INSERT_FOOT=='true') dailySummaryMarkdownContent += insertFoot() +`\n\n`;
const successHtml = generateGenAiPageHtml(
env,
'AI日报', // Title for Call 1 page
- escapeHtml(outputOfCall2),
+ escapeHtml(dailySummaryMarkdownContent),
dateStr, false, selectedItemsParams,
fullPromptForCall1_System, fullPromptForCall1_User,
null, null, // Pass Call 2 prompts
diff --git a/src/htmlGenerators.js b/src/htmlGenerators.js
index c93b55d..8fdda7e 100644
--- a/src/htmlGenerators.js
+++ b/src/htmlGenerators.js
@@ -413,7 +413,7 @@ export function generateGenAiPageHtml(env, title, bodyContent, pageDate, isError
function openContentInNewWindow() {
const content = document.getElementById('outContentBox').innerHTML;
const newWindow = window.open('', '_blank');
- newWindow.document.write('