mulmocast 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -2
- package/assets/templates/business.json +2 -181
- package/assets/templates/children_book.json +1 -128
- package/assets/templates/coding.json +2 -136
- package/assets/templates/comic_strips.json +1 -30
- package/assets/templates/ghibli_strips.json +1 -30
- package/assets/templates/sensei_and_taro.json +1 -118
- package/lib/actions/audio.js +41 -31
- package/lib/actions/captions.js +39 -26
- package/lib/actions/images.js +31 -11
- package/lib/actions/movie.js +30 -21
- package/lib/actions/pdf.js +11 -1
- package/lib/actions/translate.js +33 -18
- package/lib/agents/combine_audio_files_agent.js +19 -8
- package/lib/cli/commands/tool/scripting/builder.d.ts +1 -1
- package/lib/cli/commands/tool/scripting/builder.js +4 -4
- package/lib/cli/commands/tool/scripting/handler.d.ts +2 -1
- package/lib/cli/commands/tool/scripting/handler.js +3 -3
- package/lib/cli/commands/tool/story_to_script/builder.d.ts +3 -1
- package/lib/cli/commands/tool/story_to_script/builder.js +12 -4
- package/lib/cli/commands/tool/story_to_script/handler.d.ts +3 -1
- package/lib/cli/commands/tool/story_to_script/handler.js +4 -3
- package/lib/methods/mulmo_script_template.d.ts +2 -2
- package/lib/methods/mulmo_script_template.js +2 -2
- package/lib/methods/mulmo_studio.d.ts +8 -0
- package/lib/methods/mulmo_studio.js +24 -0
- package/lib/tools/create_mulmo_script_from_url.d.ts +1 -1
- package/lib/tools/create_mulmo_script_from_url.js +7 -7
- package/lib/tools/create_mulmo_script_interactively.d.ts +1 -1
- package/lib/tools/create_mulmo_script_interactively.js +8 -8
- package/lib/tools/story_to_script.d.ts +5 -3
- package/lib/tools/story_to_script.js +90 -16
- package/lib/types/schema.d.ts +320 -1766
- package/lib/types/schema.js +41 -2
- package/lib/types/type.d.ts +4 -2
- package/lib/utils/const.d.ts +4 -0
- package/lib/utils/const.js +4 -0
- package/lib/utils/file.d.ts +1 -0
- package/lib/utils/file.js +16 -4
- package/lib/utils/filters.js +16 -11
- package/lib/utils/markdown.js +0 -2
- package/lib/utils/preprocess.d.ts +34 -15
- package/lib/utils/preprocess.js +3 -2
- package/lib/utils/prompt.d.ts +2 -1
- package/lib/utils/prompt.js +20 -3
- package/lib/utils/utils.d.ts +8 -5
- package/lib/utils/utils.js +27 -17
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { llm } from "../../../../utils/utils.js";
|
|
2
2
|
import { getAvailableTemplates } from "../../../../utils/file.js";
|
|
3
3
|
const availableTemplateNames = getAvailableTemplates().map((template) => template.filename);
|
|
4
4
|
export const builder = (yargs) => {
|
|
@@ -49,10 +49,10 @@ export const builder = (yargs) => {
|
|
|
49
49
|
default: "script",
|
|
50
50
|
type: "string",
|
|
51
51
|
})
|
|
52
|
-
.option("
|
|
53
|
-
description: "llm
|
|
52
|
+
.option("llm", {
|
|
53
|
+
description: "llm",
|
|
54
54
|
demandOption: false,
|
|
55
|
-
choices:
|
|
55
|
+
choices: llm,
|
|
56
56
|
type: "string",
|
|
57
57
|
})
|
|
58
58
|
.option("llm_model", {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ToolCliArgs } from "../../../../types/cli_types.js";
|
|
2
|
+
import { LLM } from "../../../../utils/utils.js";
|
|
2
3
|
export declare const handler: (argv: ToolCliArgs<{
|
|
3
4
|
o?: string;
|
|
4
5
|
b?: string;
|
|
@@ -7,6 +8,6 @@ export declare const handler: (argv: ToolCliArgs<{
|
|
|
7
8
|
t?: string;
|
|
8
9
|
c?: string;
|
|
9
10
|
s?: string;
|
|
10
|
-
|
|
11
|
+
llm?: LLM;
|
|
11
12
|
llm_model?: string;
|
|
12
13
|
}>) => Promise<void>;
|
|
@@ -5,7 +5,7 @@ import { createMulmoScriptFromUrl } from "../../../../tools/create_mulmo_script_
|
|
|
5
5
|
import { createMulmoScriptInteractively } from "../../../../tools/create_mulmo_script_interactively.js";
|
|
6
6
|
import { setGraphAILogger } from "../../../../cli/helpers.js";
|
|
7
7
|
export const handler = async (argv) => {
|
|
8
|
-
const { o: outdir, b: basedir, v: verbose, i: interactive, c: cache, s: filename,
|
|
8
|
+
const { o: outdir, b: basedir, v: verbose, i: interactive, c: cache, s: filename, llm, llm_model } = argv;
|
|
9
9
|
let { t: template } = argv;
|
|
10
10
|
const urls = argv.u || [];
|
|
11
11
|
const baseDirPath = getBaseDirPath(basedir);
|
|
@@ -22,10 +22,10 @@ export const handler = async (argv) => {
|
|
|
22
22
|
urls,
|
|
23
23
|
interactive,
|
|
24
24
|
filename,
|
|
25
|
-
|
|
25
|
+
llm,
|
|
26
26
|
llm_model,
|
|
27
27
|
});
|
|
28
|
-
const context = { outDirPath, templateName: template, urls, filename: filename, cacheDirPath, llm_model,
|
|
28
|
+
const context = { outDirPath, templateName: template, urls, filename: filename, cacheDirPath, llm_model, llm };
|
|
29
29
|
if (interactive) {
|
|
30
30
|
await createMulmoScriptInteractively(context);
|
|
31
31
|
}
|
|
@@ -10,9 +10,11 @@ export declare const builder: (yargs: Argv) => Argv<{
|
|
|
10
10
|
} & {
|
|
11
11
|
beats_per_scene: number;
|
|
12
12
|
} & {
|
|
13
|
-
|
|
13
|
+
llm: "openAI" | "anthropic" | "gemini" | "groq" | undefined;
|
|
14
14
|
} & {
|
|
15
15
|
llm_model: string | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
mode: string;
|
|
16
18
|
} & {
|
|
17
19
|
file: string | undefined;
|
|
18
20
|
}>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getAvailableTemplates } from "../../../../utils/file.js";
|
|
2
|
-
import {
|
|
2
|
+
import { llm } from "../../../../utils/utils.js";
|
|
3
|
+
import { storyToScriptGenerateMode } from "../../../../utils/const.js";
|
|
3
4
|
const availableTemplateNames = getAvailableTemplates().map((template) => template.filename);
|
|
4
5
|
export const builder = (yargs) => {
|
|
5
6
|
return yargs
|
|
@@ -35,16 +36,23 @@ export const builder = (yargs) => {
|
|
|
35
36
|
default: 3,
|
|
36
37
|
type: "number",
|
|
37
38
|
})
|
|
38
|
-
.option("
|
|
39
|
-
description: "llm
|
|
39
|
+
.option("llm", {
|
|
40
|
+
description: "llm",
|
|
40
41
|
demandOption: false,
|
|
41
|
-
choices:
|
|
42
|
+
choices: llm,
|
|
42
43
|
type: "string",
|
|
43
44
|
})
|
|
44
45
|
.option("llm_model", {
|
|
45
46
|
description: "llm model",
|
|
46
47
|
demandOption: false,
|
|
47
48
|
type: "string",
|
|
49
|
+
})
|
|
50
|
+
.option("mode", {
|
|
51
|
+
description: "story to script generation mode",
|
|
52
|
+
demandOption: false,
|
|
53
|
+
choices: Object.values(storyToScriptGenerateMode),
|
|
54
|
+
default: storyToScriptGenerateMode.stepWise,
|
|
55
|
+
type: "string",
|
|
48
56
|
})
|
|
49
57
|
.positional("file", {
|
|
50
58
|
description: "story file path",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ToolCliArgs } from "../../../../types/cli_types.js";
|
|
2
|
+
import { LLM } from "../../../../utils/utils.js";
|
|
2
3
|
export declare const handler: (argv: ToolCliArgs<{
|
|
3
4
|
o?: string;
|
|
4
5
|
b?: string;
|
|
@@ -6,6 +7,7 @@ export declare const handler: (argv: ToolCliArgs<{
|
|
|
6
7
|
s?: string;
|
|
7
8
|
beats_per_scene?: number;
|
|
8
9
|
file?: string;
|
|
9
|
-
|
|
10
|
+
llm?: LLM;
|
|
10
11
|
llm_model?: string;
|
|
12
|
+
mode?: string;
|
|
11
13
|
}>) => Promise<void>;
|
|
@@ -5,7 +5,7 @@ import { mulmoStoryboardSchema } from "../../../../types/schema.js";
|
|
|
5
5
|
import { getBaseDirPath, getFullPath, readAndParseJson } from "../../../../utils/file.js";
|
|
6
6
|
import { outDirName } from "../../../../utils/const.js";
|
|
7
7
|
export const handler = async (argv) => {
|
|
8
|
-
const { v: verbose, s: filename, file, o: outdir, b: basedir, beats_per_scene,
|
|
8
|
+
const { v: verbose, s: filename, file, o: outdir, b: basedir, beats_per_scene, llm, llm_model, mode } = argv;
|
|
9
9
|
let { t: template } = argv;
|
|
10
10
|
const baseDirPath = getBaseDirPath(basedir);
|
|
11
11
|
const outDirPath = getFullPath(baseDirPath, outdir ?? outDirName);
|
|
@@ -19,7 +19,7 @@ export const handler = async (argv) => {
|
|
|
19
19
|
fileName: filename,
|
|
20
20
|
beatsPerScene: beats_per_scene,
|
|
21
21
|
storyFilePath: file,
|
|
22
|
-
llmAgent:
|
|
22
|
+
llmAgent: llm,
|
|
23
23
|
llmModel: llm_model,
|
|
24
24
|
});
|
|
25
25
|
const parsedStory = readAndParseJson(file, mulmoStoryboardSchema);
|
|
@@ -29,7 +29,8 @@ export const handler = async (argv) => {
|
|
|
29
29
|
templateName: template,
|
|
30
30
|
outdir: outDirPath,
|
|
31
31
|
fileName: filename,
|
|
32
|
-
|
|
32
|
+
llm,
|
|
33
33
|
llmModel: llm_model,
|
|
34
|
+
generateMode: mode,
|
|
34
35
|
});
|
|
35
36
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MulmoScriptTemplate } from "../types/index.js";
|
|
1
|
+
import { MulmoScript, MulmoScriptTemplate } from "../types/index.js";
|
|
2
2
|
export declare const MulmoScriptTemplateMethods: {
|
|
3
|
-
getSystemPrompt(template: MulmoScriptTemplate): string;
|
|
3
|
+
getSystemPrompt(template: MulmoScriptTemplate, script?: MulmoScript): string;
|
|
4
4
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getMulmoScriptTemplateSystemPrompt } from "../utils/prompt.js";
|
|
2
2
|
export const MulmoScriptTemplateMethods = {
|
|
3
|
-
getSystemPrompt(template) {
|
|
4
|
-
return getMulmoScriptTemplateSystemPrompt(template);
|
|
3
|
+
getSystemPrompt(template, script) {
|
|
4
|
+
return getMulmoScriptTemplateSystemPrompt(template, script);
|
|
5
5
|
},
|
|
6
6
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MulmoStudio } from "../types/index.js";
|
|
2
|
+
type SessionType = "audio" | "image" | "video" | "multiLingual" | "caption" | "pdf";
|
|
3
|
+
type BeatSessionType = "audio" | "image" | "multiLingual" | "caption";
|
|
4
|
+
export declare const MulmoStudioMethods: {
|
|
5
|
+
setSessionState(studio: MulmoStudio, sessionType: SessionType, value: boolean): void;
|
|
6
|
+
setBeatSessionState(studio: MulmoStudio, sessionType: BeatSessionType, index: number, value: boolean): void;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GraphAILogger } from "graphai";
|
|
2
|
+
const notifyStateChange = (studio, sessionType) => {
|
|
3
|
+
const prefix = studio.state.inSession[sessionType] ? "<" : " >";
|
|
4
|
+
GraphAILogger.info(`${prefix} ${sessionType}`);
|
|
5
|
+
};
|
|
6
|
+
const notifyBeatStateChange = (studio, sessionType, index) => {
|
|
7
|
+
const prefix = studio.state.inBeatSession[sessionType].has(index) ? "{" : " }";
|
|
8
|
+
GraphAILogger.info(`${prefix} ${sessionType} ${index}`);
|
|
9
|
+
};
|
|
10
|
+
export const MulmoStudioMethods = {
|
|
11
|
+
setSessionState(studio, sessionType, value) {
|
|
12
|
+
studio.state.inSession[sessionType] = value;
|
|
13
|
+
notifyStateChange(studio, sessionType);
|
|
14
|
+
},
|
|
15
|
+
setBeatSessionState(studio, sessionType, index, value) {
|
|
16
|
+
if (value) {
|
|
17
|
+
studio.state.inBeatSession[sessionType].add(index);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
studio.state.inBeatSession[sessionType].delete(index);
|
|
21
|
+
}
|
|
22
|
+
notifyBeatStateChange(studio, sessionType, index);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { ScriptingParams } from "../types/index.js";
|
|
3
|
-
export declare const createMulmoScriptFromUrl: ({ urls, templateName, outDirPath, filename, cacheDirPath,
|
|
3
|
+
export declare const createMulmoScriptFromUrl: ({ urls, templateName, outDirPath, filename, cacheDirPath, llm, llm_model }: ScriptingParams) => Promise<void>;
|
|
@@ -104,14 +104,14 @@ const graphData = {
|
|
|
104
104
|
},
|
|
105
105
|
llm: {
|
|
106
106
|
agent: ":llmAgent",
|
|
107
|
-
params: {
|
|
108
|
-
model: ":llmModel",
|
|
109
|
-
system: ":prompt",
|
|
110
|
-
max_tokens: ":maxTokens",
|
|
111
|
-
},
|
|
112
107
|
inputs: {
|
|
113
108
|
system: ":prompt",
|
|
114
109
|
prompt: graphDataScriptFromUrlPrompt("${:sourceText.text}"),
|
|
110
|
+
params: {
|
|
111
|
+
model: ":llmModel",
|
|
112
|
+
system: ":prompt",
|
|
113
|
+
max_tokens: ":maxTokens",
|
|
114
|
+
},
|
|
115
115
|
},
|
|
116
116
|
},
|
|
117
117
|
validateSchemaAgent: {
|
|
@@ -145,7 +145,7 @@ const graphData = {
|
|
|
145
145
|
},
|
|
146
146
|
},
|
|
147
147
|
};
|
|
148
|
-
export const createMulmoScriptFromUrl = async ({ urls, templateName, outDirPath, filename, cacheDirPath,
|
|
148
|
+
export const createMulmoScriptFromUrl = async ({ urls, templateName, outDirPath, filename, cacheDirPath, llm, llm_model }) => {
|
|
149
149
|
mkdir(outDirPath);
|
|
150
150
|
mkdir(cacheDirPath);
|
|
151
151
|
const parsedUrls = urlsSchema.parse(urls);
|
|
@@ -157,7 +157,7 @@ export const createMulmoScriptFromUrl = async ({ urls, templateName, outDirPath,
|
|
|
157
157
|
nodeIds: ["fetcher"],
|
|
158
158
|
},
|
|
159
159
|
];
|
|
160
|
-
const { agent, model, max_tokens } = llmPair(
|
|
160
|
+
const { agent, model, max_tokens } = llmPair(llm, llm_model);
|
|
161
161
|
const graph = new GraphAI(graphData, {
|
|
162
162
|
...vanillaAgents,
|
|
163
163
|
openAIAgent,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { ScriptingParams } from "../types/index.js";
|
|
3
|
-
export declare const createMulmoScriptInteractively: ({ outDirPath, cacheDirPath, filename, templateName, urls,
|
|
3
|
+
export declare const createMulmoScriptInteractively: ({ outDirPath, cacheDirPath, filename, templateName, urls, llm, llm_model }: ScriptingParams) => Promise<void>;
|
|
@@ -118,15 +118,15 @@ const graphData = {
|
|
|
118
118
|
},
|
|
119
119
|
chatAgent: {
|
|
120
120
|
agent: ":llmAgent",
|
|
121
|
-
params: {
|
|
122
|
-
model: ":llmModel",
|
|
123
|
-
stream: true,
|
|
124
|
-
dataStream: true,
|
|
125
|
-
max_tokens: ":maxTokens",
|
|
126
|
-
},
|
|
127
121
|
inputs: {
|
|
128
122
|
messages: ":messages",
|
|
129
123
|
prompt: ":prompt",
|
|
124
|
+
params: {
|
|
125
|
+
model: ":llmModel",
|
|
126
|
+
stream: true,
|
|
127
|
+
dataStream: true,
|
|
128
|
+
max_tokens: ":maxTokens",
|
|
129
|
+
},
|
|
130
130
|
},
|
|
131
131
|
isResult: true,
|
|
132
132
|
},
|
|
@@ -217,11 +217,11 @@ const scrapeWebContent = async (urls, cacheDirPath) => {
|
|
|
217
217
|
}
|
|
218
218
|
return `\n\n${prefixPrompt}\n${result?.sourceText.text}`;
|
|
219
219
|
};
|
|
220
|
-
export const createMulmoScriptInteractively = async ({ outDirPath, cacheDirPath, filename, templateName, urls,
|
|
220
|
+
export const createMulmoScriptInteractively = async ({ outDirPath, cacheDirPath, filename, templateName, urls, llm, llm_model }) => {
|
|
221
221
|
mkdir(outDirPath);
|
|
222
222
|
// if urls is not empty, scrape web content and reference it in the prompt
|
|
223
223
|
const webContentPrompt = urls.length > 0 ? await scrapeWebContent(urls, cacheDirPath) : "";
|
|
224
|
-
const { agent, model, max_tokens } = llmPair(
|
|
224
|
+
const { agent, model, max_tokens } = llmPair(llm, llm_model);
|
|
225
225
|
GraphAILogger.log({ agent, model, max_tokens });
|
|
226
226
|
const agentFilters = [
|
|
227
227
|
{
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { MulmoStoryboard } from "../types/index.js";
|
|
2
|
-
|
|
1
|
+
import { MulmoStoryboard, StoryToScriptGenerateMode } from "../types/index.js";
|
|
2
|
+
import { LLM } from "../utils/utils.js";
|
|
3
|
+
export declare const storyToScript: ({ story, beatsPerScene, templateName, outdir, fileName, llm, llmModel, generateMode, }: {
|
|
3
4
|
story: MulmoStoryboard;
|
|
4
5
|
beatsPerScene: number;
|
|
5
6
|
templateName: string;
|
|
6
7
|
outdir: string;
|
|
7
8
|
fileName: string;
|
|
8
|
-
|
|
9
|
+
llm?: LLM;
|
|
9
10
|
llmModel?: string;
|
|
11
|
+
generateMode: StoryToScriptGenerateMode;
|
|
10
12
|
}) => Promise<void>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getTemplateFilePath, writingMessage } from "../utils/file.js";
|
|
1
|
+
import { getTemplateFilePath, readAndParseJson, readScriptTemplateFile, writingMessage } from "../utils/file.js";
|
|
3
2
|
import { mulmoScriptSchema, mulmoScriptTemplateSchema } from "../types/schema.js";
|
|
4
3
|
import { GraphAI, GraphAILogger } from "graphai";
|
|
5
4
|
import { openAIAgent } from "@graphai/openai_agent";
|
|
@@ -7,10 +6,12 @@ import { anthropicAgent } from "@graphai/anthropic_agent";
|
|
|
7
6
|
import { geminiAgent } from "@graphai/gemini_agent";
|
|
8
7
|
import { groqAgent } from "@graphai/groq_agent";
|
|
9
8
|
import * as agents from "@graphai/vanilla";
|
|
10
|
-
import { graphDataScriptGeneratePrompt, sceneToBeatsPrompt, storyToScriptInfoPrompt } from "../utils/prompt.js";
|
|
9
|
+
import { graphDataScriptGeneratePrompt, sceneToBeatsPrompt, storyToScriptInfoPrompt, storyToScriptPrompt } from "../utils/prompt.js";
|
|
11
10
|
import { fileWriteAgent } from "@graphai/vanilla_node_agents";
|
|
12
11
|
import validateSchemaAgent from "../agents/validate_schema_agent.js";
|
|
13
12
|
import { llmPair } from "../utils/utils.js";
|
|
13
|
+
import { storyToScriptGenerateMode } from "../utils/const.js";
|
|
14
|
+
import { cliLoadingPlugin } from "../utils/plugins.js";
|
|
14
15
|
const { default: __, ...vanillaAgents } = agents;
|
|
15
16
|
const createValidatedScriptGraphData = ({ systemPrompt, prompt, schema, llmAgent, llmModel, maxTokens, }) => {
|
|
16
17
|
return {
|
|
@@ -55,7 +56,7 @@ const createValidatedScriptGraphData = ({ systemPrompt, prompt, schema, llmAgent
|
|
|
55
56
|
},
|
|
56
57
|
};
|
|
57
58
|
};
|
|
58
|
-
const
|
|
59
|
+
const stepWiseGraphData = {
|
|
59
60
|
version: 0.5,
|
|
60
61
|
nodes: {
|
|
61
62
|
scenes: {
|
|
@@ -167,35 +168,108 @@ const graphData = {
|
|
|
167
168
|
},
|
|
168
169
|
},
|
|
169
170
|
};
|
|
171
|
+
const oneStepGraphData = {
|
|
172
|
+
version: 0.5,
|
|
173
|
+
nodes: {
|
|
174
|
+
prompt: {
|
|
175
|
+
value: "",
|
|
176
|
+
},
|
|
177
|
+
outdir: {
|
|
178
|
+
value: "",
|
|
179
|
+
},
|
|
180
|
+
fileName: {
|
|
181
|
+
value: "",
|
|
182
|
+
},
|
|
183
|
+
llmAgent: {
|
|
184
|
+
value: "",
|
|
185
|
+
},
|
|
186
|
+
llmModel: {
|
|
187
|
+
value: "",
|
|
188
|
+
},
|
|
189
|
+
maxTokens: {
|
|
190
|
+
value: 0,
|
|
191
|
+
},
|
|
192
|
+
script: {
|
|
193
|
+
agent: "nestedAgent",
|
|
194
|
+
inputs: {
|
|
195
|
+
prompt: ":prompt",
|
|
196
|
+
llmAgent: ":llmAgent",
|
|
197
|
+
llmModel: ":llmModel",
|
|
198
|
+
maxTokens: ":maxTokens",
|
|
199
|
+
},
|
|
200
|
+
graph: createValidatedScriptGraphData({
|
|
201
|
+
systemPrompt: "",
|
|
202
|
+
prompt: graphDataScriptGeneratePrompt("${:prompt}"),
|
|
203
|
+
schema: mulmoScriptSchema,
|
|
204
|
+
llmAgent: ":llmAgent",
|
|
205
|
+
llmModel: ":llmModel",
|
|
206
|
+
maxTokens: ":maxTokens",
|
|
207
|
+
}),
|
|
208
|
+
},
|
|
209
|
+
json: {
|
|
210
|
+
agent: "copyAgent",
|
|
211
|
+
inputs: {
|
|
212
|
+
json: ":script.validateSchema.data",
|
|
213
|
+
},
|
|
214
|
+
params: {
|
|
215
|
+
namedKey: "json",
|
|
216
|
+
},
|
|
217
|
+
isResult: true,
|
|
218
|
+
},
|
|
219
|
+
writeJSON: {
|
|
220
|
+
agent: "fileWriteAgent",
|
|
221
|
+
inputs: {
|
|
222
|
+
file: "${:outdir}/${:fileName}-${@now}.json",
|
|
223
|
+
text: ":json.toJSON()",
|
|
224
|
+
},
|
|
225
|
+
isResult: true,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
};
|
|
170
229
|
const generateBeatsPrompt = async (template, beatsPerScene, story) => {
|
|
171
230
|
const allScenes = story.scenes.map((scene) => scene.description).join("\n");
|
|
172
|
-
const sampleBeats = template.
|
|
231
|
+
const sampleBeats = template.scriptName ? readScriptTemplateFile(template.scriptName).beats : [];
|
|
173
232
|
return sceneToBeatsPrompt({ sampleBeats, beatsPerScene, allScenes });
|
|
174
233
|
};
|
|
175
234
|
const generateScriptInfoPrompt = async (template, story) => {
|
|
176
|
-
if (!template.
|
|
235
|
+
if (!template.scriptName) {
|
|
177
236
|
// TODO: use default schema
|
|
178
237
|
throw new Error("script is not provided");
|
|
179
238
|
}
|
|
180
|
-
const
|
|
181
|
-
|
|
239
|
+
const script = readScriptTemplateFile(template.scriptName);
|
|
240
|
+
const { beats: __, ...scriptWithoutBeats } = script;
|
|
241
|
+
return storyToScriptInfoPrompt(scriptWithoutBeats, story);
|
|
182
242
|
};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
243
|
+
const generateScriptPrompt = async (template, beatsPerScene, story) => {
|
|
244
|
+
if (!template.scriptName) {
|
|
245
|
+
// TODO: use default schema
|
|
246
|
+
throw new Error("script is not provided");
|
|
247
|
+
}
|
|
248
|
+
const script = readScriptTemplateFile(template.scriptName);
|
|
249
|
+
return storyToScriptPrompt(script, beatsPerScene, story);
|
|
250
|
+
};
|
|
251
|
+
export const storyToScript = async ({ story, beatsPerScene, templateName, outdir, fileName, llm, llmModel, generateMode, }) => {
|
|
252
|
+
const template = readAndParseJson(getTemplateFilePath(templateName), mulmoScriptTemplateSchema);
|
|
253
|
+
const { agent, model, max_tokens } = llmPair(llm, llmModel);
|
|
188
254
|
const beatsPrompt = await generateBeatsPrompt(template, beatsPerScene, story);
|
|
189
255
|
const scriptInfoPrompt = await generateScriptInfoPrompt(template, story);
|
|
256
|
+
const scriptPrompt = await generateScriptPrompt(template, beatsPerScene, story);
|
|
257
|
+
const graphData = generateMode === storyToScriptGenerateMode.stepWise ? stepWiseGraphData : oneStepGraphData;
|
|
190
258
|
const graph = new GraphAI(graphData, { ...vanillaAgents, openAIAgent, anthropicAgent, geminiAgent, groqAgent, fileWriteAgent, validateSchemaAgent });
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
259
|
+
if (generateMode === storyToScriptGenerateMode.stepWise) {
|
|
260
|
+
graph.injectValue("scenes", story.scenes);
|
|
261
|
+
graph.injectValue("beatsPrompt", beatsPrompt);
|
|
262
|
+
graph.injectValue("scriptInfoPrompt", scriptInfoPrompt);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
graph.injectValue("prompt", scriptPrompt);
|
|
266
|
+
}
|
|
194
267
|
graph.injectValue("outdir", outdir);
|
|
195
268
|
graph.injectValue("fileName", fileName);
|
|
196
269
|
graph.injectValue("llmAgent", agent);
|
|
197
270
|
graph.injectValue("llmModel", model);
|
|
198
271
|
graph.injectValue("maxTokens", max_tokens);
|
|
272
|
+
graph.registerCallback(cliLoadingPlugin({ nodeId: "script", message: "Generating script..." }));
|
|
199
273
|
const result = await graph.run();
|
|
200
274
|
writingMessage(result?.writeJSON?.path ?? "");
|
|
201
275
|
};
|