@promptbook/node 0.67.2 β 0.67.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +359 -324
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +359 -324
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
/**
|
|
36
36
|
* The version of the Promptbook library
|
|
37
37
|
*/
|
|
38
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
38
|
+
var PROMPTBOOK_VERSION = '0.67.2';
|
|
39
39
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
40
40
|
|
|
41
41
|
/*! *****************************************************************************
|
|
@@ -889,7 +889,7 @@
|
|
|
889
889
|
});
|
|
890
890
|
}
|
|
891
891
|
|
|
892
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
892
|
+
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"}];
|
|
893
893
|
|
|
894
894
|
/**
|
|
895
895
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2833,13 +2833,24 @@
|
|
|
2833
2833
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2834
2834
|
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;
|
|
2835
2835
|
validatePipeline(pipeline);
|
|
2836
|
+
var pipelineIdentification = (function () {
|
|
2837
|
+
// Note: This is a π implementation of [π]
|
|
2838
|
+
var _ = [];
|
|
2839
|
+
if (pipeline.sourceFile !== undefined) {
|
|
2840
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
2841
|
+
}
|
|
2842
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
2843
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
2844
|
+
}
|
|
2845
|
+
return _.join('\n');
|
|
2846
|
+
})();
|
|
2836
2847
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2837
2848
|
var preparedPipeline;
|
|
2838
2849
|
if (isPipelinePrepared(pipeline)) {
|
|
2839
2850
|
preparedPipeline = pipeline;
|
|
2840
2851
|
}
|
|
2841
2852
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
2842
|
-
console.warn(spaceTrim.spaceTrim(
|
|
2853
|
+
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 "); }));
|
|
2843
2854
|
}
|
|
2844
2855
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2845
2856
|
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
@@ -2877,7 +2888,7 @@
|
|
|
2877
2888
|
}
|
|
2878
2889
|
function getReservedParametersForTemplate(template) {
|
|
2879
2890
|
return __awaiter(this, void 0, void 0, function () {
|
|
2880
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2891
|
+
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_3, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2881
2892
|
var e_3, _a;
|
|
2882
2893
|
return __generator(this, function (_b) {
|
|
2883
2894
|
switch (_b.label) {
|
|
@@ -2900,13 +2911,16 @@
|
|
|
2900
2911
|
currentDate: currentDate,
|
|
2901
2912
|
modelName: modelName,
|
|
2902
2913
|
};
|
|
2914
|
+
_loop_3 = function (parameterName) {
|
|
2915
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
2916
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
2917
|
+
}
|
|
2918
|
+
};
|
|
2903
2919
|
try {
|
|
2904
2920
|
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
2905
2921
|
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()) {
|
|
2906
2922
|
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
2907
|
-
|
|
2908
|
-
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
2909
|
-
}
|
|
2923
|
+
_loop_3(parameterName);
|
|
2910
2924
|
}
|
|
2911
2925
|
}
|
|
2912
2926
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -2923,10 +2937,10 @@
|
|
|
2923
2937
|
}
|
|
2924
2938
|
function executeSingleTemplate(currentTemplate) {
|
|
2925
2939
|
return __awaiter(this, void 0, void 0, function () {
|
|
2926
|
-
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,
|
|
2927
|
-
var
|
|
2928
|
-
return __generator(this, function (
|
|
2929
|
-
switch (
|
|
2940
|
+
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;
|
|
2941
|
+
var e_4, _f, _g;
|
|
2942
|
+
return __generator(this, function (_h) {
|
|
2943
|
+
switch (_h.label) {
|
|
2930
2944
|
case 0:
|
|
2931
2945
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
2932
2946
|
title = currentTemplate.title;
|
|
@@ -2943,47 +2957,48 @@
|
|
|
2943
2957
|
// <- [3]
|
|
2944
2958
|
})];
|
|
2945
2959
|
case 1:
|
|
2946
|
-
|
|
2947
|
-
|
|
2960
|
+
_h.sent();
|
|
2961
|
+
_h.label = 2;
|
|
2948
2962
|
case 2:
|
|
2949
2963
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
2950
2964
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2951
2965
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2952
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
2966
|
+
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 "); }));
|
|
2953
2967
|
}
|
|
2954
2968
|
_b = (_a = Object).freeze;
|
|
2955
2969
|
_c = [{}];
|
|
2956
2970
|
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
2957
2971
|
case 3:
|
|
2958
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(
|
|
2972
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
2959
2973
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
2960
2974
|
parameters = {};
|
|
2975
|
+
_loop_4 = function (parameterName) {
|
|
2976
|
+
// Situation: Parameter is defined and used
|
|
2977
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2978
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
2979
|
+
}
|
|
2980
|
+
// Situation: Parameter is defined but NOT used
|
|
2981
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
2982
|
+
// Situation: Parameter is NOT defined BUT used
|
|
2983
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2984
|
+
// Houston, we have a problem
|
|
2985
|
+
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
2986
|
+
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 "); }));
|
|
2987
|
+
}
|
|
2988
|
+
};
|
|
2961
2989
|
try {
|
|
2962
2990
|
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
2963
2991
|
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2964
2992
|
parameterName = _e.value;
|
|
2965
|
-
|
|
2966
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2967
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
2968
|
-
}
|
|
2969
|
-
// Situation: Parameter is defined but NOT used
|
|
2970
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
2971
|
-
// Do not pass this parameter to prompt
|
|
2972
|
-
}
|
|
2973
|
-
// Situation: Parameter is NOT defined BUT used
|
|
2974
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2975
|
-
// Houston, we have a problem
|
|
2976
|
-
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
2977
|
-
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 ")));
|
|
2978
|
-
}
|
|
2993
|
+
_loop_4(parameterName);
|
|
2979
2994
|
}
|
|
2980
2995
|
}
|
|
2981
|
-
catch (
|
|
2996
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
2982
2997
|
finally {
|
|
2983
2998
|
try {
|
|
2984
|
-
if (_e && !_e.done && (
|
|
2999
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
2985
3000
|
}
|
|
2986
|
-
finally { if (
|
|
3001
|
+
finally { if (e_4) throw e_4.error; }
|
|
2987
3002
|
}
|
|
2988
3003
|
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
2989
3004
|
Object.freeze(parameters);
|
|
@@ -2995,294 +3010,310 @@
|
|
|
2995
3010
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
2996
3011
|
.split('{content}')
|
|
2997
3012
|
.join(currentTemplate.content);
|
|
3013
|
+
_loop_5 = function (attempt) {
|
|
3014
|
+
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;
|
|
3015
|
+
var e_5, _s, e_7, _t, e_6, _u;
|
|
3016
|
+
return __generator(this, function (_v) {
|
|
3017
|
+
switch (_v.label) {
|
|
3018
|
+
case 0:
|
|
3019
|
+
isJokerAttempt = attempt < 0;
|
|
3020
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3021
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
3022
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3023
|
+
}
|
|
3024
|
+
result = null;
|
|
3025
|
+
resultString = null;
|
|
3026
|
+
expectError = null;
|
|
3027
|
+
if (isJokerAttempt) {
|
|
3028
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
3029
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3030
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3031
|
+
}
|
|
3032
|
+
else {
|
|
3033
|
+
resultString = parameters[jokerParameterName];
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
_v.label = 1;
|
|
3037
|
+
case 1:
|
|
3038
|
+
_v.trys.push([1, 44, 45, 46]);
|
|
3039
|
+
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3040
|
+
_j = currentTemplate.blockType;
|
|
3041
|
+
switch (_j) {
|
|
3042
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3043
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3044
|
+
case 'SCRIPT': return [3 /*break*/, 12];
|
|
3045
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 23];
|
|
3046
|
+
}
|
|
3047
|
+
return [3 /*break*/, 25];
|
|
3048
|
+
case 2:
|
|
3049
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
3050
|
+
return [3 /*break*/, 26];
|
|
3051
|
+
case 3:
|
|
3052
|
+
prompt = {
|
|
3053
|
+
title: currentTemplate.title,
|
|
3054
|
+
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3055
|
+
? preparedPipeline.pipelineUrl
|
|
3056
|
+
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3057
|
+
parameters: parameters,
|
|
3058
|
+
content: preparedContent,
|
|
3059
|
+
modelRequirements: currentTemplate.modelRequirements,
|
|
3060
|
+
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3061
|
+
var name = _a.name;
|
|
3062
|
+
return name === currentTemplate.personaName;
|
|
3063
|
+
}) || {})), currentTemplate.expectations),
|
|
3064
|
+
expectFormat: currentTemplate.expectFormat,
|
|
3065
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3066
|
+
}; // <- TODO: Not very good type guard
|
|
3067
|
+
_k = currentTemplate.modelRequirements.modelVariant;
|
|
3068
|
+
switch (_k) {
|
|
3069
|
+
case 'CHAT': return [3 /*break*/, 4];
|
|
3070
|
+
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3071
|
+
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3072
|
+
}
|
|
3073
|
+
return [3 /*break*/, 10];
|
|
3074
|
+
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3075
|
+
case 5:
|
|
3076
|
+
chatResult = _v.sent();
|
|
3077
|
+
// TODO: [π¬] Destroy chatThread
|
|
3078
|
+
result = chatResult;
|
|
3079
|
+
resultString = chatResult.content;
|
|
3080
|
+
return [3 /*break*/, 11];
|
|
3081
|
+
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3082
|
+
case 7:
|
|
3083
|
+
completionResult = _v.sent();
|
|
3084
|
+
result = completionResult;
|
|
3085
|
+
resultString = completionResult.content;
|
|
3086
|
+
return [3 /*break*/, 11];
|
|
3087
|
+
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3088
|
+
case 9:
|
|
3089
|
+
embeddingResult = _v.sent();
|
|
3090
|
+
result = embeddingResult;
|
|
3091
|
+
resultString = embeddingResult.content.join(',');
|
|
3092
|
+
return [3 /*break*/, 11];
|
|
3093
|
+
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 "); }));
|
|
3094
|
+
case 11: return [3 /*break*/, 26];
|
|
3095
|
+
case 12:
|
|
3096
|
+
if (arrayableToArray(tools.script).length === 0) {
|
|
3097
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3098
|
+
}
|
|
3099
|
+
if (!currentTemplate.contentLanguage) {
|
|
3100
|
+
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 "); }));
|
|
3101
|
+
}
|
|
3102
|
+
// TODO: DRY [1]
|
|
3103
|
+
scriptPipelineExecutionErrors = [];
|
|
3104
|
+
_v.label = 13;
|
|
3105
|
+
case 13:
|
|
3106
|
+
_v.trys.push([13, 20, 21, 22]);
|
|
3107
|
+
_l = (e_5 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3108
|
+
_v.label = 14;
|
|
3109
|
+
case 14:
|
|
3110
|
+
if (!!_m.done) return [3 /*break*/, 19];
|
|
3111
|
+
scriptTools = _m.value;
|
|
3112
|
+
_v.label = 15;
|
|
3113
|
+
case 15:
|
|
3114
|
+
_v.trys.push([15, 17, , 18]);
|
|
3115
|
+
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3116
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
3117
|
+
script: preparedContent,
|
|
3118
|
+
parameters: parameters,
|
|
3119
|
+
}))];
|
|
3120
|
+
case 16:
|
|
3121
|
+
resultString = _v.sent();
|
|
3122
|
+
return [3 /*break*/, 19];
|
|
3123
|
+
case 17:
|
|
3124
|
+
error_2 = _v.sent();
|
|
3125
|
+
if (!(error_2 instanceof Error)) {
|
|
3126
|
+
throw error_2;
|
|
3127
|
+
}
|
|
3128
|
+
if (error_2 instanceof UnexpectedError) {
|
|
3129
|
+
throw error_2;
|
|
3130
|
+
}
|
|
3131
|
+
scriptPipelineExecutionErrors.push(error_2);
|
|
3132
|
+
return [3 /*break*/, 18];
|
|
3133
|
+
case 18:
|
|
3134
|
+
_m = _l.next();
|
|
3135
|
+
return [3 /*break*/, 14];
|
|
3136
|
+
case 19: return [3 /*break*/, 22];
|
|
3137
|
+
case 20:
|
|
3138
|
+
e_5_1 = _v.sent();
|
|
3139
|
+
e_5 = { error: e_5_1 };
|
|
3140
|
+
return [3 /*break*/, 22];
|
|
3141
|
+
case 21:
|
|
3142
|
+
try {
|
|
3143
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3144
|
+
}
|
|
3145
|
+
finally { if (e_5) throw e_5.error; }
|
|
3146
|
+
return [7 /*endfinally*/];
|
|
3147
|
+
case 22:
|
|
3148
|
+
if (resultString !== null) {
|
|
3149
|
+
return [3 /*break*/, 26];
|
|
3150
|
+
}
|
|
3151
|
+
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3152
|
+
throw scriptPipelineExecutionErrors[0];
|
|
3153
|
+
}
|
|
3154
|
+
else {
|
|
3155
|
+
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
|
|
3156
|
+
.map(function (error) { return '- ' + error.message; })
|
|
3157
|
+
.join('\n\n')), "\n "); }));
|
|
3158
|
+
}
|
|
3159
|
+
case 23:
|
|
3160
|
+
if (tools.userInterface === undefined) {
|
|
3161
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3162
|
+
}
|
|
3163
|
+
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3164
|
+
promptTitle: currentTemplate.title,
|
|
3165
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3166
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3167
|
+
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3168
|
+
placeholder: undefined,
|
|
3169
|
+
priority: priority,
|
|
3170
|
+
}))];
|
|
3171
|
+
case 24:
|
|
3172
|
+
// TODO: [πΉ] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
3173
|
+
resultString = _v.sent();
|
|
3174
|
+
return [3 /*break*/, 26];
|
|
3175
|
+
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.blockType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3176
|
+
case 26:
|
|
3177
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3178
|
+
_v.label = 27;
|
|
3179
|
+
case 27:
|
|
3180
|
+
_v.trys.push([27, 41, 42, 43]);
|
|
3181
|
+
_o = (e_7 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3182
|
+
_v.label = 28;
|
|
3183
|
+
case 28:
|
|
3184
|
+
if (!!_p.done) return [3 /*break*/, 40];
|
|
3185
|
+
functionName = _p.value;
|
|
3186
|
+
// TODO: DRY [1]
|
|
3187
|
+
scriptPipelineExecutionErrors = [];
|
|
3188
|
+
postprocessingError = null;
|
|
3189
|
+
_v.label = 29;
|
|
3190
|
+
case 29:
|
|
3191
|
+
_v.trys.push([29, 36, 37, 38]);
|
|
3192
|
+
_q = (e_6 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3193
|
+
_v.label = 30;
|
|
3194
|
+
case 30:
|
|
3195
|
+
if (!!_r.done) return [3 /*break*/, 35];
|
|
3196
|
+
scriptTools = _r.value;
|
|
3197
|
+
_v.label = 31;
|
|
3198
|
+
case 31:
|
|
3199
|
+
_v.trys.push([31, 33, , 34]);
|
|
3200
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
3201
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3202
|
+
script: "".concat(functionName, "(resultString)"),
|
|
3203
|
+
parameters: {
|
|
3204
|
+
resultString: resultString || '',
|
|
3205
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
3206
|
+
},
|
|
3207
|
+
})];
|
|
3208
|
+
case 32:
|
|
3209
|
+
resultString = _v.sent();
|
|
3210
|
+
postprocessingError = null;
|
|
3211
|
+
return [3 /*break*/, 35];
|
|
3212
|
+
case 33:
|
|
3213
|
+
error_3 = _v.sent();
|
|
3214
|
+
if (!(error_3 instanceof Error)) {
|
|
3215
|
+
throw error_3;
|
|
3216
|
+
}
|
|
3217
|
+
if (error_3 instanceof UnexpectedError) {
|
|
3218
|
+
throw error_3;
|
|
3219
|
+
}
|
|
3220
|
+
postprocessingError = error_3;
|
|
3221
|
+
scriptPipelineExecutionErrors.push(error_3);
|
|
3222
|
+
return [3 /*break*/, 34];
|
|
3223
|
+
case 34:
|
|
3224
|
+
_r = _q.next();
|
|
3225
|
+
return [3 /*break*/, 30];
|
|
3226
|
+
case 35: return [3 /*break*/, 38];
|
|
3227
|
+
case 36:
|
|
3228
|
+
e_6_1 = _v.sent();
|
|
3229
|
+
e_6 = { error: e_6_1 };
|
|
3230
|
+
return [3 /*break*/, 38];
|
|
3231
|
+
case 37:
|
|
3232
|
+
try {
|
|
3233
|
+
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3234
|
+
}
|
|
3235
|
+
finally { if (e_6) throw e_6.error; }
|
|
3236
|
+
return [7 /*endfinally*/];
|
|
3237
|
+
case 38:
|
|
3238
|
+
if (postprocessingError) {
|
|
3239
|
+
throw postprocessingError;
|
|
3240
|
+
}
|
|
3241
|
+
_v.label = 39;
|
|
3242
|
+
case 39:
|
|
3243
|
+
_p = _o.next();
|
|
3244
|
+
return [3 /*break*/, 28];
|
|
3245
|
+
case 40: return [3 /*break*/, 43];
|
|
3246
|
+
case 41:
|
|
3247
|
+
e_7_1 = _v.sent();
|
|
3248
|
+
e_7 = { error: e_7_1 };
|
|
3249
|
+
return [3 /*break*/, 43];
|
|
3250
|
+
case 42:
|
|
3251
|
+
try {
|
|
3252
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3253
|
+
}
|
|
3254
|
+
finally { if (e_7) throw e_7.error; }
|
|
3255
|
+
return [7 /*endfinally*/];
|
|
3256
|
+
case 43:
|
|
3257
|
+
// TODO: [π] Unite object for expecting amount and format
|
|
3258
|
+
if (currentTemplate.expectFormat) {
|
|
3259
|
+
if (currentTemplate.expectFormat === 'JSON') {
|
|
3260
|
+
if (!isValidJsonString(resultString || '')) {
|
|
3261
|
+
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
// TODO: [π] Unite object for expecting amount and format
|
|
3266
|
+
if (currentTemplate.expectations) {
|
|
3267
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3268
|
+
}
|
|
3269
|
+
return [2 /*return*/, "break-attempts"];
|
|
3270
|
+
case 44:
|
|
3271
|
+
error_4 = _v.sent();
|
|
3272
|
+
if (!(error_4 instanceof ExpectError)) {
|
|
3273
|
+
throw error_4;
|
|
3274
|
+
}
|
|
3275
|
+
expectError = error_4;
|
|
3276
|
+
return [3 /*break*/, 46];
|
|
3277
|
+
case 45:
|
|
3278
|
+
if (!isJokerAttempt &&
|
|
3279
|
+
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3280
|
+
prompt
|
|
3281
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3282
|
+
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3283
|
+
) {
|
|
3284
|
+
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3285
|
+
executionReport.promptExecutions.push({
|
|
3286
|
+
prompt: __assign({}, prompt),
|
|
3287
|
+
result: result || undefined,
|
|
3288
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3289
|
+
});
|
|
3290
|
+
}
|
|
3291
|
+
return [7 /*endfinally*/];
|
|
3292
|
+
case 46:
|
|
3293
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3294
|
+
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 "); }));
|
|
3295
|
+
}
|
|
3296
|
+
return [2 /*return*/];
|
|
3297
|
+
}
|
|
3298
|
+
});
|
|
3299
|
+
};
|
|
2998
3300
|
attempt = -jokerParameterNames.length;
|
|
2999
|
-
|
|
3301
|
+
_h.label = 4;
|
|
3000
3302
|
case 4:
|
|
3001
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
3002
|
-
|
|
3003
|
-
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3004
|
-
if (isJokerAttempt && !jokerParameterName) {
|
|
3005
|
-
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
3006
|
-
}
|
|
3007
|
-
result = null;
|
|
3008
|
-
resultString = null;
|
|
3009
|
-
expectError = null;
|
|
3010
|
-
if (isJokerAttempt) {
|
|
3011
|
-
if (parameters[jokerParameterName] === undefined) {
|
|
3012
|
-
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
3013
|
-
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3014
|
-
}
|
|
3015
|
-
else {
|
|
3016
|
-
resultString = parameters[jokerParameterName];
|
|
3017
|
-
}
|
|
3018
|
-
}
|
|
3019
|
-
_u.label = 5;
|
|
3303
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 7];
|
|
3304
|
+
return [5 /*yield**/, _loop_5(attempt)];
|
|
3020
3305
|
case 5:
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
switch (_f) {
|
|
3025
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
3026
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
3027
|
-
case 'SCRIPT': return [3 /*break*/, 16];
|
|
3028
|
-
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
3306
|
+
state_2 = _h.sent();
|
|
3307
|
+
switch (state_2) {
|
|
3308
|
+
case "break-attempts": return [3 /*break*/, 7];
|
|
3029
3309
|
}
|
|
3030
|
-
|
|
3310
|
+
_h.label = 6;
|
|
3031
3311
|
case 6:
|
|
3032
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3033
|
-
return [3 /*break*/, 30];
|
|
3034
|
-
case 7:
|
|
3035
|
-
prompt = {
|
|
3036
|
-
title: currentTemplate.title,
|
|
3037
|
-
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3038
|
-
? preparedPipeline.pipelineUrl
|
|
3039
|
-
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3040
|
-
parameters: parameters,
|
|
3041
|
-
content: preparedContent,
|
|
3042
|
-
modelRequirements: currentTemplate.modelRequirements,
|
|
3043
|
-
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3044
|
-
var name = _a.name;
|
|
3045
|
-
return name === currentTemplate.personaName;
|
|
3046
|
-
}) || {})), currentTemplate.expectations),
|
|
3047
|
-
expectFormat: currentTemplate.expectFormat,
|
|
3048
|
-
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3049
|
-
}; // <- TODO: Not very good type guard
|
|
3050
|
-
_g = currentTemplate.modelRequirements.modelVariant;
|
|
3051
|
-
switch (_g) {
|
|
3052
|
-
case 'CHAT': return [3 /*break*/, 8];
|
|
3053
|
-
case 'COMPLETION': return [3 /*break*/, 10];
|
|
3054
|
-
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
3055
|
-
}
|
|
3056
|
-
return [3 /*break*/, 14];
|
|
3057
|
-
case 8: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3058
|
-
case 9:
|
|
3059
|
-
chatResult = _u.sent();
|
|
3060
|
-
// TODO: [π¬] Destroy chatThread
|
|
3061
|
-
result = chatResult;
|
|
3062
|
-
resultString = chatResult.content;
|
|
3063
|
-
return [3 /*break*/, 15];
|
|
3064
|
-
case 10: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3065
|
-
case 11:
|
|
3066
|
-
completionResult = _u.sent();
|
|
3067
|
-
result = completionResult;
|
|
3068
|
-
resultString = completionResult.content;
|
|
3069
|
-
return [3 /*break*/, 15];
|
|
3070
|
-
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3071
|
-
case 13:
|
|
3072
|
-
embeddingResult = _u.sent();
|
|
3073
|
-
result = embeddingResult;
|
|
3074
|
-
resultString = embeddingResult.content.join(',');
|
|
3075
|
-
return [3 /*break*/, 15];
|
|
3076
|
-
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
3077
|
-
case 15: return [3 /*break*/, 30];
|
|
3078
|
-
case 16:
|
|
3079
|
-
if (arrayableToArray(tools.script).length === 0) {
|
|
3080
|
-
throw new PipelineExecutionError('No script execution tools are available');
|
|
3081
|
-
}
|
|
3082
|
-
if (!currentTemplate.contentLanguage) {
|
|
3083
|
-
throw new PipelineExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
3084
|
-
}
|
|
3085
|
-
// TODO: DRY [1]
|
|
3086
|
-
scriptPipelineExecutionErrors = [];
|
|
3087
|
-
_u.label = 17;
|
|
3088
|
-
case 17:
|
|
3089
|
-
_u.trys.push([17, 24, 25, 26]);
|
|
3090
|
-
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
3091
|
-
_u.label = 18;
|
|
3092
|
-
case 18:
|
|
3093
|
-
if (!!_j.done) return [3 /*break*/, 23];
|
|
3094
|
-
scriptTools = _j.value;
|
|
3095
|
-
_u.label = 19;
|
|
3096
|
-
case 19:
|
|
3097
|
-
_u.trys.push([19, 21, , 22]);
|
|
3098
|
-
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3099
|
-
scriptLanguage: currentTemplate.contentLanguage,
|
|
3100
|
-
script: preparedContent,
|
|
3101
|
-
parameters: parameters,
|
|
3102
|
-
}))];
|
|
3103
|
-
case 20:
|
|
3104
|
-
resultString = _u.sent();
|
|
3105
|
-
return [3 /*break*/, 23];
|
|
3106
|
-
case 21:
|
|
3107
|
-
error_2 = _u.sent();
|
|
3108
|
-
if (!(error_2 instanceof Error)) {
|
|
3109
|
-
throw error_2;
|
|
3110
|
-
}
|
|
3111
|
-
if (error_2 instanceof UnexpectedError) {
|
|
3112
|
-
throw error_2;
|
|
3113
|
-
}
|
|
3114
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3115
|
-
return [3 /*break*/, 22];
|
|
3116
|
-
case 22:
|
|
3117
|
-
_j = _h.next();
|
|
3118
|
-
return [3 /*break*/, 18];
|
|
3119
|
-
case 23: return [3 /*break*/, 26];
|
|
3120
|
-
case 24:
|
|
3121
|
-
e_4_1 = _u.sent();
|
|
3122
|
-
e_4 = { error: e_4_1 };
|
|
3123
|
-
return [3 /*break*/, 26];
|
|
3124
|
-
case 25:
|
|
3125
|
-
try {
|
|
3126
|
-
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
3127
|
-
}
|
|
3128
|
-
finally { if (e_4) throw e_4.error; }
|
|
3129
|
-
return [7 /*endfinally*/];
|
|
3130
|
-
case 26:
|
|
3131
|
-
if (resultString !== null) {
|
|
3132
|
-
return [3 /*break*/, 30];
|
|
3133
|
-
}
|
|
3134
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3135
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3136
|
-
}
|
|
3137
|
-
else {
|
|
3138
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3139
|
-
.map(function (error) { return '- ' + error.message; })
|
|
3140
|
-
.join('\n\n')), "\n "); }));
|
|
3141
|
-
}
|
|
3142
|
-
case 27:
|
|
3143
|
-
if (tools.userInterface === undefined) {
|
|
3144
|
-
throw new PipelineExecutionError('User interface tools are not available');
|
|
3145
|
-
}
|
|
3146
|
-
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3147
|
-
promptTitle: currentTemplate.title,
|
|
3148
|
-
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3149
|
-
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3150
|
-
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3151
|
-
placeholder: undefined,
|
|
3152
|
-
priority: priority,
|
|
3153
|
-
}))];
|
|
3154
|
-
case 28:
|
|
3155
|
-
// TODO: [πΉ] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
3156
|
-
resultString = _u.sent();
|
|
3157
|
-
return [3 /*break*/, 30];
|
|
3158
|
-
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
3159
|
-
case 30:
|
|
3160
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
3161
|
-
_u.label = 31;
|
|
3162
|
-
case 31:
|
|
3163
|
-
_u.trys.push([31, 45, 46, 47]);
|
|
3164
|
-
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
3165
|
-
_u.label = 32;
|
|
3166
|
-
case 32:
|
|
3167
|
-
if (!!_l.done) return [3 /*break*/, 44];
|
|
3168
|
-
functionName = _l.value;
|
|
3169
|
-
// TODO: DRY [1]
|
|
3170
|
-
scriptPipelineExecutionErrors = [];
|
|
3171
|
-
postprocessingError = null;
|
|
3172
|
-
_u.label = 33;
|
|
3173
|
-
case 33:
|
|
3174
|
-
_u.trys.push([33, 40, 41, 42]);
|
|
3175
|
-
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
3176
|
-
_u.label = 34;
|
|
3177
|
-
case 34:
|
|
3178
|
-
if (!!_o.done) return [3 /*break*/, 39];
|
|
3179
|
-
scriptTools = _o.value;
|
|
3180
|
-
_u.label = 35;
|
|
3181
|
-
case 35:
|
|
3182
|
-
_u.trys.push([35, 37, , 38]);
|
|
3183
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
3184
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3185
|
-
script: "".concat(functionName, "(resultString)"),
|
|
3186
|
-
parameters: {
|
|
3187
|
-
resultString: resultString || '',
|
|
3188
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
3189
|
-
},
|
|
3190
|
-
})];
|
|
3191
|
-
case 36:
|
|
3192
|
-
resultString = _u.sent();
|
|
3193
|
-
postprocessingError = null;
|
|
3194
|
-
return [3 /*break*/, 39];
|
|
3195
|
-
case 37:
|
|
3196
|
-
error_3 = _u.sent();
|
|
3197
|
-
if (!(error_3 instanceof Error)) {
|
|
3198
|
-
throw error_3;
|
|
3199
|
-
}
|
|
3200
|
-
if (error_3 instanceof UnexpectedError) {
|
|
3201
|
-
throw error_3;
|
|
3202
|
-
}
|
|
3203
|
-
postprocessingError = error_3;
|
|
3204
|
-
scriptPipelineExecutionErrors.push(error_3);
|
|
3205
|
-
return [3 /*break*/, 38];
|
|
3206
|
-
case 38:
|
|
3207
|
-
_o = _m.next();
|
|
3208
|
-
return [3 /*break*/, 34];
|
|
3209
|
-
case 39: return [3 /*break*/, 42];
|
|
3210
|
-
case 40:
|
|
3211
|
-
e_5_1 = _u.sent();
|
|
3212
|
-
e_5 = { error: e_5_1 };
|
|
3213
|
-
return [3 /*break*/, 42];
|
|
3214
|
-
case 41:
|
|
3215
|
-
try {
|
|
3216
|
-
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
3217
|
-
}
|
|
3218
|
-
finally { if (e_5) throw e_5.error; }
|
|
3219
|
-
return [7 /*endfinally*/];
|
|
3220
|
-
case 42:
|
|
3221
|
-
if (postprocessingError) {
|
|
3222
|
-
throw postprocessingError;
|
|
3223
|
-
}
|
|
3224
|
-
_u.label = 43;
|
|
3225
|
-
case 43:
|
|
3226
|
-
_l = _k.next();
|
|
3227
|
-
return [3 /*break*/, 32];
|
|
3228
|
-
case 44: return [3 /*break*/, 47];
|
|
3229
|
-
case 45:
|
|
3230
|
-
e_6_1 = _u.sent();
|
|
3231
|
-
e_6 = { error: e_6_1 };
|
|
3232
|
-
return [3 /*break*/, 47];
|
|
3233
|
-
case 46:
|
|
3234
|
-
try {
|
|
3235
|
-
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
3236
|
-
}
|
|
3237
|
-
finally { if (e_6) throw e_6.error; }
|
|
3238
|
-
return [7 /*endfinally*/];
|
|
3239
|
-
case 47:
|
|
3240
|
-
// TODO: [π] Unite object for expecting amount and format
|
|
3241
|
-
if (currentTemplate.expectFormat) {
|
|
3242
|
-
if (currentTemplate.expectFormat === 'JSON') {
|
|
3243
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3244
|
-
throw new ExpectError('Expected valid JSON string');
|
|
3245
|
-
}
|
|
3246
|
-
}
|
|
3247
|
-
}
|
|
3248
|
-
// TODO: [π] Unite object for expecting amount and format
|
|
3249
|
-
if (currentTemplate.expectations) {
|
|
3250
|
-
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3251
|
-
}
|
|
3252
|
-
return [3 /*break*/, 52];
|
|
3253
|
-
case 48:
|
|
3254
|
-
error_4 = _u.sent();
|
|
3255
|
-
if (!(error_4 instanceof ExpectError)) {
|
|
3256
|
-
throw error_4;
|
|
3257
|
-
}
|
|
3258
|
-
expectError = error_4;
|
|
3259
|
-
return [3 /*break*/, 50];
|
|
3260
|
-
case 49:
|
|
3261
|
-
if (!isJokerAttempt &&
|
|
3262
|
-
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
3263
|
-
prompt
|
|
3264
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3265
|
-
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3266
|
-
) {
|
|
3267
|
-
// TODO: [π§ ] Maybe put other blockTypes into report
|
|
3268
|
-
executionReport.promptExecutions.push({
|
|
3269
|
-
prompt: __assign({}, prompt),
|
|
3270
|
-
result: result || undefined,
|
|
3271
|
-
error: expectError === null ? undefined : serializeError(expectError),
|
|
3272
|
-
});
|
|
3273
|
-
}
|
|
3274
|
-
return [7 /*endfinally*/];
|
|
3275
|
-
case 50:
|
|
3276
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3277
|
-
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 "); }));
|
|
3278
|
-
}
|
|
3279
|
-
_u.label = 51;
|
|
3280
|
-
case 51:
|
|
3281
3312
|
attempt++;
|
|
3282
3313
|
return [3 /*break*/, 4];
|
|
3283
|
-
case
|
|
3314
|
+
case 7:
|
|
3284
3315
|
if (resultString === null) {
|
|
3285
|
-
throw new UnexpectedError(
|
|
3316
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3286
3317
|
}
|
|
3287
3318
|
if (onProgress /* <- [3] */) {
|
|
3288
3319
|
onProgress({
|
|
@@ -3296,7 +3327,7 @@
|
|
|
3296
3327
|
// <- [3]
|
|
3297
3328
|
});
|
|
3298
3329
|
}
|
|
3299
|
-
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (
|
|
3330
|
+
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)));
|
|
3300
3331
|
return [2 /*return*/];
|
|
3301
3332
|
}
|
|
3302
3333
|
});
|
|
@@ -3305,6 +3336,14 @@
|
|
|
3305
3336
|
function filterJustOutputParameters() {
|
|
3306
3337
|
var e_8, _a;
|
|
3307
3338
|
var outputParameters = {};
|
|
3339
|
+
var _loop_6 = function (parameter) {
|
|
3340
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3341
|
+
// [4]
|
|
3342
|
+
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 "); })));
|
|
3343
|
+
return "continue";
|
|
3344
|
+
}
|
|
3345
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3346
|
+
};
|
|
3308
3347
|
try {
|
|
3309
3348
|
// Note: Filter ONLY output parameters
|
|
3310
3349
|
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
@@ -3312,12 +3351,7 @@
|
|
|
3312
3351
|
return isOutput;
|
|
3313
3352
|
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3314
3353
|
var parameter = _c.value;
|
|
3315
|
-
|
|
3316
|
-
// [4]
|
|
3317
|
-
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
|
|
3318
|
-
continue;
|
|
3319
|
-
}
|
|
3320
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3354
|
+
_loop_6(parameter);
|
|
3321
3355
|
}
|
|
3322
3356
|
}
|
|
3323
3357
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
@@ -3389,13 +3423,13 @@
|
|
|
3389
3423
|
return name === parameterName;
|
|
3390
3424
|
});
|
|
3391
3425
|
if (parameter === undefined) {
|
|
3392
|
-
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3426
|
+
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 "); })));
|
|
3393
3427
|
}
|
|
3394
3428
|
else if (parameter.isInput === false) {
|
|
3395
|
-
return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3429
|
+
return { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
3396
3430
|
isSuccessful: false,
|
|
3397
3431
|
errors: __spreadArray([
|
|
3398
|
-
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3432
|
+
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 "); }))
|
|
3399
3433
|
], __read(errors), false).map(serializeError),
|
|
3400
3434
|
warnings: warnings.map(serializeError),
|
|
3401
3435
|
executionReport: executionReport,
|
|
@@ -3444,7 +3478,7 @@
|
|
|
3444
3478
|
case 0:
|
|
3445
3479
|
if (loopLimit-- < 0) {
|
|
3446
3480
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
3447
|
-
throw new UnexpectedError(
|
|
3481
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3448
3482
|
}
|
|
3449
3483
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3450
3484
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -3454,7 +3488,7 @@
|
|
|
3454
3488
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3455
3489
|
throw new UnexpectedError(
|
|
3456
3490
|
// TODO: [π] DRY
|
|
3457
|
-
spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3491
|
+
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
|
|
3458
3492
|
.map(function (_a) {
|
|
3459
3493
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3460
3494
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -3534,6 +3568,7 @@
|
|
|
3534
3568
|
return pipelineExecutor;
|
|
3535
3569
|
}
|
|
3536
3570
|
/**
|
|
3571
|
+
* TODO: !!! Identify not only pipeline BUT exact template ${block(pipelineIdentification)}
|
|
3537
3572
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3538
3573
|
* TODO: [π§ ][π³] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
3539
3574
|
* TODO: [πͺ] Use maxParallelCount here (not only pass to `preparePipeline`)
|