@promptbook/core 0.67.2 β 0.67.3
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/esm/index.es.js +359 -324
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +359 -324
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -9,7 +9,7 @@ import moment from 'moment';
|
|
|
9
9
|
/**
|
|
10
10
|
* The version of the Promptbook library
|
|
11
11
|
*/
|
|
12
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
12
|
+
var PROMPTBOOK_VERSION = '0.67.2';
|
|
13
13
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
14
14
|
|
|
15
15
|
/*! *****************************************************************************
|
|
@@ -1779,7 +1779,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1779
1779
|
});
|
|
1780
1780
|
}
|
|
1781
1781
|
|
|
1782
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
1782
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.2",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.67.2",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.67.2",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.67.2",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1783
1783
|
|
|
1784
1784
|
var defaultDiacriticsRemovalMap = [
|
|
1785
1785
|
{
|
|
@@ -3131,13 +3131,24 @@ function createPipelineExecutor(options) {
|
|
|
3131
3131
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
3132
3132
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? IS_VERBOSE : _d, _e = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e;
|
|
3133
3133
|
validatePipeline(pipeline);
|
|
3134
|
+
var pipelineIdentification = (function () {
|
|
3135
|
+
// Note: This is a π implementation of [π]
|
|
3136
|
+
var _ = [];
|
|
3137
|
+
if (pipeline.sourceFile !== undefined) {
|
|
3138
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
3139
|
+
}
|
|
3140
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
3141
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
3142
|
+
}
|
|
3143
|
+
return _.join('\n');
|
|
3144
|
+
})();
|
|
3134
3145
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3135
3146
|
var preparedPipeline;
|
|
3136
3147
|
if (isPipelinePrepared(pipeline)) {
|
|
3137
3148
|
preparedPipeline = pipeline;
|
|
3138
3149
|
}
|
|
3139
3150
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
3140
|
-
console.warn(spaceTrim$1(
|
|
3151
|
+
console.warn(spaceTrim$1(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
3141
3152
|
}
|
|
3142
3153
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
3143
3154
|
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
@@ -3175,7 +3186,7 @@ function createPipelineExecutor(options) {
|
|
|
3175
3186
|
}
|
|
3176
3187
|
function getReservedParametersForTemplate(template) {
|
|
3177
3188
|
return __awaiter(this, void 0, void 0, function () {
|
|
3178
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3189
|
+
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_3, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3179
3190
|
var e_3, _a;
|
|
3180
3191
|
return __generator(this, function (_b) {
|
|
3181
3192
|
switch (_b.label) {
|
|
@@ -3198,13 +3209,16 @@ function createPipelineExecutor(options) {
|
|
|
3198
3209
|
currentDate: currentDate,
|
|
3199
3210
|
modelName: modelName,
|
|
3200
3211
|
};
|
|
3212
|
+
_loop_3 = function (parameterName) {
|
|
3213
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
3214
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3215
|
+
}
|
|
3216
|
+
};
|
|
3201
3217
|
try {
|
|
3202
3218
|
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3203
3219
|
for (RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
|
|
3204
3220
|
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3205
|
-
|
|
3206
|
-
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
3207
|
-
}
|
|
3221
|
+
_loop_3(parameterName);
|
|
3208
3222
|
}
|
|
3209
3223
|
}
|
|
3210
3224
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -3221,10 +3235,10 @@ function createPipelineExecutor(options) {
|
|
|
3221
3235
|
}
|
|
3222
3236
|
function executeSingleTemplate(currentTemplate) {
|
|
3223
3237
|
return __awaiter(this, void 0, void 0, function () {
|
|
3224
|
-
var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent,
|
|
3225
|
-
var
|
|
3226
|
-
return __generator(this, function (
|
|
3227
|
-
switch (
|
|
3238
|
+
var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_4, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, _loop_5, attempt, state_2;
|
|
3239
|
+
var e_4, _f, _g;
|
|
3240
|
+
return __generator(this, function (_h) {
|
|
3241
|
+
switch (_h.label) {
|
|
3228
3242
|
case 0:
|
|
3229
3243
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3230
3244
|
title = currentTemplate.title;
|
|
@@ -3241,47 +3255,48 @@ function createPipelineExecutor(options) {
|
|
|
3241
3255
|
// <- [3]
|
|
3242
3256
|
})];
|
|
3243
3257
|
case 1:
|
|
3244
|
-
|
|
3245
|
-
|
|
3258
|
+
_h.sent();
|
|
3259
|
+
_h.label = 2;
|
|
3246
3260
|
case 2:
|
|
3247
3261
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
3248
3262
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3249
3263
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3250
|
-
throw new UnexpectedError(spaceTrim$1("\n
|
|
3264
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n "); }));
|
|
3251
3265
|
}
|
|
3252
3266
|
_b = (_a = Object).freeze;
|
|
3253
3267
|
_c = [{}];
|
|
3254
3268
|
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
3255
3269
|
case 3:
|
|
3256
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(
|
|
3270
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3257
3271
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3258
3272
|
parameters = {};
|
|
3273
|
+
_loop_4 = function (parameterName) {
|
|
3274
|
+
// Situation: Parameter is defined and used
|
|
3275
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3276
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
3277
|
+
}
|
|
3278
|
+
// Situation: Parameter is defined but NOT used
|
|
3279
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3280
|
+
// Situation: Parameter is NOT defined BUT used
|
|
3281
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3282
|
+
// Houston, we have a problem
|
|
3283
|
+
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3284
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3285
|
+
}
|
|
3286
|
+
};
|
|
3259
3287
|
try {
|
|
3260
3288
|
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3261
3289
|
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3262
3290
|
parameterName = _e.value;
|
|
3263
|
-
|
|
3264
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3265
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3266
|
-
}
|
|
3267
|
-
// Situation: Parameter is defined but NOT used
|
|
3268
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
3269
|
-
// Do not pass this parameter to prompt
|
|
3270
|
-
}
|
|
3271
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3272
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3273
|
-
// Houston, we have a problem
|
|
3274
|
-
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3275
|
-
throw new UnexpectedError(spaceTrim$1("\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ")));
|
|
3276
|
-
}
|
|
3291
|
+
_loop_4(parameterName);
|
|
3277
3292
|
}
|
|
3278
3293
|
}
|
|
3279
|
-
catch (
|
|
3294
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
3280
3295
|
finally {
|
|
3281
3296
|
try {
|
|
3282
|
-
if (_e && !_e.done && (
|
|
3297
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3283
3298
|
}
|
|
3284
|
-
finally { if (
|
|
3299
|
+
finally { if (e_4) throw e_4.error; }
|
|
3285
3300
|
}
|
|
3286
3301
|
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3287
3302
|
Object.freeze(parameters);
|
|
@@ -3293,294 +3308,310 @@ function createPipelineExecutor(options) {
|
|
|
3293
3308
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3294
3309
|
.split('{content}')
|
|
3295
3310
|
.join(currentTemplate.content);
|
|
3311
|
+
_loop_5 = function (attempt) {
|
|
3312
|
+
var isJokerAttempt, jokerParameterName, _j, _k, _l, _m, scriptTools, error_2, e_5_1, _o, _p, functionName, postprocessingError, _q, _r, scriptTools, error_3, e_6_1, e_7_1, error_4;
|
|
3313
|
+
var e_5, _s, e_7, _t, e_6, _u;
|
|
3314
|
+
return __generator(this, function (_v) {
|
|
3315
|
+
switch (_v.label) {
|
|
3316
|
+
case 0:
|
|
3317
|
+
isJokerAttempt = attempt < 0;
|
|
3318
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3319
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
3320
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3321
|
+
}
|
|
3322
|
+
result = null;
|
|
3323
|
+
resultString = null;
|
|
3324
|
+
expectError = null;
|
|
3325
|
+
if (isJokerAttempt) {
|
|
3326
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
3327
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3328
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3329
|
+
}
|
|
3330
|
+
else {
|
|
3331
|
+
resultString = parameters[jokerParameterName];
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
_v.label = 1;
|
|
3335
|
+
case 1:
|
|
3336
|
+
_v.trys.push([1, 44, 45, 46]);
|
|
3337
|
+
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3338
|
+
_j = currentTemplate.blockType;
|
|
3339
|
+
switch (_j) {
|
|
3340
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3341
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3342
|
+
case 'SCRIPT': return [3 /*break*/, 12];
|
|
3343
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 23];
|
|
3344
|
+
}
|
|
3345
|
+
return [3 /*break*/, 25];
|
|
3346
|
+
case 2:
|
|
3347
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
3348
|
+
return [3 /*break*/, 26];
|
|
3349
|
+
case 3:
|
|
3350
|
+
prompt = {
|
|
3351
|
+
title: currentTemplate.title,
|
|
3352
|
+
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3353
|
+
? preparedPipeline.pipelineUrl
|
|
3354
|
+
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3355
|
+
parameters: parameters,
|
|
3356
|
+
content: preparedContent,
|
|
3357
|
+
modelRequirements: currentTemplate.modelRequirements,
|
|
3358
|
+
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3359
|
+
var name = _a.name;
|
|
3360
|
+
return name === currentTemplate.personaName;
|
|
3361
|
+
}) || {})), currentTemplate.expectations),
|
|
3362
|
+
expectFormat: currentTemplate.expectFormat,
|
|
3363
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3364
|
+
}; // <- TODO: Not very good type guard
|
|
3365
|
+
_k = currentTemplate.modelRequirements.modelVariant;
|
|
3366
|
+
switch (_k) {
|
|
3367
|
+
case 'CHAT': return [3 /*break*/, 4];
|
|
3368
|
+
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3369
|
+
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3370
|
+
}
|
|
3371
|
+
return [3 /*break*/, 10];
|
|
3372
|
+
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3373
|
+
case 5:
|
|
3374
|
+
chatResult = _v.sent();
|
|
3375
|
+
// TODO: [π¬] Destroy chatThread
|
|
3376
|
+
result = chatResult;
|
|
3377
|
+
resultString = chatResult.content;
|
|
3378
|
+
return [3 /*break*/, 11];
|
|
3379
|
+
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3380
|
+
case 7:
|
|
3381
|
+
completionResult = _v.sent();
|
|
3382
|
+
result = completionResult;
|
|
3383
|
+
resultString = completionResult.content;
|
|
3384
|
+
return [3 /*break*/, 11];
|
|
3385
|
+
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3386
|
+
case 9:
|
|
3387
|
+
embeddingResult = _v.sent();
|
|
3388
|
+
result = embeddingResult;
|
|
3389
|
+
resultString = embeddingResult.content.join(',');
|
|
3390
|
+
return [3 /*break*/, 11];
|
|
3391
|
+
case 10: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n\n "); }));
|
|
3392
|
+
case 11: return [3 /*break*/, 26];
|
|
3393
|
+
case 12:
|
|
3394
|
+
if (arrayableToArray(tools.script).length === 0) {
|
|
3395
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3396
|
+
}
|
|
3397
|
+
if (!currentTemplate.contentLanguage) {
|
|
3398
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for prompt template \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3399
|
+
}
|
|
3400
|
+
// TODO: DRY [1]
|
|
3401
|
+
scriptPipelineExecutionErrors = [];
|
|
3402
|
+
_v.label = 13;
|
|
3403
|
+
case 13:
|
|
3404
|
+
_v.trys.push([13, 20, 21, 22]);
|
|
3405
|
+
_l = (e_5 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3406
|
+
_v.label = 14;
|
|
3407
|
+
case 14:
|
|
3408
|
+
if (!!_m.done) return [3 /*break*/, 19];
|
|
3409
|
+
scriptTools = _m.value;
|
|
3410
|
+
_v.label = 15;
|
|
3411
|
+
case 15:
|
|
3412
|
+
_v.trys.push([15, 17, , 18]);
|
|
3413
|
+
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3414
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
3415
|
+
script: preparedContent,
|
|
3416
|
+
parameters: parameters,
|
|
3417
|
+
}))];
|
|
3418
|
+
case 16:
|
|
3419
|
+
resultString = _v.sent();
|
|
3420
|
+
return [3 /*break*/, 19];
|
|
3421
|
+
case 17:
|
|
3422
|
+
error_2 = _v.sent();
|
|
3423
|
+
if (!(error_2 instanceof Error)) {
|
|
3424
|
+
throw error_2;
|
|
3425
|
+
}
|
|
3426
|
+
if (error_2 instanceof UnexpectedError) {
|
|
3427
|
+
throw error_2;
|
|
3428
|
+
}
|
|
3429
|
+
scriptPipelineExecutionErrors.push(error_2);
|
|
3430
|
+
return [3 /*break*/, 18];
|
|
3431
|
+
case 18:
|
|
3432
|
+
_m = _l.next();
|
|
3433
|
+
return [3 /*break*/, 14];
|
|
3434
|
+
case 19: return [3 /*break*/, 22];
|
|
3435
|
+
case 20:
|
|
3436
|
+
e_5_1 = _v.sent();
|
|
3437
|
+
e_5 = { error: e_5_1 };
|
|
3438
|
+
return [3 /*break*/, 22];
|
|
3439
|
+
case 21:
|
|
3440
|
+
try {
|
|
3441
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3442
|
+
}
|
|
3443
|
+
finally { if (e_5) throw e_5.error; }
|
|
3444
|
+
return [7 /*endfinally*/];
|
|
3445
|
+
case 22:
|
|
3446
|
+
if (resultString !== null) {
|
|
3447
|
+
return [3 /*break*/, 26];
|
|
3448
|
+
}
|
|
3449
|
+
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3450
|
+
throw scriptPipelineExecutionErrors[0];
|
|
3451
|
+
}
|
|
3452
|
+
else {
|
|
3453
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3454
|
+
.map(function (error) { return '- ' + error.message; })
|
|
3455
|
+
.join('\n\n')), "\n "); }));
|
|
3456
|
+
}
|
|
3457
|
+
case 23:
|
|
3458
|
+
if (tools.userInterface === undefined) {
|
|
3459
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3460
|
+
}
|
|
3461
|
+
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3462
|
+
promptTitle: currentTemplate.title,
|
|
3463
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3464
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3465
|
+
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3466
|
+
placeholder: undefined,
|
|
3467
|
+
priority: priority,
|
|
3468
|
+
}))];
|
|
3469
|
+
case 24:
|
|
3470
|
+
// TODO: [πΉ] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
3471
|
+
resultString = _v.sent();
|
|
3472
|
+
return [3 /*break*/, 26];
|
|
3473
|
+
case 25: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.blockType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3474
|
+
case 26:
|
|
3475
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3476
|
+
_v.label = 27;
|
|
3477
|
+
case 27:
|
|
3478
|
+
_v.trys.push([27, 41, 42, 43]);
|
|
3479
|
+
_o = (e_7 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3480
|
+
_v.label = 28;
|
|
3481
|
+
case 28:
|
|
3482
|
+
if (!!_p.done) return [3 /*break*/, 40];
|
|
3483
|
+
functionName = _p.value;
|
|
3484
|
+
// TODO: DRY [1]
|
|
3485
|
+
scriptPipelineExecutionErrors = [];
|
|
3486
|
+
postprocessingError = null;
|
|
3487
|
+
_v.label = 29;
|
|
3488
|
+
case 29:
|
|
3489
|
+
_v.trys.push([29, 36, 37, 38]);
|
|
3490
|
+
_q = (e_6 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3491
|
+
_v.label = 30;
|
|
3492
|
+
case 30:
|
|
3493
|
+
if (!!_r.done) return [3 /*break*/, 35];
|
|
3494
|
+
scriptTools = _r.value;
|
|
3495
|
+
_v.label = 31;
|
|
3496
|
+
case 31:
|
|
3497
|
+
_v.trys.push([31, 33, , 34]);
|
|
3498
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
3499
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3500
|
+
script: "".concat(functionName, "(resultString)"),
|
|
3501
|
+
parameters: {
|
|
3502
|
+
resultString: resultString || '',
|
|
3503
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
3504
|
+
},
|
|
3505
|
+
})];
|
|
3506
|
+
case 32:
|
|
3507
|
+
resultString = _v.sent();
|
|
3508
|
+
postprocessingError = null;
|
|
3509
|
+
return [3 /*break*/, 35];
|
|
3510
|
+
case 33:
|
|
3511
|
+
error_3 = _v.sent();
|
|
3512
|
+
if (!(error_3 instanceof Error)) {
|
|
3513
|
+
throw error_3;
|
|
3514
|
+
}
|
|
3515
|
+
if (error_3 instanceof UnexpectedError) {
|
|
3516
|
+
throw error_3;
|
|
3517
|
+
}
|
|
3518
|
+
postprocessingError = error_3;
|
|
3519
|
+
scriptPipelineExecutionErrors.push(error_3);
|
|
3520
|
+
return [3 /*break*/, 34];
|
|
3521
|
+
case 34:
|
|
3522
|
+
_r = _q.next();
|
|
3523
|
+
return [3 /*break*/, 30];
|
|
3524
|
+
case 35: return [3 /*break*/, 38];
|
|
3525
|
+
case 36:
|
|
3526
|
+
e_6_1 = _v.sent();
|
|
3527
|
+
e_6 = { error: e_6_1 };
|
|
3528
|
+
return [3 /*break*/, 38];
|
|
3529
|
+
case 37:
|
|
3530
|
+
try {
|
|
3531
|
+
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3532
|
+
}
|
|
3533
|
+
finally { if (e_6) throw e_6.error; }
|
|
3534
|
+
return [7 /*endfinally*/];
|
|
3535
|
+
case 38:
|
|
3536
|
+
if (postprocessingError) {
|
|
3537
|
+
throw postprocessingError;
|
|
3538
|
+
}
|
|
3539
|
+
_v.label = 39;
|
|
3540
|
+
case 39:
|
|
3541
|
+
_p = _o.next();
|
|
3542
|
+
return [3 /*break*/, 28];
|
|
3543
|
+
case 40: return [3 /*break*/, 43];
|
|
3544
|
+
case 41:
|
|
3545
|
+
e_7_1 = _v.sent();
|
|
3546
|
+
e_7 = { error: e_7_1 };
|
|
3547
|
+
return [3 /*break*/, 43];
|
|
3548
|
+
case 42:
|
|
3549
|
+
try {
|
|
3550
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3551
|
+
}
|
|
3552
|
+
finally { if (e_7) throw e_7.error; }
|
|
3553
|
+
return [7 /*endfinally*/];
|
|
3554
|
+
case 43:
|
|
3555
|
+
// TODO: [π] Unite object for expecting amount and format
|
|
3556
|
+
if (currentTemplate.expectFormat) {
|
|
3557
|
+
if (currentTemplate.expectFormat === 'JSON') {
|
|
3558
|
+
if (!isValidJsonString(resultString || '')) {
|
|
3559
|
+
throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
// TODO: [π] Unite object for expecting amount and format
|
|
3564
|
+
if (currentTemplate.expectations) {
|
|
3565
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3566
|
+
}
|
|
3567
|
+
return [2 /*return*/, "break-attempts"];
|
|
3568
|
+
case 44:
|
|
3569
|
+
error_4 = _v.sent();
|
|
3570
|
+
if (!(error_4 instanceof ExpectError)) {
|
|
3571
|
+
throw error_4;
|
|
3572
|
+
}
|
|
3573
|
+
expectError = error_4;
|
|
3574
|
+
return [3 /*break*/, 46];
|
|
3575
|
+
case 45:
|
|
3576
|
+
if (!isJokerAttempt &&
|
|
3577
|
+
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3578
|
+
prompt
|
|
3579
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3580
|
+
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3581
|
+
) {
|
|
3582
|
+
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3583
|
+
executionReport.promptExecutions.push({
|
|
3584
|
+
prompt: __assign({}, prompt),
|
|
3585
|
+
result: result || undefined,
|
|
3586
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3587
|
+
});
|
|
3588
|
+
}
|
|
3589
|
+
return [7 /*endfinally*/];
|
|
3590
|
+
case 46:
|
|
3591
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3592
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
3593
|
+
}
|
|
3594
|
+
return [2 /*return*/];
|
|
3595
|
+
}
|
|
3596
|
+
});
|
|
3597
|
+
};
|
|
3296
3598
|
attempt = -jokerParameterNames.length;
|
|
3297
|
-
|
|
3599
|
+
_h.label = 4;
|
|
3298
3600
|
case 4:
|
|
3299
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
3300
|
-
|
|
3301
|
-
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3302
|
-
if (isJokerAttempt && !jokerParameterName) {
|
|
3303
|
-
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
3304
|
-
}
|
|
3305
|
-
result = null;
|
|
3306
|
-
resultString = null;
|
|
3307
|
-
expectError = null;
|
|
3308
|
-
if (isJokerAttempt) {
|
|
3309
|
-
if (parameters[jokerParameterName] === undefined) {
|
|
3310
|
-
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
3311
|
-
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3312
|
-
}
|
|
3313
|
-
else {
|
|
3314
|
-
resultString = parameters[jokerParameterName];
|
|
3315
|
-
}
|
|
3316
|
-
}
|
|
3317
|
-
_u.label = 5;
|
|
3601
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 7];
|
|
3602
|
+
return [5 /*yield**/, _loop_5(attempt)];
|
|
3318
3603
|
case 5:
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
switch (_f) {
|
|
3323
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
3324
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
3325
|
-
case 'SCRIPT': return [3 /*break*/, 16];
|
|
3326
|
-
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
3604
|
+
state_2 = _h.sent();
|
|
3605
|
+
switch (state_2) {
|
|
3606
|
+
case "break-attempts": return [3 /*break*/, 7];
|
|
3327
3607
|
}
|
|
3328
|
-
|
|
3608
|
+
_h.label = 6;
|
|
3329
3609
|
case 6:
|
|
3330
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3331
|
-
return [3 /*break*/, 30];
|
|
3332
|
-
case 7:
|
|
3333
|
-
prompt = {
|
|
3334
|
-
title: currentTemplate.title,
|
|
3335
|
-
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3336
|
-
? preparedPipeline.pipelineUrl
|
|
3337
|
-
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3338
|
-
parameters: parameters,
|
|
3339
|
-
content: preparedContent,
|
|
3340
|
-
modelRequirements: currentTemplate.modelRequirements,
|
|
3341
|
-
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3342
|
-
var name = _a.name;
|
|
3343
|
-
return name === currentTemplate.personaName;
|
|
3344
|
-
}) || {})), currentTemplate.expectations),
|
|
3345
|
-
expectFormat: currentTemplate.expectFormat,
|
|
3346
|
-
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3347
|
-
}; // <- TODO: Not very good type guard
|
|
3348
|
-
_g = currentTemplate.modelRequirements.modelVariant;
|
|
3349
|
-
switch (_g) {
|
|
3350
|
-
case 'CHAT': return [3 /*break*/, 8];
|
|
3351
|
-
case 'COMPLETION': return [3 /*break*/, 10];
|
|
3352
|
-
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
3353
|
-
}
|
|
3354
|
-
return [3 /*break*/, 14];
|
|
3355
|
-
case 8: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3356
|
-
case 9:
|
|
3357
|
-
chatResult = _u.sent();
|
|
3358
|
-
// TODO: [π¬] Destroy chatThread
|
|
3359
|
-
result = chatResult;
|
|
3360
|
-
resultString = chatResult.content;
|
|
3361
|
-
return [3 /*break*/, 15];
|
|
3362
|
-
case 10: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3363
|
-
case 11:
|
|
3364
|
-
completionResult = _u.sent();
|
|
3365
|
-
result = completionResult;
|
|
3366
|
-
resultString = completionResult.content;
|
|
3367
|
-
return [3 /*break*/, 15];
|
|
3368
|
-
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3369
|
-
case 13:
|
|
3370
|
-
embeddingResult = _u.sent();
|
|
3371
|
-
result = embeddingResult;
|
|
3372
|
-
resultString = embeddingResult.content.join(',');
|
|
3373
|
-
return [3 /*break*/, 15];
|
|
3374
|
-
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
3375
|
-
case 15: return [3 /*break*/, 30];
|
|
3376
|
-
case 16:
|
|
3377
|
-
if (arrayableToArray(tools.script).length === 0) {
|
|
3378
|
-
throw new PipelineExecutionError('No script execution tools are available');
|
|
3379
|
-
}
|
|
3380
|
-
if (!currentTemplate.contentLanguage) {
|
|
3381
|
-
throw new PipelineExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
3382
|
-
}
|
|
3383
|
-
// TODO: DRY [1]
|
|
3384
|
-
scriptPipelineExecutionErrors = [];
|
|
3385
|
-
_u.label = 17;
|
|
3386
|
-
case 17:
|
|
3387
|
-
_u.trys.push([17, 24, 25, 26]);
|
|
3388
|
-
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
3389
|
-
_u.label = 18;
|
|
3390
|
-
case 18:
|
|
3391
|
-
if (!!_j.done) return [3 /*break*/, 23];
|
|
3392
|
-
scriptTools = _j.value;
|
|
3393
|
-
_u.label = 19;
|
|
3394
|
-
case 19:
|
|
3395
|
-
_u.trys.push([19, 21, , 22]);
|
|
3396
|
-
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3397
|
-
scriptLanguage: currentTemplate.contentLanguage,
|
|
3398
|
-
script: preparedContent,
|
|
3399
|
-
parameters: parameters,
|
|
3400
|
-
}))];
|
|
3401
|
-
case 20:
|
|
3402
|
-
resultString = _u.sent();
|
|
3403
|
-
return [3 /*break*/, 23];
|
|
3404
|
-
case 21:
|
|
3405
|
-
error_2 = _u.sent();
|
|
3406
|
-
if (!(error_2 instanceof Error)) {
|
|
3407
|
-
throw error_2;
|
|
3408
|
-
}
|
|
3409
|
-
if (error_2 instanceof UnexpectedError) {
|
|
3410
|
-
throw error_2;
|
|
3411
|
-
}
|
|
3412
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3413
|
-
return [3 /*break*/, 22];
|
|
3414
|
-
case 22:
|
|
3415
|
-
_j = _h.next();
|
|
3416
|
-
return [3 /*break*/, 18];
|
|
3417
|
-
case 23: return [3 /*break*/, 26];
|
|
3418
|
-
case 24:
|
|
3419
|
-
e_4_1 = _u.sent();
|
|
3420
|
-
e_4 = { error: e_4_1 };
|
|
3421
|
-
return [3 /*break*/, 26];
|
|
3422
|
-
case 25:
|
|
3423
|
-
try {
|
|
3424
|
-
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
3425
|
-
}
|
|
3426
|
-
finally { if (e_4) throw e_4.error; }
|
|
3427
|
-
return [7 /*endfinally*/];
|
|
3428
|
-
case 26:
|
|
3429
|
-
if (resultString !== null) {
|
|
3430
|
-
return [3 /*break*/, 30];
|
|
3431
|
-
}
|
|
3432
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3433
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3434
|
-
}
|
|
3435
|
-
else {
|
|
3436
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3437
|
-
.map(function (error) { return '- ' + error.message; })
|
|
3438
|
-
.join('\n\n')), "\n "); }));
|
|
3439
|
-
}
|
|
3440
|
-
case 27:
|
|
3441
|
-
if (tools.userInterface === undefined) {
|
|
3442
|
-
throw new PipelineExecutionError('User interface tools are not available');
|
|
3443
|
-
}
|
|
3444
|
-
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3445
|
-
promptTitle: currentTemplate.title,
|
|
3446
|
-
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3447
|
-
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3448
|
-
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3449
|
-
placeholder: undefined,
|
|
3450
|
-
priority: priority,
|
|
3451
|
-
}))];
|
|
3452
|
-
case 28:
|
|
3453
|
-
// TODO: [πΉ] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
3454
|
-
resultString = _u.sent();
|
|
3455
|
-
return [3 /*break*/, 30];
|
|
3456
|
-
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
3457
|
-
case 30:
|
|
3458
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
3459
|
-
_u.label = 31;
|
|
3460
|
-
case 31:
|
|
3461
|
-
_u.trys.push([31, 45, 46, 47]);
|
|
3462
|
-
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
3463
|
-
_u.label = 32;
|
|
3464
|
-
case 32:
|
|
3465
|
-
if (!!_l.done) return [3 /*break*/, 44];
|
|
3466
|
-
functionName = _l.value;
|
|
3467
|
-
// TODO: DRY [1]
|
|
3468
|
-
scriptPipelineExecutionErrors = [];
|
|
3469
|
-
postprocessingError = null;
|
|
3470
|
-
_u.label = 33;
|
|
3471
|
-
case 33:
|
|
3472
|
-
_u.trys.push([33, 40, 41, 42]);
|
|
3473
|
-
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
3474
|
-
_u.label = 34;
|
|
3475
|
-
case 34:
|
|
3476
|
-
if (!!_o.done) return [3 /*break*/, 39];
|
|
3477
|
-
scriptTools = _o.value;
|
|
3478
|
-
_u.label = 35;
|
|
3479
|
-
case 35:
|
|
3480
|
-
_u.trys.push([35, 37, , 38]);
|
|
3481
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
3482
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3483
|
-
script: "".concat(functionName, "(resultString)"),
|
|
3484
|
-
parameters: {
|
|
3485
|
-
resultString: resultString || '',
|
|
3486
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
3487
|
-
},
|
|
3488
|
-
})];
|
|
3489
|
-
case 36:
|
|
3490
|
-
resultString = _u.sent();
|
|
3491
|
-
postprocessingError = null;
|
|
3492
|
-
return [3 /*break*/, 39];
|
|
3493
|
-
case 37:
|
|
3494
|
-
error_3 = _u.sent();
|
|
3495
|
-
if (!(error_3 instanceof Error)) {
|
|
3496
|
-
throw error_3;
|
|
3497
|
-
}
|
|
3498
|
-
if (error_3 instanceof UnexpectedError) {
|
|
3499
|
-
throw error_3;
|
|
3500
|
-
}
|
|
3501
|
-
postprocessingError = error_3;
|
|
3502
|
-
scriptPipelineExecutionErrors.push(error_3);
|
|
3503
|
-
return [3 /*break*/, 38];
|
|
3504
|
-
case 38:
|
|
3505
|
-
_o = _m.next();
|
|
3506
|
-
return [3 /*break*/, 34];
|
|
3507
|
-
case 39: return [3 /*break*/, 42];
|
|
3508
|
-
case 40:
|
|
3509
|
-
e_5_1 = _u.sent();
|
|
3510
|
-
e_5 = { error: e_5_1 };
|
|
3511
|
-
return [3 /*break*/, 42];
|
|
3512
|
-
case 41:
|
|
3513
|
-
try {
|
|
3514
|
-
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
3515
|
-
}
|
|
3516
|
-
finally { if (e_5) throw e_5.error; }
|
|
3517
|
-
return [7 /*endfinally*/];
|
|
3518
|
-
case 42:
|
|
3519
|
-
if (postprocessingError) {
|
|
3520
|
-
throw postprocessingError;
|
|
3521
|
-
}
|
|
3522
|
-
_u.label = 43;
|
|
3523
|
-
case 43:
|
|
3524
|
-
_l = _k.next();
|
|
3525
|
-
return [3 /*break*/, 32];
|
|
3526
|
-
case 44: return [3 /*break*/, 47];
|
|
3527
|
-
case 45:
|
|
3528
|
-
e_6_1 = _u.sent();
|
|
3529
|
-
e_6 = { error: e_6_1 };
|
|
3530
|
-
return [3 /*break*/, 47];
|
|
3531
|
-
case 46:
|
|
3532
|
-
try {
|
|
3533
|
-
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
3534
|
-
}
|
|
3535
|
-
finally { if (e_6) throw e_6.error; }
|
|
3536
|
-
return [7 /*endfinally*/];
|
|
3537
|
-
case 47:
|
|
3538
|
-
// TODO: [π] Unite object for expecting amount and format
|
|
3539
|
-
if (currentTemplate.expectFormat) {
|
|
3540
|
-
if (currentTemplate.expectFormat === 'JSON') {
|
|
3541
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3542
|
-
throw new ExpectError('Expected valid JSON string');
|
|
3543
|
-
}
|
|
3544
|
-
}
|
|
3545
|
-
}
|
|
3546
|
-
// TODO: [π] Unite object for expecting amount and format
|
|
3547
|
-
if (currentTemplate.expectations) {
|
|
3548
|
-
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3549
|
-
}
|
|
3550
|
-
return [3 /*break*/, 52];
|
|
3551
|
-
case 48:
|
|
3552
|
-
error_4 = _u.sent();
|
|
3553
|
-
if (!(error_4 instanceof ExpectError)) {
|
|
3554
|
-
throw error_4;
|
|
3555
|
-
}
|
|
3556
|
-
expectError = error_4;
|
|
3557
|
-
return [3 /*break*/, 50];
|
|
3558
|
-
case 49:
|
|
3559
|
-
if (!isJokerAttempt &&
|
|
3560
|
-
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3561
|
-
prompt
|
|
3562
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3563
|
-
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3564
|
-
) {
|
|
3565
|
-
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3566
|
-
executionReport.promptExecutions.push({
|
|
3567
|
-
prompt: __assign({}, prompt),
|
|
3568
|
-
result: result || undefined,
|
|
3569
|
-
error: expectError === null ? undefined : serializeError(expectError),
|
|
3570
|
-
});
|
|
3571
|
-
}
|
|
3572
|
-
return [7 /*endfinally*/];
|
|
3573
|
-
case 50:
|
|
3574
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3575
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
3576
|
-
}
|
|
3577
|
-
_u.label = 51;
|
|
3578
|
-
case 51:
|
|
3579
3610
|
attempt++;
|
|
3580
3611
|
return [3 /*break*/, 4];
|
|
3581
|
-
case
|
|
3612
|
+
case 7:
|
|
3582
3613
|
if (resultString === null) {
|
|
3583
|
-
throw new UnexpectedError(
|
|
3614
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3584
3615
|
}
|
|
3585
3616
|
if (onProgress /* <- [3] */) {
|
|
3586
3617
|
onProgress({
|
|
@@ -3594,7 +3625,7 @@ function createPipelineExecutor(options) {
|
|
|
3594
3625
|
// <- [3]
|
|
3595
3626
|
});
|
|
3596
3627
|
}
|
|
3597
|
-
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (
|
|
3628
|
+
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (_g = {}, _g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _g)));
|
|
3598
3629
|
return [2 /*return*/];
|
|
3599
3630
|
}
|
|
3600
3631
|
});
|
|
@@ -3603,6 +3634,14 @@ function createPipelineExecutor(options) {
|
|
|
3603
3634
|
function filterJustOutputParameters() {
|
|
3604
3635
|
var e_8, _a;
|
|
3605
3636
|
var outputParameters = {};
|
|
3637
|
+
var _loop_6 = function (parameter) {
|
|
3638
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3639
|
+
// [4]
|
|
3640
|
+
warnings.push(new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
3641
|
+
return "continue";
|
|
3642
|
+
}
|
|
3643
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3644
|
+
};
|
|
3606
3645
|
try {
|
|
3607
3646
|
// Note: Filter ONLY output parameters
|
|
3608
3647
|
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
@@ -3610,12 +3649,7 @@ function createPipelineExecutor(options) {
|
|
|
3610
3649
|
return isOutput;
|
|
3611
3650
|
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3612
3651
|
var parameter = _c.value;
|
|
3613
|
-
|
|
3614
|
-
// [4]
|
|
3615
|
-
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
|
|
3616
|
-
continue;
|
|
3617
|
-
}
|
|
3618
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3652
|
+
_loop_6(parameter);
|
|
3619
3653
|
}
|
|
3620
3654
|
}
|
|
3621
3655
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
@@ -3687,13 +3721,13 @@ function createPipelineExecutor(options) {
|
|
|
3687
3721
|
return name === parameterName;
|
|
3688
3722
|
});
|
|
3689
3723
|
if (parameter === undefined) {
|
|
3690
|
-
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3724
|
+
warnings.push(new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
3691
3725
|
}
|
|
3692
3726
|
else if (parameter.isInput === false) {
|
|
3693
|
-
return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3727
|
+
return { value: $asDeeplyFrozenSerializableJson(spaceTrim$1(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
3694
3728
|
isSuccessful: false,
|
|
3695
3729
|
errors: __spreadArray([
|
|
3696
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3730
|
+
new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
3697
3731
|
], __read(errors), false).map(serializeError),
|
|
3698
3732
|
warnings: warnings.map(serializeError),
|
|
3699
3733
|
executionReport: executionReport,
|
|
@@ -3742,7 +3776,7 @@ function createPipelineExecutor(options) {
|
|
|
3742
3776
|
case 0:
|
|
3743
3777
|
if (loopLimit-- < 0) {
|
|
3744
3778
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
3745
|
-
throw new UnexpectedError(
|
|
3779
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3746
3780
|
}
|
|
3747
3781
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3748
3782
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -3752,7 +3786,7 @@ function createPipelineExecutor(options) {
|
|
|
3752
3786
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3753
3787
|
throw new UnexpectedError(
|
|
3754
3788
|
// TODO: [π] DRY
|
|
3755
|
-
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3789
|
+
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates_1
|
|
3756
3790
|
.map(function (_a) {
|
|
3757
3791
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3758
3792
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -3832,6 +3866,7 @@ function createPipelineExecutor(options) {
|
|
|
3832
3866
|
return pipelineExecutor;
|
|
3833
3867
|
}
|
|
3834
3868
|
/**
|
|
3869
|
+
* TODO: !!! Identify not only pipeline BUT exact template ${block(pipelineIdentification)}
|
|
3835
3870
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3836
3871
|
* TODO: [π§ ][π³] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
3837
3872
|
* TODO: [πͺ] Use maxParallelCount here (not only pass to `preparePipeline`)
|