@jeliq/app-sdk-llm 1.1.24 → 1.2.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/lib/commonjs/controllers/genJSON.js +2 -22
- package/lib/commonjs/controllers/genJSON.js.map +1 -1
- package/lib/commonjs/controllers/genStructuredOutputs.js +46 -0
- package/lib/commonjs/controllers/genStructuredOutputs.js.map +1 -0
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/templates/ShouldMustTemplate.js +86 -71
- package/lib/commonjs/templates/ShouldMustTemplate.js.map +1 -1
- package/lib/commonjs/types.js +128 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/createGetLLM.js +97 -79
- package/lib/commonjs/utils/createGetLLM.js.map +1 -1
- package/lib/module/controllers/genJSON.js +2 -22
- package/lib/module/controllers/genJSON.js.map +1 -1
- package/lib/module/controllers/genStructuredOutputs.js +39 -0
- package/lib/module/controllers/genStructuredOutputs.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/templates/ShouldMustTemplate.js +86 -71
- package/lib/module/templates/ShouldMustTemplate.js.map +1 -1
- package/lib/module/types.js +127 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/createGetLLM.js +97 -79
- package/lib/module/utils/createGetLLM.js.map +1 -1
- package/lib/typescript/src/controllers/genJSON.d.ts.map +1 -1
- package/lib/typescript/src/controllers/genStructuredOutputs.d.ts +23 -0
- package/lib/typescript/src/controllers/genStructuredOutputs.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/templates/ShouldMustTemplate.d.ts +9 -5
- package/lib/typescript/src/templates/ShouldMustTemplate.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +53 -18
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/createGetLLM.d.ts +2 -2
- package/lib/typescript/src/utils/createGetLLM.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -4,96 +4,114 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = createGetLLM;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
7
|
+
var _ai = require("ai");
|
|
8
|
+
var _openai = require("@ai-sdk/openai");
|
|
9
|
+
var _openaiCompatible = require("@ai-sdk/openai-compatible");
|
|
10
|
+
var _anthropic = require("@ai-sdk/anthropic");
|
|
11
|
+
var _google = require("@ai-sdk/google");
|
|
12
|
+
var _azure = require("@ai-sdk/azure");
|
|
13
|
+
function createProviderModel(vendor, modelName) {
|
|
14
|
+
if (process.env.JELIQ_LLM_REVPROXY_KEY && process.env.JELIQ_LLM_REVPROXY_ENDPOINT) {
|
|
15
|
+
const provider = (0, _openaiCompatible.createOpenAICompatible)({
|
|
16
|
+
name: "jeliq-llm-revproxy",
|
|
17
|
+
apiKey: process.env.JELIQ_LLM_REVPROXY_KEY,
|
|
18
|
+
baseURL: process.env.JELIQ_LLM_REVPROXY_ENDPOINT
|
|
19
|
+
});
|
|
20
|
+
return provider(modelName);
|
|
21
|
+
}
|
|
22
|
+
if (vendor.type === "anthropic") {
|
|
23
|
+
const provider = vendor.apiKey || vendor.endpoint ? (0, _anthropic.createAnthropic)({
|
|
24
|
+
apiKey: vendor.apiKey,
|
|
25
|
+
...(vendor.endpoint ? {
|
|
26
|
+
baseURL: vendor.endpoint
|
|
27
|
+
} : {})
|
|
28
|
+
}) : _anthropic.anthropic;
|
|
29
|
+
return provider(modelName);
|
|
30
|
+
}
|
|
31
|
+
if (vendor.type === "google") {
|
|
32
|
+
const provider = vendor.apiKey || vendor.endpoint ? (0, _google.createGoogleGenerativeAI)({
|
|
33
|
+
apiKey: vendor.apiKey,
|
|
34
|
+
...(vendor.endpoint ? {
|
|
35
|
+
baseURL: vendor.endpoint
|
|
36
|
+
} : {})
|
|
37
|
+
}) : _google.google;
|
|
38
|
+
return provider(modelName);
|
|
39
|
+
}
|
|
40
|
+
if (vendor.type === "azure") {
|
|
41
|
+
const provider = vendor.apiKey || vendor.instanceName ? (0, _azure.createAzure)({
|
|
42
|
+
apiKey: vendor.apiKey,
|
|
43
|
+
...(vendor.instanceName ? {
|
|
44
|
+
resourceName: vendor.instanceName
|
|
45
|
+
} : {}),
|
|
46
|
+
apiVersion: vendor.apiVersion,
|
|
47
|
+
useDeploymentBasedUrls: true
|
|
48
|
+
}) : _azure.azure;
|
|
49
|
+
return provider(vendor.deploymentName || modelName);
|
|
50
|
+
}
|
|
51
|
+
return (0, _openai.openai)(modelName);
|
|
52
|
+
}
|
|
10
53
|
function createGetLLM(tasksModelsMap, defaultModel) {
|
|
11
54
|
function getModelAndTemperature(taskName) {
|
|
12
55
|
const model = taskName in tasksModelsMap ? tasksModelsMap[taskName] : defaultModel;
|
|
13
56
|
if (!model) {
|
|
14
57
|
throw new Error(`Model not found for task ${taskName}`);
|
|
15
58
|
}
|
|
16
|
-
|
|
59
|
+
const reasoningEffort = "reasoningEffort" in model ? model.reasoningEffort : undefined;
|
|
60
|
+
const verbosityLevel = "verbosityLevel" in model ? model.verbosityLevel : undefined;
|
|
61
|
+
return [model.model, model.vendor, model.temperature, reasoningEffort, verbosityLevel, model.timeout];
|
|
17
62
|
}
|
|
18
|
-
const getLLM = (taskName,
|
|
19
|
-
const [modelName, vendor, temperature, reasoningEffort, timeout] = getModelAndTemperature(taskName);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (content.type === "text") {
|
|
27
|
-
return content.text;
|
|
28
|
-
} else {
|
|
29
|
-
argsImageURLs.push(content.image_url);
|
|
30
|
-
return `\n[AttachedImage(${content.type}):${imageNum++}]`;
|
|
31
|
-
}
|
|
32
|
-
}).join("\n\n");
|
|
33
|
-
}).join("\n\n");
|
|
34
|
-
}
|
|
35
|
-
const thinkingModel = modelName === "o1-mini" || modelName === "o1-preview" || modelName === "o1" || modelName === "o3-mini";
|
|
36
|
-
let inputPrompts = [];
|
|
37
|
-
const llmConfig = {
|
|
38
|
-
timeout: (options === null || options === void 0 ? void 0 : options.timeout) || timeout || (thinkingModel ? 60 * 3 * 1000 : undefined),
|
|
39
|
-
modelName,
|
|
40
|
-
temperature: (options === null || options === void 0 ? void 0 : options.temperature) || temperature || 0.5,
|
|
41
|
-
reasoningEffort: thinkingModel ? (options === null || options === void 0 ? void 0 : options.reasoningEffort) || reasoningEffort || "low" : undefined,
|
|
42
|
-
callbacks: [{
|
|
43
|
-
handleLLMStart: async (llm, prompts) => {
|
|
44
|
-
inputPrompts = prompts;
|
|
45
|
-
},
|
|
46
|
-
handleLLMEnd: async output => {
|
|
47
|
-
var _output$llmOutput, _output$llmOutput2, _output$llmOutput3, _output$llmOutput4, _output$llmOutput5, _output$llmOutput6;
|
|
48
|
-
const promptTokens = (output === null || output === void 0 || (_output$llmOutput = output.llmOutput) === null || _output$llmOutput === void 0 || (_output$llmOutput = _output$llmOutput.usage_metadata) === null || _output$llmOutput === void 0 ? void 0 : _output$llmOutput.prompt_token_count) || (output === null || output === void 0 || (_output$llmOutput2 = output.llmOutput) === null || _output$llmOutput2 === void 0 || (_output$llmOutput2 = _output$llmOutput2.usage) === null || _output$llmOutput2 === void 0 ? void 0 : _output$llmOutput2.input_tokens) || (output === null || output === void 0 || (_output$llmOutput3 = output.llmOutput) === null || _output$llmOutput3 === void 0 || (_output$llmOutput3 = _output$llmOutput3.tokenUsage) === null || _output$llmOutput3 === void 0 ? void 0 : _output$llmOutput3.promptTokens) || 0;
|
|
49
|
-
const completionTokens = (output === null || output === void 0 || (_output$llmOutput4 = output.llmOutput) === null || _output$llmOutput4 === void 0 || (_output$llmOutput4 = _output$llmOutput4.usage_metadata) === null || _output$llmOutput4 === void 0 ? void 0 : _output$llmOutput4.candidates_token_count) || (output === null || output === void 0 || (_output$llmOutput5 = output.llmOutput) === null || _output$llmOutput5 === void 0 || (_output$llmOutput5 = _output$llmOutput5.usage) === null || _output$llmOutput5 === void 0 ? void 0 : _output$llmOutput5.output_tokens) || (output === null || output === void 0 || (_output$llmOutput6 = output.llmOutput) === null || _output$llmOutput6 === void 0 || (_output$llmOutput6 = _output$llmOutput6.tokenUsage) === null || _output$llmOutput6 === void 0 ? void 0 : _output$llmOutput6.completionTokens) || 0;
|
|
50
|
-
inputPrompts = [];
|
|
51
|
-
},
|
|
52
|
-
handleLLMError: error => {}
|
|
53
|
-
}]
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Anthropic models
|
|
57
|
-
if (vendor.type === "anthropic") {
|
|
58
|
-
return new _anthropic.ChatAnthropic({
|
|
59
|
-
...llmConfig,
|
|
60
|
-
maxTokens: vendor.maxTokens || 7000,
|
|
61
|
-
invocationKwargs: {
|
|
62
|
-
top_p: undefined
|
|
63
|
-
}
|
|
64
|
-
});
|
|
63
|
+
const getLLM = (taskName, options, _loggingInfo) => {
|
|
64
|
+
const [modelName, vendor, temperature, reasoningEffort, verbosityLevel, timeout] = getModelAndTemperature(taskName);
|
|
65
|
+
let resolvedVendor = vendor;
|
|
66
|
+
if (vendor.type !== "openai" && vendor.type !== "anthropic" && vendor.type !== "google" && vendor.type !== "azure") {
|
|
67
|
+
resolvedVendor = {
|
|
68
|
+
...vendor,
|
|
69
|
+
type: "openai"
|
|
70
|
+
};
|
|
65
71
|
}
|
|
72
|
+
const actualModelName = (options === null || options === void 0 ? void 0 : options.model) || modelName;
|
|
73
|
+
const actualTemperature = (options === null || options === void 0 ? void 0 : options.temperature) !== undefined ? options.temperature : temperature;
|
|
74
|
+
const actualReasoningEffort = (options === null || options === void 0 ? void 0 : options.reasoningEffort) !== undefined ? options.reasoningEffort : reasoningEffort;
|
|
75
|
+
const actualVerbosityLevel = (options === null || options === void 0 ? void 0 : options.verbosityLevel) !== undefined ? options.verbosityLevel : verbosityLevel;
|
|
76
|
+
const actualTimeout = (options === null || options === void 0 ? void 0 : options.timeout) !== undefined ? options.timeout : timeout !== undefined ? timeout : undefined;
|
|
77
|
+
const model = createProviderModel(resolvedVendor, actualModelName);
|
|
66
78
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
|
|
79
|
+
// 直前に CallOptions を変形するミドルウェア
|
|
80
|
+
const mutateCallOptionsMiddleware = {
|
|
81
|
+
specificationVersion: "v3",
|
|
82
|
+
async transformParams({
|
|
83
|
+
type,
|
|
84
|
+
params
|
|
85
|
+
}) {
|
|
86
|
+
var _next$providerOptions;
|
|
87
|
+
const next = {
|
|
88
|
+
...params
|
|
89
|
+
};
|
|
75
90
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
azureOpenAIApiDeploymentName: (vendor === null || vendor === void 0 ? void 0 : vendor.deploymentName) || modelName,
|
|
82
|
-
openAIBasePath: vendor.endpoint,
|
|
83
|
-
openAIApiKey: vendor.apiKey,
|
|
84
|
-
openAIApiVersion: vendor.apiVersion,
|
|
85
|
-
temperature: llmConfig.temperature,
|
|
86
|
-
modelName: modelName,
|
|
87
|
-
callbacks: llmConfig.callbacks,
|
|
88
|
-
reasoning: {
|
|
89
|
-
effort: llmConfig.reasoningEffort
|
|
90
|
-
},
|
|
91
|
-
azureOpenAIApiInstanceName: vendor.instanceName
|
|
92
|
-
});
|
|
93
|
-
}
|
|
91
|
+
/*
|
|
92
|
+
if (type === "stream") {
|
|
93
|
+
next.maxOutputTokens = next.maxOutputTokens ?? 800;
|
|
94
|
+
}
|
|
95
|
+
*/
|
|
94
96
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
if (typeof next.temperature === "number" || typeof actualTemperature === "number") {
|
|
98
|
+
next.temperature = Math.min(2, Math.max(0, next.temperature || actualTemperature || 0));
|
|
99
|
+
}
|
|
100
|
+
next.providerOptions = {
|
|
101
|
+
...(next.providerOptions ?? {}),
|
|
102
|
+
openai: {
|
|
103
|
+
...(((_next$providerOptions = next.providerOptions) === null || _next$providerOptions === void 0 ? void 0 : _next$providerOptions.openai) ?? {}),
|
|
104
|
+
reasoningEffort: actualReasoningEffort,
|
|
105
|
+
textVerbosity: actualVerbosityLevel
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return next;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return (0, _ai.wrapLanguageModel)({
|
|
112
|
+
model: model,
|
|
113
|
+
middleware: mutateCallOptionsMiddleware
|
|
114
|
+
});
|
|
97
115
|
};
|
|
98
116
|
return getLLM;
|
|
99
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_ai","require","_openai","_openaiCompatible","_anthropic","_google","_azure","createProviderModel","vendor","modelName","process","env","JELIQ_LLM_REVPROXY_KEY","JELIQ_LLM_REVPROXY_ENDPOINT","provider","createOpenAICompatible","name","apiKey","baseURL","type","endpoint","createAnthropic","anthropic","createGoogleGenerativeAI","google","instanceName","createAzure","resourceName","apiVersion","useDeploymentBasedUrls","azure","deploymentName","openai","createGetLLM","tasksModelsMap","defaultModel","getModelAndTemperature","taskName","model","Error","reasoningEffort","undefined","verbosityLevel","temperature","timeout","getLLM","options","_loggingInfo","resolvedVendor","actualModelName","actualTemperature","actualReasoningEffort","actualVerbosityLevel","actualTimeout","mutateCallOptionsMiddleware","specificationVersion","transformParams","params","_next$providerOptions","next","Math","min","max","providerOptions","textVerbosity","wrapLanguageModel","middleware"],"sourceRoot":"../../../src","sources":["utils/createGetLLM.ts"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,OAAA;AAMA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GA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A;AACA;AACA;;QAEgB,IAAI,OAAOE,IAAI,CAAChB,WAAW,KAAK,QAAQ,IAAI,OAAOO,iBAAiB,KAAK,QAAQ,EAAE;UAC/ES,IAAI,CAAChB,WAAW,GAAGiB,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,GAAG,CAAC,CAAC,EAAEH,IAAI,CAAChB,WAAW,IAAIO,iBAAiB,IAAI,CAAC,CAAC,CAAC;QAC3F;QAEAS,IAAI,CAACI,eAAe,GAAG;UACnB,IAAIJ,IAAI,CAACI,eAAe,IAAI,CAAC,CAAC,CAAC;UAC/B/B,MAAM,EAAE;YACJ,IAAI,EAAA0B,qBAAA,GAACC,IAAI,CAACI,eAAe,cAAAL,qBAAA,uBAArBA,qBAAA,CAA+B1B,MAAM,KAAI,CAAC,CAAC,CAAC;YAChDQ,eAAe,EAAEW,qBAAqB;YACtCa,aAAa,EAAEZ;UACnB;QACJ,CAAC;QAED,OAAOO,IAAI;MACf;IACJ,CAAC;IAED,OAAO,IAAAM,qBAAiB,EAAC;MACrB3B,KAAK,EAAEA,KAAY;MACnB4B,UAAU,EAAEZ;IAChB,CAAC,CAAC;EACN,CAAC;EAED,OAAOT,MAAM;AACjB","ignoreList":[]}
|
|
@@ -1,25 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import createShouldMustTemplate from "../templates/ShouldMustTemplate";
|
|
3
|
-
import { retryWithBackoff } from "../utils/retryWithBackoff";
|
|
1
|
+
import genStructuredOutputs from "./genStructuredOutputs";
|
|
4
2
|
export default async function genJSON(context, taskName, template, args, options) {
|
|
5
|
-
|
|
6
|
-
throw new Error("getLLM is not set");
|
|
7
|
-
}
|
|
8
|
-
const outputParser = StructuredOutputParser.fromZodSchema(template.outputSchema);
|
|
9
|
-
const promptTemplate = await createShouldMustTemplate(Object.keys(template.inputDef).map(key => ({
|
|
10
|
-
name: key,
|
|
11
|
-
type: template.inputDef[key].type,
|
|
12
|
-
description: template.inputDef[key].description
|
|
13
|
-
})), outputParser, template.summary, template.shouldSection, template.mustSection, template.example, template.partialVars);
|
|
14
|
-
const parser = outputParser;
|
|
15
|
-
if (!parser) {
|
|
16
|
-
throw new Error("outputParser is not set");
|
|
17
|
-
}
|
|
18
|
-
const llm = context.getLLM(taskName, await promptTemplate.format(args));
|
|
19
|
-
const fixParser = OutputFixingParser.fromLLM(llm, parser).withRetry({
|
|
20
|
-
stopAfterAttempt: 5
|
|
21
|
-
});
|
|
22
|
-
const chain = promptTemplate.pipe(llm).pipe(fixParser);
|
|
23
|
-
return await retryWithBackoff(() => chain.invoke(args), (options === null || options === void 0 ? void 0 : options.maxRetries) ?? 5, options === null || options === void 0 ? void 0 : options.initialDelayMs, options === null || options === void 0 ? void 0 : options.maxDelayMs);
|
|
3
|
+
return genStructuredOutputs(context, taskName, template, args);
|
|
24
4
|
}
|
|
25
5
|
//# sourceMappingURL=genJSON.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["genStructuredOutputs","genJSON","context","taskName","template","args","options"],"sourceRoot":"../../../src","sources":["controllers/genJSON.ts"],"mappings":"AAGA,OAAOA,oBAAoB,MAAM,wBAAwB;AAIzD,eAAe,eAAeC,OAAOA,CACjCC,OAA4B,EAC5BC,QAAgB,EAChBC,QASC,EACDC,IAAkD,EAClDC,OAIC,EACc;EACf,OAAON,oBAAoB,CACvBE,OAAO,EACPC,QAAQ,EACRC,QAAQ,EACRC,IACJ,CAAC;AACL","ignoreList":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { generateText, Output as AIOutput } from "ai";
|
|
2
|
+
import createShouldMustTemplateAI from "../templates/ShouldMustTemplate";
|
|
3
|
+
export default async function genStructuredOutputs(context, taskName, template, args, options) {
|
|
4
|
+
if (!context) {
|
|
5
|
+
throw new Error("context is not set");
|
|
6
|
+
}
|
|
7
|
+
if (!(context !== null && context !== void 0 && context.getLLM)) {
|
|
8
|
+
throw new Error("getLLM is not set");
|
|
9
|
+
}
|
|
10
|
+
const promptTemplate = await createShouldMustTemplateAI(Object.keys(template.inputDef).map(key => ({
|
|
11
|
+
name: key,
|
|
12
|
+
type: template.inputDef[key].type,
|
|
13
|
+
description: template.inputDef[key].description
|
|
14
|
+
})), template.summary, template.shouldSection, template.mustSection, template.example, template.partialVars);
|
|
15
|
+
const promptArgs = Object.entries(args).reduce((acc, [key, value]) => {
|
|
16
|
+
acc[key] = value ?? "";
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
const messages = await promptTemplate.formatMessages(promptArgs);
|
|
20
|
+
const model = context.getLLM(taskName, undefined, {
|
|
21
|
+
model: options === null || options === void 0 ? void 0 : options.model,
|
|
22
|
+
temperature: options === null || options === void 0 ? void 0 : options.temperature,
|
|
23
|
+
reasoningEffort: options === null || options === void 0 ? void 0 : options.reasoningEffort,
|
|
24
|
+
timeout: options === null || options === void 0 ? void 0 : options.timeout
|
|
25
|
+
});
|
|
26
|
+
const {
|
|
27
|
+
output
|
|
28
|
+
} = await generateText({
|
|
29
|
+
model,
|
|
30
|
+
messages,
|
|
31
|
+
temperature: options === null || options === void 0 ? void 0 : options.temperature,
|
|
32
|
+
maxRetries: options === null || options === void 0 ? void 0 : options.maxRetries,
|
|
33
|
+
output: AIOutput.object({
|
|
34
|
+
schema: template.outputSchema
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
return output;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=genStructuredOutputs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["generateText","Output","AIOutput","createShouldMustTemplateAI","genStructuredOutputs","context","taskName","template","args","options","Error","getLLM","promptTemplate","Object","keys","inputDef","map","key","name","type","description","summary","shouldSection","mustSection","example","partialVars","promptArgs","entries","reduce","acc","value","messages","formatMessages","model","undefined","temperature","reasoningEffort","timeout","output","maxRetries","object","schema","outputSchema"],"sourceRoot":"../../../src","sources":["controllers/genStructuredOutputs.ts"],"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M,MAAM,CACxBL,QAAQ,EACR4B,SAAS,EACT;IACID,KAAK,EAAExB,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEwB,KAAK;IACrBE,WAAW,EAAE1B,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAE0B,WAAW;IACjCC,eAAe,EAAE3B,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAE2B,eAAe;IACzCC,OAAO,EAAE5B,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAE4B;EACtB,CACJ,CAAC;EAED,MAAM;IAAEC;EAAO,CAAC,GAAG,MAAMtC,YAAY,CAAC;IAClCiC,KAAK;IACLF,QAAQ;IACRI,WAAW,EAAE1B,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAE0B,WAAW;IACjCI,UAAU,EAAE9B,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAE8B,UAAU;IAC/BD,MAAM,EAAEpC,QAAQ,CAACsC,MAAM,CAAC;MACpBC,MAAM,EAAElC,QAAQ,CAACmC;IACrB,CAAC;EACL,CAAC,CAAC;EAEF,OAAOJ,MAAM;AACjB","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import createShouldMustTemplate from "./templates/ShouldMustTemplate";
|
|
2
2
|
import createGetLLM from "./utils/createGetLLM";
|
|
3
3
|
import genJSON from "./controllers/genJSON";
|
|
4
|
-
|
|
4
|
+
import genStructuredOutputs from "./controllers/genStructuredOutputs";
|
|
5
|
+
export { genJSON, genStructuredOutputs, createShouldMustTemplate, createGetLLM };
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createShouldMustTemplate","createGetLLM","genJSON"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAUA,OAAOA,wBAAwB,MAAM,gCAAgC;AACrE,OAAOC,YAAY,MAAM,sBAAsB;AAC/C,OAAOC,OAAO,MAAM,uBAAuB;
|
|
1
|
+
{"version":3,"names":["createShouldMustTemplate","createGetLLM","genJSON","genStructuredOutputs"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAUA,OAAOA,wBAAwB,MAAM,gCAAgC;AACrE,OAAOC,YAAY,MAAM,sBAAsB;AAC/C,OAAOC,OAAO,MAAM,uBAAuB;AAC3C,OAAOC,oBAAoB,MAAM,oCAAoC;AAErE,SACID,OAAO,EACPC,oBAAoB,EACpBH,wBAAwB,EACxBC,YAAY","ignoreList":[]}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function getVariableRegex() {
|
|
2
|
+
try {
|
|
3
|
+
return new RegExp("{([\\p{L}\\p{N}_]+)}", "gu");
|
|
4
|
+
} catch {
|
|
5
|
+
return /{([0-9A-Za-z_\u00C0-\u02FF\u0370-\u03FF\u0400-\u04FF\u0590-\u05FF\u0600-\u06FF\u0900-\u097F\u0E00-\u0E7F\u3040-\u30FF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF]+)}/g;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
3
8
|
function extractVariables(content) {
|
|
4
|
-
const variableRegex =
|
|
9
|
+
const variableRegex = getVariableRegex();
|
|
5
10
|
const variables = [];
|
|
6
|
-
let match;
|
|
11
|
+
let match = null;
|
|
7
12
|
while ((match = variableRegex.exec(content)) !== null) {
|
|
8
13
|
if (!variables.includes(match[1])) {
|
|
9
14
|
variables.push(match[1]);
|
|
@@ -11,94 +16,104 @@ function extractVariables(content) {
|
|
|
11
16
|
}
|
|
12
17
|
return variables;
|
|
13
18
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
async function resolvePartialVars(partialVars) {
|
|
20
|
+
if (!partialVars) return {};
|
|
21
|
+
const entries = await Promise.all(Object.entries(partialVars).map(async ([key, value]) => {
|
|
22
|
+
if (typeof value === "function") {
|
|
23
|
+
const result = value();
|
|
24
|
+
return [key, typeof result === "string" ? result : await result];
|
|
25
|
+
}
|
|
26
|
+
return [key, value];
|
|
27
|
+
}));
|
|
28
|
+
return Object.fromEntries(entries);
|
|
29
|
+
}
|
|
30
|
+
function replaceTemplateVariables(template, values) {
|
|
31
|
+
return template.replace(getVariableRegex(), (_, variable) => values[variable] ?? "");
|
|
32
|
+
}
|
|
33
|
+
export default async function createShouldMustTemplate(inputDef, summary, shouldSection, mustSection, example, partialVars) {
|
|
18
34
|
const shouldSectionPrompt = (() => {
|
|
19
|
-
if (!shouldSection) return "";
|
|
35
|
+
if (!(shouldSection !== null && shouldSection !== void 0 && shouldSection.length)) return "";
|
|
20
36
|
const shouldSectionCount = shouldSection.length;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// create should section header
|
|
24
|
-
const shouldSectionHeader = `# You Should\n
|
|
25
|
-
The tasks assigned to you are you are from (a1) to (a${shouldSectionCount}) below.`;
|
|
26
|
-
// create should section
|
|
37
|
+
const shouldSectionHeader = `# You Should\n\nThe tasks assigned to you are from (a1) to (a${shouldSectionCount}) below.`;
|
|
27
38
|
const shouldSectionBody = shouldSection.map(elem => {
|
|
28
39
|
const baseBody = `## (a${elem.no}) ${elem.title}`;
|
|
29
|
-
|
|
40
|
+
return elem.content ? `${baseBody}\n${elem.content}` : baseBody;
|
|
30
41
|
}).join("\n\n");
|
|
31
|
-
return shouldSectionHeader
|
|
42
|
+
return `${shouldSectionHeader}\n\n${shouldSectionBody}`;
|
|
32
43
|
})();
|
|
33
|
-
|
|
34
|
-
// create must section prompt
|
|
35
44
|
const mustSectionPrompt = (() => {
|
|
36
|
-
if (!mustSection) return "";
|
|
45
|
+
if (!(mustSection !== null && mustSection !== void 0 && mustSection.length)) return "";
|
|
37
46
|
const mustSectionCount = mustSection.length;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// create must section header
|
|
41
|
-
const mustSectionHeader = `# You Must\n
|
|
42
|
-
You must satisfy the following tasks from (b1) to (b${mustSectionCount}) below.\n\n`;
|
|
43
|
-
// create must section
|
|
47
|
+
const mustSectionHeader = `# You Must\n\nYou must satisfy the following tasks from (b1) to (b${mustSectionCount}) below.`;
|
|
44
48
|
const mustSectionBody = mustSection.map(elem => {
|
|
45
49
|
const baseBody = `## (b${elem.no}) ${elem.title}`;
|
|
46
|
-
|
|
50
|
+
return elem.content ? `${baseBody}\n${elem.content}` : baseBody;
|
|
47
51
|
}).join("\n\n");
|
|
48
|
-
return mustSectionHeader
|
|
52
|
+
return `${mustSectionHeader}\n\n${mustSectionBody}`;
|
|
49
53
|
})();
|
|
50
|
-
|
|
51
|
-
// create example section prompt
|
|
52
54
|
const exampleSectionPrompt = (() => {
|
|
53
|
-
if (!example) return "";
|
|
54
|
-
const exampleSectionCount = example.length;
|
|
55
|
-
if (exampleSectionCount === 0) return "";
|
|
56
|
-
|
|
57
|
-
// create example section header
|
|
58
|
-
const exampleSectionHeader = `# Example\n\n`;
|
|
59
|
-
|
|
60
|
-
// create example section
|
|
55
|
+
if (!(example !== null && example !== void 0 && example.length)) return "";
|
|
61
56
|
const exampleSectionBody = example.map(elem => `## (c${elem.no}) ${elem.title}\n${elem.content}`).join("\n\n");
|
|
62
|
-
return
|
|
57
|
+
return `# Example\n\n${exampleSectionBody}`;
|
|
63
58
|
})();
|
|
64
|
-
|
|
65
|
-
// Collect all variables used in sections
|
|
66
|
-
const allSectionContent = [(shouldSection === null || shouldSection === void 0 ? void 0 : shouldSection.map(s => s.content || '').join(' ')) || '', (mustSection === null || mustSection === void 0 ? void 0 : mustSection.map(s => s.content || '').join(' ')) || '', (example === null || example === void 0 ? void 0 : example.map(s => s.content || '').join(' ')) || '', summary].join(' ');
|
|
59
|
+
const allSectionContent = [(shouldSection === null || shouldSection === void 0 ? void 0 : shouldSection.map(s => s.content || "").join(" ")) || "", (mustSection === null || mustSection === void 0 ? void 0 : mustSection.map(s => s.content || "").join(" ")) || "", (example === null || example === void 0 ? void 0 : example.map(s => s.content || "").join(" ")) || "", summary].join(" ");
|
|
67
60
|
const usedVariables = extractVariables(allSectionContent);
|
|
68
|
-
|
|
69
|
-
// Get defined variables
|
|
70
61
|
const definedInputVariables = inputDef.map(elem => elem.name);
|
|
71
62
|
const definedPartialVariables = Object.keys(partialVars || {});
|
|
72
|
-
const definedVariables = [...definedInputVariables, ...definedPartialVariables,
|
|
73
|
-
|
|
74
|
-
// Find undefined variables
|
|
63
|
+
const definedVariables = [...definedInputVariables, ...definedPartialVariables, "outputFormat"];
|
|
75
64
|
const undefinedVariables = usedVariables.filter(variable => !definedVariables.includes(variable));
|
|
76
|
-
|
|
77
|
-
// Output warning if undefined variables are found
|
|
78
65
|
if (undefinedVariables.length > 0) {
|
|
79
|
-
console.warn(`[ShouldMustTemplate] Warning: Found ${undefinedVariables.length} undefined variable(s) in template sections: [${undefinedVariables.join(
|
|
66
|
+
console.warn(`[ShouldMustTemplate] Warning: Found ${undefinedVariables.length} undefined variable(s) in template sections: [${undefinedVariables.join(", ")}]. These variables have been automatically added to the template.`);
|
|
80
67
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
68
|
+
const autoGeneratedVariablesSection = undefinedVariables.length > 0 ? `\n\n# Auto-Generated Variables\n\n${undefinedVariables.map(variable => `## ${variable}\n{${variable}}`).join("\n\n")}` : "";
|
|
69
|
+
const systemPrompt = [summary, shouldSectionPrompt, mustSectionPrompt, exampleSectionPrompt].filter(Boolean).join("\n\n");
|
|
70
|
+
const stringInputPromptTemplate = inputDef.filter(elem => elem.type === "string").map(elem => `# ${elem.name}${elem.description ? `\n${elem.description}` : ""}\n{${elem.name}}`).join("\n\n");
|
|
71
|
+
const imageInputDefs = inputDef.filter(elem => elem.type === "imageDataURL");
|
|
72
|
+
const systemTemplate = [systemPrompt, "{outputFormat}"].filter(Boolean).join("\n\n").trim();
|
|
73
|
+
const userTextTemplate = [stringInputPromptTemplate, autoGeneratedVariablesSection].filter(Boolean).join("\n\n").trim();
|
|
74
|
+
return {
|
|
75
|
+
async formatMessages(args) {
|
|
76
|
+
const resolvedPartialVars = await resolvePartialVars(partialVars || {});
|
|
77
|
+
const mergedArgs = Object.entries(args || {}).reduce((acc, [key, value]) => {
|
|
78
|
+
acc[key] = value ?? "";
|
|
79
|
+
return acc;
|
|
80
|
+
}, {});
|
|
81
|
+
const templateValues = {
|
|
82
|
+
...mergedArgs,
|
|
83
|
+
...resolvedPartialVars
|
|
84
|
+
};
|
|
85
|
+
undefinedVariables.forEach(variable => {
|
|
86
|
+
if (!(variable in templateValues)) {
|
|
87
|
+
templateValues[variable] = "";
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const systemMessage = {
|
|
91
|
+
role: "system",
|
|
92
|
+
content: replaceTemplateVariables(systemTemplate, templateValues)
|
|
93
|
+
};
|
|
94
|
+
const userText = replaceTemplateVariables(userTextTemplate, templateValues);
|
|
95
|
+
const userContentParts = [];
|
|
96
|
+
if (userText.trim().length > 0) {
|
|
97
|
+
userContentParts.push({
|
|
98
|
+
type: "text",
|
|
99
|
+
text: userText
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
imageInputDefs.forEach(elem => {
|
|
103
|
+
const imageValue = templateValues[elem.name];
|
|
104
|
+
if (imageValue && imageValue.trim().length > 0) {
|
|
105
|
+
userContentParts.push({
|
|
106
|
+
type: "image",
|
|
107
|
+
image: imageValue
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const userMessage = {
|
|
112
|
+
role: "user",
|
|
113
|
+
content: userContentParts.length > 0 ? userContentParts : ""
|
|
114
|
+
};
|
|
115
|
+
return [systemMessage, userMessage];
|
|
101
116
|
}
|
|
102
|
-
}
|
|
117
|
+
};
|
|
103
118
|
}
|
|
104
119
|
//# sourceMappingURL=ShouldMustTemplate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["getVariableRegex","RegExp","extractVariables","content","variableRegex","variables","match","exec","includes","push","resolvePartialVars","partialVars","entries","Promise","all","Object","map","key","value","result","fromEntries","replaceTemplateVariables","template","values","replace","_","variable","createShouldMustTemplate","inputDef","summary","shouldSection","mustSection","example","shouldSectionPrompt","length","shouldSectionCount","shouldSectionHeader","shouldSectionBody","elem","baseBody","no","title","join","mustSectionPrompt","mustSectionCount","mustSectionHeader","mustSectionBody","exampleSectionPrompt","exampleSectionBody","allSectionContent","s","usedVariables","definedInputVariables","name","definedPartialVariables","keys","definedVariables","undefinedVariables","filter","console","warn","autoGeneratedVariablesSection","systemPrompt","Boolean","stringInputPromptTemplate","type","description","imageInputDefs","systemTemplate","trim","userTextTemplate","formatMessages","args","resolvedPartialVars","mergedArgs","reduce","acc","templateValues","forEach","systemMessage","role","userText","userContentParts","text","imageValue","image","userMessage"],"sourceRoot":"../../../src","sources":["templates/ShouldMustTemplate.ts"],"mappings":"AAWA,SAASA,gBAAgBA,CAAA,EAAW;EAChC,IAAI;IACA,OAAO,IAAIC,MAAM,CAAC,sBAAsB,EAAE,IAAI,CAAC;EACnD,CAAC,CAAC,MAAM;IACJ,OAAO,6LAA6L;EACxM;AACJ;AAEA,SAASC,gBAAgBA,CAACC,OAAe,EAAY;EACjD,MAAMC,aAAa,GAAGJ,gBAAgB,CAAC,CAAC;EACxC,MAAMK,SAAmB,GAAG,EAAE;EAC9B,IAAIC,KAA6B,GAAG,IAAI;EACxC,OAAO,CAACA,KAAK,GAAGF,aAAa,CAACG,IAAI,CAACJ,OAAO,CAAC,MAAM,IAAI,EAAE;IACnD,IAAI,CAACE,SAAS,CAACG,QAAQ,CAACF,KAAK,CAAC,CAAC,CAAC,CAAC,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