@promptbook/cli 0.67.2 β 0.67.4
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 +360 -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 +360 -324
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ import OpenAI from 'openai';
|
|
|
20
20
|
/**
|
|
21
21
|
* The version of the Promptbook library
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
23
|
+
var PROMPTBOOK_VERSION = '0.67.3';
|
|
24
24
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
25
25
|
|
|
26
26
|
/*! *****************************************************************************
|
|
@@ -1034,7 +1034,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1034
1034
|
});
|
|
1035
1035
|
}
|
|
1036
1036
|
|
|
1037
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
1037
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.3",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.3",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.3",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.3",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"}];
|
|
1038
1038
|
|
|
1039
1039
|
/**
|
|
1040
1040
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2962,13 +2962,24 @@ function createPipelineExecutor(options) {
|
|
|
2962
2962
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2963
2963
|
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;
|
|
2964
2964
|
validatePipeline(pipeline);
|
|
2965
|
+
var pipelineIdentification = (function () {
|
|
2966
|
+
// Note: This is a π implementation of [π]
|
|
2967
|
+
var _ = [];
|
|
2968
|
+
if (pipeline.sourceFile !== undefined) {
|
|
2969
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
2970
|
+
}
|
|
2971
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
2972
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
2973
|
+
}
|
|
2974
|
+
return _.join('\n');
|
|
2975
|
+
})();
|
|
2965
2976
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2966
2977
|
var preparedPipeline;
|
|
2967
2978
|
if (isPipelinePrepared(pipeline)) {
|
|
2968
2979
|
preparedPipeline = pipeline;
|
|
2969
2980
|
}
|
|
2970
2981
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
2971
|
-
console.warn(spaceTrim(
|
|
2982
|
+
console.warn(spaceTrim(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 "); }));
|
|
2972
2983
|
}
|
|
2973
2984
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2974
2985
|
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
@@ -3006,7 +3017,7 @@ function createPipelineExecutor(options) {
|
|
|
3006
3017
|
}
|
|
3007
3018
|
function getReservedParametersForTemplate(template) {
|
|
3008
3019
|
return __awaiter(this, void 0, void 0, function () {
|
|
3009
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3020
|
+
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_3, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3010
3021
|
var e_3, _a;
|
|
3011
3022
|
return __generator(this, function (_b) {
|
|
3012
3023
|
switch (_b.label) {
|
|
@@ -3029,13 +3040,16 @@ function createPipelineExecutor(options) {
|
|
|
3029
3040
|
currentDate: currentDate,
|
|
3030
3041
|
modelName: modelName,
|
|
3031
3042
|
};
|
|
3043
|
+
_loop_3 = function (parameterName) {
|
|
3044
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
3045
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3032
3048
|
try {
|
|
3033
3049
|
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3034
3050
|
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()) {
|
|
3035
3051
|
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3036
|
-
|
|
3037
|
-
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
3038
|
-
}
|
|
3052
|
+
_loop_3(parameterName);
|
|
3039
3053
|
}
|
|
3040
3054
|
}
|
|
3041
3055
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -3052,10 +3066,10 @@ function createPipelineExecutor(options) {
|
|
|
3052
3066
|
}
|
|
3053
3067
|
function executeSingleTemplate(currentTemplate) {
|
|
3054
3068
|
return __awaiter(this, void 0, void 0, function () {
|
|
3055
|
-
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,
|
|
3056
|
-
var
|
|
3057
|
-
return __generator(this, function (
|
|
3058
|
-
switch (
|
|
3069
|
+
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;
|
|
3070
|
+
var e_4, _f, _g;
|
|
3071
|
+
return __generator(this, function (_h) {
|
|
3072
|
+
switch (_h.label) {
|
|
3059
3073
|
case 0:
|
|
3060
3074
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3061
3075
|
title = currentTemplate.title;
|
|
@@ -3072,47 +3086,48 @@ function createPipelineExecutor(options) {
|
|
|
3072
3086
|
// <- [3]
|
|
3073
3087
|
})];
|
|
3074
3088
|
case 1:
|
|
3075
|
-
|
|
3076
|
-
|
|
3089
|
+
_h.sent();
|
|
3090
|
+
_h.label = 2;
|
|
3077
3091
|
case 2:
|
|
3078
3092
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
3079
3093
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3080
3094
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3081
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
3095
|
+
throw new UnexpectedError(spaceTrim(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 "); }));
|
|
3082
3096
|
}
|
|
3083
3097
|
_b = (_a = Object).freeze;
|
|
3084
3098
|
_c = [{}];
|
|
3085
3099
|
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
3086
3100
|
case 3:
|
|
3087
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(
|
|
3101
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3088
3102
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3089
3103
|
parameters = {};
|
|
3104
|
+
_loop_4 = function (parameterName) {
|
|
3105
|
+
// Situation: Parameter is defined and used
|
|
3106
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3107
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
3108
|
+
}
|
|
3109
|
+
// Situation: Parameter is defined but NOT used
|
|
3110
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3111
|
+
// Situation: Parameter is NOT defined BUT used
|
|
3112
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3113
|
+
// Houston, we have a problem
|
|
3114
|
+
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3115
|
+
throw new UnexpectedError(spaceTrim(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 "); }));
|
|
3116
|
+
}
|
|
3117
|
+
};
|
|
3090
3118
|
try {
|
|
3091
3119
|
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3092
3120
|
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3093
3121
|
parameterName = _e.value;
|
|
3094
|
-
|
|
3095
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3096
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3097
|
-
}
|
|
3098
|
-
// Situation: Parameter is defined but NOT used
|
|
3099
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
3100
|
-
// Do not pass this parameter to prompt
|
|
3101
|
-
}
|
|
3102
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3103
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3104
|
-
// Houston, we have a problem
|
|
3105
|
-
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3106
|
-
throw new UnexpectedError(spaceTrim("\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 ")));
|
|
3107
|
-
}
|
|
3122
|
+
_loop_4(parameterName);
|
|
3108
3123
|
}
|
|
3109
3124
|
}
|
|
3110
|
-
catch (
|
|
3125
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
3111
3126
|
finally {
|
|
3112
3127
|
try {
|
|
3113
|
-
if (_e && !_e.done && (
|
|
3128
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3114
3129
|
}
|
|
3115
|
-
finally { if (
|
|
3130
|
+
finally { if (e_4) throw e_4.error; }
|
|
3116
3131
|
}
|
|
3117
3132
|
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3118
3133
|
Object.freeze(parameters);
|
|
@@ -3124,294 +3139,311 @@ function createPipelineExecutor(options) {
|
|
|
3124
3139
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3125
3140
|
.split('{content}')
|
|
3126
3141
|
.join(currentTemplate.content);
|
|
3142
|
+
_loop_5 = function (attempt) {
|
|
3143
|
+
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;
|
|
3144
|
+
var e_5, _s, e_7, _t, e_6, _u;
|
|
3145
|
+
return __generator(this, function (_v) {
|
|
3146
|
+
switch (_v.label) {
|
|
3147
|
+
case 0:
|
|
3148
|
+
isJokerAttempt = attempt < 0;
|
|
3149
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3150
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
3151
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3152
|
+
}
|
|
3153
|
+
result = null;
|
|
3154
|
+
resultString = null;
|
|
3155
|
+
expectError = null;
|
|
3156
|
+
if (isJokerAttempt) {
|
|
3157
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
3158
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3159
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3160
|
+
}
|
|
3161
|
+
else {
|
|
3162
|
+
resultString = parameters[jokerParameterName];
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
_v.label = 1;
|
|
3166
|
+
case 1:
|
|
3167
|
+
_v.trys.push([1, 44, 45, 46]);
|
|
3168
|
+
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3169
|
+
_j = currentTemplate.blockType;
|
|
3170
|
+
switch (_j) {
|
|
3171
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3172
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3173
|
+
case 'SCRIPT': return [3 /*break*/, 12];
|
|
3174
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 23];
|
|
3175
|
+
}
|
|
3176
|
+
return [3 /*break*/, 25];
|
|
3177
|
+
case 2:
|
|
3178
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
3179
|
+
return [3 /*break*/, 26];
|
|
3180
|
+
case 3:
|
|
3181
|
+
prompt = {
|
|
3182
|
+
title: currentTemplate.title,
|
|
3183
|
+
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3184
|
+
? preparedPipeline.pipelineUrl
|
|
3185
|
+
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3186
|
+
parameters: parameters,
|
|
3187
|
+
content: preparedContent,
|
|
3188
|
+
modelRequirements: currentTemplate.modelRequirements,
|
|
3189
|
+
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3190
|
+
var name = _a.name;
|
|
3191
|
+
return name === currentTemplate.personaName;
|
|
3192
|
+
}) || {})), currentTemplate.expectations),
|
|
3193
|
+
expectFormat: currentTemplate.expectFormat,
|
|
3194
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3195
|
+
}; // <- TODO: Not very good type guard
|
|
3196
|
+
_k = currentTemplate.modelRequirements.modelVariant;
|
|
3197
|
+
switch (_k) {
|
|
3198
|
+
case 'CHAT': return [3 /*break*/, 4];
|
|
3199
|
+
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3200
|
+
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3201
|
+
}
|
|
3202
|
+
return [3 /*break*/, 10];
|
|
3203
|
+
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3204
|
+
case 5:
|
|
3205
|
+
chatResult = _v.sent();
|
|
3206
|
+
// TODO: [π¬] Destroy chatThread
|
|
3207
|
+
result = chatResult;
|
|
3208
|
+
resultString = chatResult.content;
|
|
3209
|
+
return [3 /*break*/, 11];
|
|
3210
|
+
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3211
|
+
case 7:
|
|
3212
|
+
completionResult = _v.sent();
|
|
3213
|
+
result = completionResult;
|
|
3214
|
+
resultString = completionResult.content;
|
|
3215
|
+
return [3 /*break*/, 11];
|
|
3216
|
+
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3217
|
+
case 9:
|
|
3218
|
+
embeddingResult = _v.sent();
|
|
3219
|
+
result = embeddingResult;
|
|
3220
|
+
resultString = embeddingResult.content.join(',');
|
|
3221
|
+
return [3 /*break*/, 11];
|
|
3222
|
+
case 10: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n\n "); }));
|
|
3223
|
+
case 11: return [3 /*break*/, 26];
|
|
3224
|
+
case 12:
|
|
3225
|
+
if (arrayableToArray(tools.script).length === 0) {
|
|
3226
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3227
|
+
}
|
|
3228
|
+
if (!currentTemplate.contentLanguage) {
|
|
3229
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script language is not defined for prompt template \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3230
|
+
}
|
|
3231
|
+
// TODO: DRY [1]
|
|
3232
|
+
scriptPipelineExecutionErrors = [];
|
|
3233
|
+
_v.label = 13;
|
|
3234
|
+
case 13:
|
|
3235
|
+
_v.trys.push([13, 20, 21, 22]);
|
|
3236
|
+
_l = (e_5 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3237
|
+
_v.label = 14;
|
|
3238
|
+
case 14:
|
|
3239
|
+
if (!!_m.done) return [3 /*break*/, 19];
|
|
3240
|
+
scriptTools = _m.value;
|
|
3241
|
+
_v.label = 15;
|
|
3242
|
+
case 15:
|
|
3243
|
+
_v.trys.push([15, 17, , 18]);
|
|
3244
|
+
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3245
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
3246
|
+
script: preparedContent,
|
|
3247
|
+
parameters: parameters,
|
|
3248
|
+
}))];
|
|
3249
|
+
case 16:
|
|
3250
|
+
resultString = _v.sent();
|
|
3251
|
+
return [3 /*break*/, 19];
|
|
3252
|
+
case 17:
|
|
3253
|
+
error_2 = _v.sent();
|
|
3254
|
+
if (!(error_2 instanceof Error)) {
|
|
3255
|
+
throw error_2;
|
|
3256
|
+
}
|
|
3257
|
+
if (error_2 instanceof UnexpectedError) {
|
|
3258
|
+
throw error_2;
|
|
3259
|
+
}
|
|
3260
|
+
scriptPipelineExecutionErrors.push(error_2);
|
|
3261
|
+
return [3 /*break*/, 18];
|
|
3262
|
+
case 18:
|
|
3263
|
+
_m = _l.next();
|
|
3264
|
+
return [3 /*break*/, 14];
|
|
3265
|
+
case 19: return [3 /*break*/, 22];
|
|
3266
|
+
case 20:
|
|
3267
|
+
e_5_1 = _v.sent();
|
|
3268
|
+
e_5 = { error: e_5_1 };
|
|
3269
|
+
return [3 /*break*/, 22];
|
|
3270
|
+
case 21:
|
|
3271
|
+
try {
|
|
3272
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3273
|
+
}
|
|
3274
|
+
finally { if (e_5) throw e_5.error; }
|
|
3275
|
+
return [7 /*endfinally*/];
|
|
3276
|
+
case 22:
|
|
3277
|
+
if (resultString !== null) {
|
|
3278
|
+
return [3 /*break*/, 26];
|
|
3279
|
+
}
|
|
3280
|
+
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3281
|
+
throw scriptPipelineExecutionErrors[0];
|
|
3282
|
+
}
|
|
3283
|
+
else {
|
|
3284
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3285
|
+
.map(function (error) { return '- ' + error.message; })
|
|
3286
|
+
.join('\n\n')), "\n "); }));
|
|
3287
|
+
}
|
|
3288
|
+
case 23:
|
|
3289
|
+
if (tools.userInterface === undefined) {
|
|
3290
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3291
|
+
}
|
|
3292
|
+
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3293
|
+
promptTitle: currentTemplate.title,
|
|
3294
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3295
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3296
|
+
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3297
|
+
placeholder: undefined,
|
|
3298
|
+
priority: priority,
|
|
3299
|
+
}))];
|
|
3300
|
+
case 24:
|
|
3301
|
+
// TODO: [πΉ] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
3302
|
+
resultString = _v.sent();
|
|
3303
|
+
return [3 /*break*/, 26];
|
|
3304
|
+
case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.blockType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3305
|
+
case 26:
|
|
3306
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3307
|
+
_v.label = 27;
|
|
3308
|
+
case 27:
|
|
3309
|
+
_v.trys.push([27, 41, 42, 43]);
|
|
3310
|
+
_o = (e_7 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3311
|
+
_v.label = 28;
|
|
3312
|
+
case 28:
|
|
3313
|
+
if (!!_p.done) return [3 /*break*/, 40];
|
|
3314
|
+
functionName = _p.value;
|
|
3315
|
+
// TODO: DRY [1]
|
|
3316
|
+
scriptPipelineExecutionErrors = [];
|
|
3317
|
+
postprocessingError = null;
|
|
3318
|
+
_v.label = 29;
|
|
3319
|
+
case 29:
|
|
3320
|
+
_v.trys.push([29, 36, 37, 38]);
|
|
3321
|
+
_q = (e_6 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3322
|
+
_v.label = 30;
|
|
3323
|
+
case 30:
|
|
3324
|
+
if (!!_r.done) return [3 /*break*/, 35];
|
|
3325
|
+
scriptTools = _r.value;
|
|
3326
|
+
_v.label = 31;
|
|
3327
|
+
case 31:
|
|
3328
|
+
_v.trys.push([31, 33, , 34]);
|
|
3329
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
3330
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3331
|
+
script: "".concat(functionName, "(resultString)"),
|
|
3332
|
+
parameters: {
|
|
3333
|
+
resultString: resultString || '',
|
|
3334
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
3335
|
+
},
|
|
3336
|
+
})];
|
|
3337
|
+
case 32:
|
|
3338
|
+
resultString = _v.sent();
|
|
3339
|
+
postprocessingError = null;
|
|
3340
|
+
return [3 /*break*/, 35];
|
|
3341
|
+
case 33:
|
|
3342
|
+
error_3 = _v.sent();
|
|
3343
|
+
if (!(error_3 instanceof Error)) {
|
|
3344
|
+
throw error_3;
|
|
3345
|
+
}
|
|
3346
|
+
if (error_3 instanceof UnexpectedError) {
|
|
3347
|
+
throw error_3;
|
|
3348
|
+
}
|
|
3349
|
+
postprocessingError = error_3;
|
|
3350
|
+
scriptPipelineExecutionErrors.push(error_3);
|
|
3351
|
+
return [3 /*break*/, 34];
|
|
3352
|
+
case 34:
|
|
3353
|
+
_r = _q.next();
|
|
3354
|
+
return [3 /*break*/, 30];
|
|
3355
|
+
case 35: return [3 /*break*/, 38];
|
|
3356
|
+
case 36:
|
|
3357
|
+
e_6_1 = _v.sent();
|
|
3358
|
+
e_6 = { error: e_6_1 };
|
|
3359
|
+
return [3 /*break*/, 38];
|
|
3360
|
+
case 37:
|
|
3361
|
+
try {
|
|
3362
|
+
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3363
|
+
}
|
|
3364
|
+
finally { if (e_6) throw e_6.error; }
|
|
3365
|
+
return [7 /*endfinally*/];
|
|
3366
|
+
case 38:
|
|
3367
|
+
if (postprocessingError) {
|
|
3368
|
+
throw postprocessingError;
|
|
3369
|
+
}
|
|
3370
|
+
_v.label = 39;
|
|
3371
|
+
case 39:
|
|
3372
|
+
_p = _o.next();
|
|
3373
|
+
return [3 /*break*/, 28];
|
|
3374
|
+
case 40: return [3 /*break*/, 43];
|
|
3375
|
+
case 41:
|
|
3376
|
+
e_7_1 = _v.sent();
|
|
3377
|
+
e_7 = { error: e_7_1 };
|
|
3378
|
+
return [3 /*break*/, 43];
|
|
3379
|
+
case 42:
|
|
3380
|
+
try {
|
|
3381
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3382
|
+
}
|
|
3383
|
+
finally { if (e_7) throw e_7.error; }
|
|
3384
|
+
return [7 /*endfinally*/];
|
|
3385
|
+
case 43:
|
|
3386
|
+
// TODO: [π] Unite object for expecting amount and format
|
|
3387
|
+
if (currentTemplate.expectFormat) {
|
|
3388
|
+
if (currentTemplate.expectFormat === 'JSON') {
|
|
3389
|
+
if (!isValidJsonString(resultString || '')) {
|
|
3390
|
+
throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3391
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
// TODO: [π] Unite object for expecting amount and format
|
|
3396
|
+
if (currentTemplate.expectations) {
|
|
3397
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3398
|
+
}
|
|
3399
|
+
return [2 /*return*/, "break-attempts"];
|
|
3400
|
+
case 44:
|
|
3401
|
+
error_4 = _v.sent();
|
|
3402
|
+
if (!(error_4 instanceof ExpectError)) {
|
|
3403
|
+
throw error_4;
|
|
3404
|
+
}
|
|
3405
|
+
expectError = error_4;
|
|
3406
|
+
return [3 /*break*/, 46];
|
|
3407
|
+
case 45:
|
|
3408
|
+
if (!isJokerAttempt &&
|
|
3409
|
+
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3410
|
+
prompt
|
|
3411
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3412
|
+
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3413
|
+
) {
|
|
3414
|
+
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3415
|
+
executionReport.promptExecutions.push({
|
|
3416
|
+
prompt: __assign({}, prompt),
|
|
3417
|
+
result: result || undefined,
|
|
3418
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3419
|
+
});
|
|
3420
|
+
}
|
|
3421
|
+
return [7 /*endfinally*/];
|
|
3422
|
+
case 46:
|
|
3423
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3424
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block(prompt.content), "\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(block(resultString || 'null'), "\n ---\n "); }));
|
|
3425
|
+
}
|
|
3426
|
+
return [2 /*return*/];
|
|
3427
|
+
}
|
|
3428
|
+
});
|
|
3429
|
+
};
|
|
3127
3430
|
attempt = -jokerParameterNames.length;
|
|
3128
|
-
|
|
3431
|
+
_h.label = 4;
|
|
3129
3432
|
case 4:
|
|
3130
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
3131
|
-
|
|
3132
|
-
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3133
|
-
if (isJokerAttempt && !jokerParameterName) {
|
|
3134
|
-
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
3135
|
-
}
|
|
3136
|
-
result = null;
|
|
3137
|
-
resultString = null;
|
|
3138
|
-
expectError = null;
|
|
3139
|
-
if (isJokerAttempt) {
|
|
3140
|
-
if (parameters[jokerParameterName] === undefined) {
|
|
3141
|
-
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
3142
|
-
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3143
|
-
}
|
|
3144
|
-
else {
|
|
3145
|
-
resultString = parameters[jokerParameterName];
|
|
3146
|
-
}
|
|
3147
|
-
}
|
|
3148
|
-
_u.label = 5;
|
|
3433
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 7];
|
|
3434
|
+
return [5 /*yield**/, _loop_5(attempt)];
|
|
3149
3435
|
case 5:
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
switch (_f) {
|
|
3154
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
3155
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
3156
|
-
case 'SCRIPT': return [3 /*break*/, 16];
|
|
3157
|
-
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
3436
|
+
state_2 = _h.sent();
|
|
3437
|
+
switch (state_2) {
|
|
3438
|
+
case "break-attempts": return [3 /*break*/, 7];
|
|
3158
3439
|
}
|
|
3159
|
-
|
|
3440
|
+
_h.label = 6;
|
|
3160
3441
|
case 6:
|
|
3161
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3162
|
-
return [3 /*break*/, 30];
|
|
3163
|
-
case 7:
|
|
3164
|
-
prompt = {
|
|
3165
|
-
title: currentTemplate.title,
|
|
3166
|
-
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3167
|
-
? preparedPipeline.pipelineUrl
|
|
3168
|
-
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3169
|
-
parameters: parameters,
|
|
3170
|
-
content: preparedContent,
|
|
3171
|
-
modelRequirements: currentTemplate.modelRequirements,
|
|
3172
|
-
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3173
|
-
var name = _a.name;
|
|
3174
|
-
return name === currentTemplate.personaName;
|
|
3175
|
-
}) || {})), currentTemplate.expectations),
|
|
3176
|
-
expectFormat: currentTemplate.expectFormat,
|
|
3177
|
-
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3178
|
-
}; // <- TODO: Not very good type guard
|
|
3179
|
-
_g = currentTemplate.modelRequirements.modelVariant;
|
|
3180
|
-
switch (_g) {
|
|
3181
|
-
case 'CHAT': return [3 /*break*/, 8];
|
|
3182
|
-
case 'COMPLETION': return [3 /*break*/, 10];
|
|
3183
|
-
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
3184
|
-
}
|
|
3185
|
-
return [3 /*break*/, 14];
|
|
3186
|
-
case 8: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3187
|
-
case 9:
|
|
3188
|
-
chatResult = _u.sent();
|
|
3189
|
-
// TODO: [π¬] Destroy chatThread
|
|
3190
|
-
result = chatResult;
|
|
3191
|
-
resultString = chatResult.content;
|
|
3192
|
-
return [3 /*break*/, 15];
|
|
3193
|
-
case 10: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3194
|
-
case 11:
|
|
3195
|
-
completionResult = _u.sent();
|
|
3196
|
-
result = completionResult;
|
|
3197
|
-
resultString = completionResult.content;
|
|
3198
|
-
return [3 /*break*/, 15];
|
|
3199
|
-
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3200
|
-
case 13:
|
|
3201
|
-
embeddingResult = _u.sent();
|
|
3202
|
-
result = embeddingResult;
|
|
3203
|
-
resultString = embeddingResult.content.join(',');
|
|
3204
|
-
return [3 /*break*/, 15];
|
|
3205
|
-
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
3206
|
-
case 15: return [3 /*break*/, 30];
|
|
3207
|
-
case 16:
|
|
3208
|
-
if (arrayableToArray(tools.script).length === 0) {
|
|
3209
|
-
throw new PipelineExecutionError('No script execution tools are available');
|
|
3210
|
-
}
|
|
3211
|
-
if (!currentTemplate.contentLanguage) {
|
|
3212
|
-
throw new PipelineExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
3213
|
-
}
|
|
3214
|
-
// TODO: DRY [1]
|
|
3215
|
-
scriptPipelineExecutionErrors = [];
|
|
3216
|
-
_u.label = 17;
|
|
3217
|
-
case 17:
|
|
3218
|
-
_u.trys.push([17, 24, 25, 26]);
|
|
3219
|
-
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
3220
|
-
_u.label = 18;
|
|
3221
|
-
case 18:
|
|
3222
|
-
if (!!_j.done) return [3 /*break*/, 23];
|
|
3223
|
-
scriptTools = _j.value;
|
|
3224
|
-
_u.label = 19;
|
|
3225
|
-
case 19:
|
|
3226
|
-
_u.trys.push([19, 21, , 22]);
|
|
3227
|
-
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3228
|
-
scriptLanguage: currentTemplate.contentLanguage,
|
|
3229
|
-
script: preparedContent,
|
|
3230
|
-
parameters: parameters,
|
|
3231
|
-
}))];
|
|
3232
|
-
case 20:
|
|
3233
|
-
resultString = _u.sent();
|
|
3234
|
-
return [3 /*break*/, 23];
|
|
3235
|
-
case 21:
|
|
3236
|
-
error_2 = _u.sent();
|
|
3237
|
-
if (!(error_2 instanceof Error)) {
|
|
3238
|
-
throw error_2;
|
|
3239
|
-
}
|
|
3240
|
-
if (error_2 instanceof UnexpectedError) {
|
|
3241
|
-
throw error_2;
|
|
3242
|
-
}
|
|
3243
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3244
|
-
return [3 /*break*/, 22];
|
|
3245
|
-
case 22:
|
|
3246
|
-
_j = _h.next();
|
|
3247
|
-
return [3 /*break*/, 18];
|
|
3248
|
-
case 23: return [3 /*break*/, 26];
|
|
3249
|
-
case 24:
|
|
3250
|
-
e_4_1 = _u.sent();
|
|
3251
|
-
e_4 = { error: e_4_1 };
|
|
3252
|
-
return [3 /*break*/, 26];
|
|
3253
|
-
case 25:
|
|
3254
|
-
try {
|
|
3255
|
-
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
3256
|
-
}
|
|
3257
|
-
finally { if (e_4) throw e_4.error; }
|
|
3258
|
-
return [7 /*endfinally*/];
|
|
3259
|
-
case 26:
|
|
3260
|
-
if (resultString !== null) {
|
|
3261
|
-
return [3 /*break*/, 30];
|
|
3262
|
-
}
|
|
3263
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3264
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3265
|
-
}
|
|
3266
|
-
else {
|
|
3267
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3268
|
-
.map(function (error) { return '- ' + error.message; })
|
|
3269
|
-
.join('\n\n')), "\n "); }));
|
|
3270
|
-
}
|
|
3271
|
-
case 27:
|
|
3272
|
-
if (tools.userInterface === undefined) {
|
|
3273
|
-
throw new PipelineExecutionError('User interface tools are not available');
|
|
3274
|
-
}
|
|
3275
|
-
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3276
|
-
promptTitle: currentTemplate.title,
|
|
3277
|
-
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3278
|
-
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3279
|
-
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3280
|
-
placeholder: undefined,
|
|
3281
|
-
priority: priority,
|
|
3282
|
-
}))];
|
|
3283
|
-
case 28:
|
|
3284
|
-
// TODO: [πΉ] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
3285
|
-
resultString = _u.sent();
|
|
3286
|
-
return [3 /*break*/, 30];
|
|
3287
|
-
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
3288
|
-
case 30:
|
|
3289
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
3290
|
-
_u.label = 31;
|
|
3291
|
-
case 31:
|
|
3292
|
-
_u.trys.push([31, 45, 46, 47]);
|
|
3293
|
-
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
3294
|
-
_u.label = 32;
|
|
3295
|
-
case 32:
|
|
3296
|
-
if (!!_l.done) return [3 /*break*/, 44];
|
|
3297
|
-
functionName = _l.value;
|
|
3298
|
-
// TODO: DRY [1]
|
|
3299
|
-
scriptPipelineExecutionErrors = [];
|
|
3300
|
-
postprocessingError = null;
|
|
3301
|
-
_u.label = 33;
|
|
3302
|
-
case 33:
|
|
3303
|
-
_u.trys.push([33, 40, 41, 42]);
|
|
3304
|
-
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
3305
|
-
_u.label = 34;
|
|
3306
|
-
case 34:
|
|
3307
|
-
if (!!_o.done) return [3 /*break*/, 39];
|
|
3308
|
-
scriptTools = _o.value;
|
|
3309
|
-
_u.label = 35;
|
|
3310
|
-
case 35:
|
|
3311
|
-
_u.trys.push([35, 37, , 38]);
|
|
3312
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
3313
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3314
|
-
script: "".concat(functionName, "(resultString)"),
|
|
3315
|
-
parameters: {
|
|
3316
|
-
resultString: resultString || '',
|
|
3317
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
3318
|
-
},
|
|
3319
|
-
})];
|
|
3320
|
-
case 36:
|
|
3321
|
-
resultString = _u.sent();
|
|
3322
|
-
postprocessingError = null;
|
|
3323
|
-
return [3 /*break*/, 39];
|
|
3324
|
-
case 37:
|
|
3325
|
-
error_3 = _u.sent();
|
|
3326
|
-
if (!(error_3 instanceof Error)) {
|
|
3327
|
-
throw error_3;
|
|
3328
|
-
}
|
|
3329
|
-
if (error_3 instanceof UnexpectedError) {
|
|
3330
|
-
throw error_3;
|
|
3331
|
-
}
|
|
3332
|
-
postprocessingError = error_3;
|
|
3333
|
-
scriptPipelineExecutionErrors.push(error_3);
|
|
3334
|
-
return [3 /*break*/, 38];
|
|
3335
|
-
case 38:
|
|
3336
|
-
_o = _m.next();
|
|
3337
|
-
return [3 /*break*/, 34];
|
|
3338
|
-
case 39: return [3 /*break*/, 42];
|
|
3339
|
-
case 40:
|
|
3340
|
-
e_5_1 = _u.sent();
|
|
3341
|
-
e_5 = { error: e_5_1 };
|
|
3342
|
-
return [3 /*break*/, 42];
|
|
3343
|
-
case 41:
|
|
3344
|
-
try {
|
|
3345
|
-
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
3346
|
-
}
|
|
3347
|
-
finally { if (e_5) throw e_5.error; }
|
|
3348
|
-
return [7 /*endfinally*/];
|
|
3349
|
-
case 42:
|
|
3350
|
-
if (postprocessingError) {
|
|
3351
|
-
throw postprocessingError;
|
|
3352
|
-
}
|
|
3353
|
-
_u.label = 43;
|
|
3354
|
-
case 43:
|
|
3355
|
-
_l = _k.next();
|
|
3356
|
-
return [3 /*break*/, 32];
|
|
3357
|
-
case 44: return [3 /*break*/, 47];
|
|
3358
|
-
case 45:
|
|
3359
|
-
e_6_1 = _u.sent();
|
|
3360
|
-
e_6 = { error: e_6_1 };
|
|
3361
|
-
return [3 /*break*/, 47];
|
|
3362
|
-
case 46:
|
|
3363
|
-
try {
|
|
3364
|
-
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
3365
|
-
}
|
|
3366
|
-
finally { if (e_6) throw e_6.error; }
|
|
3367
|
-
return [7 /*endfinally*/];
|
|
3368
|
-
case 47:
|
|
3369
|
-
// TODO: [π] Unite object for expecting amount and format
|
|
3370
|
-
if (currentTemplate.expectFormat) {
|
|
3371
|
-
if (currentTemplate.expectFormat === 'JSON') {
|
|
3372
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3373
|
-
throw new ExpectError('Expected valid JSON string');
|
|
3374
|
-
}
|
|
3375
|
-
}
|
|
3376
|
-
}
|
|
3377
|
-
// TODO: [π] Unite object for expecting amount and format
|
|
3378
|
-
if (currentTemplate.expectations) {
|
|
3379
|
-
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3380
|
-
}
|
|
3381
|
-
return [3 /*break*/, 52];
|
|
3382
|
-
case 48:
|
|
3383
|
-
error_4 = _u.sent();
|
|
3384
|
-
if (!(error_4 instanceof ExpectError)) {
|
|
3385
|
-
throw error_4;
|
|
3386
|
-
}
|
|
3387
|
-
expectError = error_4;
|
|
3388
|
-
return [3 /*break*/, 50];
|
|
3389
|
-
case 49:
|
|
3390
|
-
if (!isJokerAttempt &&
|
|
3391
|
-
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3392
|
-
prompt
|
|
3393
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3394
|
-
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3395
|
-
) {
|
|
3396
|
-
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3397
|
-
executionReport.promptExecutions.push({
|
|
3398
|
-
prompt: __assign({}, prompt),
|
|
3399
|
-
result: result || undefined,
|
|
3400
|
-
error: expectError === null ? undefined : serializeError(expectError),
|
|
3401
|
-
});
|
|
3402
|
-
}
|
|
3403
|
-
return [7 /*endfinally*/];
|
|
3404
|
-
case 50:
|
|
3405
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3406
|
-
throw new PipelineExecutionError(spaceTrim(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 "); }));
|
|
3407
|
-
}
|
|
3408
|
-
_u.label = 51;
|
|
3409
|
-
case 51:
|
|
3410
3442
|
attempt++;
|
|
3411
3443
|
return [3 /*break*/, 4];
|
|
3412
|
-
case
|
|
3444
|
+
case 7:
|
|
3413
3445
|
if (resultString === null) {
|
|
3414
|
-
throw new UnexpectedError(
|
|
3446
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3415
3447
|
}
|
|
3416
3448
|
if (onProgress /* <- [3] */) {
|
|
3417
3449
|
onProgress({
|
|
@@ -3425,7 +3457,7 @@ function createPipelineExecutor(options) {
|
|
|
3425
3457
|
// <- [3]
|
|
3426
3458
|
});
|
|
3427
3459
|
}
|
|
3428
|
-
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (
|
|
3460
|
+
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)));
|
|
3429
3461
|
return [2 /*return*/];
|
|
3430
3462
|
}
|
|
3431
3463
|
});
|
|
@@ -3434,6 +3466,14 @@ function createPipelineExecutor(options) {
|
|
|
3434
3466
|
function filterJustOutputParameters() {
|
|
3435
3467
|
var e_8, _a;
|
|
3436
3468
|
var outputParameters = {};
|
|
3469
|
+
var _loop_6 = function (parameter) {
|
|
3470
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3471
|
+
// [4]
|
|
3472
|
+
warnings.push(new PipelineExecutionError(spaceTrim(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 "); })));
|
|
3473
|
+
return "continue";
|
|
3474
|
+
}
|
|
3475
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3476
|
+
};
|
|
3437
3477
|
try {
|
|
3438
3478
|
// Note: Filter ONLY output parameters
|
|
3439
3479
|
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
@@ -3441,12 +3481,7 @@ function createPipelineExecutor(options) {
|
|
|
3441
3481
|
return isOutput;
|
|
3442
3482
|
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3443
3483
|
var parameter = _c.value;
|
|
3444
|
-
|
|
3445
|
-
// [4]
|
|
3446
|
-
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
|
|
3447
|
-
continue;
|
|
3448
|
-
}
|
|
3449
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3484
|
+
_loop_6(parameter);
|
|
3450
3485
|
}
|
|
3451
3486
|
}
|
|
3452
3487
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
@@ -3518,13 +3553,13 @@ function createPipelineExecutor(options) {
|
|
|
3518
3553
|
return name === parameterName;
|
|
3519
3554
|
});
|
|
3520
3555
|
if (parameter === undefined) {
|
|
3521
|
-
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3556
|
+
warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
3522
3557
|
}
|
|
3523
3558
|
else if (parameter.isInput === false) {
|
|
3524
|
-
return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3559
|
+
return { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
3525
3560
|
isSuccessful: false,
|
|
3526
3561
|
errors: __spreadArray([
|
|
3527
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3562
|
+
new PipelineExecutionError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
3528
3563
|
], __read(errors), false).map(serializeError),
|
|
3529
3564
|
warnings: warnings.map(serializeError),
|
|
3530
3565
|
executionReport: executionReport,
|
|
@@ -3573,7 +3608,7 @@ function createPipelineExecutor(options) {
|
|
|
3573
3608
|
case 0:
|
|
3574
3609
|
if (loopLimit-- < 0) {
|
|
3575
3610
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
3576
|
-
throw new UnexpectedError(
|
|
3611
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3577
3612
|
}
|
|
3578
3613
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3579
3614
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -3583,7 +3618,7 @@ function createPipelineExecutor(options) {
|
|
|
3583
3618
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3584
3619
|
throw new UnexpectedError(
|
|
3585
3620
|
// TODO: [π] DRY
|
|
3586
|
-
spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3621
|
+
spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates_1
|
|
3587
3622
|
.map(function (_a) {
|
|
3588
3623
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3589
3624
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -3663,6 +3698,7 @@ function createPipelineExecutor(options) {
|
|
|
3663
3698
|
return pipelineExecutor;
|
|
3664
3699
|
}
|
|
3665
3700
|
/**
|
|
3701
|
+
* TODO: !!! Identify not only pipeline BUT exact template ${block(pipelineIdentification)}
|
|
3666
3702
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3667
3703
|
* TODO: [π§ ][π³] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
3668
3704
|
* TODO: [πͺ] Use maxParallelCount here (not only pass to `preparePipeline`)
|