Skip to content

Commit 8d366d2

Browse files
committed
Send only article content to AI
1 parent 09d69d7 commit 8d366d2

2 files changed

Lines changed: 9 additions & 25 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ https://api.plunox.site/rss?url={url}
9090
https://api.plunox.site/ai/responses
9191
```
9292

93-
AI 的文章类型由前端按标题判断:标题含中文字符时使用“中文摘要提示词”,标题不含中文字符时使用“非中文全文翻译提示词”。这两段提示词、是否启用流式输出、AI Worker URL 和鉴权方式都在设置里保存。Worker 不负责判断文章语言、不裁剪模型输出,只把请求转发给上游并把 JSON 或 SSE 流返回给前端。
93+
AI 的文章类型由前端按标题判断:标题含中文字符时使用“中文摘要提示词”,标题不含中文字符时使用“非中文全文翻译提示词”。标题只在浏览器本地用于选择提示词;发送给 Worker 和模型的 `input` 只包含正文文本,不包含标题、作者、发布时间或原文链接。这两段提示词、是否启用流式输出、AI Worker URL 和鉴权方式都在设置里保存。Worker 不负责判断文章语言、不裁剪模型输出,只把请求转发给上游并把 JSON 或 SSE 流返回给前端。
9494

9595
## 保护 AI 接口
9696

src/App.jsx

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ function App() {
473473
const config = libraryRef.current.config;
474474
const sourceText = stripHtml(article.content || article.excerpt || "");
475475
const contentText = sourceText.slice(0, MAX_AI_CONTENT_CHARS);
476+
477+
if (!contentText.trim()) {
478+
throw new Error("这篇文章没有可发送给 AI 的正文内容");
479+
}
480+
476481
const isChineseArticle = hasChineseText(article.title);
477482
const expectedHeading = aiExpectedHeading(isChineseArticle);
478483
let rawAiOutput = "";
@@ -485,11 +490,9 @@ function App() {
485490
"content-type": "application/json",
486491
},
487492
body: JSON.stringify(
488-
buildAiResponseRequest(article, contentText || article.title, {
489-
isChineseArticle,
493+
buildAiResponseRequest(contentText, {
490494
prompt: aiPromptForArticle(config, isChineseArticle),
491495
stream: config.aiStream !== false,
492-
truncated: sourceText.length > MAX_AI_CONTENT_CHARS,
493496
}),
494497
),
495498
};
@@ -1533,29 +1536,10 @@ function aiPromptForArticle(config, isChineseArticle) {
15331536
return String(prompt || fallback).trim();
15341537
}
15351538

1536-
function buildAiResponseRequest(article, contentText, options) {
1537-
const expectedHeading = aiExpectedHeading(options.isChineseArticle);
1538-
const articleType = options.isChineseArticle
1539-
? "标题含中文字符,按中文文章处理:生成摘要。"
1540-
: "标题不含中文字符,按非中文文章处理:全文翻译为简体中文。";
1541-
1539+
function buildAiResponseRequest(contentText, options) {
15421540
return {
15431541
instructions: options.prompt,
1544-
input: [
1545-
`任务判定:${articleType}`,
1546-
`前端裁剪锚点:输出必须以 <h2>${expectedHeading}</h2> 开始。`,
1547-
options.truncated ? "注意:正文因为长度限制被截断,请在输出中简短说明。" : "",
1548-
"",
1549-
`Title: ${article.title || "无标题"}`,
1550-
article.author ? `Author: ${article.author}` : "",
1551-
article.publishedAt ? `Publish Time: ${article.publishedAt}` : "",
1552-
article.link ? `Link: ${article.link}` : "",
1553-
"",
1554-
"Content:",
1555-
contentText || article.title || "",
1556-
]
1557-
.filter((line) => line !== "")
1558-
.join("\n"),
1542+
input: contentText,
15591543
stream: Boolean(options.stream),
15601544
store: false,
15611545
};

0 commit comments

Comments
 (0)