@promptbook/node 0.69.0-1 โ 0.69.0-4
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 +1000 -911
- 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 +6 -0
- package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +2 -6
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +26 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +4 -4
- package/esm/typings/src/config.d.ts +7 -1
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.d.ts +2 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +4 -0
- package/esm/typings/src/execution/createPipelineExecutor/CreatePipelineExecutorOptions.d.ts +20 -0
- package/esm/typings/src/execution/createPipelineExecutor/CreatePipelineExecutorSettings.d.ts +30 -0
- package/esm/typings/src/execution/createPipelineExecutor/createPipelineExecutor.d.ts +24 -0
- package/esm/typings/src/execution/createPipelineExecutor/executeSingleTemplate.d.ts +27 -0
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +8 -0
- package/esm/typings/src/execution/createPipelineExecutor/getContextForTemplate.d.ts +8 -0
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTemplate.d.ts +9 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTemplate.d.ts +8 -0
- package/esm/typings/src/execution/createPipelineExecutor/getSamplesForTemplate.d.ts +8 -0
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +5 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -0
- package/package.json +2 -2
- package/umd/index.umd.js +1000 -911
- 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-3';
|
|
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
|
]);
|
|
@@ -426,6 +427,15 @@ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
|
426
427
|
* @public exported from `@promptbook/core`
|
|
427
428
|
*/
|
|
428
429
|
var IS_VERBOSE = false;
|
|
430
|
+
/**
|
|
431
|
+
* @@@
|
|
432
|
+
*
|
|
433
|
+
* @private within the repository
|
|
434
|
+
*/
|
|
435
|
+
var IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
436
|
+
/**/
|
|
437
|
+
// Note: In normal situations, we check the pipeline logic:
|
|
438
|
+
true);
|
|
429
439
|
/**
|
|
430
440
|
* TODO: [๐ง ][๐งโโ๏ธ] Maybe join remoteUrl and path into single value
|
|
431
441
|
*/
|
|
@@ -874,7 +884,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
874
884
|
});
|
|
875
885
|
}
|
|
876
886
|
|
|
877
|
-
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-3",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-3",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-3",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-3",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"}];
|
|
878
888
|
|
|
879
889
|
/**
|
|
880
890
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1081,6 +1091,26 @@ function isValidPipelineUrl(url) {
|
|
|
1081
1091
|
* @public exported from `@promptbook/core`
|
|
1082
1092
|
*/
|
|
1083
1093
|
function validatePipeline(pipeline) {
|
|
1094
|
+
if (IS_PIPELINE_LOGIC_VALIDATED) {
|
|
1095
|
+
validatePipelineCore(pipeline);
|
|
1096
|
+
}
|
|
1097
|
+
else {
|
|
1098
|
+
try {
|
|
1099
|
+
validatePipelineCore(pipeline);
|
|
1100
|
+
}
|
|
1101
|
+
catch (error) {
|
|
1102
|
+
if (!(error instanceof PipelineLogicError)) {
|
|
1103
|
+
throw error;
|
|
1104
|
+
}
|
|
1105
|
+
console.error(spaceTrim(function (block) { return "\n Pipeline is not valid but logic errors are temporarily disabled via `IS_PIPELINE_LOGIC_VALIDATED`\n\n ".concat(block(error.message), "\n "); }));
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
return pipeline;
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* @private internal function for `validatePipeline`
|
|
1112
|
+
*/
|
|
1113
|
+
function validatePipelineCore(pipeline) {
|
|
1084
1114
|
// TODO: [๐ง ] Maybe test if promptbook is a promise and make specific error case for that
|
|
1085
1115
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
1086
1116
|
var pipelineIdentification = (function () {
|
|
@@ -1279,7 +1309,6 @@ function validatePipeline(pipeline) {
|
|
|
1279
1309
|
while (unresovedTemplates.length > 0) {
|
|
1280
1310
|
_loop_3();
|
|
1281
1311
|
}
|
|
1282
|
-
return pipeline;
|
|
1283
1312
|
}
|
|
1284
1313
|
/**
|
|
1285
1314
|
* TODO: [๐ง ] Work with promptbookVersion
|
|
@@ -2018,116 +2047,6 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2018
2047
|
* TODO: [๐ง ] Can this return type be better typed than void
|
|
2019
2048
|
*/
|
|
2020
2049
|
|
|
2021
|
-
/**
|
|
2022
|
-
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
2023
|
-
*
|
|
2024
|
-
* @param script from which to extract the variables
|
|
2025
|
-
* @returns the list of variable names
|
|
2026
|
-
* @throws {ParseError} if the script is invalid
|
|
2027
|
-
* @public exported from `@promptbook/utils`
|
|
2028
|
-
*/
|
|
2029
|
-
function extractVariables(script) {
|
|
2030
|
-
var variables = new Set();
|
|
2031
|
-
script = "(()=>{".concat(script, "})()");
|
|
2032
|
-
try {
|
|
2033
|
-
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2034
|
-
try {
|
|
2035
|
-
eval(script);
|
|
2036
|
-
}
|
|
2037
|
-
catch (error) {
|
|
2038
|
-
if (!(error instanceof ReferenceError)) {
|
|
2039
|
-
throw error;
|
|
2040
|
-
}
|
|
2041
|
-
var undefinedName = error.message.split(' ')[0];
|
|
2042
|
-
/*
|
|
2043
|
-
Note: Parsing the error
|
|
2044
|
-
[PipelineUrlError: thing is not defined]
|
|
2045
|
-
*/
|
|
2046
|
-
if (!undefinedName) {
|
|
2047
|
-
throw error;
|
|
2048
|
-
}
|
|
2049
|
-
if (script.includes(undefinedName + '(')) {
|
|
2050
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2051
|
-
}
|
|
2052
|
-
else {
|
|
2053
|
-
variables.add(undefinedName);
|
|
2054
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
catch (error) {
|
|
2059
|
-
if (!(error instanceof Error)) {
|
|
2060
|
-
throw error;
|
|
2061
|
-
}
|
|
2062
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
2063
|
-
}
|
|
2064
|
-
return variables;
|
|
2065
|
-
}
|
|
2066
|
-
/**
|
|
2067
|
-
* TODO: [๐ฃ] Support for multiple languages - python, java,...
|
|
2068
|
-
*/
|
|
2069
|
-
|
|
2070
|
-
/**
|
|
2071
|
-
* Parses the template and returns the set of all used parameters
|
|
2072
|
-
*
|
|
2073
|
-
* @param template the template with used parameters
|
|
2074
|
-
* @returns the set of parameter names
|
|
2075
|
-
* @throws {ParseError} if the script is invalid
|
|
2076
|
-
* @public exported from `@promptbook/utils`
|
|
2077
|
-
*/
|
|
2078
|
-
function extractParameterNamesFromTemplate(template) {
|
|
2079
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
2080
|
-
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
|
|
2081
|
-
var parameterNames = new Set();
|
|
2082
|
-
try {
|
|
2083
|
-
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()) {
|
|
2084
|
-
var parameterName = _e.value;
|
|
2085
|
-
parameterNames.add(parameterName);
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2089
|
-
finally {
|
|
2090
|
-
try {
|
|
2091
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2092
|
-
}
|
|
2093
|
-
finally { if (e_1) throw e_1.error; }
|
|
2094
|
-
}
|
|
2095
|
-
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
2096
|
-
try {
|
|
2097
|
-
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2098
|
-
var parameterName = _g.value;
|
|
2099
|
-
parameterNames.add(parameterName);
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2103
|
-
finally {
|
|
2104
|
-
try {
|
|
2105
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2106
|
-
}
|
|
2107
|
-
finally { if (e_2) throw e_2.error; }
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
try {
|
|
2111
|
-
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
2112
|
-
var jokerName = _j.value;
|
|
2113
|
-
parameterNames.add(jokerName);
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2117
|
-
finally {
|
|
2118
|
-
try {
|
|
2119
|
-
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
2120
|
-
}
|
|
2121
|
-
finally { if (e_3) throw e_3.error; }
|
|
2122
|
-
}
|
|
2123
|
-
parameterNames.delete('content');
|
|
2124
|
-
// <- Note {websiteContent} is used in `preparedContent`
|
|
2125
|
-
return parameterNames;
|
|
2126
|
-
}
|
|
2127
|
-
/**
|
|
2128
|
-
* TODO: [๐ฃ] If script require contentLanguage
|
|
2129
|
-
*/
|
|
2130
|
-
|
|
2131
2050
|
/**
|
|
2132
2051
|
* Serializes an error into a [๐] JSON-serializable object
|
|
2133
2052
|
*
|
|
@@ -2145,27 +2064,6 @@ function serializeError(error) {
|
|
|
2145
2064
|
};
|
|
2146
2065
|
}
|
|
2147
2066
|
|
|
2148
|
-
/**
|
|
2149
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2150
|
-
*
|
|
2151
|
-
* @public exported from `@promptbook/utils`
|
|
2152
|
-
*/
|
|
2153
|
-
function isValidJsonString(value /* <- [๐จโโ๏ธ] */) {
|
|
2154
|
-
try {
|
|
2155
|
-
JSON.parse(value);
|
|
2156
|
-
return true;
|
|
2157
|
-
}
|
|
2158
|
-
catch (error) {
|
|
2159
|
-
if (!(error instanceof Error)) {
|
|
2160
|
-
throw error;
|
|
2161
|
-
}
|
|
2162
|
-
if (error.message.includes('Unexpected token')) {
|
|
2163
|
-
return false;
|
|
2164
|
-
}
|
|
2165
|
-
return false;
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
2067
|
/**
|
|
2170
2068
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2171
2069
|
*
|
|
@@ -2460,171 +2358,310 @@ function joinLlmExecutionTools() {
|
|
|
2460
2358
|
*/
|
|
2461
2359
|
|
|
2462
2360
|
/**
|
|
2463
|
-
*
|
|
2464
|
-
*
|
|
2465
|
-
* Note: There are multiple simmilar function:
|
|
2466
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2467
|
-
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2468
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2469
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2361
|
+
* Determine if the pipeline is fully prepared
|
|
2470
2362
|
*
|
|
2471
|
-
* @
|
|
2472
|
-
* @returns code blocks with language and content
|
|
2473
|
-
* @throws {ParseError} if block is not closed properly
|
|
2474
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
2363
|
+
* @public exported from `@promptbook/core`
|
|
2475
2364
|
*/
|
|
2476
|
-
function
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
lines.push('');
|
|
2482
|
-
var currentCodeBlock = null;
|
|
2483
|
-
try {
|
|
2484
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2485
|
-
var line = lines_1_1.value;
|
|
2486
|
-
if (line.startsWith('> ') || line === '>') {
|
|
2487
|
-
if (currentCodeBlock === null) {
|
|
2488
|
-
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2489
|
-
} /* not else */
|
|
2490
|
-
if (currentCodeBlock.blockNotation === '>') {
|
|
2491
|
-
if (currentCodeBlock.content !== '') {
|
|
2492
|
-
currentCodeBlock.content += '\n';
|
|
2493
|
-
}
|
|
2494
|
-
currentCodeBlock.content += line.slice(2);
|
|
2495
|
-
}
|
|
2496
|
-
}
|
|
2497
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2498
|
-
codeBlocks.push(currentCodeBlock);
|
|
2499
|
-
currentCodeBlock = null;
|
|
2500
|
-
}
|
|
2501
|
-
/* not else */
|
|
2502
|
-
if (line.startsWith('```')) {
|
|
2503
|
-
var language = line.slice(3).trim() || null;
|
|
2504
|
-
if (currentCodeBlock === null) {
|
|
2505
|
-
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2506
|
-
}
|
|
2507
|
-
else {
|
|
2508
|
-
if (language !== null) {
|
|
2509
|
-
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2510
|
-
}
|
|
2511
|
-
codeBlocks.push(currentCodeBlock);
|
|
2512
|
-
currentCodeBlock = null;
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2516
|
-
if (currentCodeBlock.content !== '') {
|
|
2517
|
-
currentCodeBlock.content += '\n';
|
|
2518
|
-
}
|
|
2519
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2524
|
-
finally {
|
|
2525
|
-
try {
|
|
2526
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2527
|
-
}
|
|
2528
|
-
finally { if (e_1) throw e_1.error; }
|
|
2365
|
+
function isPipelinePrepared(pipeline) {
|
|
2366
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2367
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2368
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2369
|
+
return false;
|
|
2529
2370
|
}
|
|
2530
|
-
if (
|
|
2531
|
-
|
|
2371
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2372
|
+
return false;
|
|
2532
2373
|
}
|
|
2533
|
-
|
|
2374
|
+
/*
|
|
2375
|
+
TODO: [๐ง ][๐ซ] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2376
|
+
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2377
|
+
> return false;
|
|
2378
|
+
> }
|
|
2379
|
+
*/
|
|
2380
|
+
return true;
|
|
2534
2381
|
}
|
|
2535
2382
|
/**
|
|
2536
|
-
* TODO:
|
|
2383
|
+
* TODO: [๐] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2384
|
+
* TODO: [๐ ] Maybe base this on `makeValidator`
|
|
2385
|
+
* TODO: [๐ง] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2386
|
+
* TODO: [๐งฟ] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2387
|
+
* - [๐] ? Is context in each template
|
|
2388
|
+
* - [โจ] Are samples prepared
|
|
2389
|
+
* - [โจ] Are templates prepared
|
|
2537
2390
|
*/
|
|
2538
2391
|
|
|
2539
2392
|
/**
|
|
2540
|
-
*
|
|
2541
|
-
*
|
|
2542
|
-
* - When given string is a valid JSON as it is, it just returns it
|
|
2543
|
-
* - When there is no JSON code block the function throws a `ParseError`
|
|
2544
|
-
* - When there are multiple JSON code blocks the function throws a `ParseError`
|
|
2393
|
+
* Takes an item or an array of items and returns an array of items
|
|
2545
2394
|
*
|
|
2546
|
-
*
|
|
2547
|
-
*
|
|
2548
|
-
*
|
|
2549
|
-
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2550
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2551
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
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
|
|
2552
2398
|
*
|
|
2553
|
-
* @
|
|
2554
|
-
* @throws {ParseError} if there is no valid JSON block in the markdown
|
|
2399
|
+
* @private internal utility
|
|
2555
2400
|
*/
|
|
2556
|
-
function
|
|
2557
|
-
if (
|
|
2558
|
-
return
|
|
2401
|
+
function arrayableToArray(input) {
|
|
2402
|
+
if (input === undefined) {
|
|
2403
|
+
return [];
|
|
2559
2404
|
}
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
var content = _a.content;
|
|
2563
|
-
return isValidJsonString(content);
|
|
2564
|
-
});
|
|
2565
|
-
if (jsonBlocks.length === 0) {
|
|
2566
|
-
throw new Error('There is no valid JSON block in the markdown');
|
|
2405
|
+
if (input instanceof Array) {
|
|
2406
|
+
return input;
|
|
2567
2407
|
}
|
|
2568
|
-
|
|
2569
|
-
|
|
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
|
+
}
|
|
2570
2447
|
}
|
|
2571
|
-
|
|
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;
|
|
2572
2455
|
}
|
|
2573
2456
|
/**
|
|
2574
|
-
* TODO:
|
|
2575
|
-
* TODO: [๐ข] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2457
|
+
* TODO: [๐ฃ] Support for multiple languages - python, java,...
|
|
2576
2458
|
*/
|
|
2577
2459
|
|
|
2578
2460
|
/**
|
|
2579
|
-
*
|
|
2461
|
+
* Parses the template and returns the set of all used parameters
|
|
2580
2462
|
*
|
|
2581
|
-
* @
|
|
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`
|
|
2582
2467
|
*/
|
|
2583
|
-
function
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
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
|
+
}
|
|
2588
2477
|
}
|
|
2589
|
-
|
|
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
|
+
}
|
|
2590
2546
|
return false;
|
|
2591
2547
|
}
|
|
2592
|
-
/*
|
|
2593
|
-
TODO: [๐ง ][๐ซ] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2594
|
-
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2595
|
-
> return false;
|
|
2596
|
-
> }
|
|
2597
|
-
*/
|
|
2598
|
-
return true;
|
|
2599
2548
|
}
|
|
2549
|
+
|
|
2600
2550
|
/**
|
|
2601
|
-
*
|
|
2602
|
-
*
|
|
2603
|
-
*
|
|
2604
|
-
*
|
|
2605
|
-
*
|
|
2606
|
-
*
|
|
2607
|
-
*
|
|
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 '>'
|
|
2608
2625
|
*/
|
|
2609
2626
|
|
|
2610
2627
|
/**
|
|
2611
|
-
*
|
|
2628
|
+
* Extracts extracts exactly one valid JSON code block
|
|
2612
2629
|
*
|
|
2613
|
-
*
|
|
2614
|
-
*
|
|
2615
|
-
*
|
|
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`
|
|
2632
|
+
* - When there are multiple JSON code blocks the function throws a `ParseError`
|
|
2616
2633
|
*
|
|
2617
|
-
*
|
|
2634
|
+
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
2635
|
+
* Note: There are multiple simmilar function:
|
|
2636
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2637
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2638
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2639
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2640
|
+
*
|
|
2641
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2642
|
+
* @throws {ParseError} if there is no valid JSON block in the markdown
|
|
2618
2643
|
*/
|
|
2619
|
-
function
|
|
2620
|
-
if (
|
|
2621
|
-
return
|
|
2644
|
+
function extractJsonBlock(markdown) {
|
|
2645
|
+
if (isValidJsonString(markdown)) {
|
|
2646
|
+
return markdown;
|
|
2622
2647
|
}
|
|
2623
|
-
|
|
2624
|
-
|
|
2648
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2649
|
+
var jsonBlocks = codeBlocks.filter(function (_a) {
|
|
2650
|
+
var content = _a.content;
|
|
2651
|
+
return isValidJsonString(content);
|
|
2652
|
+
});
|
|
2653
|
+
if (jsonBlocks.length === 0) {
|
|
2654
|
+
throw new Error('There is no valid JSON block in the markdown');
|
|
2625
2655
|
}
|
|
2626
|
-
|
|
2656
|
+
if (jsonBlocks.length > 1) {
|
|
2657
|
+
throw new Error('There are multiple JSON code blocks in the markdown');
|
|
2658
|
+
}
|
|
2659
|
+
return jsonBlocks[0].content;
|
|
2627
2660
|
}
|
|
2661
|
+
/**
|
|
2662
|
+
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
2663
|
+
* TODO: [๐ข] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2664
|
+
*/
|
|
2628
2665
|
|
|
2629
2666
|
/**
|
|
2630
2667
|
* Just says that the variable is not used but should be kept
|
|
@@ -2647,23 +2684,6 @@ function keepUnused() {
|
|
|
2647
2684
|
}
|
|
2648
2685
|
}
|
|
2649
2686
|
|
|
2650
|
-
/**
|
|
2651
|
-
* Just marks a place of place where should be something implemented
|
|
2652
|
-
* No side effects.
|
|
2653
|
-
*
|
|
2654
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2655
|
-
*
|
|
2656
|
-
* @param value any values
|
|
2657
|
-
* @returns void
|
|
2658
|
-
* @private within the repository
|
|
2659
|
-
*/
|
|
2660
|
-
function TODO_USE() {
|
|
2661
|
-
var value = [];
|
|
2662
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2663
|
-
value[_i] = arguments[_i];
|
|
2664
|
-
}
|
|
2665
|
-
}
|
|
2666
|
-
|
|
2667
2687
|
/**
|
|
2668
2688
|
* Replaces parameters in template with values from parameters object
|
|
2669
2689
|
*
|
|
@@ -2875,62 +2895,655 @@ function splitIntoSentences(text) {
|
|
|
2875
2895
|
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
2876
2896
|
}
|
|
2877
2897
|
/**
|
|
2878
|
-
* Counts number of sentences in the text
|
|
2879
|
-
*
|
|
2880
|
-
* @public exported from `@promptbook/utils`
|
|
2898
|
+
* Counts number of sentences in the text
|
|
2899
|
+
*
|
|
2900
|
+
* @public exported from `@promptbook/utils`
|
|
2901
|
+
*/
|
|
2902
|
+
function countSentences(text) {
|
|
2903
|
+
return splitIntoSentences(text).length;
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2906
|
+
/**
|
|
2907
|
+
* Counts number of words in the text
|
|
2908
|
+
*
|
|
2909
|
+
* @public exported from `@promptbook/utils`
|
|
2910
|
+
*/
|
|
2911
|
+
function countWords(text) {
|
|
2912
|
+
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
2913
|
+
text = removeDiacritics(text);
|
|
2914
|
+
return text.split(/[^a-zะฐ-ั0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
2915
|
+
}
|
|
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
|
+
* @private @@@
|
|
2987
|
+
*/
|
|
2988
|
+
function getContextForTemplate(template) {
|
|
2989
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2990
|
+
return __generator(this, function (_a) {
|
|
2991
|
+
TODO_USE(template);
|
|
2992
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [๐] Implement */];
|
|
2993
|
+
});
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2996
|
+
|
|
2997
|
+
/**
|
|
2998
|
+
* @private @@@
|
|
2999
|
+
*/
|
|
3000
|
+
function getKnowledgeForTemplate(preparedPipeline, template) {
|
|
3001
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3002
|
+
return __generator(this, function (_a) {
|
|
3003
|
+
// TODO: [โจ] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3004
|
+
TODO_USE(template);
|
|
3005
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3006
|
+
var content = _a.content;
|
|
3007
|
+
return "- ".concat(content);
|
|
3008
|
+
}).join('\n')];
|
|
3009
|
+
});
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
|
|
3013
|
+
/**
|
|
3014
|
+
* @private @@@
|
|
3015
|
+
*/
|
|
3016
|
+
function getSamplesForTemplate(template) {
|
|
3017
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3018
|
+
return __generator(this, function (_a) {
|
|
3019
|
+
// TODO: [โจ] Implement Better - use real index and keyword search
|
|
3020
|
+
TODO_USE(template);
|
|
3021
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [โจ] Implement */];
|
|
3022
|
+
});
|
|
3023
|
+
});
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
/**
|
|
3027
|
+
* @private @@@
|
|
2881
3028
|
*/
|
|
2882
|
-
function
|
|
2883
|
-
return
|
|
3029
|
+
function getReservedParametersForTemplate(preparedPipeline, template, pipelineIdentification) {
|
|
3030
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3031
|
+
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3032
|
+
var e_1, _a;
|
|
3033
|
+
return __generator(this, function (_b) {
|
|
3034
|
+
switch (_b.label) {
|
|
3035
|
+
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
3036
|
+
case 1:
|
|
3037
|
+
context = _b.sent();
|
|
3038
|
+
return [4 /*yield*/, getKnowledgeForTemplate(preparedPipeline, template)];
|
|
3039
|
+
case 2:
|
|
3040
|
+
knowledge = _b.sent();
|
|
3041
|
+
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3042
|
+
case 3:
|
|
3043
|
+
samples = _b.sent();
|
|
3044
|
+
currentDate = new Date().toISOString();
|
|
3045
|
+
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3046
|
+
reservedParameters = {
|
|
3047
|
+
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3048
|
+
context: context,
|
|
3049
|
+
knowledge: knowledge,
|
|
3050
|
+
samples: samples,
|
|
3051
|
+
currentDate: currentDate,
|
|
3052
|
+
modelName: modelName,
|
|
3053
|
+
};
|
|
3054
|
+
_loop_1 = function (parameterName) {
|
|
3055
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
3056
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3057
|
+
}
|
|
3058
|
+
};
|
|
3059
|
+
try {
|
|
3060
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3061
|
+
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()) {
|
|
3062
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3063
|
+
_loop_1(parameterName);
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3067
|
+
finally {
|
|
3068
|
+
try {
|
|
3069
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3070
|
+
}
|
|
3071
|
+
finally { if (e_1) throw e_1.error; }
|
|
3072
|
+
}
|
|
3073
|
+
return [2 /*return*/, reservedParameters];
|
|
3074
|
+
}
|
|
3075
|
+
});
|
|
3076
|
+
});
|
|
2884
3077
|
}
|
|
2885
3078
|
|
|
2886
3079
|
/**
|
|
2887
|
-
*
|
|
2888
|
-
*
|
|
2889
|
-
* @public exported from `@promptbook/utils`
|
|
3080
|
+
* @private @@@
|
|
2890
3081
|
*/
|
|
2891
|
-
function
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
3082
|
+
function executeSingleTemplate(options) {
|
|
3083
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3084
|
+
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress, maxExecutionAttempts, $executionReport, pipelineIdentification, 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;
|
|
3085
|
+
var e_1, _f, _g;
|
|
3086
|
+
return __generator(this, function (_h) {
|
|
3087
|
+
switch (_h.label) {
|
|
3088
|
+
case 0:
|
|
3089
|
+
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress, maxExecutionAttempts = options.maxExecutionAttempts, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
|
|
3090
|
+
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3091
|
+
title = currentTemplate.title;
|
|
3092
|
+
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3093
|
+
return [4 /*yield*/, onProgress({
|
|
3094
|
+
name: name,
|
|
3095
|
+
title: title,
|
|
3096
|
+
isStarted: false,
|
|
3097
|
+
isDone: false,
|
|
3098
|
+
templateType: currentTemplate.templateType,
|
|
3099
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
3100
|
+
parameterValue: null,
|
|
3101
|
+
// <- [๐ธ]
|
|
3102
|
+
})];
|
|
3103
|
+
case 1:
|
|
3104
|
+
_h.sent();
|
|
3105
|
+
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3106
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3107
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3108
|
+
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)
|
|
3109
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3110
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3111
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3112
|
+
.join(', '), "\n\n "); }));
|
|
3113
|
+
}
|
|
3114
|
+
_b = (_a = Object).freeze;
|
|
3115
|
+
_c = [{}];
|
|
3116
|
+
return [4 /*yield*/, getReservedParametersForTemplate(preparedPipeline, currentTemplate, pipelineIdentification)];
|
|
3117
|
+
case 2:
|
|
3118
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3119
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3120
|
+
parameters = {};
|
|
3121
|
+
_loop_1 = function (parameterName) {
|
|
3122
|
+
// Situation: Parameter is defined and used
|
|
3123
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3124
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
3125
|
+
}
|
|
3126
|
+
// Situation: Parameter is defined but NOT used
|
|
3127
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3128
|
+
// Situation: Parameter is NOT defined BUT used
|
|
3129
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3130
|
+
// Houston, we have a problem
|
|
3131
|
+
// Note: Checking part is also done in `validatePipeline`, but itโs good to doublecheck
|
|
3132
|
+
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 "); }));
|
|
3133
|
+
}
|
|
3134
|
+
};
|
|
3135
|
+
try {
|
|
3136
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3137
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3138
|
+
parameterName = _e.value;
|
|
3139
|
+
_loop_1(parameterName);
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3143
|
+
finally {
|
|
3144
|
+
try {
|
|
3145
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3146
|
+
}
|
|
3147
|
+
finally { if (e_1) throw e_1.error; }
|
|
3148
|
+
}
|
|
3149
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3150
|
+
Object.freeze(parameters);
|
|
3151
|
+
result = null;
|
|
3152
|
+
resultString = null;
|
|
3153
|
+
expectError = null;
|
|
3154
|
+
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3155
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3156
|
+
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3157
|
+
.split('{content}')
|
|
3158
|
+
.join(currentTemplate.content);
|
|
3159
|
+
_loop_2 = function (attempt) {
|
|
3160
|
+
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;
|
|
3161
|
+
var e_2, _s, e_4, _t, e_3, _u;
|
|
3162
|
+
return __generator(this, function (_v) {
|
|
3163
|
+
switch (_v.label) {
|
|
3164
|
+
case 0:
|
|
3165
|
+
isJokerAttempt = attempt < 0;
|
|
3166
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3167
|
+
// TODO: [๐ง ] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3168
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
3169
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3170
|
+
}
|
|
3171
|
+
result = null;
|
|
3172
|
+
resultString = null;
|
|
3173
|
+
expectError = null;
|
|
3174
|
+
if (isJokerAttempt) {
|
|
3175
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
3176
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3177
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3178
|
+
}
|
|
3179
|
+
else {
|
|
3180
|
+
resultString = parameters[jokerParameterName];
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
_v.label = 1;
|
|
3184
|
+
case 1:
|
|
3185
|
+
_v.trys.push([1, 44, 45, 46]);
|
|
3186
|
+
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3187
|
+
_j = currentTemplate.templateType;
|
|
3188
|
+
switch (_j) {
|
|
3189
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3190
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3191
|
+
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
3192
|
+
case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
|
|
3193
|
+
}
|
|
3194
|
+
return [3 /*break*/, 25];
|
|
3195
|
+
case 2:
|
|
3196
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
3197
|
+
return [3 /*break*/, 26];
|
|
3198
|
+
case 3:
|
|
3199
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
|
|
3200
|
+
prompt = {
|
|
3201
|
+
title: currentTemplate.title,
|
|
3202
|
+
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3203
|
+
? preparedPipeline.pipelineUrl
|
|
3204
|
+
: 'anonymous' /* <- TODO: [๐ง ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3205
|
+
parameters: parameters,
|
|
3206
|
+
content: preparedContent,
|
|
3207
|
+
modelRequirements: modelRequirements,
|
|
3208
|
+
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3209
|
+
var name = _a.name;
|
|
3210
|
+
return name === currentTemplate.personaName;
|
|
3211
|
+
}) || {})), currentTemplate.expectations),
|
|
3212
|
+
format: currentTemplate.format,
|
|
3213
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3214
|
+
}; // <- TODO: Not very good type guard
|
|
3215
|
+
_k = modelRequirements.modelVariant;
|
|
3216
|
+
switch (_k) {
|
|
3217
|
+
case 'CHAT': return [3 /*break*/, 4];
|
|
3218
|
+
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3219
|
+
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3220
|
+
}
|
|
3221
|
+
return [3 /*break*/, 10];
|
|
3222
|
+
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3223
|
+
case 5:
|
|
3224
|
+
chatResult = _v.sent();
|
|
3225
|
+
// TODO: [๐ฌ] Destroy chatThread
|
|
3226
|
+
result = chatResult;
|
|
3227
|
+
resultString = chatResult.content;
|
|
3228
|
+
return [3 /*break*/, 11];
|
|
3229
|
+
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3230
|
+
case 7:
|
|
3231
|
+
completionResult = _v.sent();
|
|
3232
|
+
result = completionResult;
|
|
3233
|
+
resultString = completionResult.content;
|
|
3234
|
+
return [3 /*break*/, 11];
|
|
3235
|
+
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3236
|
+
case 9:
|
|
3237
|
+
// TODO: [๐ง ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3238
|
+
embeddingResult = _v.sent();
|
|
3239
|
+
result = embeddingResult;
|
|
3240
|
+
resultString = embeddingResult.content.join(',');
|
|
3241
|
+
return [3 /*break*/, 11];
|
|
3242
|
+
case 10: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3243
|
+
case 11: return [3 /*break*/, 26];
|
|
3244
|
+
case 12:
|
|
3245
|
+
if (arrayableToArray(tools.script).length === 0) {
|
|
3246
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3247
|
+
}
|
|
3248
|
+
if (!currentTemplate.contentLanguage) {
|
|
3249
|
+
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 "); }));
|
|
3250
|
+
}
|
|
3251
|
+
// TODO: DRY [1]
|
|
3252
|
+
scriptPipelineExecutionErrors = [];
|
|
3253
|
+
_v.label = 13;
|
|
3254
|
+
case 13:
|
|
3255
|
+
_v.trys.push([13, 20, 21, 22]);
|
|
3256
|
+
_l = (e_2 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3257
|
+
_v.label = 14;
|
|
3258
|
+
case 14:
|
|
3259
|
+
if (!!_m.done) return [3 /*break*/, 19];
|
|
3260
|
+
scriptTools = _m.value;
|
|
3261
|
+
_v.label = 15;
|
|
3262
|
+
case 15:
|
|
3263
|
+
_v.trys.push([15, 17, , 18]);
|
|
3264
|
+
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3265
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
3266
|
+
script: preparedContent,
|
|
3267
|
+
parameters: parameters,
|
|
3268
|
+
}))];
|
|
3269
|
+
case 16:
|
|
3270
|
+
resultString = _v.sent();
|
|
3271
|
+
return [3 /*break*/, 19];
|
|
3272
|
+
case 17:
|
|
3273
|
+
error_1 = _v.sent();
|
|
3274
|
+
if (!(error_1 instanceof Error)) {
|
|
3275
|
+
throw error_1;
|
|
3276
|
+
}
|
|
3277
|
+
if (error_1 instanceof UnexpectedError) {
|
|
3278
|
+
throw error_1;
|
|
3279
|
+
}
|
|
3280
|
+
scriptPipelineExecutionErrors.push(error_1);
|
|
3281
|
+
return [3 /*break*/, 18];
|
|
3282
|
+
case 18:
|
|
3283
|
+
_m = _l.next();
|
|
3284
|
+
return [3 /*break*/, 14];
|
|
3285
|
+
case 19: return [3 /*break*/, 22];
|
|
3286
|
+
case 20:
|
|
3287
|
+
e_2_1 = _v.sent();
|
|
3288
|
+
e_2 = { error: e_2_1 };
|
|
3289
|
+
return [3 /*break*/, 22];
|
|
3290
|
+
case 21:
|
|
3291
|
+
try {
|
|
3292
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3293
|
+
}
|
|
3294
|
+
finally { if (e_2) throw e_2.error; }
|
|
3295
|
+
return [7 /*endfinally*/];
|
|
3296
|
+
case 22:
|
|
3297
|
+
if (resultString !== null) {
|
|
3298
|
+
return [3 /*break*/, 26];
|
|
3299
|
+
}
|
|
3300
|
+
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3301
|
+
throw scriptPipelineExecutionErrors[0];
|
|
3302
|
+
}
|
|
3303
|
+
else {
|
|
3304
|
+
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
|
|
3305
|
+
.map(function (error) { return '- ' + error.message; })
|
|
3306
|
+
.join('\n\n')), "\n "); }));
|
|
3307
|
+
}
|
|
3308
|
+
case 23:
|
|
3309
|
+
if (tools.userInterface === undefined) {
|
|
3310
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3311
|
+
}
|
|
3312
|
+
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3313
|
+
promptTitle: currentTemplate.title,
|
|
3314
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3315
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3316
|
+
// TODO: [๐ง ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3317
|
+
placeholder: undefined,
|
|
3318
|
+
priority: priority,
|
|
3319
|
+
}))];
|
|
3320
|
+
case 24:
|
|
3321
|
+
// TODO: [๐น] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3322
|
+
resultString = _v.sent();
|
|
3323
|
+
return [3 /*break*/, 26];
|
|
3324
|
+
case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3325
|
+
case 26:
|
|
3326
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3327
|
+
_v.label = 27;
|
|
3328
|
+
case 27:
|
|
3329
|
+
_v.trys.push([27, 41, 42, 43]);
|
|
3330
|
+
_o = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3331
|
+
_v.label = 28;
|
|
3332
|
+
case 28:
|
|
3333
|
+
if (!!_p.done) return [3 /*break*/, 40];
|
|
3334
|
+
functionName = _p.value;
|
|
3335
|
+
// TODO: DRY [1]
|
|
3336
|
+
scriptPipelineExecutionErrors = [];
|
|
3337
|
+
postprocessingError = null;
|
|
3338
|
+
_v.label = 29;
|
|
3339
|
+
case 29:
|
|
3340
|
+
_v.trys.push([29, 36, 37, 38]);
|
|
3341
|
+
_q = (e_3 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3342
|
+
_v.label = 30;
|
|
3343
|
+
case 30:
|
|
3344
|
+
if (!!_r.done) return [3 /*break*/, 35];
|
|
3345
|
+
scriptTools = _r.value;
|
|
3346
|
+
_v.label = 31;
|
|
3347
|
+
case 31:
|
|
3348
|
+
_v.trys.push([31, 33, , 34]);
|
|
3349
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
3350
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3351
|
+
script: "".concat(functionName, "(resultString)"),
|
|
3352
|
+
parameters: {
|
|
3353
|
+
resultString: resultString || '',
|
|
3354
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
3355
|
+
},
|
|
3356
|
+
})];
|
|
3357
|
+
case 32:
|
|
3358
|
+
resultString = _v.sent();
|
|
3359
|
+
postprocessingError = null;
|
|
3360
|
+
return [3 /*break*/, 35];
|
|
3361
|
+
case 33:
|
|
3362
|
+
error_2 = _v.sent();
|
|
3363
|
+
if (!(error_2 instanceof Error)) {
|
|
3364
|
+
throw error_2;
|
|
3365
|
+
}
|
|
3366
|
+
if (error_2 instanceof UnexpectedError) {
|
|
3367
|
+
throw error_2;
|
|
3368
|
+
}
|
|
3369
|
+
postprocessingError = error_2;
|
|
3370
|
+
scriptPipelineExecutionErrors.push(error_2);
|
|
3371
|
+
return [3 /*break*/, 34];
|
|
3372
|
+
case 34:
|
|
3373
|
+
_r = _q.next();
|
|
3374
|
+
return [3 /*break*/, 30];
|
|
3375
|
+
case 35: return [3 /*break*/, 38];
|
|
3376
|
+
case 36:
|
|
3377
|
+
e_3_1 = _v.sent();
|
|
3378
|
+
e_3 = { error: e_3_1 };
|
|
3379
|
+
return [3 /*break*/, 38];
|
|
3380
|
+
case 37:
|
|
3381
|
+
try {
|
|
3382
|
+
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3383
|
+
}
|
|
3384
|
+
finally { if (e_3) throw e_3.error; }
|
|
3385
|
+
return [7 /*endfinally*/];
|
|
3386
|
+
case 38:
|
|
3387
|
+
if (postprocessingError) {
|
|
3388
|
+
throw postprocessingError;
|
|
3389
|
+
}
|
|
3390
|
+
_v.label = 39;
|
|
3391
|
+
case 39:
|
|
3392
|
+
_p = _o.next();
|
|
3393
|
+
return [3 /*break*/, 28];
|
|
3394
|
+
case 40: return [3 /*break*/, 43];
|
|
3395
|
+
case 41:
|
|
3396
|
+
e_4_1 = _v.sent();
|
|
3397
|
+
e_4 = { error: e_4_1 };
|
|
3398
|
+
return [3 /*break*/, 43];
|
|
3399
|
+
case 42:
|
|
3400
|
+
try {
|
|
3401
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3402
|
+
}
|
|
3403
|
+
finally { if (e_4) throw e_4.error; }
|
|
3404
|
+
return [7 /*endfinally*/];
|
|
3405
|
+
case 43:
|
|
3406
|
+
// TODO: [๐] Unite object for expecting amount and format
|
|
3407
|
+
if (currentTemplate.format) {
|
|
3408
|
+
if (currentTemplate.format === 'JSON') {
|
|
3409
|
+
if (!isValidJsonString(resultString || '')) {
|
|
3410
|
+
// TODO: [๐ข] Do more universally via `FormatDefinition`
|
|
3411
|
+
try {
|
|
3412
|
+
resultString = extractJsonBlock(resultString || '');
|
|
3413
|
+
}
|
|
3414
|
+
catch (error) {
|
|
3415
|
+
keepUnused(error);
|
|
3416
|
+
throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3417
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
else {
|
|
3422
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
// TODO: [๐] Unite object for expecting amount and format
|
|
3426
|
+
if (currentTemplate.expectations) {
|
|
3427
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3428
|
+
}
|
|
3429
|
+
return [2 /*return*/, "break-attempts"];
|
|
3430
|
+
case 44:
|
|
3431
|
+
error_3 = _v.sent();
|
|
3432
|
+
if (!(error_3 instanceof ExpectError)) {
|
|
3433
|
+
throw error_3;
|
|
3434
|
+
}
|
|
3435
|
+
expectError = error_3;
|
|
3436
|
+
return [3 /*break*/, 46];
|
|
3437
|
+
case 45:
|
|
3438
|
+
if (!isJokerAttempt &&
|
|
3439
|
+
currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
|
|
3440
|
+
prompt
|
|
3441
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3442
|
+
// In that case we donโt want to make a report about it because itโs not a llm execution error
|
|
3443
|
+
) {
|
|
3444
|
+
// TODO: [๐ง ] Maybe put other templateTypes into report
|
|
3445
|
+
$executionReport.promptExecutions.push({
|
|
3446
|
+
prompt: __assign({}, prompt),
|
|
3447
|
+
result: result || undefined,
|
|
3448
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3449
|
+
});
|
|
3450
|
+
}
|
|
3451
|
+
return [7 /*endfinally*/];
|
|
3452
|
+
case 46:
|
|
3453
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3454
|
+
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
|
|
3455
|
+
.split('\n')
|
|
3456
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3457
|
+
.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) || '')
|
|
3458
|
+
.split('\n')
|
|
3459
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3460
|
+
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3461
|
+
? 'null'
|
|
3462
|
+
: resultString
|
|
3463
|
+
.split('\n')
|
|
3464
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3465
|
+
.join('\n')), "\n ---\n "); }));
|
|
3466
|
+
}
|
|
3467
|
+
return [2 /*return*/];
|
|
3468
|
+
}
|
|
3469
|
+
});
|
|
3470
|
+
};
|
|
3471
|
+
attempt = -jokerParameterNames.length;
|
|
3472
|
+
_h.label = 3;
|
|
3473
|
+
case 3:
|
|
3474
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 6];
|
|
3475
|
+
return [5 /*yield**/, _loop_2(attempt)];
|
|
3476
|
+
case 4:
|
|
3477
|
+
state_1 = _h.sent();
|
|
3478
|
+
switch (state_1) {
|
|
3479
|
+
case "break-attempts": return [3 /*break*/, 6];
|
|
3480
|
+
}
|
|
3481
|
+
_h.label = 5;
|
|
3482
|
+
case 5:
|
|
3483
|
+
attempt++;
|
|
3484
|
+
return [3 /*break*/, 3];
|
|
3485
|
+
case 6:
|
|
3486
|
+
//------------------------------------
|
|
3487
|
+
/*
|
|
3488
|
+
|
|
3489
|
+
|
|
3490
|
+
|
|
3491
|
+
|
|
3492
|
+
|
|
3493
|
+
|
|
3494
|
+
|
|
3495
|
+
|
|
3496
|
+
|
|
3497
|
+
*/
|
|
3498
|
+
//------------------------------------
|
|
3499
|
+
if (resultString === null) {
|
|
3500
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3501
|
+
}
|
|
3502
|
+
return [4 /*yield*/, onProgress({
|
|
3503
|
+
name: name,
|
|
3504
|
+
title: title,
|
|
3505
|
+
isStarted: true,
|
|
3506
|
+
isDone: true,
|
|
3507
|
+
templateType: currentTemplate.templateType,
|
|
3508
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
3509
|
+
parameterValue: resultString,
|
|
3510
|
+
// <- [๐ธ]
|
|
3511
|
+
})];
|
|
3512
|
+
case 7:
|
|
3513
|
+
_h.sent();
|
|
3514
|
+
return [2 /*return*/, Object.freeze((_g = {},
|
|
3515
|
+
_g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3516
|
+
_g))];
|
|
3517
|
+
}
|
|
3518
|
+
});
|
|
3519
|
+
});
|
|
2895
3520
|
}
|
|
2896
|
-
|
|
2897
3521
|
/**
|
|
2898
|
-
*
|
|
2899
|
-
*
|
|
2900
|
-
* @public exported from `@promptbook/utils`
|
|
3522
|
+
* TODO: [๐คนโโ๏ธ]
|
|
2901
3523
|
*/
|
|
2902
|
-
var CountUtils = {
|
|
2903
|
-
CHARACTERS: countCharacters,
|
|
2904
|
-
WORDS: countWords,
|
|
2905
|
-
SENTENCES: countSentences,
|
|
2906
|
-
PARAGRAPHS: countParagraphs,
|
|
2907
|
-
LINES: countLines,
|
|
2908
|
-
PAGES: countPages,
|
|
2909
|
-
};
|
|
2910
3524
|
|
|
2911
3525
|
/**
|
|
2912
|
-
*
|
|
2913
|
-
*
|
|
2914
|
-
* Note: There are two simmilar functions:
|
|
2915
|
-
* - `checkExpectations` which throws an error if the expectations are not met
|
|
2916
|
-
* - `isPassingExpectations` which returns a boolean
|
|
2917
|
-
*
|
|
2918
|
-
* @throws {ExpectError} if the expectations are not met
|
|
2919
|
-
* @returns {void} Nothing
|
|
2920
|
-
* @private internal function of `createPipelineExecutor`
|
|
3526
|
+
* @private @@@
|
|
2921
3527
|
*/
|
|
2922
|
-
function
|
|
3528
|
+
function filterJustOutputParameters(preparedPipeline, parametersToPass, $warnings, pipelineIdentification) {
|
|
2923
3529
|
var e_1, _a;
|
|
3530
|
+
var outputParameters = {};
|
|
3531
|
+
var _loop_1 = function (parameter) {
|
|
3532
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3533
|
+
// [4]
|
|
3534
|
+
$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 "); })));
|
|
3535
|
+
return "continue";
|
|
3536
|
+
}
|
|
3537
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3538
|
+
};
|
|
2924
3539
|
try {
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
var
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
2933
|
-
}
|
|
3540
|
+
// Note: Filter ONLY output parameters
|
|
3541
|
+
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
3542
|
+
var isOutput = _a.isOutput;
|
|
3543
|
+
return isOutput;
|
|
3544
|
+
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3545
|
+
var parameter = _c.value;
|
|
3546
|
+
_loop_1(parameter);
|
|
2934
3547
|
}
|
|
2935
3548
|
}
|
|
2936
3549
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -2940,10 +3553,8 @@ function checkExpectations(expectations, value) {
|
|
|
2940
3553
|
}
|
|
2941
3554
|
finally { if (e_1) throw e_1.error; }
|
|
2942
3555
|
}
|
|
3556
|
+
return outputParameters;
|
|
2943
3557
|
}
|
|
2944
|
-
/**
|
|
2945
|
-
* TODO: [๐] Unite object for expecting amount and format
|
|
2946
|
-
*/
|
|
2947
3558
|
|
|
2948
3559
|
/**
|
|
2949
3560
|
* Creates executor function from pipeline and execution tools.
|
|
@@ -2977,558 +3588,6 @@ function createPipelineExecutor(options) {
|
|
|
2977
3588
|
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 "); }));
|
|
2978
3589
|
}
|
|
2979
3590
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2980
|
-
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
2981
|
-
function getContextForTemplate(template) {
|
|
2982
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2983
|
-
return __generator(this, function (_a) {
|
|
2984
|
-
TODO_USE(template);
|
|
2985
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [๐] Implement */];
|
|
2986
|
-
});
|
|
2987
|
-
});
|
|
2988
|
-
}
|
|
2989
|
-
function getKnowledgeForTemplate(template) {
|
|
2990
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2991
|
-
return __generator(this, function (_a) {
|
|
2992
|
-
// TODO: [โจ] Implement Better - use real index and keyword search from `template` and {samples}
|
|
2993
|
-
TODO_USE(template);
|
|
2994
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
2995
|
-
var content = _a.content;
|
|
2996
|
-
return "- ".concat(content);
|
|
2997
|
-
}).join('\n')];
|
|
2998
|
-
});
|
|
2999
|
-
});
|
|
3000
|
-
}
|
|
3001
|
-
function getSamplesForTemplate(template) {
|
|
3002
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3003
|
-
return __generator(this, function (_a) {
|
|
3004
|
-
// TODO: [โจ] Implement Better - use real index and keyword search
|
|
3005
|
-
TODO_USE(template);
|
|
3006
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [โจ] Implement */];
|
|
3007
|
-
});
|
|
3008
|
-
});
|
|
3009
|
-
}
|
|
3010
|
-
function getReservedParametersForTemplate(template) {
|
|
3011
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3012
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_3, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3013
|
-
var e_3, _a;
|
|
3014
|
-
return __generator(this, function (_b) {
|
|
3015
|
-
switch (_b.label) {
|
|
3016
|
-
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
3017
|
-
case 1:
|
|
3018
|
-
context = _b.sent();
|
|
3019
|
-
return [4 /*yield*/, getKnowledgeForTemplate(template)];
|
|
3020
|
-
case 2:
|
|
3021
|
-
knowledge = _b.sent();
|
|
3022
|
-
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3023
|
-
case 3:
|
|
3024
|
-
samples = _b.sent();
|
|
3025
|
-
currentDate = new Date().toISOString();
|
|
3026
|
-
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3027
|
-
reservedParameters = {
|
|
3028
|
-
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3029
|
-
context: context,
|
|
3030
|
-
knowledge: knowledge,
|
|
3031
|
-
samples: samples,
|
|
3032
|
-
currentDate: currentDate,
|
|
3033
|
-
modelName: modelName,
|
|
3034
|
-
};
|
|
3035
|
-
_loop_3 = function (parameterName) {
|
|
3036
|
-
if (reservedParameters[parameterName] === undefined) {
|
|
3037
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3038
|
-
}
|
|
3039
|
-
};
|
|
3040
|
-
try {
|
|
3041
|
-
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3042
|
-
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()) {
|
|
3043
|
-
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3044
|
-
_loop_3(parameterName);
|
|
3045
|
-
}
|
|
3046
|
-
}
|
|
3047
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
3048
|
-
finally {
|
|
3049
|
-
try {
|
|
3050
|
-
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3051
|
-
}
|
|
3052
|
-
finally { if (e_3) throw e_3.error; }
|
|
3053
|
-
}
|
|
3054
|
-
return [2 /*return*/, reservedParameters];
|
|
3055
|
-
}
|
|
3056
|
-
});
|
|
3057
|
-
});
|
|
3058
|
-
}
|
|
3059
|
-
function executeSingleTemplate(currentTemplate) {
|
|
3060
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3061
|
-
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;
|
|
3062
|
-
var e_4, _f, _g;
|
|
3063
|
-
return __generator(this, function (_h) {
|
|
3064
|
-
switch (_h.label) {
|
|
3065
|
-
case 0:
|
|
3066
|
-
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3067
|
-
title = currentTemplate.title;
|
|
3068
|
-
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3069
|
-
if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
3070
|
-
progress_1 = {
|
|
3071
|
-
name: name,
|
|
3072
|
-
title: title,
|
|
3073
|
-
isStarted: false,
|
|
3074
|
-
isDone: false,
|
|
3075
|
-
templateType: currentTemplate.templateType,
|
|
3076
|
-
parameterName: currentTemplate.resultingParameterName,
|
|
3077
|
-
parameterValue: null,
|
|
3078
|
-
// <- [3]
|
|
3079
|
-
};
|
|
3080
|
-
if (isReturned) {
|
|
3081
|
-
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)
|
|
3082
|
-
.split('\n')
|
|
3083
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3084
|
-
.join('\n')), "\n "); }));
|
|
3085
|
-
}
|
|
3086
|
-
return [4 /*yield*/, onProgress(progress_1)];
|
|
3087
|
-
case 1:
|
|
3088
|
-
_h.sent();
|
|
3089
|
-
_h.label = 2;
|
|
3090
|
-
case 2:
|
|
3091
|
-
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3092
|
-
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3093
|
-
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3094
|
-
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)
|
|
3095
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3096
|
-
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3097
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3098
|
-
.join(', '), "\n\n "); }));
|
|
3099
|
-
}
|
|
3100
|
-
_b = (_a = Object).freeze;
|
|
3101
|
-
_c = [{}];
|
|
3102
|
-
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
3103
|
-
case 3:
|
|
3104
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3105
|
-
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3106
|
-
parameters = {};
|
|
3107
|
-
_loop_4 = function (parameterName) {
|
|
3108
|
-
// Situation: Parameter is defined and used
|
|
3109
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3110
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3111
|
-
}
|
|
3112
|
-
// Situation: Parameter is defined but NOT used
|
|
3113
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3114
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3115
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3116
|
-
// Houston, we have a problem
|
|
3117
|
-
// Note: Checking part is also done in `validatePipeline`, but itโs good to doublecheck
|
|
3118
|
-
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 "); }));
|
|
3119
|
-
}
|
|
3120
|
-
};
|
|
3121
|
-
try {
|
|
3122
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3123
|
-
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3124
|
-
parameterName = _e.value;
|
|
3125
|
-
_loop_4(parameterName);
|
|
3126
|
-
}
|
|
3127
|
-
}
|
|
3128
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
3129
|
-
finally {
|
|
3130
|
-
try {
|
|
3131
|
-
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3132
|
-
}
|
|
3133
|
-
finally { if (e_4) throw e_4.error; }
|
|
3134
|
-
}
|
|
3135
|
-
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3136
|
-
Object.freeze(parameters);
|
|
3137
|
-
result = null;
|
|
3138
|
-
resultString = null;
|
|
3139
|
-
expectError = null;
|
|
3140
|
-
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3141
|
-
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3142
|
-
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3143
|
-
.split('{content}')
|
|
3144
|
-
.join(currentTemplate.content);
|
|
3145
|
-
_loop_5 = function (attempt) {
|
|
3146
|
-
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;
|
|
3147
|
-
var e_5, _s, e_7, _t, e_6, _u;
|
|
3148
|
-
return __generator(this, function (_v) {
|
|
3149
|
-
switch (_v.label) {
|
|
3150
|
-
case 0:
|
|
3151
|
-
isJokerAttempt = attempt < 0;
|
|
3152
|
-
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3153
|
-
if (isJokerAttempt && !jokerParameterName) {
|
|
3154
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3155
|
-
}
|
|
3156
|
-
result = null;
|
|
3157
|
-
resultString = null;
|
|
3158
|
-
expectError = null;
|
|
3159
|
-
if (isJokerAttempt) {
|
|
3160
|
-
if (parameters[jokerParameterName] === undefined) {
|
|
3161
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3162
|
-
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3163
|
-
}
|
|
3164
|
-
else {
|
|
3165
|
-
resultString = parameters[jokerParameterName];
|
|
3166
|
-
}
|
|
3167
|
-
}
|
|
3168
|
-
_v.label = 1;
|
|
3169
|
-
case 1:
|
|
3170
|
-
_v.trys.push([1, 44, 45, 46]);
|
|
3171
|
-
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3172
|
-
_j = currentTemplate.templateType;
|
|
3173
|
-
switch (_j) {
|
|
3174
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3175
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3176
|
-
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
3177
|
-
case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
|
|
3178
|
-
}
|
|
3179
|
-
return [3 /*break*/, 25];
|
|
3180
|
-
case 2:
|
|
3181
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3182
|
-
return [3 /*break*/, 26];
|
|
3183
|
-
case 3:
|
|
3184
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (pipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
|
|
3185
|
-
prompt = {
|
|
3186
|
-
title: currentTemplate.title,
|
|
3187
|
-
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3188
|
-
? preparedPipeline.pipelineUrl
|
|
3189
|
-
: 'anonymous' /* <- TODO: [๐ง ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3190
|
-
parameters: parameters,
|
|
3191
|
-
content: preparedContent,
|
|
3192
|
-
modelRequirements: modelRequirements,
|
|
3193
|
-
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3194
|
-
var name = _a.name;
|
|
3195
|
-
return name === currentTemplate.personaName;
|
|
3196
|
-
}) || {})), currentTemplate.expectations),
|
|
3197
|
-
format: currentTemplate.format,
|
|
3198
|
-
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3199
|
-
}; // <- TODO: Not very good type guard
|
|
3200
|
-
_k = modelRequirements.modelVariant;
|
|
3201
|
-
switch (_k) {
|
|
3202
|
-
case 'CHAT': return [3 /*break*/, 4];
|
|
3203
|
-
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3204
|
-
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3205
|
-
}
|
|
3206
|
-
return [3 /*break*/, 10];
|
|
3207
|
-
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3208
|
-
case 5:
|
|
3209
|
-
chatResult = _v.sent();
|
|
3210
|
-
// TODO: [๐ฌ] Destroy chatThread
|
|
3211
|
-
result = chatResult;
|
|
3212
|
-
resultString = chatResult.content;
|
|
3213
|
-
return [3 /*break*/, 11];
|
|
3214
|
-
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3215
|
-
case 7:
|
|
3216
|
-
completionResult = _v.sent();
|
|
3217
|
-
result = completionResult;
|
|
3218
|
-
resultString = completionResult.content;
|
|
3219
|
-
return [3 /*break*/, 11];
|
|
3220
|
-
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3221
|
-
case 9:
|
|
3222
|
-
embeddingResult = _v.sent();
|
|
3223
|
-
result = embeddingResult;
|
|
3224
|
-
resultString = embeddingResult.content.join(',');
|
|
3225
|
-
return [3 /*break*/, 11];
|
|
3226
|
-
case 10: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements
|
|
3227
|
-
.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3228
|
-
case 11: return [3 /*break*/, 26];
|
|
3229
|
-
case 12:
|
|
3230
|
-
if (arrayableToArray(tools.script).length === 0) {
|
|
3231
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3232
|
-
}
|
|
3233
|
-
if (!currentTemplate.contentLanguage) {
|
|
3234
|
-
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 "); }));
|
|
3235
|
-
}
|
|
3236
|
-
// TODO: DRY [1]
|
|
3237
|
-
scriptPipelineExecutionErrors = [];
|
|
3238
|
-
_v.label = 13;
|
|
3239
|
-
case 13:
|
|
3240
|
-
_v.trys.push([13, 20, 21, 22]);
|
|
3241
|
-
_l = (e_5 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3242
|
-
_v.label = 14;
|
|
3243
|
-
case 14:
|
|
3244
|
-
if (!!_m.done) return [3 /*break*/, 19];
|
|
3245
|
-
scriptTools = _m.value;
|
|
3246
|
-
_v.label = 15;
|
|
3247
|
-
case 15:
|
|
3248
|
-
_v.trys.push([15, 17, , 18]);
|
|
3249
|
-
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3250
|
-
scriptLanguage: currentTemplate.contentLanguage,
|
|
3251
|
-
script: preparedContent,
|
|
3252
|
-
parameters: parameters,
|
|
3253
|
-
}))];
|
|
3254
|
-
case 16:
|
|
3255
|
-
resultString = _v.sent();
|
|
3256
|
-
return [3 /*break*/, 19];
|
|
3257
|
-
case 17:
|
|
3258
|
-
error_2 = _v.sent();
|
|
3259
|
-
if (!(error_2 instanceof Error)) {
|
|
3260
|
-
throw error_2;
|
|
3261
|
-
}
|
|
3262
|
-
if (error_2 instanceof UnexpectedError) {
|
|
3263
|
-
throw error_2;
|
|
3264
|
-
}
|
|
3265
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3266
|
-
return [3 /*break*/, 18];
|
|
3267
|
-
case 18:
|
|
3268
|
-
_m = _l.next();
|
|
3269
|
-
return [3 /*break*/, 14];
|
|
3270
|
-
case 19: return [3 /*break*/, 22];
|
|
3271
|
-
case 20:
|
|
3272
|
-
e_5_1 = _v.sent();
|
|
3273
|
-
e_5 = { error: e_5_1 };
|
|
3274
|
-
return [3 /*break*/, 22];
|
|
3275
|
-
case 21:
|
|
3276
|
-
try {
|
|
3277
|
-
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3278
|
-
}
|
|
3279
|
-
finally { if (e_5) throw e_5.error; }
|
|
3280
|
-
return [7 /*endfinally*/];
|
|
3281
|
-
case 22:
|
|
3282
|
-
if (resultString !== null) {
|
|
3283
|
-
return [3 /*break*/, 26];
|
|
3284
|
-
}
|
|
3285
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3286
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3287
|
-
}
|
|
3288
|
-
else {
|
|
3289
|
-
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
|
|
3290
|
-
.map(function (error) { return '- ' + error.message; })
|
|
3291
|
-
.join('\n\n')), "\n "); }));
|
|
3292
|
-
}
|
|
3293
|
-
case 23:
|
|
3294
|
-
if (tools.userInterface === undefined) {
|
|
3295
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3296
|
-
}
|
|
3297
|
-
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3298
|
-
promptTitle: currentTemplate.title,
|
|
3299
|
-
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3300
|
-
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3301
|
-
// TODO: [๐ง ] !! Figure out how to define placeholder in .ptbk.md file
|
|
3302
|
-
placeholder: undefined,
|
|
3303
|
-
priority: priority,
|
|
3304
|
-
}))];
|
|
3305
|
-
case 24:
|
|
3306
|
-
// TODO: [๐น] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3307
|
-
resultString = _v.sent();
|
|
3308
|
-
return [3 /*break*/, 26];
|
|
3309
|
-
case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3310
|
-
case 26:
|
|
3311
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3312
|
-
_v.label = 27;
|
|
3313
|
-
case 27:
|
|
3314
|
-
_v.trys.push([27, 41, 42, 43]);
|
|
3315
|
-
_o = (e_7 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3316
|
-
_v.label = 28;
|
|
3317
|
-
case 28:
|
|
3318
|
-
if (!!_p.done) return [3 /*break*/, 40];
|
|
3319
|
-
functionName = _p.value;
|
|
3320
|
-
// TODO: DRY [1]
|
|
3321
|
-
scriptPipelineExecutionErrors = [];
|
|
3322
|
-
postprocessingError = null;
|
|
3323
|
-
_v.label = 29;
|
|
3324
|
-
case 29:
|
|
3325
|
-
_v.trys.push([29, 36, 37, 38]);
|
|
3326
|
-
_q = (e_6 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3327
|
-
_v.label = 30;
|
|
3328
|
-
case 30:
|
|
3329
|
-
if (!!_r.done) return [3 /*break*/, 35];
|
|
3330
|
-
scriptTools = _r.value;
|
|
3331
|
-
_v.label = 31;
|
|
3332
|
-
case 31:
|
|
3333
|
-
_v.trys.push([31, 33, , 34]);
|
|
3334
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
3335
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3336
|
-
script: "".concat(functionName, "(resultString)"),
|
|
3337
|
-
parameters: {
|
|
3338
|
-
resultString: resultString || '',
|
|
3339
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
3340
|
-
},
|
|
3341
|
-
})];
|
|
3342
|
-
case 32:
|
|
3343
|
-
resultString = _v.sent();
|
|
3344
|
-
postprocessingError = null;
|
|
3345
|
-
return [3 /*break*/, 35];
|
|
3346
|
-
case 33:
|
|
3347
|
-
error_3 = _v.sent();
|
|
3348
|
-
if (!(error_3 instanceof Error)) {
|
|
3349
|
-
throw error_3;
|
|
3350
|
-
}
|
|
3351
|
-
if (error_3 instanceof UnexpectedError) {
|
|
3352
|
-
throw error_3;
|
|
3353
|
-
}
|
|
3354
|
-
postprocessingError = error_3;
|
|
3355
|
-
scriptPipelineExecutionErrors.push(error_3);
|
|
3356
|
-
return [3 /*break*/, 34];
|
|
3357
|
-
case 34:
|
|
3358
|
-
_r = _q.next();
|
|
3359
|
-
return [3 /*break*/, 30];
|
|
3360
|
-
case 35: return [3 /*break*/, 38];
|
|
3361
|
-
case 36:
|
|
3362
|
-
e_6_1 = _v.sent();
|
|
3363
|
-
e_6 = { error: e_6_1 };
|
|
3364
|
-
return [3 /*break*/, 38];
|
|
3365
|
-
case 37:
|
|
3366
|
-
try {
|
|
3367
|
-
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3368
|
-
}
|
|
3369
|
-
finally { if (e_6) throw e_6.error; }
|
|
3370
|
-
return [7 /*endfinally*/];
|
|
3371
|
-
case 38:
|
|
3372
|
-
if (postprocessingError) {
|
|
3373
|
-
throw postprocessingError;
|
|
3374
|
-
}
|
|
3375
|
-
_v.label = 39;
|
|
3376
|
-
case 39:
|
|
3377
|
-
_p = _o.next();
|
|
3378
|
-
return [3 /*break*/, 28];
|
|
3379
|
-
case 40: return [3 /*break*/, 43];
|
|
3380
|
-
case 41:
|
|
3381
|
-
e_7_1 = _v.sent();
|
|
3382
|
-
e_7 = { error: e_7_1 };
|
|
3383
|
-
return [3 /*break*/, 43];
|
|
3384
|
-
case 42:
|
|
3385
|
-
try {
|
|
3386
|
-
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3387
|
-
}
|
|
3388
|
-
finally { if (e_7) throw e_7.error; }
|
|
3389
|
-
return [7 /*endfinally*/];
|
|
3390
|
-
case 43:
|
|
3391
|
-
// TODO: [๐] Unite object for expecting amount and format
|
|
3392
|
-
if (currentTemplate.format) {
|
|
3393
|
-
if (currentTemplate.format === 'JSON') {
|
|
3394
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3395
|
-
// TODO: [๐ข] Do more universally via `FormatDefinition`
|
|
3396
|
-
try {
|
|
3397
|
-
resultString = extractJsonBlock(resultString || '');
|
|
3398
|
-
}
|
|
3399
|
-
catch (error) {
|
|
3400
|
-
keepUnused(error);
|
|
3401
|
-
throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3402
|
-
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
}
|
|
3406
|
-
else {
|
|
3407
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3408
|
-
}
|
|
3409
|
-
}
|
|
3410
|
-
// TODO: [๐] Unite object for expecting amount and format
|
|
3411
|
-
if (currentTemplate.expectations) {
|
|
3412
|
-
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3413
|
-
}
|
|
3414
|
-
return [2 /*return*/, "break-attempts"];
|
|
3415
|
-
case 44:
|
|
3416
|
-
error_4 = _v.sent();
|
|
3417
|
-
if (!(error_4 instanceof ExpectError)) {
|
|
3418
|
-
throw error_4;
|
|
3419
|
-
}
|
|
3420
|
-
expectError = error_4;
|
|
3421
|
-
return [3 /*break*/, 46];
|
|
3422
|
-
case 45:
|
|
3423
|
-
if (!isJokerAttempt &&
|
|
3424
|
-
currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
|
|
3425
|
-
prompt
|
|
3426
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3427
|
-
// In that case we donโt want to make a report about it because itโs not a llm execution error
|
|
3428
|
-
) {
|
|
3429
|
-
// TODO: [๐ง ] Maybe put other templateTypes into report
|
|
3430
|
-
executionReport.promptExecutions.push({
|
|
3431
|
-
prompt: __assign({}, prompt),
|
|
3432
|
-
result: result || undefined,
|
|
3433
|
-
error: expectError === null ? undefined : serializeError(expectError),
|
|
3434
|
-
});
|
|
3435
|
-
}
|
|
3436
|
-
return [7 /*endfinally*/];
|
|
3437
|
-
case 46:
|
|
3438
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3439
|
-
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
|
|
3440
|
-
.split('\n')
|
|
3441
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3442
|
-
.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) || '')
|
|
3443
|
-
.split('\n')
|
|
3444
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3445
|
-
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3446
|
-
? 'null'
|
|
3447
|
-
: resultString
|
|
3448
|
-
.split('\n')
|
|
3449
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3450
|
-
.join('\n')), "\n ---\n "); }));
|
|
3451
|
-
}
|
|
3452
|
-
return [2 /*return*/];
|
|
3453
|
-
}
|
|
3454
|
-
});
|
|
3455
|
-
};
|
|
3456
|
-
attempt = -jokerParameterNames.length;
|
|
3457
|
-
_h.label = 4;
|
|
3458
|
-
case 4:
|
|
3459
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/, 7];
|
|
3460
|
-
return [5 /*yield**/, _loop_5(attempt)];
|
|
3461
|
-
case 5:
|
|
3462
|
-
state_2 = _h.sent();
|
|
3463
|
-
switch (state_2) {
|
|
3464
|
-
case "break-attempts": return [3 /*break*/, 7];
|
|
3465
|
-
}
|
|
3466
|
-
_h.label = 6;
|
|
3467
|
-
case 6:
|
|
3468
|
-
attempt++;
|
|
3469
|
-
return [3 /*break*/, 4];
|
|
3470
|
-
case 7:
|
|
3471
|
-
if (resultString === null) {
|
|
3472
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3473
|
-
}
|
|
3474
|
-
if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 9]; /* <- [3] */
|
|
3475
|
-
progress_2 = {
|
|
3476
|
-
name: name,
|
|
3477
|
-
title: title,
|
|
3478
|
-
isStarted: true,
|
|
3479
|
-
isDone: true,
|
|
3480
|
-
templateType: currentTemplate.templateType,
|
|
3481
|
-
parameterName: currentTemplate.resultingParameterName,
|
|
3482
|
-
parameterValue: resultString,
|
|
3483
|
-
// <- [3]
|
|
3484
|
-
};
|
|
3485
|
-
if (isReturned) {
|
|
3486
|
-
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)
|
|
3487
|
-
.split('\n')
|
|
3488
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3489
|
-
.join('\n')), "\n\n "); }));
|
|
3490
|
-
}
|
|
3491
|
-
return [4 /*yield*/, onProgress(progress_2)];
|
|
3492
|
-
case 8:
|
|
3493
|
-
_h.sent();
|
|
3494
|
-
_h.label = 9;
|
|
3495
|
-
case 9:
|
|
3496
|
-
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)));
|
|
3497
|
-
return [2 /*return*/];
|
|
3498
|
-
}
|
|
3499
|
-
});
|
|
3500
|
-
});
|
|
3501
|
-
}
|
|
3502
|
-
function filterJustOutputParameters() {
|
|
3503
|
-
var e_8, _a;
|
|
3504
|
-
var outputParameters = {};
|
|
3505
|
-
var _loop_6 = function (parameter) {
|
|
3506
|
-
if (parametersToPass[parameter.name] === undefined) {
|
|
3507
|
-
// [4]
|
|
3508
|
-
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 "); })));
|
|
3509
|
-
return "continue";
|
|
3510
|
-
}
|
|
3511
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3512
|
-
};
|
|
3513
|
-
try {
|
|
3514
|
-
// Note: Filter ONLY output parameters
|
|
3515
|
-
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
3516
|
-
var isOutput = _a.isOutput;
|
|
3517
|
-
return isOutput;
|
|
3518
|
-
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3519
|
-
var parameter = _c.value;
|
|
3520
|
-
_loop_6(parameter);
|
|
3521
|
-
}
|
|
3522
|
-
}
|
|
3523
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
3524
|
-
finally {
|
|
3525
|
-
try {
|
|
3526
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3527
|
-
}
|
|
3528
|
-
finally { if (e_8) throw e_8.error; }
|
|
3529
|
-
}
|
|
3530
|
-
return outputParameters;
|
|
3531
|
-
}
|
|
3532
3591
|
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;
|
|
3533
3592
|
var e_1, _e, e_2, _f;
|
|
3534
3593
|
return __generator(this, function (_g) {
|
|
@@ -3710,14 +3769,35 @@ function createPipelineExecutor(options) {
|
|
|
3710
3769
|
.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 "); }));
|
|
3711
3770
|
case 1:
|
|
3712
3771
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
3713
|
-
/* [
|
|
3772
|
+
/* [๐คนโโ๏ธ] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
3714
3773
|
case 2:
|
|
3715
|
-
/* [
|
|
3774
|
+
/* [๐คนโโ๏ธ] */ _j.sent();
|
|
3716
3775
|
return [3 /*break*/, 4];
|
|
3717
3776
|
case 3:
|
|
3718
3777
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
3719
|
-
work_1 = executeSingleTemplate(
|
|
3720
|
-
|
|
3778
|
+
work_1 = executeSingleTemplate({
|
|
3779
|
+
currentTemplate: currentTemplate,
|
|
3780
|
+
preparedPipeline: preparedPipeline,
|
|
3781
|
+
parametersToPass: parametersToPass,
|
|
3782
|
+
tools: tools,
|
|
3783
|
+
llmTools: llmTools,
|
|
3784
|
+
onProgress: function (progress) {
|
|
3785
|
+
if (isReturned) {
|
|
3786
|
+
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)
|
|
3787
|
+
.split('\n')
|
|
3788
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3789
|
+
.join('\n')), "\n "); }));
|
|
3790
|
+
}
|
|
3791
|
+
if (onProgress) {
|
|
3792
|
+
onProgress(progress);
|
|
3793
|
+
}
|
|
3794
|
+
},
|
|
3795
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
3796
|
+
$executionReport: executionReport,
|
|
3797
|
+
pipelineIdentification: pipelineIdentification,
|
|
3798
|
+
})
|
|
3799
|
+
.then(function (newParametersToPass) {
|
|
3800
|
+
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
3721
3801
|
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
|
|
3722
3802
|
})
|
|
3723
3803
|
.then(function () {
|
|
@@ -3749,7 +3829,7 @@ function createPipelineExecutor(options) {
|
|
|
3749
3829
|
var result = _a.result;
|
|
3750
3830
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3751
3831
|
})), false));
|
|
3752
|
-
outputParameters_1 = filterJustOutputParameters();
|
|
3832
|
+
outputParameters_1 = filterJustOutputParameters(preparedPipeline, parametersToPass, warnings, pipelineIdentification);
|
|
3753
3833
|
isReturned = true;
|
|
3754
3834
|
if (!(onProgress !== undefined)) return [3 /*break*/, 27];
|
|
3755
3835
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -3772,7 +3852,7 @@ function createPipelineExecutor(options) {
|
|
|
3772
3852
|
var result = _a.result;
|
|
3773
3853
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3774
3854
|
})), false));
|
|
3775
|
-
outputParameters = filterJustOutputParameters();
|
|
3855
|
+
outputParameters = filterJustOutputParameters(preparedPipeline, parametersToPass, warnings, pipelineIdentification);
|
|
3776
3856
|
isReturned = true;
|
|
3777
3857
|
if (!(onProgress !== undefined)) return [3 /*break*/, 30];
|
|
3778
3858
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -3796,6 +3876,7 @@ function createPipelineExecutor(options) {
|
|
|
3796
3876
|
return pipelineExecutor;
|
|
3797
3877
|
}
|
|
3798
3878
|
/**
|
|
3879
|
+
* TODO: [๐คนโโ๏ธ] Make some smarter system for limiting concurrent executions MAX_PARALLEL_TOTAL, MAX_PARALLEL_PER_LLM
|
|
3799
3880
|
* TODO: !!! Identify not only pipeline BUT exact template ${block(pipelineIdentification)}
|
|
3800
3881
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3801
3882
|
* TODO: [๐ง ][๐ณ] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
@@ -3804,7 +3885,7 @@ function createPipelineExecutor(options) {
|
|
|
3804
3885
|
* TODO: [๐ง ] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
|
|
3805
3886
|
* TODO: [๐ง] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
3806
3887
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
3807
|
-
* TODO: [๐ง ][
|
|
3888
|
+
* TODO: [๐ง ][๐ธ] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
3808
3889
|
* TODO: [๐ ] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3809
3890
|
* TODO: [๐ง ][๐ท] `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result BUT maybe NOT to preserve pure JSON object
|
|
3810
3891
|
*/
|
|
@@ -4995,20 +5076,21 @@ var foreachCommandParser = {
|
|
|
4995
5076
|
* Example usages of the FOREACH command
|
|
4996
5077
|
*/
|
|
4997
5078
|
examples: [
|
|
4998
|
-
'FOREACH List Line -> `{customer}`',
|
|
4999
|
-
'FOR List Line -> `{customer}`',
|
|
5000
|
-
'EACH List Line -> `{customer}`',
|
|
5079
|
+
'FOREACH List Line `{customers}` -> `{customer}`',
|
|
5080
|
+
'FOR List Line `{customers}` -> `{customer}`',
|
|
5081
|
+
'EACH List Line `{customers}` -> `{customer}`',
|
|
5001
5082
|
// <- TODO: [๐ญ] !!!!!! More
|
|
5002
5083
|
],
|
|
5003
5084
|
/**
|
|
5004
5085
|
* Parses the FOREACH command
|
|
5005
5086
|
*/
|
|
5006
5087
|
parse: function (input) {
|
|
5007
|
-
var args = input.args
|
|
5088
|
+
var args = input.args;
|
|
5008
5089
|
var formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
|
|
5009
5090
|
var cellName = normalizeTo_SCREAMING_CASE(args[1] || '');
|
|
5010
|
-
var
|
|
5011
|
-
var
|
|
5091
|
+
var parameterNameWrapped = args[2];
|
|
5092
|
+
var assignSign = args[3];
|
|
5093
|
+
var subparameterNameWrapped = args[4];
|
|
5012
5094
|
if (![
|
|
5013
5095
|
'LIST',
|
|
5014
5096
|
'CSV',
|
|
@@ -5023,7 +5105,7 @@ var foreachCommandParser = {
|
|
|
5023
5105
|
'ROW',
|
|
5024
5106
|
'COLUMN',
|
|
5025
5107
|
'CELL',
|
|
5026
|
-
// <- TODO: [๐ข] Unhardcode format
|
|
5108
|
+
// <- TODO: [๐ข] Unhardcode format cells
|
|
5027
5109
|
].includes(cellName)) {
|
|
5028
5110
|
console.info({ args: args, cellName: cellName });
|
|
5029
5111
|
throw new Error("Format ".concat(formatName, " does not support cell \"").concat(cellName, "\""));
|
|
@@ -5033,24 +5115,27 @@ var foreachCommandParser = {
|
|
|
5033
5115
|
console.info({ args: args, assignSign: assignSign });
|
|
5034
5116
|
throw new Error("FOREACH command must have '->' to assign the value to the parameter");
|
|
5035
5117
|
}
|
|
5036
|
-
|
|
5037
|
-
if (
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
//
|
|
5044
|
-
) {
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5118
|
+
// TODO: !!!!!! Replace with propper parameter name validation
|
|
5119
|
+
if ((parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1)) !== '{' ||
|
|
5120
|
+
(parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length)) !== '}') {
|
|
5121
|
+
console.info({ args: args, parameterNameWrapped: parameterNameWrapped }, parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1), parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length));
|
|
5122
|
+
throw new Error("!!!!!! 1 Here will be error (with rules and precise error) from validateParameterName");
|
|
5123
|
+
}
|
|
5124
|
+
var parameterName = parameterNameWrapped.substring(1, parameterNameWrapped.length - 1);
|
|
5125
|
+
// TODO: !!!!!! Replace with propper parameter name validation
|
|
5126
|
+
if ((subparameterNameWrapped === null || subparameterNameWrapped === void 0 ? void 0 : subparameterNameWrapped.substring(0, 1)) !== '{' ||
|
|
5127
|
+
(subparameterNameWrapped === null || subparameterNameWrapped === void 0 ? void 0 : subparameterNameWrapped.substring(subparameterNameWrapped.length - 1, subparameterNameWrapped.length)) !==
|
|
5128
|
+
'}') {
|
|
5129
|
+
console.info({ args: args, subparameterNameWrapped: subparameterNameWrapped });
|
|
5130
|
+
throw new Error("!!!!!! 2 Here will be error (with rules and precise error) from validateParameterName");
|
|
5131
|
+
}
|
|
5132
|
+
var subparameterName = subparameterNameWrapped.substring(1, subparameterNameWrapped.length - 1);
|
|
5049
5133
|
return {
|
|
5050
5134
|
type: 'FOREACH',
|
|
5051
5135
|
formatName: formatName,
|
|
5052
5136
|
cellName: cellName,
|
|
5053
5137
|
parameterName: parameterName,
|
|
5138
|
+
subparameterName: subparameterName,
|
|
5054
5139
|
};
|
|
5055
5140
|
},
|
|
5056
5141
|
/**
|
|
@@ -5059,8 +5144,12 @@ var foreachCommandParser = {
|
|
|
5059
5144
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5060
5145
|
*/
|
|
5061
5146
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5062
|
-
|
|
5063
|
-
//
|
|
5147
|
+
var formatName = command.formatName, cellName = command.cellName, parameterName = command.parameterName, subparameterName = command.subparameterName;
|
|
5148
|
+
// TODO: !!!!!! Detect double use
|
|
5149
|
+
// TODO: !!!!!! Detect usage with JOKER and don't allow it
|
|
5150
|
+
$templateJson.foreach = { formatName: formatName, cellName: cellName, parameterName: parameterName, subparameterName: subparameterName };
|
|
5151
|
+
keepUnused($pipelineJson); // <- TODO: !!!!!! BUT Maybe register subparameter from foreach into parameters of the pipeline
|
|
5152
|
+
// Note: [๐ญ] FOREACH apply has some sideeffects on different places in codebase
|
|
5064
5153
|
},
|
|
5065
5154
|
/**
|
|
5066
5155
|
* Converts the FOREACH command back to string
|
|
@@ -5069,8 +5158,7 @@ var foreachCommandParser = {
|
|
|
5069
5158
|
*/
|
|
5070
5159
|
stringify: function (command) {
|
|
5071
5160
|
keepUnused(command);
|
|
5072
|
-
return "";
|
|
5073
|
-
// <- TODO: [๐ญ] !!!!!! Implement
|
|
5161
|
+
return "---"; // <- TODO: [๐] Implement
|
|
5074
5162
|
},
|
|
5075
5163
|
/**
|
|
5076
5164
|
* Reads the FOREACH command from the `TemplateJson`
|
|
@@ -5079,8 +5167,7 @@ var foreachCommandParser = {
|
|
|
5079
5167
|
*/
|
|
5080
5168
|
takeFromTemplateJson: function ($templateJson) {
|
|
5081
5169
|
keepUnused($templateJson);
|
|
5082
|
-
|
|
5083
|
-
// <- TODO: [๐ญ] !!!!!! Implement
|
|
5170
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [๐] Implement
|
|
5084
5171
|
},
|
|
5085
5172
|
};
|
|
5086
5173
|
/**
|
|
@@ -5195,6 +5282,7 @@ var jokerCommandParser = {
|
|
|
5195
5282
|
*/
|
|
5196
5283
|
parse: function (input) {
|
|
5197
5284
|
var args = input.args;
|
|
5285
|
+
// TODO: !!!!!! Replace with propper parameter name validation
|
|
5198
5286
|
var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
5199
5287
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
5200
5288
|
throw new ParseError("Invalid joker");
|
|
@@ -5324,6 +5412,7 @@ var modelCommandParser = {
|
|
|
5324
5412
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
5325
5413
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
5326
5414
|
console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
|
|
5415
|
+
// <- TODO: [๐] Some better way how to get warnings from pipeline parsing / logic
|
|
5327
5416
|
}
|
|
5328
5417
|
else {
|
|
5329
5418
|
throw new ParseError(spaceTrim$1("\n Redefinition of MODEL `".concat(command.key, "` in the pipeline head\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($pipelineJson.defaultModelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
|