@promptbook/node 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 +2 -2
- package/umd/index.umd.js +507 -455
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatCell.d.ts +0 -30
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempt.d.ts +0 -30
package/umd/index.umd.js
CHANGED
|
@@ -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,249 +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, $ongoingResult, 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 and are not going to be changed
|
|
3190
|
-
Object.freeze(parameters);
|
|
3191
|
-
$ongoingResult = {
|
|
3192
|
-
$result: null,
|
|
3193
|
-
$resultString: null,
|
|
3194
|
-
$expectError: null,
|
|
3195
|
-
$scriptPipelineExecutionErrors: [],
|
|
3196
|
-
};
|
|
3197
|
-
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3198
|
-
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3199
|
-
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3200
|
-
.split('{content}')
|
|
3201
|
-
.join(currentTemplate.content);
|
|
3202
|
-
_loop_2 = function (attempt) {
|
|
3203
|
-
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;
|
|
3204
|
-
var e_2, _y, e_4, _z, e_3, _0;
|
|
3205
|
-
return __generator(this, function (_1) {
|
|
3206
|
-
switch (_1.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) {
|
|
3207
3007
|
case 0:
|
|
3208
3008
|
isJokerAttempt = attempt < 0;
|
|
3209
3009
|
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3210
3010
|
// TODO: [π§ ] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3211
3011
|
if (isJokerAttempt && !jokerParameterName) {
|
|
3212
|
-
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 "); }));
|
|
3213
3013
|
}
|
|
3214
|
-
$
|
|
3215
|
-
$
|
|
3216
|
-
$
|
|
3014
|
+
$ongoingTemplateResult.$result = null;
|
|
3015
|
+
$ongoingTemplateResult.$resultString = null;
|
|
3016
|
+
$ongoingTemplateResult.$expectError = null;
|
|
3217
3017
|
if (isJokerAttempt) {
|
|
3218
3018
|
if (parameters[jokerParameterName] === undefined) {
|
|
3219
|
-
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 "); }));
|
|
3220
3020
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3221
3021
|
}
|
|
3222
3022
|
else {
|
|
3223
|
-
$
|
|
3023
|
+
$ongoingTemplateResult.$resultString = parameters[jokerParameterName];
|
|
3224
3024
|
}
|
|
3225
3025
|
}
|
|
3226
|
-
|
|
3026
|
+
_u.label = 1;
|
|
3227
3027
|
case 1:
|
|
3228
|
-
|
|
3028
|
+
_u.trys.push([1, 44, 45, 46]);
|
|
3229
3029
|
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3230
|
-
|
|
3231
|
-
switch (
|
|
3030
|
+
_b = template.templateType;
|
|
3031
|
+
switch (_b) {
|
|
3232
3032
|
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3233
3033
|
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3234
3034
|
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
@@ -3236,133 +3036,136 @@
|
|
|
3236
3036
|
}
|
|
3237
3037
|
return [3 /*break*/, 25];
|
|
3238
3038
|
case 2:
|
|
3239
|
-
$
|
|
3039
|
+
$ongoingTemplateResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
3240
3040
|
return [3 /*break*/, 26];
|
|
3241
3041
|
case 3:
|
|
3242
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (
|
|
3243
|
-
$
|
|
3244
|
-
title:
|
|
3042
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (template.modelRequirements || {}));
|
|
3043
|
+
$ongoingTemplateResult.$prompt = {
|
|
3044
|
+
title: template.title,
|
|
3245
3045
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3246
3046
|
? preparedPipeline.pipelineUrl
|
|
3247
|
-
: '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),
|
|
3248
3048
|
parameters: parameters,
|
|
3249
3049
|
content: preparedContent,
|
|
3250
3050
|
modelRequirements: modelRequirements,
|
|
3251
3051
|
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3252
3052
|
var name = _a.name;
|
|
3253
|
-
return name ===
|
|
3254
|
-
}) ||
|
|
3255
|
-
|
|
3256
|
-
|
|
3053
|
+
return name === template.personaName;
|
|
3054
|
+
}) ||
|
|
3055
|
+
{})), template.expectations),
|
|
3056
|
+
format: template.format,
|
|
3057
|
+
postprocessingFunctionNames: template.postprocessingFunctionNames,
|
|
3257
3058
|
}; // <- TODO: Not very good type guard
|
|
3258
|
-
|
|
3259
|
-
switch (
|
|
3059
|
+
_c = modelRequirements.modelVariant;
|
|
3060
|
+
switch (_c) {
|
|
3260
3061
|
case 'CHAT': return [3 /*break*/, 4];
|
|
3261
3062
|
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3262
3063
|
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3263
3064
|
}
|
|
3264
3065
|
return [3 /*break*/, 10];
|
|
3265
3066
|
case 4:
|
|
3266
|
-
|
|
3267
|
-
return [4 /*yield*/, llmTools.callChatModel($deepFreeze($
|
|
3067
|
+
_d = $ongoingTemplateResult;
|
|
3068
|
+
return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3268
3069
|
case 5:
|
|
3269
|
-
|
|
3070
|
+
_d.$chatResult = _u.sent();
|
|
3270
3071
|
// TODO: [π¬] Destroy chatThread
|
|
3271
|
-
$
|
|
3272
|
-
$
|
|
3072
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$chatResult;
|
|
3073
|
+
$ongoingTemplateResult.$resultString = $ongoingTemplateResult.$chatResult.content;
|
|
3273
3074
|
return [3 /*break*/, 11];
|
|
3274
3075
|
case 6:
|
|
3275
|
-
|
|
3276
|
-
return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($
|
|
3076
|
+
_e = $ongoingTemplateResult;
|
|
3077
|
+
return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3277
3078
|
case 7:
|
|
3278
|
-
|
|
3279
|
-
$
|
|
3280
|
-
$
|
|
3079
|
+
_e.$completionResult = _u.sent();
|
|
3080
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$completionResult;
|
|
3081
|
+
$ongoingTemplateResult.$resultString =
|
|
3082
|
+
$ongoingTemplateResult.$completionResult.content;
|
|
3281
3083
|
return [3 /*break*/, 11];
|
|
3282
3084
|
case 8:
|
|
3283
3085
|
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3284
|
-
|
|
3285
|
-
return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($
|
|
3086
|
+
_f = $ongoingTemplateResult;
|
|
3087
|
+
return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3286
3088
|
case 9:
|
|
3287
3089
|
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3288
|
-
|
|
3289
|
-
$
|
|
3290
|
-
$
|
|
3090
|
+
_f.$embeddingResult = _u.sent();
|
|
3091
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$embeddingResult;
|
|
3092
|
+
$ongoingTemplateResult.$resultString =
|
|
3093
|
+
$ongoingTemplateResult.$embeddingResult.content.join(',');
|
|
3291
3094
|
return [3 /*break*/, 11];
|
|
3292
|
-
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 "); }));
|
|
3293
3096
|
case 11: return [3 /*break*/, 26];
|
|
3294
3097
|
case 12:
|
|
3295
3098
|
if (arrayableToArray(tools.script).length === 0) {
|
|
3296
|
-
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 "); }));
|
|
3297
3100
|
}
|
|
3298
|
-
if (!
|
|
3299
|
-
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 "); }));
|
|
3300
3103
|
}
|
|
3301
|
-
|
|
3104
|
+
_u.label = 13;
|
|
3302
3105
|
case 13:
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
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;
|
|
3306
3109
|
case 14:
|
|
3307
|
-
if (!!
|
|
3308
|
-
scriptTools =
|
|
3309
|
-
|
|
3110
|
+
if (!!_h.done) return [3 /*break*/, 19];
|
|
3111
|
+
scriptTools = _h.value;
|
|
3112
|
+
_u.label = 15;
|
|
3310
3113
|
case 15:
|
|
3311
|
-
|
|
3312
|
-
|
|
3114
|
+
_u.trys.push([15, 17, , 18]);
|
|
3115
|
+
_j = $ongoingTemplateResult;
|
|
3313
3116
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3314
|
-
scriptLanguage:
|
|
3117
|
+
scriptLanguage: template.contentLanguage,
|
|
3315
3118
|
script: preparedContent,
|
|
3316
3119
|
parameters: parameters,
|
|
3317
3120
|
}))];
|
|
3318
3121
|
case 16:
|
|
3319
|
-
|
|
3122
|
+
_j.$resultString = _u.sent();
|
|
3320
3123
|
return [3 /*break*/, 19];
|
|
3321
3124
|
case 17:
|
|
3322
|
-
error_1 =
|
|
3125
|
+
error_1 = _u.sent();
|
|
3323
3126
|
if (!(error_1 instanceof Error)) {
|
|
3324
3127
|
throw error_1;
|
|
3325
3128
|
}
|
|
3326
3129
|
if (error_1 instanceof UnexpectedError) {
|
|
3327
3130
|
throw error_1;
|
|
3328
3131
|
}
|
|
3329
|
-
$
|
|
3132
|
+
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
3330
3133
|
return [3 /*break*/, 18];
|
|
3331
3134
|
case 18:
|
|
3332
|
-
|
|
3135
|
+
_h = _g.next();
|
|
3333
3136
|
return [3 /*break*/, 14];
|
|
3334
3137
|
case 19: return [3 /*break*/, 22];
|
|
3335
3138
|
case 20:
|
|
3336
|
-
|
|
3337
|
-
|
|
3139
|
+
e_1_1 = _u.sent();
|
|
3140
|
+
e_1 = { error: e_1_1 };
|
|
3338
3141
|
return [3 /*break*/, 22];
|
|
3339
3142
|
case 21:
|
|
3340
3143
|
try {
|
|
3341
|
-
if (
|
|
3144
|
+
if (_h && !_h.done && (_r = _g.return)) _r.call(_g);
|
|
3342
3145
|
}
|
|
3343
|
-
finally { if (
|
|
3146
|
+
finally { if (e_1) throw e_1.error; }
|
|
3344
3147
|
return [7 /*endfinally*/];
|
|
3345
3148
|
case 22:
|
|
3346
|
-
if ($
|
|
3149
|
+
if ($ongoingTemplateResult.$resultString !== null) {
|
|
3347
3150
|
return [3 /*break*/, 26];
|
|
3348
3151
|
}
|
|
3349
|
-
if ($
|
|
3350
|
-
throw $
|
|
3152
|
+
if ($ongoingTemplateResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
3153
|
+
throw $ongoingTemplateResult.$scriptPipelineExecutionErrors[0];
|
|
3351
3154
|
}
|
|
3352
3155
|
else {
|
|
3353
|
-
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
|
|
3354
3157
|
.map(function (error) { return '- ' + error.message; })
|
|
3355
|
-
.join('\n\n')), "\n
|
|
3158
|
+
.join('\n\n')), "\n "); }));
|
|
3356
3159
|
}
|
|
3357
3160
|
case 23:
|
|
3358
3161
|
if (tools.userInterface === undefined) {
|
|
3359
|
-
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 "); }));
|
|
3360
3163
|
}
|
|
3361
3164
|
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3362
|
-
|
|
3165
|
+
_k = $ongoingTemplateResult;
|
|
3363
3166
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3364
|
-
promptTitle:
|
|
3365
|
-
promptMessage: replaceParameters(
|
|
3167
|
+
promptTitle: template.title,
|
|
3168
|
+
promptMessage: replaceParameters(template.description || '', parameters),
|
|
3366
3169
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3367
3170
|
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3368
3171
|
placeholder: undefined,
|
|
@@ -3370,46 +3173,46 @@
|
|
|
3370
3173
|
}))];
|
|
3371
3174
|
case 24:
|
|
3372
3175
|
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3373
|
-
|
|
3176
|
+
_k.$resultString = _u.sent();
|
|
3374
3177
|
return [3 /*break*/, 26];
|
|
3375
|
-
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 "); }));
|
|
3376
3179
|
case 26:
|
|
3377
|
-
if (!(!isJokerAttempt &&
|
|
3378
|
-
|
|
3180
|
+
if (!(!isJokerAttempt && template.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3181
|
+
_u.label = 27;
|
|
3379
3182
|
case 27:
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3183
|
+
_u.trys.push([27, 41, 42, 43]);
|
|
3184
|
+
_l = (e_3 = void 0, __values(template.postprocessingFunctionNames)), _m = _l.next();
|
|
3185
|
+
_u.label = 28;
|
|
3383
3186
|
case 28:
|
|
3384
|
-
if (!!
|
|
3385
|
-
functionName =
|
|
3187
|
+
if (!!_m.done) return [3 /*break*/, 40];
|
|
3188
|
+
functionName = _m.value;
|
|
3386
3189
|
postprocessingError = null;
|
|
3387
|
-
|
|
3190
|
+
_u.label = 29;
|
|
3388
3191
|
case 29:
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
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;
|
|
3392
3195
|
case 30:
|
|
3393
|
-
if (!!
|
|
3394
|
-
scriptTools =
|
|
3395
|
-
|
|
3196
|
+
if (!!_p.done) return [3 /*break*/, 35];
|
|
3197
|
+
scriptTools = _p.value;
|
|
3198
|
+
_u.label = 31;
|
|
3396
3199
|
case 31:
|
|
3397
|
-
|
|
3398
|
-
|
|
3200
|
+
_u.trys.push([31, 33, , 34]);
|
|
3201
|
+
_q = $ongoingTemplateResult;
|
|
3399
3202
|
return [4 /*yield*/, scriptTools.execute({
|
|
3400
3203
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3401
3204
|
script: "".concat(functionName, "(resultString)"),
|
|
3402
3205
|
parameters: {
|
|
3403
|
-
resultString: $
|
|
3206
|
+
resultString: $ongoingTemplateResult.$resultString || '',
|
|
3404
3207
|
// Note: No ...parametersForTemplate, because working with result only
|
|
3405
3208
|
},
|
|
3406
3209
|
})];
|
|
3407
3210
|
case 32:
|
|
3408
|
-
|
|
3211
|
+
_q.$resultString = _u.sent();
|
|
3409
3212
|
postprocessingError = null;
|
|
3410
3213
|
return [3 /*break*/, 35];
|
|
3411
3214
|
case 33:
|
|
3412
|
-
error_2 =
|
|
3215
|
+
error_2 = _u.sent();
|
|
3413
3216
|
if (!(error_2 instanceof Error)) {
|
|
3414
3217
|
throw error_2;
|
|
3415
3218
|
}
|
|
@@ -3417,104 +3220,106 @@
|
|
|
3417
3220
|
throw error_2;
|
|
3418
3221
|
}
|
|
3419
3222
|
postprocessingError = error_2;
|
|
3420
|
-
$
|
|
3223
|
+
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
3421
3224
|
return [3 /*break*/, 34];
|
|
3422
3225
|
case 34:
|
|
3423
|
-
|
|
3226
|
+
_p = _o.next();
|
|
3424
3227
|
return [3 /*break*/, 30];
|
|
3425
3228
|
case 35: return [3 /*break*/, 38];
|
|
3426
3229
|
case 36:
|
|
3427
|
-
|
|
3428
|
-
|
|
3230
|
+
e_2_1 = _u.sent();
|
|
3231
|
+
e_2 = { error: e_2_1 };
|
|
3429
3232
|
return [3 /*break*/, 38];
|
|
3430
3233
|
case 37:
|
|
3431
3234
|
try {
|
|
3432
|
-
if (
|
|
3235
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3433
3236
|
}
|
|
3434
|
-
finally { if (
|
|
3237
|
+
finally { if (e_2) throw e_2.error; }
|
|
3435
3238
|
return [7 /*endfinally*/];
|
|
3436
3239
|
case 38:
|
|
3437
3240
|
if (postprocessingError) {
|
|
3438
3241
|
throw postprocessingError;
|
|
3439
3242
|
}
|
|
3440
|
-
|
|
3243
|
+
_u.label = 39;
|
|
3441
3244
|
case 39:
|
|
3442
|
-
|
|
3245
|
+
_m = _l.next();
|
|
3443
3246
|
return [3 /*break*/, 28];
|
|
3444
3247
|
case 40: return [3 /*break*/, 43];
|
|
3445
3248
|
case 41:
|
|
3446
|
-
|
|
3447
|
-
|
|
3249
|
+
e_3_1 = _u.sent();
|
|
3250
|
+
e_3 = { error: e_3_1 };
|
|
3448
3251
|
return [3 /*break*/, 43];
|
|
3449
3252
|
case 42:
|
|
3450
3253
|
try {
|
|
3451
|
-
if (
|
|
3254
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3452
3255
|
}
|
|
3453
|
-
finally { if (
|
|
3256
|
+
finally { if (e_3) throw e_3.error; }
|
|
3454
3257
|
return [7 /*endfinally*/];
|
|
3455
3258
|
case 43:
|
|
3456
3259
|
// TODO: [π] Unite object for expecting amount and format
|
|
3457
|
-
if (
|
|
3458
|
-
if (
|
|
3459
|
-
if (!isValidJsonString($
|
|
3260
|
+
if (template.format) {
|
|
3261
|
+
if (template.format === 'JSON') {
|
|
3262
|
+
if (!isValidJsonString($ongoingTemplateResult.$resultString || '')) {
|
|
3460
3263
|
// TODO: [π’] Do more universally via `FormatDefinition`
|
|
3461
3264
|
try {
|
|
3462
|
-
$
|
|
3265
|
+
$ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
|
|
3463
3266
|
}
|
|
3464
3267
|
catch (error) {
|
|
3465
3268
|
keepUnused(error);
|
|
3466
|
-
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3467
|
-
/*<- 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 "); }));
|
|
3468
3271
|
}
|
|
3469
3272
|
}
|
|
3470
3273
|
}
|
|
3471
3274
|
else {
|
|
3472
|
-
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 "); }));
|
|
3473
3276
|
}
|
|
3474
3277
|
}
|
|
3475
3278
|
// TODO: [π] Unite object for expecting amount and format
|
|
3476
|
-
if (
|
|
3477
|
-
checkExpectations(
|
|
3279
|
+
if (template.expectations) {
|
|
3280
|
+
checkExpectations(template.expectations, $ongoingTemplateResult.$resultString || '');
|
|
3478
3281
|
}
|
|
3479
3282
|
return [2 /*return*/, "break-attempts"];
|
|
3480
3283
|
case 44:
|
|
3481
|
-
error_3 =
|
|
3284
|
+
error_3 = _u.sent();
|
|
3482
3285
|
if (!(error_3 instanceof ExpectError)) {
|
|
3483
3286
|
throw error_3;
|
|
3484
3287
|
}
|
|
3485
|
-
$
|
|
3288
|
+
$ongoingTemplateResult.$expectError = error_3;
|
|
3486
3289
|
return [3 /*break*/, 46];
|
|
3487
3290
|
case 45:
|
|
3488
3291
|
if (!isJokerAttempt &&
|
|
3489
|
-
|
|
3490
|
-
$
|
|
3292
|
+
template.templateType === 'PROMPT_TEMPLATE' &&
|
|
3293
|
+
$ongoingTemplateResult.$prompt
|
|
3491
3294
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3492
3295
|
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3493
3296
|
) {
|
|
3494
3297
|
// TODO: [π§ ] Maybe put other templateTypes into report
|
|
3495
3298
|
$executionReport.promptExecutions.push({
|
|
3496
|
-
prompt: __assign({}, $
|
|
3497
|
-
result: $
|
|
3498
|
-
error: $
|
|
3299
|
+
prompt: __assign({}, $ongoingTemplateResult.$prompt),
|
|
3300
|
+
result: $ongoingTemplateResult.$result || undefined,
|
|
3301
|
+
error: $ongoingTemplateResult.$expectError === null
|
|
3302
|
+
? undefined
|
|
3303
|
+
: serializeError($ongoingTemplateResult.$expectError),
|
|
3499
3304
|
});
|
|
3500
3305
|
}
|
|
3501
3306
|
return [7 /*endfinally*/];
|
|
3502
3307
|
case 46:
|
|
3503
|
-
if ($
|
|
3308
|
+
if ($ongoingTemplateResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
3504
3309
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
|
|
3505
3310
|
var _a, _b, _c;
|
|
3506
|
-
return "\n
|
|
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) || '')
|
|
3507
3312
|
.split('\n')
|
|
3508
3313
|
.map(function (line) { return "> ".concat(line); })
|
|
3509
|
-
.join('\n')), "\n\n
|
|
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) || '')
|
|
3510
3315
|
.split('\n')
|
|
3511
3316
|
.map(function (line) { return "> ".concat(line); })
|
|
3512
|
-
.join('\n')), "\n\n
|
|
3317
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
|
|
3513
3318
|
? 'null'
|
|
3514
|
-
: $
|
|
3319
|
+
: $ongoingTemplateResult.$resultString
|
|
3515
3320
|
.split('\n')
|
|
3516
3321
|
.map(function (line) { return "> ".concat(line); })
|
|
3517
|
-
.join('\n')), "\n
|
|
3322
|
+
.join('\n')), "\n ---\n ");
|
|
3518
3323
|
}));
|
|
3519
3324
|
}
|
|
3520
3325
|
return [2 /*return*/];
|
|
@@ -3522,34 +3327,279 @@
|
|
|
3522
3327
|
});
|
|
3523
3328
|
};
|
|
3524
3329
|
attempt = -jokerParameterNames.length;
|
|
3525
|
-
|
|
3526
|
-
case
|
|
3527
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
3528
|
-
return [5 /*yield**/,
|
|
3529
|
-
case
|
|
3530
|
-
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();
|
|
3531
3336
|
switch (state_1) {
|
|
3532
|
-
case "break-attempts": return [3 /*break*/,
|
|
3337
|
+
case "break-attempts": return [3 /*break*/, 4];
|
|
3533
3338
|
}
|
|
3534
|
-
|
|
3535
|
-
case
|
|
3339
|
+
_a.label = 3;
|
|
3340
|
+
case 3:
|
|
3536
3341
|
attempt++;
|
|
3537
|
-
return [3 /*break*/,
|
|
3538
|
-
case
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
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) {
|
|
3553
3603
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3554
3604
|
}
|
|
3555
3605
|
return [4 /*yield*/, onProgress({
|
|
@@ -3559,13 +3609,13 @@
|
|
|
3559
3609
|
isDone: true,
|
|
3560
3610
|
templateType: currentTemplate.templateType,
|
|
3561
3611
|
parameterName: currentTemplate.resultingParameterName,
|
|
3562
|
-
parameterValue: $
|
|
3612
|
+
parameterValue: $ongoingTemplateResult.$resultString,
|
|
3563
3613
|
// <- [πΈ]
|
|
3564
3614
|
})];
|
|
3565
|
-
case
|
|
3615
|
+
case 4:
|
|
3566
3616
|
_h.sent();
|
|
3567
3617
|
return [2 /*return*/, Object.freeze((_g = {},
|
|
3568
|
-
_g[currentTemplate.resultingParameterName] = $
|
|
3618
|
+
_g[currentTemplate.resultingParameterName] = $ongoingTemplateResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3569
3619
|
_g))];
|
|
3570
3620
|
}
|
|
3571
3621
|
});
|
|
@@ -3841,6 +3891,8 @@
|
|
|
3841
3891
|
.then(function () {
|
|
3842
3892
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
3843
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
|
|
3844
3896
|
resolving_1.push(work_1);
|
|
3845
3897
|
_j.label = 4;
|
|
3846
3898
|
case 4: return [2 /*return*/];
|