|
|
@@ -9,7 +9,7 @@ import { parseOutline } from '../parsers/outline.parser';
|
|
|
import { buildOutlineMessages, SCALE_CHAPTER_RANGE } from '../prompts/builder';
|
|
|
import { PROGRESS } from '../utils';
|
|
|
import { callLLMWithRetry, executeNodeWithTimeout, FAULT_TOLERANCE_CONFIG } from '../fault-tolerance';
|
|
|
-import { getChapterRange } from '../book-type-config';
|
|
|
+import { getChapterRange, calcChapters } from '../book-type-config';
|
|
|
|
|
|
export async function generateOutlineNode(state: typeof GraphState.State): Promise<Partial<typeof GraphState.State>> {
|
|
|
console.log('[LangGraph] 生成大纲, bookId:', state.bookId, 'scale:', state.bookScale);
|
|
|
@@ -96,6 +96,14 @@ export async function generateOutlineNode(state: typeof GraphState.State): Promi
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
+ // 根据 bookScale 限制章节数(防止LLM生成超出配置范围的章节)
|
|
|
+ const configuredChapters = calcChapters(parseInt(state.bookScale) || 2000);
|
|
|
+ const chapterRange = getChapterRange(configuredChapters);
|
|
|
+ if (outline.chapters.length > chapterRange.max) {
|
|
|
+ console.log(`[LangGraph] 大纲章节数(${outline.chapters.length})超出上限(${chapterRange.max}),裁剪到${chapterRange.max}章`);
|
|
|
+ outline.chapters = outline.chapters.slice(0, chapterRange.max);
|
|
|
+ }
|
|
|
+
|
|
|
const totalChapters = outline.chapters.length;
|
|
|
await bookStore.update(state.bookId, {
|
|
|
totalChapters,
|