@promptbook/cli 0.67.1 β 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 +384 -346
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +0 -2
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/errors/{_ExpectError.d.ts β ExpectError.d.ts} +2 -1
- package/esm/typings/src/errors/index.d.ts +2 -0
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +2 -0
- package/package.json +1 -1
- package/umd/index.umd.js +384 -346
- 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.2';
|
|
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.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"}];
|
|
1038
1038
|
|
|
1039
1039
|
/**
|
|
1040
1040
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2045,6 +2045,25 @@ var CollectionError = /** @class */ (function (_super) {
|
|
|
2045
2045
|
return CollectionError;
|
|
2046
2046
|
}(Error));
|
|
2047
2047
|
|
|
2048
|
+
/**
|
|
2049
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
2050
|
+
*
|
|
2051
|
+
* @public exported from `@promptbook/core`
|
|
2052
|
+
* Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
|
|
2053
|
+
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
2054
|
+
* Note: This is a kindof subtype of PipelineExecutionError
|
|
2055
|
+
*/
|
|
2056
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
2057
|
+
__extends(ExpectError, _super);
|
|
2058
|
+
function ExpectError(message) {
|
|
2059
|
+
var _this = _super.call(this, message) || this;
|
|
2060
|
+
_this.name = 'ExpectError';
|
|
2061
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
2062
|
+
return _this;
|
|
2063
|
+
}
|
|
2064
|
+
return ExpectError;
|
|
2065
|
+
}(Error));
|
|
2066
|
+
|
|
2048
2067
|
/**
|
|
2049
2068
|
* This error type indicates that some limit was reached
|
|
2050
2069
|
*
|
|
@@ -2083,6 +2102,7 @@ var NotYetImplementedError = /** @class */ (function (_super) {
|
|
|
2083
2102
|
* @public exported from `@promptbook/core`
|
|
2084
2103
|
*/
|
|
2085
2104
|
var ERRORS = {
|
|
2105
|
+
ExpectError: ExpectError,
|
|
2086
2106
|
CollectionError: CollectionError,
|
|
2087
2107
|
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
2088
2108
|
LimitReachedError: LimitReachedError,
|
|
@@ -2250,24 +2270,6 @@ function extractParameterNamesFromPromptTemplate(promptTemplate) {
|
|
|
2250
2270
|
* TODO: [π£] If script require contentLanguage
|
|
2251
2271
|
*/
|
|
2252
2272
|
|
|
2253
|
-
/**
|
|
2254
|
-
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
2255
|
-
*
|
|
2256
|
-
* @private error of `checkExpectations` and `createPipelineExecutor`
|
|
2257
|
-
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
2258
|
-
* Note: This is a kindof subtype of PipelineExecutionError
|
|
2259
|
-
*/
|
|
2260
|
-
var ExpectError = /** @class */ (function (_super) {
|
|
2261
|
-
__extends(ExpectError, _super);
|
|
2262
|
-
function ExpectError(message) {
|
|
2263
|
-
var _this = _super.call(this, message) || this;
|
|
2264
|
-
_this.name = 'ExpectError';
|
|
2265
|
-
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
2266
|
-
return _this;
|
|
2267
|
-
}
|
|
2268
|
-
return ExpectError;
|
|
2269
|
-
}(Error));
|
|
2270
|
-
|
|
2271
2273
|
/**
|
|
2272
2274
|
* Serializes an error into a [π] JSON-serializable object
|
|
2273
2275
|
*
|
|
@@ -2960,13 +2962,24 @@ function createPipelineExecutor(options) {
|
|
|
2960
2962
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2961
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;
|
|
2962
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
|
+
})();
|
|
2963
2976
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2964
2977
|
var preparedPipeline;
|
|
2965
2978
|
if (isPipelinePrepared(pipeline)) {
|
|
2966
2979
|
preparedPipeline = pipeline;
|
|
2967
2980
|
}
|
|
2968
2981
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
2969
|
-
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 "); }));
|
|
2970
2983
|
}
|
|
2971
2984
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2972
2985
|
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
@@ -3004,7 +3017,7 @@ function createPipelineExecutor(options) {
|
|
|
3004
3017
|
}
|
|
3005
3018
|
function getReservedParametersForTemplate(template) {
|
|
3006
3019
|
return __awaiter(this, void 0, void 0, function () {
|
|
3007
|
-
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;
|
|
3008
3021
|
var e_3, _a;
|
|
3009
3022
|
return __generator(this, function (_b) {
|
|
3010
3023
|
switch (_b.label) {
|
|
@@ -3027,13 +3040,16 @@ function createPipelineExecutor(options) {
|
|
|
3027
3040
|
currentDate: currentDate,
|
|
3028
3041
|
modelName: modelName,
|
|
3029
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
|
+
};
|
|
3030
3048
|
try {
|
|
3031
3049
|
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3032
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()) {
|
|
3033
3051
|
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3034
|
-
|
|
3035
|
-
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
3036
|
-
}
|
|
3052
|
+
_loop_3(parameterName);
|
|
3037
3053
|
}
|
|
3038
3054
|
}
|
|
3039
3055
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -3050,10 +3066,10 @@ function createPipelineExecutor(options) {
|
|
|
3050
3066
|
}
|
|
3051
3067
|
function executeSingleTemplate(currentTemplate) {
|
|
3052
3068
|
return __awaiter(this, void 0, void 0, function () {
|
|
3053
|
-
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,
|
|
3054
|
-
var
|
|
3055
|
-
return __generator(this, function (
|
|
3056
|
-
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) {
|
|
3057
3073
|
case 0:
|
|
3058
3074
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3059
3075
|
title = currentTemplate.title;
|
|
@@ -3070,47 +3086,48 @@ function createPipelineExecutor(options) {
|
|
|
3070
3086
|
// <- [3]
|
|
3071
3087
|
})];
|
|
3072
3088
|
case 1:
|
|
3073
|
-
|
|
3074
|
-
|
|
3089
|
+
_h.sent();
|
|
3090
|
+
_h.label = 2;
|
|
3075
3091
|
case 2:
|
|
3076
3092
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
3077
3093
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3078
3094
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3079
|
-
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 "); }));
|
|
3080
3096
|
}
|
|
3081
3097
|
_b = (_a = Object).freeze;
|
|
3082
3098
|
_c = [{}];
|
|
3083
3099
|
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
3084
3100
|
case 3:
|
|
3085
|
-
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])]);
|
|
3086
3102
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3087
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
|
+
};
|
|
3088
3118
|
try {
|
|
3089
3119
|
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3090
3120
|
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3091
3121
|
parameterName = _e.value;
|
|
3092
|
-
|
|
3093
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3094
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3095
|
-
}
|
|
3096
|
-
// Situation: Parameter is defined but NOT used
|
|
3097
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
3098
|
-
// Do not pass this parameter to prompt
|
|
3099
|
-
}
|
|
3100
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3101
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3102
|
-
// Houston, we have a problem
|
|
3103
|
-
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3104
|
-
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 ")));
|
|
3105
|
-
}
|
|
3122
|
+
_loop_4(parameterName);
|
|
3106
3123
|
}
|
|
3107
3124
|
}
|
|
3108
|
-
catch (
|
|
3125
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
3109
3126
|
finally {
|
|
3110
3127
|
try {
|
|
3111
|
-
if (_e && !_e.done && (
|
|
3128
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3112
3129
|
}
|
|
3113
|
-
finally { if (
|
|
3130
|
+
finally { if (e_4) throw e_4.error; }
|
|
3114
3131
|
}
|
|
3115
3132
|
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3116
3133
|
Object.freeze(parameters);
|
|
@@ -3122,297 +3139,310 @@ function createPipelineExecutor(options) {
|
|
|
3122
3139
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3123
3140
|
.split('{content}')
|
|
3124
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(pipelineIdentification), "\n "); }));
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
// TODO: [π] Unite object for expecting amount and format
|
|
3395
|
+
if (currentTemplate.expectations) {
|
|
3396
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3397
|
+
}
|
|
3398
|
+
return [2 /*return*/, "break-attempts"];
|
|
3399
|
+
case 44:
|
|
3400
|
+
error_4 = _v.sent();
|
|
3401
|
+
if (!(error_4 instanceof ExpectError)) {
|
|
3402
|
+
throw error_4;
|
|
3403
|
+
}
|
|
3404
|
+
expectError = error_4;
|
|
3405
|
+
return [3 /*break*/, 46];
|
|
3406
|
+
case 45:
|
|
3407
|
+
if (!isJokerAttempt &&
|
|
3408
|
+
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3409
|
+
prompt
|
|
3410
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3411
|
+
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3412
|
+
) {
|
|
3413
|
+
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3414
|
+
executionReport.promptExecutions.push({
|
|
3415
|
+
prompt: __assign({}, prompt),
|
|
3416
|
+
result: result || undefined,
|
|
3417
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3418
|
+
});
|
|
3419
|
+
}
|
|
3420
|
+
return [7 /*endfinally*/];
|
|
3421
|
+
case 46:
|
|
3422
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3423
|
+
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 "); }));
|
|
3424
|
+
}
|
|
3425
|
+
return [2 /*return*/];
|
|
3426
|
+
}
|
|
3427
|
+
});
|
|
3428
|
+
};
|
|
3125
3429
|
attempt = -jokerParameterNames.length;
|
|
3126
|
-
|
|
3430
|
+
_h.label = 4;
|
|
3127
3431
|
case 4:
|
|
3128
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
3129
|
-
|
|
3130
|
-
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3131
|
-
if (isJokerAttempt && !jokerParameterName) {
|
|
3132
|
-
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
3133
|
-
}
|
|
3134
|
-
result = null;
|
|
3135
|
-
resultString = null;
|
|
3136
|
-
expectError = null;
|
|
3137
|
-
if (isJokerAttempt) {
|
|
3138
|
-
if (parameters[jokerParameterName] === undefined) {
|
|
3139
|
-
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
3140
|
-
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3141
|
-
}
|
|
3142
|
-
else {
|
|
3143
|
-
resultString = parameters[jokerParameterName];
|
|
3144
|
-
}
|
|
3145
|
-
}
|
|
3146
|
-
_u.label = 5;
|
|
3432
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 7];
|
|
3433
|
+
return [5 /*yield**/, _loop_5(attempt)];
|
|
3147
3434
|
case 5:
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
switch (_f) {
|
|
3152
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
3153
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
3154
|
-
case 'SCRIPT': return [3 /*break*/, 16];
|
|
3155
|
-
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
3435
|
+
state_2 = _h.sent();
|
|
3436
|
+
switch (state_2) {
|
|
3437
|
+
case "break-attempts": return [3 /*break*/, 7];
|
|
3156
3438
|
}
|
|
3157
|
-
|
|
3439
|
+
_h.label = 6;
|
|
3158
3440
|
case 6:
|
|
3159
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3160
|
-
return [3 /*break*/, 30];
|
|
3161
|
-
case 7:
|
|
3162
|
-
prompt = {
|
|
3163
|
-
title: currentTemplate.title,
|
|
3164
|
-
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3165
|
-
? preparedPipeline.pipelineUrl
|
|
3166
|
-
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3167
|
-
parameters: parameters,
|
|
3168
|
-
content: preparedContent,
|
|
3169
|
-
modelRequirements: currentTemplate.modelRequirements,
|
|
3170
|
-
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3171
|
-
var name = _a.name;
|
|
3172
|
-
return name === currentTemplate.personaName;
|
|
3173
|
-
}) || {})), currentTemplate.expectations),
|
|
3174
|
-
expectFormat: currentTemplate.expectFormat,
|
|
3175
|
-
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3176
|
-
}; // <- TODO: Not very good type guard
|
|
3177
|
-
_g = currentTemplate.modelRequirements.modelVariant;
|
|
3178
|
-
switch (_g) {
|
|
3179
|
-
case 'CHAT': return [3 /*break*/, 8];
|
|
3180
|
-
case 'COMPLETION': return [3 /*break*/, 10];
|
|
3181
|
-
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
3182
|
-
}
|
|
3183
|
-
return [3 /*break*/, 14];
|
|
3184
|
-
case 8: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3185
|
-
case 9:
|
|
3186
|
-
chatResult = _u.sent();
|
|
3187
|
-
// TODO: [π¬] Destroy chatThread
|
|
3188
|
-
result = chatResult;
|
|
3189
|
-
resultString = chatResult.content;
|
|
3190
|
-
return [3 /*break*/, 15];
|
|
3191
|
-
case 10: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3192
|
-
case 11:
|
|
3193
|
-
completionResult = _u.sent();
|
|
3194
|
-
result = completionResult;
|
|
3195
|
-
resultString = completionResult.content;
|
|
3196
|
-
return [3 /*break*/, 15];
|
|
3197
|
-
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3198
|
-
case 13:
|
|
3199
|
-
embeddingResult = _u.sent();
|
|
3200
|
-
result = embeddingResult;
|
|
3201
|
-
resultString = embeddingResult.content.join(',');
|
|
3202
|
-
return [3 /*break*/, 15];
|
|
3203
|
-
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
3204
|
-
case 15: return [3 /*break*/, 30];
|
|
3205
|
-
case 16:
|
|
3206
|
-
if (arrayableToArray(tools.script).length === 0) {
|
|
3207
|
-
throw new PipelineExecutionError('No script execution tools are available');
|
|
3208
|
-
}
|
|
3209
|
-
if (!currentTemplate.contentLanguage) {
|
|
3210
|
-
throw new PipelineExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
3211
|
-
}
|
|
3212
|
-
// TODO: DRY [1]
|
|
3213
|
-
scriptPipelineExecutionErrors = [];
|
|
3214
|
-
_u.label = 17;
|
|
3215
|
-
case 17:
|
|
3216
|
-
_u.trys.push([17, 24, 25, 26]);
|
|
3217
|
-
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
3218
|
-
_u.label = 18;
|
|
3219
|
-
case 18:
|
|
3220
|
-
if (!!_j.done) return [3 /*break*/, 23];
|
|
3221
|
-
scriptTools = _j.value;
|
|
3222
|
-
_u.label = 19;
|
|
3223
|
-
case 19:
|
|
3224
|
-
_u.trys.push([19, 21, , 22]);
|
|
3225
|
-
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3226
|
-
scriptLanguage: currentTemplate.contentLanguage,
|
|
3227
|
-
script: preparedContent,
|
|
3228
|
-
parameters: parameters,
|
|
3229
|
-
}))];
|
|
3230
|
-
case 20:
|
|
3231
|
-
resultString = _u.sent();
|
|
3232
|
-
return [3 /*break*/, 23];
|
|
3233
|
-
case 21:
|
|
3234
|
-
error_2 = _u.sent();
|
|
3235
|
-
if (!(error_2 instanceof Error)) {
|
|
3236
|
-
throw error_2;
|
|
3237
|
-
}
|
|
3238
|
-
if (error_2 instanceof UnexpectedError) {
|
|
3239
|
-
throw error_2;
|
|
3240
|
-
}
|
|
3241
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3242
|
-
return [3 /*break*/, 22];
|
|
3243
|
-
case 22:
|
|
3244
|
-
_j = _h.next();
|
|
3245
|
-
return [3 /*break*/, 18];
|
|
3246
|
-
case 23: return [3 /*break*/, 26];
|
|
3247
|
-
case 24:
|
|
3248
|
-
e_4_1 = _u.sent();
|
|
3249
|
-
e_4 = { error: e_4_1 };
|
|
3250
|
-
return [3 /*break*/, 26];
|
|
3251
|
-
case 25:
|
|
3252
|
-
try {
|
|
3253
|
-
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
3254
|
-
}
|
|
3255
|
-
finally { if (e_4) throw e_4.error; }
|
|
3256
|
-
return [7 /*endfinally*/];
|
|
3257
|
-
case 26:
|
|
3258
|
-
if (resultString !== null) {
|
|
3259
|
-
return [3 /*break*/, 30];
|
|
3260
|
-
}
|
|
3261
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3262
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3263
|
-
}
|
|
3264
|
-
else {
|
|
3265
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3266
|
-
.map(function (error) { return '- ' + error.message; })
|
|
3267
|
-
.join('\n\n')), "\n "); }));
|
|
3268
|
-
}
|
|
3269
|
-
case 27:
|
|
3270
|
-
if (tools.userInterface === undefined) {
|
|
3271
|
-
throw new PipelineExecutionError('User interface tools are not available');
|
|
3272
|
-
}
|
|
3273
|
-
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3274
|
-
promptTitle: currentTemplate.title,
|
|
3275
|
-
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3276
|
-
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3277
|
-
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3278
|
-
placeholder: undefined,
|
|
3279
|
-
priority: priority,
|
|
3280
|
-
}))];
|
|
3281
|
-
case 28:
|
|
3282
|
-
// TODO: [πΉ] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
3283
|
-
resultString = _u.sent();
|
|
3284
|
-
return [3 /*break*/, 30];
|
|
3285
|
-
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
3286
|
-
case 30:
|
|
3287
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
3288
|
-
_u.label = 31;
|
|
3289
|
-
case 31:
|
|
3290
|
-
_u.trys.push([31, 45, 46, 47]);
|
|
3291
|
-
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
3292
|
-
_u.label = 32;
|
|
3293
|
-
case 32:
|
|
3294
|
-
if (!!_l.done) return [3 /*break*/, 44];
|
|
3295
|
-
functionName = _l.value;
|
|
3296
|
-
// TODO: DRY [1]
|
|
3297
|
-
scriptPipelineExecutionErrors = [];
|
|
3298
|
-
postprocessingError = null;
|
|
3299
|
-
_u.label = 33;
|
|
3300
|
-
case 33:
|
|
3301
|
-
_u.trys.push([33, 40, 41, 42]);
|
|
3302
|
-
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
3303
|
-
_u.label = 34;
|
|
3304
|
-
case 34:
|
|
3305
|
-
if (!!_o.done) return [3 /*break*/, 39];
|
|
3306
|
-
scriptTools = _o.value;
|
|
3307
|
-
_u.label = 35;
|
|
3308
|
-
case 35:
|
|
3309
|
-
_u.trys.push([35, 37, , 38]);
|
|
3310
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
3311
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3312
|
-
script: "".concat(functionName, "(resultString)"),
|
|
3313
|
-
parameters: {
|
|
3314
|
-
resultString: resultString || '',
|
|
3315
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
3316
|
-
},
|
|
3317
|
-
})];
|
|
3318
|
-
case 36:
|
|
3319
|
-
resultString = _u.sent();
|
|
3320
|
-
postprocessingError = null;
|
|
3321
|
-
return [3 /*break*/, 39];
|
|
3322
|
-
case 37:
|
|
3323
|
-
error_3 = _u.sent();
|
|
3324
|
-
if (!(error_3 instanceof Error)) {
|
|
3325
|
-
throw error_3;
|
|
3326
|
-
}
|
|
3327
|
-
if (error_3 instanceof UnexpectedError) {
|
|
3328
|
-
throw error_3;
|
|
3329
|
-
}
|
|
3330
|
-
postprocessingError = error_3;
|
|
3331
|
-
scriptPipelineExecutionErrors.push(error_3);
|
|
3332
|
-
return [3 /*break*/, 38];
|
|
3333
|
-
case 38:
|
|
3334
|
-
_o = _m.next();
|
|
3335
|
-
return [3 /*break*/, 34];
|
|
3336
|
-
case 39: return [3 /*break*/, 42];
|
|
3337
|
-
case 40:
|
|
3338
|
-
e_5_1 = _u.sent();
|
|
3339
|
-
e_5 = { error: e_5_1 };
|
|
3340
|
-
return [3 /*break*/, 42];
|
|
3341
|
-
case 41:
|
|
3342
|
-
try {
|
|
3343
|
-
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
3344
|
-
}
|
|
3345
|
-
finally { if (e_5) throw e_5.error; }
|
|
3346
|
-
return [7 /*endfinally*/];
|
|
3347
|
-
case 42:
|
|
3348
|
-
if (postprocessingError) {
|
|
3349
|
-
throw postprocessingError;
|
|
3350
|
-
}
|
|
3351
|
-
_u.label = 43;
|
|
3352
|
-
case 43:
|
|
3353
|
-
_l = _k.next();
|
|
3354
|
-
return [3 /*break*/, 32];
|
|
3355
|
-
case 44: return [3 /*break*/, 47];
|
|
3356
|
-
case 45:
|
|
3357
|
-
e_6_1 = _u.sent();
|
|
3358
|
-
e_6 = { error: e_6_1 };
|
|
3359
|
-
return [3 /*break*/, 47];
|
|
3360
|
-
case 46:
|
|
3361
|
-
try {
|
|
3362
|
-
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
3363
|
-
}
|
|
3364
|
-
finally { if (e_6) throw e_6.error; }
|
|
3365
|
-
return [7 /*endfinally*/];
|
|
3366
|
-
case 47:
|
|
3367
|
-
// TODO: [π] Unite object for expecting amount and format
|
|
3368
|
-
if (currentTemplate.expectFormat) {
|
|
3369
|
-
if (currentTemplate.expectFormat === 'JSON') {
|
|
3370
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3371
|
-
throw new ExpectError('Expected valid JSON string');
|
|
3372
|
-
}
|
|
3373
|
-
}
|
|
3374
|
-
}
|
|
3375
|
-
// TODO: [π] Unite object for expecting amount and format
|
|
3376
|
-
if (currentTemplate.expectations) {
|
|
3377
|
-
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3378
|
-
}
|
|
3379
|
-
return [3 /*break*/, 52];
|
|
3380
|
-
case 48:
|
|
3381
|
-
error_4 = _u.sent();
|
|
3382
|
-
if (!(error_4 instanceof ExpectError)) {
|
|
3383
|
-
throw error_4;
|
|
3384
|
-
}
|
|
3385
|
-
if (error_4 instanceof UnexpectedError) {
|
|
3386
|
-
throw error_4;
|
|
3387
|
-
}
|
|
3388
|
-
expectError = error_4;
|
|
3389
|
-
return [3 /*break*/, 50];
|
|
3390
|
-
case 49:
|
|
3391
|
-
if (!isJokerAttempt &&
|
|
3392
|
-
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3393
|
-
prompt
|
|
3394
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3395
|
-
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3396
|
-
) {
|
|
3397
|
-
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3398
|
-
executionReport.promptExecutions.push({
|
|
3399
|
-
prompt: __assign({}, prompt),
|
|
3400
|
-
result: result || undefined,
|
|
3401
|
-
error: expectError === null ? undefined : serializeError(expectError),
|
|
3402
|
-
});
|
|
3403
|
-
}
|
|
3404
|
-
return [7 /*endfinally*/];
|
|
3405
|
-
case 50:
|
|
3406
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3407
|
-
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 "); }));
|
|
3408
|
-
}
|
|
3409
|
-
_u.label = 51;
|
|
3410
|
-
case 51:
|
|
3411
3441
|
attempt++;
|
|
3412
3442
|
return [3 /*break*/, 4];
|
|
3413
|
-
case
|
|
3443
|
+
case 7:
|
|
3414
3444
|
if (resultString === null) {
|
|
3415
|
-
throw new UnexpectedError(
|
|
3445
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3416
3446
|
}
|
|
3417
3447
|
if (onProgress /* <- [3] */) {
|
|
3418
3448
|
onProgress({
|
|
@@ -3426,7 +3456,7 @@ function createPipelineExecutor(options) {
|
|
|
3426
3456
|
// <- [3]
|
|
3427
3457
|
});
|
|
3428
3458
|
}
|
|
3429
|
-
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (
|
|
3459
|
+
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)));
|
|
3430
3460
|
return [2 /*return*/];
|
|
3431
3461
|
}
|
|
3432
3462
|
});
|
|
@@ -3435,6 +3465,14 @@ function createPipelineExecutor(options) {
|
|
|
3435
3465
|
function filterJustOutputParameters() {
|
|
3436
3466
|
var e_8, _a;
|
|
3437
3467
|
var outputParameters = {};
|
|
3468
|
+
var _loop_6 = function (parameter) {
|
|
3469
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3470
|
+
// [4]
|
|
3471
|
+
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 "); })));
|
|
3472
|
+
return "continue";
|
|
3473
|
+
}
|
|
3474
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3475
|
+
};
|
|
3438
3476
|
try {
|
|
3439
3477
|
// Note: Filter ONLY output parameters
|
|
3440
3478
|
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
@@ -3442,12 +3480,7 @@ function createPipelineExecutor(options) {
|
|
|
3442
3480
|
return isOutput;
|
|
3443
3481
|
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3444
3482
|
var parameter = _c.value;
|
|
3445
|
-
|
|
3446
|
-
// [4]
|
|
3447
|
-
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
|
|
3448
|
-
continue;
|
|
3449
|
-
}
|
|
3450
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3483
|
+
_loop_6(parameter);
|
|
3451
3484
|
}
|
|
3452
3485
|
}
|
|
3453
3486
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
@@ -3519,13 +3552,13 @@ function createPipelineExecutor(options) {
|
|
|
3519
3552
|
return name === parameterName;
|
|
3520
3553
|
});
|
|
3521
3554
|
if (parameter === undefined) {
|
|
3522
|
-
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3555
|
+
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 "); })));
|
|
3523
3556
|
}
|
|
3524
3557
|
else if (parameter.isInput === false) {
|
|
3525
|
-
return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3558
|
+
return { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
3526
3559
|
isSuccessful: false,
|
|
3527
3560
|
errors: __spreadArray([
|
|
3528
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3561
|
+
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 "); }))
|
|
3529
3562
|
], __read(errors), false).map(serializeError),
|
|
3530
3563
|
warnings: warnings.map(serializeError),
|
|
3531
3564
|
executionReport: executionReport,
|
|
@@ -3574,7 +3607,7 @@ function createPipelineExecutor(options) {
|
|
|
3574
3607
|
case 0:
|
|
3575
3608
|
if (loopLimit-- < 0) {
|
|
3576
3609
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
3577
|
-
throw new UnexpectedError(
|
|
3610
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3578
3611
|
}
|
|
3579
3612
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3580
3613
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -3584,7 +3617,7 @@ function createPipelineExecutor(options) {
|
|
|
3584
3617
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3585
3618
|
throw new UnexpectedError(
|
|
3586
3619
|
// TODO: [π] DRY
|
|
3587
|
-
spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3620
|
+
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
|
|
3588
3621
|
.map(function (_a) {
|
|
3589
3622
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3590
3623
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -3664,6 +3697,7 @@ function createPipelineExecutor(options) {
|
|
|
3664
3697
|
return pipelineExecutor;
|
|
3665
3698
|
}
|
|
3666
3699
|
/**
|
|
3700
|
+
* TODO: !!! Identify not only pipeline BUT exact template ${block(pipelineIdentification)}
|
|
3667
3701
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3668
3702
|
* TODO: [π§ ][π³] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
3669
3703
|
* TODO: [πͺ] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
@@ -4203,6 +4237,8 @@ function preparePipeline(pipeline, options) {
|
|
|
4203
4237
|
* TODO: [π] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
4204
4238
|
* TODO: [π§] In future one preparation can take data from previous preparation and save tokens and time
|
|
4205
4239
|
* TODO: [π ] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4240
|
+
* TODO: [π§ ][β] Maybe if expecting JSON (In Anthropic Claude and other models without non-json) and its not specified in prompt content, append the instructions
|
|
4241
|
+
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
4206
4242
|
*/
|
|
4207
4243
|
|
|
4208
4244
|
/**
|
|
@@ -8332,6 +8368,8 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
8332
8368
|
{
|
|
8333
8369
|
role: 'user',
|
|
8334
8370
|
content: rawPromptContent,
|
|
8371
|
+
// <- TODO: [π§ ][β] Maybe if expecting JSON and its not specified in prompt content, append the instructions
|
|
8372
|
+
// @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
8335
8373
|
},
|
|
8336
8374
|
],
|
|
8337
8375
|
// TODO: Is here some equivalent of user identification?> user: this.options.user,
|
|
@@ -8470,7 +8508,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
8470
8508
|
* Default model for chat variant.
|
|
8471
8509
|
*/
|
|
8472
8510
|
AnthropicClaudeExecutionTools.prototype.getDefaultChatModel = function () {
|
|
8473
|
-
return this.getDefaultModel('claude-3-
|
|
8511
|
+
return this.getDefaultModel('claude-3-5-sonnet');
|
|
8474
8512
|
};
|
|
8475
8513
|
return AnthropicClaudeExecutionTools;
|
|
8476
8514
|
}());
|