|
@@ -28,10 +28,15 @@ function chapters2md(chapters, sub = []) {
|
|
|
levels[i] = 0
|
|
levels[i] = 0
|
|
|
}
|
|
}
|
|
|
let title
|
|
let title
|
|
|
- if (level === 0 && !sub.length) {
|
|
|
|
|
- title = ''
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (sub.length) {
|
|
|
|
|
+ title = sub.concat(levels.slice(0, level + 1)).join('.') + ' '
|
|
|
} else {
|
|
} else {
|
|
|
- title = levels.slice(0, level + 1).join('.') + ' '
|
|
|
|
|
|
|
+ if (level === 0 && !sub.length) {
|
|
|
|
|
+ title = ''
|
|
|
|
|
+ } else {
|
|
|
|
|
+ title = levels.slice(0, level + 1).join('.') + ' '
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
md += `${' '.repeat(level)}- ${title}${child.title}\n`
|
|
md += `${' '.repeat(level)}- ${title}${child.title}\n`
|
|
@@ -75,24 +80,29 @@ ${chapters2md(chapters)}
|
|
|
// paper.write('\n\n' + content)
|
|
// paper.write('\n\n' + content)
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
- paper.write(
|
|
|
|
|
- '\n\n' +
|
|
|
|
|
- (
|
|
|
|
|
- await Promise.all(
|
|
|
|
|
- chapter.children.map(async (section, j) => {
|
|
|
|
|
- let prompt = `第${i + 1}章: # ${chapter.title}`
|
|
|
|
|
- prompt += `\n## ${i + 1}.${j + 1} ${section.title} (请注意只需要编写这一小节的内容):`
|
|
|
|
|
- const { content } = await llm.call([
|
|
|
|
|
- new SystemMessage(sysPrompt),
|
|
|
|
|
- new HumanMessage(prompt)
|
|
|
|
|
- ])
|
|
|
|
|
- return `## ${i + 1}.${j + 1} ${section.title}\n\n` + content
|
|
|
|
|
- })
|
|
|
|
|
- )
|
|
|
|
|
- ).join('\n\n')
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ const content = (
|
|
|
|
|
+ await Promise.all(
|
|
|
|
|
+ chapter.children.map(async (section, j) => {
|
|
|
|
|
+ let prompt
|
|
|
|
|
+ if (section.children?.length) {
|
|
|
|
|
+ prompt = `${chapters2md(section.children, [i + 1, j + 1])}
|
|
|
|
|
+请按照以上结构编写第${i + 1}章: # ${chapter.title}
|
|
|
|
|
+## ${i + 1}.${j + 1} ${section.title} (请注意只需要编写这一小节的内容):`
|
|
|
|
|
+ } else {
|
|
|
|
|
+ prompt = `第${i + 1}章: # ${chapter.title}
|
|
|
|
|
+## ${i + 1}.${j + 1} ${section.title} (请注意只需要编写这一小节的内容):`
|
|
|
|
|
+ }
|
|
|
|
|
+ const { content } = await llm.call([new SystemMessage(sysPrompt), new HumanMessage(prompt)])
|
|
|
|
|
+ return `## ${i + 1}.${j + 1} ${section.title}\n\n` + content
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
|
|
+ ).join('\n\n')
|
|
|
|
|
+ paper.write('\n\n' + content)
|
|
|
} else {
|
|
} else {
|
|
|
let prompt = `第${i + 1}章: # ${chapter.title}`
|
|
let prompt = `第${i + 1}章: # ${chapter.title}`
|
|
|
|
|
+ if (chapter.title.includes('参考文献')) {
|
|
|
|
|
+ prompt += `(请给出一些文献来支持我的论点和方法,请给出文献的标题,作者,年份,摘要和关键词)`
|
|
|
|
|
+ }
|
|
|
const { content } = await llm.call([new SystemMessage(sysPrompt), new HumanMessage(prompt)])
|
|
const { content } = await llm.call([new SystemMessage(sysPrompt), new HumanMessage(prompt)])
|
|
|
// if (!content.trim().split('\n')[0].includes(chapter.title)) {
|
|
// if (!content.trim().split('\n')[0].includes(chapter.title)) {
|
|
|
// paper.write(`\n\n# ${chapter.title}`)
|
|
// paper.write(`\n\n# ${chapter.title}`)
|