mulmocast 0.0.1 → 0.0.2
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 +108 -12
- package/assets/html/chart.html +47 -0
- package/assets/html/mermaid.html +63 -0
- package/assets/templates/business.json +60 -6
- package/assets/templates/children_book.json +1 -3
- package/assets/templates/coding.json +103 -0
- package/lib/actions/audio.d.ts +1 -1
- package/lib/actions/audio.js +52 -81
- package/lib/actions/images.d.ts +1 -1
- package/lib/actions/images.js +48 -80
- package/lib/actions/movie.d.ts +1 -1
- package/lib/actions/movie.js +76 -76
- package/lib/actions/translate.d.ts +1 -1
- package/lib/actions/translate.js +16 -52
- package/lib/agents/add_bgm_agent.d.ts +1 -1
- package/lib/agents/add_bgm_agent.js +10 -14
- package/lib/agents/combine_audio_files_agent.d.ts +1 -1
- package/lib/agents/combine_audio_files_agent.js +40 -30
- package/lib/agents/image_google_agent.d.ts +1 -1
- package/lib/agents/image_google_agent.js +8 -11
- package/lib/agents/image_openai_agent.js +7 -14
- package/lib/agents/index.d.ts +8 -8
- package/lib/agents/index.js +13 -30
- package/lib/agents/mulmo_prompts_agent.d.ts +1 -1
- package/lib/agents/mulmo_prompts_agent.js +7 -11
- package/lib/agents/prompts_data.js +1 -4
- package/lib/agents/tts_nijivoice_agent.d.ts +1 -1
- package/lib/agents/tts_nijivoice_agent.js +8 -12
- package/lib/agents/tts_openai_agent.js +9 -16
- package/lib/agents/validate_mulmo_script_agent.d.ts +1 -1
- package/lib/agents/validate_mulmo_script_agent.js +6 -10
- package/lib/cli/args.d.ts +2 -1
- package/lib/cli/args.js +16 -14
- package/lib/cli/cli.js +64 -49
- package/lib/cli/common.js +1 -5
- package/lib/cli/tool-args.d.ts +2 -1
- package/lib/cli/tool-args.js +19 -18
- package/lib/cli/tool-cli.js +32 -51
- package/lib/methods/index.d.ts +3 -3
- package/lib/methods/index.js +3 -19
- package/lib/methods/mulmo_script.d.ts +10 -5
- package/lib/methods/mulmo_script.js +17 -11
- package/lib/methods/mulmo_script_template.d.ts +1 -1
- package/lib/methods/mulmo_script_template.js +4 -10
- package/lib/methods/mulmo_studio_context.d.ts +1 -1
- package/lib/methods/mulmo_studio_context.js +3 -9
- package/lib/tools/create_mulmo_script_from_url.d.ts +3 -0
- package/lib/tools/create_mulmo_script_from_url.js +152 -0
- package/lib/tools/create_mulmo_script_interactively.d.ts +3 -0
- package/lib/tools/create_mulmo_script_interactively.js +217 -0
- package/lib/tools/dump_prompt.js +5 -8
- package/lib/tools/prompt.js +9 -11
- package/lib/tools/seed_from_url2.d.ts +3 -0
- package/lib/tools/seed_from_url2.js +154 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.js +1 -17
- package/lib/types/schema.d.ts +433 -71
- package/lib/types/schema.js +126 -111
- package/lib/types/type.d.ts +7 -3
- package/lib/types/type.js +1 -2
- package/lib/utils/const.d.ts +2 -1
- package/lib/utils/const.js +4 -6
- package/lib/utils/file.d.ts +19 -4
- package/lib/utils/file.js +78 -71
- package/lib/utils/filters.d.ts +1 -0
- package/lib/utils/filters.js +47 -26
- package/lib/utils/image_preprocess.d.ts +14 -0
- package/lib/utils/image_preprocess.js +52 -0
- package/lib/utils/inquirer.d.ts +2 -0
- package/lib/utils/inquirer.js +33 -0
- package/lib/utils/markdown.d.ts +3 -1
- package/lib/utils/markdown.js +17 -19
- package/lib/utils/plugins.d.ts +5 -0
- package/lib/utils/plugins.js +11 -0
- package/lib/utils/preprocess.d.ts +24 -7
- package/lib/utils/preprocess.js +8 -14
- package/lib/utils/string.js +4 -10
- package/lib/utils/text_hash.js +2 -39
- package/package.json +12 -6
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { GraphAI } from "graphai";
|
|
3
|
+
import { openAIAgent } from "@graphai/openai_agent";
|
|
4
|
+
import * as agents from "@graphai/vanilla";
|
|
5
|
+
import { fileWriteAgent } from "@graphai/vanilla_node_agents";
|
|
6
|
+
import { browserlessAgent } from "@graphai/browserless_agent";
|
|
7
|
+
import validateMulmoScriptAgent from "../agents/validate_mulmo_script_agent.js";
|
|
8
|
+
import { readTemplatePrompt, mkdir, writingMessage } from "../utils/file.js";
|
|
9
|
+
import { browserlessCacheGenerator } from "../utils/filters.js";
|
|
10
|
+
import { urlsSchema } from "../types/schema.js";
|
|
11
|
+
import { cliLoadingPlugin } from "../utils/plugins.js";
|
|
12
|
+
const { default: __, ...vanillaAgents } = agents;
|
|
13
|
+
const graphData = {
|
|
14
|
+
version: 0.5,
|
|
15
|
+
// Execute sequentially because the free version of browserless API doesn't support concurrent execution.
|
|
16
|
+
concurrency: 1,
|
|
17
|
+
nodes: {
|
|
18
|
+
urls: {
|
|
19
|
+
value: [],
|
|
20
|
+
},
|
|
21
|
+
prompt: {
|
|
22
|
+
value: "",
|
|
23
|
+
},
|
|
24
|
+
outdir: {
|
|
25
|
+
value: "",
|
|
26
|
+
},
|
|
27
|
+
fileName: {
|
|
28
|
+
value: "",
|
|
29
|
+
},
|
|
30
|
+
// get the text content of the urls
|
|
31
|
+
fetchResults: {
|
|
32
|
+
agent: "mapAgent",
|
|
33
|
+
inputs: {
|
|
34
|
+
rows: ":urls",
|
|
35
|
+
},
|
|
36
|
+
params: {
|
|
37
|
+
compositeResult: true,
|
|
38
|
+
},
|
|
39
|
+
graph: {
|
|
40
|
+
nodes: {
|
|
41
|
+
fetcher: {
|
|
42
|
+
agent: "browserlessAgent",
|
|
43
|
+
inputs: {
|
|
44
|
+
url: ":row",
|
|
45
|
+
text_content: true,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
copyAgent: {
|
|
49
|
+
agent: "copyAgent",
|
|
50
|
+
inputs: {
|
|
51
|
+
text: '{ url: "${:row}", text: "${:fetcher.text}" }',
|
|
52
|
+
},
|
|
53
|
+
params: {
|
|
54
|
+
namedKey: "text",
|
|
55
|
+
},
|
|
56
|
+
isResult: true,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
// join the text content
|
|
62
|
+
sourceText: {
|
|
63
|
+
agent: "arrayJoinAgent",
|
|
64
|
+
inputs: {
|
|
65
|
+
array: ":fetchResults.copyAgent",
|
|
66
|
+
},
|
|
67
|
+
params: {
|
|
68
|
+
separator: ",",
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
// generate the mulmo script
|
|
72
|
+
mulmoScript: {
|
|
73
|
+
agent: "nestedAgent",
|
|
74
|
+
inputs: {
|
|
75
|
+
sourceText: ":sourceText",
|
|
76
|
+
prompt: ":prompt",
|
|
77
|
+
},
|
|
78
|
+
graph: {
|
|
79
|
+
loop: {
|
|
80
|
+
// If the script is not valid and the counter is less than 3, continue the loop
|
|
81
|
+
while: ":continue",
|
|
82
|
+
},
|
|
83
|
+
nodes: {
|
|
84
|
+
counter: {
|
|
85
|
+
value: 0,
|
|
86
|
+
update: ":counter.add(1)",
|
|
87
|
+
},
|
|
88
|
+
openAIAgent: {
|
|
89
|
+
agent: "openAIAgent",
|
|
90
|
+
inputs: {
|
|
91
|
+
model: "gpt-4o",
|
|
92
|
+
system: ":prompt",
|
|
93
|
+
prompt: "Please create a script using the information from the following URLs as reference: ${:sourceText.text}",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
validateMulmoScriptAgent: {
|
|
97
|
+
agent: "validateMulmoScriptAgent",
|
|
98
|
+
inputs: {
|
|
99
|
+
text: ":openAIAgent.text.codeBlock()",
|
|
100
|
+
},
|
|
101
|
+
isResult: true,
|
|
102
|
+
},
|
|
103
|
+
continue: {
|
|
104
|
+
agent: ({ isValid, counter }) => {
|
|
105
|
+
return !isValid && counter < 3;
|
|
106
|
+
},
|
|
107
|
+
inputs: {
|
|
108
|
+
isValid: ":validateMulmoScriptAgent.isValid",
|
|
109
|
+
counter: ":counter",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
writeJSON: {
|
|
116
|
+
if: ":mulmoScript.validateMulmoScriptAgent.isValid",
|
|
117
|
+
agent: "fileWriteAgent",
|
|
118
|
+
inputs: {
|
|
119
|
+
file: "${:outdir}/${:fileName}-${@now}.json",
|
|
120
|
+
text: ":mulmoScript.validateMulmoScriptAgent.data.toJSON()",
|
|
121
|
+
},
|
|
122
|
+
isResult: true,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
export const createMulmoScriptFromUrl = async ({ urls, templateName, outDirPath, filename, cacheDirPath }) => {
|
|
127
|
+
mkdir(outDirPath);
|
|
128
|
+
mkdir(cacheDirPath);
|
|
129
|
+
const parsedUrls = urlsSchema.parse(urls);
|
|
130
|
+
const browserlessCache = browserlessCacheGenerator(cacheDirPath);
|
|
131
|
+
const agentFilters = [
|
|
132
|
+
{
|
|
133
|
+
name: "browserlessCache",
|
|
134
|
+
agent: browserlessCache,
|
|
135
|
+
nodeIds: ["fetcher"],
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
const graph = new GraphAI(graphData, {
|
|
139
|
+
...vanillaAgents,
|
|
140
|
+
openAIAgent,
|
|
141
|
+
browserlessAgent,
|
|
142
|
+
validateMulmoScriptAgent,
|
|
143
|
+
fileWriteAgent,
|
|
144
|
+
}, { agentFilters });
|
|
145
|
+
graph.injectValue("urls", parsedUrls);
|
|
146
|
+
graph.injectValue("prompt", readTemplatePrompt(templateName));
|
|
147
|
+
graph.injectValue("outdir", outDirPath);
|
|
148
|
+
graph.injectValue("fileName", filename);
|
|
149
|
+
graph.registerCallback(cliLoadingPlugin({ nodeId: "mulmoScript", message: "Generating script..." }));
|
|
150
|
+
const result = await graph.run();
|
|
151
|
+
writingMessage(result?.writeJSON?.path ?? "");
|
|
152
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { GraphAILogger, GraphAI } from "graphai";
|
|
3
|
+
import { textInputAgent } from "@graphai/input_agents";
|
|
4
|
+
import { openAIAgent } from "@graphai/openai_agent";
|
|
5
|
+
import * as agents from "@graphai/vanilla";
|
|
6
|
+
import { fileWriteAgent } from "@graphai/vanilla_node_agents";
|
|
7
|
+
import { readTemplatePrompt, mkdir } from "../utils/file.js";
|
|
8
|
+
import { browserlessCacheGenerator } from "../utils/filters.js";
|
|
9
|
+
import { browserlessAgent } from "@graphai/browserless_agent";
|
|
10
|
+
import validateMulmoScriptAgent from "../agents/validate_mulmo_script_agent.js";
|
|
11
|
+
import { cliLoadingPlugin } from "../utils/plugins.js";
|
|
12
|
+
const { default: __, ...vanillaAgents } = agents;
|
|
13
|
+
const agentHeader = "\x1b[34m● \x1b[0m\x1b[1mAgent\x1b[0m:\x1b[0m";
|
|
14
|
+
const graphDataForScraping = {
|
|
15
|
+
version: 0.5,
|
|
16
|
+
nodes: {
|
|
17
|
+
urls: {
|
|
18
|
+
value: [],
|
|
19
|
+
},
|
|
20
|
+
fetchResults: {
|
|
21
|
+
agent: "mapAgent",
|
|
22
|
+
inputs: {
|
|
23
|
+
rows: ":urls",
|
|
24
|
+
},
|
|
25
|
+
params: {
|
|
26
|
+
compositeResult: true,
|
|
27
|
+
},
|
|
28
|
+
graph: {
|
|
29
|
+
nodes: {
|
|
30
|
+
fetcher: {
|
|
31
|
+
agent: "browserlessAgent",
|
|
32
|
+
inputs: {
|
|
33
|
+
url: ":row",
|
|
34
|
+
text_content: true,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
copyAgent: {
|
|
38
|
+
agent: "copyAgent",
|
|
39
|
+
inputs: {
|
|
40
|
+
text: '{ url: "${:row}", text: "${:fetcher.text}" }',
|
|
41
|
+
},
|
|
42
|
+
params: {
|
|
43
|
+
namedKey: "text",
|
|
44
|
+
},
|
|
45
|
+
isResult: true,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
sourceText: {
|
|
51
|
+
agent: "arrayJoinAgent",
|
|
52
|
+
inputs: {
|
|
53
|
+
array: ":fetchResults.copyAgent",
|
|
54
|
+
},
|
|
55
|
+
params: {
|
|
56
|
+
separator: ",",
|
|
57
|
+
},
|
|
58
|
+
isResult: true,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const graphData = {
|
|
63
|
+
version: 0.5,
|
|
64
|
+
loop: {
|
|
65
|
+
while: ":continue",
|
|
66
|
+
},
|
|
67
|
+
nodes: {
|
|
68
|
+
fileName: {
|
|
69
|
+
update: ":fileName",
|
|
70
|
+
},
|
|
71
|
+
outdir: {
|
|
72
|
+
update: ":outdir",
|
|
73
|
+
},
|
|
74
|
+
messages: {
|
|
75
|
+
value: [],
|
|
76
|
+
update: ":reply.llmAgent.messages",
|
|
77
|
+
},
|
|
78
|
+
userInput: {
|
|
79
|
+
agent: "textInputAgent",
|
|
80
|
+
params: {
|
|
81
|
+
message: "You:",
|
|
82
|
+
required: true,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
reply: {
|
|
86
|
+
agent: "nestedAgent",
|
|
87
|
+
inputs: {
|
|
88
|
+
messages: ":messages",
|
|
89
|
+
prompt: ":userInput.text",
|
|
90
|
+
},
|
|
91
|
+
graph: {
|
|
92
|
+
loop: {
|
|
93
|
+
while: ":continue",
|
|
94
|
+
},
|
|
95
|
+
nodes: {
|
|
96
|
+
counter: {
|
|
97
|
+
value: 0,
|
|
98
|
+
update: ":counter.add(1)",
|
|
99
|
+
},
|
|
100
|
+
llmAgent: {
|
|
101
|
+
agent: "openAIAgent",
|
|
102
|
+
params: {
|
|
103
|
+
model: "gpt-4o",
|
|
104
|
+
},
|
|
105
|
+
inputs: {
|
|
106
|
+
messages: ":messages",
|
|
107
|
+
prompt: ":prompt",
|
|
108
|
+
},
|
|
109
|
+
isResult: true,
|
|
110
|
+
},
|
|
111
|
+
validateMulmoScriptAgent: {
|
|
112
|
+
agent: "validateMulmoScriptAgent",
|
|
113
|
+
inputs: {
|
|
114
|
+
text: ":llmAgent.text.codeBlock()",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
continue: {
|
|
118
|
+
agent: ({ codeBlock, isValid, counter }) => {
|
|
119
|
+
if (counter >= 3) {
|
|
120
|
+
GraphAILogger.info("\n" + agentHeader + " \x1b[31mFailed to generate a valid script. Please try again.\n");
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return !!codeBlock && !isValid;
|
|
124
|
+
},
|
|
125
|
+
inputs: {
|
|
126
|
+
counter: ":counter",
|
|
127
|
+
codeBlock: ":llmAgent.text.codeBlock()",
|
|
128
|
+
isValid: ":validateMulmoScriptAgent.isValid",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
json: {
|
|
135
|
+
agent: "copyAgent",
|
|
136
|
+
inputs: {
|
|
137
|
+
json: ":reply.llmAgent.text.codeBlock().jsonParse()",
|
|
138
|
+
text: ":reply.llmAgent.text.codeBlock()",
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
writeJSON: {
|
|
142
|
+
if: ":json.json",
|
|
143
|
+
agent: "fileWriteAgent",
|
|
144
|
+
inputs: {
|
|
145
|
+
file: "${:outdir}/${:fileName}-${@now}.json",
|
|
146
|
+
text: ":json.text",
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
writeLog: {
|
|
150
|
+
agent: "consoleAgent",
|
|
151
|
+
inputs: {
|
|
152
|
+
text: "\n\x1b[32m🎉 Script file generated successfully! Type /bye to exit.\x1b[0m\nwriting: ${:writeJSON.path}",
|
|
153
|
+
waiting: ":writeJSON",
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
shouldResponse: {
|
|
157
|
+
agent: "compareAgent",
|
|
158
|
+
inputs: {
|
|
159
|
+
array: [[":json.json", "==", undefined], "&&", [":userInput.text", "!=", "/bye"]],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
agentResponse: {
|
|
163
|
+
if: ":shouldResponse.result",
|
|
164
|
+
agent: "consoleAgent",
|
|
165
|
+
inputs: {
|
|
166
|
+
text: "\n" + agentHeader + " ${:reply.llmAgent.text}\n",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
checkInput: {
|
|
170
|
+
agent: "compareAgent",
|
|
171
|
+
inputs: { array: [":userInput.text", "!=", "/bye"] },
|
|
172
|
+
},
|
|
173
|
+
continue: {
|
|
174
|
+
value: true,
|
|
175
|
+
update: ":checkInput.result",
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
const interactiveClarificationPrompt = `If there are any unclear points, be sure to ask the user questions and clarify them before generating the script.`;
|
|
180
|
+
const scrapeWebContent = async (urls, cacheDirPath) => {
|
|
181
|
+
mkdir(cacheDirPath);
|
|
182
|
+
GraphAILogger.info(`${agentHeader} Scraping ${urls.length} URLs...\n`);
|
|
183
|
+
const browserlessCache = browserlessCacheGenerator(cacheDirPath);
|
|
184
|
+
const agentFilters = [
|
|
185
|
+
{
|
|
186
|
+
name: "browserlessCache",
|
|
187
|
+
agent: browserlessCache,
|
|
188
|
+
nodeIds: ["fetcher"],
|
|
189
|
+
},
|
|
190
|
+
];
|
|
191
|
+
const graph = new GraphAI(graphDataForScraping, { ...vanillaAgents, openAIAgent, textInputAgent, fileWriteAgent, browserlessAgent }, { agentFilters });
|
|
192
|
+
graph.injectValue("urls", urls);
|
|
193
|
+
const result = (await graph.run());
|
|
194
|
+
if (!result?.sourceText?.text) {
|
|
195
|
+
return "";
|
|
196
|
+
}
|
|
197
|
+
const prefixPrompt = "Here is the web content that can be used as reference material for the script:";
|
|
198
|
+
return `\n\n${prefixPrompt}\n${result?.sourceText.text}`;
|
|
199
|
+
};
|
|
200
|
+
export const createMulmoScriptInteractively = async ({ outDirPath, cacheDirPath, filename, templateName, urls }) => {
|
|
201
|
+
mkdir(outDirPath);
|
|
202
|
+
// if urls is not empty, scrape web content and reference it in the prompt
|
|
203
|
+
const webContentPrompt = urls.length > 0 ? await scrapeWebContent(urls, cacheDirPath) : "";
|
|
204
|
+
const graph = new GraphAI(graphData, { ...vanillaAgents, openAIAgent, textInputAgent, fileWriteAgent, validateMulmoScriptAgent });
|
|
205
|
+
const prompt = readTemplatePrompt(templateName);
|
|
206
|
+
graph.injectValue("messages", [
|
|
207
|
+
{
|
|
208
|
+
role: "system",
|
|
209
|
+
content: `${prompt}\n\n${interactiveClarificationPrompt}${webContentPrompt}`,
|
|
210
|
+
},
|
|
211
|
+
]);
|
|
212
|
+
graph.injectValue("outdir", outDirPath);
|
|
213
|
+
graph.injectValue("fileName", filename);
|
|
214
|
+
graph.registerCallback(cliLoadingPlugin({ nodeId: "reply", message: "Loading..." }));
|
|
215
|
+
GraphAILogger.info(`${agentHeader} Hi! What topic would you like me to generate about?\n`);
|
|
216
|
+
await graph.run();
|
|
217
|
+
};
|
package/lib/tools/dump_prompt.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const prompt = (0, file_1.readTemplatePrompt)(templateName);
|
|
7
|
-
console.log(prompt);
|
|
1
|
+
import { GraphAILogger } from "graphai";
|
|
2
|
+
import { readTemplatePrompt } from "../utils/file.js";
|
|
3
|
+
export const dumpPromptFromTemplate = async ({ templateName }) => {
|
|
4
|
+
const prompt = readTemplatePrompt(templateName);
|
|
5
|
+
GraphAILogger.info(prompt);
|
|
8
6
|
};
|
|
9
|
-
exports.dumpPromptFromTemplate = dumpPromptFromTemplate;
|
package/lib/tools/prompt.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = path.dirname(__filename);
|
|
8
6
|
const main = async () => {
|
|
9
|
-
const basePath =
|
|
7
|
+
const basePath = path.resolve(__dirname, "../../prompts/");
|
|
10
8
|
const ret = {};
|
|
11
|
-
|
|
9
|
+
fs.readdirSync(basePath).map((file) => {
|
|
12
10
|
const key = file.split(".")[0];
|
|
13
|
-
const content =
|
|
11
|
+
const content = fs.readFileSync(path.resolve(basePath, file), "utf-8");
|
|
14
12
|
ret[key] = content;
|
|
15
13
|
});
|
|
16
14
|
const code = ["// This file is auto-generated by src/tools/prompt.ts and Do not be edited manually.", `export const prompts = ${JSON.stringify(ret)};`].join("\n");
|
|
17
|
-
|
|
15
|
+
fs.writeFileSync(path.resolve(__dirname, "../../src/agents/prompts_data.ts"), code, "utf8");
|
|
18
16
|
// console.log(hoge);
|
|
19
17
|
};
|
|
20
18
|
main();
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { GraphAI } from "graphai";
|
|
3
|
+
import { openAIAgent } from "@graphai/openai_agent";
|
|
4
|
+
import * as vanilla from "@graphai/vanilla";
|
|
5
|
+
import { fileWriteAgent } from "@graphai/vanilla_node_agents";
|
|
6
|
+
import { browserlessAgent } from "@graphai/browserless_agent";
|
|
7
|
+
import validateMulmoScriptAgent from "../agents/validate_mulmo_script_agent";
|
|
8
|
+
import { readTemplatePrompt, mkdir, writingMessage } from "../utils/file";
|
|
9
|
+
import { browserlessCacheGenerator } from "../utils/filters";
|
|
10
|
+
import { urlsSchema } from "../types/schema";
|
|
11
|
+
import { cliLoadingPlugin } from "../utils/plugins";
|
|
12
|
+
const graphData = {
|
|
13
|
+
version: 0.5,
|
|
14
|
+
// Execute sequentially because the free version of browserless API doesn't support concurrent execution.
|
|
15
|
+
concurrency: 1,
|
|
16
|
+
nodes: {
|
|
17
|
+
urls: {
|
|
18
|
+
value: [],
|
|
19
|
+
},
|
|
20
|
+
prompt: {
|
|
21
|
+
value: "",
|
|
22
|
+
},
|
|
23
|
+
outdir: {
|
|
24
|
+
value: "",
|
|
25
|
+
},
|
|
26
|
+
fileName: {
|
|
27
|
+
value: "",
|
|
28
|
+
},
|
|
29
|
+
fetchGraph: {
|
|
30
|
+
value: {
|
|
31
|
+
nodes: {
|
|
32
|
+
fetcher: {
|
|
33
|
+
agent: "browserlessAgent",
|
|
34
|
+
inputs: {
|
|
35
|
+
url: ":row",
|
|
36
|
+
text_content: true,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
copyAgent: {
|
|
40
|
+
agent: "copyAgent",
|
|
41
|
+
inputs: {
|
|
42
|
+
text: '{ url: "${:row}", text: "${:fetcher.text}" }',
|
|
43
|
+
},
|
|
44
|
+
params: {
|
|
45
|
+
namedKey: "text",
|
|
46
|
+
},
|
|
47
|
+
isResult: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
// get the text content of the urls
|
|
53
|
+
fetchResults: {
|
|
54
|
+
agent: "mapAgent",
|
|
55
|
+
inputs: {
|
|
56
|
+
rows: ":urls",
|
|
57
|
+
},
|
|
58
|
+
params: {
|
|
59
|
+
compositeResult: true,
|
|
60
|
+
},
|
|
61
|
+
graph: ":fetchGraph",
|
|
62
|
+
},
|
|
63
|
+
// join the text content
|
|
64
|
+
sourceText: {
|
|
65
|
+
agent: "arrayJoinAgent",
|
|
66
|
+
inputs: {
|
|
67
|
+
array: ":fetchResults.copyAgent",
|
|
68
|
+
},
|
|
69
|
+
params: {
|
|
70
|
+
separator: ",",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
// generate the mulmo script
|
|
74
|
+
mulmoScript: {
|
|
75
|
+
agent: "nestedAgent",
|
|
76
|
+
inputs: {
|
|
77
|
+
sourceText: ":sourceText",
|
|
78
|
+
prompt: ":prompt",
|
|
79
|
+
},
|
|
80
|
+
graph: {
|
|
81
|
+
loop: {
|
|
82
|
+
// If the script is not valid and the counter is less than 3, continue the loop
|
|
83
|
+
while: ":continue",
|
|
84
|
+
},
|
|
85
|
+
nodes: {
|
|
86
|
+
counter: {
|
|
87
|
+
value: 0,
|
|
88
|
+
update: ":counter.add(1)",
|
|
89
|
+
},
|
|
90
|
+
openAIAgent: {
|
|
91
|
+
agent: "openAIAgent",
|
|
92
|
+
inputs: {
|
|
93
|
+
model: "gpt-4o",
|
|
94
|
+
system: ":prompt",
|
|
95
|
+
prompt: "Please create a script using the information from the following URLs as reference: ${:sourceText.text}",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
validateMulmoScriptAgent: {
|
|
99
|
+
agent: "validateMulmoScriptAgent",
|
|
100
|
+
inputs: {
|
|
101
|
+
text: ":openAIAgent.text.codeBlock()",
|
|
102
|
+
},
|
|
103
|
+
isResult: true,
|
|
104
|
+
},
|
|
105
|
+
continue: {
|
|
106
|
+
agent: ({ isValid, counter }) => {
|
|
107
|
+
return !isValid && counter < 3;
|
|
108
|
+
},
|
|
109
|
+
inputs: {
|
|
110
|
+
isValid: ":validateMulmoScriptAgent.isValid",
|
|
111
|
+
counter: ":counter",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
writeJSON: {
|
|
118
|
+
if: ":mulmoScript.validateMulmoScriptAgent.isValid",
|
|
119
|
+
agent: "fileWriteAgent",
|
|
120
|
+
inputs: {
|
|
121
|
+
file: "${:outdir}/${:fileName}-${@now}.json",
|
|
122
|
+
text: ":mulmoScript.validateMulmoScriptAgent.data.toJSON()",
|
|
123
|
+
},
|
|
124
|
+
isResult: true,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
export const createMulmoScriptFromUrl = async ({ urls, templateName, outDirPath, filename, cacheDirPath }) => {
|
|
129
|
+
mkdir(outDirPath);
|
|
130
|
+
mkdir(cacheDirPath);
|
|
131
|
+
const parsedUrls = urlsSchema.parse(urls);
|
|
132
|
+
const browserlessCache = browserlessCacheGenerator(cacheDirPath);
|
|
133
|
+
const agentFilters = [
|
|
134
|
+
{
|
|
135
|
+
name: "browserlessCache",
|
|
136
|
+
agent: browserlessCache,
|
|
137
|
+
nodeIds: ["fetcher"],
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
const graph = new GraphAI(graphData, {
|
|
141
|
+
...vanilla,
|
|
142
|
+
openAIAgent,
|
|
143
|
+
browserlessAgent,
|
|
144
|
+
validateMulmoScriptAgent,
|
|
145
|
+
fileWriteAgent,
|
|
146
|
+
}, { agentFilters });
|
|
147
|
+
graph.injectValue("urls", parsedUrls);
|
|
148
|
+
graph.injectValue("prompt", readTemplatePrompt(templateName));
|
|
149
|
+
graph.injectValue("outdir", outDirPath);
|
|
150
|
+
graph.injectValue("fileName", filename);
|
|
151
|
+
graph.registerCallback(cliLoadingPlugin({ nodeId: "mulmoScript", message: "Generating script..." }));
|
|
152
|
+
const result = await graph.run();
|
|
153
|
+
writingMessage(result?.writeJSON?.path ?? "");
|
|
154
|
+
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./type";
|
|
1
|
+
export * from "./type.js";
|
package/lib/types/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./type"), exports);
|
|
1
|
+
export * from "./type.js";
|