@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/umd/index.umd.js
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
/**
|
|
40
40
|
* The version of the Promptbook library
|
|
41
41
|
*/
|
|
42
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
42
|
+
var PROMPTBOOK_VERSION = '0.67.2';
|
|
43
43
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
44
44
|
|
|
45
45
|
/*! *****************************************************************************
|
|
@@ -1053,7 +1053,7 @@
|
|
|
1053
1053
|
});
|
|
1054
1054
|
}
|
|
1055
1055
|
|
|
1056
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
1056
|
+
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"}];
|
|
1057
1057
|
|
|
1058
1058
|
/**
|
|
1059
1059
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2064,6 +2064,25 @@
|
|
|
2064
2064
|
return CollectionError;
|
|
2065
2065
|
}(Error));
|
|
2066
2066
|
|
|
2067
|
+
/**
|
|
2068
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
2069
|
+
*
|
|
2070
|
+
* @public exported from `@promptbook/core`
|
|
2071
|
+
* Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
|
|
2072
|
+
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
2073
|
+
* Note: This is a kindof subtype of PipelineExecutionError
|
|
2074
|
+
*/
|
|
2075
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
2076
|
+
__extends(ExpectError, _super);
|
|
2077
|
+
function ExpectError(message) {
|
|
2078
|
+
var _this = _super.call(this, message) || this;
|
|
2079
|
+
_this.name = 'ExpectError';
|
|
2080
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
2081
|
+
return _this;
|
|
2082
|
+
}
|
|
2083
|
+
return ExpectError;
|
|
2084
|
+
}(Error));
|
|
2085
|
+
|
|
2067
2086
|
/**
|
|
2068
2087
|
* This error type indicates that some limit was reached
|
|
2069
2088
|
*
|
|
@@ -2102,6 +2121,7 @@
|
|
|
2102
2121
|
* @public exported from `@promptbook/core`
|
|
2103
2122
|
*/
|
|
2104
2123
|
var ERRORS = {
|
|
2124
|
+
ExpectError: ExpectError,
|
|
2105
2125
|
CollectionError: CollectionError,
|
|
2106
2126
|
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
2107
2127
|
LimitReachedError: LimitReachedError,
|
|
@@ -2269,24 +2289,6 @@
|
|
|
2269
2289
|
* TODO: [π£] If script require contentLanguage
|
|
2270
2290
|
*/
|
|
2271
2291
|
|
|
2272
|
-
/**
|
|
2273
|
-
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
2274
|
-
*
|
|
2275
|
-
* @private error of `checkExpectations` and `createPipelineExecutor`
|
|
2276
|
-
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
2277
|
-
* Note: This is a kindof subtype of PipelineExecutionError
|
|
2278
|
-
*/
|
|
2279
|
-
var ExpectError = /** @class */ (function (_super) {
|
|
2280
|
-
__extends(ExpectError, _super);
|
|
2281
|
-
function ExpectError(message) {
|
|
2282
|
-
var _this = _super.call(this, message) || this;
|
|
2283
|
-
_this.name = 'ExpectError';
|
|
2284
|
-
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
2285
|
-
return _this;
|
|
2286
|
-
}
|
|
2287
|
-
return ExpectError;
|
|
2288
|
-
}(Error));
|
|
2289
|
-
|
|
2290
2292
|
/**
|
|
2291
2293
|
* Serializes an error into a [π] JSON-serializable object
|
|
2292
2294
|
*
|
|
@@ -2979,13 +2981,24 @@
|
|
|
2979
2981
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2980
2982
|
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;
|
|
2981
2983
|
validatePipeline(pipeline);
|
|
2984
|
+
var pipelineIdentification = (function () {
|
|
2985
|
+
// Note: This is a π implementation of [π]
|
|
2986
|
+
var _ = [];
|
|
2987
|
+
if (pipeline.sourceFile !== undefined) {
|
|
2988
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
2989
|
+
}
|
|
2990
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
2991
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
2992
|
+
}
|
|
2993
|
+
return _.join('\n');
|
|
2994
|
+
})();
|
|
2982
2995
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2983
2996
|
var preparedPipeline;
|
|
2984
2997
|
if (isPipelinePrepared(pipeline)) {
|
|
2985
2998
|
preparedPipeline = pipeline;
|
|
2986
2999
|
}
|
|
2987
3000
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
2988
|
-
console.warn(spaceTrim.spaceTrim(
|
|
3001
|
+
console.warn(spaceTrim.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 "); }));
|
|
2989
3002
|
}
|
|
2990
3003
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2991
3004
|
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
@@ -3023,7 +3036,7 @@
|
|
|
3023
3036
|
}
|
|
3024
3037
|
function getReservedParametersForTemplate(template) {
|
|
3025
3038
|
return __awaiter(this, void 0, void 0, function () {
|
|
3026
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3039
|
+
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_3, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3027
3040
|
var e_3, _a;
|
|
3028
3041
|
return __generator(this, function (_b) {
|
|
3029
3042
|
switch (_b.label) {
|
|
@@ -3046,13 +3059,16 @@
|
|
|
3046
3059
|
currentDate: currentDate,
|
|
3047
3060
|
modelName: modelName,
|
|
3048
3061
|
};
|
|
3062
|
+
_loop_3 = function (parameterName) {
|
|
3063
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
3064
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3065
|
+
}
|
|
3066
|
+
};
|
|
3049
3067
|
try {
|
|
3050
3068
|
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3051
3069
|
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()) {
|
|
3052
3070
|
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3053
|
-
|
|
3054
|
-
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
3055
|
-
}
|
|
3071
|
+
_loop_3(parameterName);
|
|
3056
3072
|
}
|
|
3057
3073
|
}
|
|
3058
3074
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -3069,10 +3085,10 @@
|
|
|
3069
3085
|
}
|
|
3070
3086
|
function executeSingleTemplate(currentTemplate) {
|
|
3071
3087
|
return __awaiter(this, void 0, void 0, function () {
|
|
3072
|
-
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,
|
|
3073
|
-
var
|
|
3074
|
-
return __generator(this, function (
|
|
3075
|
-
switch (
|
|
3088
|
+
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;
|
|
3089
|
+
var e_4, _f, _g;
|
|
3090
|
+
return __generator(this, function (_h) {
|
|
3091
|
+
switch (_h.label) {
|
|
3076
3092
|
case 0:
|
|
3077
3093
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3078
3094
|
title = currentTemplate.title;
|
|
@@ -3089,47 +3105,48 @@
|
|
|
3089
3105
|
// <- [3]
|
|
3090
3106
|
})];
|
|
3091
3107
|
case 1:
|
|
3092
|
-
|
|
3093
|
-
|
|
3108
|
+
_h.sent();
|
|
3109
|
+
_h.label = 2;
|
|
3094
3110
|
case 2:
|
|
3095
3111
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
3096
3112
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3097
3113
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3098
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
3114
|
+
throw new UnexpectedError(spaceTrim.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 "); }));
|
|
3099
3115
|
}
|
|
3100
3116
|
_b = (_a = Object).freeze;
|
|
3101
3117
|
_c = [{}];
|
|
3102
3118
|
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
3103
3119
|
case 3:
|
|
3104
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(
|
|
3120
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3105
3121
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3106
3122
|
parameters = {};
|
|
3123
|
+
_loop_4 = function (parameterName) {
|
|
3124
|
+
// Situation: Parameter is defined and used
|
|
3125
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3126
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
3127
|
+
}
|
|
3128
|
+
// Situation: Parameter is defined but NOT used
|
|
3129
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3130
|
+
// Situation: Parameter is NOT defined BUT used
|
|
3131
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3132
|
+
// Houston, we have a problem
|
|
3133
|
+
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3134
|
+
throw new UnexpectedError(spaceTrim.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 "); }));
|
|
3135
|
+
}
|
|
3136
|
+
};
|
|
3107
3137
|
try {
|
|
3108
3138
|
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3109
3139
|
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3110
3140
|
parameterName = _e.value;
|
|
3111
|
-
|
|
3112
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3113
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3114
|
-
}
|
|
3115
|
-
// Situation: Parameter is defined but NOT used
|
|
3116
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
3117
|
-
// Do not pass this parameter to prompt
|
|
3118
|
-
}
|
|
3119
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3120
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3121
|
-
// Houston, we have a problem
|
|
3122
|
-
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3123
|
-
throw new UnexpectedError(spaceTrim.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 ")));
|
|
3124
|
-
}
|
|
3141
|
+
_loop_4(parameterName);
|
|
3125
3142
|
}
|
|
3126
3143
|
}
|
|
3127
|
-
catch (
|
|
3144
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
3128
3145
|
finally {
|
|
3129
3146
|
try {
|
|
3130
|
-
if (_e && !_e.done && (
|
|
3147
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3131
3148
|
}
|
|
3132
|
-
finally { if (
|
|
3149
|
+
finally { if (e_4) throw e_4.error; }
|
|
3133
3150
|
}
|
|
3134
3151
|
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3135
3152
|
Object.freeze(parameters);
|
|
@@ -3141,297 +3158,310 @@
|
|
|
3141
3158
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3142
3159
|
.split('{content}')
|
|
3143
3160
|
.join(currentTemplate.content);
|
|
3161
|
+
_loop_5 = function (attempt) {
|
|
3162
|
+
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;
|
|
3163
|
+
var e_5, _s, e_7, _t, e_6, _u;
|
|
3164
|
+
return __generator(this, function (_v) {
|
|
3165
|
+
switch (_v.label) {
|
|
3166
|
+
case 0:
|
|
3167
|
+
isJokerAttempt = attempt < 0;
|
|
3168
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3169
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
3170
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3171
|
+
}
|
|
3172
|
+
result = null;
|
|
3173
|
+
resultString = null;
|
|
3174
|
+
expectError = null;
|
|
3175
|
+
if (isJokerAttempt) {
|
|
3176
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
3177
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3178
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3179
|
+
}
|
|
3180
|
+
else {
|
|
3181
|
+
resultString = parameters[jokerParameterName];
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
_v.label = 1;
|
|
3185
|
+
case 1:
|
|
3186
|
+
_v.trys.push([1, 44, 45, 46]);
|
|
3187
|
+
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3188
|
+
_j = currentTemplate.blockType;
|
|
3189
|
+
switch (_j) {
|
|
3190
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3191
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3192
|
+
case 'SCRIPT': return [3 /*break*/, 12];
|
|
3193
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 23];
|
|
3194
|
+
}
|
|
3195
|
+
return [3 /*break*/, 25];
|
|
3196
|
+
case 2:
|
|
3197
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
3198
|
+
return [3 /*break*/, 26];
|
|
3199
|
+
case 3:
|
|
3200
|
+
prompt = {
|
|
3201
|
+
title: currentTemplate.title,
|
|
3202
|
+
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3203
|
+
? preparedPipeline.pipelineUrl
|
|
3204
|
+
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3205
|
+
parameters: parameters,
|
|
3206
|
+
content: preparedContent,
|
|
3207
|
+
modelRequirements: currentTemplate.modelRequirements,
|
|
3208
|
+
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3209
|
+
var name = _a.name;
|
|
3210
|
+
return name === currentTemplate.personaName;
|
|
3211
|
+
}) || {})), currentTemplate.expectations),
|
|
3212
|
+
expectFormat: currentTemplate.expectFormat,
|
|
3213
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3214
|
+
}; // <- TODO: Not very good type guard
|
|
3215
|
+
_k = currentTemplate.modelRequirements.modelVariant;
|
|
3216
|
+
switch (_k) {
|
|
3217
|
+
case 'CHAT': return [3 /*break*/, 4];
|
|
3218
|
+
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3219
|
+
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3220
|
+
}
|
|
3221
|
+
return [3 /*break*/, 10];
|
|
3222
|
+
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3223
|
+
case 5:
|
|
3224
|
+
chatResult = _v.sent();
|
|
3225
|
+
// TODO: [π¬] Destroy chatThread
|
|
3226
|
+
result = chatResult;
|
|
3227
|
+
resultString = chatResult.content;
|
|
3228
|
+
return [3 /*break*/, 11];
|
|
3229
|
+
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3230
|
+
case 7:
|
|
3231
|
+
completionResult = _v.sent();
|
|
3232
|
+
result = completionResult;
|
|
3233
|
+
resultString = completionResult.content;
|
|
3234
|
+
return [3 /*break*/, 11];
|
|
3235
|
+
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3236
|
+
case 9:
|
|
3237
|
+
embeddingResult = _v.sent();
|
|
3238
|
+
result = embeddingResult;
|
|
3239
|
+
resultString = embeddingResult.content.join(',');
|
|
3240
|
+
return [3 /*break*/, 11];
|
|
3241
|
+
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n\n "); }));
|
|
3242
|
+
case 11: return [3 /*break*/, 26];
|
|
3243
|
+
case 12:
|
|
3244
|
+
if (arrayableToArray(tools.script).length === 0) {
|
|
3245
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3246
|
+
}
|
|
3247
|
+
if (!currentTemplate.contentLanguage) {
|
|
3248
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for prompt template \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3249
|
+
}
|
|
3250
|
+
// TODO: DRY [1]
|
|
3251
|
+
scriptPipelineExecutionErrors = [];
|
|
3252
|
+
_v.label = 13;
|
|
3253
|
+
case 13:
|
|
3254
|
+
_v.trys.push([13, 20, 21, 22]);
|
|
3255
|
+
_l = (e_5 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3256
|
+
_v.label = 14;
|
|
3257
|
+
case 14:
|
|
3258
|
+
if (!!_m.done) return [3 /*break*/, 19];
|
|
3259
|
+
scriptTools = _m.value;
|
|
3260
|
+
_v.label = 15;
|
|
3261
|
+
case 15:
|
|
3262
|
+
_v.trys.push([15, 17, , 18]);
|
|
3263
|
+
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3264
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
3265
|
+
script: preparedContent,
|
|
3266
|
+
parameters: parameters,
|
|
3267
|
+
}))];
|
|
3268
|
+
case 16:
|
|
3269
|
+
resultString = _v.sent();
|
|
3270
|
+
return [3 /*break*/, 19];
|
|
3271
|
+
case 17:
|
|
3272
|
+
error_2 = _v.sent();
|
|
3273
|
+
if (!(error_2 instanceof Error)) {
|
|
3274
|
+
throw error_2;
|
|
3275
|
+
}
|
|
3276
|
+
if (error_2 instanceof UnexpectedError) {
|
|
3277
|
+
throw error_2;
|
|
3278
|
+
}
|
|
3279
|
+
scriptPipelineExecutionErrors.push(error_2);
|
|
3280
|
+
return [3 /*break*/, 18];
|
|
3281
|
+
case 18:
|
|
3282
|
+
_m = _l.next();
|
|
3283
|
+
return [3 /*break*/, 14];
|
|
3284
|
+
case 19: return [3 /*break*/, 22];
|
|
3285
|
+
case 20:
|
|
3286
|
+
e_5_1 = _v.sent();
|
|
3287
|
+
e_5 = { error: e_5_1 };
|
|
3288
|
+
return [3 /*break*/, 22];
|
|
3289
|
+
case 21:
|
|
3290
|
+
try {
|
|
3291
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3292
|
+
}
|
|
3293
|
+
finally { if (e_5) throw e_5.error; }
|
|
3294
|
+
return [7 /*endfinally*/];
|
|
3295
|
+
case 22:
|
|
3296
|
+
if (resultString !== null) {
|
|
3297
|
+
return [3 /*break*/, 26];
|
|
3298
|
+
}
|
|
3299
|
+
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3300
|
+
throw scriptPipelineExecutionErrors[0];
|
|
3301
|
+
}
|
|
3302
|
+
else {
|
|
3303
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3304
|
+
.map(function (error) { return '- ' + error.message; })
|
|
3305
|
+
.join('\n\n')), "\n "); }));
|
|
3306
|
+
}
|
|
3307
|
+
case 23:
|
|
3308
|
+
if (tools.userInterface === undefined) {
|
|
3309
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3310
|
+
}
|
|
3311
|
+
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3312
|
+
promptTitle: currentTemplate.title,
|
|
3313
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3314
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3315
|
+
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3316
|
+
placeholder: undefined,
|
|
3317
|
+
priority: priority,
|
|
3318
|
+
}))];
|
|
3319
|
+
case 24:
|
|
3320
|
+
// TODO: [πΉ] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
3321
|
+
resultString = _v.sent();
|
|
3322
|
+
return [3 /*break*/, 26];
|
|
3323
|
+
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.blockType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3324
|
+
case 26:
|
|
3325
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3326
|
+
_v.label = 27;
|
|
3327
|
+
case 27:
|
|
3328
|
+
_v.trys.push([27, 41, 42, 43]);
|
|
3329
|
+
_o = (e_7 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3330
|
+
_v.label = 28;
|
|
3331
|
+
case 28:
|
|
3332
|
+
if (!!_p.done) return [3 /*break*/, 40];
|
|
3333
|
+
functionName = _p.value;
|
|
3334
|
+
// TODO: DRY [1]
|
|
3335
|
+
scriptPipelineExecutionErrors = [];
|
|
3336
|
+
postprocessingError = null;
|
|
3337
|
+
_v.label = 29;
|
|
3338
|
+
case 29:
|
|
3339
|
+
_v.trys.push([29, 36, 37, 38]);
|
|
3340
|
+
_q = (e_6 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3341
|
+
_v.label = 30;
|
|
3342
|
+
case 30:
|
|
3343
|
+
if (!!_r.done) return [3 /*break*/, 35];
|
|
3344
|
+
scriptTools = _r.value;
|
|
3345
|
+
_v.label = 31;
|
|
3346
|
+
case 31:
|
|
3347
|
+
_v.trys.push([31, 33, , 34]);
|
|
3348
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
3349
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3350
|
+
script: "".concat(functionName, "(resultString)"),
|
|
3351
|
+
parameters: {
|
|
3352
|
+
resultString: resultString || '',
|
|
3353
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
3354
|
+
},
|
|
3355
|
+
})];
|
|
3356
|
+
case 32:
|
|
3357
|
+
resultString = _v.sent();
|
|
3358
|
+
postprocessingError = null;
|
|
3359
|
+
return [3 /*break*/, 35];
|
|
3360
|
+
case 33:
|
|
3361
|
+
error_3 = _v.sent();
|
|
3362
|
+
if (!(error_3 instanceof Error)) {
|
|
3363
|
+
throw error_3;
|
|
3364
|
+
}
|
|
3365
|
+
if (error_3 instanceof UnexpectedError) {
|
|
3366
|
+
throw error_3;
|
|
3367
|
+
}
|
|
3368
|
+
postprocessingError = error_3;
|
|
3369
|
+
scriptPipelineExecutionErrors.push(error_3);
|
|
3370
|
+
return [3 /*break*/, 34];
|
|
3371
|
+
case 34:
|
|
3372
|
+
_r = _q.next();
|
|
3373
|
+
return [3 /*break*/, 30];
|
|
3374
|
+
case 35: return [3 /*break*/, 38];
|
|
3375
|
+
case 36:
|
|
3376
|
+
e_6_1 = _v.sent();
|
|
3377
|
+
e_6 = { error: e_6_1 };
|
|
3378
|
+
return [3 /*break*/, 38];
|
|
3379
|
+
case 37:
|
|
3380
|
+
try {
|
|
3381
|
+
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3382
|
+
}
|
|
3383
|
+
finally { if (e_6) throw e_6.error; }
|
|
3384
|
+
return [7 /*endfinally*/];
|
|
3385
|
+
case 38:
|
|
3386
|
+
if (postprocessingError) {
|
|
3387
|
+
throw postprocessingError;
|
|
3388
|
+
}
|
|
3389
|
+
_v.label = 39;
|
|
3390
|
+
case 39:
|
|
3391
|
+
_p = _o.next();
|
|
3392
|
+
return [3 /*break*/, 28];
|
|
3393
|
+
case 40: return [3 /*break*/, 43];
|
|
3394
|
+
case 41:
|
|
3395
|
+
e_7_1 = _v.sent();
|
|
3396
|
+
e_7 = { error: e_7_1 };
|
|
3397
|
+
return [3 /*break*/, 43];
|
|
3398
|
+
case 42:
|
|
3399
|
+
try {
|
|
3400
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3401
|
+
}
|
|
3402
|
+
finally { if (e_7) throw e_7.error; }
|
|
3403
|
+
return [7 /*endfinally*/];
|
|
3404
|
+
case 43:
|
|
3405
|
+
// TODO: [π] Unite object for expecting amount and format
|
|
3406
|
+
if (currentTemplate.expectFormat) {
|
|
3407
|
+
if (currentTemplate.expectFormat === 'JSON') {
|
|
3408
|
+
if (!isValidJsonString(resultString || '')) {
|
|
3409
|
+
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
// TODO: [π] Unite object for expecting amount and format
|
|
3414
|
+
if (currentTemplate.expectations) {
|
|
3415
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3416
|
+
}
|
|
3417
|
+
return [2 /*return*/, "break-attempts"];
|
|
3418
|
+
case 44:
|
|
3419
|
+
error_4 = _v.sent();
|
|
3420
|
+
if (!(error_4 instanceof ExpectError)) {
|
|
3421
|
+
throw error_4;
|
|
3422
|
+
}
|
|
3423
|
+
expectError = error_4;
|
|
3424
|
+
return [3 /*break*/, 46];
|
|
3425
|
+
case 45:
|
|
3426
|
+
if (!isJokerAttempt &&
|
|
3427
|
+
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3428
|
+
prompt
|
|
3429
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3430
|
+
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3431
|
+
) {
|
|
3432
|
+
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3433
|
+
executionReport.promptExecutions.push({
|
|
3434
|
+
prompt: __assign({}, prompt),
|
|
3435
|
+
result: result || undefined,
|
|
3436
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3439
|
+
return [7 /*endfinally*/];
|
|
3440
|
+
case 46:
|
|
3441
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3442
|
+
throw new PipelineExecutionError(spaceTrim.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 "); }));
|
|
3443
|
+
}
|
|
3444
|
+
return [2 /*return*/];
|
|
3445
|
+
}
|
|
3446
|
+
});
|
|
3447
|
+
};
|
|
3144
3448
|
attempt = -jokerParameterNames.length;
|
|
3145
|
-
|
|
3449
|
+
_h.label = 4;
|
|
3146
3450
|
case 4:
|
|
3147
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
3148
|
-
|
|
3149
|
-
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3150
|
-
if (isJokerAttempt && !jokerParameterName) {
|
|
3151
|
-
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
3152
|
-
}
|
|
3153
|
-
result = null;
|
|
3154
|
-
resultString = null;
|
|
3155
|
-
expectError = null;
|
|
3156
|
-
if (isJokerAttempt) {
|
|
3157
|
-
if (parameters[jokerParameterName] === undefined) {
|
|
3158
|
-
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
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
|
-
_u.label = 5;
|
|
3451
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 7];
|
|
3452
|
+
return [5 /*yield**/, _loop_5(attempt)];
|
|
3166
3453
|
case 5:
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
switch (_f) {
|
|
3171
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
3172
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
3173
|
-
case 'SCRIPT': return [3 /*break*/, 16];
|
|
3174
|
-
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
3454
|
+
state_2 = _h.sent();
|
|
3455
|
+
switch (state_2) {
|
|
3456
|
+
case "break-attempts": return [3 /*break*/, 7];
|
|
3175
3457
|
}
|
|
3176
|
-
|
|
3458
|
+
_h.label = 6;
|
|
3177
3459
|
case 6:
|
|
3178
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3179
|
-
return [3 /*break*/, 30];
|
|
3180
|
-
case 7:
|
|
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
|
-
_g = currentTemplate.modelRequirements.modelVariant;
|
|
3197
|
-
switch (_g) {
|
|
3198
|
-
case 'CHAT': return [3 /*break*/, 8];
|
|
3199
|
-
case 'COMPLETION': return [3 /*break*/, 10];
|
|
3200
|
-
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
3201
|
-
}
|
|
3202
|
-
return [3 /*break*/, 14];
|
|
3203
|
-
case 8: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3204
|
-
case 9:
|
|
3205
|
-
chatResult = _u.sent();
|
|
3206
|
-
// TODO: [π¬] Destroy chatThread
|
|
3207
|
-
result = chatResult;
|
|
3208
|
-
resultString = chatResult.content;
|
|
3209
|
-
return [3 /*break*/, 15];
|
|
3210
|
-
case 10: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3211
|
-
case 11:
|
|
3212
|
-
completionResult = _u.sent();
|
|
3213
|
-
result = completionResult;
|
|
3214
|
-
resultString = completionResult.content;
|
|
3215
|
-
return [3 /*break*/, 15];
|
|
3216
|
-
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3217
|
-
case 13:
|
|
3218
|
-
embeddingResult = _u.sent();
|
|
3219
|
-
result = embeddingResult;
|
|
3220
|
-
resultString = embeddingResult.content.join(',');
|
|
3221
|
-
return [3 /*break*/, 15];
|
|
3222
|
-
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
3223
|
-
case 15: return [3 /*break*/, 30];
|
|
3224
|
-
case 16:
|
|
3225
|
-
if (arrayableToArray(tools.script).length === 0) {
|
|
3226
|
-
throw new PipelineExecutionError('No script execution tools are available');
|
|
3227
|
-
}
|
|
3228
|
-
if (!currentTemplate.contentLanguage) {
|
|
3229
|
-
throw new PipelineExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
3230
|
-
}
|
|
3231
|
-
// TODO: DRY [1]
|
|
3232
|
-
scriptPipelineExecutionErrors = [];
|
|
3233
|
-
_u.label = 17;
|
|
3234
|
-
case 17:
|
|
3235
|
-
_u.trys.push([17, 24, 25, 26]);
|
|
3236
|
-
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
3237
|
-
_u.label = 18;
|
|
3238
|
-
case 18:
|
|
3239
|
-
if (!!_j.done) return [3 /*break*/, 23];
|
|
3240
|
-
scriptTools = _j.value;
|
|
3241
|
-
_u.label = 19;
|
|
3242
|
-
case 19:
|
|
3243
|
-
_u.trys.push([19, 21, , 22]);
|
|
3244
|
-
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3245
|
-
scriptLanguage: currentTemplate.contentLanguage,
|
|
3246
|
-
script: preparedContent,
|
|
3247
|
-
parameters: parameters,
|
|
3248
|
-
}))];
|
|
3249
|
-
case 20:
|
|
3250
|
-
resultString = _u.sent();
|
|
3251
|
-
return [3 /*break*/, 23];
|
|
3252
|
-
case 21:
|
|
3253
|
-
error_2 = _u.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*/, 22];
|
|
3262
|
-
case 22:
|
|
3263
|
-
_j = _h.next();
|
|
3264
|
-
return [3 /*break*/, 18];
|
|
3265
|
-
case 23: return [3 /*break*/, 26];
|
|
3266
|
-
case 24:
|
|
3267
|
-
e_4_1 = _u.sent();
|
|
3268
|
-
e_4 = { error: e_4_1 };
|
|
3269
|
-
return [3 /*break*/, 26];
|
|
3270
|
-
case 25:
|
|
3271
|
-
try {
|
|
3272
|
-
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
3273
|
-
}
|
|
3274
|
-
finally { if (e_4) throw e_4.error; }
|
|
3275
|
-
return [7 /*endfinally*/];
|
|
3276
|
-
case 26:
|
|
3277
|
-
if (resultString !== null) {
|
|
3278
|
-
return [3 /*break*/, 30];
|
|
3279
|
-
}
|
|
3280
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3281
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3282
|
-
}
|
|
3283
|
-
else {
|
|
3284
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3285
|
-
.map(function (error) { return '- ' + error.message; })
|
|
3286
|
-
.join('\n\n')), "\n "); }));
|
|
3287
|
-
}
|
|
3288
|
-
case 27:
|
|
3289
|
-
if (tools.userInterface === undefined) {
|
|
3290
|
-
throw new PipelineExecutionError('User interface tools are not available');
|
|
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 28:
|
|
3301
|
-
// TODO: [πΉ] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
3302
|
-
resultString = _u.sent();
|
|
3303
|
-
return [3 /*break*/, 30];
|
|
3304
|
-
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
3305
|
-
case 30:
|
|
3306
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
3307
|
-
_u.label = 31;
|
|
3308
|
-
case 31:
|
|
3309
|
-
_u.trys.push([31, 45, 46, 47]);
|
|
3310
|
-
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
3311
|
-
_u.label = 32;
|
|
3312
|
-
case 32:
|
|
3313
|
-
if (!!_l.done) return [3 /*break*/, 44];
|
|
3314
|
-
functionName = _l.value;
|
|
3315
|
-
// TODO: DRY [1]
|
|
3316
|
-
scriptPipelineExecutionErrors = [];
|
|
3317
|
-
postprocessingError = null;
|
|
3318
|
-
_u.label = 33;
|
|
3319
|
-
case 33:
|
|
3320
|
-
_u.trys.push([33, 40, 41, 42]);
|
|
3321
|
-
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
3322
|
-
_u.label = 34;
|
|
3323
|
-
case 34:
|
|
3324
|
-
if (!!_o.done) return [3 /*break*/, 39];
|
|
3325
|
-
scriptTools = _o.value;
|
|
3326
|
-
_u.label = 35;
|
|
3327
|
-
case 35:
|
|
3328
|
-
_u.trys.push([35, 37, , 38]);
|
|
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 36:
|
|
3338
|
-
resultString = _u.sent();
|
|
3339
|
-
postprocessingError = null;
|
|
3340
|
-
return [3 /*break*/, 39];
|
|
3341
|
-
case 37:
|
|
3342
|
-
error_3 = _u.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*/, 38];
|
|
3352
|
-
case 38:
|
|
3353
|
-
_o = _m.next();
|
|
3354
|
-
return [3 /*break*/, 34];
|
|
3355
|
-
case 39: return [3 /*break*/, 42];
|
|
3356
|
-
case 40:
|
|
3357
|
-
e_5_1 = _u.sent();
|
|
3358
|
-
e_5 = { error: e_5_1 };
|
|
3359
|
-
return [3 /*break*/, 42];
|
|
3360
|
-
case 41:
|
|
3361
|
-
try {
|
|
3362
|
-
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
3363
|
-
}
|
|
3364
|
-
finally { if (e_5) throw e_5.error; }
|
|
3365
|
-
return [7 /*endfinally*/];
|
|
3366
|
-
case 42:
|
|
3367
|
-
if (postprocessingError) {
|
|
3368
|
-
throw postprocessingError;
|
|
3369
|
-
}
|
|
3370
|
-
_u.label = 43;
|
|
3371
|
-
case 43:
|
|
3372
|
-
_l = _k.next();
|
|
3373
|
-
return [3 /*break*/, 32];
|
|
3374
|
-
case 44: return [3 /*break*/, 47];
|
|
3375
|
-
case 45:
|
|
3376
|
-
e_6_1 = _u.sent();
|
|
3377
|
-
e_6 = { error: e_6_1 };
|
|
3378
|
-
return [3 /*break*/, 47];
|
|
3379
|
-
case 46:
|
|
3380
|
-
try {
|
|
3381
|
-
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
3382
|
-
}
|
|
3383
|
-
finally { if (e_6) throw e_6.error; }
|
|
3384
|
-
return [7 /*endfinally*/];
|
|
3385
|
-
case 47:
|
|
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('Expected valid JSON string');
|
|
3391
|
-
}
|
|
3392
|
-
}
|
|
3393
|
-
}
|
|
3394
|
-
// TODO: [π] Unite object for expecting amount and format
|
|
3395
|
-
if (currentTemplate.expectations) {
|
|
3396
|
-
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3397
|
-
}
|
|
3398
|
-
return [3 /*break*/, 52];
|
|
3399
|
-
case 48:
|
|
3400
|
-
error_4 = _u.sent();
|
|
3401
|
-
if (!(error_4 instanceof ExpectError)) {
|
|
3402
|
-
throw error_4;
|
|
3403
|
-
}
|
|
3404
|
-
if (error_4 instanceof UnexpectedError) {
|
|
3405
|
-
throw error_4;
|
|
3406
|
-
}
|
|
3407
|
-
expectError = error_4;
|
|
3408
|
-
return [3 /*break*/, 50];
|
|
3409
|
-
case 49:
|
|
3410
|
-
if (!isJokerAttempt &&
|
|
3411
|
-
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3412
|
-
prompt
|
|
3413
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3414
|
-
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3415
|
-
) {
|
|
3416
|
-
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3417
|
-
executionReport.promptExecutions.push({
|
|
3418
|
-
prompt: __assign({}, prompt),
|
|
3419
|
-
result: result || undefined,
|
|
3420
|
-
error: expectError === null ? undefined : serializeError(expectError),
|
|
3421
|
-
});
|
|
3422
|
-
}
|
|
3423
|
-
return [7 /*endfinally*/];
|
|
3424
|
-
case 50:
|
|
3425
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3426
|
-
throw new PipelineExecutionError(spaceTrim.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 "); }));
|
|
3427
|
-
}
|
|
3428
|
-
_u.label = 51;
|
|
3429
|
-
case 51:
|
|
3430
3460
|
attempt++;
|
|
3431
3461
|
return [3 /*break*/, 4];
|
|
3432
|
-
case
|
|
3462
|
+
case 7:
|
|
3433
3463
|
if (resultString === null) {
|
|
3434
|
-
throw new UnexpectedError(
|
|
3464
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3435
3465
|
}
|
|
3436
3466
|
if (onProgress /* <- [3] */) {
|
|
3437
3467
|
onProgress({
|
|
@@ -3445,7 +3475,7 @@
|
|
|
3445
3475
|
// <- [3]
|
|
3446
3476
|
});
|
|
3447
3477
|
}
|
|
3448
|
-
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (
|
|
3478
|
+
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)));
|
|
3449
3479
|
return [2 /*return*/];
|
|
3450
3480
|
}
|
|
3451
3481
|
});
|
|
@@ -3454,6 +3484,14 @@
|
|
|
3454
3484
|
function filterJustOutputParameters() {
|
|
3455
3485
|
var e_8, _a;
|
|
3456
3486
|
var outputParameters = {};
|
|
3487
|
+
var _loop_6 = function (parameter) {
|
|
3488
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3489
|
+
// [4]
|
|
3490
|
+
warnings.push(new PipelineExecutionError(spaceTrim.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 "); })));
|
|
3491
|
+
return "continue";
|
|
3492
|
+
}
|
|
3493
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3494
|
+
};
|
|
3457
3495
|
try {
|
|
3458
3496
|
// Note: Filter ONLY output parameters
|
|
3459
3497
|
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
@@ -3461,12 +3499,7 @@
|
|
|
3461
3499
|
return isOutput;
|
|
3462
3500
|
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3463
3501
|
var parameter = _c.value;
|
|
3464
|
-
|
|
3465
|
-
// [4]
|
|
3466
|
-
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
|
|
3467
|
-
continue;
|
|
3468
|
-
}
|
|
3469
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3502
|
+
_loop_6(parameter);
|
|
3470
3503
|
}
|
|
3471
3504
|
}
|
|
3472
3505
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
@@ -3538,13 +3571,13 @@
|
|
|
3538
3571
|
return name === parameterName;
|
|
3539
3572
|
});
|
|
3540
3573
|
if (parameter === undefined) {
|
|
3541
|
-
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3574
|
+
warnings.push(new PipelineExecutionError(spaceTrim.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 "); })));
|
|
3542
3575
|
}
|
|
3543
3576
|
else if (parameter.isInput === false) {
|
|
3544
|
-
return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3577
|
+
return { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
3545
3578
|
isSuccessful: false,
|
|
3546
3579
|
errors: __spreadArray([
|
|
3547
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3580
|
+
new PipelineExecutionError(spaceTrim.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 "); }))
|
|
3548
3581
|
], __read(errors), false).map(serializeError),
|
|
3549
3582
|
warnings: warnings.map(serializeError),
|
|
3550
3583
|
executionReport: executionReport,
|
|
@@ -3593,7 +3626,7 @@
|
|
|
3593
3626
|
case 0:
|
|
3594
3627
|
if (loopLimit-- < 0) {
|
|
3595
3628
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
3596
|
-
throw new UnexpectedError(
|
|
3629
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3597
3630
|
}
|
|
3598
3631
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3599
3632
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -3603,7 +3636,7 @@
|
|
|
3603
3636
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3604
3637
|
throw new UnexpectedError(
|
|
3605
3638
|
// TODO: [π] DRY
|
|
3606
|
-
spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3639
|
+
spaceTrim.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
|
|
3607
3640
|
.map(function (_a) {
|
|
3608
3641
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3609
3642
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -3683,6 +3716,7 @@
|
|
|
3683
3716
|
return pipelineExecutor;
|
|
3684
3717
|
}
|
|
3685
3718
|
/**
|
|
3719
|
+
* TODO: !!! Identify not only pipeline BUT exact template ${block(pipelineIdentification)}
|
|
3686
3720
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3687
3721
|
* TODO: [π§ ][π³] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
3688
3722
|
* TODO: [πͺ] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
@@ -4222,6 +4256,8 @@
|
|
|
4222
4256
|
* TODO: [π] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
4223
4257
|
* TODO: [π§] In future one preparation can take data from previous preparation and save tokens and time
|
|
4224
4258
|
* TODO: [π ] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4259
|
+
* TODO: [π§ ][β] Maybe if expecting JSON (In Anthropic Claude and other models without non-json) and its not specified in prompt content, append the instructions
|
|
4260
|
+
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
4225
4261
|
*/
|
|
4226
4262
|
|
|
4227
4263
|
/**
|
|
@@ -8351,6 +8387,8 @@
|
|
|
8351
8387
|
{
|
|
8352
8388
|
role: 'user',
|
|
8353
8389
|
content: rawPromptContent,
|
|
8390
|
+
// <- TODO: [π§ ][β] Maybe if expecting JSON and its not specified in prompt content, append the instructions
|
|
8391
|
+
// @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
8354
8392
|
},
|
|
8355
8393
|
],
|
|
8356
8394
|
// TODO: Is here some equivalent of user identification?> user: this.options.user,
|
|
@@ -8489,7 +8527,7 @@
|
|
|
8489
8527
|
* Default model for chat variant.
|
|
8490
8528
|
*/
|
|
8491
8529
|
AnthropicClaudeExecutionTools.prototype.getDefaultChatModel = function () {
|
|
8492
|
-
return this.getDefaultModel('claude-3-
|
|
8530
|
+
return this.getDefaultModel('claude-3-5-sonnet');
|
|
8493
8531
|
};
|
|
8494
8532
|
return AnthropicClaudeExecutionTools;
|
|
8495
8533
|
}());
|