@promptbook/cli 0.69.0-7 β 0.69.0-8
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 +507 -455
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/$OngoingTemplateResult.d.ts +21 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatCells.d.ts +15 -0
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +80 -0
- package/package.json +1 -1
- package/umd/index.umd.js +507 -455
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatCell.d.ts +0 -30
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempt.d.ts +0 -30
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.69.0-
|
|
42
|
+
var PROMPTBOOK_VERSION = '0.69.0-7';
|
|
43
43
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
44
44
|
|
|
45
45
|
/*! *****************************************************************************
|
|
@@ -449,13 +449,13 @@
|
|
|
449
449
|
*
|
|
450
450
|
* @public exported from `@promptbook/core`
|
|
451
451
|
*/
|
|
452
|
-
var MAX_PARALLEL_COUNT = 5;
|
|
452
|
+
var MAX_PARALLEL_COUNT = 5; // <- TODO: [π€ΉββοΈ]
|
|
453
453
|
/**
|
|
454
454
|
* The maximum number of attempts to execute LLM task before giving up
|
|
455
455
|
*
|
|
456
456
|
* @public exported from `@promptbook/core`
|
|
457
457
|
*/
|
|
458
|
-
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
458
|
+
var MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [π€ΉββοΈ]
|
|
459
459
|
/**
|
|
460
460
|
* The maximum length of the (generated) filename
|
|
461
461
|
*
|
|
@@ -1069,7 +1069,7 @@
|
|
|
1069
1069
|
});
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
1072
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-7",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],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.69.0-7",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],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.69.0-7",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],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.69.0-7",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}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",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}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1073
1073
|
|
|
1074
1074
|
/**
|
|
1075
1075
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2248,6 +2248,23 @@
|
|
|
2248
2248
|
* - [β¨] Are templates prepared
|
|
2249
2249
|
*/
|
|
2250
2250
|
|
|
2251
|
+
/**
|
|
2252
|
+
* Serializes an error into a [π] JSON-serializable object
|
|
2253
|
+
*
|
|
2254
|
+
* @public exported from `@promptbook/utils`
|
|
2255
|
+
*/
|
|
2256
|
+
function serializeError(error) {
|
|
2257
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2258
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2259
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2260
|
+
}
|
|
2261
|
+
return {
|
|
2262
|
+
name: name,
|
|
2263
|
+
message: message,
|
|
2264
|
+
stack: stack,
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2251
2268
|
/**
|
|
2252
2269
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2253
2270
|
*
|
|
@@ -2541,23 +2558,6 @@
|
|
|
2541
2558
|
* TODO: [π·ββοΈ] @@@ Manual about construction of llmTools
|
|
2542
2559
|
*/
|
|
2543
2560
|
|
|
2544
|
-
/**
|
|
2545
|
-
* Serializes an error into a [π] JSON-serializable object
|
|
2546
|
-
*
|
|
2547
|
-
* @public exported from `@promptbook/utils`
|
|
2548
|
-
*/
|
|
2549
|
-
function serializeError(error) {
|
|
2550
|
-
var name = error.name, message = error.message, stack = error.stack;
|
|
2551
|
-
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2552
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2553
|
-
}
|
|
2554
|
-
return {
|
|
2555
|
-
name: name,
|
|
2556
|
-
message: message,
|
|
2557
|
-
stack: stack,
|
|
2558
|
-
};
|
|
2559
|
-
}
|
|
2560
|
-
|
|
2561
2561
|
/**
|
|
2562
2562
|
* Takes an item or an array of items and returns an array of items
|
|
2563
2563
|
*
|
|
@@ -2695,6 +2695,81 @@
|
|
|
2695
2695
|
* TODO: [π£] If script require contentLanguage
|
|
2696
2696
|
*/
|
|
2697
2697
|
|
|
2698
|
+
/**
|
|
2699
|
+
* Create difference set of two sets.
|
|
2700
|
+
*
|
|
2701
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2702
|
+
* @public exported from `@promptbook/utils`
|
|
2703
|
+
*/
|
|
2704
|
+
function difference(a, b, isEqual) {
|
|
2705
|
+
var e_1, _a;
|
|
2706
|
+
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
2707
|
+
var diff = new Set();
|
|
2708
|
+
var _loop_1 = function (itemA) {
|
|
2709
|
+
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
2710
|
+
diff.add(itemA);
|
|
2711
|
+
}
|
|
2712
|
+
};
|
|
2713
|
+
try {
|
|
2714
|
+
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2715
|
+
var itemA = _c.value;
|
|
2716
|
+
_loop_1(itemA);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2720
|
+
finally {
|
|
2721
|
+
try {
|
|
2722
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2723
|
+
}
|
|
2724
|
+
finally { if (e_1) throw e_1.error; }
|
|
2725
|
+
}
|
|
2726
|
+
return diff;
|
|
2727
|
+
}
|
|
2728
|
+
/**
|
|
2729
|
+
* TODO: [π§ ][π―] Maybe also implement symmetricDifference
|
|
2730
|
+
*/
|
|
2731
|
+
|
|
2732
|
+
/**
|
|
2733
|
+
* Creates a new set with all elements that are present in either set
|
|
2734
|
+
*
|
|
2735
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2736
|
+
* @public exported from `@promptbook/utils`
|
|
2737
|
+
*/
|
|
2738
|
+
function union() {
|
|
2739
|
+
var e_1, _a, e_2, _b;
|
|
2740
|
+
var sets = [];
|
|
2741
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2742
|
+
sets[_i] = arguments[_i];
|
|
2743
|
+
}
|
|
2744
|
+
var union = new Set();
|
|
2745
|
+
try {
|
|
2746
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2747
|
+
var set = sets_1_1.value;
|
|
2748
|
+
try {
|
|
2749
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2750
|
+
var item = _d.value;
|
|
2751
|
+
union.add(item);
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2755
|
+
finally {
|
|
2756
|
+
try {
|
|
2757
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
2758
|
+
}
|
|
2759
|
+
finally { if (e_2) throw e_2.error; }
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2764
|
+
finally {
|
|
2765
|
+
try {
|
|
2766
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
2767
|
+
}
|
|
2768
|
+
finally { if (e_1) throw e_1.error; }
|
|
2769
|
+
}
|
|
2770
|
+
return union;
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2698
2773
|
/**
|
|
2699
2774
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2700
2775
|
*
|
|
@@ -2932,81 +3007,6 @@
|
|
|
2932
3007
|
return replacedTemplate;
|
|
2933
3008
|
}
|
|
2934
3009
|
|
|
2935
|
-
/**
|
|
2936
|
-
* Create difference set of two sets.
|
|
2937
|
-
*
|
|
2938
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2939
|
-
* @public exported from `@promptbook/utils`
|
|
2940
|
-
*/
|
|
2941
|
-
function difference(a, b, isEqual) {
|
|
2942
|
-
var e_1, _a;
|
|
2943
|
-
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
2944
|
-
var diff = new Set();
|
|
2945
|
-
var _loop_1 = function (itemA) {
|
|
2946
|
-
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
2947
|
-
diff.add(itemA);
|
|
2948
|
-
}
|
|
2949
|
-
};
|
|
2950
|
-
try {
|
|
2951
|
-
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2952
|
-
var itemA = _c.value;
|
|
2953
|
-
_loop_1(itemA);
|
|
2954
|
-
}
|
|
2955
|
-
}
|
|
2956
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2957
|
-
finally {
|
|
2958
|
-
try {
|
|
2959
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2960
|
-
}
|
|
2961
|
-
finally { if (e_1) throw e_1.error; }
|
|
2962
|
-
}
|
|
2963
|
-
return diff;
|
|
2964
|
-
}
|
|
2965
|
-
/**
|
|
2966
|
-
* TODO: [π§ ][π―] Maybe also implement symmetricDifference
|
|
2967
|
-
*/
|
|
2968
|
-
|
|
2969
|
-
/**
|
|
2970
|
-
* Creates a new set with all elements that are present in either set
|
|
2971
|
-
*
|
|
2972
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2973
|
-
* @public exported from `@promptbook/utils`
|
|
2974
|
-
*/
|
|
2975
|
-
function union() {
|
|
2976
|
-
var e_1, _a, e_2, _b;
|
|
2977
|
-
var sets = [];
|
|
2978
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2979
|
-
sets[_i] = arguments[_i];
|
|
2980
|
-
}
|
|
2981
|
-
var union = new Set();
|
|
2982
|
-
try {
|
|
2983
|
-
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2984
|
-
var set = sets_1_1.value;
|
|
2985
|
-
try {
|
|
2986
|
-
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2987
|
-
var item = _d.value;
|
|
2988
|
-
union.add(item);
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2992
|
-
finally {
|
|
2993
|
-
try {
|
|
2994
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
2995
|
-
}
|
|
2996
|
-
finally { if (e_2) throw e_2.error; }
|
|
2997
|
-
}
|
|
2998
|
-
}
|
|
2999
|
-
}
|
|
3000
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3001
|
-
finally {
|
|
3002
|
-
try {
|
|
3003
|
-
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
3004
|
-
}
|
|
3005
|
-
finally { if (e_1) throw e_1.error; }
|
|
3006
|
-
}
|
|
3007
|
-
return union;
|
|
3008
|
-
}
|
|
3009
|
-
|
|
3010
3010
|
/**
|
|
3011
3011
|
* Counts number of characters in the text
|
|
3012
3012
|
*
|
|
@@ -3134,249 +3134,49 @@
|
|
|
3134
3134
|
* TODO: [π] Unite object for expecting amount and format
|
|
3135
3135
|
*/
|
|
3136
3136
|
|
|
3137
|
-
/**
|
|
3138
|
-
* Just marks a place of place where should be something implemented
|
|
3139
|
-
* No side effects.
|
|
3140
|
-
*
|
|
3141
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
3142
|
-
*
|
|
3143
|
-
* @param value any values
|
|
3144
|
-
* @returns void
|
|
3145
|
-
* @private within the repository
|
|
3146
|
-
*/
|
|
3147
|
-
function TODO_USE() {
|
|
3148
|
-
var value = [];
|
|
3149
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3150
|
-
value[_i] = arguments[_i];
|
|
3151
|
-
}
|
|
3152
|
-
}
|
|
3153
|
-
|
|
3154
|
-
/**
|
|
3155
|
-
* @@@
|
|
3156
|
-
*
|
|
3157
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3158
|
-
*/
|
|
3159
|
-
function getContextForTemplate(template) {
|
|
3160
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3161
|
-
return __generator(this, function (_a) {
|
|
3162
|
-
TODO_USE(template);
|
|
3163
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [π] Implement */];
|
|
3164
|
-
});
|
|
3165
|
-
});
|
|
3166
|
-
}
|
|
3167
|
-
|
|
3168
|
-
/**
|
|
3169
|
-
* @@@
|
|
3170
|
-
*
|
|
3171
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3172
|
-
*/
|
|
3173
|
-
function getKnowledgeForTemplate(options) {
|
|
3174
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3175
|
-
var preparedPipeline, template;
|
|
3176
|
-
return __generator(this, function (_a) {
|
|
3177
|
-
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3178
|
-
// TODO: [β¨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3179
|
-
TODO_USE(template);
|
|
3180
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3181
|
-
var content = _a.content;
|
|
3182
|
-
return "- ".concat(content);
|
|
3183
|
-
}).join('\n')];
|
|
3184
|
-
});
|
|
3185
|
-
});
|
|
3186
|
-
}
|
|
3187
|
-
|
|
3188
3137
|
/**
|
|
3189
3138
|
* @@@
|
|
3190
3139
|
*
|
|
3191
3140
|
* @private internal utility of `createPipelineExecutor`
|
|
3192
3141
|
*/
|
|
3193
|
-
function
|
|
3142
|
+
function executeAttempts(options) {
|
|
3194
3143
|
return __awaiter(this, void 0, void 0, function () {
|
|
3144
|
+
var $ongoingTemplateResult, jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, llmTools, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, _loop_1, attempt, state_1;
|
|
3195
3145
|
return __generator(this, function (_a) {
|
|
3196
|
-
|
|
3197
|
-
TODO_USE(template);
|
|
3198
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [β¨] Implement */];
|
|
3199
|
-
});
|
|
3200
|
-
});
|
|
3201
|
-
}
|
|
3202
|
-
|
|
3203
|
-
/**
|
|
3204
|
-
* @@@
|
|
3205
|
-
*
|
|
3206
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3207
|
-
*/
|
|
3208
|
-
function getReservedParametersForTemplate(options) {
|
|
3209
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3210
|
-
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3211
|
-
var e_1, _a;
|
|
3212
|
-
return __generator(this, function (_b) {
|
|
3213
|
-
switch (_b.label) {
|
|
3146
|
+
switch (_a.label) {
|
|
3214
3147
|
case 0:
|
|
3215
|
-
|
|
3216
|
-
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3217
|
-
case 1:
|
|
3218
|
-
context = _b.sent();
|
|
3219
|
-
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3220
|
-
case 2:
|
|
3221
|
-
knowledge = _b.sent();
|
|
3222
|
-
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3223
|
-
case 3:
|
|
3224
|
-
samples = _b.sent();
|
|
3225
|
-
currentDate = new Date().toISOString();
|
|
3226
|
-
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3227
|
-
reservedParameters = {
|
|
3228
|
-
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3229
|
-
context: context,
|
|
3230
|
-
knowledge: knowledge,
|
|
3231
|
-
samples: samples,
|
|
3232
|
-
currentDate: currentDate,
|
|
3233
|
-
modelName: modelName,
|
|
3234
|
-
};
|
|
3235
|
-
_loop_1 = function (parameterName) {
|
|
3236
|
-
if (reservedParameters[parameterName] === undefined) {
|
|
3237
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3238
|
-
}
|
|
3239
|
-
};
|
|
3240
|
-
try {
|
|
3241
|
-
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3242
|
-
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()) {
|
|
3243
|
-
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3244
|
-
_loop_1(parameterName);
|
|
3245
|
-
}
|
|
3246
|
-
}
|
|
3247
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3248
|
-
finally {
|
|
3249
|
-
try {
|
|
3250
|
-
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3251
|
-
}
|
|
3252
|
-
finally { if (e_1) throw e_1.error; }
|
|
3253
|
-
}
|
|
3254
|
-
return [2 /*return*/, reservedParameters];
|
|
3255
|
-
}
|
|
3256
|
-
});
|
|
3257
|
-
});
|
|
3258
|
-
}
|
|
3259
|
-
|
|
3260
|
-
/**
|
|
3261
|
-
* @@@
|
|
3262
|
-
*
|
|
3263
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3264
|
-
*/
|
|
3265
|
-
function executeTemplate(options) {
|
|
3266
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3267
|
-
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, $ongoingResult, maxAttempts, jokerParameterNames, preparedContent, _loop_2, attempt, state_1;
|
|
3268
|
-
var e_1, _f, _g;
|
|
3269
|
-
return __generator(this, function (_h) {
|
|
3270
|
-
switch (_h.label) {
|
|
3271
|
-
case 0:
|
|
3272
|
-
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
|
|
3148
|
+
$ongoingTemplateResult = options.$ongoingTemplateResult, jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools, llmTools = options.llmTools, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
|
|
3273
3149
|
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
title: title,
|
|
3280
|
-
isStarted: false,
|
|
3281
|
-
isDone: false,
|
|
3282
|
-
templateType: currentTemplate.templateType,
|
|
3283
|
-
parameterName: currentTemplate.resultingParameterName,
|
|
3284
|
-
parameterValue: null,
|
|
3285
|
-
// <- [πΈ]
|
|
3286
|
-
})];
|
|
3287
|
-
case 1:
|
|
3288
|
-
_h.sent();
|
|
3289
|
-
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3290
|
-
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3291
|
-
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3292
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
|
|
3293
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3294
|
-
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3295
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3296
|
-
.join(', '), "\n\n "); }));
|
|
3297
|
-
}
|
|
3298
|
-
_b = (_a = Object).freeze;
|
|
3299
|
-
_c = [{}];
|
|
3300
|
-
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3301
|
-
preparedPipeline: preparedPipeline,
|
|
3302
|
-
template: currentTemplate,
|
|
3303
|
-
pipelineIdentification: pipelineIdentification,
|
|
3304
|
-
})];
|
|
3305
|
-
case 2:
|
|
3306
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3307
|
-
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3308
|
-
parameters = {};
|
|
3309
|
-
_loop_1 = function (parameterName) {
|
|
3310
|
-
// Situation: Parameter is defined and used
|
|
3311
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3312
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3313
|
-
}
|
|
3314
|
-
// Situation: Parameter is defined but NOT used
|
|
3315
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3316
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3317
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3318
|
-
// Houston, we have a problem
|
|
3319
|
-
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3320
|
-
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 "); }));
|
|
3321
|
-
}
|
|
3322
|
-
};
|
|
3323
|
-
try {
|
|
3324
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3325
|
-
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3326
|
-
parameterName = _e.value;
|
|
3327
|
-
_loop_1(parameterName);
|
|
3328
|
-
}
|
|
3329
|
-
}
|
|
3330
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3331
|
-
finally {
|
|
3332
|
-
try {
|
|
3333
|
-
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3334
|
-
}
|
|
3335
|
-
finally { if (e_1) throw e_1.error; }
|
|
3336
|
-
}
|
|
3337
|
-
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
3338
|
-
Object.freeze(parameters);
|
|
3339
|
-
$ongoingResult = {
|
|
3340
|
-
$result: null,
|
|
3341
|
-
$resultString: null,
|
|
3342
|
-
$expectError: null,
|
|
3343
|
-
$scriptPipelineExecutionErrors: [],
|
|
3344
|
-
};
|
|
3345
|
-
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3346
|
-
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3347
|
-
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3348
|
-
.split('{content}')
|
|
3349
|
-
.join(currentTemplate.content);
|
|
3350
|
-
_loop_2 = function (attempt) {
|
|
3351
|
-
var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, _o, _p, _q, scriptTools, _r, error_1, e_2_1, _s, _t, _u, functionName, postprocessingError, _v, _w, scriptTools, _x, error_2, e_3_1, e_4_1, error_3;
|
|
3352
|
-
var e_2, _y, e_4, _z, e_3, _0;
|
|
3353
|
-
return __generator(this, function (_1) {
|
|
3354
|
-
switch (_1.label) {
|
|
3150
|
+
_loop_1 = function (attempt) {
|
|
3151
|
+
var isJokerAttempt, jokerParameterName, _b, modelRequirements, _c, _d, _e, _f, _g, _h, scriptTools, _j, error_1, e_1_1, _k, _l, _m, functionName, postprocessingError, _o, _p, scriptTools, _q, error_2, e_2_1, e_3_1, error_3;
|
|
3152
|
+
var e_1, _r, e_3, _s, e_2, _t;
|
|
3153
|
+
return __generator(this, function (_u) {
|
|
3154
|
+
switch (_u.label) {
|
|
3355
3155
|
case 0:
|
|
3356
3156
|
isJokerAttempt = attempt < 0;
|
|
3357
3157
|
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3358
3158
|
// TODO: [π§ ] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3359
3159
|
if (isJokerAttempt && !jokerParameterName) {
|
|
3360
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3160
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3361
3161
|
}
|
|
3362
|
-
$
|
|
3363
|
-
$
|
|
3364
|
-
$
|
|
3162
|
+
$ongoingTemplateResult.$result = null;
|
|
3163
|
+
$ongoingTemplateResult.$resultString = null;
|
|
3164
|
+
$ongoingTemplateResult.$expectError = null;
|
|
3365
3165
|
if (isJokerAttempt) {
|
|
3366
3166
|
if (parameters[jokerParameterName] === undefined) {
|
|
3367
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3167
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3368
3168
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3369
3169
|
}
|
|
3370
3170
|
else {
|
|
3371
|
-
$
|
|
3171
|
+
$ongoingTemplateResult.$resultString = parameters[jokerParameterName];
|
|
3372
3172
|
}
|
|
3373
3173
|
}
|
|
3374
|
-
|
|
3174
|
+
_u.label = 1;
|
|
3375
3175
|
case 1:
|
|
3376
|
-
|
|
3176
|
+
_u.trys.push([1, 44, 45, 46]);
|
|
3377
3177
|
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3378
|
-
|
|
3379
|
-
switch (
|
|
3178
|
+
_b = template.templateType;
|
|
3179
|
+
switch (_b) {
|
|
3380
3180
|
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3381
3181
|
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3382
3182
|
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
@@ -3384,133 +3184,136 @@
|
|
|
3384
3184
|
}
|
|
3385
3185
|
return [3 /*break*/, 25];
|
|
3386
3186
|
case 2:
|
|
3387
|
-
$
|
|
3187
|
+
$ongoingTemplateResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
3388
3188
|
return [3 /*break*/, 26];
|
|
3389
3189
|
case 3:
|
|
3390
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (
|
|
3391
|
-
$
|
|
3392
|
-
title:
|
|
3190
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (template.modelRequirements || {}));
|
|
3191
|
+
$ongoingTemplateResult.$prompt = {
|
|
3192
|
+
title: template.title,
|
|
3393
3193
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3394
3194
|
? preparedPipeline.pipelineUrl
|
|
3395
|
-
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(
|
|
3195
|
+
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name),
|
|
3396
3196
|
parameters: parameters,
|
|
3397
3197
|
content: preparedContent,
|
|
3398
3198
|
modelRequirements: modelRequirements,
|
|
3399
3199
|
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3400
3200
|
var name = _a.name;
|
|
3401
|
-
return name ===
|
|
3402
|
-
}) ||
|
|
3403
|
-
|
|
3404
|
-
|
|
3201
|
+
return name === template.personaName;
|
|
3202
|
+
}) ||
|
|
3203
|
+
{})), template.expectations),
|
|
3204
|
+
format: template.format,
|
|
3205
|
+
postprocessingFunctionNames: template.postprocessingFunctionNames,
|
|
3405
3206
|
}; // <- TODO: Not very good type guard
|
|
3406
|
-
|
|
3407
|
-
switch (
|
|
3207
|
+
_c = modelRequirements.modelVariant;
|
|
3208
|
+
switch (_c) {
|
|
3408
3209
|
case 'CHAT': return [3 /*break*/, 4];
|
|
3409
3210
|
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3410
3211
|
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3411
3212
|
}
|
|
3412
3213
|
return [3 /*break*/, 10];
|
|
3413
3214
|
case 4:
|
|
3414
|
-
|
|
3415
|
-
return [4 /*yield*/, llmTools.callChatModel($deepFreeze($
|
|
3215
|
+
_d = $ongoingTemplateResult;
|
|
3216
|
+
return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3416
3217
|
case 5:
|
|
3417
|
-
|
|
3218
|
+
_d.$chatResult = _u.sent();
|
|
3418
3219
|
// TODO: [π¬] Destroy chatThread
|
|
3419
|
-
$
|
|
3420
|
-
$
|
|
3220
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$chatResult;
|
|
3221
|
+
$ongoingTemplateResult.$resultString = $ongoingTemplateResult.$chatResult.content;
|
|
3421
3222
|
return [3 /*break*/, 11];
|
|
3422
3223
|
case 6:
|
|
3423
|
-
|
|
3424
|
-
return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($
|
|
3224
|
+
_e = $ongoingTemplateResult;
|
|
3225
|
+
return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3425
3226
|
case 7:
|
|
3426
|
-
|
|
3427
|
-
$
|
|
3428
|
-
$
|
|
3227
|
+
_e.$completionResult = _u.sent();
|
|
3228
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$completionResult;
|
|
3229
|
+
$ongoingTemplateResult.$resultString =
|
|
3230
|
+
$ongoingTemplateResult.$completionResult.content;
|
|
3429
3231
|
return [3 /*break*/, 11];
|
|
3430
3232
|
case 8:
|
|
3431
3233
|
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3432
|
-
|
|
3433
|
-
return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($
|
|
3234
|
+
_f = $ongoingTemplateResult;
|
|
3235
|
+
return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3434
3236
|
case 9:
|
|
3435
3237
|
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3436
|
-
|
|
3437
|
-
$
|
|
3438
|
-
$
|
|
3238
|
+
_f.$embeddingResult = _u.sent();
|
|
3239
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$embeddingResult;
|
|
3240
|
+
$ongoingTemplateResult.$resultString =
|
|
3241
|
+
$ongoingTemplateResult.$embeddingResult.content.join(',');
|
|
3439
3242
|
return [3 /*break*/, 11];
|
|
3440
|
-
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3243
|
+
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(template.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3441
3244
|
case 11: return [3 /*break*/, 26];
|
|
3442
3245
|
case 12:
|
|
3443
3246
|
if (arrayableToArray(tools.script).length === 0) {
|
|
3444
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3247
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3445
3248
|
}
|
|
3446
|
-
if (!
|
|
3447
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3249
|
+
if (!template.contentLanguage) {
|
|
3250
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(template.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3448
3251
|
}
|
|
3449
|
-
|
|
3252
|
+
_u.label = 13;
|
|
3450
3253
|
case 13:
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3254
|
+
_u.trys.push([13, 20, 21, 22]);
|
|
3255
|
+
_g = (e_1 = void 0, __values(arrayableToArray(tools.script))), _h = _g.next();
|
|
3256
|
+
_u.label = 14;
|
|
3454
3257
|
case 14:
|
|
3455
|
-
if (!!
|
|
3456
|
-
scriptTools =
|
|
3457
|
-
|
|
3258
|
+
if (!!_h.done) return [3 /*break*/, 19];
|
|
3259
|
+
scriptTools = _h.value;
|
|
3260
|
+
_u.label = 15;
|
|
3458
3261
|
case 15:
|
|
3459
|
-
|
|
3460
|
-
|
|
3262
|
+
_u.trys.push([15, 17, , 18]);
|
|
3263
|
+
_j = $ongoingTemplateResult;
|
|
3461
3264
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3462
|
-
scriptLanguage:
|
|
3265
|
+
scriptLanguage: template.contentLanguage,
|
|
3463
3266
|
script: preparedContent,
|
|
3464
3267
|
parameters: parameters,
|
|
3465
3268
|
}))];
|
|
3466
3269
|
case 16:
|
|
3467
|
-
|
|
3270
|
+
_j.$resultString = _u.sent();
|
|
3468
3271
|
return [3 /*break*/, 19];
|
|
3469
3272
|
case 17:
|
|
3470
|
-
error_1 =
|
|
3273
|
+
error_1 = _u.sent();
|
|
3471
3274
|
if (!(error_1 instanceof Error)) {
|
|
3472
3275
|
throw error_1;
|
|
3473
3276
|
}
|
|
3474
3277
|
if (error_1 instanceof UnexpectedError) {
|
|
3475
3278
|
throw error_1;
|
|
3476
3279
|
}
|
|
3477
|
-
$
|
|
3280
|
+
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
3478
3281
|
return [3 /*break*/, 18];
|
|
3479
3282
|
case 18:
|
|
3480
|
-
|
|
3283
|
+
_h = _g.next();
|
|
3481
3284
|
return [3 /*break*/, 14];
|
|
3482
3285
|
case 19: return [3 /*break*/, 22];
|
|
3483
3286
|
case 20:
|
|
3484
|
-
|
|
3485
|
-
|
|
3287
|
+
e_1_1 = _u.sent();
|
|
3288
|
+
e_1 = { error: e_1_1 };
|
|
3486
3289
|
return [3 /*break*/, 22];
|
|
3487
3290
|
case 21:
|
|
3488
3291
|
try {
|
|
3489
|
-
if (
|
|
3292
|
+
if (_h && !_h.done && (_r = _g.return)) _r.call(_g);
|
|
3490
3293
|
}
|
|
3491
|
-
finally { if (
|
|
3294
|
+
finally { if (e_1) throw e_1.error; }
|
|
3492
3295
|
return [7 /*endfinally*/];
|
|
3493
3296
|
case 22:
|
|
3494
|
-
if ($
|
|
3297
|
+
if ($ongoingTemplateResult.$resultString !== null) {
|
|
3495
3298
|
return [3 /*break*/, 26];
|
|
3496
3299
|
}
|
|
3497
|
-
if ($
|
|
3498
|
-
throw $
|
|
3300
|
+
if ($ongoingTemplateResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
3301
|
+
throw $ongoingTemplateResult.$scriptPipelineExecutionErrors[0];
|
|
3499
3302
|
}
|
|
3500
3303
|
else {
|
|
3501
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3304
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingTemplateResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTemplateResult.$scriptPipelineExecutionErrors
|
|
3502
3305
|
.map(function (error) { return '- ' + error.message; })
|
|
3503
|
-
.join('\n\n')), "\n
|
|
3306
|
+
.join('\n\n')), "\n "); }));
|
|
3504
3307
|
}
|
|
3505
3308
|
case 23:
|
|
3506
3309
|
if (tools.userInterface === undefined) {
|
|
3507
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3310
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3508
3311
|
}
|
|
3509
3312
|
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3510
|
-
|
|
3313
|
+
_k = $ongoingTemplateResult;
|
|
3511
3314
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3512
|
-
promptTitle:
|
|
3513
|
-
promptMessage: replaceParameters(
|
|
3315
|
+
promptTitle: template.title,
|
|
3316
|
+
promptMessage: replaceParameters(template.description || '', parameters),
|
|
3514
3317
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3515
3318
|
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3516
3319
|
placeholder: undefined,
|
|
@@ -3518,46 +3321,46 @@
|
|
|
3518
3321
|
}))];
|
|
3519
3322
|
case 24:
|
|
3520
3323
|
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3521
|
-
|
|
3324
|
+
_k.$resultString = _u.sent();
|
|
3522
3325
|
return [3 /*break*/, 26];
|
|
3523
|
-
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3326
|
+
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(template.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3524
3327
|
case 26:
|
|
3525
|
-
if (!(!isJokerAttempt &&
|
|
3526
|
-
|
|
3328
|
+
if (!(!isJokerAttempt && template.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3329
|
+
_u.label = 27;
|
|
3527
3330
|
case 27:
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3331
|
+
_u.trys.push([27, 41, 42, 43]);
|
|
3332
|
+
_l = (e_3 = void 0, __values(template.postprocessingFunctionNames)), _m = _l.next();
|
|
3333
|
+
_u.label = 28;
|
|
3531
3334
|
case 28:
|
|
3532
|
-
if (!!
|
|
3533
|
-
functionName =
|
|
3335
|
+
if (!!_m.done) return [3 /*break*/, 40];
|
|
3336
|
+
functionName = _m.value;
|
|
3534
3337
|
postprocessingError = null;
|
|
3535
|
-
|
|
3338
|
+
_u.label = 29;
|
|
3536
3339
|
case 29:
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3340
|
+
_u.trys.push([29, 36, 37, 38]);
|
|
3341
|
+
_o = (e_2 = void 0, __values(arrayableToArray(tools.script))), _p = _o.next();
|
|
3342
|
+
_u.label = 30;
|
|
3540
3343
|
case 30:
|
|
3541
|
-
if (!!
|
|
3542
|
-
scriptTools =
|
|
3543
|
-
|
|
3344
|
+
if (!!_p.done) return [3 /*break*/, 35];
|
|
3345
|
+
scriptTools = _p.value;
|
|
3346
|
+
_u.label = 31;
|
|
3544
3347
|
case 31:
|
|
3545
|
-
|
|
3546
|
-
|
|
3348
|
+
_u.trys.push([31, 33, , 34]);
|
|
3349
|
+
_q = $ongoingTemplateResult;
|
|
3547
3350
|
return [4 /*yield*/, scriptTools.execute({
|
|
3548
3351
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3549
3352
|
script: "".concat(functionName, "(resultString)"),
|
|
3550
3353
|
parameters: {
|
|
3551
|
-
resultString: $
|
|
3354
|
+
resultString: $ongoingTemplateResult.$resultString || '',
|
|
3552
3355
|
// Note: No ...parametersForTemplate, because working with result only
|
|
3553
3356
|
},
|
|
3554
3357
|
})];
|
|
3555
3358
|
case 32:
|
|
3556
|
-
|
|
3359
|
+
_q.$resultString = _u.sent();
|
|
3557
3360
|
postprocessingError = null;
|
|
3558
3361
|
return [3 /*break*/, 35];
|
|
3559
3362
|
case 33:
|
|
3560
|
-
error_2 =
|
|
3363
|
+
error_2 = _u.sent();
|
|
3561
3364
|
if (!(error_2 instanceof Error)) {
|
|
3562
3365
|
throw error_2;
|
|
3563
3366
|
}
|
|
@@ -3565,104 +3368,106 @@
|
|
|
3565
3368
|
throw error_2;
|
|
3566
3369
|
}
|
|
3567
3370
|
postprocessingError = error_2;
|
|
3568
|
-
$
|
|
3371
|
+
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
3569
3372
|
return [3 /*break*/, 34];
|
|
3570
3373
|
case 34:
|
|
3571
|
-
|
|
3374
|
+
_p = _o.next();
|
|
3572
3375
|
return [3 /*break*/, 30];
|
|
3573
3376
|
case 35: return [3 /*break*/, 38];
|
|
3574
3377
|
case 36:
|
|
3575
|
-
|
|
3576
|
-
|
|
3378
|
+
e_2_1 = _u.sent();
|
|
3379
|
+
e_2 = { error: e_2_1 };
|
|
3577
3380
|
return [3 /*break*/, 38];
|
|
3578
3381
|
case 37:
|
|
3579
3382
|
try {
|
|
3580
|
-
if (
|
|
3383
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3581
3384
|
}
|
|
3582
|
-
finally { if (
|
|
3385
|
+
finally { if (e_2) throw e_2.error; }
|
|
3583
3386
|
return [7 /*endfinally*/];
|
|
3584
3387
|
case 38:
|
|
3585
3388
|
if (postprocessingError) {
|
|
3586
3389
|
throw postprocessingError;
|
|
3587
3390
|
}
|
|
3588
|
-
|
|
3391
|
+
_u.label = 39;
|
|
3589
3392
|
case 39:
|
|
3590
|
-
|
|
3393
|
+
_m = _l.next();
|
|
3591
3394
|
return [3 /*break*/, 28];
|
|
3592
3395
|
case 40: return [3 /*break*/, 43];
|
|
3593
3396
|
case 41:
|
|
3594
|
-
|
|
3595
|
-
|
|
3397
|
+
e_3_1 = _u.sent();
|
|
3398
|
+
e_3 = { error: e_3_1 };
|
|
3596
3399
|
return [3 /*break*/, 43];
|
|
3597
3400
|
case 42:
|
|
3598
3401
|
try {
|
|
3599
|
-
if (
|
|
3402
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3600
3403
|
}
|
|
3601
|
-
finally { if (
|
|
3404
|
+
finally { if (e_3) throw e_3.error; }
|
|
3602
3405
|
return [7 /*endfinally*/];
|
|
3603
3406
|
case 43:
|
|
3604
3407
|
// TODO: [π] Unite object for expecting amount and format
|
|
3605
|
-
if (
|
|
3606
|
-
if (
|
|
3607
|
-
if (!isValidJsonString($
|
|
3408
|
+
if (template.format) {
|
|
3409
|
+
if (template.format === 'JSON') {
|
|
3410
|
+
if (!isValidJsonString($ongoingTemplateResult.$resultString || '')) {
|
|
3608
3411
|
// TODO: [π’] Do more universally via `FormatDefinition`
|
|
3609
3412
|
try {
|
|
3610
|
-
$
|
|
3413
|
+
$ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
|
|
3611
3414
|
}
|
|
3612
3415
|
catch (error) {
|
|
3613
3416
|
keepUnused(error);
|
|
3614
|
-
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3615
|
-
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n
|
|
3417
|
+
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3418
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3616
3419
|
}
|
|
3617
3420
|
}
|
|
3618
3421
|
}
|
|
3619
3422
|
else {
|
|
3620
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3423
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(template.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3621
3424
|
}
|
|
3622
3425
|
}
|
|
3623
3426
|
// TODO: [π] Unite object for expecting amount and format
|
|
3624
|
-
if (
|
|
3625
|
-
checkExpectations(
|
|
3427
|
+
if (template.expectations) {
|
|
3428
|
+
checkExpectations(template.expectations, $ongoingTemplateResult.$resultString || '');
|
|
3626
3429
|
}
|
|
3627
3430
|
return [2 /*return*/, "break-attempts"];
|
|
3628
3431
|
case 44:
|
|
3629
|
-
error_3 =
|
|
3432
|
+
error_3 = _u.sent();
|
|
3630
3433
|
if (!(error_3 instanceof ExpectError)) {
|
|
3631
3434
|
throw error_3;
|
|
3632
3435
|
}
|
|
3633
|
-
$
|
|
3436
|
+
$ongoingTemplateResult.$expectError = error_3;
|
|
3634
3437
|
return [3 /*break*/, 46];
|
|
3635
3438
|
case 45:
|
|
3636
3439
|
if (!isJokerAttempt &&
|
|
3637
|
-
|
|
3638
|
-
$
|
|
3440
|
+
template.templateType === 'PROMPT_TEMPLATE' &&
|
|
3441
|
+
$ongoingTemplateResult.$prompt
|
|
3639
3442
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3640
3443
|
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3641
3444
|
) {
|
|
3642
3445
|
// TODO: [π§ ] Maybe put other templateTypes into report
|
|
3643
3446
|
$executionReport.promptExecutions.push({
|
|
3644
|
-
prompt: __assign({}, $
|
|
3645
|
-
result: $
|
|
3646
|
-
error: $
|
|
3447
|
+
prompt: __assign({}, $ongoingTemplateResult.$prompt),
|
|
3448
|
+
result: $ongoingTemplateResult.$result || undefined,
|
|
3449
|
+
error: $ongoingTemplateResult.$expectError === null
|
|
3450
|
+
? undefined
|
|
3451
|
+
: serializeError($ongoingTemplateResult.$expectError),
|
|
3647
3452
|
});
|
|
3648
3453
|
}
|
|
3649
3454
|
return [7 /*endfinally*/];
|
|
3650
3455
|
case 46:
|
|
3651
|
-
if ($
|
|
3456
|
+
if ($ongoingTemplateResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
3652
3457
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
|
|
3653
3458
|
var _a, _b, _c;
|
|
3654
|
-
return "\n
|
|
3459
|
+
return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTemplateResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
|
|
3655
3460
|
.split('\n')
|
|
3656
3461
|
.map(function (line) { return "> ".concat(line); })
|
|
3657
|
-
.join('\n')), "\n\n
|
|
3462
|
+
.join('\n')), "\n\n Last error ").concat(((_b = $ongoingTemplateResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingTemplateResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
|
|
3658
3463
|
.split('\n')
|
|
3659
3464
|
.map(function (line) { return "> ".concat(line); })
|
|
3660
|
-
.join('\n')), "\n\n
|
|
3465
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
|
|
3661
3466
|
? 'null'
|
|
3662
|
-
: $
|
|
3467
|
+
: $ongoingTemplateResult.$resultString
|
|
3663
3468
|
.split('\n')
|
|
3664
3469
|
.map(function (line) { return "> ".concat(line); })
|
|
3665
|
-
.join('\n')), "\n
|
|
3470
|
+
.join('\n')), "\n ---\n ");
|
|
3666
3471
|
}));
|
|
3667
3472
|
}
|
|
3668
3473
|
return [2 /*return*/];
|
|
@@ -3670,34 +3475,279 @@
|
|
|
3670
3475
|
});
|
|
3671
3476
|
};
|
|
3672
3477
|
attempt = -jokerParameterNames.length;
|
|
3673
|
-
|
|
3674
|
-
case
|
|
3675
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
3676
|
-
return [5 /*yield**/,
|
|
3677
|
-
case
|
|
3678
|
-
state_1 =
|
|
3478
|
+
_a.label = 1;
|
|
3479
|
+
case 1:
|
|
3480
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 4];
|
|
3481
|
+
return [5 /*yield**/, _loop_1(attempt)];
|
|
3482
|
+
case 2:
|
|
3483
|
+
state_1 = _a.sent();
|
|
3679
3484
|
switch (state_1) {
|
|
3680
|
-
case "break-attempts": return [3 /*break*/,
|
|
3485
|
+
case "break-attempts": return [3 /*break*/, 4];
|
|
3681
3486
|
}
|
|
3682
|
-
|
|
3683
|
-
case
|
|
3487
|
+
_a.label = 3;
|
|
3488
|
+
case 3:
|
|
3684
3489
|
attempt++;
|
|
3685
|
-
return [3 /*break*/,
|
|
3686
|
-
case
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3490
|
+
return [3 /*break*/, 1];
|
|
3491
|
+
case 4: return [2 /*return*/];
|
|
3492
|
+
}
|
|
3493
|
+
});
|
|
3494
|
+
});
|
|
3495
|
+
}
|
|
3496
|
+
/**
|
|
3497
|
+
* TODO: Break into smaller functions
|
|
3498
|
+
*/
|
|
3499
|
+
|
|
3500
|
+
/**
|
|
3501
|
+
* @@@
|
|
3502
|
+
*
|
|
3503
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3504
|
+
*/
|
|
3505
|
+
function executeFormatCells(options) {
|
|
3506
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3507
|
+
var template;
|
|
3508
|
+
return __generator(this, function (_a) {
|
|
3509
|
+
template = options.template;
|
|
3510
|
+
if (template.foreach === undefined) {
|
|
3511
|
+
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
3512
|
+
}
|
|
3513
|
+
throw new NotYetImplementedError('FOREACH execution not implemented yet');
|
|
3514
|
+
});
|
|
3515
|
+
});
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3518
|
+
/**
|
|
3519
|
+
* Just marks a place of place where should be something implemented
|
|
3520
|
+
* No side effects.
|
|
3521
|
+
*
|
|
3522
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
3523
|
+
*
|
|
3524
|
+
* @param value any values
|
|
3525
|
+
* @returns void
|
|
3526
|
+
* @private within the repository
|
|
3527
|
+
*/
|
|
3528
|
+
function TODO_USE() {
|
|
3529
|
+
var value = [];
|
|
3530
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3531
|
+
value[_i] = arguments[_i];
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3535
|
+
/**
|
|
3536
|
+
* @@@
|
|
3537
|
+
*
|
|
3538
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3539
|
+
*/
|
|
3540
|
+
function getContextForTemplate(template) {
|
|
3541
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3542
|
+
return __generator(this, function (_a) {
|
|
3543
|
+
TODO_USE(template);
|
|
3544
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [π] Implement */];
|
|
3545
|
+
});
|
|
3546
|
+
});
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
/**
|
|
3550
|
+
* @@@
|
|
3551
|
+
*
|
|
3552
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3553
|
+
*/
|
|
3554
|
+
function getKnowledgeForTemplate(options) {
|
|
3555
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3556
|
+
var preparedPipeline, template;
|
|
3557
|
+
return __generator(this, function (_a) {
|
|
3558
|
+
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3559
|
+
// TODO: [β¨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3560
|
+
TODO_USE(template);
|
|
3561
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3562
|
+
var content = _a.content;
|
|
3563
|
+
return "- ".concat(content);
|
|
3564
|
+
}).join('\n')];
|
|
3565
|
+
});
|
|
3566
|
+
});
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
/**
|
|
3570
|
+
* @@@
|
|
3571
|
+
*
|
|
3572
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3573
|
+
*/
|
|
3574
|
+
function getSamplesForTemplate(template) {
|
|
3575
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3576
|
+
return __generator(this, function (_a) {
|
|
3577
|
+
// TODO: [β¨] Implement Better - use real index and keyword search
|
|
3578
|
+
TODO_USE(template);
|
|
3579
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [β¨] Implement */];
|
|
3580
|
+
});
|
|
3581
|
+
});
|
|
3582
|
+
}
|
|
3583
|
+
|
|
3584
|
+
/**
|
|
3585
|
+
* @@@
|
|
3586
|
+
*
|
|
3587
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3588
|
+
*/
|
|
3589
|
+
function getReservedParametersForTemplate(options) {
|
|
3590
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3591
|
+
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3592
|
+
var e_1, _a;
|
|
3593
|
+
return __generator(this, function (_b) {
|
|
3594
|
+
switch (_b.label) {
|
|
3595
|
+
case 0:
|
|
3596
|
+
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
3597
|
+
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3598
|
+
case 1:
|
|
3599
|
+
context = _b.sent();
|
|
3600
|
+
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3601
|
+
case 2:
|
|
3602
|
+
knowledge = _b.sent();
|
|
3603
|
+
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3604
|
+
case 3:
|
|
3605
|
+
samples = _b.sent();
|
|
3606
|
+
currentDate = new Date().toISOString();
|
|
3607
|
+
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3608
|
+
reservedParameters = {
|
|
3609
|
+
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3610
|
+
context: context,
|
|
3611
|
+
knowledge: knowledge,
|
|
3612
|
+
samples: samples,
|
|
3613
|
+
currentDate: currentDate,
|
|
3614
|
+
modelName: modelName,
|
|
3615
|
+
};
|
|
3616
|
+
_loop_1 = function (parameterName) {
|
|
3617
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
3618
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3619
|
+
}
|
|
3620
|
+
};
|
|
3621
|
+
try {
|
|
3622
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3623
|
+
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()) {
|
|
3624
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3625
|
+
_loop_1(parameterName);
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3629
|
+
finally {
|
|
3630
|
+
try {
|
|
3631
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3632
|
+
}
|
|
3633
|
+
finally { if (e_1) throw e_1.error; }
|
|
3634
|
+
}
|
|
3635
|
+
return [2 /*return*/, reservedParameters];
|
|
3636
|
+
}
|
|
3637
|
+
});
|
|
3638
|
+
});
|
|
3639
|
+
}
|
|
3640
|
+
|
|
3641
|
+
/**
|
|
3642
|
+
* @@@
|
|
3643
|
+
*
|
|
3644
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3645
|
+
*/
|
|
3646
|
+
function executeTemplate(options) {
|
|
3647
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3648
|
+
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, $ongoingTemplateResult, maxAttempts, jokerParameterNames, preparedContent;
|
|
3649
|
+
var e_1, _f, _g;
|
|
3650
|
+
return __generator(this, function (_h) {
|
|
3651
|
+
switch (_h.label) {
|
|
3652
|
+
case 0:
|
|
3653
|
+
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
|
|
3654
|
+
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3655
|
+
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3656
|
+
title = currentTemplate.title;
|
|
3657
|
+
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3658
|
+
return [4 /*yield*/, onProgress({
|
|
3659
|
+
name: name,
|
|
3660
|
+
title: title,
|
|
3661
|
+
isStarted: false,
|
|
3662
|
+
isDone: false,
|
|
3663
|
+
templateType: currentTemplate.templateType,
|
|
3664
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
3665
|
+
parameterValue: null,
|
|
3666
|
+
// <- [πΈ]
|
|
3667
|
+
})];
|
|
3668
|
+
case 1:
|
|
3669
|
+
_h.sent();
|
|
3670
|
+
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3671
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3672
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3673
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
|
|
3674
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3675
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3676
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3677
|
+
.join(', '), "\n\n "); }));
|
|
3678
|
+
}
|
|
3679
|
+
_b = (_a = Object).freeze;
|
|
3680
|
+
_c = [{}];
|
|
3681
|
+
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3682
|
+
preparedPipeline: preparedPipeline,
|
|
3683
|
+
template: currentTemplate,
|
|
3684
|
+
pipelineIdentification: pipelineIdentification,
|
|
3685
|
+
})];
|
|
3686
|
+
case 2:
|
|
3687
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3688
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3689
|
+
parameters = {};
|
|
3690
|
+
_loop_1 = function (parameterName) {
|
|
3691
|
+
// Situation: Parameter is defined and used
|
|
3692
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3693
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
3694
|
+
}
|
|
3695
|
+
// Situation: Parameter is defined but NOT used
|
|
3696
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3697
|
+
// Situation: Parameter is NOT defined BUT used
|
|
3698
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3699
|
+
// Houston, we have a problem
|
|
3700
|
+
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3701
|
+
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 "); }));
|
|
3702
|
+
}
|
|
3703
|
+
};
|
|
3704
|
+
try {
|
|
3705
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3706
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3707
|
+
parameterName = _e.value;
|
|
3708
|
+
_loop_1(parameterName);
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3712
|
+
finally {
|
|
3713
|
+
try {
|
|
3714
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3715
|
+
}
|
|
3716
|
+
finally { if (e_1) throw e_1.error; }
|
|
3717
|
+
}
|
|
3718
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
3719
|
+
Object.freeze(parameters);
|
|
3720
|
+
$ongoingTemplateResult = {
|
|
3721
|
+
$result: null,
|
|
3722
|
+
$resultString: null,
|
|
3723
|
+
$expectError: null,
|
|
3724
|
+
$scriptPipelineExecutionErrors: [],
|
|
3725
|
+
};
|
|
3726
|
+
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3727
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3728
|
+
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3729
|
+
.split('{content}')
|
|
3730
|
+
.join(currentTemplate.content);
|
|
3731
|
+
// <- TODO: [π΅] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
|
|
3732
|
+
return [4 /*yield*/, executeFormatCells({
|
|
3733
|
+
$ongoingTemplateResult: $ongoingTemplateResult,
|
|
3734
|
+
jokerParameterNames: jokerParameterNames,
|
|
3735
|
+
priority: priority,
|
|
3736
|
+
maxAttempts: maxAttempts,
|
|
3737
|
+
preparedContent: preparedContent,
|
|
3738
|
+
parameters: parameters,
|
|
3739
|
+
template: currentTemplate,
|
|
3740
|
+
preparedPipeline: preparedPipeline,
|
|
3741
|
+
tools: tools,
|
|
3742
|
+
llmTools: llmTools,
|
|
3743
|
+
settings: settings,
|
|
3744
|
+
$executionReport: $executionReport,
|
|
3745
|
+
pipelineIdentification: pipelineIdentification,
|
|
3746
|
+
})];
|
|
3747
|
+
case 3:
|
|
3748
|
+
// <- TODO: [π΅] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
|
|
3749
|
+
_h.sent();
|
|
3750
|
+
if ($ongoingTemplateResult.$resultString === null) {
|
|
3701
3751
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3702
3752
|
}
|
|
3703
3753
|
return [4 /*yield*/, onProgress({
|
|
@@ -3707,13 +3757,13 @@
|
|
|
3707
3757
|
isDone: true,
|
|
3708
3758
|
templateType: currentTemplate.templateType,
|
|
3709
3759
|
parameterName: currentTemplate.resultingParameterName,
|
|
3710
|
-
parameterValue: $
|
|
3760
|
+
parameterValue: $ongoingTemplateResult.$resultString,
|
|
3711
3761
|
// <- [πΈ]
|
|
3712
3762
|
})];
|
|
3713
|
-
case
|
|
3763
|
+
case 4:
|
|
3714
3764
|
_h.sent();
|
|
3715
3765
|
return [2 /*return*/, Object.freeze((_g = {},
|
|
3716
|
-
_g[currentTemplate.resultingParameterName] = $
|
|
3766
|
+
_g[currentTemplate.resultingParameterName] = $ongoingTemplateResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3717
3767
|
_g))];
|
|
3718
3768
|
}
|
|
3719
3769
|
});
|
|
@@ -3989,6 +4039,8 @@
|
|
|
3989
4039
|
.then(function () {
|
|
3990
4040
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
3991
4041
|
});
|
|
4042
|
+
// <- Note: Errors are catched here [3]
|
|
4043
|
+
// TODO: BUT if in multiple templates are errors, only the first one is catched so maybe we should catch errors here and save them to errors array here
|
|
3992
4044
|
resolving_1.push(work_1);
|
|
3993
4045
|
_j.label = 4;
|
|
3994
4046
|
case 4: return [2 /*return*/];
|