mulmocast 0.0.8 → 0.0.10

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.
Files changed (45) hide show
  1. package/assets/templates/akira_comic.json +28 -0
  2. package/assets/templates/children_book.json +13 -0
  3. package/assets/templates/comic_strips.json +14 -1
  4. package/assets/templates/drslump_comic.json +28 -0
  5. package/assets/templates/ghibli_comic.json +28 -0
  6. package/assets/templates/ghost_comic.json +35 -0
  7. package/assets/templates/onepiece_comic.json +28 -0
  8. package/assets/templates/portrait_movie.json +28 -0
  9. package/assets/templates/realistic_movie.json +28 -0
  10. package/assets/templates/sensei_and_taro.json +21 -0
  11. package/lib/actions/audio.js +1 -1
  12. package/lib/actions/captions.js +1 -1
  13. package/lib/actions/images.js +98 -13
  14. package/lib/actions/movie.d.ts +1 -1
  15. package/lib/actions/movie.js +13 -11
  16. package/lib/actions/pdf.js +6 -4
  17. package/lib/actions/translate.js +1 -1
  18. package/lib/agents/image_openai_agent.d.ts +1 -0
  19. package/lib/agents/image_openai_agent.js +16 -4
  20. package/lib/agents/movie_google_agent.d.ts +17 -0
  21. package/lib/agents/movie_google_agent.js +114 -0
  22. package/lib/cli/bin.js +19 -0
  23. package/lib/cli/helpers.js +2 -1
  24. package/lib/methods/mulmo_studio.d.ts +1 -1
  25. package/lib/tools/create_mulmo_script_from_url.js +1 -1
  26. package/lib/tools/create_mulmo_script_interactively.js +1 -1
  27. package/lib/tools/story_to_script.js +1 -1
  28. package/lib/types/schema.d.ts +1966 -322
  29. package/lib/types/schema.js +21 -3
  30. package/lib/types/type.d.ts +3 -1
  31. package/lib/utils/file.js +20 -9
  32. package/lib/utils/pdf.d.ts +1 -0
  33. package/lib/utils/pdf.js +5 -3
  34. package/lib/utils/preprocess.d.ts +57 -16
  35. package/lib/utils/utils.d.ts +1 -0
  36. package/lib/utils/utils.js +3 -0
  37. package/package.json +9 -9
  38. package/scripts/templates/children_book.json +0 -7
  39. package/scripts/templates/image_prompts_template.json +41 -0
  40. package/scripts/templates/movie_prompts_template.json +50 -0
  41. package/scripts/templates/sensei_and_taro.json +0 -11
  42. package/scripts/templates/text_only_template.json +35 -0
  43. package/assets/templates/ghibli_strips.json +0 -6
  44. package/scripts/templates/comic_strips.json +0 -30
  45. package/scripts/templates/ghibli_strips.json +0 -30
@@ -1,19 +1,31 @@
1
- import OpenAI from "openai";
1
+ import fs from "fs";
2
+ import OpenAI, { toFile } from "openai";
2
3
  // https://platform.openai.com/docs/guides/image-generation
3
4
  export const imageOpenaiAgent = async ({ namedInputs, params }) => {
4
5
  const { prompt } = namedInputs;
5
- const { apiKey, model, size, moderation } = params;
6
+ const { apiKey, model, size, moderation, images } = params;
6
7
  const openai = new OpenAI({ apiKey });
7
8
  const imageOptions = {
8
9
  model: model ?? "dall-e-3",
9
10
  prompt,
10
11
  n: 1,
11
- size: size || model === "gpt-image-1" ? "1536x1024" : "1792x1024",
12
+ size: size ?? (model === "gpt-image-1" ? "1536x1024" : "1792x1024"),
12
13
  };
13
14
  if (model === "gpt-image-1") {
14
15
  imageOptions.moderation = moderation || "auto";
15
16
  }
16
- const response = await openai.images.generate(imageOptions);
17
+ const response = await (async () => {
18
+ const targetSize = imageOptions.size;
19
+ if ((images ?? []).length > 0 && (targetSize === "1536x1024" || targetSize === "1024x1536" || targetSize === "1024x1024")) {
20
+ const imagelist = await Promise.all((images ?? []).map(async (file) => await toFile(fs.createReadStream(file), null, {
21
+ type: "image/png", // TODO: Support JPEG as well
22
+ })));
23
+ return await openai.images.edit({ ...imageOptions, size: targetSize, image: imagelist });
24
+ }
25
+ else {
26
+ return await openai.images.generate(imageOptions);
27
+ }
28
+ })();
17
29
  if (!response.data) {
18
30
  throw new Error(`response.data is undefined: ${response}`);
19
31
  }
@@ -0,0 +1,17 @@
1
+ import type { AgentFunction, AgentFunctionInfo } from "graphai";
2
+ export type MovieGoogleConfig = {
3
+ projectId?: string;
4
+ token?: string;
5
+ };
6
+ export declare const movieGoogleAgent: AgentFunction<{
7
+ model: string;
8
+ aspectRatio: string;
9
+ duration?: number;
10
+ }, {
11
+ buffer: Buffer;
12
+ }, {
13
+ prompt: string;
14
+ imagePath: string;
15
+ }, MovieGoogleConfig>;
16
+ declare const movieGoogleAgentInfo: AgentFunctionInfo;
17
+ export default movieGoogleAgentInfo;
@@ -0,0 +1,114 @@
1
+ import { readFileSync } from "fs";
2
+ import { GraphAILogger, sleep } from "graphai";
3
+ async function generateMovie(projectId, model, token, prompt, imagePath, aspectRatio, duration) {
4
+ const GOOGLE_IMAGEN_ENDPOINT = `https://us-central1-aiplatform.googleapis.com/v1/projects/${projectId}/locations/us-central1/publishers/google/models/${model}`;
5
+ // Prepare the payload for the API request
6
+ const buffer = readFileSync(imagePath);
7
+ const bytesBase64Encoded = buffer.toString("base64");
8
+ const payload = {
9
+ instances: [
10
+ {
11
+ prompt: prompt,
12
+ image: {
13
+ bytesBase64Encoded,
14
+ mimeType: "image/png",
15
+ },
16
+ },
17
+ ],
18
+ parameters: {
19
+ sampleCount: 1,
20
+ aspectRatio: aspectRatio,
21
+ //safetySetting: "block_only_high",
22
+ durationSeconds: duration,
23
+ },
24
+ };
25
+ // Make the API call using fetch
26
+ const response = await fetch(`${GOOGLE_IMAGEN_ENDPOINT}:predictLongRunning`, {
27
+ method: "POST",
28
+ headers: {
29
+ Authorization: `Bearer ${token}`,
30
+ "Content-Type": "application/json",
31
+ },
32
+ body: JSON.stringify(payload),
33
+ });
34
+ if (!response.ok) {
35
+ throw new Error(`Error: ${response.status} - ${response.statusText}`);
36
+ }
37
+ const initialResponse = await response.json();
38
+ const fetchBody = {
39
+ operationName: initialResponse.name,
40
+ };
41
+ const completeResponse = await (async () => {
42
+ while (true) {
43
+ GraphAILogger.info("...waiting for movie generation...");
44
+ await sleep(3000);
45
+ const response = await fetch(`${GOOGLE_IMAGEN_ENDPOINT}:fetchPredictOperation`, {
46
+ method: "POST",
47
+ headers: {
48
+ Authorization: `Bearer ${token}`,
49
+ "Content-Type": "application/json",
50
+ },
51
+ body: JSON.stringify(fetchBody),
52
+ });
53
+ if (!response.ok) {
54
+ throw new Error(`Error: ${response.status} - ${response.statusText}`);
55
+ }
56
+ const responseData = await response.json();
57
+ if (responseData.done) {
58
+ if (responseData.error) {
59
+ GraphAILogger.info("Prompt: ", prompt);
60
+ throw new Error(`Error: ${responseData.error.message}`);
61
+ }
62
+ if (!responseData.response.videos) {
63
+ throw new Error(`No video: ${JSON.stringify(responseData, null, 2)}`);
64
+ }
65
+ return responseData.response;
66
+ }
67
+ }
68
+ })();
69
+ const encodedMovie = completeResponse.videos[0].bytesBase64Encoded;
70
+ if (encodedMovie) {
71
+ return Buffer.from(encodedMovie, "base64");
72
+ }
73
+ return undefined;
74
+ }
75
+ export const movieGoogleAgent = async ({ namedInputs, params, config }) => {
76
+ const { prompt, imagePath } = namedInputs;
77
+ /*
78
+ if (prompt) {
79
+ const buffer = Buffer.from(prompt);
80
+ return { buffer };
81
+ }
82
+ */
83
+ const aspectRatio = params.aspectRatio ?? "16:9";
84
+ const model = params.model ?? "veo-2.0-generate-001"; // "veo-3.0-generate-preview";
85
+ const duration = params.duration ?? 8;
86
+ //const projectId = process.env.GOOGLE_PROJECT_ID; // Your Google Cloud Project ID
87
+ const projectId = config?.projectId;
88
+ const token = config?.token;
89
+ try {
90
+ const buffer = await generateMovie(projectId, model, token, prompt, imagePath, aspectRatio, duration);
91
+ if (buffer) {
92
+ return { buffer };
93
+ }
94
+ throw new Error("ERROR: geneateImage returned undefined");
95
+ }
96
+ catch (error) {
97
+ GraphAILogger.info("Failed to generate movie:", error);
98
+ throw error;
99
+ }
100
+ };
101
+ const movieGoogleAgentInfo = {
102
+ name: "movieGoogleAgent",
103
+ agent: movieGoogleAgent,
104
+ mock: movieGoogleAgent,
105
+ samples: [],
106
+ description: "Google Movie agent",
107
+ category: ["movie"],
108
+ author: "Receptron Team",
109
+ repository: "https://github.com/receptron/mulmocast-cli/",
110
+ // source: "https://github.com/receptron/mulmocast-cli/blob/main/src/agents/image_google_agent.ts",
111
+ license: "MIT",
112
+ environmentVariables: [],
113
+ };
114
+ export default movieGoogleAgentInfo;
package/lib/cli/bin.js CHANGED
@@ -2,6 +2,9 @@
2
2
  import "dotenv/config";
3
3
  import yargs from "yargs/yargs";
4
4
  import { hideBin } from "yargs/helpers";
5
+ import { readFileSync } from "fs";
6
+ import { fileURLToPath } from "url";
7
+ import { dirname, join } from "path";
5
8
  import * as translateCmd from "./commands/translate/index.js";
6
9
  import * as audioCmd from "./commands/audio/index.js";
7
10
  import * as imagesCmd from "./commands/image/index.js";
@@ -9,9 +12,13 @@ import * as movieCmd from "./commands/movie/index.js";
9
12
  import * as pdfCmd from "./commands/pdf/index.js";
10
13
  import * as toolCmd from "./commands/tool/index.js";
11
14
  import { GraphAILogger } from "graphai";
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+ const packageJson = JSON.parse(readFileSync(join(__dirname, "../../package.json"), "utf8"));
12
18
  export const main = async () => {
13
19
  const cli = yargs(hideBin(process.argv))
14
20
  .scriptName("mulmo")
21
+ .version(packageJson.version)
15
22
  .usage("$0 <command> [options]")
16
23
  .option("v", {
17
24
  alias: "verbose",
@@ -29,6 +36,18 @@ export const main = async () => {
29
36
  .demandCommand()
30
37
  .strict()
31
38
  .help()
39
+ .showHelpOnFail(false)
40
+ .fail((msg, err, y) => {
41
+ // if yargs detect error, show help and exit
42
+ if (msg) {
43
+ y.showHelp();
44
+ GraphAILogger.info("\\n" + msg);
45
+ process.exit(1);
46
+ }
47
+ if (err) {
48
+ throw err;
49
+ }
50
+ })
32
51
  .alias("help", "h");
33
52
  await cli.parseAsync();
34
53
  };
@@ -2,7 +2,7 @@ import { GraphAILogger } from "graphai";
2
2
  import fs from "fs";
3
3
  import path from "path";
4
4
  import clipboardy from "clipboardy";
5
- import { getBaseDirPath, getFullPath, readMulmoScriptFile, fetchMulmoScriptFile, getOutputStudioFilePath, resolveDirPath } from "../utils/file.js";
5
+ import { getBaseDirPath, getFullPath, readMulmoScriptFile, fetchMulmoScriptFile, getOutputStudioFilePath, resolveDirPath, mkdir } from "../utils/file.js";
6
6
  import { isHttp } from "../utils/utils.js";
7
7
  import { createOrUpdateStudioData } from "../utils/preprocess.js";
8
8
  import { outDirName, imageDirName, audioDirName } from "../utils/const.js";
@@ -33,6 +33,7 @@ export const getFileObject = (args) => {
33
33
  const fileName = `script_${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
34
34
  const clipboardText = clipboardy.readSync();
35
35
  const fileOrUrl = resolveDirPath(outDirPath, `${fileName}.json`);
36
+ mkdir(outDirPath);
36
37
  fs.writeFileSync(fileOrUrl, clipboardText, "utf8");
37
38
  return { fileOrUrl, fileName };
38
39
  }
@@ -1,6 +1,6 @@
1
1
  import { MulmoStudio } from "../types/index.js";
2
2
  type SessionType = "audio" | "image" | "video" | "multiLingual" | "caption" | "pdf";
3
- type BeatSessionType = "audio" | "image" | "multiLingual" | "caption";
3
+ type BeatSessionType = "audio" | "image" | "multiLingual" | "caption" | "movie";
4
4
  export declare const MulmoStudioMethods: {
5
5
  setSessionState(studio: MulmoStudio, sessionType: SessionType, value: boolean): void;
6
6
  setBeatSessionState(studio: MulmoStudio, sessionType: BeatSessionType, index: number, value: boolean): void;
@@ -14,7 +14,7 @@ import { mulmoScriptSchema, urlsSchema } from "../types/schema.js";
14
14
  import { cliLoadingPlugin } from "../utils/plugins.js";
15
15
  import { graphDataScriptFromUrlPrompt } from "../utils/prompt.js";
16
16
  import { llmPair } from "../utils/utils.js";
17
- const { default: __, ...vanillaAgents } = agents;
17
+ const vanillaAgents = agents.default ?? agents;
18
18
  const graphData = {
19
19
  version: 0.5,
20
20
  // Execute sequentially because the free version of browserless API doesn't support concurrent execution.
@@ -16,7 +16,7 @@ import validateSchemaAgent from "../agents/validate_schema_agent.js";
16
16
  import { llmPair } from "../utils/utils.js";
17
17
  import { interactiveClarificationPrompt, prefixPrompt } from "../utils/prompt.js";
18
18
  // import { cliLoadingPlugin } from "../utils/plugins.js";
19
- const { default: __, ...vanillaAgents } = agents;
19
+ const vanillaAgents = agents.default ?? agents;
20
20
  const agentHeader = "\x1b[34m● \x1b[0m\x1b[1mAgent\x1b[0m:\x1b[0m";
21
21
  const graphDataForScraping = {
22
22
  version: 0.5,
@@ -12,7 +12,7 @@ import validateSchemaAgent from "../agents/validate_schema_agent.js";
12
12
  import { llmPair } from "../utils/utils.js";
13
13
  import { storyToScriptGenerateMode } from "../utils/const.js";
14
14
  import { cliLoadingPlugin } from "../utils/plugins.js";
15
- const { default: __, ...vanillaAgents } = agents;
15
+ const vanillaAgents = agents.default ?? agents;
16
16
  const createValidatedScriptGraphData = ({ systemPrompt, prompt, schema, llmAgent, llmModel, maxTokens, }) => {
17
17
  return {
18
18
  loop: {