@promptbook/node 0.69.0-6 β 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/README.md +17 -57
- package/esm/index.es.js +520 -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 +2 -2
- package/umd/index.umd.js +520 -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
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
/**
|
|
36
36
|
* The version of the Promptbook library
|
|
37
37
|
*/
|
|
38
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
38
|
+
var PROMPTBOOK_VERSION = '0.69.0-7';
|
|
39
39
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
40
40
|
|
|
41
41
|
/*! *****************************************************************************
|
|
@@ -388,13 +388,13 @@
|
|
|
388
388
|
*
|
|
389
389
|
* @public exported from `@promptbook/core`
|
|
390
390
|
*/
|
|
391
|
-
var MAX_PARALLEL_COUNT = 5;
|
|
391
|
+
var MAX_PARALLEL_COUNT = 5; // <- TODO: [π€ΉββοΈ]
|
|
392
392
|
/**
|
|
393
393
|
* The maximum number of attempts to execute LLM task before giving up
|
|
394
394
|
*
|
|
395
395
|
* @public exported from `@promptbook/core`
|
|
396
396
|
*/
|
|
397
|
-
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
397
|
+
var MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [π€ΉββοΈ]
|
|
398
398
|
/**
|
|
399
399
|
* The maximum length of the (generated) filename
|
|
400
400
|
*
|
|
@@ -905,7 +905,7 @@
|
|
|
905
905
|
});
|
|
906
906
|
}
|
|
907
907
|
|
|
908
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
908
|
+
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"}];
|
|
909
909
|
|
|
910
910
|
/**
|
|
911
911
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2100,6 +2100,23 @@
|
|
|
2100
2100
|
* - [β¨] Are templates prepared
|
|
2101
2101
|
*/
|
|
2102
2102
|
|
|
2103
|
+
/**
|
|
2104
|
+
* Serializes an error into a [π] JSON-serializable object
|
|
2105
|
+
*
|
|
2106
|
+
* @public exported from `@promptbook/utils`
|
|
2107
|
+
*/
|
|
2108
|
+
function serializeError(error) {
|
|
2109
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2110
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2111
|
+
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 "); }));
|
|
2112
|
+
}
|
|
2113
|
+
return {
|
|
2114
|
+
name: name,
|
|
2115
|
+
message: message,
|
|
2116
|
+
stack: stack,
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2103
2120
|
/**
|
|
2104
2121
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2105
2122
|
*
|
|
@@ -2393,23 +2410,6 @@
|
|
|
2393
2410
|
* TODO: [π·ββοΈ] @@@ Manual about construction of llmTools
|
|
2394
2411
|
*/
|
|
2395
2412
|
|
|
2396
|
-
/**
|
|
2397
|
-
* Serializes an error into a [π] JSON-serializable object
|
|
2398
|
-
*
|
|
2399
|
-
* @public exported from `@promptbook/utils`
|
|
2400
|
-
*/
|
|
2401
|
-
function serializeError(error) {
|
|
2402
|
-
var name = error.name, message = error.message, stack = error.stack;
|
|
2403
|
-
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2404
|
-
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 "); }));
|
|
2405
|
-
}
|
|
2406
|
-
return {
|
|
2407
|
-
name: name,
|
|
2408
|
-
message: message,
|
|
2409
|
-
stack: stack,
|
|
2410
|
-
};
|
|
2411
|
-
}
|
|
2412
|
-
|
|
2413
2413
|
/**
|
|
2414
2414
|
* Takes an item or an array of items and returns an array of items
|
|
2415
2415
|
*
|
|
@@ -2547,6 +2547,81 @@
|
|
|
2547
2547
|
* TODO: [π£] If script require contentLanguage
|
|
2548
2548
|
*/
|
|
2549
2549
|
|
|
2550
|
+
/**
|
|
2551
|
+
* Create difference set of two sets.
|
|
2552
|
+
*
|
|
2553
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2554
|
+
* @public exported from `@promptbook/utils`
|
|
2555
|
+
*/
|
|
2556
|
+
function difference(a, b, isEqual) {
|
|
2557
|
+
var e_1, _a;
|
|
2558
|
+
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
2559
|
+
var diff = new Set();
|
|
2560
|
+
var _loop_1 = function (itemA) {
|
|
2561
|
+
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
2562
|
+
diff.add(itemA);
|
|
2563
|
+
}
|
|
2564
|
+
};
|
|
2565
|
+
try {
|
|
2566
|
+
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2567
|
+
var itemA = _c.value;
|
|
2568
|
+
_loop_1(itemA);
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2572
|
+
finally {
|
|
2573
|
+
try {
|
|
2574
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2575
|
+
}
|
|
2576
|
+
finally { if (e_1) throw e_1.error; }
|
|
2577
|
+
}
|
|
2578
|
+
return diff;
|
|
2579
|
+
}
|
|
2580
|
+
/**
|
|
2581
|
+
* TODO: [π§ ][π―] Maybe also implement symmetricDifference
|
|
2582
|
+
*/
|
|
2583
|
+
|
|
2584
|
+
/**
|
|
2585
|
+
* Creates a new set with all elements that are present in either set
|
|
2586
|
+
*
|
|
2587
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2588
|
+
* @public exported from `@promptbook/utils`
|
|
2589
|
+
*/
|
|
2590
|
+
function union() {
|
|
2591
|
+
var e_1, _a, e_2, _b;
|
|
2592
|
+
var sets = [];
|
|
2593
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2594
|
+
sets[_i] = arguments[_i];
|
|
2595
|
+
}
|
|
2596
|
+
var union = new Set();
|
|
2597
|
+
try {
|
|
2598
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2599
|
+
var set = sets_1_1.value;
|
|
2600
|
+
try {
|
|
2601
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2602
|
+
var item = _d.value;
|
|
2603
|
+
union.add(item);
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2607
|
+
finally {
|
|
2608
|
+
try {
|
|
2609
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
2610
|
+
}
|
|
2611
|
+
finally { if (e_2) throw e_2.error; }
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2616
|
+
finally {
|
|
2617
|
+
try {
|
|
2618
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
2619
|
+
}
|
|
2620
|
+
finally { if (e_1) throw e_1.error; }
|
|
2621
|
+
}
|
|
2622
|
+
return union;
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2550
2625
|
/**
|
|
2551
2626
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2552
2627
|
*
|
|
@@ -2784,81 +2859,6 @@
|
|
|
2784
2859
|
return replacedTemplate;
|
|
2785
2860
|
}
|
|
2786
2861
|
|
|
2787
|
-
/**
|
|
2788
|
-
* Create difference set of two sets.
|
|
2789
|
-
*
|
|
2790
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2791
|
-
* @public exported from `@promptbook/utils`
|
|
2792
|
-
*/
|
|
2793
|
-
function difference(a, b, isEqual) {
|
|
2794
|
-
var e_1, _a;
|
|
2795
|
-
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
2796
|
-
var diff = new Set();
|
|
2797
|
-
var _loop_1 = function (itemA) {
|
|
2798
|
-
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
2799
|
-
diff.add(itemA);
|
|
2800
|
-
}
|
|
2801
|
-
};
|
|
2802
|
-
try {
|
|
2803
|
-
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2804
|
-
var itemA = _c.value;
|
|
2805
|
-
_loop_1(itemA);
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2809
|
-
finally {
|
|
2810
|
-
try {
|
|
2811
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2812
|
-
}
|
|
2813
|
-
finally { if (e_1) throw e_1.error; }
|
|
2814
|
-
}
|
|
2815
|
-
return diff;
|
|
2816
|
-
}
|
|
2817
|
-
/**
|
|
2818
|
-
* TODO: [π§ ][π―] Maybe also implement symmetricDifference
|
|
2819
|
-
*/
|
|
2820
|
-
|
|
2821
|
-
/**
|
|
2822
|
-
* Creates a new set with all elements that are present in either set
|
|
2823
|
-
*
|
|
2824
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2825
|
-
* @public exported from `@promptbook/utils`
|
|
2826
|
-
*/
|
|
2827
|
-
function union() {
|
|
2828
|
-
var e_1, _a, e_2, _b;
|
|
2829
|
-
var sets = [];
|
|
2830
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2831
|
-
sets[_i] = arguments[_i];
|
|
2832
|
-
}
|
|
2833
|
-
var union = new Set();
|
|
2834
|
-
try {
|
|
2835
|
-
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2836
|
-
var set = sets_1_1.value;
|
|
2837
|
-
try {
|
|
2838
|
-
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2839
|
-
var item = _d.value;
|
|
2840
|
-
union.add(item);
|
|
2841
|
-
}
|
|
2842
|
-
}
|
|
2843
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2844
|
-
finally {
|
|
2845
|
-
try {
|
|
2846
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
2847
|
-
}
|
|
2848
|
-
finally { if (e_2) throw e_2.error; }
|
|
2849
|
-
}
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2853
|
-
finally {
|
|
2854
|
-
try {
|
|
2855
|
-
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
2856
|
-
}
|
|
2857
|
-
finally { if (e_1) throw e_1.error; }
|
|
2858
|
-
}
|
|
2859
|
-
return union;
|
|
2860
|
-
}
|
|
2861
|
-
|
|
2862
2862
|
/**
|
|
2863
2863
|
* Counts number of characters in the text
|
|
2864
2864
|
*
|
|
@@ -2986,246 +2986,49 @@
|
|
|
2986
2986
|
* TODO: [π] Unite object for expecting amount and format
|
|
2987
2987
|
*/
|
|
2988
2988
|
|
|
2989
|
-
/**
|
|
2990
|
-
* Just marks a place of place where should be something implemented
|
|
2991
|
-
* No side effects.
|
|
2992
|
-
*
|
|
2993
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2994
|
-
*
|
|
2995
|
-
* @param value any values
|
|
2996
|
-
* @returns void
|
|
2997
|
-
* @private within the repository
|
|
2998
|
-
*/
|
|
2999
|
-
function TODO_USE() {
|
|
3000
|
-
var value = [];
|
|
3001
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3002
|
-
value[_i] = arguments[_i];
|
|
3003
|
-
}
|
|
3004
|
-
}
|
|
3005
|
-
|
|
3006
|
-
/**
|
|
3007
|
-
* @@@
|
|
3008
|
-
*
|
|
3009
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3010
|
-
*/
|
|
3011
|
-
function getContextForTemplate(template) {
|
|
3012
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3013
|
-
return __generator(this, function (_a) {
|
|
3014
|
-
TODO_USE(template);
|
|
3015
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [π] Implement */];
|
|
3016
|
-
});
|
|
3017
|
-
});
|
|
3018
|
-
}
|
|
3019
|
-
|
|
3020
|
-
/**
|
|
3021
|
-
* @@@
|
|
3022
|
-
*
|
|
3023
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3024
|
-
*/
|
|
3025
|
-
function getKnowledgeForTemplate(options) {
|
|
3026
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3027
|
-
var preparedPipeline, template;
|
|
3028
|
-
return __generator(this, function (_a) {
|
|
3029
|
-
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3030
|
-
// TODO: [β¨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3031
|
-
TODO_USE(template);
|
|
3032
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3033
|
-
var content = _a.content;
|
|
3034
|
-
return "- ".concat(content);
|
|
3035
|
-
}).join('\n')];
|
|
3036
|
-
});
|
|
3037
|
-
});
|
|
3038
|
-
}
|
|
3039
|
-
|
|
3040
2989
|
/**
|
|
3041
2990
|
* @@@
|
|
3042
2991
|
*
|
|
3043
2992
|
* @private internal utility of `createPipelineExecutor`
|
|
3044
2993
|
*/
|
|
3045
|
-
function
|
|
2994
|
+
function executeAttempts(options) {
|
|
3046
2995
|
return __awaiter(this, void 0, void 0, function () {
|
|
2996
|
+
var $ongoingTemplateResult, jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, llmTools, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, _loop_1, attempt, state_1;
|
|
3047
2997
|
return __generator(this, function (_a) {
|
|
3048
|
-
|
|
3049
|
-
TODO_USE(template);
|
|
3050
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [β¨] Implement */];
|
|
3051
|
-
});
|
|
3052
|
-
});
|
|
3053
|
-
}
|
|
3054
|
-
|
|
3055
|
-
/**
|
|
3056
|
-
* @@@
|
|
3057
|
-
*
|
|
3058
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3059
|
-
*/
|
|
3060
|
-
function getReservedParametersForTemplate(options) {
|
|
3061
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3062
|
-
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3063
|
-
var e_1, _a;
|
|
3064
|
-
return __generator(this, function (_b) {
|
|
3065
|
-
switch (_b.label) {
|
|
2998
|
+
switch (_a.label) {
|
|
3066
2999
|
case 0:
|
|
3067
|
-
|
|
3068
|
-
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3069
|
-
case 1:
|
|
3070
|
-
context = _b.sent();
|
|
3071
|
-
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3072
|
-
case 2:
|
|
3073
|
-
knowledge = _b.sent();
|
|
3074
|
-
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3075
|
-
case 3:
|
|
3076
|
-
samples = _b.sent();
|
|
3077
|
-
currentDate = new Date().toISOString();
|
|
3078
|
-
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3079
|
-
reservedParameters = {
|
|
3080
|
-
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3081
|
-
context: context,
|
|
3082
|
-
knowledge: knowledge,
|
|
3083
|
-
samples: samples,
|
|
3084
|
-
currentDate: currentDate,
|
|
3085
|
-
modelName: modelName,
|
|
3086
|
-
};
|
|
3087
|
-
_loop_1 = function (parameterName) {
|
|
3088
|
-
if (reservedParameters[parameterName] === undefined) {
|
|
3089
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3090
|
-
}
|
|
3091
|
-
};
|
|
3092
|
-
try {
|
|
3093
|
-
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3094
|
-
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()) {
|
|
3095
|
-
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3096
|
-
_loop_1(parameterName);
|
|
3097
|
-
}
|
|
3098
|
-
}
|
|
3099
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3100
|
-
finally {
|
|
3101
|
-
try {
|
|
3102
|
-
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3103
|
-
}
|
|
3104
|
-
finally { if (e_1) throw e_1.error; }
|
|
3105
|
-
}
|
|
3106
|
-
return [2 /*return*/, reservedParameters];
|
|
3107
|
-
}
|
|
3108
|
-
});
|
|
3109
|
-
});
|
|
3110
|
-
}
|
|
3111
|
-
|
|
3112
|
-
/**
|
|
3113
|
-
* @@@
|
|
3114
|
-
*
|
|
3115
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3116
|
-
*/
|
|
3117
|
-
function executeTemplate(options) {
|
|
3118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3119
|
-
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, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, _loop_2, attempt, state_1;
|
|
3120
|
-
var e_1, _f, _g;
|
|
3121
|
-
return __generator(this, function (_h) {
|
|
3122
|
-
switch (_h.label) {
|
|
3123
|
-
case 0:
|
|
3124
|
-
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;
|
|
3000
|
+
$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;
|
|
3125
3001
|
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
title: title,
|
|
3132
|
-
isStarted: false,
|
|
3133
|
-
isDone: false,
|
|
3134
|
-
templateType: currentTemplate.templateType,
|
|
3135
|
-
parameterName: currentTemplate.resultingParameterName,
|
|
3136
|
-
parameterValue: null,
|
|
3137
|
-
// <- [πΈ]
|
|
3138
|
-
})];
|
|
3139
|
-
case 1:
|
|
3140
|
-
_h.sent();
|
|
3141
|
-
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3142
|
-
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3143
|
-
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3144
|
-
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)
|
|
3145
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3146
|
-
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3147
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3148
|
-
.join(', '), "\n\n "); }));
|
|
3149
|
-
}
|
|
3150
|
-
_b = (_a = Object).freeze;
|
|
3151
|
-
_c = [{}];
|
|
3152
|
-
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3153
|
-
preparedPipeline: preparedPipeline,
|
|
3154
|
-
template: currentTemplate,
|
|
3155
|
-
pipelineIdentification: pipelineIdentification,
|
|
3156
|
-
})];
|
|
3157
|
-
case 2:
|
|
3158
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3159
|
-
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3160
|
-
parameters = {};
|
|
3161
|
-
_loop_1 = function (parameterName) {
|
|
3162
|
-
// Situation: Parameter is defined and used
|
|
3163
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3164
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3165
|
-
}
|
|
3166
|
-
// Situation: Parameter is defined but NOT used
|
|
3167
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3168
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3169
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3170
|
-
// Houston, we have a problem
|
|
3171
|
-
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3172
|
-
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 "); }));
|
|
3173
|
-
}
|
|
3174
|
-
};
|
|
3175
|
-
try {
|
|
3176
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3177
|
-
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3178
|
-
parameterName = _e.value;
|
|
3179
|
-
_loop_1(parameterName);
|
|
3180
|
-
}
|
|
3181
|
-
}
|
|
3182
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3183
|
-
finally {
|
|
3184
|
-
try {
|
|
3185
|
-
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3186
|
-
}
|
|
3187
|
-
finally { if (e_1) throw e_1.error; }
|
|
3188
|
-
}
|
|
3189
|
-
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3190
|
-
Object.freeze(parameters);
|
|
3191
|
-
result = null;
|
|
3192
|
-
resultString = null;
|
|
3193
|
-
expectError = null;
|
|
3194
|
-
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3195
|
-
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3196
|
-
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3197
|
-
.split('{content}')
|
|
3198
|
-
.join(currentTemplate.content);
|
|
3199
|
-
_loop_2 = function (attempt) {
|
|
3200
|
-
var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, scriptTools, error_1, e_2_1, _o, _p, functionName, postprocessingError, _q, _r, scriptTools, error_2, e_3_1, e_4_1, error_3;
|
|
3201
|
-
var e_2, _s, e_4, _t, e_3, _u;
|
|
3202
|
-
return __generator(this, function (_v) {
|
|
3203
|
-
switch (_v.label) {
|
|
3002
|
+
_loop_1 = function (attempt) {
|
|
3003
|
+
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;
|
|
3004
|
+
var e_1, _r, e_3, _s, e_2, _t;
|
|
3005
|
+
return __generator(this, function (_u) {
|
|
3006
|
+
switch (_u.label) {
|
|
3204
3007
|
case 0:
|
|
3205
3008
|
isJokerAttempt = attempt < 0;
|
|
3206
3009
|
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3207
3010
|
// TODO: [π§ ] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3208
3011
|
if (isJokerAttempt && !jokerParameterName) {
|
|
3209
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3012
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3210
3013
|
}
|
|
3211
|
-
result = null;
|
|
3212
|
-
resultString = null;
|
|
3213
|
-
expectError = null;
|
|
3014
|
+
$ongoingTemplateResult.$result = null;
|
|
3015
|
+
$ongoingTemplateResult.$resultString = null;
|
|
3016
|
+
$ongoingTemplateResult.$expectError = null;
|
|
3214
3017
|
if (isJokerAttempt) {
|
|
3215
3018
|
if (parameters[jokerParameterName] === undefined) {
|
|
3216
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3019
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3217
3020
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3218
3021
|
}
|
|
3219
3022
|
else {
|
|
3220
|
-
resultString = parameters[jokerParameterName];
|
|
3023
|
+
$ongoingTemplateResult.$resultString = parameters[jokerParameterName];
|
|
3221
3024
|
}
|
|
3222
3025
|
}
|
|
3223
|
-
|
|
3026
|
+
_u.label = 1;
|
|
3224
3027
|
case 1:
|
|
3225
|
-
|
|
3028
|
+
_u.trys.push([1, 44, 45, 46]);
|
|
3226
3029
|
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3227
|
-
|
|
3228
|
-
switch (
|
|
3030
|
+
_b = template.templateType;
|
|
3031
|
+
switch (_b) {
|
|
3229
3032
|
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3230
3033
|
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3231
3034
|
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
@@ -3233,125 +3036,136 @@
|
|
|
3233
3036
|
}
|
|
3234
3037
|
return [3 /*break*/, 25];
|
|
3235
3038
|
case 2:
|
|
3236
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3039
|
+
$ongoingTemplateResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
3237
3040
|
return [3 /*break*/, 26];
|
|
3238
3041
|
case 3:
|
|
3239
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (
|
|
3240
|
-
prompt = {
|
|
3241
|
-
title:
|
|
3042
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (template.modelRequirements || {}));
|
|
3043
|
+
$ongoingTemplateResult.$prompt = {
|
|
3044
|
+
title: template.title,
|
|
3242
3045
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3243
3046
|
? preparedPipeline.pipelineUrl
|
|
3244
|
-
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(
|
|
3047
|
+
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name),
|
|
3245
3048
|
parameters: parameters,
|
|
3246
3049
|
content: preparedContent,
|
|
3247
3050
|
modelRequirements: modelRequirements,
|
|
3248
3051
|
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3249
3052
|
var name = _a.name;
|
|
3250
|
-
return name ===
|
|
3251
|
-
}) ||
|
|
3252
|
-
|
|
3253
|
-
|
|
3053
|
+
return name === template.personaName;
|
|
3054
|
+
}) ||
|
|
3055
|
+
{})), template.expectations),
|
|
3056
|
+
format: template.format,
|
|
3057
|
+
postprocessingFunctionNames: template.postprocessingFunctionNames,
|
|
3254
3058
|
}; // <- TODO: Not very good type guard
|
|
3255
|
-
|
|
3256
|
-
switch (
|
|
3059
|
+
_c = modelRequirements.modelVariant;
|
|
3060
|
+
switch (_c) {
|
|
3257
3061
|
case 'CHAT': return [3 /*break*/, 4];
|
|
3258
3062
|
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3259
3063
|
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3260
3064
|
}
|
|
3261
3065
|
return [3 /*break*/, 10];
|
|
3262
|
-
case 4:
|
|
3066
|
+
case 4:
|
|
3067
|
+
_d = $ongoingTemplateResult;
|
|
3068
|
+
return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3263
3069
|
case 5:
|
|
3264
|
-
chatResult =
|
|
3070
|
+
_d.$chatResult = _u.sent();
|
|
3265
3071
|
// TODO: [π¬] Destroy chatThread
|
|
3266
|
-
result = chatResult;
|
|
3267
|
-
resultString = chatResult.content;
|
|
3072
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$chatResult;
|
|
3073
|
+
$ongoingTemplateResult.$resultString = $ongoingTemplateResult.$chatResult.content;
|
|
3268
3074
|
return [3 /*break*/, 11];
|
|
3269
|
-
case 6:
|
|
3075
|
+
case 6:
|
|
3076
|
+
_e = $ongoingTemplateResult;
|
|
3077
|
+
return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3270
3078
|
case 7:
|
|
3271
|
-
completionResult =
|
|
3272
|
-
result = completionResult;
|
|
3273
|
-
resultString =
|
|
3079
|
+
_e.$completionResult = _u.sent();
|
|
3080
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$completionResult;
|
|
3081
|
+
$ongoingTemplateResult.$resultString =
|
|
3082
|
+
$ongoingTemplateResult.$completionResult.content;
|
|
3274
3083
|
return [3 /*break*/, 11];
|
|
3275
|
-
case 8:
|
|
3084
|
+
case 8:
|
|
3085
|
+
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3086
|
+
_f = $ongoingTemplateResult;
|
|
3087
|
+
return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3276
3088
|
case 9:
|
|
3277
3089
|
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3278
|
-
embeddingResult =
|
|
3279
|
-
result = embeddingResult;
|
|
3280
|
-
resultString =
|
|
3090
|
+
_f.$embeddingResult = _u.sent();
|
|
3091
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$embeddingResult;
|
|
3092
|
+
$ongoingTemplateResult.$resultString =
|
|
3093
|
+
$ongoingTemplateResult.$embeddingResult.content.join(',');
|
|
3281
3094
|
return [3 /*break*/, 11];
|
|
3282
|
-
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3095
|
+
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 "); }));
|
|
3283
3096
|
case 11: return [3 /*break*/, 26];
|
|
3284
3097
|
case 12:
|
|
3285
3098
|
if (arrayableToArray(tools.script).length === 0) {
|
|
3286
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3099
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3287
3100
|
}
|
|
3288
|
-
if (!
|
|
3289
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3101
|
+
if (!template.contentLanguage) {
|
|
3102
|
+
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 "); }));
|
|
3290
3103
|
}
|
|
3291
|
-
|
|
3292
|
-
scriptPipelineExecutionErrors = [];
|
|
3293
|
-
_v.label = 13;
|
|
3104
|
+
_u.label = 13;
|
|
3294
3105
|
case 13:
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3106
|
+
_u.trys.push([13, 20, 21, 22]);
|
|
3107
|
+
_g = (e_1 = void 0, __values(arrayableToArray(tools.script))), _h = _g.next();
|
|
3108
|
+
_u.label = 14;
|
|
3298
3109
|
case 14:
|
|
3299
|
-
if (!!
|
|
3300
|
-
scriptTools =
|
|
3301
|
-
|
|
3110
|
+
if (!!_h.done) return [3 /*break*/, 19];
|
|
3111
|
+
scriptTools = _h.value;
|
|
3112
|
+
_u.label = 15;
|
|
3302
3113
|
case 15:
|
|
3303
|
-
|
|
3114
|
+
_u.trys.push([15, 17, , 18]);
|
|
3115
|
+
_j = $ongoingTemplateResult;
|
|
3304
3116
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3305
|
-
scriptLanguage:
|
|
3117
|
+
scriptLanguage: template.contentLanguage,
|
|
3306
3118
|
script: preparedContent,
|
|
3307
3119
|
parameters: parameters,
|
|
3308
3120
|
}))];
|
|
3309
3121
|
case 16:
|
|
3310
|
-
resultString =
|
|
3122
|
+
_j.$resultString = _u.sent();
|
|
3311
3123
|
return [3 /*break*/, 19];
|
|
3312
3124
|
case 17:
|
|
3313
|
-
error_1 =
|
|
3125
|
+
error_1 = _u.sent();
|
|
3314
3126
|
if (!(error_1 instanceof Error)) {
|
|
3315
3127
|
throw error_1;
|
|
3316
3128
|
}
|
|
3317
3129
|
if (error_1 instanceof UnexpectedError) {
|
|
3318
3130
|
throw error_1;
|
|
3319
3131
|
}
|
|
3320
|
-
scriptPipelineExecutionErrors.push(error_1);
|
|
3132
|
+
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
3321
3133
|
return [3 /*break*/, 18];
|
|
3322
3134
|
case 18:
|
|
3323
|
-
|
|
3135
|
+
_h = _g.next();
|
|
3324
3136
|
return [3 /*break*/, 14];
|
|
3325
3137
|
case 19: return [3 /*break*/, 22];
|
|
3326
3138
|
case 20:
|
|
3327
|
-
|
|
3328
|
-
|
|
3139
|
+
e_1_1 = _u.sent();
|
|
3140
|
+
e_1 = { error: e_1_1 };
|
|
3329
3141
|
return [3 /*break*/, 22];
|
|
3330
3142
|
case 21:
|
|
3331
3143
|
try {
|
|
3332
|
-
if (
|
|
3144
|
+
if (_h && !_h.done && (_r = _g.return)) _r.call(_g);
|
|
3333
3145
|
}
|
|
3334
|
-
finally { if (
|
|
3146
|
+
finally { if (e_1) throw e_1.error; }
|
|
3335
3147
|
return [7 /*endfinally*/];
|
|
3336
3148
|
case 22:
|
|
3337
|
-
if (resultString !== null) {
|
|
3149
|
+
if ($ongoingTemplateResult.$resultString !== null) {
|
|
3338
3150
|
return [3 /*break*/, 26];
|
|
3339
3151
|
}
|
|
3340
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3341
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3152
|
+
if ($ongoingTemplateResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
3153
|
+
throw $ongoingTemplateResult.$scriptPipelineExecutionErrors[0];
|
|
3342
3154
|
}
|
|
3343
3155
|
else {
|
|
3344
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3156
|
+
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
|
|
3345
3157
|
.map(function (error) { return '- ' + error.message; })
|
|
3346
|
-
.join('\n\n')), "\n
|
|
3158
|
+
.join('\n\n')), "\n "); }));
|
|
3347
3159
|
}
|
|
3348
3160
|
case 23:
|
|
3349
3161
|
if (tools.userInterface === undefined) {
|
|
3350
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3162
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3351
3163
|
}
|
|
3164
|
+
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3165
|
+
_k = $ongoingTemplateResult;
|
|
3352
3166
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3353
|
-
promptTitle:
|
|
3354
|
-
promptMessage: replaceParameters(
|
|
3167
|
+
promptTitle: template.title,
|
|
3168
|
+
promptMessage: replaceParameters(template.description || '', parameters),
|
|
3355
3169
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3356
3170
|
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3357
3171
|
placeholder: undefined,
|
|
@@ -3359,47 +3173,46 @@
|
|
|
3359
3173
|
}))];
|
|
3360
3174
|
case 24:
|
|
3361
3175
|
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3362
|
-
resultString =
|
|
3176
|
+
_k.$resultString = _u.sent();
|
|
3363
3177
|
return [3 /*break*/, 26];
|
|
3364
|
-
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3178
|
+
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(template.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3365
3179
|
case 26:
|
|
3366
|
-
if (!(!isJokerAttempt &&
|
|
3367
|
-
|
|
3180
|
+
if (!(!isJokerAttempt && template.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3181
|
+
_u.label = 27;
|
|
3368
3182
|
case 27:
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3183
|
+
_u.trys.push([27, 41, 42, 43]);
|
|
3184
|
+
_l = (e_3 = void 0, __values(template.postprocessingFunctionNames)), _m = _l.next();
|
|
3185
|
+
_u.label = 28;
|
|
3372
3186
|
case 28:
|
|
3373
|
-
if (!!
|
|
3374
|
-
functionName =
|
|
3375
|
-
// TODO: DRY [1]
|
|
3376
|
-
scriptPipelineExecutionErrors = [];
|
|
3187
|
+
if (!!_m.done) return [3 /*break*/, 40];
|
|
3188
|
+
functionName = _m.value;
|
|
3377
3189
|
postprocessingError = null;
|
|
3378
|
-
|
|
3190
|
+
_u.label = 29;
|
|
3379
3191
|
case 29:
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3192
|
+
_u.trys.push([29, 36, 37, 38]);
|
|
3193
|
+
_o = (e_2 = void 0, __values(arrayableToArray(tools.script))), _p = _o.next();
|
|
3194
|
+
_u.label = 30;
|
|
3383
3195
|
case 30:
|
|
3384
|
-
if (!!
|
|
3385
|
-
scriptTools =
|
|
3386
|
-
|
|
3196
|
+
if (!!_p.done) return [3 /*break*/, 35];
|
|
3197
|
+
scriptTools = _p.value;
|
|
3198
|
+
_u.label = 31;
|
|
3387
3199
|
case 31:
|
|
3388
|
-
|
|
3200
|
+
_u.trys.push([31, 33, , 34]);
|
|
3201
|
+
_q = $ongoingTemplateResult;
|
|
3389
3202
|
return [4 /*yield*/, scriptTools.execute({
|
|
3390
3203
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3391
3204
|
script: "".concat(functionName, "(resultString)"),
|
|
3392
3205
|
parameters: {
|
|
3393
|
-
resultString: resultString || '',
|
|
3206
|
+
resultString: $ongoingTemplateResult.$resultString || '',
|
|
3394
3207
|
// Note: No ...parametersForTemplate, because working with result only
|
|
3395
3208
|
},
|
|
3396
3209
|
})];
|
|
3397
3210
|
case 32:
|
|
3398
|
-
resultString =
|
|
3211
|
+
_q.$resultString = _u.sent();
|
|
3399
3212
|
postprocessingError = null;
|
|
3400
3213
|
return [3 /*break*/, 35];
|
|
3401
3214
|
case 33:
|
|
3402
|
-
error_2 =
|
|
3215
|
+
error_2 = _u.sent();
|
|
3403
3216
|
if (!(error_2 instanceof Error)) {
|
|
3404
3217
|
throw error_2;
|
|
3405
3218
|
}
|
|
@@ -3407,136 +3220,386 @@
|
|
|
3407
3220
|
throw error_2;
|
|
3408
3221
|
}
|
|
3409
3222
|
postprocessingError = error_2;
|
|
3410
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3223
|
+
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
3411
3224
|
return [3 /*break*/, 34];
|
|
3412
3225
|
case 34:
|
|
3413
|
-
|
|
3226
|
+
_p = _o.next();
|
|
3414
3227
|
return [3 /*break*/, 30];
|
|
3415
3228
|
case 35: return [3 /*break*/, 38];
|
|
3416
3229
|
case 36:
|
|
3417
|
-
|
|
3418
|
-
|
|
3230
|
+
e_2_1 = _u.sent();
|
|
3231
|
+
e_2 = { error: e_2_1 };
|
|
3419
3232
|
return [3 /*break*/, 38];
|
|
3420
3233
|
case 37:
|
|
3421
3234
|
try {
|
|
3422
|
-
if (
|
|
3235
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3423
3236
|
}
|
|
3424
|
-
finally { if (
|
|
3237
|
+
finally { if (e_2) throw e_2.error; }
|
|
3425
3238
|
return [7 /*endfinally*/];
|
|
3426
3239
|
case 38:
|
|
3427
3240
|
if (postprocessingError) {
|
|
3428
3241
|
throw postprocessingError;
|
|
3429
3242
|
}
|
|
3430
|
-
|
|
3243
|
+
_u.label = 39;
|
|
3431
3244
|
case 39:
|
|
3432
|
-
|
|
3245
|
+
_m = _l.next();
|
|
3433
3246
|
return [3 /*break*/, 28];
|
|
3434
3247
|
case 40: return [3 /*break*/, 43];
|
|
3435
3248
|
case 41:
|
|
3436
|
-
|
|
3437
|
-
|
|
3249
|
+
e_3_1 = _u.sent();
|
|
3250
|
+
e_3 = { error: e_3_1 };
|
|
3438
3251
|
return [3 /*break*/, 43];
|
|
3439
3252
|
case 42:
|
|
3440
3253
|
try {
|
|
3441
|
-
if (
|
|
3254
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3442
3255
|
}
|
|
3443
|
-
finally { if (
|
|
3256
|
+
finally { if (e_3) throw e_3.error; }
|
|
3444
3257
|
return [7 /*endfinally*/];
|
|
3445
3258
|
case 43:
|
|
3446
3259
|
// TODO: [π] Unite object for expecting amount and format
|
|
3447
|
-
if (
|
|
3448
|
-
if (
|
|
3449
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3260
|
+
if (template.format) {
|
|
3261
|
+
if (template.format === 'JSON') {
|
|
3262
|
+
if (!isValidJsonString($ongoingTemplateResult.$resultString || '')) {
|
|
3450
3263
|
// TODO: [π’] Do more universally via `FormatDefinition`
|
|
3451
3264
|
try {
|
|
3452
|
-
resultString = extractJsonBlock(resultString || '');
|
|
3265
|
+
$ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
|
|
3453
3266
|
}
|
|
3454
3267
|
catch (error) {
|
|
3455
3268
|
keepUnused(error);
|
|
3456
|
-
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3457
|
-
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n
|
|
3269
|
+
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3270
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3458
3271
|
}
|
|
3459
3272
|
}
|
|
3460
3273
|
}
|
|
3461
3274
|
else {
|
|
3462
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3275
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(template.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3463
3276
|
}
|
|
3464
3277
|
}
|
|
3465
3278
|
// TODO: [π] Unite object for expecting amount and format
|
|
3466
|
-
if (
|
|
3467
|
-
checkExpectations(
|
|
3279
|
+
if (template.expectations) {
|
|
3280
|
+
checkExpectations(template.expectations, $ongoingTemplateResult.$resultString || '');
|
|
3468
3281
|
}
|
|
3469
3282
|
return [2 /*return*/, "break-attempts"];
|
|
3470
3283
|
case 44:
|
|
3471
|
-
error_3 =
|
|
3284
|
+
error_3 = _u.sent();
|
|
3472
3285
|
if (!(error_3 instanceof ExpectError)) {
|
|
3473
3286
|
throw error_3;
|
|
3474
3287
|
}
|
|
3475
|
-
expectError = error_3;
|
|
3288
|
+
$ongoingTemplateResult.$expectError = error_3;
|
|
3476
3289
|
return [3 /*break*/, 46];
|
|
3477
3290
|
case 45:
|
|
3478
3291
|
if (!isJokerAttempt &&
|
|
3479
|
-
|
|
3480
|
-
prompt
|
|
3292
|
+
template.templateType === 'PROMPT_TEMPLATE' &&
|
|
3293
|
+
$ongoingTemplateResult.$prompt
|
|
3481
3294
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3482
3295
|
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3483
3296
|
) {
|
|
3484
3297
|
// TODO: [π§ ] Maybe put other templateTypes into report
|
|
3485
3298
|
$executionReport.promptExecutions.push({
|
|
3486
|
-
prompt: __assign({}, prompt),
|
|
3487
|
-
result: result || undefined,
|
|
3488
|
-
error: expectError === null
|
|
3299
|
+
prompt: __assign({}, $ongoingTemplateResult.$prompt),
|
|
3300
|
+
result: $ongoingTemplateResult.$result || undefined,
|
|
3301
|
+
error: $ongoingTemplateResult.$expectError === null
|
|
3302
|
+
? undefined
|
|
3303
|
+
: serializeError($ongoingTemplateResult.$expectError),
|
|
3489
3304
|
});
|
|
3490
3305
|
}
|
|
3491
3306
|
return [7 /*endfinally*/];
|
|
3492
3307
|
case 46:
|
|
3493
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3494
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
|
|
3495
|
-
|
|
3496
|
-
.
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3501
|
-
? 'null'
|
|
3502
|
-
: resultString
|
|
3308
|
+
if ($ongoingTemplateResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
3309
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
|
|
3310
|
+
var _a, _b, _c;
|
|
3311
|
+
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) || '')
|
|
3312
|
+
.split('\n')
|
|
3313
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3314
|
+
.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) || '')
|
|
3503
3315
|
.split('\n')
|
|
3504
3316
|
.map(function (line) { return "> ".concat(line); })
|
|
3505
|
-
.join('\n')), "\n
|
|
3317
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
|
|
3318
|
+
? 'null'
|
|
3319
|
+
: $ongoingTemplateResult.$resultString
|
|
3320
|
+
.split('\n')
|
|
3321
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3322
|
+
.join('\n')), "\n ---\n ");
|
|
3323
|
+
}));
|
|
3506
3324
|
}
|
|
3507
3325
|
return [2 /*return*/];
|
|
3508
3326
|
}
|
|
3509
3327
|
});
|
|
3510
3328
|
};
|
|
3511
3329
|
attempt = -jokerParameterNames.length;
|
|
3512
|
-
|
|
3513
|
-
case
|
|
3514
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
3515
|
-
return [5 /*yield**/,
|
|
3516
|
-
case
|
|
3517
|
-
state_1 =
|
|
3330
|
+
_a.label = 1;
|
|
3331
|
+
case 1:
|
|
3332
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 4];
|
|
3333
|
+
return [5 /*yield**/, _loop_1(attempt)];
|
|
3334
|
+
case 2:
|
|
3335
|
+
state_1 = _a.sent();
|
|
3518
3336
|
switch (state_1) {
|
|
3519
|
-
case "break-attempts": return [3 /*break*/,
|
|
3337
|
+
case "break-attempts": return [3 /*break*/, 4];
|
|
3520
3338
|
}
|
|
3521
|
-
|
|
3522
|
-
case
|
|
3339
|
+
_a.label = 3;
|
|
3340
|
+
case 3:
|
|
3523
3341
|
attempt++;
|
|
3524
|
-
return [3 /*break*/,
|
|
3525
|
-
case
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3342
|
+
return [3 /*break*/, 1];
|
|
3343
|
+
case 4: return [2 /*return*/];
|
|
3344
|
+
}
|
|
3345
|
+
});
|
|
3346
|
+
});
|
|
3347
|
+
}
|
|
3348
|
+
/**
|
|
3349
|
+
* TODO: Break into smaller functions
|
|
3350
|
+
*/
|
|
3351
|
+
|
|
3352
|
+
/**
|
|
3353
|
+
* @@@
|
|
3354
|
+
*
|
|
3355
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3356
|
+
*/
|
|
3357
|
+
function executeFormatCells(options) {
|
|
3358
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3359
|
+
var template;
|
|
3360
|
+
return __generator(this, function (_a) {
|
|
3361
|
+
template = options.template;
|
|
3362
|
+
if (template.foreach === undefined) {
|
|
3363
|
+
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
3364
|
+
}
|
|
3365
|
+
throw new NotYetImplementedError('FOREACH execution not implemented yet');
|
|
3366
|
+
});
|
|
3367
|
+
});
|
|
3368
|
+
}
|
|
3369
|
+
|
|
3370
|
+
/**
|
|
3371
|
+
* Just marks a place of place where should be something implemented
|
|
3372
|
+
* No side effects.
|
|
3373
|
+
*
|
|
3374
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
3375
|
+
*
|
|
3376
|
+
* @param value any values
|
|
3377
|
+
* @returns void
|
|
3378
|
+
* @private within the repository
|
|
3379
|
+
*/
|
|
3380
|
+
function TODO_USE() {
|
|
3381
|
+
var value = [];
|
|
3382
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3383
|
+
value[_i] = arguments[_i];
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3387
|
+
/**
|
|
3388
|
+
* @@@
|
|
3389
|
+
*
|
|
3390
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3391
|
+
*/
|
|
3392
|
+
function getContextForTemplate(template) {
|
|
3393
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3394
|
+
return __generator(this, function (_a) {
|
|
3395
|
+
TODO_USE(template);
|
|
3396
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [π] Implement */];
|
|
3397
|
+
});
|
|
3398
|
+
});
|
|
3399
|
+
}
|
|
3400
|
+
|
|
3401
|
+
/**
|
|
3402
|
+
* @@@
|
|
3403
|
+
*
|
|
3404
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3405
|
+
*/
|
|
3406
|
+
function getKnowledgeForTemplate(options) {
|
|
3407
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3408
|
+
var preparedPipeline, template;
|
|
3409
|
+
return __generator(this, function (_a) {
|
|
3410
|
+
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3411
|
+
// TODO: [β¨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3412
|
+
TODO_USE(template);
|
|
3413
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3414
|
+
var content = _a.content;
|
|
3415
|
+
return "- ".concat(content);
|
|
3416
|
+
}).join('\n')];
|
|
3417
|
+
});
|
|
3418
|
+
});
|
|
3419
|
+
}
|
|
3420
|
+
|
|
3421
|
+
/**
|
|
3422
|
+
* @@@
|
|
3423
|
+
*
|
|
3424
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3425
|
+
*/
|
|
3426
|
+
function getSamplesForTemplate(template) {
|
|
3427
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3428
|
+
return __generator(this, function (_a) {
|
|
3429
|
+
// TODO: [β¨] Implement Better - use real index and keyword search
|
|
3430
|
+
TODO_USE(template);
|
|
3431
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [β¨] Implement */];
|
|
3432
|
+
});
|
|
3433
|
+
});
|
|
3434
|
+
}
|
|
3435
|
+
|
|
3436
|
+
/**
|
|
3437
|
+
* @@@
|
|
3438
|
+
*
|
|
3439
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3440
|
+
*/
|
|
3441
|
+
function getReservedParametersForTemplate(options) {
|
|
3442
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3443
|
+
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3444
|
+
var e_1, _a;
|
|
3445
|
+
return __generator(this, function (_b) {
|
|
3446
|
+
switch (_b.label) {
|
|
3447
|
+
case 0:
|
|
3448
|
+
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
3449
|
+
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3450
|
+
case 1:
|
|
3451
|
+
context = _b.sent();
|
|
3452
|
+
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3453
|
+
case 2:
|
|
3454
|
+
knowledge = _b.sent();
|
|
3455
|
+
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3456
|
+
case 3:
|
|
3457
|
+
samples = _b.sent();
|
|
3458
|
+
currentDate = new Date().toISOString();
|
|
3459
|
+
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3460
|
+
reservedParameters = {
|
|
3461
|
+
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3462
|
+
context: context,
|
|
3463
|
+
knowledge: knowledge,
|
|
3464
|
+
samples: samples,
|
|
3465
|
+
currentDate: currentDate,
|
|
3466
|
+
modelName: modelName,
|
|
3467
|
+
};
|
|
3468
|
+
_loop_1 = function (parameterName) {
|
|
3469
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
3470
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3471
|
+
}
|
|
3472
|
+
};
|
|
3473
|
+
try {
|
|
3474
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3475
|
+
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()) {
|
|
3476
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3477
|
+
_loop_1(parameterName);
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3481
|
+
finally {
|
|
3482
|
+
try {
|
|
3483
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3484
|
+
}
|
|
3485
|
+
finally { if (e_1) throw e_1.error; }
|
|
3486
|
+
}
|
|
3487
|
+
return [2 /*return*/, reservedParameters];
|
|
3488
|
+
}
|
|
3489
|
+
});
|
|
3490
|
+
});
|
|
3491
|
+
}
|
|
3492
|
+
|
|
3493
|
+
/**
|
|
3494
|
+
* @@@
|
|
3495
|
+
*
|
|
3496
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3497
|
+
*/
|
|
3498
|
+
function executeTemplate(options) {
|
|
3499
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3500
|
+
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;
|
|
3501
|
+
var e_1, _f, _g;
|
|
3502
|
+
return __generator(this, function (_h) {
|
|
3503
|
+
switch (_h.label) {
|
|
3504
|
+
case 0:
|
|
3505
|
+
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;
|
|
3506
|
+
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3507
|
+
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3508
|
+
title = currentTemplate.title;
|
|
3509
|
+
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3510
|
+
return [4 /*yield*/, onProgress({
|
|
3511
|
+
name: name,
|
|
3512
|
+
title: title,
|
|
3513
|
+
isStarted: false,
|
|
3514
|
+
isDone: false,
|
|
3515
|
+
templateType: currentTemplate.templateType,
|
|
3516
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
3517
|
+
parameterValue: null,
|
|
3518
|
+
// <- [πΈ]
|
|
3519
|
+
})];
|
|
3520
|
+
case 1:
|
|
3521
|
+
_h.sent();
|
|
3522
|
+
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3523
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3524
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3525
|
+
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)
|
|
3526
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3527
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3528
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3529
|
+
.join(', '), "\n\n "); }));
|
|
3530
|
+
}
|
|
3531
|
+
_b = (_a = Object).freeze;
|
|
3532
|
+
_c = [{}];
|
|
3533
|
+
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3534
|
+
preparedPipeline: preparedPipeline,
|
|
3535
|
+
template: currentTemplate,
|
|
3536
|
+
pipelineIdentification: pipelineIdentification,
|
|
3537
|
+
})];
|
|
3538
|
+
case 2:
|
|
3539
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3540
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3541
|
+
parameters = {};
|
|
3542
|
+
_loop_1 = function (parameterName) {
|
|
3543
|
+
// Situation: Parameter is defined and used
|
|
3544
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3545
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
3546
|
+
}
|
|
3547
|
+
// Situation: Parameter is defined but NOT used
|
|
3548
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3549
|
+
// Situation: Parameter is NOT defined BUT used
|
|
3550
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3551
|
+
// Houston, we have a problem
|
|
3552
|
+
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3553
|
+
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 "); }));
|
|
3554
|
+
}
|
|
3555
|
+
};
|
|
3556
|
+
try {
|
|
3557
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3558
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3559
|
+
parameterName = _e.value;
|
|
3560
|
+
_loop_1(parameterName);
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3564
|
+
finally {
|
|
3565
|
+
try {
|
|
3566
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3567
|
+
}
|
|
3568
|
+
finally { if (e_1) throw e_1.error; }
|
|
3569
|
+
}
|
|
3570
|
+
// 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
|
|
3571
|
+
Object.freeze(parameters);
|
|
3572
|
+
$ongoingTemplateResult = {
|
|
3573
|
+
$result: null,
|
|
3574
|
+
$resultString: null,
|
|
3575
|
+
$expectError: null,
|
|
3576
|
+
$scriptPipelineExecutionErrors: [],
|
|
3577
|
+
};
|
|
3578
|
+
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3579
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3580
|
+
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3581
|
+
.split('{content}')
|
|
3582
|
+
.join(currentTemplate.content);
|
|
3583
|
+
// <- TODO: [π΅] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
|
|
3584
|
+
return [4 /*yield*/, executeFormatCells({
|
|
3585
|
+
$ongoingTemplateResult: $ongoingTemplateResult,
|
|
3586
|
+
jokerParameterNames: jokerParameterNames,
|
|
3587
|
+
priority: priority,
|
|
3588
|
+
maxAttempts: maxAttempts,
|
|
3589
|
+
preparedContent: preparedContent,
|
|
3590
|
+
parameters: parameters,
|
|
3591
|
+
template: currentTemplate,
|
|
3592
|
+
preparedPipeline: preparedPipeline,
|
|
3593
|
+
tools: tools,
|
|
3594
|
+
llmTools: llmTools,
|
|
3595
|
+
settings: settings,
|
|
3596
|
+
$executionReport: $executionReport,
|
|
3597
|
+
pipelineIdentification: pipelineIdentification,
|
|
3598
|
+
})];
|
|
3599
|
+
case 3:
|
|
3600
|
+
// <- TODO: [π΅] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
|
|
3601
|
+
_h.sent();
|
|
3602
|
+
if ($ongoingTemplateResult.$resultString === null) {
|
|
3540
3603
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3541
3604
|
}
|
|
3542
3605
|
return [4 /*yield*/, onProgress({
|
|
@@ -3546,13 +3609,13 @@
|
|
|
3546
3609
|
isDone: true,
|
|
3547
3610
|
templateType: currentTemplate.templateType,
|
|
3548
3611
|
parameterName: currentTemplate.resultingParameterName,
|
|
3549
|
-
parameterValue: resultString,
|
|
3612
|
+
parameterValue: $ongoingTemplateResult.$resultString,
|
|
3550
3613
|
// <- [πΈ]
|
|
3551
3614
|
})];
|
|
3552
|
-
case
|
|
3615
|
+
case 4:
|
|
3553
3616
|
_h.sent();
|
|
3554
3617
|
return [2 /*return*/, Object.freeze((_g = {},
|
|
3555
|
-
_g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3618
|
+
_g[currentTemplate.resultingParameterName] = $ongoingTemplateResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3556
3619
|
_g))];
|
|
3557
3620
|
}
|
|
3558
3621
|
});
|
|
@@ -3828,6 +3891,8 @@
|
|
|
3828
3891
|
.then(function () {
|
|
3829
3892
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
3830
3893
|
});
|
|
3894
|
+
// <- Note: Errors are catched here [3]
|
|
3895
|
+
// 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
|
|
3831
3896
|
resolving_1.push(work_1);
|
|
3832
3897
|
_j.label = 4;
|
|
3833
3898
|
case 4: return [2 /*return*/];
|