write scene details

Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Xe Iaso 2023-04-14 17:20:15 -04:00
parent d5abf3e67e
commit 84dfa12326
3 changed files with 84 additions and 2 deletions

54
book.ts
View File

@ -145,3 +145,57 @@ export const createAndParseSummary = async (
return bookInfo;
};
export const createChapterScenes = async (
dirName: string,
openai: OpenAIApi,
summary: Summary,
ch: ChapterListItem
): Promise<Chapter> => {
console.log(`creating chapter scene information for chapter ${ch.title}`);
const prompt =
`Given the following plot summary, character information, and chapter information, write descriptions of scenes that would happen in that chapter. End each description with two newlines. Write at least 4 scenes. Use detail and be creative. DO NOT include the chapter title in your output. ONLY output the scenes separated by newlines like this.
What happens first.
What happens after that.
Plot summary: ${summary.plotSummary}
Character information:
` +
summary.characters.map((char) => `- ${char.name}: ${char.role}`).join("\n") +
`
Chapter title: ${ch.title}
Chapter summary: ${ch.summary}`;
const chInfo = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{
role: "user",
content: prompt,
},
],
});
const chInfoText = chInfo.data.choices[0].message?.content as string;
return {
title: ch.title,
summary: ch.summary,
sceneDescriptions: chInfoText.split("\n\n"),
};
};
export const writeChapterScene = async (
dirName: string,
openai: OpenAIApi,
summary: Summary,
ch: Chapter,
chNum: number,
sceneNum: number,
scene: string
): Promise<string> => {
return "";
};

View File

@ -104,4 +104,33 @@ program
summary.chapterList.forEach(({ title, summary }) => console.log(`- ${title} - ${summary}`));
});
program
.command("genChapterScenes <dir>")
.description("generate the list of scenes for all of the chapters in the chapter")
.action(async (dir) => {
if (!fileExists(dir)) {
console.error(`${dir} does not exist, run init?`);
process.exit(1);
}
if (!fileExists(`${dir}/summary.json`)) {
console.error(`plot summary does not exist in ${dir}, run genSummary?`);
process.exit(1);
}
if (fileExists(`${dir}/chapterScenes.json`)) {
console.error(`plot summary already exists in ${dir}`);
process.exit(1);
}
const summary: book.Summary = JSON.parse(await fs.readFile(`${dir}/summary.json`, "utf8"));
const chapters: book.Chapter[] = [];
for (const ch of summary.chapterList) {
chapters.push(await book.createChapterScenes(dir, openai, summary, ch));
}
console.log(chapters);
await fs.writeFile(`${dir}/chapterScenes.json`, JSON.stringify(chapters));
});
program.parse();

View File

@ -10,8 +10,7 @@
"sourceMap": true,
"target": "es2022",
"types": ["node"],
"outDir": "dist",
"allowImportingTsExtensions": true
"outDir": "dist"
},
"exclude": ["node_modules"]
}