@promptbook/node 0.69.0-2 → 0.69.0-5
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 +1033 -947
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.d.ts +2 -1
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +5 -3
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +20 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +30 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +10 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +55 -0
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +62 -0
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatCell.d.ts +30 -0
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempt.d.ts +30 -0
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +34 -0
- package/esm/typings/src/execution/createPipelineExecutor/getContextForTemplate.d.ts +10 -0
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTemplate.d.ts +27 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTemplate.d.ts +30 -0
- package/esm/typings/src/execution/createPipelineExecutor/getSamplesForTemplate.d.ts +10 -0
- package/package.json +2 -2
- package/umd/index.umd.js +1033 -947
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +0 -72
package/esm/index.es.js
CHANGED
|
@@ -14,7 +14,7 @@ import * as dotenv from 'dotenv';
|
|
|
14
14
|
/**
|
|
15
15
|
* The version of the Promptbook library
|
|
16
16
|
*/
|
|
17
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
17
|
+
var PROMPTBOOK_VERSION = '0.69.0-4';
|
|
18
18
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
19
19
|
|
|
20
20
|
/*! *****************************************************************************
|
|
@@ -404,6 +404,7 @@ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMET
|
|
|
404
404
|
'samples',
|
|
405
405
|
'modelName',
|
|
406
406
|
'currentDate',
|
|
407
|
+
// <- TODO: !!!!! list here all command names
|
|
407
408
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
408
409
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
409
410
|
]);
|
|
@@ -883,7 +884,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
883
884
|
});
|
|
884
885
|
}
|
|
885
886
|
|
|
886
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
887
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-4",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-4",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-4",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-4",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"}];
|
|
887
888
|
|
|
888
889
|
/**
|
|
889
890
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1134,12 +1135,12 @@ function validatePipelineCore(pipeline) {
|
|
|
1134
1135
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1135
1136
|
if (!Array.isArray(pipeline.parameters)) {
|
|
1136
1137
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1137
|
-
throw new ParseError(spaceTrim(function (block) { return "\n
|
|
1138
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1138
1139
|
}
|
|
1139
1140
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1140
1141
|
if (!Array.isArray(pipeline.templates)) {
|
|
1141
1142
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1142
|
-
throw new ParseError(spaceTrim(function (block) { return "\n
|
|
1143
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.templates` expected to be an array, but got ".concat(typeof pipeline.templates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1143
1144
|
}
|
|
1144
1145
|
var _loop_1 = function (parameter) {
|
|
1145
1146
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -2047,160 +2048,36 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2047
2048
|
*/
|
|
2048
2049
|
|
|
2049
2050
|
/**
|
|
2050
|
-
*
|
|
2051
|
-
*
|
|
2052
|
-
* @param script from which to extract the variables
|
|
2053
|
-
* @returns the list of variable names
|
|
2054
|
-
* @throws {ParseError} if the script is invalid
|
|
2055
|
-
* @public exported from `@promptbook/utils`
|
|
2056
|
-
*/
|
|
2057
|
-
function extractVariables(script) {
|
|
2058
|
-
var variables = new Set();
|
|
2059
|
-
script = "(()=>{".concat(script, "})()");
|
|
2060
|
-
try {
|
|
2061
|
-
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2062
|
-
try {
|
|
2063
|
-
eval(script);
|
|
2064
|
-
}
|
|
2065
|
-
catch (error) {
|
|
2066
|
-
if (!(error instanceof ReferenceError)) {
|
|
2067
|
-
throw error;
|
|
2068
|
-
}
|
|
2069
|
-
var undefinedName = error.message.split(' ')[0];
|
|
2070
|
-
/*
|
|
2071
|
-
Note: Parsing the error
|
|
2072
|
-
[PipelineUrlError: thing is not defined]
|
|
2073
|
-
*/
|
|
2074
|
-
if (!undefinedName) {
|
|
2075
|
-
throw error;
|
|
2076
|
-
}
|
|
2077
|
-
if (script.includes(undefinedName + '(')) {
|
|
2078
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2079
|
-
}
|
|
2080
|
-
else {
|
|
2081
|
-
variables.add(undefinedName);
|
|
2082
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
catch (error) {
|
|
2087
|
-
if (!(error instanceof Error)) {
|
|
2088
|
-
throw error;
|
|
2089
|
-
}
|
|
2090
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
2091
|
-
}
|
|
2092
|
-
return variables;
|
|
2093
|
-
}
|
|
2094
|
-
/**
|
|
2095
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
2096
|
-
*/
|
|
2097
|
-
|
|
2098
|
-
/**
|
|
2099
|
-
* Parses the template and returns the set of all used parameters
|
|
2051
|
+
* Determine if the pipeline is fully prepared
|
|
2100
2052
|
*
|
|
2101
|
-
* @
|
|
2102
|
-
* @returns the set of parameter names
|
|
2103
|
-
* @throws {ParseError} if the script is invalid
|
|
2104
|
-
* @public exported from `@promptbook/utils`
|
|
2053
|
+
* @public exported from `@promptbook/core`
|
|
2105
2054
|
*/
|
|
2106
|
-
function
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2112
|
-
var parameterName = _e.value;
|
|
2113
|
-
parameterNames.add(parameterName);
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2117
|
-
finally {
|
|
2118
|
-
try {
|
|
2119
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2120
|
-
}
|
|
2121
|
-
finally { if (e_1) throw e_1.error; }
|
|
2122
|
-
}
|
|
2123
|
-
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
2124
|
-
try {
|
|
2125
|
-
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2126
|
-
var parameterName = _g.value;
|
|
2127
|
-
parameterNames.add(parameterName);
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2131
|
-
finally {
|
|
2132
|
-
try {
|
|
2133
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2134
|
-
}
|
|
2135
|
-
finally { if (e_2) throw e_2.error; }
|
|
2136
|
-
}
|
|
2137
|
-
}
|
|
2138
|
-
try {
|
|
2139
|
-
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
2140
|
-
var jokerName = _j.value;
|
|
2141
|
-
parameterNames.add(jokerName);
|
|
2142
|
-
}
|
|
2143
|
-
}
|
|
2144
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2145
|
-
finally {
|
|
2146
|
-
try {
|
|
2147
|
-
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
2148
|
-
}
|
|
2149
|
-
finally { if (e_3) throw e_3.error; }
|
|
2150
|
-
}
|
|
2151
|
-
parameterNames.delete('content');
|
|
2152
|
-
// <- Note {websiteContent} is used in `preparedContent`
|
|
2153
|
-
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2154
|
-
if (foreach !== undefined) {
|
|
2155
|
-
if (parameterNames.has(foreach.subparameterName)) {
|
|
2156
|
-
parameterNames.delete(foreach.subparameterName);
|
|
2157
|
-
parameterNames.add(foreach.parameterName);
|
|
2158
|
-
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
2159
|
-
}
|
|
2055
|
+
function isPipelinePrepared(pipeline) {
|
|
2056
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2057
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2058
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2059
|
+
return false;
|
|
2160
2060
|
}
|
|
2161
|
-
return
|
|
2162
|
-
|
|
2163
|
-
/**
|
|
2164
|
-
* TODO: [🔣] If script require contentLanguage
|
|
2165
|
-
*/
|
|
2166
|
-
|
|
2167
|
-
/**
|
|
2168
|
-
* Serializes an error into a [🚉] JSON-serializable object
|
|
2169
|
-
*
|
|
2170
|
-
* @public exported from `@promptbook/utils`
|
|
2171
|
-
*/
|
|
2172
|
-
function serializeError(error) {
|
|
2173
|
-
var name = error.name, message = error.message, stack = error.stack;
|
|
2174
|
-
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2175
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2061
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2062
|
+
return false;
|
|
2176
2063
|
}
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
}
|
|
2064
|
+
/*
|
|
2065
|
+
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2066
|
+
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2067
|
+
> return false;
|
|
2068
|
+
> }
|
|
2069
|
+
*/
|
|
2070
|
+
return true;
|
|
2182
2071
|
}
|
|
2183
|
-
|
|
2184
2072
|
/**
|
|
2185
|
-
*
|
|
2186
|
-
*
|
|
2187
|
-
*
|
|
2073
|
+
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2074
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2075
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2076
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2077
|
+
* - [🏍] ? Is context in each template
|
|
2078
|
+
* - [♨] Are samples prepared
|
|
2079
|
+
* - [♨] Are templates prepared
|
|
2188
2080
|
*/
|
|
2189
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
2190
|
-
try {
|
|
2191
|
-
JSON.parse(value);
|
|
2192
|
-
return true;
|
|
2193
|
-
}
|
|
2194
|
-
catch (error) {
|
|
2195
|
-
if (!(error instanceof Error)) {
|
|
2196
|
-
throw error;
|
|
2197
|
-
}
|
|
2198
|
-
if (error.message.includes('Unexpected token')) {
|
|
2199
|
-
return false;
|
|
2200
|
-
}
|
|
2201
|
-
return false;
|
|
2202
|
-
}
|
|
2203
|
-
}
|
|
2204
2081
|
|
|
2205
2082
|
/**
|
|
2206
2083
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
@@ -2496,87 +2373,262 @@ function joinLlmExecutionTools() {
|
|
|
2496
2373
|
*/
|
|
2497
2374
|
|
|
2498
2375
|
/**
|
|
2499
|
-
*
|
|
2500
|
-
*
|
|
2501
|
-
* Note: There are multiple simmilar function:
|
|
2502
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2503
|
-
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2504
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2505
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2376
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2506
2377
|
*
|
|
2507
|
-
* @
|
|
2508
|
-
* @returns code blocks with language and content
|
|
2509
|
-
* @throws {ParseError} if block is not closed properly
|
|
2510
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
2378
|
+
* @public exported from `@promptbook/utils`
|
|
2511
2379
|
*/
|
|
2512
|
-
function
|
|
2513
|
-
var
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
2517
|
-
lines.push('');
|
|
2518
|
-
var currentCodeBlock = null;
|
|
2519
|
-
try {
|
|
2520
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2521
|
-
var line = lines_1_1.value;
|
|
2522
|
-
if (line.startsWith('> ') || line === '>') {
|
|
2523
|
-
if (currentCodeBlock === null) {
|
|
2524
|
-
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2525
|
-
} /* not else */
|
|
2526
|
-
if (currentCodeBlock.blockNotation === '>') {
|
|
2527
|
-
if (currentCodeBlock.content !== '') {
|
|
2528
|
-
currentCodeBlock.content += '\n';
|
|
2529
|
-
}
|
|
2530
|
-
currentCodeBlock.content += line.slice(2);
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2534
|
-
codeBlocks.push(currentCodeBlock);
|
|
2535
|
-
currentCodeBlock = null;
|
|
2536
|
-
}
|
|
2537
|
-
/* not else */
|
|
2538
|
-
if (line.startsWith('```')) {
|
|
2539
|
-
var language = line.slice(3).trim() || null;
|
|
2540
|
-
if (currentCodeBlock === null) {
|
|
2541
|
-
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2542
|
-
}
|
|
2543
|
-
else {
|
|
2544
|
-
if (language !== null) {
|
|
2545
|
-
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2546
|
-
}
|
|
2547
|
-
codeBlocks.push(currentCodeBlock);
|
|
2548
|
-
currentCodeBlock = null;
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2552
|
-
if (currentCodeBlock.content !== '') {
|
|
2553
|
-
currentCodeBlock.content += '\n';
|
|
2554
|
-
}
|
|
2555
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2560
|
-
finally {
|
|
2561
|
-
try {
|
|
2562
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2563
|
-
}
|
|
2564
|
-
finally { if (e_1) throw e_1.error; }
|
|
2565
|
-
}
|
|
2566
|
-
if (currentCodeBlock !== null) {
|
|
2567
|
-
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2380
|
+
function serializeError(error) {
|
|
2381
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2382
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2383
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2568
2384
|
}
|
|
2569
|
-
return
|
|
2385
|
+
return {
|
|
2386
|
+
name: name,
|
|
2387
|
+
message: message,
|
|
2388
|
+
stack: stack,
|
|
2389
|
+
};
|
|
2570
2390
|
}
|
|
2571
|
-
/**
|
|
2572
|
-
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
2573
|
-
*/
|
|
2574
2391
|
|
|
2575
2392
|
/**
|
|
2576
|
-
*
|
|
2393
|
+
* Takes an item or an array of items and returns an array of items
|
|
2577
2394
|
*
|
|
2578
|
-
*
|
|
2579
|
-
*
|
|
2395
|
+
* 1) Any item except array and undefined returns array with that one item (also null)
|
|
2396
|
+
* 2) Undefined returns empty array
|
|
2397
|
+
* 3) Array returns itself
|
|
2398
|
+
*
|
|
2399
|
+
* @private internal utility
|
|
2400
|
+
*/
|
|
2401
|
+
function arrayableToArray(input) {
|
|
2402
|
+
if (input === undefined) {
|
|
2403
|
+
return [];
|
|
2404
|
+
}
|
|
2405
|
+
if (input instanceof Array) {
|
|
2406
|
+
return input;
|
|
2407
|
+
}
|
|
2408
|
+
return [input];
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
/**
|
|
2412
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
2413
|
+
*
|
|
2414
|
+
* @param script from which to extract the variables
|
|
2415
|
+
* @returns the list of variable names
|
|
2416
|
+
* @throws {ParseError} if the script is invalid
|
|
2417
|
+
* @public exported from `@promptbook/utils`
|
|
2418
|
+
*/
|
|
2419
|
+
function extractVariables(script) {
|
|
2420
|
+
var variables = new Set();
|
|
2421
|
+
script = "(()=>{".concat(script, "})()");
|
|
2422
|
+
try {
|
|
2423
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2424
|
+
try {
|
|
2425
|
+
eval(script);
|
|
2426
|
+
}
|
|
2427
|
+
catch (error) {
|
|
2428
|
+
if (!(error instanceof ReferenceError)) {
|
|
2429
|
+
throw error;
|
|
2430
|
+
}
|
|
2431
|
+
var undefinedName = error.message.split(' ')[0];
|
|
2432
|
+
/*
|
|
2433
|
+
Note: Parsing the error
|
|
2434
|
+
[PipelineUrlError: thing is not defined]
|
|
2435
|
+
*/
|
|
2436
|
+
if (!undefinedName) {
|
|
2437
|
+
throw error;
|
|
2438
|
+
}
|
|
2439
|
+
if (script.includes(undefinedName + '(')) {
|
|
2440
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2441
|
+
}
|
|
2442
|
+
else {
|
|
2443
|
+
variables.add(undefinedName);
|
|
2444
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
catch (error) {
|
|
2449
|
+
if (!(error instanceof Error)) {
|
|
2450
|
+
throw error;
|
|
2451
|
+
}
|
|
2452
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
2453
|
+
}
|
|
2454
|
+
return variables;
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
2458
|
+
*/
|
|
2459
|
+
|
|
2460
|
+
/**
|
|
2461
|
+
* Parses the template and returns the set of all used parameters
|
|
2462
|
+
*
|
|
2463
|
+
* @param template the template with used parameters
|
|
2464
|
+
* @returns the set of parameter names
|
|
2465
|
+
* @throws {ParseError} if the script is invalid
|
|
2466
|
+
* @public exported from `@promptbook/utils`
|
|
2467
|
+
*/
|
|
2468
|
+
function extractParameterNamesFromTemplate(template) {
|
|
2469
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
2470
|
+
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
|
|
2471
|
+
var parameterNames = new Set();
|
|
2472
|
+
try {
|
|
2473
|
+
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2474
|
+
var parameterName = _e.value;
|
|
2475
|
+
parameterNames.add(parameterName);
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2479
|
+
finally {
|
|
2480
|
+
try {
|
|
2481
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2482
|
+
}
|
|
2483
|
+
finally { if (e_1) throw e_1.error; }
|
|
2484
|
+
}
|
|
2485
|
+
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
2486
|
+
try {
|
|
2487
|
+
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2488
|
+
var parameterName = _g.value;
|
|
2489
|
+
parameterNames.add(parameterName);
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2493
|
+
finally {
|
|
2494
|
+
try {
|
|
2495
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2496
|
+
}
|
|
2497
|
+
finally { if (e_2) throw e_2.error; }
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
try {
|
|
2501
|
+
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
2502
|
+
var jokerName = _j.value;
|
|
2503
|
+
parameterNames.add(jokerName);
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2507
|
+
finally {
|
|
2508
|
+
try {
|
|
2509
|
+
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
2510
|
+
}
|
|
2511
|
+
finally { if (e_3) throw e_3.error; }
|
|
2512
|
+
}
|
|
2513
|
+
parameterNames.delete('content');
|
|
2514
|
+
// <- Note {websiteContent} is used in `preparedContent`
|
|
2515
|
+
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2516
|
+
if (foreach !== undefined) {
|
|
2517
|
+
if (parameterNames.has(foreach.subparameterName)) {
|
|
2518
|
+
parameterNames.delete(foreach.subparameterName);
|
|
2519
|
+
parameterNames.add(foreach.parameterName);
|
|
2520
|
+
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
return parameterNames;
|
|
2524
|
+
}
|
|
2525
|
+
/**
|
|
2526
|
+
* TODO: [🔣] If script require contentLanguage
|
|
2527
|
+
*/
|
|
2528
|
+
|
|
2529
|
+
/**
|
|
2530
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2531
|
+
*
|
|
2532
|
+
* @public exported from `@promptbook/utils`
|
|
2533
|
+
*/
|
|
2534
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
2535
|
+
try {
|
|
2536
|
+
JSON.parse(value);
|
|
2537
|
+
return true;
|
|
2538
|
+
}
|
|
2539
|
+
catch (error) {
|
|
2540
|
+
if (!(error instanceof Error)) {
|
|
2541
|
+
throw error;
|
|
2542
|
+
}
|
|
2543
|
+
if (error.message.includes('Unexpected token')) {
|
|
2544
|
+
return false;
|
|
2545
|
+
}
|
|
2546
|
+
return false;
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
/**
|
|
2551
|
+
* Extracts all code blocks from markdown.
|
|
2552
|
+
*
|
|
2553
|
+
* Note: There are multiple simmilar function:
|
|
2554
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2555
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2556
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2557
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2558
|
+
*
|
|
2559
|
+
* @param markdown any valid markdown
|
|
2560
|
+
* @returns code blocks with language and content
|
|
2561
|
+
* @throws {ParseError} if block is not closed properly
|
|
2562
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2563
|
+
*/
|
|
2564
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
2565
|
+
var e_1, _a;
|
|
2566
|
+
var codeBlocks = [];
|
|
2567
|
+
var lines = markdown.split('\n');
|
|
2568
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
2569
|
+
lines.push('');
|
|
2570
|
+
var currentCodeBlock = null;
|
|
2571
|
+
try {
|
|
2572
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2573
|
+
var line = lines_1_1.value;
|
|
2574
|
+
if (line.startsWith('> ') || line === '>') {
|
|
2575
|
+
if (currentCodeBlock === null) {
|
|
2576
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2577
|
+
} /* not else */
|
|
2578
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
2579
|
+
if (currentCodeBlock.content !== '') {
|
|
2580
|
+
currentCodeBlock.content += '\n';
|
|
2581
|
+
}
|
|
2582
|
+
currentCodeBlock.content += line.slice(2);
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2586
|
+
codeBlocks.push(currentCodeBlock);
|
|
2587
|
+
currentCodeBlock = null;
|
|
2588
|
+
}
|
|
2589
|
+
/* not else */
|
|
2590
|
+
if (line.startsWith('```')) {
|
|
2591
|
+
var language = line.slice(3).trim() || null;
|
|
2592
|
+
if (currentCodeBlock === null) {
|
|
2593
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2594
|
+
}
|
|
2595
|
+
else {
|
|
2596
|
+
if (language !== null) {
|
|
2597
|
+
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2598
|
+
}
|
|
2599
|
+
codeBlocks.push(currentCodeBlock);
|
|
2600
|
+
currentCodeBlock = null;
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2604
|
+
if (currentCodeBlock.content !== '') {
|
|
2605
|
+
currentCodeBlock.content += '\n';
|
|
2606
|
+
}
|
|
2607
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2612
|
+
finally {
|
|
2613
|
+
try {
|
|
2614
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2615
|
+
}
|
|
2616
|
+
finally { if (e_1) throw e_1.error; }
|
|
2617
|
+
}
|
|
2618
|
+
if (currentCodeBlock !== null) {
|
|
2619
|
+
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2620
|
+
}
|
|
2621
|
+
return codeBlocks;
|
|
2622
|
+
}
|
|
2623
|
+
/**
|
|
2624
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
2625
|
+
*/
|
|
2626
|
+
|
|
2627
|
+
/**
|
|
2628
|
+
* Extracts extracts exactly one valid JSON code block
|
|
2629
|
+
*
|
|
2630
|
+
* - When given string is a valid JSON as it is, it just returns it
|
|
2631
|
+
* - When there is no JSON code block the function throws a `ParseError`
|
|
2580
2632
|
* - When there are multiple JSON code blocks the function throws a `ParseError`
|
|
2581
2633
|
*
|
|
2582
2634
|
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
@@ -2611,57 +2663,6 @@ function extractJsonBlock(markdown) {
|
|
|
2611
2663
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2612
2664
|
*/
|
|
2613
2665
|
|
|
2614
|
-
/**
|
|
2615
|
-
* Determine if the pipeline is fully prepared
|
|
2616
|
-
*
|
|
2617
|
-
* @public exported from `@promptbook/core`
|
|
2618
|
-
*/
|
|
2619
|
-
function isPipelinePrepared(pipeline) {
|
|
2620
|
-
// Note: Ignoring `pipeline.preparations` @@@
|
|
2621
|
-
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2622
|
-
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2623
|
-
return false;
|
|
2624
|
-
}
|
|
2625
|
-
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2626
|
-
return false;
|
|
2627
|
-
}
|
|
2628
|
-
/*
|
|
2629
|
-
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2630
|
-
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2631
|
-
> return false;
|
|
2632
|
-
> }
|
|
2633
|
-
*/
|
|
2634
|
-
return true;
|
|
2635
|
-
}
|
|
2636
|
-
/**
|
|
2637
|
-
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2638
|
-
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2639
|
-
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2640
|
-
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2641
|
-
* - [🏍] ? Is context in each template
|
|
2642
|
-
* - [♨] Are samples prepared
|
|
2643
|
-
* - [♨] Are templates prepared
|
|
2644
|
-
*/
|
|
2645
|
-
|
|
2646
|
-
/**
|
|
2647
|
-
* Takes an item or an array of items and returns an array of items
|
|
2648
|
-
*
|
|
2649
|
-
* 1) Any item except array and undefined returns array with that one item (also null)
|
|
2650
|
-
* 2) Undefined returns empty array
|
|
2651
|
-
* 3) Array returns itself
|
|
2652
|
-
*
|
|
2653
|
-
* @private internal utility
|
|
2654
|
-
*/
|
|
2655
|
-
function arrayableToArray(input) {
|
|
2656
|
-
if (input === undefined) {
|
|
2657
|
-
return [];
|
|
2658
|
-
}
|
|
2659
|
-
if (input instanceof Array) {
|
|
2660
|
-
return input;
|
|
2661
|
-
}
|
|
2662
|
-
return [input];
|
|
2663
|
-
}
|
|
2664
|
-
|
|
2665
2666
|
/**
|
|
2666
2667
|
* Just says that the variable is not used but should be kept
|
|
2667
2668
|
* No side effects.
|
|
@@ -2683,23 +2684,6 @@ function keepUnused() {
|
|
|
2683
2684
|
}
|
|
2684
2685
|
}
|
|
2685
2686
|
|
|
2686
|
-
/**
|
|
2687
|
-
* Just marks a place of place where should be something implemented
|
|
2688
|
-
* No side effects.
|
|
2689
|
-
*
|
|
2690
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2691
|
-
*
|
|
2692
|
-
* @param value any values
|
|
2693
|
-
* @returns void
|
|
2694
|
-
* @private within the repository
|
|
2695
|
-
*/
|
|
2696
|
-
function TODO_USE() {
|
|
2697
|
-
var value = [];
|
|
2698
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2699
|
-
value[_i] = arguments[_i];
|
|
2700
|
-
}
|
|
2701
|
-
}
|
|
2702
|
-
|
|
2703
2687
|
/**
|
|
2704
2688
|
* Replaces parameters in template with values from parameters object
|
|
2705
2689
|
*
|
|
@@ -2929,44 +2913,659 @@ function countWords(text) {
|
|
|
2929
2913
|
text = removeDiacritics(text);
|
|
2930
2914
|
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
2931
2915
|
}
|
|
2932
|
-
|
|
2916
|
+
|
|
2917
|
+
/**
|
|
2918
|
+
* Index of all counter functions
|
|
2919
|
+
*
|
|
2920
|
+
* @public exported from `@promptbook/utils`
|
|
2921
|
+
*/
|
|
2922
|
+
var CountUtils = {
|
|
2923
|
+
CHARACTERS: countCharacters,
|
|
2924
|
+
WORDS: countWords,
|
|
2925
|
+
SENTENCES: countSentences,
|
|
2926
|
+
PARAGRAPHS: countParagraphs,
|
|
2927
|
+
LINES: countLines,
|
|
2928
|
+
PAGES: countPages,
|
|
2929
|
+
};
|
|
2930
|
+
|
|
2931
|
+
/**
|
|
2932
|
+
* Function checkExpectations will check if the expectations on given value are met
|
|
2933
|
+
*
|
|
2934
|
+
* Note: There are two simmilar functions:
|
|
2935
|
+
* - `checkExpectations` which throws an error if the expectations are not met
|
|
2936
|
+
* - `isPassingExpectations` which returns a boolean
|
|
2937
|
+
*
|
|
2938
|
+
* @throws {ExpectError} if the expectations are not met
|
|
2939
|
+
* @returns {void} Nothing
|
|
2940
|
+
* @private internal function of `createPipelineExecutor`
|
|
2941
|
+
*/
|
|
2942
|
+
function checkExpectations(expectations, value) {
|
|
2943
|
+
var e_1, _a;
|
|
2944
|
+
try {
|
|
2945
|
+
for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2946
|
+
var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
|
|
2947
|
+
var amount = CountUtils[unit.toUpperCase()](value);
|
|
2948
|
+
if (min && amount < min) {
|
|
2949
|
+
throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
|
|
2950
|
+
} /* not else */
|
|
2951
|
+
if (max && amount > max) {
|
|
2952
|
+
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2957
|
+
finally {
|
|
2958
|
+
try {
|
|
2959
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2960
|
+
}
|
|
2961
|
+
finally { if (e_1) throw e_1.error; }
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
/**
|
|
2965
|
+
* TODO: [💝] Unite object for expecting amount and format
|
|
2966
|
+
*/
|
|
2967
|
+
|
|
2968
|
+
/**
|
|
2969
|
+
* Just marks a place of place where should be something implemented
|
|
2970
|
+
* No side effects.
|
|
2971
|
+
*
|
|
2972
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2973
|
+
*
|
|
2974
|
+
* @param value any values
|
|
2975
|
+
* @returns void
|
|
2976
|
+
* @private within the repository
|
|
2977
|
+
*/
|
|
2978
|
+
function TODO_USE() {
|
|
2979
|
+
var value = [];
|
|
2980
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2981
|
+
value[_i] = arguments[_i];
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
/**
|
|
2986
|
+
* @@@
|
|
2987
|
+
*
|
|
2988
|
+
* @private internal utility of `createPipelineExecutor`
|
|
2989
|
+
*/
|
|
2990
|
+
function getContextForTemplate(template) {
|
|
2991
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2992
|
+
return __generator(this, function (_a) {
|
|
2993
|
+
TODO_USE(template);
|
|
2994
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
2995
|
+
});
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
/**
|
|
3000
|
+
* @@@
|
|
3001
|
+
*
|
|
3002
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3003
|
+
*/
|
|
3004
|
+
function getKnowledgeForTemplate(options) {
|
|
3005
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3006
|
+
var preparedPipeline, template;
|
|
3007
|
+
return __generator(this, function (_a) {
|
|
3008
|
+
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3009
|
+
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3010
|
+
TODO_USE(template);
|
|
3011
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3012
|
+
var content = _a.content;
|
|
3013
|
+
return "- ".concat(content);
|
|
3014
|
+
}).join('\n')];
|
|
3015
|
+
});
|
|
3016
|
+
});
|
|
3017
|
+
}
|
|
3018
|
+
|
|
3019
|
+
/**
|
|
3020
|
+
* @@@
|
|
3021
|
+
*
|
|
3022
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3023
|
+
*/
|
|
3024
|
+
function getSamplesForTemplate(template) {
|
|
3025
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3026
|
+
return __generator(this, function (_a) {
|
|
3027
|
+
// TODO: [♨] Implement Better - use real index and keyword search
|
|
3028
|
+
TODO_USE(template);
|
|
3029
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
3030
|
+
});
|
|
3031
|
+
});
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
/**
|
|
3035
|
+
* @@@
|
|
3036
|
+
*
|
|
3037
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3038
|
+
*/
|
|
3039
|
+
function getReservedParametersForTemplate(options) {
|
|
3040
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3041
|
+
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3042
|
+
var e_1, _a;
|
|
3043
|
+
return __generator(this, function (_b) {
|
|
3044
|
+
switch (_b.label) {
|
|
3045
|
+
case 0:
|
|
3046
|
+
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
3047
|
+
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3048
|
+
case 1:
|
|
3049
|
+
context = _b.sent();
|
|
3050
|
+
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3051
|
+
case 2:
|
|
3052
|
+
knowledge = _b.sent();
|
|
3053
|
+
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3054
|
+
case 3:
|
|
3055
|
+
samples = _b.sent();
|
|
3056
|
+
currentDate = new Date().toISOString();
|
|
3057
|
+
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3058
|
+
reservedParameters = {
|
|
3059
|
+
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3060
|
+
context: context,
|
|
3061
|
+
knowledge: knowledge,
|
|
3062
|
+
samples: samples,
|
|
3063
|
+
currentDate: currentDate,
|
|
3064
|
+
modelName: modelName,
|
|
3065
|
+
};
|
|
3066
|
+
_loop_1 = function (parameterName) {
|
|
3067
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
3068
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3069
|
+
}
|
|
3070
|
+
};
|
|
3071
|
+
try {
|
|
3072
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3073
|
+
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()) {
|
|
3074
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3075
|
+
_loop_1(parameterName);
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3079
|
+
finally {
|
|
3080
|
+
try {
|
|
3081
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3082
|
+
}
|
|
3083
|
+
finally { if (e_1) throw e_1.error; }
|
|
3084
|
+
}
|
|
3085
|
+
return [2 /*return*/, reservedParameters];
|
|
3086
|
+
}
|
|
3087
|
+
});
|
|
3088
|
+
});
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
/**
|
|
3092
|
+
* @@@
|
|
3093
|
+
*
|
|
3094
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3095
|
+
*/
|
|
3096
|
+
function executeTemplate(options) {
|
|
3097
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3098
|
+
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;
|
|
3099
|
+
var e_1, _f, _g;
|
|
3100
|
+
return __generator(this, function (_h) {
|
|
3101
|
+
switch (_h.label) {
|
|
3102
|
+
case 0:
|
|
3103
|
+
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;
|
|
3104
|
+
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3105
|
+
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3106
|
+
title = currentTemplate.title;
|
|
3107
|
+
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3108
|
+
return [4 /*yield*/, onProgress({
|
|
3109
|
+
name: name,
|
|
3110
|
+
title: title,
|
|
3111
|
+
isStarted: false,
|
|
3112
|
+
isDone: false,
|
|
3113
|
+
templateType: currentTemplate.templateType,
|
|
3114
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
3115
|
+
parameterValue: null,
|
|
3116
|
+
// <- [🍸]
|
|
3117
|
+
})];
|
|
3118
|
+
case 1:
|
|
3119
|
+
_h.sent();
|
|
3120
|
+
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3121
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3122
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3123
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
|
|
3124
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3125
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3126
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3127
|
+
.join(', '), "\n\n "); }));
|
|
3128
|
+
}
|
|
3129
|
+
_b = (_a = Object).freeze;
|
|
3130
|
+
_c = [{}];
|
|
3131
|
+
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3132
|
+
preparedPipeline: preparedPipeline,
|
|
3133
|
+
template: currentTemplate,
|
|
3134
|
+
pipelineIdentification: pipelineIdentification,
|
|
3135
|
+
})];
|
|
3136
|
+
case 2:
|
|
3137
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3138
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3139
|
+
parameters = {};
|
|
3140
|
+
_loop_1 = function (parameterName) {
|
|
3141
|
+
// Situation: Parameter is defined and used
|
|
3142
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3143
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
3144
|
+
}
|
|
3145
|
+
// Situation: Parameter is defined but NOT used
|
|
3146
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3147
|
+
// Situation: Parameter is NOT defined BUT used
|
|
3148
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3149
|
+
// Houston, we have a problem
|
|
3150
|
+
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
3151
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3152
|
+
}
|
|
3153
|
+
};
|
|
3154
|
+
try {
|
|
3155
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3156
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3157
|
+
parameterName = _e.value;
|
|
3158
|
+
_loop_1(parameterName);
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3162
|
+
finally {
|
|
3163
|
+
try {
|
|
3164
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3165
|
+
}
|
|
3166
|
+
finally { if (e_1) throw e_1.error; }
|
|
3167
|
+
}
|
|
3168
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3169
|
+
Object.freeze(parameters);
|
|
3170
|
+
result = null;
|
|
3171
|
+
resultString = null;
|
|
3172
|
+
expectError = null;
|
|
3173
|
+
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3174
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3175
|
+
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3176
|
+
.split('{content}')
|
|
3177
|
+
.join(currentTemplate.content);
|
|
3178
|
+
_loop_2 = function (attempt) {
|
|
3179
|
+
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;
|
|
3180
|
+
var e_2, _s, e_4, _t, e_3, _u;
|
|
3181
|
+
return __generator(this, function (_v) {
|
|
3182
|
+
switch (_v.label) {
|
|
3183
|
+
case 0:
|
|
3184
|
+
isJokerAttempt = attempt < 0;
|
|
3185
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3186
|
+
// TODO: [🧠] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3187
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
3188
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3189
|
+
}
|
|
3190
|
+
result = null;
|
|
3191
|
+
resultString = null;
|
|
3192
|
+
expectError = null;
|
|
3193
|
+
if (isJokerAttempt) {
|
|
3194
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
3195
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3196
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3197
|
+
}
|
|
3198
|
+
else {
|
|
3199
|
+
resultString = parameters[jokerParameterName];
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
_v.label = 1;
|
|
3203
|
+
case 1:
|
|
3204
|
+
_v.trys.push([1, 44, 45, 46]);
|
|
3205
|
+
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3206
|
+
_j = currentTemplate.templateType;
|
|
3207
|
+
switch (_j) {
|
|
3208
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3209
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3210
|
+
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
3211
|
+
case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
|
|
3212
|
+
}
|
|
3213
|
+
return [3 /*break*/, 25];
|
|
3214
|
+
case 2:
|
|
3215
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
3216
|
+
return [3 /*break*/, 26];
|
|
3217
|
+
case 3:
|
|
3218
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
|
|
3219
|
+
prompt = {
|
|
3220
|
+
title: currentTemplate.title,
|
|
3221
|
+
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3222
|
+
? preparedPipeline.pipelineUrl
|
|
3223
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3224
|
+
parameters: parameters,
|
|
3225
|
+
content: preparedContent,
|
|
3226
|
+
modelRequirements: modelRequirements,
|
|
3227
|
+
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3228
|
+
var name = _a.name;
|
|
3229
|
+
return name === currentTemplate.personaName;
|
|
3230
|
+
}) || {})), currentTemplate.expectations),
|
|
3231
|
+
format: currentTemplate.format,
|
|
3232
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3233
|
+
}; // <- TODO: Not very good type guard
|
|
3234
|
+
_k = modelRequirements.modelVariant;
|
|
3235
|
+
switch (_k) {
|
|
3236
|
+
case 'CHAT': return [3 /*break*/, 4];
|
|
3237
|
+
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3238
|
+
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3239
|
+
}
|
|
3240
|
+
return [3 /*break*/, 10];
|
|
3241
|
+
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3242
|
+
case 5:
|
|
3243
|
+
chatResult = _v.sent();
|
|
3244
|
+
// TODO: [🍬] Destroy chatThread
|
|
3245
|
+
result = chatResult;
|
|
3246
|
+
resultString = chatResult.content;
|
|
3247
|
+
return [3 /*break*/, 11];
|
|
3248
|
+
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3249
|
+
case 7:
|
|
3250
|
+
completionResult = _v.sent();
|
|
3251
|
+
result = completionResult;
|
|
3252
|
+
resultString = completionResult.content;
|
|
3253
|
+
return [3 /*break*/, 11];
|
|
3254
|
+
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3255
|
+
case 9:
|
|
3256
|
+
// TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
|
|
3257
|
+
embeddingResult = _v.sent();
|
|
3258
|
+
result = embeddingResult;
|
|
3259
|
+
resultString = embeddingResult.content.join(',');
|
|
3260
|
+
return [3 /*break*/, 11];
|
|
3261
|
+
case 10: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3262
|
+
case 11: return [3 /*break*/, 26];
|
|
3263
|
+
case 12:
|
|
3264
|
+
if (arrayableToArray(tools.script).length === 0) {
|
|
3265
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3266
|
+
}
|
|
3267
|
+
if (!currentTemplate.contentLanguage) {
|
|
3268
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3269
|
+
}
|
|
3270
|
+
// TODO: DRY [1]
|
|
3271
|
+
scriptPipelineExecutionErrors = [];
|
|
3272
|
+
_v.label = 13;
|
|
3273
|
+
case 13:
|
|
3274
|
+
_v.trys.push([13, 20, 21, 22]);
|
|
3275
|
+
_l = (e_2 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3276
|
+
_v.label = 14;
|
|
3277
|
+
case 14:
|
|
3278
|
+
if (!!_m.done) return [3 /*break*/, 19];
|
|
3279
|
+
scriptTools = _m.value;
|
|
3280
|
+
_v.label = 15;
|
|
3281
|
+
case 15:
|
|
3282
|
+
_v.trys.push([15, 17, , 18]);
|
|
3283
|
+
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3284
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
3285
|
+
script: preparedContent,
|
|
3286
|
+
parameters: parameters,
|
|
3287
|
+
}))];
|
|
3288
|
+
case 16:
|
|
3289
|
+
resultString = _v.sent();
|
|
3290
|
+
return [3 /*break*/, 19];
|
|
3291
|
+
case 17:
|
|
3292
|
+
error_1 = _v.sent();
|
|
3293
|
+
if (!(error_1 instanceof Error)) {
|
|
3294
|
+
throw error_1;
|
|
3295
|
+
}
|
|
3296
|
+
if (error_1 instanceof UnexpectedError) {
|
|
3297
|
+
throw error_1;
|
|
3298
|
+
}
|
|
3299
|
+
scriptPipelineExecutionErrors.push(error_1);
|
|
3300
|
+
return [3 /*break*/, 18];
|
|
3301
|
+
case 18:
|
|
3302
|
+
_m = _l.next();
|
|
3303
|
+
return [3 /*break*/, 14];
|
|
3304
|
+
case 19: return [3 /*break*/, 22];
|
|
3305
|
+
case 20:
|
|
3306
|
+
e_2_1 = _v.sent();
|
|
3307
|
+
e_2 = { error: e_2_1 };
|
|
3308
|
+
return [3 /*break*/, 22];
|
|
3309
|
+
case 21:
|
|
3310
|
+
try {
|
|
3311
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3312
|
+
}
|
|
3313
|
+
finally { if (e_2) throw e_2.error; }
|
|
3314
|
+
return [7 /*endfinally*/];
|
|
3315
|
+
case 22:
|
|
3316
|
+
if (resultString !== null) {
|
|
3317
|
+
return [3 /*break*/, 26];
|
|
3318
|
+
}
|
|
3319
|
+
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3320
|
+
throw scriptPipelineExecutionErrors[0];
|
|
3321
|
+
}
|
|
3322
|
+
else {
|
|
3323
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3324
|
+
.map(function (error) { return '- ' + error.message; })
|
|
3325
|
+
.join('\n\n')), "\n "); }));
|
|
3326
|
+
}
|
|
3327
|
+
case 23:
|
|
3328
|
+
if (tools.userInterface === undefined) {
|
|
3329
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3330
|
+
}
|
|
3331
|
+
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3332
|
+
promptTitle: currentTemplate.title,
|
|
3333
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3334
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3335
|
+
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
3336
|
+
placeholder: undefined,
|
|
3337
|
+
priority: priority,
|
|
3338
|
+
}))];
|
|
3339
|
+
case 24:
|
|
3340
|
+
// TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3341
|
+
resultString = _v.sent();
|
|
3342
|
+
return [3 /*break*/, 26];
|
|
3343
|
+
case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3344
|
+
case 26:
|
|
3345
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3346
|
+
_v.label = 27;
|
|
3347
|
+
case 27:
|
|
3348
|
+
_v.trys.push([27, 41, 42, 43]);
|
|
3349
|
+
_o = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3350
|
+
_v.label = 28;
|
|
3351
|
+
case 28:
|
|
3352
|
+
if (!!_p.done) return [3 /*break*/, 40];
|
|
3353
|
+
functionName = _p.value;
|
|
3354
|
+
// TODO: DRY [1]
|
|
3355
|
+
scriptPipelineExecutionErrors = [];
|
|
3356
|
+
postprocessingError = null;
|
|
3357
|
+
_v.label = 29;
|
|
3358
|
+
case 29:
|
|
3359
|
+
_v.trys.push([29, 36, 37, 38]);
|
|
3360
|
+
_q = (e_3 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3361
|
+
_v.label = 30;
|
|
3362
|
+
case 30:
|
|
3363
|
+
if (!!_r.done) return [3 /*break*/, 35];
|
|
3364
|
+
scriptTools = _r.value;
|
|
3365
|
+
_v.label = 31;
|
|
3366
|
+
case 31:
|
|
3367
|
+
_v.trys.push([31, 33, , 34]);
|
|
3368
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
3369
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3370
|
+
script: "".concat(functionName, "(resultString)"),
|
|
3371
|
+
parameters: {
|
|
3372
|
+
resultString: resultString || '',
|
|
3373
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
3374
|
+
},
|
|
3375
|
+
})];
|
|
3376
|
+
case 32:
|
|
3377
|
+
resultString = _v.sent();
|
|
3378
|
+
postprocessingError = null;
|
|
3379
|
+
return [3 /*break*/, 35];
|
|
3380
|
+
case 33:
|
|
3381
|
+
error_2 = _v.sent();
|
|
3382
|
+
if (!(error_2 instanceof Error)) {
|
|
3383
|
+
throw error_2;
|
|
3384
|
+
}
|
|
3385
|
+
if (error_2 instanceof UnexpectedError) {
|
|
3386
|
+
throw error_2;
|
|
3387
|
+
}
|
|
3388
|
+
postprocessingError = error_2;
|
|
3389
|
+
scriptPipelineExecutionErrors.push(error_2);
|
|
3390
|
+
return [3 /*break*/, 34];
|
|
3391
|
+
case 34:
|
|
3392
|
+
_r = _q.next();
|
|
3393
|
+
return [3 /*break*/, 30];
|
|
3394
|
+
case 35: return [3 /*break*/, 38];
|
|
3395
|
+
case 36:
|
|
3396
|
+
e_3_1 = _v.sent();
|
|
3397
|
+
e_3 = { error: e_3_1 };
|
|
3398
|
+
return [3 /*break*/, 38];
|
|
3399
|
+
case 37:
|
|
3400
|
+
try {
|
|
3401
|
+
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3402
|
+
}
|
|
3403
|
+
finally { if (e_3) throw e_3.error; }
|
|
3404
|
+
return [7 /*endfinally*/];
|
|
3405
|
+
case 38:
|
|
3406
|
+
if (postprocessingError) {
|
|
3407
|
+
throw postprocessingError;
|
|
3408
|
+
}
|
|
3409
|
+
_v.label = 39;
|
|
3410
|
+
case 39:
|
|
3411
|
+
_p = _o.next();
|
|
3412
|
+
return [3 /*break*/, 28];
|
|
3413
|
+
case 40: return [3 /*break*/, 43];
|
|
3414
|
+
case 41:
|
|
3415
|
+
e_4_1 = _v.sent();
|
|
3416
|
+
e_4 = { error: e_4_1 };
|
|
3417
|
+
return [3 /*break*/, 43];
|
|
3418
|
+
case 42:
|
|
3419
|
+
try {
|
|
3420
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3421
|
+
}
|
|
3422
|
+
finally { if (e_4) throw e_4.error; }
|
|
3423
|
+
return [7 /*endfinally*/];
|
|
3424
|
+
case 43:
|
|
3425
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
3426
|
+
if (currentTemplate.format) {
|
|
3427
|
+
if (currentTemplate.format === 'JSON') {
|
|
3428
|
+
if (!isValidJsonString(resultString || '')) {
|
|
3429
|
+
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3430
|
+
try {
|
|
3431
|
+
resultString = extractJsonBlock(resultString || '');
|
|
3432
|
+
}
|
|
3433
|
+
catch (error) {
|
|
3434
|
+
keepUnused(error);
|
|
3435
|
+
throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3436
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
else {
|
|
3441
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3442
|
+
}
|
|
3443
|
+
}
|
|
3444
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
3445
|
+
if (currentTemplate.expectations) {
|
|
3446
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3447
|
+
}
|
|
3448
|
+
return [2 /*return*/, "break-attempts"];
|
|
3449
|
+
case 44:
|
|
3450
|
+
error_3 = _v.sent();
|
|
3451
|
+
if (!(error_3 instanceof ExpectError)) {
|
|
3452
|
+
throw error_3;
|
|
3453
|
+
}
|
|
3454
|
+
expectError = error_3;
|
|
3455
|
+
return [3 /*break*/, 46];
|
|
3456
|
+
case 45:
|
|
3457
|
+
if (!isJokerAttempt &&
|
|
3458
|
+
currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
|
|
3459
|
+
prompt
|
|
3460
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3461
|
+
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
3462
|
+
) {
|
|
3463
|
+
// TODO: [🧠] Maybe put other templateTypes into report
|
|
3464
|
+
$executionReport.promptExecutions.push({
|
|
3465
|
+
prompt: __assign({}, prompt),
|
|
3466
|
+
result: result || undefined,
|
|
3467
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3468
|
+
});
|
|
3469
|
+
}
|
|
3470
|
+
return [7 /*endfinally*/];
|
|
3471
|
+
case 46:
|
|
3472
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3473
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block(prompt.content
|
|
3474
|
+
.split('\n')
|
|
3475
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3476
|
+
.join('\n')), "\n\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block(((expectError === null || expectError === void 0 ? void 0 : expectError.message) || '')
|
|
3477
|
+
.split('\n')
|
|
3478
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3479
|
+
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3480
|
+
? 'null'
|
|
3481
|
+
: resultString
|
|
3482
|
+
.split('\n')
|
|
3483
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3484
|
+
.join('\n')), "\n ---\n "); }));
|
|
3485
|
+
}
|
|
3486
|
+
return [2 /*return*/];
|
|
3487
|
+
}
|
|
3488
|
+
});
|
|
3489
|
+
};
|
|
3490
|
+
attempt = -jokerParameterNames.length;
|
|
3491
|
+
_h.label = 3;
|
|
3492
|
+
case 3:
|
|
3493
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 6];
|
|
3494
|
+
return [5 /*yield**/, _loop_2(attempt)];
|
|
3495
|
+
case 4:
|
|
3496
|
+
state_1 = _h.sent();
|
|
3497
|
+
switch (state_1) {
|
|
3498
|
+
case "break-attempts": return [3 /*break*/, 6];
|
|
3499
|
+
}
|
|
3500
|
+
_h.label = 5;
|
|
3501
|
+
case 5:
|
|
3502
|
+
attempt++;
|
|
3503
|
+
return [3 /*break*/, 3];
|
|
3504
|
+
case 6:
|
|
3505
|
+
//------------------------------------
|
|
3506
|
+
/*
|
|
3507
|
+
|
|
3508
|
+
|
|
3509
|
+
|
|
3510
|
+
|
|
3511
|
+
|
|
3512
|
+
|
|
3513
|
+
|
|
3514
|
+
|
|
3515
|
+
|
|
3516
|
+
*/
|
|
3517
|
+
//------------------------------------
|
|
3518
|
+
if (resultString === null) {
|
|
3519
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3520
|
+
}
|
|
3521
|
+
return [4 /*yield*/, onProgress({
|
|
3522
|
+
name: name,
|
|
3523
|
+
title: title,
|
|
3524
|
+
isStarted: true,
|
|
3525
|
+
isDone: true,
|
|
3526
|
+
templateType: currentTemplate.templateType,
|
|
3527
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
3528
|
+
parameterValue: resultString,
|
|
3529
|
+
// <- [🍸]
|
|
3530
|
+
})];
|
|
3531
|
+
case 7:
|
|
3532
|
+
_h.sent();
|
|
3533
|
+
return [2 /*return*/, Object.freeze((_g = {},
|
|
3534
|
+
_g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3535
|
+
_g))];
|
|
3536
|
+
}
|
|
3537
|
+
});
|
|
3538
|
+
});
|
|
3539
|
+
}
|
|
2933
3540
|
/**
|
|
2934
|
-
*
|
|
2935
|
-
*
|
|
2936
|
-
* @public exported from `@promptbook/utils`
|
|
3541
|
+
* TODO: [🤹♂️]
|
|
2937
3542
|
*/
|
|
2938
|
-
var CountUtils = {
|
|
2939
|
-
CHARACTERS: countCharacters,
|
|
2940
|
-
WORDS: countWords,
|
|
2941
|
-
SENTENCES: countSentences,
|
|
2942
|
-
PARAGRAPHS: countParagraphs,
|
|
2943
|
-
LINES: countLines,
|
|
2944
|
-
PAGES: countPages,
|
|
2945
|
-
};
|
|
2946
3543
|
|
|
2947
3544
|
/**
|
|
2948
|
-
*
|
|
2949
|
-
*
|
|
2950
|
-
* Note: There are two simmilar functions:
|
|
2951
|
-
* - `checkExpectations` which throws an error if the expectations are not met
|
|
2952
|
-
* - `isPassingExpectations` which returns a boolean
|
|
3545
|
+
* @@@
|
|
2953
3546
|
*
|
|
2954
|
-
* @
|
|
2955
|
-
* @returns {void} Nothing
|
|
2956
|
-
* @private internal function of `createPipelineExecutor`
|
|
3547
|
+
* @private internal utility of `createPipelineExecutor`
|
|
2957
3548
|
*/
|
|
2958
|
-
function
|
|
3549
|
+
function filterJustOutputParameters(options) {
|
|
2959
3550
|
var e_1, _a;
|
|
3551
|
+
var preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, $warnings = options.$warnings, pipelineIdentification = options.pipelineIdentification;
|
|
3552
|
+
var outputParameters = {};
|
|
3553
|
+
var _loop_1 = function (parameter) {
|
|
3554
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3555
|
+
// [4]
|
|
3556
|
+
$warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
3557
|
+
return "continue";
|
|
3558
|
+
}
|
|
3559
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3560
|
+
};
|
|
2960
3561
|
try {
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
var
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
2969
|
-
}
|
|
3562
|
+
// Note: Filter ONLY output parameters
|
|
3563
|
+
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
3564
|
+
var isOutput = _a.isOutput;
|
|
3565
|
+
return isOutput;
|
|
3566
|
+
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3567
|
+
var parameter = _c.value;
|
|
3568
|
+
_loop_1(parameter);
|
|
2970
3569
|
}
|
|
2971
3570
|
}
|
|
2972
3571
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -2976,614 +3575,27 @@ function checkExpectations(expectations, value) {
|
|
|
2976
3575
|
}
|
|
2977
3576
|
finally { if (e_1) throw e_1.error; }
|
|
2978
3577
|
}
|
|
3578
|
+
return outputParameters;
|
|
2979
3579
|
}
|
|
2980
|
-
/**
|
|
2981
|
-
* TODO: [💝] Unite object for expecting amount and format
|
|
2982
|
-
*/
|
|
2983
3580
|
|
|
2984
3581
|
/**
|
|
2985
|
-
*
|
|
3582
|
+
* @@@
|
|
2986
3583
|
*
|
|
2987
|
-
*
|
|
2988
|
-
*
|
|
2989
|
-
* @
|
|
3584
|
+
* Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
|
|
3585
|
+
*
|
|
3586
|
+
* @private internal utility of `createPipelineExecutor`
|
|
2990
3587
|
*/
|
|
2991
|
-
function
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? IS_VERBOSE : _d, _e = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e;
|
|
2995
|
-
validatePipeline(pipeline);
|
|
2996
|
-
var pipelineIdentification = (function () {
|
|
2997
|
-
// Note: This is a 😐 implementation of [🚞]
|
|
2998
|
-
var _ = [];
|
|
2999
|
-
if (pipeline.sourceFile !== undefined) {
|
|
3000
|
-
_.push("File: ".concat(pipeline.sourceFile));
|
|
3001
|
-
}
|
|
3002
|
-
if (pipeline.pipelineUrl !== undefined) {
|
|
3003
|
-
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
3004
|
-
}
|
|
3005
|
-
return _.join('\n');
|
|
3006
|
-
})();
|
|
3007
|
-
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3008
|
-
var preparedPipeline;
|
|
3009
|
-
if (isPipelinePrepared(pipeline)) {
|
|
3010
|
-
preparedPipeline = pipeline;
|
|
3011
|
-
}
|
|
3012
|
-
else if (isNotPreparedWarningSupressed !== true) {
|
|
3013
|
-
console.warn(spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
3014
|
-
}
|
|
3015
|
-
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
3016
|
-
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
3017
|
-
function getContextForTemplate(template) {
|
|
3018
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3019
|
-
return __generator(this, function (_a) {
|
|
3020
|
-
TODO_USE(template);
|
|
3021
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
3022
|
-
});
|
|
3023
|
-
});
|
|
3024
|
-
}
|
|
3025
|
-
function getKnowledgeForTemplate(template) {
|
|
3026
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3027
|
-
return __generator(this, function (_a) {
|
|
3028
|
-
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3029
|
-
TODO_USE(template);
|
|
3030
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3031
|
-
var content = _a.content;
|
|
3032
|
-
return "- ".concat(content);
|
|
3033
|
-
}).join('\n')];
|
|
3034
|
-
});
|
|
3035
|
-
});
|
|
3036
|
-
}
|
|
3037
|
-
function getSamplesForTemplate(template) {
|
|
3038
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3039
|
-
return __generator(this, function (_a) {
|
|
3040
|
-
// TODO: [♨] Implement Better - use real index and keyword search
|
|
3041
|
-
TODO_USE(template);
|
|
3042
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
3043
|
-
});
|
|
3044
|
-
});
|
|
3045
|
-
}
|
|
3046
|
-
function getReservedParametersForTemplate(template) {
|
|
3047
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3048
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_3, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3049
|
-
var e_3, _a;
|
|
3050
|
-
return __generator(this, function (_b) {
|
|
3051
|
-
switch (_b.label) {
|
|
3052
|
-
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
3053
|
-
case 1:
|
|
3054
|
-
context = _b.sent();
|
|
3055
|
-
return [4 /*yield*/, getKnowledgeForTemplate(template)];
|
|
3056
|
-
case 2:
|
|
3057
|
-
knowledge = _b.sent();
|
|
3058
|
-
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3059
|
-
case 3:
|
|
3060
|
-
samples = _b.sent();
|
|
3061
|
-
currentDate = new Date().toISOString();
|
|
3062
|
-
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3063
|
-
reservedParameters = {
|
|
3064
|
-
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3065
|
-
context: context,
|
|
3066
|
-
knowledge: knowledge,
|
|
3067
|
-
samples: samples,
|
|
3068
|
-
currentDate: currentDate,
|
|
3069
|
-
modelName: modelName,
|
|
3070
|
-
};
|
|
3071
|
-
_loop_3 = function (parameterName) {
|
|
3072
|
-
if (reservedParameters[parameterName] === undefined) {
|
|
3073
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3074
|
-
}
|
|
3075
|
-
};
|
|
3076
|
-
try {
|
|
3077
|
-
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3078
|
-
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()) {
|
|
3079
|
-
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3080
|
-
_loop_3(parameterName);
|
|
3081
|
-
}
|
|
3082
|
-
}
|
|
3083
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
3084
|
-
finally {
|
|
3085
|
-
try {
|
|
3086
|
-
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3087
|
-
}
|
|
3088
|
-
finally { if (e_3) throw e_3.error; }
|
|
3089
|
-
}
|
|
3090
|
-
return [2 /*return*/, reservedParameters];
|
|
3091
|
-
}
|
|
3092
|
-
});
|
|
3093
|
-
});
|
|
3094
|
-
}
|
|
3095
|
-
function executeSingleTemplate(currentTemplate) {
|
|
3096
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3097
|
-
var name, title, priority, progress_1, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_4, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, _loop_5, attempt, state_2, progress_2;
|
|
3098
|
-
var e_4, _f, _g;
|
|
3099
|
-
return __generator(this, function (_h) {
|
|
3100
|
-
switch (_h.label) {
|
|
3101
|
-
case 0:
|
|
3102
|
-
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3103
|
-
title = currentTemplate.title;
|
|
3104
|
-
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3105
|
-
if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
3106
|
-
progress_1 = {
|
|
3107
|
-
name: name,
|
|
3108
|
-
title: title,
|
|
3109
|
-
isStarted: false,
|
|
3110
|
-
isDone: false,
|
|
3111
|
-
templateType: currentTemplate.templateType,
|
|
3112
|
-
parameterName: currentTemplate.resultingParameterName,
|
|
3113
|
-
parameterValue: null,
|
|
3114
|
-
// <- [3]
|
|
3115
|
-
};
|
|
3116
|
-
if (isReturned) {
|
|
3117
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished \uD83C\uDF4F\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress_1, null, 4)
|
|
3118
|
-
.split('\n')
|
|
3119
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3120
|
-
.join('\n')), "\n "); }));
|
|
3121
|
-
}
|
|
3122
|
-
return [4 /*yield*/, onProgress(progress_1)];
|
|
3123
|
-
case 1:
|
|
3124
|
-
_h.sent();
|
|
3125
|
-
_h.label = 2;
|
|
3126
|
-
case 2:
|
|
3127
|
-
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3128
|
-
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3129
|
-
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3130
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
|
|
3131
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3132
|
-
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3133
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3134
|
-
.join(', '), "\n\n "); }));
|
|
3135
|
-
}
|
|
3136
|
-
_b = (_a = Object).freeze;
|
|
3137
|
-
_c = [{}];
|
|
3138
|
-
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
3139
|
-
case 3:
|
|
3140
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3141
|
-
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3142
|
-
parameters = {};
|
|
3143
|
-
_loop_4 = function (parameterName) {
|
|
3144
|
-
// Situation: Parameter is defined and used
|
|
3145
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3146
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3147
|
-
}
|
|
3148
|
-
// Situation: Parameter is defined but NOT used
|
|
3149
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3150
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3151
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3152
|
-
// Houston, we have a problem
|
|
3153
|
-
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
3154
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3155
|
-
}
|
|
3156
|
-
};
|
|
3157
|
-
try {
|
|
3158
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3159
|
-
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3160
|
-
parameterName = _e.value;
|
|
3161
|
-
_loop_4(parameterName);
|
|
3162
|
-
}
|
|
3163
|
-
}
|
|
3164
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
3165
|
-
finally {
|
|
3166
|
-
try {
|
|
3167
|
-
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3168
|
-
}
|
|
3169
|
-
finally { if (e_4) throw e_4.error; }
|
|
3170
|
-
}
|
|
3171
|
-
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3172
|
-
Object.freeze(parameters);
|
|
3173
|
-
result = null;
|
|
3174
|
-
resultString = null;
|
|
3175
|
-
expectError = null;
|
|
3176
|
-
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3177
|
-
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3178
|
-
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3179
|
-
.split('{content}')
|
|
3180
|
-
.join(currentTemplate.content);
|
|
3181
|
-
_loop_5 = function (attempt) {
|
|
3182
|
-
var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, scriptTools, error_2, e_5_1, _o, _p, functionName, postprocessingError, _q, _r, scriptTools, error_3, e_6_1, e_7_1, error_4;
|
|
3183
|
-
var e_5, _s, e_7, _t, e_6, _u;
|
|
3184
|
-
return __generator(this, function (_v) {
|
|
3185
|
-
switch (_v.label) {
|
|
3186
|
-
case 0:
|
|
3187
|
-
isJokerAttempt = attempt < 0;
|
|
3188
|
-
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3189
|
-
// TODO: [🧠] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3190
|
-
if (isJokerAttempt && !jokerParameterName) {
|
|
3191
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3192
|
-
}
|
|
3193
|
-
result = null;
|
|
3194
|
-
resultString = null;
|
|
3195
|
-
expectError = null;
|
|
3196
|
-
if (isJokerAttempt) {
|
|
3197
|
-
if (parameters[jokerParameterName] === undefined) {
|
|
3198
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3199
|
-
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3200
|
-
}
|
|
3201
|
-
else {
|
|
3202
|
-
resultString = parameters[jokerParameterName];
|
|
3203
|
-
}
|
|
3204
|
-
}
|
|
3205
|
-
_v.label = 1;
|
|
3206
|
-
case 1:
|
|
3207
|
-
_v.trys.push([1, 44, 45, 46]);
|
|
3208
|
-
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3209
|
-
_j = currentTemplate.templateType;
|
|
3210
|
-
switch (_j) {
|
|
3211
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3212
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3213
|
-
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
3214
|
-
case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
|
|
3215
|
-
}
|
|
3216
|
-
return [3 /*break*/, 25];
|
|
3217
|
-
case 2:
|
|
3218
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3219
|
-
return [3 /*break*/, 26];
|
|
3220
|
-
case 3:
|
|
3221
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (pipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
|
|
3222
|
-
prompt = {
|
|
3223
|
-
title: currentTemplate.title,
|
|
3224
|
-
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3225
|
-
? preparedPipeline.pipelineUrl
|
|
3226
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3227
|
-
parameters: parameters,
|
|
3228
|
-
content: preparedContent,
|
|
3229
|
-
modelRequirements: modelRequirements,
|
|
3230
|
-
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3231
|
-
var name = _a.name;
|
|
3232
|
-
return name === currentTemplate.personaName;
|
|
3233
|
-
}) || {})), currentTemplate.expectations),
|
|
3234
|
-
format: currentTemplate.format,
|
|
3235
|
-
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3236
|
-
}; // <- TODO: Not very good type guard
|
|
3237
|
-
_k = modelRequirements.modelVariant;
|
|
3238
|
-
switch (_k) {
|
|
3239
|
-
case 'CHAT': return [3 /*break*/, 4];
|
|
3240
|
-
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3241
|
-
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3242
|
-
}
|
|
3243
|
-
return [3 /*break*/, 10];
|
|
3244
|
-
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3245
|
-
case 5:
|
|
3246
|
-
chatResult = _v.sent();
|
|
3247
|
-
// TODO: [🍬] Destroy chatThread
|
|
3248
|
-
result = chatResult;
|
|
3249
|
-
resultString = chatResult.content;
|
|
3250
|
-
return [3 /*break*/, 11];
|
|
3251
|
-
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3252
|
-
case 7:
|
|
3253
|
-
completionResult = _v.sent();
|
|
3254
|
-
result = completionResult;
|
|
3255
|
-
resultString = completionResult.content;
|
|
3256
|
-
return [3 /*break*/, 11];
|
|
3257
|
-
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3258
|
-
case 9:
|
|
3259
|
-
embeddingResult = _v.sent();
|
|
3260
|
-
result = embeddingResult;
|
|
3261
|
-
resultString = embeddingResult.content.join(',');
|
|
3262
|
-
return [3 /*break*/, 11];
|
|
3263
|
-
case 10: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements
|
|
3264
|
-
.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3265
|
-
case 11: return [3 /*break*/, 26];
|
|
3266
|
-
case 12:
|
|
3267
|
-
if (arrayableToArray(tools.script).length === 0) {
|
|
3268
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3269
|
-
}
|
|
3270
|
-
if (!currentTemplate.contentLanguage) {
|
|
3271
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3272
|
-
}
|
|
3273
|
-
// TODO: DRY [1]
|
|
3274
|
-
scriptPipelineExecutionErrors = [];
|
|
3275
|
-
_v.label = 13;
|
|
3276
|
-
case 13:
|
|
3277
|
-
_v.trys.push([13, 20, 21, 22]);
|
|
3278
|
-
_l = (e_5 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3279
|
-
_v.label = 14;
|
|
3280
|
-
case 14:
|
|
3281
|
-
if (!!_m.done) return [3 /*break*/, 19];
|
|
3282
|
-
scriptTools = _m.value;
|
|
3283
|
-
_v.label = 15;
|
|
3284
|
-
case 15:
|
|
3285
|
-
_v.trys.push([15, 17, , 18]);
|
|
3286
|
-
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3287
|
-
scriptLanguage: currentTemplate.contentLanguage,
|
|
3288
|
-
script: preparedContent,
|
|
3289
|
-
parameters: parameters,
|
|
3290
|
-
}))];
|
|
3291
|
-
case 16:
|
|
3292
|
-
resultString = _v.sent();
|
|
3293
|
-
return [3 /*break*/, 19];
|
|
3294
|
-
case 17:
|
|
3295
|
-
error_2 = _v.sent();
|
|
3296
|
-
if (!(error_2 instanceof Error)) {
|
|
3297
|
-
throw error_2;
|
|
3298
|
-
}
|
|
3299
|
-
if (error_2 instanceof UnexpectedError) {
|
|
3300
|
-
throw error_2;
|
|
3301
|
-
}
|
|
3302
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3303
|
-
return [3 /*break*/, 18];
|
|
3304
|
-
case 18:
|
|
3305
|
-
_m = _l.next();
|
|
3306
|
-
return [3 /*break*/, 14];
|
|
3307
|
-
case 19: return [3 /*break*/, 22];
|
|
3308
|
-
case 20:
|
|
3309
|
-
e_5_1 = _v.sent();
|
|
3310
|
-
e_5 = { error: e_5_1 };
|
|
3311
|
-
return [3 /*break*/, 22];
|
|
3312
|
-
case 21:
|
|
3313
|
-
try {
|
|
3314
|
-
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3315
|
-
}
|
|
3316
|
-
finally { if (e_5) throw e_5.error; }
|
|
3317
|
-
return [7 /*endfinally*/];
|
|
3318
|
-
case 22:
|
|
3319
|
-
if (resultString !== null) {
|
|
3320
|
-
return [3 /*break*/, 26];
|
|
3321
|
-
}
|
|
3322
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3323
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3324
|
-
}
|
|
3325
|
-
else {
|
|
3326
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3327
|
-
.map(function (error) { return '- ' + error.message; })
|
|
3328
|
-
.join('\n\n')), "\n "); }));
|
|
3329
|
-
}
|
|
3330
|
-
case 23:
|
|
3331
|
-
if (tools.userInterface === undefined) {
|
|
3332
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3333
|
-
}
|
|
3334
|
-
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3335
|
-
promptTitle: currentTemplate.title,
|
|
3336
|
-
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3337
|
-
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3338
|
-
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
3339
|
-
placeholder: undefined,
|
|
3340
|
-
priority: priority,
|
|
3341
|
-
}))];
|
|
3342
|
-
case 24:
|
|
3343
|
-
// TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3344
|
-
resultString = _v.sent();
|
|
3345
|
-
return [3 /*break*/, 26];
|
|
3346
|
-
case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3347
|
-
case 26:
|
|
3348
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3349
|
-
_v.label = 27;
|
|
3350
|
-
case 27:
|
|
3351
|
-
_v.trys.push([27, 41, 42, 43]);
|
|
3352
|
-
_o = (e_7 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3353
|
-
_v.label = 28;
|
|
3354
|
-
case 28:
|
|
3355
|
-
if (!!_p.done) return [3 /*break*/, 40];
|
|
3356
|
-
functionName = _p.value;
|
|
3357
|
-
// TODO: DRY [1]
|
|
3358
|
-
scriptPipelineExecutionErrors = [];
|
|
3359
|
-
postprocessingError = null;
|
|
3360
|
-
_v.label = 29;
|
|
3361
|
-
case 29:
|
|
3362
|
-
_v.trys.push([29, 36, 37, 38]);
|
|
3363
|
-
_q = (e_6 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3364
|
-
_v.label = 30;
|
|
3365
|
-
case 30:
|
|
3366
|
-
if (!!_r.done) return [3 /*break*/, 35];
|
|
3367
|
-
scriptTools = _r.value;
|
|
3368
|
-
_v.label = 31;
|
|
3369
|
-
case 31:
|
|
3370
|
-
_v.trys.push([31, 33, , 34]);
|
|
3371
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
3372
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3373
|
-
script: "".concat(functionName, "(resultString)"),
|
|
3374
|
-
parameters: {
|
|
3375
|
-
resultString: resultString || '',
|
|
3376
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
3377
|
-
},
|
|
3378
|
-
})];
|
|
3379
|
-
case 32:
|
|
3380
|
-
resultString = _v.sent();
|
|
3381
|
-
postprocessingError = null;
|
|
3382
|
-
return [3 /*break*/, 35];
|
|
3383
|
-
case 33:
|
|
3384
|
-
error_3 = _v.sent();
|
|
3385
|
-
if (!(error_3 instanceof Error)) {
|
|
3386
|
-
throw error_3;
|
|
3387
|
-
}
|
|
3388
|
-
if (error_3 instanceof UnexpectedError) {
|
|
3389
|
-
throw error_3;
|
|
3390
|
-
}
|
|
3391
|
-
postprocessingError = error_3;
|
|
3392
|
-
scriptPipelineExecutionErrors.push(error_3);
|
|
3393
|
-
return [3 /*break*/, 34];
|
|
3394
|
-
case 34:
|
|
3395
|
-
_r = _q.next();
|
|
3396
|
-
return [3 /*break*/, 30];
|
|
3397
|
-
case 35: return [3 /*break*/, 38];
|
|
3398
|
-
case 36:
|
|
3399
|
-
e_6_1 = _v.sent();
|
|
3400
|
-
e_6 = { error: e_6_1 };
|
|
3401
|
-
return [3 /*break*/, 38];
|
|
3402
|
-
case 37:
|
|
3403
|
-
try {
|
|
3404
|
-
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3405
|
-
}
|
|
3406
|
-
finally { if (e_6) throw e_6.error; }
|
|
3407
|
-
return [7 /*endfinally*/];
|
|
3408
|
-
case 38:
|
|
3409
|
-
if (postprocessingError) {
|
|
3410
|
-
throw postprocessingError;
|
|
3411
|
-
}
|
|
3412
|
-
_v.label = 39;
|
|
3413
|
-
case 39:
|
|
3414
|
-
_p = _o.next();
|
|
3415
|
-
return [3 /*break*/, 28];
|
|
3416
|
-
case 40: return [3 /*break*/, 43];
|
|
3417
|
-
case 41:
|
|
3418
|
-
e_7_1 = _v.sent();
|
|
3419
|
-
e_7 = { error: e_7_1 };
|
|
3420
|
-
return [3 /*break*/, 43];
|
|
3421
|
-
case 42:
|
|
3422
|
-
try {
|
|
3423
|
-
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3424
|
-
}
|
|
3425
|
-
finally { if (e_7) throw e_7.error; }
|
|
3426
|
-
return [7 /*endfinally*/];
|
|
3427
|
-
case 43:
|
|
3428
|
-
// TODO: [💝] Unite object for expecting amount and format
|
|
3429
|
-
if (currentTemplate.format) {
|
|
3430
|
-
if (currentTemplate.format === 'JSON') {
|
|
3431
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3432
|
-
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3433
|
-
try {
|
|
3434
|
-
resultString = extractJsonBlock(resultString || '');
|
|
3435
|
-
}
|
|
3436
|
-
catch (error) {
|
|
3437
|
-
keepUnused(error);
|
|
3438
|
-
throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3439
|
-
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3440
|
-
}
|
|
3441
|
-
}
|
|
3442
|
-
}
|
|
3443
|
-
else {
|
|
3444
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3445
|
-
}
|
|
3446
|
-
}
|
|
3447
|
-
// TODO: [💝] Unite object for expecting amount and format
|
|
3448
|
-
if (currentTemplate.expectations) {
|
|
3449
|
-
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3450
|
-
}
|
|
3451
|
-
return [2 /*return*/, "break-attempts"];
|
|
3452
|
-
case 44:
|
|
3453
|
-
error_4 = _v.sent();
|
|
3454
|
-
if (!(error_4 instanceof ExpectError)) {
|
|
3455
|
-
throw error_4;
|
|
3456
|
-
}
|
|
3457
|
-
expectError = error_4;
|
|
3458
|
-
return [3 /*break*/, 46];
|
|
3459
|
-
case 45:
|
|
3460
|
-
if (!isJokerAttempt &&
|
|
3461
|
-
currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
|
|
3462
|
-
prompt
|
|
3463
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3464
|
-
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
3465
|
-
) {
|
|
3466
|
-
// TODO: [🧠] Maybe put other templateTypes into report
|
|
3467
|
-
executionReport.promptExecutions.push({
|
|
3468
|
-
prompt: __assign({}, prompt),
|
|
3469
|
-
result: result || undefined,
|
|
3470
|
-
error: expectError === null ? undefined : serializeError(expectError),
|
|
3471
|
-
});
|
|
3472
|
-
}
|
|
3473
|
-
return [7 /*endfinally*/];
|
|
3474
|
-
case 46:
|
|
3475
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3476
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block(prompt.content
|
|
3477
|
-
.split('\n')
|
|
3478
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3479
|
-
.join('\n')), "\n\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block(((expectError === null || expectError === void 0 ? void 0 : expectError.message) || '')
|
|
3480
|
-
.split('\n')
|
|
3481
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3482
|
-
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3483
|
-
? 'null'
|
|
3484
|
-
: resultString
|
|
3485
|
-
.split('\n')
|
|
3486
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3487
|
-
.join('\n')), "\n ---\n "); }));
|
|
3488
|
-
}
|
|
3489
|
-
return [2 /*return*/];
|
|
3490
|
-
}
|
|
3491
|
-
});
|
|
3492
|
-
};
|
|
3493
|
-
attempt = -jokerParameterNames.length;
|
|
3494
|
-
_h.label = 4;
|
|
3495
|
-
case 4:
|
|
3496
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/, 7];
|
|
3497
|
-
return [5 /*yield**/, _loop_5(attempt)];
|
|
3498
|
-
case 5:
|
|
3499
|
-
state_2 = _h.sent();
|
|
3500
|
-
switch (state_2) {
|
|
3501
|
-
case "break-attempts": return [3 /*break*/, 7];
|
|
3502
|
-
}
|
|
3503
|
-
_h.label = 6;
|
|
3504
|
-
case 6:
|
|
3505
|
-
attempt++;
|
|
3506
|
-
return [3 /*break*/, 4];
|
|
3507
|
-
case 7:
|
|
3508
|
-
//------------------------------------
|
|
3509
|
-
/*
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
*/
|
|
3520
|
-
//------------------------------------
|
|
3521
|
-
if (resultString === null) {
|
|
3522
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3523
|
-
}
|
|
3524
|
-
if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 9]; /* <- [3] */
|
|
3525
|
-
progress_2 = {
|
|
3526
|
-
name: name,
|
|
3527
|
-
title: title,
|
|
3528
|
-
isStarted: true,
|
|
3529
|
-
isDone: true,
|
|
3530
|
-
templateType: currentTemplate.templateType,
|
|
3531
|
-
parameterName: currentTemplate.resultingParameterName,
|
|
3532
|
-
parameterValue: resultString,
|
|
3533
|
-
// <- [3]
|
|
3534
|
-
};
|
|
3535
|
-
if (isReturned) {
|
|
3536
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished \uD83C\uDF4E\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress_2, null, 4)
|
|
3537
|
-
.split('\n')
|
|
3538
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3539
|
-
.join('\n')), "\n\n "); }));
|
|
3540
|
-
}
|
|
3541
|
-
return [4 /*yield*/, onProgress(progress_2)];
|
|
3542
|
-
case 8:
|
|
3543
|
-
_h.sent();
|
|
3544
|
-
_h.label = 9;
|
|
3545
|
-
case 9:
|
|
3546
|
-
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (_g = {}, _g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _g)));
|
|
3547
|
-
return [2 /*return*/];
|
|
3548
|
-
}
|
|
3549
|
-
});
|
|
3550
|
-
});
|
|
3551
|
-
}
|
|
3552
|
-
function filterJustOutputParameters() {
|
|
3553
|
-
var e_8, _a;
|
|
3554
|
-
var outputParameters = {};
|
|
3555
|
-
var _loop_6 = function (parameter) {
|
|
3556
|
-
if (parametersToPass[parameter.name] === undefined) {
|
|
3557
|
-
// [4]
|
|
3558
|
-
warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
3559
|
-
return "continue";
|
|
3560
|
-
}
|
|
3561
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3562
|
-
};
|
|
3563
|
-
try {
|
|
3564
|
-
// Note: Filter ONLY output parameters
|
|
3565
|
-
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
3566
|
-
var isOutput = _a.isOutput;
|
|
3567
|
-
return isOutput;
|
|
3568
|
-
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3569
|
-
var parameter = _c.value;
|
|
3570
|
-
_loop_6(parameter);
|
|
3571
|
-
}
|
|
3572
|
-
}
|
|
3573
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
3574
|
-
finally {
|
|
3575
|
-
try {
|
|
3576
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3577
|
-
}
|
|
3578
|
-
finally { if (e_8) throw e_8.error; }
|
|
3579
|
-
}
|
|
3580
|
-
return outputParameters;
|
|
3581
|
-
}
|
|
3582
|
-
var errors, warnings, executionReport, isReturned, _a, _b, parameter, e_1_1, _loop_1, _c, _d, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
3588
|
+
function executePipeline(options) {
|
|
3589
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3590
|
+
var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, settings, maxParallelCount, isVerbose, preparedPipeline, llmTools, errors, warnings, executionReport, isReturned, _a, _b, parameter, e_1_1, _loop_1, _c, _d, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
3583
3591
|
var e_1, _e, e_2, _f;
|
|
3584
3592
|
return __generator(this, function (_g) {
|
|
3585
3593
|
switch (_g.label) {
|
|
3586
3594
|
case 0:
|
|
3595
|
+
inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification, settings = options.settings;
|
|
3596
|
+
maxParallelCount = settings.maxParallelCount, isVerbose = settings.isVerbose;
|
|
3597
|
+
preparedPipeline = options.preparedPipeline;
|
|
3598
|
+
llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3587
3599
|
if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
|
|
3588
3600
|
return [4 /*yield*/, preparePipeline(pipeline, {
|
|
3589
3601
|
llmTools: llmTools,
|
|
@@ -3592,6 +3604,7 @@ function createPipelineExecutor(options) {
|
|
|
3592
3604
|
})];
|
|
3593
3605
|
case 1:
|
|
3594
3606
|
preparedPipeline = _g.sent();
|
|
3607
|
+
setPreparedPipeline(preparedPipeline);
|
|
3595
3608
|
_g.label = 2;
|
|
3596
3609
|
case 2:
|
|
3597
3610
|
errors = [];
|
|
@@ -3661,7 +3674,7 @@ function createPipelineExecutor(options) {
|
|
|
3661
3674
|
return name === parameterName;
|
|
3662
3675
|
});
|
|
3663
3676
|
if (!(parameter === undefined)) return [3 /*break*/, 1];
|
|
3664
|
-
warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n
|
|
3677
|
+
warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
3665
3678
|
return [3 /*break*/, 4];
|
|
3666
3679
|
case 1:
|
|
3667
3680
|
if (!(parameter.isInput === false)) return [3 /*break*/, 4];
|
|
@@ -3673,10 +3686,10 @@ function createPipelineExecutor(options) {
|
|
|
3673
3686
|
// Note: Wait a short time to prevent race conditions
|
|
3674
3687
|
_h.sent();
|
|
3675
3688
|
_h.label = 3;
|
|
3676
|
-
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n
|
|
3689
|
+
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
3677
3690
|
isSuccessful: false,
|
|
3678
3691
|
errors: __spreadArray([
|
|
3679
|
-
new PipelineExecutionError(spaceTrim(function (block) { return "\n
|
|
3692
|
+
new PipelineExecutionError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
3680
3693
|
], __read(errors), false).map(serializeError),
|
|
3681
3694
|
warnings: warnings.map(serializeError),
|
|
3682
3695
|
executionReport: executionReport,
|
|
@@ -3740,7 +3753,7 @@ function createPipelineExecutor(options) {
|
|
|
3740
3753
|
case 0:
|
|
3741
3754
|
if (loopLimit-- < 0) {
|
|
3742
3755
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
3743
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n
|
|
3756
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3744
3757
|
}
|
|
3745
3758
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3746
3759
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -3750,24 +3763,45 @@ function createPipelineExecutor(options) {
|
|
|
3750
3763
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3751
3764
|
throw new UnexpectedError(
|
|
3752
3765
|
// TODO: [🐎] DRY
|
|
3753
|
-
spaceTrim(function (block) { return "\n
|
|
3766
|
+
spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates_1
|
|
3754
3767
|
.map(function (_a) {
|
|
3755
3768
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3756
3769
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
3757
3770
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
3758
3771
|
.join(' and '));
|
|
3759
3772
|
})
|
|
3760
|
-
.join('\n')), "\n\n
|
|
3773
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameterNames_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
|
|
3761
3774
|
case 1:
|
|
3762
3775
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
3763
|
-
/* [
|
|
3776
|
+
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
3764
3777
|
case 2:
|
|
3765
|
-
/* [
|
|
3778
|
+
/* [🤹♂️] */ _j.sent();
|
|
3766
3779
|
return [3 /*break*/, 4];
|
|
3767
3780
|
case 3:
|
|
3768
3781
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
3769
|
-
work_1 =
|
|
3770
|
-
|
|
3782
|
+
work_1 = executeTemplate({
|
|
3783
|
+
currentTemplate: currentTemplate,
|
|
3784
|
+
preparedPipeline: preparedPipeline,
|
|
3785
|
+
parametersToPass: parametersToPass,
|
|
3786
|
+
tools: tools,
|
|
3787
|
+
llmTools: llmTools,
|
|
3788
|
+
onProgress: function (progress) {
|
|
3789
|
+
if (isReturned) {
|
|
3790
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
|
|
3791
|
+
.split('\n')
|
|
3792
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3793
|
+
.join('\n')), "\n "); }));
|
|
3794
|
+
}
|
|
3795
|
+
if (onProgress) {
|
|
3796
|
+
onProgress(progress);
|
|
3797
|
+
}
|
|
3798
|
+
},
|
|
3799
|
+
settings: settings,
|
|
3800
|
+
$executionReport: executionReport,
|
|
3801
|
+
pipelineIdentification: pipelineIdentification,
|
|
3802
|
+
})
|
|
3803
|
+
.then(function (newParametersToPass) {
|
|
3804
|
+
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
3771
3805
|
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
|
|
3772
3806
|
})
|
|
3773
3807
|
.then(function () {
|
|
@@ -3799,7 +3833,12 @@ function createPipelineExecutor(options) {
|
|
|
3799
3833
|
var result = _a.result;
|
|
3800
3834
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3801
3835
|
})), false));
|
|
3802
|
-
outputParameters_1 = filterJustOutputParameters(
|
|
3836
|
+
outputParameters_1 = filterJustOutputParameters({
|
|
3837
|
+
preparedPipeline: preparedPipeline,
|
|
3838
|
+
parametersToPass: parametersToPass,
|
|
3839
|
+
$warnings: warnings,
|
|
3840
|
+
pipelineIdentification: pipelineIdentification,
|
|
3841
|
+
});
|
|
3803
3842
|
isReturned = true;
|
|
3804
3843
|
if (!(onProgress !== undefined)) return [3 /*break*/, 27];
|
|
3805
3844
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -3822,7 +3861,12 @@ function createPipelineExecutor(options) {
|
|
|
3822
3861
|
var result = _a.result;
|
|
3823
3862
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3824
3863
|
})), false));
|
|
3825
|
-
outputParameters = filterJustOutputParameters(
|
|
3864
|
+
outputParameters = filterJustOutputParameters({
|
|
3865
|
+
preparedPipeline: preparedPipeline,
|
|
3866
|
+
parametersToPass: parametersToPass,
|
|
3867
|
+
$warnings: warnings,
|
|
3868
|
+
pipelineIdentification: pipelineIdentification,
|
|
3869
|
+
});
|
|
3826
3870
|
isReturned = true;
|
|
3827
3871
|
if (!(onProgress !== undefined)) return [3 /*break*/, 30];
|
|
3828
3872
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -3842,22 +3886,62 @@ function createPipelineExecutor(options) {
|
|
|
3842
3886
|
})];
|
|
3843
3887
|
}
|
|
3844
3888
|
});
|
|
3845
|
-
});
|
|
3846
|
-
return pipelineExecutor;
|
|
3889
|
+
});
|
|
3847
3890
|
}
|
|
3891
|
+
|
|
3848
3892
|
/**
|
|
3849
|
-
*
|
|
3850
|
-
*
|
|
3851
|
-
*
|
|
3852
|
-
*
|
|
3853
|
-
*
|
|
3854
|
-
* TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
|
|
3855
|
-
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
3856
|
-
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
3857
|
-
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
3858
|
-
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3859
|
-
* TODO: [🧠][💷] `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result BUT maybe NOT to preserve pure JSON object
|
|
3893
|
+
* Creates executor function from pipeline and execution tools.
|
|
3894
|
+
*
|
|
3895
|
+
* @returns The executor function
|
|
3896
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
3897
|
+
* @public exported from `@promptbook/core`
|
|
3860
3898
|
*/
|
|
3899
|
+
function createPipelineExecutor(options) {
|
|
3900
|
+
var _this = this;
|
|
3901
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
3902
|
+
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? IS_VERBOSE : _d, _e = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e;
|
|
3903
|
+
validatePipeline(pipeline);
|
|
3904
|
+
var pipelineIdentification = (function () {
|
|
3905
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
3906
|
+
var _ = [];
|
|
3907
|
+
if (pipeline.sourceFile !== undefined) {
|
|
3908
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
3909
|
+
}
|
|
3910
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
3911
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
3912
|
+
}
|
|
3913
|
+
return _.join('\n');
|
|
3914
|
+
})();
|
|
3915
|
+
var preparedPipeline;
|
|
3916
|
+
if (isPipelinePrepared(pipeline)) {
|
|
3917
|
+
preparedPipeline = pipeline;
|
|
3918
|
+
}
|
|
3919
|
+
else if (isNotPreparedWarningSupressed !== true) {
|
|
3920
|
+
console.warn(spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
3921
|
+
}
|
|
3922
|
+
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
3923
|
+
return __generator(this, function (_a) {
|
|
3924
|
+
return [2 /*return*/, executePipeline({
|
|
3925
|
+
pipeline: pipeline,
|
|
3926
|
+
preparedPipeline: preparedPipeline,
|
|
3927
|
+
setPreparedPipeline: function (newPreparedPipeline) {
|
|
3928
|
+
preparedPipeline = newPreparedPipeline;
|
|
3929
|
+
},
|
|
3930
|
+
inputParameters: inputParameters,
|
|
3931
|
+
tools: tools,
|
|
3932
|
+
onProgress: onProgress,
|
|
3933
|
+
pipelineIdentification: pipelineIdentification,
|
|
3934
|
+
settings: {
|
|
3935
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
3936
|
+
maxParallelCount: maxParallelCount,
|
|
3937
|
+
isVerbose: isVerbose,
|
|
3938
|
+
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
3939
|
+
},
|
|
3940
|
+
})];
|
|
3941
|
+
});
|
|
3942
|
+
}); };
|
|
3943
|
+
return pipelineExecutor;
|
|
3944
|
+
}
|
|
3861
3945
|
|
|
3862
3946
|
/**
|
|
3863
3947
|
* @@@
|
|
@@ -5114,6 +5198,8 @@ var foreachCommandParser = {
|
|
|
5114
5198
|
*/
|
|
5115
5199
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5116
5200
|
var formatName = command.formatName, cellName = command.cellName, parameterName = command.parameterName, subparameterName = command.subparameterName;
|
|
5201
|
+
// TODO: !!!!!! Detect double use
|
|
5202
|
+
// TODO: !!!!!! Detect usage with JOKER and don't allow it
|
|
5117
5203
|
$templateJson.foreach = { formatName: formatName, cellName: cellName, parameterName: parameterName, subparameterName: subparameterName };
|
|
5118
5204
|
keepUnused($pipelineJson); // <- TODO: !!!!!! BUT Maybe register subparameter from foreach into parameters of the pipeline
|
|
5119
5205
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|