xiongzhu 2 سال پیش
والد
کامیت
e414c348f0
1فایلهای تغییر یافته به همراه12 افزوده شده و 6 حذف شده
  1. 12 6
      src/paper/paper-gen/general.ts

+ 12 - 6
src/paper/paper-gen/general.ts

@@ -86,13 +86,18 @@ ${chapters2md(chapters)}
                         let prompt
                         if (section.children?.length) {
                             prompt = `${chapters2md(section.children, [i + 1, j + 1])}
-请按照以上结构编写第${i + 1}章: # ${chapter.title}
-## ${i + 1}.${j + 1} ${section.title} (请注意只需要编写这一小节的内容):`
+请按照以上结构编写第${i + 1}章${chapter.title}的${i + 1}.${j + 1}小节(请注意只需要编写这一小节的内容)
+## ${i + 1}.${j + 1} ${section.title} :`
                         } else {
-                            prompt = `第${i + 1}章: # ${chapter.title}
-## ${i + 1}.${j + 1} ${section.title} (请注意只需要编写这一小节的内容):`
+                            prompt = `请编写第${i + 1}章${chapter.title}的${i + 1}.${
+                                j + 1
+                            }小节(请注意只需要编写这一小节的内容)
+## ${i + 1}.${j + 1} ${section.title}:`
                         }
-                        const { content } = await llm.call([new SystemMessage(sysPrompt), new HumanMessage(prompt)])
+                        let { content } = await llm.call([new SystemMessage(sysPrompt), new HumanMessage(prompt)])
+                        content = content
+                            .replace(new RegExp(`#.*${chapter.title}.*\n`), '')
+                            .replace(new RegExp(`#.*${section.title}.*\n`), '')
                         return `## ${i + 1}.${j + 1} ${section.title}\n\n` + content
                     })
                 )
@@ -103,7 +108,8 @@ ${chapters2md(chapters)}
             if (chapter.title.includes('参考文献')) {
                 prompt += `(请给出一些文献来支持我的论点和方法,请给出文献的标题,作者,年份,摘要和关键词)`
             }
-            const { content } = await llm.call([new SystemMessage(sysPrompt), new HumanMessage(prompt)])
+            let { content } = await llm.call([new SystemMessage(sysPrompt), new HumanMessage(prompt)])
+            content = content.replace(new RegExp(`#.*${chapter.title}.*\n`), '')
             // if (!content.trim().split('\n')[0].includes(chapter.title)) {
             //     paper.write(`\n\n# ${chapter.title}`)
             // }