@promptbook/core 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 +1 -1
- 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/esm/index.es.js
CHANGED
|
@@ -10,7 +10,7 @@ import moment from 'moment';
|
|
|
10
10
|
/**
|
|
11
11
|
* The version of the Promptbook library
|
|
12
12
|
*/
|
|
13
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
13
|
+
var PROMPTBOOK_VERSION = '0.69.0-7';
|
|
14
14
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
15
15
|
|
|
16
16
|
/*! *****************************************************************************
|
|
@@ -652,13 +652,13 @@ var IMMEDIATE_TIME = 10;
|
|
|
652
652
|
*
|
|
653
653
|
* @public exported from `@promptbook/core`
|
|
654
654
|
*/
|
|
655
|
-
var MAX_PARALLEL_COUNT = 5;
|
|
655
|
+
var MAX_PARALLEL_COUNT = 5; // <- TODO: [π€ΉββοΈ]
|
|
656
656
|
/**
|
|
657
657
|
* The maximum number of attempts to execute LLM task before giving up
|
|
658
658
|
*
|
|
659
659
|
* @public exported from `@promptbook/core`
|
|
660
660
|
*/
|
|
661
|
-
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
661
|
+
var MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [π€ΉββοΈ]
|
|
662
662
|
/**
|
|
663
663
|
* The maximum length of the (generated) filename
|
|
664
664
|
*
|
|
@@ -1817,7 +1817,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1817
1817
|
});
|
|
1818
1818
|
}
|
|
1819
1819
|
|
|
1820
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
1820
|
+
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"}];
|
|
1821
1821
|
|
|
1822
1822
|
var defaultDiacriticsRemovalMap = [
|
|
1823
1823
|
{
|
|
@@ -2377,6 +2377,23 @@ function isPipelinePrepared(pipeline) {
|
|
|
2377
2377
|
* - [β¨] Are templates prepared
|
|
2378
2378
|
*/
|
|
2379
2379
|
|
|
2380
|
+
/**
|
|
2381
|
+
* Serializes an error into a [π] JSON-serializable object
|
|
2382
|
+
*
|
|
2383
|
+
* @public exported from `@promptbook/utils`
|
|
2384
|
+
*/
|
|
2385
|
+
function serializeError(error) {
|
|
2386
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2387
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2388
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2389
|
+
}
|
|
2390
|
+
return {
|
|
2391
|
+
name: name,
|
|
2392
|
+
message: message,
|
|
2393
|
+
stack: stack,
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2380
2397
|
/**
|
|
2381
2398
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2382
2399
|
*
|
|
@@ -2670,23 +2687,6 @@ function joinLlmExecutionTools() {
|
|
|
2670
2687
|
* TODO: [π·ββοΈ] @@@ Manual about construction of llmTools
|
|
2671
2688
|
*/
|
|
2672
2689
|
|
|
2673
|
-
/**
|
|
2674
|
-
* Serializes an error into a [π] JSON-serializable object
|
|
2675
|
-
*
|
|
2676
|
-
* @public exported from `@promptbook/utils`
|
|
2677
|
-
*/
|
|
2678
|
-
function serializeError(error) {
|
|
2679
|
-
var name = error.name, message = error.message, stack = error.stack;
|
|
2680
|
-
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2681
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2682
|
-
}
|
|
2683
|
-
return {
|
|
2684
|
-
name: name,
|
|
2685
|
-
message: message,
|
|
2686
|
-
stack: stack,
|
|
2687
|
-
};
|
|
2688
|
-
}
|
|
2689
|
-
|
|
2690
2690
|
/**
|
|
2691
2691
|
* Takes an item or an array of items and returns an array of items
|
|
2692
2692
|
*
|
|
@@ -2824,6 +2824,81 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
2824
2824
|
* TODO: [π£] If script require contentLanguage
|
|
2825
2825
|
*/
|
|
2826
2826
|
|
|
2827
|
+
/**
|
|
2828
|
+
* Create difference set of two sets.
|
|
2829
|
+
*
|
|
2830
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2831
|
+
* @public exported from `@promptbook/utils`
|
|
2832
|
+
*/
|
|
2833
|
+
function difference(a, b, isEqual) {
|
|
2834
|
+
var e_1, _a;
|
|
2835
|
+
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
2836
|
+
var diff = new Set();
|
|
2837
|
+
var _loop_1 = function (itemA) {
|
|
2838
|
+
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
2839
|
+
diff.add(itemA);
|
|
2840
|
+
}
|
|
2841
|
+
};
|
|
2842
|
+
try {
|
|
2843
|
+
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2844
|
+
var itemA = _c.value;
|
|
2845
|
+
_loop_1(itemA);
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2849
|
+
finally {
|
|
2850
|
+
try {
|
|
2851
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2852
|
+
}
|
|
2853
|
+
finally { if (e_1) throw e_1.error; }
|
|
2854
|
+
}
|
|
2855
|
+
return diff;
|
|
2856
|
+
}
|
|
2857
|
+
/**
|
|
2858
|
+
* TODO: [π§ ][π―] Maybe also implement symmetricDifference
|
|
2859
|
+
*/
|
|
2860
|
+
|
|
2861
|
+
/**
|
|
2862
|
+
* Creates a new set with all elements that are present in either set
|
|
2863
|
+
*
|
|
2864
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2865
|
+
* @public exported from `@promptbook/utils`
|
|
2866
|
+
*/
|
|
2867
|
+
function union() {
|
|
2868
|
+
var e_1, _a, e_2, _b;
|
|
2869
|
+
var sets = [];
|
|
2870
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2871
|
+
sets[_i] = arguments[_i];
|
|
2872
|
+
}
|
|
2873
|
+
var union = new Set();
|
|
2874
|
+
try {
|
|
2875
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2876
|
+
var set = sets_1_1.value;
|
|
2877
|
+
try {
|
|
2878
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2879
|
+
var item = _d.value;
|
|
2880
|
+
union.add(item);
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2884
|
+
finally {
|
|
2885
|
+
try {
|
|
2886
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
2887
|
+
}
|
|
2888
|
+
finally { if (e_2) throw e_2.error; }
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2893
|
+
finally {
|
|
2894
|
+
try {
|
|
2895
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
2896
|
+
}
|
|
2897
|
+
finally { if (e_1) throw e_1.error; }
|
|
2898
|
+
}
|
|
2899
|
+
return union;
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2827
2902
|
/**
|
|
2828
2903
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2829
2904
|
*
|
|
@@ -3061,81 +3136,6 @@ function replaceParameters(template, parameters) {
|
|
|
3061
3136
|
return replacedTemplate;
|
|
3062
3137
|
}
|
|
3063
3138
|
|
|
3064
|
-
/**
|
|
3065
|
-
* Create difference set of two sets.
|
|
3066
|
-
*
|
|
3067
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
3068
|
-
* @public exported from `@promptbook/utils`
|
|
3069
|
-
*/
|
|
3070
|
-
function difference(a, b, isEqual) {
|
|
3071
|
-
var e_1, _a;
|
|
3072
|
-
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
3073
|
-
var diff = new Set();
|
|
3074
|
-
var _loop_1 = function (itemA) {
|
|
3075
|
-
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
3076
|
-
diff.add(itemA);
|
|
3077
|
-
}
|
|
3078
|
-
};
|
|
3079
|
-
try {
|
|
3080
|
-
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3081
|
-
var itemA = _c.value;
|
|
3082
|
-
_loop_1(itemA);
|
|
3083
|
-
}
|
|
3084
|
-
}
|
|
3085
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3086
|
-
finally {
|
|
3087
|
-
try {
|
|
3088
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3089
|
-
}
|
|
3090
|
-
finally { if (e_1) throw e_1.error; }
|
|
3091
|
-
}
|
|
3092
|
-
return diff;
|
|
3093
|
-
}
|
|
3094
|
-
/**
|
|
3095
|
-
* TODO: [π§ ][π―] Maybe also implement symmetricDifference
|
|
3096
|
-
*/
|
|
3097
|
-
|
|
3098
|
-
/**
|
|
3099
|
-
* Creates a new set with all elements that are present in either set
|
|
3100
|
-
*
|
|
3101
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
3102
|
-
* @public exported from `@promptbook/utils`
|
|
3103
|
-
*/
|
|
3104
|
-
function union() {
|
|
3105
|
-
var e_1, _a, e_2, _b;
|
|
3106
|
-
var sets = [];
|
|
3107
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3108
|
-
sets[_i] = arguments[_i];
|
|
3109
|
-
}
|
|
3110
|
-
var union = new Set();
|
|
3111
|
-
try {
|
|
3112
|
-
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
3113
|
-
var set = sets_1_1.value;
|
|
3114
|
-
try {
|
|
3115
|
-
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3116
|
-
var item = _d.value;
|
|
3117
|
-
union.add(item);
|
|
3118
|
-
}
|
|
3119
|
-
}
|
|
3120
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3121
|
-
finally {
|
|
3122
|
-
try {
|
|
3123
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
3124
|
-
}
|
|
3125
|
-
finally { if (e_2) throw e_2.error; }
|
|
3126
|
-
}
|
|
3127
|
-
}
|
|
3128
|
-
}
|
|
3129
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3130
|
-
finally {
|
|
3131
|
-
try {
|
|
3132
|
-
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
3133
|
-
}
|
|
3134
|
-
finally { if (e_1) throw e_1.error; }
|
|
3135
|
-
}
|
|
3136
|
-
return union;
|
|
3137
|
-
}
|
|
3138
|
-
|
|
3139
3139
|
/**
|
|
3140
3140
|
* Counts number of characters in the text
|
|
3141
3141
|
*
|
|
@@ -3285,246 +3285,49 @@ function isPassingExpectations(expectations, value) {
|
|
|
3285
3285
|
* TODO: [π] Unite object for expecting amount and format
|
|
3286
3286
|
*/
|
|
3287
3287
|
|
|
3288
|
-
/**
|
|
3289
|
-
* Just marks a place of place where should be something implemented
|
|
3290
|
-
* No side effects.
|
|
3291
|
-
*
|
|
3292
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
3293
|
-
*
|
|
3294
|
-
* @param value any values
|
|
3295
|
-
* @returns void
|
|
3296
|
-
* @private within the repository
|
|
3297
|
-
*/
|
|
3298
|
-
function TODO_USE() {
|
|
3299
|
-
var value = [];
|
|
3300
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3301
|
-
value[_i] = arguments[_i];
|
|
3302
|
-
}
|
|
3303
|
-
}
|
|
3304
|
-
|
|
3305
|
-
/**
|
|
3306
|
-
* @@@
|
|
3307
|
-
*
|
|
3308
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3309
|
-
*/
|
|
3310
|
-
function getContextForTemplate(template) {
|
|
3311
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3312
|
-
return __generator(this, function (_a) {
|
|
3313
|
-
TODO_USE(template);
|
|
3314
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [π] Implement */];
|
|
3315
|
-
});
|
|
3316
|
-
});
|
|
3317
|
-
}
|
|
3318
|
-
|
|
3319
|
-
/**
|
|
3320
|
-
* @@@
|
|
3321
|
-
*
|
|
3322
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3323
|
-
*/
|
|
3324
|
-
function getKnowledgeForTemplate(options) {
|
|
3325
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3326
|
-
var preparedPipeline, template;
|
|
3327
|
-
return __generator(this, function (_a) {
|
|
3328
|
-
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3329
|
-
// TODO: [β¨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3330
|
-
TODO_USE(template);
|
|
3331
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3332
|
-
var content = _a.content;
|
|
3333
|
-
return "- ".concat(content);
|
|
3334
|
-
}).join('\n')];
|
|
3335
|
-
});
|
|
3336
|
-
});
|
|
3337
|
-
}
|
|
3338
|
-
|
|
3339
3288
|
/**
|
|
3340
3289
|
* @@@
|
|
3341
3290
|
*
|
|
3342
3291
|
* @private internal utility of `createPipelineExecutor`
|
|
3343
3292
|
*/
|
|
3344
|
-
function
|
|
3293
|
+
function executeAttempts(options) {
|
|
3345
3294
|
return __awaiter(this, void 0, void 0, function () {
|
|
3295
|
+
var $ongoingTemplateResult, jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, llmTools, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, _loop_1, attempt, state_1;
|
|
3346
3296
|
return __generator(this, function (_a) {
|
|
3347
|
-
|
|
3348
|
-
TODO_USE(template);
|
|
3349
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [β¨] Implement */];
|
|
3350
|
-
});
|
|
3351
|
-
});
|
|
3352
|
-
}
|
|
3353
|
-
|
|
3354
|
-
/**
|
|
3355
|
-
* @@@
|
|
3356
|
-
*
|
|
3357
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3358
|
-
*/
|
|
3359
|
-
function getReservedParametersForTemplate(options) {
|
|
3360
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3361
|
-
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3362
|
-
var e_1, _a;
|
|
3363
|
-
return __generator(this, function (_b) {
|
|
3364
|
-
switch (_b.label) {
|
|
3297
|
+
switch (_a.label) {
|
|
3365
3298
|
case 0:
|
|
3366
|
-
|
|
3367
|
-
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3368
|
-
case 1:
|
|
3369
|
-
context = _b.sent();
|
|
3370
|
-
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3371
|
-
case 2:
|
|
3372
|
-
knowledge = _b.sent();
|
|
3373
|
-
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3374
|
-
case 3:
|
|
3375
|
-
samples = _b.sent();
|
|
3376
|
-
currentDate = new Date().toISOString();
|
|
3377
|
-
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3378
|
-
reservedParameters = {
|
|
3379
|
-
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3380
|
-
context: context,
|
|
3381
|
-
knowledge: knowledge,
|
|
3382
|
-
samples: samples,
|
|
3383
|
-
currentDate: currentDate,
|
|
3384
|
-
modelName: modelName,
|
|
3385
|
-
};
|
|
3386
|
-
_loop_1 = function (parameterName) {
|
|
3387
|
-
if (reservedParameters[parameterName] === undefined) {
|
|
3388
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3389
|
-
}
|
|
3390
|
-
};
|
|
3391
|
-
try {
|
|
3392
|
-
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3393
|
-
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()) {
|
|
3394
|
-
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3395
|
-
_loop_1(parameterName);
|
|
3396
|
-
}
|
|
3397
|
-
}
|
|
3398
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3399
|
-
finally {
|
|
3400
|
-
try {
|
|
3401
|
-
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3402
|
-
}
|
|
3403
|
-
finally { if (e_1) throw e_1.error; }
|
|
3404
|
-
}
|
|
3405
|
-
return [2 /*return*/, reservedParameters];
|
|
3406
|
-
}
|
|
3407
|
-
});
|
|
3408
|
-
});
|
|
3409
|
-
}
|
|
3410
|
-
|
|
3411
|
-
/**
|
|
3412
|
-
* @@@
|
|
3413
|
-
*
|
|
3414
|
-
* @private internal utility of `createPipelineExecutor`
|
|
3415
|
-
*/
|
|
3416
|
-
function executeTemplate(options) {
|
|
3417
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3418
|
-
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;
|
|
3419
|
-
var e_1, _f, _g;
|
|
3420
|
-
return __generator(this, function (_h) {
|
|
3421
|
-
switch (_h.label) {
|
|
3422
|
-
case 0:
|
|
3423
|
-
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;
|
|
3299
|
+
$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;
|
|
3424
3300
|
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
title: title,
|
|
3431
|
-
isStarted: false,
|
|
3432
|
-
isDone: false,
|
|
3433
|
-
templateType: currentTemplate.templateType,
|
|
3434
|
-
parameterName: currentTemplate.resultingParameterName,
|
|
3435
|
-
parameterValue: null,
|
|
3436
|
-
// <- [πΈ]
|
|
3437
|
-
})];
|
|
3438
|
-
case 1:
|
|
3439
|
-
_h.sent();
|
|
3440
|
-
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3441
|
-
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3442
|
-
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3443
|
-
throw new UnexpectedError(spaceTrim$1(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)
|
|
3444
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3445
|
-
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3446
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3447
|
-
.join(', '), "\n\n "); }));
|
|
3448
|
-
}
|
|
3449
|
-
_b = (_a = Object).freeze;
|
|
3450
|
-
_c = [{}];
|
|
3451
|
-
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3452
|
-
preparedPipeline: preparedPipeline,
|
|
3453
|
-
template: currentTemplate,
|
|
3454
|
-
pipelineIdentification: pipelineIdentification,
|
|
3455
|
-
})];
|
|
3456
|
-
case 2:
|
|
3457
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3458
|
-
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3459
|
-
parameters = {};
|
|
3460
|
-
_loop_1 = function (parameterName) {
|
|
3461
|
-
// Situation: Parameter is defined and used
|
|
3462
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3463
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3464
|
-
}
|
|
3465
|
-
// Situation: Parameter is defined but NOT used
|
|
3466
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3467
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3468
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3469
|
-
// Houston, we have a problem
|
|
3470
|
-
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3471
|
-
throw new UnexpectedError(spaceTrim$1(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 "); }));
|
|
3472
|
-
}
|
|
3473
|
-
};
|
|
3474
|
-
try {
|
|
3475
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3476
|
-
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3477
|
-
parameterName = _e.value;
|
|
3478
|
-
_loop_1(parameterName);
|
|
3479
|
-
}
|
|
3480
|
-
}
|
|
3481
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3482
|
-
finally {
|
|
3483
|
-
try {
|
|
3484
|
-
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3485
|
-
}
|
|
3486
|
-
finally { if (e_1) throw e_1.error; }
|
|
3487
|
-
}
|
|
3488
|
-
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3489
|
-
Object.freeze(parameters);
|
|
3490
|
-
result = null;
|
|
3491
|
-
resultString = null;
|
|
3492
|
-
expectError = null;
|
|
3493
|
-
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3494
|
-
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3495
|
-
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3496
|
-
.split('{content}')
|
|
3497
|
-
.join(currentTemplate.content);
|
|
3498
|
-
_loop_2 = function (attempt) {
|
|
3499
|
-
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;
|
|
3500
|
-
var e_2, _s, e_4, _t, e_3, _u;
|
|
3501
|
-
return __generator(this, function (_v) {
|
|
3502
|
-
switch (_v.label) {
|
|
3301
|
+
_loop_1 = function (attempt) {
|
|
3302
|
+
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;
|
|
3303
|
+
var e_1, _r, e_3, _s, e_2, _t;
|
|
3304
|
+
return __generator(this, function (_u) {
|
|
3305
|
+
switch (_u.label) {
|
|
3503
3306
|
case 0:
|
|
3504
3307
|
isJokerAttempt = attempt < 0;
|
|
3505
3308
|
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3506
3309
|
// TODO: [π§ ] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3507
3310
|
if (isJokerAttempt && !jokerParameterName) {
|
|
3508
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n
|
|
3311
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3509
3312
|
}
|
|
3510
|
-
result = null;
|
|
3511
|
-
resultString = null;
|
|
3512
|
-
expectError = null;
|
|
3313
|
+
$ongoingTemplateResult.$result = null;
|
|
3314
|
+
$ongoingTemplateResult.$resultString = null;
|
|
3315
|
+
$ongoingTemplateResult.$expectError = null;
|
|
3513
3316
|
if (isJokerAttempt) {
|
|
3514
3317
|
if (parameters[jokerParameterName] === undefined) {
|
|
3515
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n
|
|
3318
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3516
3319
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3517
3320
|
}
|
|
3518
3321
|
else {
|
|
3519
|
-
resultString = parameters[jokerParameterName];
|
|
3322
|
+
$ongoingTemplateResult.$resultString = parameters[jokerParameterName];
|
|
3520
3323
|
}
|
|
3521
3324
|
}
|
|
3522
|
-
|
|
3325
|
+
_u.label = 1;
|
|
3523
3326
|
case 1:
|
|
3524
|
-
|
|
3327
|
+
_u.trys.push([1, 44, 45, 46]);
|
|
3525
3328
|
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3526
|
-
|
|
3527
|
-
switch (
|
|
3329
|
+
_b = template.templateType;
|
|
3330
|
+
switch (_b) {
|
|
3528
3331
|
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3529
3332
|
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3530
3333
|
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
@@ -3532,125 +3335,136 @@ function executeTemplate(options) {
|
|
|
3532
3335
|
}
|
|
3533
3336
|
return [3 /*break*/, 25];
|
|
3534
3337
|
case 2:
|
|
3535
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3338
|
+
$ongoingTemplateResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
3536
3339
|
return [3 /*break*/, 26];
|
|
3537
3340
|
case 3:
|
|
3538
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (
|
|
3539
|
-
prompt = {
|
|
3540
|
-
title:
|
|
3341
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (template.modelRequirements || {}));
|
|
3342
|
+
$ongoingTemplateResult.$prompt = {
|
|
3343
|
+
title: template.title,
|
|
3541
3344
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3542
3345
|
? preparedPipeline.pipelineUrl
|
|
3543
|
-
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(
|
|
3346
|
+
: 'anonymous' /* <- TODO: [π§ ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name),
|
|
3544
3347
|
parameters: parameters,
|
|
3545
3348
|
content: preparedContent,
|
|
3546
3349
|
modelRequirements: modelRequirements,
|
|
3547
3350
|
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3548
3351
|
var name = _a.name;
|
|
3549
|
-
return name ===
|
|
3550
|
-
}) ||
|
|
3551
|
-
|
|
3552
|
-
|
|
3352
|
+
return name === template.personaName;
|
|
3353
|
+
}) ||
|
|
3354
|
+
{})), template.expectations),
|
|
3355
|
+
format: template.format,
|
|
3356
|
+
postprocessingFunctionNames: template.postprocessingFunctionNames,
|
|
3553
3357
|
}; // <- TODO: Not very good type guard
|
|
3554
|
-
|
|
3555
|
-
switch (
|
|
3358
|
+
_c = modelRequirements.modelVariant;
|
|
3359
|
+
switch (_c) {
|
|
3556
3360
|
case 'CHAT': return [3 /*break*/, 4];
|
|
3557
3361
|
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3558
3362
|
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3559
3363
|
}
|
|
3560
3364
|
return [3 /*break*/, 10];
|
|
3561
|
-
case 4:
|
|
3365
|
+
case 4:
|
|
3366
|
+
_d = $ongoingTemplateResult;
|
|
3367
|
+
return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3562
3368
|
case 5:
|
|
3563
|
-
chatResult =
|
|
3369
|
+
_d.$chatResult = _u.sent();
|
|
3564
3370
|
// TODO: [π¬] Destroy chatThread
|
|
3565
|
-
result = chatResult;
|
|
3566
|
-
resultString = chatResult.content;
|
|
3371
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$chatResult;
|
|
3372
|
+
$ongoingTemplateResult.$resultString = $ongoingTemplateResult.$chatResult.content;
|
|
3567
3373
|
return [3 /*break*/, 11];
|
|
3568
|
-
case 6:
|
|
3374
|
+
case 6:
|
|
3375
|
+
_e = $ongoingTemplateResult;
|
|
3376
|
+
return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3569
3377
|
case 7:
|
|
3570
|
-
completionResult =
|
|
3571
|
-
result = completionResult;
|
|
3572
|
-
resultString =
|
|
3378
|
+
_e.$completionResult = _u.sent();
|
|
3379
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$completionResult;
|
|
3380
|
+
$ongoingTemplateResult.$resultString =
|
|
3381
|
+
$ongoingTemplateResult.$completionResult.content;
|
|
3573
3382
|
return [3 /*break*/, 11];
|
|
3574
|
-
case 8:
|
|
3383
|
+
case 8:
|
|
3384
|
+
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3385
|
+
_f = $ongoingTemplateResult;
|
|
3386
|
+
return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3575
3387
|
case 9:
|
|
3576
3388
|
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3577
|
-
embeddingResult =
|
|
3578
|
-
result = embeddingResult;
|
|
3579
|
-
resultString =
|
|
3389
|
+
_f.$embeddingResult = _u.sent();
|
|
3390
|
+
$ongoingTemplateResult.$result = $ongoingTemplateResult.$embeddingResult;
|
|
3391
|
+
$ongoingTemplateResult.$resultString =
|
|
3392
|
+
$ongoingTemplateResult.$embeddingResult.content.join(',');
|
|
3580
3393
|
return [3 /*break*/, 11];
|
|
3581
|
-
case 10: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n
|
|
3394
|
+
case 10: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(template.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3582
3395
|
case 11: return [3 /*break*/, 26];
|
|
3583
3396
|
case 12:
|
|
3584
3397
|
if (arrayableToArray(tools.script).length === 0) {
|
|
3585
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n
|
|
3398
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3586
3399
|
}
|
|
3587
|
-
if (!
|
|
3588
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n
|
|
3400
|
+
if (!template.contentLanguage) {
|
|
3401
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(template.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3589
3402
|
}
|
|
3590
|
-
|
|
3591
|
-
scriptPipelineExecutionErrors = [];
|
|
3592
|
-
_v.label = 13;
|
|
3403
|
+
_u.label = 13;
|
|
3593
3404
|
case 13:
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3405
|
+
_u.trys.push([13, 20, 21, 22]);
|
|
3406
|
+
_g = (e_1 = void 0, __values(arrayableToArray(tools.script))), _h = _g.next();
|
|
3407
|
+
_u.label = 14;
|
|
3597
3408
|
case 14:
|
|
3598
|
-
if (!!
|
|
3599
|
-
scriptTools =
|
|
3600
|
-
|
|
3409
|
+
if (!!_h.done) return [3 /*break*/, 19];
|
|
3410
|
+
scriptTools = _h.value;
|
|
3411
|
+
_u.label = 15;
|
|
3601
3412
|
case 15:
|
|
3602
|
-
|
|
3413
|
+
_u.trys.push([15, 17, , 18]);
|
|
3414
|
+
_j = $ongoingTemplateResult;
|
|
3603
3415
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3604
|
-
scriptLanguage:
|
|
3416
|
+
scriptLanguage: template.contentLanguage,
|
|
3605
3417
|
script: preparedContent,
|
|
3606
3418
|
parameters: parameters,
|
|
3607
3419
|
}))];
|
|
3608
3420
|
case 16:
|
|
3609
|
-
resultString =
|
|
3421
|
+
_j.$resultString = _u.sent();
|
|
3610
3422
|
return [3 /*break*/, 19];
|
|
3611
3423
|
case 17:
|
|
3612
|
-
error_1 =
|
|
3424
|
+
error_1 = _u.sent();
|
|
3613
3425
|
if (!(error_1 instanceof Error)) {
|
|
3614
3426
|
throw error_1;
|
|
3615
3427
|
}
|
|
3616
3428
|
if (error_1 instanceof UnexpectedError) {
|
|
3617
3429
|
throw error_1;
|
|
3618
3430
|
}
|
|
3619
|
-
scriptPipelineExecutionErrors.push(error_1);
|
|
3431
|
+
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
3620
3432
|
return [3 /*break*/, 18];
|
|
3621
3433
|
case 18:
|
|
3622
|
-
|
|
3434
|
+
_h = _g.next();
|
|
3623
3435
|
return [3 /*break*/, 14];
|
|
3624
3436
|
case 19: return [3 /*break*/, 22];
|
|
3625
3437
|
case 20:
|
|
3626
|
-
|
|
3627
|
-
|
|
3438
|
+
e_1_1 = _u.sent();
|
|
3439
|
+
e_1 = { error: e_1_1 };
|
|
3628
3440
|
return [3 /*break*/, 22];
|
|
3629
3441
|
case 21:
|
|
3630
3442
|
try {
|
|
3631
|
-
if (
|
|
3443
|
+
if (_h && !_h.done && (_r = _g.return)) _r.call(_g);
|
|
3632
3444
|
}
|
|
3633
|
-
finally { if (
|
|
3445
|
+
finally { if (e_1) throw e_1.error; }
|
|
3634
3446
|
return [7 /*endfinally*/];
|
|
3635
3447
|
case 22:
|
|
3636
|
-
if (resultString !== null) {
|
|
3448
|
+
if ($ongoingTemplateResult.$resultString !== null) {
|
|
3637
3449
|
return [3 /*break*/, 26];
|
|
3638
3450
|
}
|
|
3639
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3640
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3451
|
+
if ($ongoingTemplateResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
3452
|
+
throw $ongoingTemplateResult.$scriptPipelineExecutionErrors[0];
|
|
3641
3453
|
}
|
|
3642
3454
|
else {
|
|
3643
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n
|
|
3455
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($ongoingTemplateResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTemplateResult.$scriptPipelineExecutionErrors
|
|
3644
3456
|
.map(function (error) { return '- ' + error.message; })
|
|
3645
|
-
.join('\n\n')), "\n
|
|
3457
|
+
.join('\n\n')), "\n "); }));
|
|
3646
3458
|
}
|
|
3647
3459
|
case 23:
|
|
3648
3460
|
if (tools.userInterface === undefined) {
|
|
3649
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n
|
|
3461
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3650
3462
|
}
|
|
3463
|
+
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3464
|
+
_k = $ongoingTemplateResult;
|
|
3651
3465
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3652
|
-
promptTitle:
|
|
3653
|
-
promptMessage: replaceParameters(
|
|
3466
|
+
promptTitle: template.title,
|
|
3467
|
+
promptMessage: replaceParameters(template.description || '', parameters),
|
|
3654
3468
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3655
3469
|
// TODO: [π§ ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3656
3470
|
placeholder: undefined,
|
|
@@ -3658,47 +3472,46 @@ function executeTemplate(options) {
|
|
|
3658
3472
|
}))];
|
|
3659
3473
|
case 24:
|
|
3660
3474
|
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3661
|
-
resultString =
|
|
3475
|
+
_k.$resultString = _u.sent();
|
|
3662
3476
|
return [3 /*break*/, 26];
|
|
3663
|
-
case 25: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n
|
|
3477
|
+
case 25: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(template.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3664
3478
|
case 26:
|
|
3665
|
-
if (!(!isJokerAttempt &&
|
|
3666
|
-
|
|
3479
|
+
if (!(!isJokerAttempt && template.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3480
|
+
_u.label = 27;
|
|
3667
3481
|
case 27:
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3482
|
+
_u.trys.push([27, 41, 42, 43]);
|
|
3483
|
+
_l = (e_3 = void 0, __values(template.postprocessingFunctionNames)), _m = _l.next();
|
|
3484
|
+
_u.label = 28;
|
|
3671
3485
|
case 28:
|
|
3672
|
-
if (!!
|
|
3673
|
-
functionName =
|
|
3674
|
-
// TODO: DRY [1]
|
|
3675
|
-
scriptPipelineExecutionErrors = [];
|
|
3486
|
+
if (!!_m.done) return [3 /*break*/, 40];
|
|
3487
|
+
functionName = _m.value;
|
|
3676
3488
|
postprocessingError = null;
|
|
3677
|
-
|
|
3489
|
+
_u.label = 29;
|
|
3678
3490
|
case 29:
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3491
|
+
_u.trys.push([29, 36, 37, 38]);
|
|
3492
|
+
_o = (e_2 = void 0, __values(arrayableToArray(tools.script))), _p = _o.next();
|
|
3493
|
+
_u.label = 30;
|
|
3682
3494
|
case 30:
|
|
3683
|
-
if (!!
|
|
3684
|
-
scriptTools =
|
|
3685
|
-
|
|
3495
|
+
if (!!_p.done) return [3 /*break*/, 35];
|
|
3496
|
+
scriptTools = _p.value;
|
|
3497
|
+
_u.label = 31;
|
|
3686
3498
|
case 31:
|
|
3687
|
-
|
|
3499
|
+
_u.trys.push([31, 33, , 34]);
|
|
3500
|
+
_q = $ongoingTemplateResult;
|
|
3688
3501
|
return [4 /*yield*/, scriptTools.execute({
|
|
3689
3502
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3690
3503
|
script: "".concat(functionName, "(resultString)"),
|
|
3691
3504
|
parameters: {
|
|
3692
|
-
resultString: resultString || '',
|
|
3505
|
+
resultString: $ongoingTemplateResult.$resultString || '',
|
|
3693
3506
|
// Note: No ...parametersForTemplate, because working with result only
|
|
3694
3507
|
},
|
|
3695
3508
|
})];
|
|
3696
3509
|
case 32:
|
|
3697
|
-
resultString =
|
|
3510
|
+
_q.$resultString = _u.sent();
|
|
3698
3511
|
postprocessingError = null;
|
|
3699
3512
|
return [3 /*break*/, 35];
|
|
3700
3513
|
case 33:
|
|
3701
|
-
error_2 =
|
|
3514
|
+
error_2 = _u.sent();
|
|
3702
3515
|
if (!(error_2 instanceof Error)) {
|
|
3703
3516
|
throw error_2;
|
|
3704
3517
|
}
|
|
@@ -3706,136 +3519,386 @@ function executeTemplate(options) {
|
|
|
3706
3519
|
throw error_2;
|
|
3707
3520
|
}
|
|
3708
3521
|
postprocessingError = error_2;
|
|
3709
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3522
|
+
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
3710
3523
|
return [3 /*break*/, 34];
|
|
3711
3524
|
case 34:
|
|
3712
|
-
|
|
3525
|
+
_p = _o.next();
|
|
3713
3526
|
return [3 /*break*/, 30];
|
|
3714
3527
|
case 35: return [3 /*break*/, 38];
|
|
3715
3528
|
case 36:
|
|
3716
|
-
|
|
3717
|
-
|
|
3529
|
+
e_2_1 = _u.sent();
|
|
3530
|
+
e_2 = { error: e_2_1 };
|
|
3718
3531
|
return [3 /*break*/, 38];
|
|
3719
3532
|
case 37:
|
|
3720
3533
|
try {
|
|
3721
|
-
if (
|
|
3534
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3722
3535
|
}
|
|
3723
|
-
finally { if (
|
|
3536
|
+
finally { if (e_2) throw e_2.error; }
|
|
3724
3537
|
return [7 /*endfinally*/];
|
|
3725
3538
|
case 38:
|
|
3726
3539
|
if (postprocessingError) {
|
|
3727
3540
|
throw postprocessingError;
|
|
3728
3541
|
}
|
|
3729
|
-
|
|
3542
|
+
_u.label = 39;
|
|
3730
3543
|
case 39:
|
|
3731
|
-
|
|
3544
|
+
_m = _l.next();
|
|
3732
3545
|
return [3 /*break*/, 28];
|
|
3733
3546
|
case 40: return [3 /*break*/, 43];
|
|
3734
3547
|
case 41:
|
|
3735
|
-
|
|
3736
|
-
|
|
3548
|
+
e_3_1 = _u.sent();
|
|
3549
|
+
e_3 = { error: e_3_1 };
|
|
3737
3550
|
return [3 /*break*/, 43];
|
|
3738
3551
|
case 42:
|
|
3739
3552
|
try {
|
|
3740
|
-
if (
|
|
3553
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3741
3554
|
}
|
|
3742
|
-
finally { if (
|
|
3555
|
+
finally { if (e_3) throw e_3.error; }
|
|
3743
3556
|
return [7 /*endfinally*/];
|
|
3744
3557
|
case 43:
|
|
3745
3558
|
// TODO: [π] Unite object for expecting amount and format
|
|
3746
|
-
if (
|
|
3747
|
-
if (
|
|
3748
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3559
|
+
if (template.format) {
|
|
3560
|
+
if (template.format === 'JSON') {
|
|
3561
|
+
if (!isValidJsonString($ongoingTemplateResult.$resultString || '')) {
|
|
3749
3562
|
// TODO: [π’] Do more universally via `FormatDefinition`
|
|
3750
3563
|
try {
|
|
3751
|
-
resultString = extractJsonBlock(resultString || '');
|
|
3564
|
+
$ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
|
|
3752
3565
|
}
|
|
3753
3566
|
catch (error) {
|
|
3754
3567
|
keepUnused(error);
|
|
3755
|
-
throw new ExpectError(spaceTrim$1(function (block) { return "\n
|
|
3756
|
-
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n
|
|
3568
|
+
throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3569
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3757
3570
|
}
|
|
3758
3571
|
}
|
|
3759
3572
|
}
|
|
3760
3573
|
else {
|
|
3761
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n
|
|
3574
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(template.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3762
3575
|
}
|
|
3763
3576
|
}
|
|
3764
3577
|
// TODO: [π] Unite object for expecting amount and format
|
|
3765
|
-
if (
|
|
3766
|
-
checkExpectations(
|
|
3578
|
+
if (template.expectations) {
|
|
3579
|
+
checkExpectations(template.expectations, $ongoingTemplateResult.$resultString || '');
|
|
3767
3580
|
}
|
|
3768
3581
|
return [2 /*return*/, "break-attempts"];
|
|
3769
3582
|
case 44:
|
|
3770
|
-
error_3 =
|
|
3583
|
+
error_3 = _u.sent();
|
|
3771
3584
|
if (!(error_3 instanceof ExpectError)) {
|
|
3772
3585
|
throw error_3;
|
|
3773
3586
|
}
|
|
3774
|
-
expectError = error_3;
|
|
3587
|
+
$ongoingTemplateResult.$expectError = error_3;
|
|
3775
3588
|
return [3 /*break*/, 46];
|
|
3776
3589
|
case 45:
|
|
3777
3590
|
if (!isJokerAttempt &&
|
|
3778
|
-
|
|
3779
|
-
prompt
|
|
3591
|
+
template.templateType === 'PROMPT_TEMPLATE' &&
|
|
3592
|
+
$ongoingTemplateResult.$prompt
|
|
3780
3593
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3781
3594
|
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3782
3595
|
) {
|
|
3783
3596
|
// TODO: [π§ ] Maybe put other templateTypes into report
|
|
3784
3597
|
$executionReport.promptExecutions.push({
|
|
3785
|
-
prompt: __assign({}, prompt),
|
|
3786
|
-
result: result || undefined,
|
|
3787
|
-
error: expectError === null
|
|
3598
|
+
prompt: __assign({}, $ongoingTemplateResult.$prompt),
|
|
3599
|
+
result: $ongoingTemplateResult.$result || undefined,
|
|
3600
|
+
error: $ongoingTemplateResult.$expectError === null
|
|
3601
|
+
? undefined
|
|
3602
|
+
: serializeError($ongoingTemplateResult.$expectError),
|
|
3788
3603
|
});
|
|
3789
3604
|
}
|
|
3790
3605
|
return [7 /*endfinally*/];
|
|
3791
3606
|
case 46:
|
|
3792
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3793
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) {
|
|
3794
|
-
|
|
3795
|
-
.
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3800
|
-
? 'null'
|
|
3801
|
-
: resultString
|
|
3607
|
+
if ($ongoingTemplateResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
3608
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) {
|
|
3609
|
+
var _a, _b, _c;
|
|
3610
|
+
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) || '')
|
|
3611
|
+
.split('\n')
|
|
3612
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3613
|
+
.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) || '')
|
|
3802
3614
|
.split('\n')
|
|
3803
3615
|
.map(function (line) { return "> ".concat(line); })
|
|
3804
|
-
.join('\n')), "\n
|
|
3616
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
|
|
3617
|
+
? 'null'
|
|
3618
|
+
: $ongoingTemplateResult.$resultString
|
|
3619
|
+
.split('\n')
|
|
3620
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3621
|
+
.join('\n')), "\n ---\n ");
|
|
3622
|
+
}));
|
|
3805
3623
|
}
|
|
3806
3624
|
return [2 /*return*/];
|
|
3807
3625
|
}
|
|
3808
3626
|
});
|
|
3809
3627
|
};
|
|
3810
3628
|
attempt = -jokerParameterNames.length;
|
|
3811
|
-
|
|
3812
|
-
case
|
|
3813
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
3814
|
-
return [5 /*yield**/,
|
|
3815
|
-
case
|
|
3816
|
-
state_1 =
|
|
3629
|
+
_a.label = 1;
|
|
3630
|
+
case 1:
|
|
3631
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 4];
|
|
3632
|
+
return [5 /*yield**/, _loop_1(attempt)];
|
|
3633
|
+
case 2:
|
|
3634
|
+
state_1 = _a.sent();
|
|
3817
3635
|
switch (state_1) {
|
|
3818
|
-
case "break-attempts": return [3 /*break*/,
|
|
3636
|
+
case "break-attempts": return [3 /*break*/, 4];
|
|
3819
3637
|
}
|
|
3820
|
-
|
|
3821
|
-
case
|
|
3638
|
+
_a.label = 3;
|
|
3639
|
+
case 3:
|
|
3822
3640
|
attempt++;
|
|
3823
|
-
return [3 /*break*/,
|
|
3824
|
-
case
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3641
|
+
return [3 /*break*/, 1];
|
|
3642
|
+
case 4: return [2 /*return*/];
|
|
3643
|
+
}
|
|
3644
|
+
});
|
|
3645
|
+
});
|
|
3646
|
+
}
|
|
3647
|
+
/**
|
|
3648
|
+
* TODO: Break into smaller functions
|
|
3649
|
+
*/
|
|
3650
|
+
|
|
3651
|
+
/**
|
|
3652
|
+
* @@@
|
|
3653
|
+
*
|
|
3654
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3655
|
+
*/
|
|
3656
|
+
function executeFormatCells(options) {
|
|
3657
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3658
|
+
var template;
|
|
3659
|
+
return __generator(this, function (_a) {
|
|
3660
|
+
template = options.template;
|
|
3661
|
+
if (template.foreach === undefined) {
|
|
3662
|
+
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
3663
|
+
}
|
|
3664
|
+
throw new NotYetImplementedError('FOREACH execution not implemented yet');
|
|
3665
|
+
});
|
|
3666
|
+
});
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3669
|
+
/**
|
|
3670
|
+
* Just marks a place of place where should be something implemented
|
|
3671
|
+
* No side effects.
|
|
3672
|
+
*
|
|
3673
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
3674
|
+
*
|
|
3675
|
+
* @param value any values
|
|
3676
|
+
* @returns void
|
|
3677
|
+
* @private within the repository
|
|
3678
|
+
*/
|
|
3679
|
+
function TODO_USE() {
|
|
3680
|
+
var value = [];
|
|
3681
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3682
|
+
value[_i] = arguments[_i];
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
|
|
3686
|
+
/**
|
|
3687
|
+
* @@@
|
|
3688
|
+
*
|
|
3689
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3690
|
+
*/
|
|
3691
|
+
function getContextForTemplate(template) {
|
|
3692
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3693
|
+
return __generator(this, function (_a) {
|
|
3694
|
+
TODO_USE(template);
|
|
3695
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [π] Implement */];
|
|
3696
|
+
});
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
|
|
3700
|
+
/**
|
|
3701
|
+
* @@@
|
|
3702
|
+
*
|
|
3703
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3704
|
+
*/
|
|
3705
|
+
function getKnowledgeForTemplate(options) {
|
|
3706
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3707
|
+
var preparedPipeline, template;
|
|
3708
|
+
return __generator(this, function (_a) {
|
|
3709
|
+
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3710
|
+
// TODO: [β¨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3711
|
+
TODO_USE(template);
|
|
3712
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3713
|
+
var content = _a.content;
|
|
3714
|
+
return "- ".concat(content);
|
|
3715
|
+
}).join('\n')];
|
|
3716
|
+
});
|
|
3717
|
+
});
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
/**
|
|
3721
|
+
* @@@
|
|
3722
|
+
*
|
|
3723
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3724
|
+
*/
|
|
3725
|
+
function getSamplesForTemplate(template) {
|
|
3726
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3727
|
+
return __generator(this, function (_a) {
|
|
3728
|
+
// TODO: [β¨] Implement Better - use real index and keyword search
|
|
3729
|
+
TODO_USE(template);
|
|
3730
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [β¨] Implement */];
|
|
3731
|
+
});
|
|
3732
|
+
});
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3735
|
+
/**
|
|
3736
|
+
* @@@
|
|
3737
|
+
*
|
|
3738
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3739
|
+
*/
|
|
3740
|
+
function getReservedParametersForTemplate(options) {
|
|
3741
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3742
|
+
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3743
|
+
var e_1, _a;
|
|
3744
|
+
return __generator(this, function (_b) {
|
|
3745
|
+
switch (_b.label) {
|
|
3746
|
+
case 0:
|
|
3747
|
+
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
3748
|
+
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3749
|
+
case 1:
|
|
3750
|
+
context = _b.sent();
|
|
3751
|
+
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3752
|
+
case 2:
|
|
3753
|
+
knowledge = _b.sent();
|
|
3754
|
+
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3755
|
+
case 3:
|
|
3756
|
+
samples = _b.sent();
|
|
3757
|
+
currentDate = new Date().toISOString();
|
|
3758
|
+
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3759
|
+
reservedParameters = {
|
|
3760
|
+
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3761
|
+
context: context,
|
|
3762
|
+
knowledge: knowledge,
|
|
3763
|
+
samples: samples,
|
|
3764
|
+
currentDate: currentDate,
|
|
3765
|
+
modelName: modelName,
|
|
3766
|
+
};
|
|
3767
|
+
_loop_1 = function (parameterName) {
|
|
3768
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
3769
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3770
|
+
}
|
|
3771
|
+
};
|
|
3772
|
+
try {
|
|
3773
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3774
|
+
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()) {
|
|
3775
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3776
|
+
_loop_1(parameterName);
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3780
|
+
finally {
|
|
3781
|
+
try {
|
|
3782
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3783
|
+
}
|
|
3784
|
+
finally { if (e_1) throw e_1.error; }
|
|
3785
|
+
}
|
|
3786
|
+
return [2 /*return*/, reservedParameters];
|
|
3787
|
+
}
|
|
3788
|
+
});
|
|
3789
|
+
});
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
/**
|
|
3793
|
+
* @@@
|
|
3794
|
+
*
|
|
3795
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3796
|
+
*/
|
|
3797
|
+
function executeTemplate(options) {
|
|
3798
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3799
|
+
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;
|
|
3800
|
+
var e_1, _f, _g;
|
|
3801
|
+
return __generator(this, function (_h) {
|
|
3802
|
+
switch (_h.label) {
|
|
3803
|
+
case 0:
|
|
3804
|
+
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;
|
|
3805
|
+
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3806
|
+
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3807
|
+
title = currentTemplate.title;
|
|
3808
|
+
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3809
|
+
return [4 /*yield*/, onProgress({
|
|
3810
|
+
name: name,
|
|
3811
|
+
title: title,
|
|
3812
|
+
isStarted: false,
|
|
3813
|
+
isDone: false,
|
|
3814
|
+
templateType: currentTemplate.templateType,
|
|
3815
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
3816
|
+
parameterValue: null,
|
|
3817
|
+
// <- [πΈ]
|
|
3818
|
+
})];
|
|
3819
|
+
case 1:
|
|
3820
|
+
_h.sent();
|
|
3821
|
+
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3822
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3823
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3824
|
+
throw new UnexpectedError(spaceTrim$1(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)
|
|
3825
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3826
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3827
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3828
|
+
.join(', '), "\n\n "); }));
|
|
3829
|
+
}
|
|
3830
|
+
_b = (_a = Object).freeze;
|
|
3831
|
+
_c = [{}];
|
|
3832
|
+
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3833
|
+
preparedPipeline: preparedPipeline,
|
|
3834
|
+
template: currentTemplate,
|
|
3835
|
+
pipelineIdentification: pipelineIdentification,
|
|
3836
|
+
})];
|
|
3837
|
+
case 2:
|
|
3838
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3839
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3840
|
+
parameters = {};
|
|
3841
|
+
_loop_1 = function (parameterName) {
|
|
3842
|
+
// Situation: Parameter is defined and used
|
|
3843
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3844
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
3845
|
+
}
|
|
3846
|
+
// Situation: Parameter is defined but NOT used
|
|
3847
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3848
|
+
// Situation: Parameter is NOT defined BUT used
|
|
3849
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3850
|
+
// Houston, we have a problem
|
|
3851
|
+
// Note: Checking part is also done in `validatePipeline`, but itβs good to doublecheck
|
|
3852
|
+
throw new UnexpectedError(spaceTrim$1(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 "); }));
|
|
3853
|
+
}
|
|
3854
|
+
};
|
|
3855
|
+
try {
|
|
3856
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3857
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3858
|
+
parameterName = _e.value;
|
|
3859
|
+
_loop_1(parameterName);
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3863
|
+
finally {
|
|
3864
|
+
try {
|
|
3865
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3866
|
+
}
|
|
3867
|
+
finally { if (e_1) throw e_1.error; }
|
|
3868
|
+
}
|
|
3869
|
+
// 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
|
|
3870
|
+
Object.freeze(parameters);
|
|
3871
|
+
$ongoingTemplateResult = {
|
|
3872
|
+
$result: null,
|
|
3873
|
+
$resultString: null,
|
|
3874
|
+
$expectError: null,
|
|
3875
|
+
$scriptPipelineExecutionErrors: [],
|
|
3876
|
+
};
|
|
3877
|
+
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3878
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3879
|
+
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3880
|
+
.split('{content}')
|
|
3881
|
+
.join(currentTemplate.content);
|
|
3882
|
+
// <- TODO: [π΅] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
|
|
3883
|
+
return [4 /*yield*/, executeFormatCells({
|
|
3884
|
+
$ongoingTemplateResult: $ongoingTemplateResult,
|
|
3885
|
+
jokerParameterNames: jokerParameterNames,
|
|
3886
|
+
priority: priority,
|
|
3887
|
+
maxAttempts: maxAttempts,
|
|
3888
|
+
preparedContent: preparedContent,
|
|
3889
|
+
parameters: parameters,
|
|
3890
|
+
template: currentTemplate,
|
|
3891
|
+
preparedPipeline: preparedPipeline,
|
|
3892
|
+
tools: tools,
|
|
3893
|
+
llmTools: llmTools,
|
|
3894
|
+
settings: settings,
|
|
3895
|
+
$executionReport: $executionReport,
|
|
3896
|
+
pipelineIdentification: pipelineIdentification,
|
|
3897
|
+
})];
|
|
3898
|
+
case 3:
|
|
3899
|
+
// <- TODO: [π΅] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
|
|
3900
|
+
_h.sent();
|
|
3901
|
+
if ($ongoingTemplateResult.$resultString === null) {
|
|
3839
3902
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3840
3903
|
}
|
|
3841
3904
|
return [4 /*yield*/, onProgress({
|
|
@@ -3845,13 +3908,13 @@ function executeTemplate(options) {
|
|
|
3845
3908
|
isDone: true,
|
|
3846
3909
|
templateType: currentTemplate.templateType,
|
|
3847
3910
|
parameterName: currentTemplate.resultingParameterName,
|
|
3848
|
-
parameterValue: resultString,
|
|
3911
|
+
parameterValue: $ongoingTemplateResult.$resultString,
|
|
3849
3912
|
// <- [πΈ]
|
|
3850
3913
|
})];
|
|
3851
|
-
case
|
|
3914
|
+
case 4:
|
|
3852
3915
|
_h.sent();
|
|
3853
3916
|
return [2 /*return*/, Object.freeze((_g = {},
|
|
3854
|
-
_g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3917
|
+
_g[currentTemplate.resultingParameterName] = $ongoingTemplateResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3855
3918
|
_g))];
|
|
3856
3919
|
}
|
|
3857
3920
|
});
|
|
@@ -4127,6 +4190,8 @@ function executePipeline(options) {
|
|
|
4127
4190
|
.then(function () {
|
|
4128
4191
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
4129
4192
|
});
|
|
4193
|
+
// <- Note: Errors are catched here [3]
|
|
4194
|
+
// 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
|
|
4130
4195
|
resolving_1.push(work_1);
|
|
4131
4196
|
_j.label = 4;
|
|
4132
4197
|
case 4: return [2 /*return*/];
|