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