mulmocast 0.0.5 → 0.0.6
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 +257 -39
- package/assets/audio/silent60sec.mp3 +0 -0
- package/assets/html/caption.html +45 -0
- package/assets/html/chart.html +1 -1
- package/assets/html/mermaid.html +6 -2
- package/assets/html/tailwind.html +13 -0
- package/assets/templates/business.json +57 -4
- package/assets/templates/comic_strips.json +35 -0
- package/assets/templates/ghibli_strips.json +35 -0
- package/lib/actions/audio.js +24 -11
- package/lib/actions/captions.d.ts +2 -0
- package/lib/actions/captions.js +62 -0
- package/lib/actions/images.js +3 -2
- package/lib/actions/index.d.ts +1 -0
- package/lib/actions/index.js +1 -0
- package/lib/actions/movie.js +78 -86
- package/lib/actions/pdf.js +15 -5
- package/lib/actions/translate.js +32 -26
- package/lib/agents/add_bgm_agent.js +15 -39
- package/lib/agents/combine_audio_files_agent.js +43 -36
- package/lib/agents/index.d.ts +2 -3
- package/lib/agents/index.js +2 -3
- package/lib/agents/tts_google_agent.d.ts +4 -0
- package/lib/agents/tts_google_agent.js +51 -0
- package/lib/agents/validate_schema_agent.d.ts +19 -0
- package/lib/agents/validate_schema_agent.js +36 -0
- package/lib/cli/args.d.ts +2 -0
- package/lib/cli/args.js +9 -2
- package/lib/cli/bin.d.ts +3 -0
- package/lib/cli/bin.js +38 -0
- package/lib/cli/cli.js +34 -7
- package/lib/cli/commands/audio/builder.d.ts +14 -0
- package/lib/cli/commands/audio/builder.js +6 -0
- package/lib/cli/commands/audio/handler.d.ts +4 -0
- package/lib/cli/commands/audio/handler.js +7 -0
- package/lib/cli/commands/audio/index.d.ts +4 -0
- package/lib/cli/commands/audio/index.js +4 -0
- package/lib/cli/commands/image/builder.d.ts +14 -0
- package/lib/cli/commands/image/builder.js +6 -0
- package/lib/cli/commands/image/handler.d.ts +4 -0
- package/lib/cli/commands/image/handler.js +7 -0
- package/lib/cli/commands/image/index.d.ts +4 -0
- package/lib/cli/commands/image/index.js +4 -0
- package/lib/cli/commands/movie/builder.d.ts +18 -0
- package/lib/cli/commands/movie/builder.js +19 -0
- package/lib/cli/commands/movie/handler.d.ts +6 -0
- package/lib/cli/commands/movie/handler.js +12 -0
- package/lib/cli/commands/movie/index.d.ts +4 -0
- package/lib/cli/commands/movie/index.js +4 -0
- package/lib/cli/commands/pdf/builder.d.ts +18 -0
- package/lib/cli/commands/pdf/builder.js +19 -0
- package/lib/cli/commands/pdf/handler.d.ts +6 -0
- package/lib/cli/commands/pdf/handler.js +8 -0
- package/lib/cli/commands/pdf/index.d.ts +4 -0
- package/lib/cli/commands/pdf/index.js +4 -0
- package/lib/cli/commands/tool/index.d.ts +6 -0
- package/lib/cli/commands/tool/index.js +8 -0
- package/lib/cli/commands/tool/prompt/builder.d.ts +4 -0
- package/lib/cli/commands/tool/prompt/builder.js +11 -0
- package/lib/cli/commands/tool/prompt/handler.d.ts +4 -0
- package/lib/cli/commands/tool/prompt/handler.js +14 -0
- package/lib/cli/commands/tool/prompt/index.d.ts +4 -0
- package/lib/cli/commands/tool/prompt/index.js +4 -0
- package/lib/cli/commands/tool/schema/builder.d.ts +2 -0
- package/lib/cli/commands/tool/schema/builder.js +3 -0
- package/lib/cli/commands/tool/schema/handler.d.ts +2 -0
- package/lib/cli/commands/tool/schema/handler.js +12 -0
- package/lib/cli/commands/tool/schema/index.d.ts +4 -0
- package/lib/cli/commands/tool/schema/index.js +4 -0
- package/lib/cli/commands/tool/scripting/builder.d.ts +20 -0
- package/lib/cli/commands/tool/scripting/builder.js +63 -0
- package/lib/cli/commands/tool/scripting/handler.d.ts +12 -0
- package/lib/cli/commands/tool/scripting/handler.js +36 -0
- package/lib/cli/commands/tool/scripting/index.d.ts +4 -0
- package/lib/cli/commands/tool/scripting/index.js +4 -0
- package/lib/cli/commands/tool/story_to_script/builder.d.ts +18 -0
- package/lib/cli/commands/tool/story_to_script/builder.js +53 -0
- package/lib/cli/commands/tool/story_to_script/handler.d.ts +11 -0
- package/lib/cli/commands/tool/story_to_script/handler.js +35 -0
- package/lib/cli/commands/tool/story_to_script/index.d.ts +4 -0
- package/lib/cli/commands/tool/story_to_script/index.js +4 -0
- package/lib/cli/commands/translate/builder.d.ts +14 -0
- package/lib/cli/commands/translate/builder.js +5 -0
- package/lib/cli/commands/translate/handler.d.ts +4 -0
- package/lib/cli/commands/translate/handler.js +6 -0
- package/lib/cli/commands/translate/index.d.ts +4 -0
- package/lib/cli/commands/translate/index.js +4 -0
- package/lib/cli/common.d.ts +6 -2
- package/lib/cli/common.js +18 -7
- package/lib/cli/helpers.d.ts +38 -0
- package/lib/cli/helpers.js +115 -0
- package/lib/cli/tool-args.d.ts +1 -0
- package/lib/cli/tool-args.js +1 -1
- package/lib/cli/tool-cli.js +8 -0
- package/lib/methods/mulmo_script.d.ts +0 -1
- package/lib/methods/mulmo_script.js +4 -7
- package/lib/methods/mulmo_script_template.js +2 -12
- package/lib/tools/create_mulmo_script_from_url.d.ts +1 -1
- package/lib/tools/create_mulmo_script_from_url.js +43 -14
- package/lib/tools/create_mulmo_script_interactively.js +14 -13
- package/lib/tools/dump_prompt.js +2 -0
- package/lib/tools/story_to_script.d.ts +10 -0
- package/lib/tools/story_to_script.js +201 -0
- package/lib/types/cli_types.d.ts +14 -0
- package/lib/types/cli_types.js +1 -0
- package/lib/types/schema.d.ts +493 -176
- package/lib/types/schema.js +37 -7
- package/lib/types/type.d.ts +6 -1
- package/lib/utils/const.d.ts +1 -0
- package/lib/utils/const.js +1 -0
- package/lib/utils/ffmpeg_utils.d.ts +12 -0
- package/lib/utils/ffmpeg_utils.js +63 -0
- package/lib/utils/file.d.ts +7 -3
- package/lib/utils/file.js +24 -5
- package/lib/utils/image_plugins/chart.js +6 -1
- package/lib/utils/image_plugins/html_tailwind.d.ts +3 -0
- package/lib/utils/image_plugins/html_tailwind.js +18 -0
- package/lib/utils/image_plugins/index.d.ts +2 -1
- package/lib/utils/image_plugins/index.js +2 -1
- package/lib/utils/image_plugins/mermaid.js +1 -1
- package/lib/utils/image_plugins/tailwind.d.ts +3 -0
- package/lib/utils/image_plugins/tailwind.js +18 -0
- package/lib/utils/image_plugins/text_slide.js +9 -2
- package/lib/utils/markdown.d.ts +1 -1
- package/lib/utils/markdown.js +8 -2
- package/lib/utils/preprocess.d.ts +23 -12
- package/lib/utils/preprocess.js +4 -0
- package/lib/utils/prompt.d.ts +15 -0
- package/lib/utils/prompt.js +57 -0
- package/lib/utils/utils.d.ts +2 -0
- package/lib/utils/utils.js +10 -0
- package/package.json +27 -23
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { getTemplateFilePath, writingMessage } from "../utils/file.js";
|
|
3
|
+
import { mulmoScriptSchema, mulmoScriptTemplateSchema } from "../types/schema.js";
|
|
4
|
+
import { GraphAI, GraphAILogger } from "graphai";
|
|
5
|
+
import { openAIAgent } from "@graphai/openai_agent";
|
|
6
|
+
import { anthropicAgent } from "@graphai/anthropic_agent";
|
|
7
|
+
import { geminiAgent } from "@graphai/gemini_agent";
|
|
8
|
+
import { groqAgent } from "@graphai/groq_agent";
|
|
9
|
+
import * as agents from "@graphai/vanilla";
|
|
10
|
+
import { graphDataScriptGeneratePrompt, sceneToBeatsPrompt, storyToScriptInfoPrompt } from "../utils/prompt.js";
|
|
11
|
+
import { fileWriteAgent } from "@graphai/vanilla_node_agents";
|
|
12
|
+
import validateSchemaAgent from "../agents/validate_schema_agent.js";
|
|
13
|
+
import { llmPair } from "../utils/utils.js";
|
|
14
|
+
const { default: __, ...vanillaAgents } = agents;
|
|
15
|
+
const createValidatedScriptGraphData = ({ systemPrompt, prompt, schema, llmAgent, llmModel, maxTokens, }) => {
|
|
16
|
+
return {
|
|
17
|
+
loop: {
|
|
18
|
+
while: ":continue",
|
|
19
|
+
},
|
|
20
|
+
nodes: {
|
|
21
|
+
counter: {
|
|
22
|
+
value: 0,
|
|
23
|
+
update: ":counter.add(1)",
|
|
24
|
+
},
|
|
25
|
+
llm: {
|
|
26
|
+
agent: llmAgent,
|
|
27
|
+
inputs: {
|
|
28
|
+
model: llmModel,
|
|
29
|
+
system: systemPrompt,
|
|
30
|
+
prompt: prompt,
|
|
31
|
+
max_tokens: maxTokens,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
validateSchema: {
|
|
35
|
+
agent: "validateSchemaAgent",
|
|
36
|
+
inputs: {
|
|
37
|
+
text: ":llm.text.codeBlock()",
|
|
38
|
+
schema: schema,
|
|
39
|
+
},
|
|
40
|
+
isResult: true,
|
|
41
|
+
},
|
|
42
|
+
continue: {
|
|
43
|
+
agent: ({ isValid, counter }) => {
|
|
44
|
+
if (counter >= 3) {
|
|
45
|
+
GraphAILogger.info("Failed to generate a valid script. Please try again.");
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
return !isValid;
|
|
49
|
+
},
|
|
50
|
+
inputs: {
|
|
51
|
+
counter: ":counter",
|
|
52
|
+
isValid: ":validateSchema.isValid",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const graphData = {
|
|
59
|
+
version: 0.5,
|
|
60
|
+
nodes: {
|
|
61
|
+
scenes: {
|
|
62
|
+
value: [],
|
|
63
|
+
},
|
|
64
|
+
beatsPrompt: {
|
|
65
|
+
value: "",
|
|
66
|
+
},
|
|
67
|
+
scriptInfoPrompt: {
|
|
68
|
+
value: "",
|
|
69
|
+
},
|
|
70
|
+
outdir: {
|
|
71
|
+
value: "",
|
|
72
|
+
},
|
|
73
|
+
fileName: {
|
|
74
|
+
value: "",
|
|
75
|
+
},
|
|
76
|
+
llmAgent: {
|
|
77
|
+
value: "",
|
|
78
|
+
},
|
|
79
|
+
llmModel: {
|
|
80
|
+
value: "",
|
|
81
|
+
},
|
|
82
|
+
maxTokens: {
|
|
83
|
+
value: 0,
|
|
84
|
+
},
|
|
85
|
+
script: {
|
|
86
|
+
agent: "mapAgent",
|
|
87
|
+
inputs: {
|
|
88
|
+
rows: ":scenes",
|
|
89
|
+
prompt: ":beatsPrompt",
|
|
90
|
+
llmAgent: ":llmAgent",
|
|
91
|
+
llmModel: ":llmModel",
|
|
92
|
+
maxTokens: ":maxTokens",
|
|
93
|
+
},
|
|
94
|
+
params: {
|
|
95
|
+
compositeResult: true,
|
|
96
|
+
},
|
|
97
|
+
graph: {
|
|
98
|
+
nodes: {
|
|
99
|
+
script: {
|
|
100
|
+
agent: "nestedAgent",
|
|
101
|
+
inputs: {
|
|
102
|
+
prompt: ":prompt",
|
|
103
|
+
row: ":row",
|
|
104
|
+
llmAgent: ":llmAgent",
|
|
105
|
+
llmModel: ":llmModel",
|
|
106
|
+
maxTokens: ":maxTokens",
|
|
107
|
+
},
|
|
108
|
+
graph: createValidatedScriptGraphData({
|
|
109
|
+
systemPrompt: ":prompt",
|
|
110
|
+
prompt: graphDataScriptGeneratePrompt("${:row}"),
|
|
111
|
+
schema: mulmoScriptSchema.shape.beats,
|
|
112
|
+
llmAgent: ":llmAgent",
|
|
113
|
+
llmModel: ":llmModel",
|
|
114
|
+
maxTokens: ":maxTokens",
|
|
115
|
+
}),
|
|
116
|
+
},
|
|
117
|
+
json: {
|
|
118
|
+
agent: "copyAgent",
|
|
119
|
+
inputs: {
|
|
120
|
+
json: ":script.validateSchema.data",
|
|
121
|
+
},
|
|
122
|
+
params: {
|
|
123
|
+
namedKey: "json",
|
|
124
|
+
},
|
|
125
|
+
isResult: true,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
beats: {
|
|
131
|
+
agent: "arrayFlatAgent",
|
|
132
|
+
inputs: {
|
|
133
|
+
array: ":script.json",
|
|
134
|
+
},
|
|
135
|
+
isResult: true,
|
|
136
|
+
},
|
|
137
|
+
scriptInfo: {
|
|
138
|
+
agent: "nestedAgent",
|
|
139
|
+
inputs: {
|
|
140
|
+
prompt: ":scriptInfoPrompt",
|
|
141
|
+
llmAgent: ":llmAgent",
|
|
142
|
+
llmModel: ":llmModel",
|
|
143
|
+
maxTokens: ":maxTokens",
|
|
144
|
+
},
|
|
145
|
+
graph: createValidatedScriptGraphData({
|
|
146
|
+
systemPrompt: "",
|
|
147
|
+
prompt: ":prompt",
|
|
148
|
+
schema: mulmoScriptSchema.omit({ beats: true }),
|
|
149
|
+
llmAgent: ":llmAgent",
|
|
150
|
+
llmModel: ":llmModel",
|
|
151
|
+
maxTokens: ":maxTokens",
|
|
152
|
+
}),
|
|
153
|
+
},
|
|
154
|
+
mergedScript: {
|
|
155
|
+
agent: "mergeObjectAgent",
|
|
156
|
+
inputs: {
|
|
157
|
+
items: [":scriptInfo.validateSchema.data", { beats: ":beats.array" }],
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
writeJSON: {
|
|
161
|
+
agent: "fileWriteAgent",
|
|
162
|
+
inputs: {
|
|
163
|
+
file: "${:outdir}/${:fileName}-${@now}.json",
|
|
164
|
+
text: ":mergedScript.toJSON()",
|
|
165
|
+
},
|
|
166
|
+
isResult: true,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
const generateBeatsPrompt = async (template, beatsPerScene, story) => {
|
|
171
|
+
const allScenes = story.scenes.map((scene) => scene.description).join("\n");
|
|
172
|
+
const sampleBeats = template.script?.beats ?? [];
|
|
173
|
+
return sceneToBeatsPrompt({ sampleBeats, beatsPerScene, allScenes });
|
|
174
|
+
};
|
|
175
|
+
const generateScriptInfoPrompt = async (template, story) => {
|
|
176
|
+
if (!template.script) {
|
|
177
|
+
// TODO: use default schema
|
|
178
|
+
throw new Error("script is not provided");
|
|
179
|
+
}
|
|
180
|
+
const { beats: __, ...sampleScriptWithoutBeats } = template.script;
|
|
181
|
+
return storyToScriptInfoPrompt(sampleScriptWithoutBeats, story);
|
|
182
|
+
};
|
|
183
|
+
export const storyToScript = async ({ story, beatsPerScene, templateName, outdir, fileName, llmAgent, llmModel, }) => {
|
|
184
|
+
const templatePath = getTemplateFilePath(templateName);
|
|
185
|
+
const rowTemplate = await import(path.resolve(templatePath), { assert: { type: "json" } }).then((mod) => mod.default);
|
|
186
|
+
const template = mulmoScriptTemplateSchema.parse(rowTemplate);
|
|
187
|
+
const { agent, model, max_tokens } = llmPair(llmAgent, llmModel);
|
|
188
|
+
const beatsPrompt = await generateBeatsPrompt(template, beatsPerScene, story);
|
|
189
|
+
const scriptInfoPrompt = await generateScriptInfoPrompt(template, story);
|
|
190
|
+
const graph = new GraphAI(graphData, { ...vanillaAgents, openAIAgent, anthropicAgent, geminiAgent, groqAgent, fileWriteAgent, validateSchemaAgent });
|
|
191
|
+
graph.injectValue("beatsPrompt", beatsPrompt);
|
|
192
|
+
graph.injectValue("scriptInfoPrompt", scriptInfoPrompt);
|
|
193
|
+
graph.injectValue("scenes", story.scenes);
|
|
194
|
+
graph.injectValue("outdir", outdir);
|
|
195
|
+
graph.injectValue("fileName", fileName);
|
|
196
|
+
graph.injectValue("llmAgent", agent);
|
|
197
|
+
graph.injectValue("llmModel", model);
|
|
198
|
+
graph.injectValue("maxTokens", max_tokens);
|
|
199
|
+
const result = await graph.run();
|
|
200
|
+
writingMessage(result?.writeJSON?.path ?? "");
|
|
201
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Arguments } from "yargs";
|
|
2
|
+
export type ToolGlobalOptions = {
|
|
3
|
+
v?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type ToolCliArgs<T = object> = Arguments<T & ToolGlobalOptions>;
|
|
6
|
+
export type GlobalOptions = {
|
|
7
|
+
v?: boolean;
|
|
8
|
+
o?: string;
|
|
9
|
+
b?: string;
|
|
10
|
+
l?: string;
|
|
11
|
+
f?: boolean;
|
|
12
|
+
file?: string;
|
|
13
|
+
};
|
|
14
|
+
export type CliArgs<T = object> = Arguments<T & GlobalOptions>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|