@@ -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