mulmocast-preprocessor 0.1.1 → 0.2.0
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/lib/cli/commands/process.js +1 -1
- package/lib/cli/commands/profiles.js +1 -1
- package/lib/cli/commands/query.d.ts +15 -0
- package/lib/cli/commands/query.js +31 -0
- package/lib/cli/commands/summarize.d.ts +1 -0
- package/lib/cli/commands/summarize.js +4 -4
- package/lib/cli/index.js +68 -3
- package/lib/cli/utils.d.ts +9 -0
- package/lib/cli/utils.js +35 -0
- package/lib/core/ai/command/query/index.d.ts +8 -0
- package/lib/core/ai/command/query/index.js +33 -0
- package/lib/core/ai/command/query/prompts.d.ts +14 -0
- package/lib/core/ai/command/query/prompts.js +59 -0
- package/lib/core/ai/command/summarize/index.d.ts +8 -0
- package/lib/core/ai/command/summarize/index.js +33 -0
- package/lib/core/ai/command/summarize/prompts.d.ts +18 -0
- package/lib/core/ai/command/summarize/prompts.js +70 -0
- package/lib/core/ai/llm.d.ts +45 -0
- package/lib/core/ai/llm.js +144 -0
- package/lib/core/llm/index.d.ts +45 -0
- package/lib/core/llm/index.js +144 -0
- package/lib/core/preprocessing/filter.d.ts +14 -0
- package/lib/core/preprocessing/filter.js +30 -0
- package/lib/core/preprocessing/process.d.ts +7 -0
- package/lib/core/preprocessing/process.js +12 -0
- package/lib/core/preprocessing/profiles.d.ts +5 -0
- package/lib/core/preprocessing/profiles.js +38 -0
- package/lib/core/preprocessing/variant.d.ts +6 -0
- package/lib/core/preprocessing/variant.js +26 -0
- package/lib/core/query/index.d.ts +8 -0
- package/lib/core/query/index.js +33 -0
- package/lib/core/query/prompts.d.ts +14 -0
- package/lib/core/query/prompts.js +59 -0
- package/lib/core/summarize/index.js +3 -84
- package/lib/core/summarize/prompts.d.ts +1 -1
- package/lib/core/summarize/prompts.js +9 -2
- package/lib/index.d.ts +8 -5
- package/lib/index.js +9 -7
- package/lib/types/query.d.ts +30 -0
- package/lib/types/query.js +21 -0
- package/lib/types/summarize.d.ts +1 -0
- package/lib/types/summarize.js +2 -0
- package/package.json +1 -1
|
@@ -1,65 +1,12 @@
|
|
|
1
|
-
import dotenv from "dotenv";
|
|
2
|
-
import { GraphAI, GraphAILogger } from "graphai";
|
|
3
|
-
import * as vanillaAgents from "@graphai/vanilla";
|
|
4
|
-
import { openAIAgent } from "@graphai/openai_agent";
|
|
5
|
-
import { anthropicAgent } from "@graphai/anthropic_agent";
|
|
6
|
-
import { groqAgent } from "@graphai/groq_agent";
|
|
7
|
-
import { geminiAgent } from "@graphai/gemini_agent";
|
|
8
1
|
import { summarizeOptionsSchema } from "../../types/summarize.js";
|
|
9
|
-
import {
|
|
2
|
+
import { executeLLM, filterScript } from "../llm/index.js";
|
|
10
3
|
import { buildUserPrompt, getSystemPrompt } from "./prompts.js";
|
|
11
|
-
import { filterBySection, filterByTags } from "../filter.js";
|
|
12
|
-
dotenv.config({ quiet: true });
|
|
13
|
-
const agents = vanillaAgents.default ?? vanillaAgents;
|
|
14
|
-
/**
|
|
15
|
-
* Create GraphAI graph for summarizing script
|
|
16
|
-
*/
|
|
17
|
-
const createSummarizeGraph = (agentName) => ({
|
|
18
|
-
version: 0.5,
|
|
19
|
-
nodes: {
|
|
20
|
-
systemPrompt: {},
|
|
21
|
-
userPrompt: {},
|
|
22
|
-
model: {},
|
|
23
|
-
temperature: {},
|
|
24
|
-
maxTokens: {},
|
|
25
|
-
llmCall: {
|
|
26
|
-
agent: agentName,
|
|
27
|
-
inputs: {
|
|
28
|
-
system: ":systemPrompt",
|
|
29
|
-
prompt: ":userPrompt",
|
|
30
|
-
model: ":model",
|
|
31
|
-
temperature: ":temperature",
|
|
32
|
-
max_tokens: ":maxTokens",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
result: {
|
|
36
|
-
isResult: true,
|
|
37
|
-
agent: "copyAgent",
|
|
38
|
-
inputs: {
|
|
39
|
-
summary: ":llmCall.text",
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
/**
|
|
45
|
-
* Filter script based on options (section, tags)
|
|
46
|
-
*/
|
|
47
|
-
const filterScript = (script, options) => {
|
|
48
|
-
const afterSection = options.section ? filterBySection(script, options.section) : script;
|
|
49
|
-
const afterTags = options.tags && options.tags.length > 0 ? filterByTags(afterSection, options.tags) : afterSection;
|
|
50
|
-
return afterTags;
|
|
51
|
-
};
|
|
52
4
|
/**
|
|
53
5
|
* Main summarize function - generates a summary of the entire script
|
|
54
6
|
*/
|
|
55
7
|
export const summarizeScript = async (script, options = {}) => {
|
|
56
8
|
// Validate and apply defaults
|
|
57
9
|
const validatedOptions = summarizeOptionsSchema.parse(options);
|
|
58
|
-
const providerConfig = getProviderConfig(validatedOptions.provider);
|
|
59
|
-
const apiKey = getProviderApiKey(validatedOptions.provider);
|
|
60
|
-
if (!apiKey) {
|
|
61
|
-
throw new Error(`API key not found for provider "${validatedOptions.provider}". ` + `Please set the ${providerConfig.keyName} environment variable.`);
|
|
62
|
-
}
|
|
63
10
|
// Filter script if section/tags specified
|
|
64
11
|
const filteredScript = filterScript(script, validatedOptions);
|
|
65
12
|
const scriptTitle = script.title || "Untitled";
|
|
@@ -71,39 +18,11 @@ export const summarizeScript = async (script, options = {}) => {
|
|
|
71
18
|
beatCount: 0,
|
|
72
19
|
};
|
|
73
20
|
}
|
|
74
|
-
// Build GraphAI config
|
|
75
|
-
const config = {
|
|
76
|
-
openAIAgent: { apiKey: process.env.OPENAI_API_KEY },
|
|
77
|
-
anthropicAgent: { apiKey: process.env.ANTHROPIC_API_KEY },
|
|
78
|
-
groqAgent: { apiKey: process.env.GROQ_API_KEY },
|
|
79
|
-
geminiAgent: { apiKey: process.env.GEMINI_API_KEY },
|
|
80
|
-
};
|
|
81
|
-
// Create GraphAI instance
|
|
82
|
-
const graph = new GraphAI(createSummarizeGraph(providerConfig.agentName), {
|
|
83
|
-
...agents,
|
|
84
|
-
openAIAgent,
|
|
85
|
-
anthropicAgent,
|
|
86
|
-
groqAgent,
|
|
87
|
-
geminiAgent,
|
|
88
|
-
}, { config });
|
|
89
21
|
// Build prompts
|
|
90
22
|
const systemPrompt = getSystemPrompt(validatedOptions);
|
|
91
23
|
const userPrompt = buildUserPrompt(filteredScript, validatedOptions);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
GraphAILogger.info(`Beats: ${filteredScript.beats.length}, Format: ${validatedOptions.format}`);
|
|
95
|
-
}
|
|
96
|
-
// Inject values
|
|
97
|
-
graph.injectValue("systemPrompt", systemPrompt);
|
|
98
|
-
graph.injectValue("userPrompt", userPrompt);
|
|
99
|
-
graph.injectValue("model", validatedOptions.model ?? providerConfig.defaultModel);
|
|
100
|
-
graph.injectValue("temperature", validatedOptions.temperature ?? 0.7);
|
|
101
|
-
graph.injectValue("maxTokens", validatedOptions.maxTokens ?? providerConfig.maxTokens ?? 2048);
|
|
102
|
-
// Run graph
|
|
103
|
-
const graphResult = await graph.run();
|
|
104
|
-
// Extract summary from result node
|
|
105
|
-
const resultNode = graphResult.result;
|
|
106
|
-
const summary = resultNode?.summary || "";
|
|
24
|
+
// Execute LLM
|
|
25
|
+
const summary = await executeLLM(systemPrompt, userPrompt, validatedOptions, `Summarizing script "${script.title}" with ${validatedOptions.provider}... Beats: ${filteredScript.beats.length}, Format: ${validatedOptions.format}`);
|
|
107
26
|
return {
|
|
108
27
|
summary,
|
|
109
28
|
format: validatedOptions.format,
|
|
@@ -13,6 +13,6 @@ export declare const DEFAULT_SYSTEM_PROMPT_MARKDOWN = "You are creating a summar
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const buildUserPrompt: (script: ExtendedScript, options: SummarizeOptions) => string;
|
|
15
15
|
/**
|
|
16
|
-
* Get system prompt based on format
|
|
16
|
+
* Get system prompt based on format and language
|
|
17
17
|
*/
|
|
18
18
|
export declare const getSystemPrompt: (options: SummarizeOptions) => string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getLanguageName } from "../llm/index.js";
|
|
1
2
|
/**
|
|
2
3
|
* Default system prompt for text summary
|
|
3
4
|
*/
|
|
@@ -53,11 +54,17 @@ export const buildUserPrompt = (script, options) => {
|
|
|
53
54
|
return parts.join("\n");
|
|
54
55
|
};
|
|
55
56
|
/**
|
|
56
|
-
* Get system prompt based on format
|
|
57
|
+
* Get system prompt based on format and language
|
|
57
58
|
*/
|
|
58
59
|
export const getSystemPrompt = (options) => {
|
|
59
60
|
if (options.systemPrompt) {
|
|
60
61
|
return options.systemPrompt;
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
+
const basePrompt = options.format === "markdown" ? DEFAULT_SYSTEM_PROMPT_MARKDOWN : DEFAULT_SYSTEM_PROMPT_TEXT;
|
|
64
|
+
// Add language instruction if specified
|
|
65
|
+
if (options.lang) {
|
|
66
|
+
const langName = getLanguageName(options.lang);
|
|
67
|
+
return `${basePrompt}\n- IMPORTANT: Write the output in ${langName}`;
|
|
68
|
+
}
|
|
69
|
+
return basePrompt;
|
|
63
70
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
export { processScript } from "./core/process.js";
|
|
2
|
-
export { applyProfile } from "./core/variant.js";
|
|
3
|
-
export { filterBySection, filterByTags, stripExtendedFields } from "./core/filter.js";
|
|
4
|
-
export { listProfiles } from "./core/profiles.js";
|
|
5
|
-
export { summarizeScript } from "./core/summarize/index.js";
|
|
1
|
+
export { processScript } from "./core/preprocessing/process.js";
|
|
2
|
+
export { applyProfile } from "./core/preprocessing/variant.js";
|
|
3
|
+
export { filterBySection, filterByTags, stripExtendedFields } from "./core/preprocessing/filter.js";
|
|
4
|
+
export { listProfiles } from "./core/preprocessing/profiles.js";
|
|
5
|
+
export { summarizeScript } from "./core/ai/command/summarize/index.js";
|
|
6
|
+
export { queryScript } from "./core/ai/command/query/index.js";
|
|
6
7
|
export type { BeatVariant, BeatMeta, ExtendedBeat, ExtendedScript, OutputProfile, ProcessOptions, ProfileInfo } from "./types/index.js";
|
|
7
8
|
export type { SummarizeOptions, SummarizeResult, LLMProvider, SummarizeFormat, ProviderConfig } from "./types/summarize.js";
|
|
9
|
+
export type { QueryOptions, QueryResult } from "./types/query.js";
|
|
8
10
|
export { beatVariantSchema, beatMetaSchema, extendedBeatSchema, extendedScriptSchema, outputProfileSchema } from "./types/index.js";
|
|
9
11
|
export { summarizeOptionsSchema, llmProviderSchema, summarizeFormatSchema } from "./types/summarize.js";
|
|
12
|
+
export { queryOptionsSchema } from "./types/query.js";
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
//
|
|
2
|
-
export { processScript } from "./core/process.js";
|
|
3
|
-
export { applyProfile } from "./core/variant.js";
|
|
4
|
-
export { filterBySection, filterByTags, stripExtendedFields } from "./core/filter.js";
|
|
5
|
-
export { listProfiles } from "./core/profiles.js";
|
|
6
|
-
//
|
|
7
|
-
export { summarizeScript } from "./core/summarize/index.js";
|
|
1
|
+
// Preprocessing API
|
|
2
|
+
export { processScript } from "./core/preprocessing/process.js";
|
|
3
|
+
export { applyProfile } from "./core/preprocessing/variant.js";
|
|
4
|
+
export { filterBySection, filterByTags, stripExtendedFields } from "./core/preprocessing/filter.js";
|
|
5
|
+
export { listProfiles } from "./core/preprocessing/profiles.js";
|
|
6
|
+
// AI API
|
|
7
|
+
export { summarizeScript } from "./core/ai/command/summarize/index.js";
|
|
8
|
+
export { queryScript } from "./core/ai/command/query/index.js";
|
|
8
9
|
// Schemas (for validation)
|
|
9
10
|
export { beatVariantSchema, beatMetaSchema, extendedBeatSchema, extendedScriptSchema, outputProfileSchema } from "./types/index.js";
|
|
10
11
|
export { summarizeOptionsSchema, llmProviderSchema, summarizeFormatSchema } from "./types/summarize.js";
|
|
12
|
+
export { queryOptionsSchema } from "./types/query.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Query Options - configuration for querying script content
|
|
4
|
+
*/
|
|
5
|
+
export declare const queryOptionsSchema: z.ZodObject<{
|
|
6
|
+
provider: z.ZodDefault<z.ZodEnum<{
|
|
7
|
+
openai: "openai";
|
|
8
|
+
anthropic: "anthropic";
|
|
9
|
+
groq: "groq";
|
|
10
|
+
gemini: "gemini";
|
|
11
|
+
}>>;
|
|
12
|
+
model: z.ZodOptional<z.ZodString>;
|
|
13
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
16
|
+
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
17
|
+
verbose: z.ZodDefault<z.ZodBoolean>;
|
|
18
|
+
section: z.ZodOptional<z.ZodString>;
|
|
19
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type QueryOptions = z.infer<typeof queryOptionsSchema>;
|
|
22
|
+
/**
|
|
23
|
+
* Query Result - the generated answer
|
|
24
|
+
*/
|
|
25
|
+
export interface QueryResult {
|
|
26
|
+
answer: string;
|
|
27
|
+
question: string;
|
|
28
|
+
scriptTitle: string;
|
|
29
|
+
beatCount: number;
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { llmProviderSchema } from "./summarize.js";
|
|
3
|
+
/**
|
|
4
|
+
* Query Options - configuration for querying script content
|
|
5
|
+
*/
|
|
6
|
+
export const queryOptionsSchema = z.object({
|
|
7
|
+
// LLM settings
|
|
8
|
+
provider: llmProviderSchema.default("openai"),
|
|
9
|
+
model: z.string().optional(),
|
|
10
|
+
temperature: z.number().min(0).max(2).optional(),
|
|
11
|
+
maxTokens: z.number().positive().optional(),
|
|
12
|
+
// Output language (e.g., "ja", "en", "fr")
|
|
13
|
+
lang: z.string().optional(),
|
|
14
|
+
// Custom prompt
|
|
15
|
+
systemPrompt: z.string().optional(),
|
|
16
|
+
// Processing options
|
|
17
|
+
verbose: z.boolean().default(false),
|
|
18
|
+
// Beat filtering
|
|
19
|
+
section: z.string().optional(),
|
|
20
|
+
tags: z.array(z.string()).optional(),
|
|
21
|
+
});
|
package/lib/types/summarize.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare const summarizeOptionsSchema: z.ZodObject<{
|
|
|
34
34
|
text: "text";
|
|
35
35
|
markdown: "markdown";
|
|
36
36
|
}>>;
|
|
37
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
37
38
|
targetLengthChars: z.ZodOptional<z.ZodNumber>;
|
|
38
39
|
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
39
40
|
verbose: z.ZodDefault<z.ZodBoolean>;
|
package/lib/types/summarize.js
CHANGED
|
@@ -18,6 +18,8 @@ export const summarizeOptionsSchema = z.object({
|
|
|
18
18
|
maxTokens: z.number().positive().optional(),
|
|
19
19
|
// Output format
|
|
20
20
|
format: summarizeFormatSchema.default("text"),
|
|
21
|
+
// Output language (e.g., "ja", "en", "fr")
|
|
22
|
+
lang: z.string().optional(),
|
|
21
23
|
// Target length (optional)
|
|
22
24
|
targetLengthChars: z.number().positive().optional(),
|
|
23
25
|
// Custom prompt
|