From 9cd45747e1bfd3d795cd76f1ee2ce130ded31da2 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sat, 15 Apr 2023 07:56:21 -0400 Subject: [PATCH] index: command to rewrite an entire chapter Signed-off-by: Xe Iaso --- index.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/index.ts b/index.ts index 7d367ed..454f5a7 100644 --- a/index.ts +++ b/index.ts @@ -231,6 +231,37 @@ language: en-US console.log(stdout); }); +program + .command("rewriteChapter ") + .description("completely rewrite a single chapter, useful for fixing the generation process") + .action(async (dir, chapterStr) => { + await fs.mkdir(`${dir}/src`, { recursive: true }); + + const chapter = parseInt(chapterStr); + console.log({ dir, chapter }); + + const summary: book.Summary = JSON.parse(await fs.readFile(`${dir}/summary.json`, "utf8")); + const chapters: book.Chapter[] = JSON.parse( + await fs.readFile(`${dir}/chapterScenes.json`, "utf8") + ); + + const ch = await book.createChapterScenes( + dir, + openai, + summary, + summary.chapterList[chapter - 1] + ); + + chapters[chapter - 1] = ch; + + await fs.writeFile(`${dir}/chapterScenes.json`, JSON.stringify(chapters)); + + for (let [sceneNum, scene] of ch.sceneDescriptions.entries()) { + sceneNum = sceneNum + 1; + console.log(await book.writeChapterScene(dir, openai, summary, ch, chapter, sceneNum, scene)); + } + }); + program .command("writeOneScene ") .description("write a single scene of the novel, useful for debugging the generation process")