mulmocast-preprocessor 0.1.2 → 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.js +2 -36
- package/lib/cli/index.js +59 -0
- 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.js +1 -18
- 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/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,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getLanguageName } from "../llm/index.js";
|
|
1
2
|
/**
|
|
2
3
|
* Default system prompt for text summary
|
|
3
4
|
*/
|
|
@@ -52,24 +53,6 @@ export const buildUserPrompt = (script, options) => {
|
|
|
52
53
|
parts.push("Based on the above content, explain the topic directly to the reader:");
|
|
53
54
|
return parts.join("\n");
|
|
54
55
|
};
|
|
55
|
-
/**
|
|
56
|
-
* Get language name from code
|
|
57
|
-
*/
|
|
58
|
-
const getLanguageName = (langCode) => {
|
|
59
|
-
const langMap = {
|
|
60
|
-
ja: "Japanese",
|
|
61
|
-
en: "English",
|
|
62
|
-
zh: "Chinese",
|
|
63
|
-
ko: "Korean",
|
|
64
|
-
fr: "French",
|
|
65
|
-
de: "German",
|
|
66
|
-
es: "Spanish",
|
|
67
|
-
it: "Italian",
|
|
68
|
-
pt: "Portuguese",
|
|
69
|
-
ru: "Russian",
|
|
70
|
-
};
|
|
71
|
-
return langMap[langCode] || langCode;
|
|
72
|
-
};
|
|
73
56
|
/**
|
|
74
57
|
* Get system prompt based on format and language
|
|
75
58
|
*/
|
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
|
+
});
|