|
|
@@ -16,7 +16,7 @@ export async function genGeneralPaper(major: string, title: string, desc: string
|
|
|
const { llm, usage, conversation } = tools
|
|
|
const pRetry = (await eval("import('p-retry')")).default
|
|
|
|
|
|
- const chapters = await genChapters(major, tools, title, desc)
|
|
|
+ const chapters = await genChapters(tools, major, title, desc)
|
|
|
Logger.log(JSON.stringify(chapters, null, 4))
|
|
|
|
|
|
let paper = new WritableStreamBuffer()
|
|
|
@@ -83,7 +83,7 @@ export async function genGeneralPaper1(major: string, title: string, desc: strin
|
|
|
const { llm, usage, conversation } = tools
|
|
|
const pRetry = (await eval("import('p-retry')")).default
|
|
|
|
|
|
- const chapters = await genChapters(major, tools, title, desc)
|
|
|
+ const chapters = await genChapters(tools, major, title, desc)
|
|
|
Logger.log(JSON.stringify(chapters, null, 4))
|
|
|
|
|
|
let paper = new WritableStreamBuffer()
|
|
|
@@ -93,20 +93,23 @@ export async function genGeneralPaper1(major: string, title: string, desc: strin
|
|
|
|
|
|
for (let i = 0; i < chapters.length; i++) {
|
|
|
const sysPrompt = `你是一个擅长写${major}专业毕业论文的专家。
|
|
|
-你的任务是写一篇标题为"${title}"的论文。以下是本论文的大纲,请你根据大纲分章节帮我生成文章:
|
|
|
-${chapters.map((i) => `- ${i.chapterName}\n ${i.chapterDesc}`).join('\n')}`
|
|
|
- let prompt = `请开始完成第${i + 1}章:${chapters[i].chapterName},本章主要内容是${chapters[i].chapterDesc}`
|
|
|
+你的任务是写一篇标题为"${title}"的论文。
|
|
|
+以下是论文的大纲:
|
|
|
+${chapters.map((i, index) => `${index + 1}. ${i.chapterName}\n ${i.chapterDesc}`).join('\n')}
|
|
|
+
|
|
|
+你要根据大纲分章节帮我生成文章。
|
|
|
+你的语气应正式,内容应适合和吸引一般读者。
|
|
|
+你要严格按照markdown格式返回内容。
|
|
|
+你只需要输出能够直接出现在论文中的内容,不需要输出你对该内容的总结或者介绍等其他文字,不需要出现介绍下一章或其他承上启下的文字。`
|
|
|
+ let prompt = `第${i + 1}章是:${chapters[i].chapterName},本章主要内容是${chapters[i].chapterDesc}`
|
|
|
if (chapters[i].sections && chapters[i].sections.length) {
|
|
|
- prompt += `\n本章分为多个小节,分别是:
|
|
|
+ prompt += `\n本章分为多个小节,每小节的主要论述内容应采用五段式结构进行论述,论述内容应尽量详细且逻辑清晰。
|
|
|
+以下是各小节的简介:
|
|
|
${chapters[i].sections.map((e) => `- ${e.sectionName}\n ${e.sectionDesc}`).join('\n')}
|
|
|
|
|
|
-请按照此结构完成本章内容`
|
|
|
+请按照此结构一次性完成本章内容`
|
|
|
}
|
|
|
prompt += `\n
|
|
|
-每小节的主要论述内容应采用五段式结构进行论述,论述内容应尽量详细且逻辑清晰。
|
|
|
-语气应正式,内容应适合和吸引一般读者。
|
|
|
-请严格按照markdown格式返回内容。
|
|
|
-你只需要输出能够直接出现在论文中的内容,不需要输出你对该内容的总结或者介绍等其他文字,不需要出现介绍下一章或其他承上启下的文字。
|
|
|
第${i + 1}章:# ${chapters[i].chapterName}:`
|
|
|
const { content } = await llm.call([new SystemMessage(sysPrompt), new HumanMessage(prompt)])
|
|
|
if (!content.trim().split('\n')[0].includes(chapters[i].chapterName)) {
|
|
|
@@ -115,7 +118,23 @@ ${chapters[i].sections.map((e) => `- ${e.sectionName}\n ${e.sectionDesc}`).jo
|
|
|
paper.write('\n\n' + content)
|
|
|
}
|
|
|
|
|
|
- const content = paper.getContentsAsString('utf8')
|
|
|
+ let content = paper.getContentsAsString('utf8').split('\n')
|
|
|
+ for (let i = 0; i < content.length; i++) {
|
|
|
+ const match = content[i].match(/(^#+)([^ #]+)/)
|
|
|
+ if (match) {
|
|
|
+ content[i] = match[1] + ' ' + match[2]
|
|
|
+ }
|
|
|
+ if (/^#+.*$/.test(content[i])) {
|
|
|
+ if (content[i - 1] && content[i - 1].length) {
|
|
|
+ content[i] = '\n' + content[i]
|
|
|
+ }
|
|
|
+ if (content[i + 1] && content[i + 1].length) {
|
|
|
+ content[i] += '\n'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ content = content.join('\n')
|
|
|
+
|
|
|
const duration = (Date.now() - startTime) / 1000
|
|
|
const fileUrl = await uploadDoc(title, content)
|
|
|
return {
|