@promptbook/core 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 +1020 -928
- 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 +1 -1
- package/umd/index.umd.js +1020 -928
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +0 -72
package/umd/index.umd.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* The version of the Promptbook library
|
|
18
18
|
*/
|
|
19
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
19
|
+
var PROMPTBOOK_VERSION = '0.69.0-3';
|
|
20
20
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
21
21
|
|
|
22
22
|
/*! *****************************************************************************
|
|
@@ -715,6 +715,7 @@
|
|
|
715
715
|
'samples',
|
|
716
716
|
'modelName',
|
|
717
717
|
'currentDate',
|
|
718
|
+
// <- TODO: !!!!! list here all command names
|
|
718
719
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
719
720
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
720
721
|
]);
|
|
@@ -758,6 +759,15 @@
|
|
|
758
759
|
* @public exported from `@promptbook/core`
|
|
759
760
|
*/
|
|
760
761
|
var IS_VERBOSE = false;
|
|
762
|
+
/**
|
|
763
|
+
* @@@
|
|
764
|
+
*
|
|
765
|
+
* @private within the repository
|
|
766
|
+
*/
|
|
767
|
+
var IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
768
|
+
/**/
|
|
769
|
+
// Note: In normal situations, we check the pipeline logic:
|
|
770
|
+
true);
|
|
761
771
|
/**
|
|
762
772
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
763
773
|
*/
|
|
@@ -967,6 +977,26 @@
|
|
|
967
977
|
* @public exported from `@promptbook/core`
|
|
968
978
|
*/
|
|
969
979
|
function validatePipeline(pipeline) {
|
|
980
|
+
if (IS_PIPELINE_LOGIC_VALIDATED) {
|
|
981
|
+
validatePipelineCore(pipeline);
|
|
982
|
+
}
|
|
983
|
+
else {
|
|
984
|
+
try {
|
|
985
|
+
validatePipelineCore(pipeline);
|
|
986
|
+
}
|
|
987
|
+
catch (error) {
|
|
988
|
+
if (!(error instanceof PipelineLogicError)) {
|
|
989
|
+
throw error;
|
|
990
|
+
}
|
|
991
|
+
console.error(spaceTrim.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 "); }));
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
return pipeline;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* @private internal function for `validatePipeline`
|
|
998
|
+
*/
|
|
999
|
+
function validatePipelineCore(pipeline) {
|
|
970
1000
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
971
1001
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
972
1002
|
var pipelineIdentification = (function () {
|
|
@@ -1165,7 +1195,6 @@
|
|
|
1165
1195
|
while (unresovedTemplates.length > 0) {
|
|
1166
1196
|
_loop_3();
|
|
1167
1197
|
}
|
|
1168
|
-
return pipeline;
|
|
1169
1198
|
}
|
|
1170
1199
|
/**
|
|
1171
1200
|
* TODO: [🧠] Work with promptbookVersion
|
|
@@ -1794,7 +1823,7 @@
|
|
|
1794
1823
|
});
|
|
1795
1824
|
}
|
|
1796
1825
|
|
|
1797
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
1826
|
+
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"}];
|
|
1798
1827
|
|
|
1799
1828
|
var defaultDiacriticsRemovalMap = [
|
|
1800
1829
|
{
|
|
@@ -2322,116 +2351,6 @@
|
|
|
2322
2351
|
* TODO: [🧠] Can this return type be better typed than void
|
|
2323
2352
|
*/
|
|
2324
2353
|
|
|
2325
|
-
/**
|
|
2326
|
-
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
2327
|
-
*
|
|
2328
|
-
* @param script from which to extract the variables
|
|
2329
|
-
* @returns the list of variable names
|
|
2330
|
-
* @throws {ParseError} if the script is invalid
|
|
2331
|
-
* @public exported from `@promptbook/utils`
|
|
2332
|
-
*/
|
|
2333
|
-
function extractVariables(script) {
|
|
2334
|
-
var variables = new Set();
|
|
2335
|
-
script = "(()=>{".concat(script, "})()");
|
|
2336
|
-
try {
|
|
2337
|
-
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2338
|
-
try {
|
|
2339
|
-
eval(script);
|
|
2340
|
-
}
|
|
2341
|
-
catch (error) {
|
|
2342
|
-
if (!(error instanceof ReferenceError)) {
|
|
2343
|
-
throw error;
|
|
2344
|
-
}
|
|
2345
|
-
var undefinedName = error.message.split(' ')[0];
|
|
2346
|
-
/*
|
|
2347
|
-
Note: Parsing the error
|
|
2348
|
-
[PipelineUrlError: thing is not defined]
|
|
2349
|
-
*/
|
|
2350
|
-
if (!undefinedName) {
|
|
2351
|
-
throw error;
|
|
2352
|
-
}
|
|
2353
|
-
if (script.includes(undefinedName + '(')) {
|
|
2354
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2355
|
-
}
|
|
2356
|
-
else {
|
|
2357
|
-
variables.add(undefinedName);
|
|
2358
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
catch (error) {
|
|
2363
|
-
if (!(error instanceof Error)) {
|
|
2364
|
-
throw error;
|
|
2365
|
-
}
|
|
2366
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
2367
|
-
}
|
|
2368
|
-
return variables;
|
|
2369
|
-
}
|
|
2370
|
-
/**
|
|
2371
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
2372
|
-
*/
|
|
2373
|
-
|
|
2374
|
-
/**
|
|
2375
|
-
* Parses the template and returns the set of all used parameters
|
|
2376
|
-
*
|
|
2377
|
-
* @param template the template with used parameters
|
|
2378
|
-
* @returns the set of parameter names
|
|
2379
|
-
* @throws {ParseError} if the script is invalid
|
|
2380
|
-
* @public exported from `@promptbook/utils`
|
|
2381
|
-
*/
|
|
2382
|
-
function extractParameterNamesFromTemplate(template) {
|
|
2383
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
2384
|
-
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
|
|
2385
|
-
var parameterNames = new Set();
|
|
2386
|
-
try {
|
|
2387
|
-
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()) {
|
|
2388
|
-
var parameterName = _e.value;
|
|
2389
|
-
parameterNames.add(parameterName);
|
|
2390
|
-
}
|
|
2391
|
-
}
|
|
2392
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2393
|
-
finally {
|
|
2394
|
-
try {
|
|
2395
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2396
|
-
}
|
|
2397
|
-
finally { if (e_1) throw e_1.error; }
|
|
2398
|
-
}
|
|
2399
|
-
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
2400
|
-
try {
|
|
2401
|
-
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2402
|
-
var parameterName = _g.value;
|
|
2403
|
-
parameterNames.add(parameterName);
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2407
|
-
finally {
|
|
2408
|
-
try {
|
|
2409
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2410
|
-
}
|
|
2411
|
-
finally { if (e_2) throw e_2.error; }
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
try {
|
|
2415
|
-
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
2416
|
-
var jokerName = _j.value;
|
|
2417
|
-
parameterNames.add(jokerName);
|
|
2418
|
-
}
|
|
2419
|
-
}
|
|
2420
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2421
|
-
finally {
|
|
2422
|
-
try {
|
|
2423
|
-
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
2424
|
-
}
|
|
2425
|
-
finally { if (e_3) throw e_3.error; }
|
|
2426
|
-
}
|
|
2427
|
-
parameterNames.delete('content');
|
|
2428
|
-
// <- Note {websiteContent} is used in `preparedContent`
|
|
2429
|
-
return parameterNames;
|
|
2430
|
-
}
|
|
2431
|
-
/**
|
|
2432
|
-
* TODO: [🔣] If script require contentLanguage
|
|
2433
|
-
*/
|
|
2434
|
-
|
|
2435
2354
|
/**
|
|
2436
2355
|
* Serializes an error into a [🚉] JSON-serializable object
|
|
2437
2356
|
*
|
|
@@ -2449,27 +2368,6 @@
|
|
|
2449
2368
|
};
|
|
2450
2369
|
}
|
|
2451
2370
|
|
|
2452
|
-
/**
|
|
2453
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2454
|
-
*
|
|
2455
|
-
* @public exported from `@promptbook/utils`
|
|
2456
|
-
*/
|
|
2457
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
2458
|
-
try {
|
|
2459
|
-
JSON.parse(value);
|
|
2460
|
-
return true;
|
|
2461
|
-
}
|
|
2462
|
-
catch (error) {
|
|
2463
|
-
if (!(error instanceof Error)) {
|
|
2464
|
-
throw error;
|
|
2465
|
-
}
|
|
2466
|
-
if (error.message.includes('Unexpected token')) {
|
|
2467
|
-
return false;
|
|
2468
|
-
}
|
|
2469
|
-
return false;
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
|
|
2473
2371
|
/**
|
|
2474
2372
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2475
2373
|
*
|
|
@@ -2764,171 +2662,310 @@
|
|
|
2764
2662
|
*/
|
|
2765
2663
|
|
|
2766
2664
|
/**
|
|
2767
|
-
*
|
|
2768
|
-
*
|
|
2769
|
-
* Note: There are multiple simmilar function:
|
|
2770
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2771
|
-
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2772
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2773
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2665
|
+
* Determine if the pipeline is fully prepared
|
|
2774
2666
|
*
|
|
2775
|
-
* @
|
|
2776
|
-
* @returns code blocks with language and content
|
|
2777
|
-
* @throws {ParseError} if block is not closed properly
|
|
2778
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
2667
|
+
* @public exported from `@promptbook/core`
|
|
2779
2668
|
*/
|
|
2780
|
-
function
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
lines.push('');
|
|
2786
|
-
var currentCodeBlock = null;
|
|
2787
|
-
try {
|
|
2788
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2789
|
-
var line = lines_1_1.value;
|
|
2790
|
-
if (line.startsWith('> ') || line === '>') {
|
|
2791
|
-
if (currentCodeBlock === null) {
|
|
2792
|
-
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2793
|
-
} /* not else */
|
|
2794
|
-
if (currentCodeBlock.blockNotation === '>') {
|
|
2795
|
-
if (currentCodeBlock.content !== '') {
|
|
2796
|
-
currentCodeBlock.content += '\n';
|
|
2797
|
-
}
|
|
2798
|
-
currentCodeBlock.content += line.slice(2);
|
|
2799
|
-
}
|
|
2800
|
-
}
|
|
2801
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2802
|
-
codeBlocks.push(currentCodeBlock);
|
|
2803
|
-
currentCodeBlock = null;
|
|
2804
|
-
}
|
|
2805
|
-
/* not else */
|
|
2806
|
-
if (line.startsWith('```')) {
|
|
2807
|
-
var language = line.slice(3).trim() || null;
|
|
2808
|
-
if (currentCodeBlock === null) {
|
|
2809
|
-
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2810
|
-
}
|
|
2811
|
-
else {
|
|
2812
|
-
if (language !== null) {
|
|
2813
|
-
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2814
|
-
}
|
|
2815
|
-
codeBlocks.push(currentCodeBlock);
|
|
2816
|
-
currentCodeBlock = null;
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2820
|
-
if (currentCodeBlock.content !== '') {
|
|
2821
|
-
currentCodeBlock.content += '\n';
|
|
2822
|
-
}
|
|
2823
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2828
|
-
finally {
|
|
2829
|
-
try {
|
|
2830
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2831
|
-
}
|
|
2832
|
-
finally { if (e_1) throw e_1.error; }
|
|
2669
|
+
function isPipelinePrepared(pipeline) {
|
|
2670
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2671
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2672
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2673
|
+
return false;
|
|
2833
2674
|
}
|
|
2834
|
-
if (
|
|
2835
|
-
|
|
2675
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2676
|
+
return false;
|
|
2836
2677
|
}
|
|
2837
|
-
|
|
2678
|
+
/*
|
|
2679
|
+
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2680
|
+
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2681
|
+
> return false;
|
|
2682
|
+
> }
|
|
2683
|
+
*/
|
|
2684
|
+
return true;
|
|
2838
2685
|
}
|
|
2839
2686
|
/**
|
|
2840
|
-
* TODO:
|
|
2687
|
+
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2688
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2689
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2690
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2691
|
+
* - [🏍] ? Is context in each template
|
|
2692
|
+
* - [♨] Are samples prepared
|
|
2693
|
+
* - [♨] Are templates prepared
|
|
2841
2694
|
*/
|
|
2842
2695
|
|
|
2843
2696
|
/**
|
|
2844
|
-
*
|
|
2845
|
-
*
|
|
2846
|
-
* - When given string is a valid JSON as it is, it just returns it
|
|
2847
|
-
* - When there is no JSON code block the function throws a `ParseError`
|
|
2848
|
-
* - When there are multiple JSON code blocks the function throws a `ParseError`
|
|
2697
|
+
* Takes an item or an array of items and returns an array of items
|
|
2849
2698
|
*
|
|
2850
|
-
*
|
|
2851
|
-
*
|
|
2852
|
-
*
|
|
2853
|
-
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2854
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2855
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2699
|
+
* 1) Any item except array and undefined returns array with that one item (also null)
|
|
2700
|
+
* 2) Undefined returns empty array
|
|
2701
|
+
* 3) Array returns itself
|
|
2856
2702
|
*
|
|
2857
|
-
* @
|
|
2858
|
-
* @throws {ParseError} if there is no valid JSON block in the markdown
|
|
2703
|
+
* @private internal utility
|
|
2859
2704
|
*/
|
|
2860
|
-
function
|
|
2861
|
-
if (
|
|
2862
|
-
return
|
|
2705
|
+
function arrayableToArray(input) {
|
|
2706
|
+
if (input === undefined) {
|
|
2707
|
+
return [];
|
|
2863
2708
|
}
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
var content = _a.content;
|
|
2867
|
-
return isValidJsonString(content);
|
|
2868
|
-
});
|
|
2869
|
-
if (jsonBlocks.length === 0) {
|
|
2870
|
-
throw new Error('There is no valid JSON block in the markdown');
|
|
2709
|
+
if (input instanceof Array) {
|
|
2710
|
+
return input;
|
|
2871
2711
|
}
|
|
2872
|
-
|
|
2873
|
-
|
|
2712
|
+
return [input];
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
/**
|
|
2716
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
2717
|
+
*
|
|
2718
|
+
* @param script from which to extract the variables
|
|
2719
|
+
* @returns the list of variable names
|
|
2720
|
+
* @throws {ParseError} if the script is invalid
|
|
2721
|
+
* @public exported from `@promptbook/utils`
|
|
2722
|
+
*/
|
|
2723
|
+
function extractVariables(script) {
|
|
2724
|
+
var variables = new Set();
|
|
2725
|
+
script = "(()=>{".concat(script, "})()");
|
|
2726
|
+
try {
|
|
2727
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2728
|
+
try {
|
|
2729
|
+
eval(script);
|
|
2730
|
+
}
|
|
2731
|
+
catch (error) {
|
|
2732
|
+
if (!(error instanceof ReferenceError)) {
|
|
2733
|
+
throw error;
|
|
2734
|
+
}
|
|
2735
|
+
var undefinedName = error.message.split(' ')[0];
|
|
2736
|
+
/*
|
|
2737
|
+
Note: Parsing the error
|
|
2738
|
+
[PipelineUrlError: thing is not defined]
|
|
2739
|
+
*/
|
|
2740
|
+
if (!undefinedName) {
|
|
2741
|
+
throw error;
|
|
2742
|
+
}
|
|
2743
|
+
if (script.includes(undefinedName + '(')) {
|
|
2744
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2745
|
+
}
|
|
2746
|
+
else {
|
|
2747
|
+
variables.add(undefinedName);
|
|
2748
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2874
2751
|
}
|
|
2875
|
-
|
|
2752
|
+
catch (error) {
|
|
2753
|
+
if (!(error instanceof Error)) {
|
|
2754
|
+
throw error;
|
|
2755
|
+
}
|
|
2756
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
2757
|
+
}
|
|
2758
|
+
return variables;
|
|
2876
2759
|
}
|
|
2877
2760
|
/**
|
|
2878
|
-
* TODO:
|
|
2879
|
-
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2761
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
2880
2762
|
*/
|
|
2881
2763
|
|
|
2882
2764
|
/**
|
|
2883
|
-
*
|
|
2765
|
+
* Parses the template and returns the set of all used parameters
|
|
2884
2766
|
*
|
|
2885
|
-
* @
|
|
2767
|
+
* @param template the template with used parameters
|
|
2768
|
+
* @returns the set of parameter names
|
|
2769
|
+
* @throws {ParseError} if the script is invalid
|
|
2770
|
+
* @public exported from `@promptbook/utils`
|
|
2886
2771
|
*/
|
|
2887
|
-
function
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2772
|
+
function extractParameterNamesFromTemplate(template) {
|
|
2773
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
2774
|
+
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
|
|
2775
|
+
var parameterNames = new Set();
|
|
2776
|
+
try {
|
|
2777
|
+
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()) {
|
|
2778
|
+
var parameterName = _e.value;
|
|
2779
|
+
parameterNames.add(parameterName);
|
|
2780
|
+
}
|
|
2892
2781
|
}
|
|
2893
|
-
|
|
2782
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2783
|
+
finally {
|
|
2784
|
+
try {
|
|
2785
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2786
|
+
}
|
|
2787
|
+
finally { if (e_1) throw e_1.error; }
|
|
2788
|
+
}
|
|
2789
|
+
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
2790
|
+
try {
|
|
2791
|
+
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2792
|
+
var parameterName = _g.value;
|
|
2793
|
+
parameterNames.add(parameterName);
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2797
|
+
finally {
|
|
2798
|
+
try {
|
|
2799
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2800
|
+
}
|
|
2801
|
+
finally { if (e_2) throw e_2.error; }
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
try {
|
|
2805
|
+
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
2806
|
+
var jokerName = _j.value;
|
|
2807
|
+
parameterNames.add(jokerName);
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2811
|
+
finally {
|
|
2812
|
+
try {
|
|
2813
|
+
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
2814
|
+
}
|
|
2815
|
+
finally { if (e_3) throw e_3.error; }
|
|
2816
|
+
}
|
|
2817
|
+
parameterNames.delete('content');
|
|
2818
|
+
// <- Note {websiteContent} is used in `preparedContent`
|
|
2819
|
+
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2820
|
+
if (foreach !== undefined) {
|
|
2821
|
+
if (parameterNames.has(foreach.subparameterName)) {
|
|
2822
|
+
parameterNames.delete(foreach.subparameterName);
|
|
2823
|
+
parameterNames.add(foreach.parameterName);
|
|
2824
|
+
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
return parameterNames;
|
|
2828
|
+
}
|
|
2829
|
+
/**
|
|
2830
|
+
* TODO: [🔣] If script require contentLanguage
|
|
2831
|
+
*/
|
|
2832
|
+
|
|
2833
|
+
/**
|
|
2834
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2835
|
+
*
|
|
2836
|
+
* @public exported from `@promptbook/utils`
|
|
2837
|
+
*/
|
|
2838
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
2839
|
+
try {
|
|
2840
|
+
JSON.parse(value);
|
|
2841
|
+
return true;
|
|
2842
|
+
}
|
|
2843
|
+
catch (error) {
|
|
2844
|
+
if (!(error instanceof Error)) {
|
|
2845
|
+
throw error;
|
|
2846
|
+
}
|
|
2847
|
+
if (error.message.includes('Unexpected token')) {
|
|
2848
|
+
return false;
|
|
2849
|
+
}
|
|
2894
2850
|
return false;
|
|
2895
2851
|
}
|
|
2896
|
-
/*
|
|
2897
|
-
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2898
|
-
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2899
|
-
> return false;
|
|
2900
|
-
> }
|
|
2901
|
-
*/
|
|
2902
|
-
return true;
|
|
2903
2852
|
}
|
|
2853
|
+
|
|
2904
2854
|
/**
|
|
2905
|
-
*
|
|
2906
|
-
*
|
|
2907
|
-
*
|
|
2908
|
-
*
|
|
2909
|
-
*
|
|
2910
|
-
*
|
|
2911
|
-
*
|
|
2855
|
+
* Extracts all code blocks from markdown.
|
|
2856
|
+
*
|
|
2857
|
+
* Note: There are multiple simmilar function:
|
|
2858
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2859
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2860
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2861
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2862
|
+
*
|
|
2863
|
+
* @param markdown any valid markdown
|
|
2864
|
+
* @returns code blocks with language and content
|
|
2865
|
+
* @throws {ParseError} if block is not closed properly
|
|
2866
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2867
|
+
*/
|
|
2868
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
2869
|
+
var e_1, _a;
|
|
2870
|
+
var codeBlocks = [];
|
|
2871
|
+
var lines = markdown.split('\n');
|
|
2872
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
2873
|
+
lines.push('');
|
|
2874
|
+
var currentCodeBlock = null;
|
|
2875
|
+
try {
|
|
2876
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2877
|
+
var line = lines_1_1.value;
|
|
2878
|
+
if (line.startsWith('> ') || line === '>') {
|
|
2879
|
+
if (currentCodeBlock === null) {
|
|
2880
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2881
|
+
} /* not else */
|
|
2882
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
2883
|
+
if (currentCodeBlock.content !== '') {
|
|
2884
|
+
currentCodeBlock.content += '\n';
|
|
2885
|
+
}
|
|
2886
|
+
currentCodeBlock.content += line.slice(2);
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2890
|
+
codeBlocks.push(currentCodeBlock);
|
|
2891
|
+
currentCodeBlock = null;
|
|
2892
|
+
}
|
|
2893
|
+
/* not else */
|
|
2894
|
+
if (line.startsWith('```')) {
|
|
2895
|
+
var language = line.slice(3).trim() || null;
|
|
2896
|
+
if (currentCodeBlock === null) {
|
|
2897
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2898
|
+
}
|
|
2899
|
+
else {
|
|
2900
|
+
if (language !== null) {
|
|
2901
|
+
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2902
|
+
}
|
|
2903
|
+
codeBlocks.push(currentCodeBlock);
|
|
2904
|
+
currentCodeBlock = null;
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2908
|
+
if (currentCodeBlock.content !== '') {
|
|
2909
|
+
currentCodeBlock.content += '\n';
|
|
2910
|
+
}
|
|
2911
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2916
|
+
finally {
|
|
2917
|
+
try {
|
|
2918
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2919
|
+
}
|
|
2920
|
+
finally { if (e_1) throw e_1.error; }
|
|
2921
|
+
}
|
|
2922
|
+
if (currentCodeBlock !== null) {
|
|
2923
|
+
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2924
|
+
}
|
|
2925
|
+
return codeBlocks;
|
|
2926
|
+
}
|
|
2927
|
+
/**
|
|
2928
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
2912
2929
|
*/
|
|
2913
2930
|
|
|
2914
2931
|
/**
|
|
2915
|
-
*
|
|
2932
|
+
* Extracts extracts exactly one valid JSON code block
|
|
2916
2933
|
*
|
|
2917
|
-
*
|
|
2918
|
-
*
|
|
2919
|
-
*
|
|
2934
|
+
* - When given string is a valid JSON as it is, it just returns it
|
|
2935
|
+
* - When there is no JSON code block the function throws a `ParseError`
|
|
2936
|
+
* - When there are multiple JSON code blocks the function throws a `ParseError`
|
|
2920
2937
|
*
|
|
2921
|
-
*
|
|
2938
|
+
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
2939
|
+
* Note: There are multiple simmilar function:
|
|
2940
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2941
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2942
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2943
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2944
|
+
*
|
|
2945
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2946
|
+
* @throws {ParseError} if there is no valid JSON block in the markdown
|
|
2922
2947
|
*/
|
|
2923
|
-
function
|
|
2924
|
-
if (
|
|
2925
|
-
return
|
|
2948
|
+
function extractJsonBlock(markdown) {
|
|
2949
|
+
if (isValidJsonString(markdown)) {
|
|
2950
|
+
return markdown;
|
|
2926
2951
|
}
|
|
2927
|
-
|
|
2928
|
-
|
|
2952
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2953
|
+
var jsonBlocks = codeBlocks.filter(function (_a) {
|
|
2954
|
+
var content = _a.content;
|
|
2955
|
+
return isValidJsonString(content);
|
|
2956
|
+
});
|
|
2957
|
+
if (jsonBlocks.length === 0) {
|
|
2958
|
+
throw new Error('There is no valid JSON block in the markdown');
|
|
2929
2959
|
}
|
|
2930
|
-
|
|
2960
|
+
if (jsonBlocks.length > 1) {
|
|
2961
|
+
throw new Error('There are multiple JSON code blocks in the markdown');
|
|
2962
|
+
}
|
|
2963
|
+
return jsonBlocks[0].content;
|
|
2931
2964
|
}
|
|
2965
|
+
/**
|
|
2966
|
+
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
2967
|
+
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2968
|
+
*/
|
|
2932
2969
|
|
|
2933
2970
|
/**
|
|
2934
2971
|
* Just says that the variable is not used but should be kept
|
|
@@ -2951,23 +2988,6 @@
|
|
|
2951
2988
|
}
|
|
2952
2989
|
}
|
|
2953
2990
|
|
|
2954
|
-
/**
|
|
2955
|
-
* Just marks a place of place where should be something implemented
|
|
2956
|
-
* No side effects.
|
|
2957
|
-
*
|
|
2958
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2959
|
-
*
|
|
2960
|
-
* @param value any values
|
|
2961
|
-
* @returns void
|
|
2962
|
-
* @private within the repository
|
|
2963
|
-
*/
|
|
2964
|
-
function TODO_USE() {
|
|
2965
|
-
var value = [];
|
|
2966
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2967
|
-
value[_i] = arguments[_i];
|
|
2968
|
-
}
|
|
2969
|
-
}
|
|
2970
|
-
|
|
2971
2991
|
/**
|
|
2972
2992
|
* Replaces parameters in template with values from parameters object
|
|
2973
2993
|
*
|
|
@@ -3188,53 +3208,668 @@
|
|
|
3188
3208
|
}
|
|
3189
3209
|
|
|
3190
3210
|
/**
|
|
3191
|
-
* Counts number of words in the text
|
|
3192
|
-
*
|
|
3193
|
-
* @public exported from `@promptbook/utils`
|
|
3211
|
+
* Counts number of words in the text
|
|
3212
|
+
*
|
|
3213
|
+
* @public exported from `@promptbook/utils`
|
|
3214
|
+
*/
|
|
3215
|
+
function countWords(text) {
|
|
3216
|
+
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
3217
|
+
text = removeDiacritics(text);
|
|
3218
|
+
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3221
|
+
/**
|
|
3222
|
+
* Index of all counter functions
|
|
3223
|
+
*
|
|
3224
|
+
* @public exported from `@promptbook/utils`
|
|
3225
|
+
*/
|
|
3226
|
+
var CountUtils = {
|
|
3227
|
+
CHARACTERS: countCharacters,
|
|
3228
|
+
WORDS: countWords,
|
|
3229
|
+
SENTENCES: countSentences,
|
|
3230
|
+
PARAGRAPHS: countParagraphs,
|
|
3231
|
+
LINES: countLines,
|
|
3232
|
+
PAGES: countPages,
|
|
3233
|
+
};
|
|
3234
|
+
|
|
3235
|
+
/**
|
|
3236
|
+
* Function checkExpectations will check if the expectations on given value are met
|
|
3237
|
+
*
|
|
3238
|
+
* Note: There are two simmilar functions:
|
|
3239
|
+
* - `checkExpectations` which throws an error if the expectations are not met
|
|
3240
|
+
* - `isPassingExpectations` which returns a boolean
|
|
3241
|
+
*
|
|
3242
|
+
* @throws {ExpectError} if the expectations are not met
|
|
3243
|
+
* @returns {void} Nothing
|
|
3244
|
+
* @private internal function of `createPipelineExecutor`
|
|
3245
|
+
*/
|
|
3246
|
+
function checkExpectations(expectations, value) {
|
|
3247
|
+
var e_1, _a;
|
|
3248
|
+
try {
|
|
3249
|
+
for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3250
|
+
var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
|
|
3251
|
+
var amount = CountUtils[unit.toUpperCase()](value);
|
|
3252
|
+
if (min && amount < min) {
|
|
3253
|
+
throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
|
|
3254
|
+
} /* not else */
|
|
3255
|
+
if (max && amount > max) {
|
|
3256
|
+
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3261
|
+
finally {
|
|
3262
|
+
try {
|
|
3263
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3264
|
+
}
|
|
3265
|
+
finally { if (e_1) throw e_1.error; }
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
/**
|
|
3269
|
+
* Function checkExpectations will check if the expectations on given value are met
|
|
3270
|
+
*
|
|
3271
|
+
* Note: There are two simmilar functions:
|
|
3272
|
+
* - `checkExpectations` which throws an error if the expectations are not met
|
|
3273
|
+
* - `isPassingExpectations` which returns a boolean
|
|
3274
|
+
*
|
|
3275
|
+
* @returns {boolean} True if the expectations are met
|
|
3276
|
+
* @public exported from `@promptbook/core`
|
|
3277
|
+
*/
|
|
3278
|
+
function isPassingExpectations(expectations, value) {
|
|
3279
|
+
try {
|
|
3280
|
+
checkExpectations(expectations, value);
|
|
3281
|
+
return true;
|
|
3282
|
+
}
|
|
3283
|
+
catch (error) {
|
|
3284
|
+
if (!(error instanceof ExpectError)) {
|
|
3285
|
+
throw error;
|
|
3286
|
+
}
|
|
3287
|
+
return false;
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
/**
|
|
3291
|
+
* TODO: [💝] Unite object for expecting amount and format
|
|
3292
|
+
*/
|
|
3293
|
+
|
|
3294
|
+
/**
|
|
3295
|
+
* Just marks a place of place where should be something implemented
|
|
3296
|
+
* No side effects.
|
|
3297
|
+
*
|
|
3298
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
3299
|
+
*
|
|
3300
|
+
* @param value any values
|
|
3301
|
+
* @returns void
|
|
3302
|
+
* @private within the repository
|
|
3303
|
+
*/
|
|
3304
|
+
function TODO_USE() {
|
|
3305
|
+
var value = [];
|
|
3306
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3307
|
+
value[_i] = arguments[_i];
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
/**
|
|
3312
|
+
* @private @@@
|
|
3313
|
+
*/
|
|
3314
|
+
function getContextForTemplate(template) {
|
|
3315
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3316
|
+
return __generator(this, function (_a) {
|
|
3317
|
+
TODO_USE(template);
|
|
3318
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
3319
|
+
});
|
|
3320
|
+
});
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
/**
|
|
3324
|
+
* @private @@@
|
|
3325
|
+
*/
|
|
3326
|
+
function getKnowledgeForTemplate(preparedPipeline, template) {
|
|
3327
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3328
|
+
return __generator(this, function (_a) {
|
|
3329
|
+
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3330
|
+
TODO_USE(template);
|
|
3331
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3332
|
+
var content = _a.content;
|
|
3333
|
+
return "- ".concat(content);
|
|
3334
|
+
}).join('\n')];
|
|
3335
|
+
});
|
|
3336
|
+
});
|
|
3337
|
+
}
|
|
3338
|
+
|
|
3339
|
+
/**
|
|
3340
|
+
* @private @@@
|
|
3341
|
+
*/
|
|
3342
|
+
function getSamplesForTemplate(template) {
|
|
3343
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3344
|
+
return __generator(this, function (_a) {
|
|
3345
|
+
// TODO: [♨] Implement Better - use real index and keyword search
|
|
3346
|
+
TODO_USE(template);
|
|
3347
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
3348
|
+
});
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3351
|
+
|
|
3352
|
+
/**
|
|
3353
|
+
* @private @@@
|
|
3354
|
+
*/
|
|
3355
|
+
function getReservedParametersForTemplate(preparedPipeline, template, pipelineIdentification) {
|
|
3356
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3357
|
+
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3358
|
+
var e_1, _a;
|
|
3359
|
+
return __generator(this, function (_b) {
|
|
3360
|
+
switch (_b.label) {
|
|
3361
|
+
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
3362
|
+
case 1:
|
|
3363
|
+
context = _b.sent();
|
|
3364
|
+
return [4 /*yield*/, getKnowledgeForTemplate(preparedPipeline, template)];
|
|
3365
|
+
case 2:
|
|
3366
|
+
knowledge = _b.sent();
|
|
3367
|
+
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3368
|
+
case 3:
|
|
3369
|
+
samples = _b.sent();
|
|
3370
|
+
currentDate = new Date().toISOString();
|
|
3371
|
+
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3372
|
+
reservedParameters = {
|
|
3373
|
+
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3374
|
+
context: context,
|
|
3375
|
+
knowledge: knowledge,
|
|
3376
|
+
samples: samples,
|
|
3377
|
+
currentDate: currentDate,
|
|
3378
|
+
modelName: modelName,
|
|
3379
|
+
};
|
|
3380
|
+
_loop_1 = function (parameterName) {
|
|
3381
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
3382
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3383
|
+
}
|
|
3384
|
+
};
|
|
3385
|
+
try {
|
|
3386
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3387
|
+
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()) {
|
|
3388
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3389
|
+
_loop_1(parameterName);
|
|
3390
|
+
}
|
|
3391
|
+
}
|
|
3392
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3393
|
+
finally {
|
|
3394
|
+
try {
|
|
3395
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3396
|
+
}
|
|
3397
|
+
finally { if (e_1) throw e_1.error; }
|
|
3398
|
+
}
|
|
3399
|
+
return [2 /*return*/, reservedParameters];
|
|
3400
|
+
}
|
|
3401
|
+
});
|
|
3402
|
+
});
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
/**
|
|
3406
|
+
* @private @@@
|
|
3194
3407
|
*/
|
|
3195
|
-
function
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3408
|
+
function executeSingleTemplate(options) {
|
|
3409
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3410
|
+
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;
|
|
3411
|
+
var e_1, _f, _g;
|
|
3412
|
+
return __generator(this, function (_h) {
|
|
3413
|
+
switch (_h.label) {
|
|
3414
|
+
case 0:
|
|
3415
|
+
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;
|
|
3416
|
+
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3417
|
+
title = currentTemplate.title;
|
|
3418
|
+
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3419
|
+
return [4 /*yield*/, onProgress({
|
|
3420
|
+
name: name,
|
|
3421
|
+
title: title,
|
|
3422
|
+
isStarted: false,
|
|
3423
|
+
isDone: false,
|
|
3424
|
+
templateType: currentTemplate.templateType,
|
|
3425
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
3426
|
+
parameterValue: null,
|
|
3427
|
+
// <- [🍸]
|
|
3428
|
+
})];
|
|
3429
|
+
case 1:
|
|
3430
|
+
_h.sent();
|
|
3431
|
+
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3432
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3433
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3434
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
|
|
3435
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3436
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3437
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3438
|
+
.join(', '), "\n\n "); }));
|
|
3439
|
+
}
|
|
3440
|
+
_b = (_a = Object).freeze;
|
|
3441
|
+
_c = [{}];
|
|
3442
|
+
return [4 /*yield*/, getReservedParametersForTemplate(preparedPipeline, currentTemplate, pipelineIdentification)];
|
|
3443
|
+
case 2:
|
|
3444
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3445
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3446
|
+
parameters = {};
|
|
3447
|
+
_loop_1 = function (parameterName) {
|
|
3448
|
+
// Situation: Parameter is defined and used
|
|
3449
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3450
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
3451
|
+
}
|
|
3452
|
+
// Situation: Parameter is defined but NOT used
|
|
3453
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3454
|
+
// Situation: Parameter is NOT defined BUT used
|
|
3455
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3456
|
+
// Houston, we have a problem
|
|
3457
|
+
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
3458
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3459
|
+
}
|
|
3460
|
+
};
|
|
3461
|
+
try {
|
|
3462
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3463
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3464
|
+
parameterName = _e.value;
|
|
3465
|
+
_loop_1(parameterName);
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3469
|
+
finally {
|
|
3470
|
+
try {
|
|
3471
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3472
|
+
}
|
|
3473
|
+
finally { if (e_1) throw e_1.error; }
|
|
3474
|
+
}
|
|
3475
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3476
|
+
Object.freeze(parameters);
|
|
3477
|
+
result = null;
|
|
3478
|
+
resultString = null;
|
|
3479
|
+
expectError = null;
|
|
3480
|
+
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3481
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3482
|
+
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3483
|
+
.split('{content}')
|
|
3484
|
+
.join(currentTemplate.content);
|
|
3485
|
+
_loop_2 = function (attempt) {
|
|
3486
|
+
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;
|
|
3487
|
+
var e_2, _s, e_4, _t, e_3, _u;
|
|
3488
|
+
return __generator(this, function (_v) {
|
|
3489
|
+
switch (_v.label) {
|
|
3490
|
+
case 0:
|
|
3491
|
+
isJokerAttempt = attempt < 0;
|
|
3492
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3493
|
+
// TODO: [🧠] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3494
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
3495
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3496
|
+
}
|
|
3497
|
+
result = null;
|
|
3498
|
+
resultString = null;
|
|
3499
|
+
expectError = null;
|
|
3500
|
+
if (isJokerAttempt) {
|
|
3501
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
3502
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3503
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3504
|
+
}
|
|
3505
|
+
else {
|
|
3506
|
+
resultString = parameters[jokerParameterName];
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
_v.label = 1;
|
|
3510
|
+
case 1:
|
|
3511
|
+
_v.trys.push([1, 44, 45, 46]);
|
|
3512
|
+
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3513
|
+
_j = currentTemplate.templateType;
|
|
3514
|
+
switch (_j) {
|
|
3515
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3516
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3517
|
+
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
3518
|
+
case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
|
|
3519
|
+
}
|
|
3520
|
+
return [3 /*break*/, 25];
|
|
3521
|
+
case 2:
|
|
3522
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
3523
|
+
return [3 /*break*/, 26];
|
|
3524
|
+
case 3:
|
|
3525
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
|
|
3526
|
+
prompt = {
|
|
3527
|
+
title: currentTemplate.title,
|
|
3528
|
+
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3529
|
+
? preparedPipeline.pipelineUrl
|
|
3530
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3531
|
+
parameters: parameters,
|
|
3532
|
+
content: preparedContent,
|
|
3533
|
+
modelRequirements: modelRequirements,
|
|
3534
|
+
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3535
|
+
var name = _a.name;
|
|
3536
|
+
return name === currentTemplate.personaName;
|
|
3537
|
+
}) || {})), currentTemplate.expectations),
|
|
3538
|
+
format: currentTemplate.format,
|
|
3539
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3540
|
+
}; // <- TODO: Not very good type guard
|
|
3541
|
+
_k = modelRequirements.modelVariant;
|
|
3542
|
+
switch (_k) {
|
|
3543
|
+
case 'CHAT': return [3 /*break*/, 4];
|
|
3544
|
+
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3545
|
+
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3546
|
+
}
|
|
3547
|
+
return [3 /*break*/, 10];
|
|
3548
|
+
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3549
|
+
case 5:
|
|
3550
|
+
chatResult = _v.sent();
|
|
3551
|
+
// TODO: [🍬] Destroy chatThread
|
|
3552
|
+
result = chatResult;
|
|
3553
|
+
resultString = chatResult.content;
|
|
3554
|
+
return [3 /*break*/, 11];
|
|
3555
|
+
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3556
|
+
case 7:
|
|
3557
|
+
completionResult = _v.sent();
|
|
3558
|
+
result = completionResult;
|
|
3559
|
+
resultString = completionResult.content;
|
|
3560
|
+
return [3 /*break*/, 11];
|
|
3561
|
+
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3562
|
+
case 9:
|
|
3563
|
+
// TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
|
|
3564
|
+
embeddingResult = _v.sent();
|
|
3565
|
+
result = embeddingResult;
|
|
3566
|
+
resultString = embeddingResult.content.join(',');
|
|
3567
|
+
return [3 /*break*/, 11];
|
|
3568
|
+
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3569
|
+
case 11: return [3 /*break*/, 26];
|
|
3570
|
+
case 12:
|
|
3571
|
+
if (arrayableToArray(tools.script).length === 0) {
|
|
3572
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3573
|
+
}
|
|
3574
|
+
if (!currentTemplate.contentLanguage) {
|
|
3575
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3576
|
+
}
|
|
3577
|
+
// TODO: DRY [1]
|
|
3578
|
+
scriptPipelineExecutionErrors = [];
|
|
3579
|
+
_v.label = 13;
|
|
3580
|
+
case 13:
|
|
3581
|
+
_v.trys.push([13, 20, 21, 22]);
|
|
3582
|
+
_l = (e_2 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3583
|
+
_v.label = 14;
|
|
3584
|
+
case 14:
|
|
3585
|
+
if (!!_m.done) return [3 /*break*/, 19];
|
|
3586
|
+
scriptTools = _m.value;
|
|
3587
|
+
_v.label = 15;
|
|
3588
|
+
case 15:
|
|
3589
|
+
_v.trys.push([15, 17, , 18]);
|
|
3590
|
+
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3591
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
3592
|
+
script: preparedContent,
|
|
3593
|
+
parameters: parameters,
|
|
3594
|
+
}))];
|
|
3595
|
+
case 16:
|
|
3596
|
+
resultString = _v.sent();
|
|
3597
|
+
return [3 /*break*/, 19];
|
|
3598
|
+
case 17:
|
|
3599
|
+
error_1 = _v.sent();
|
|
3600
|
+
if (!(error_1 instanceof Error)) {
|
|
3601
|
+
throw error_1;
|
|
3602
|
+
}
|
|
3603
|
+
if (error_1 instanceof UnexpectedError) {
|
|
3604
|
+
throw error_1;
|
|
3605
|
+
}
|
|
3606
|
+
scriptPipelineExecutionErrors.push(error_1);
|
|
3607
|
+
return [3 /*break*/, 18];
|
|
3608
|
+
case 18:
|
|
3609
|
+
_m = _l.next();
|
|
3610
|
+
return [3 /*break*/, 14];
|
|
3611
|
+
case 19: return [3 /*break*/, 22];
|
|
3612
|
+
case 20:
|
|
3613
|
+
e_2_1 = _v.sent();
|
|
3614
|
+
e_2 = { error: e_2_1 };
|
|
3615
|
+
return [3 /*break*/, 22];
|
|
3616
|
+
case 21:
|
|
3617
|
+
try {
|
|
3618
|
+
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3619
|
+
}
|
|
3620
|
+
finally { if (e_2) throw e_2.error; }
|
|
3621
|
+
return [7 /*endfinally*/];
|
|
3622
|
+
case 22:
|
|
3623
|
+
if (resultString !== null) {
|
|
3624
|
+
return [3 /*break*/, 26];
|
|
3625
|
+
}
|
|
3626
|
+
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3627
|
+
throw scriptPipelineExecutionErrors[0];
|
|
3628
|
+
}
|
|
3629
|
+
else {
|
|
3630
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3631
|
+
.map(function (error) { return '- ' + error.message; })
|
|
3632
|
+
.join('\n\n')), "\n "); }));
|
|
3633
|
+
}
|
|
3634
|
+
case 23:
|
|
3635
|
+
if (tools.userInterface === undefined) {
|
|
3636
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3637
|
+
}
|
|
3638
|
+
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3639
|
+
promptTitle: currentTemplate.title,
|
|
3640
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3641
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3642
|
+
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
3643
|
+
placeholder: undefined,
|
|
3644
|
+
priority: priority,
|
|
3645
|
+
}))];
|
|
3646
|
+
case 24:
|
|
3647
|
+
// TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3648
|
+
resultString = _v.sent();
|
|
3649
|
+
return [3 /*break*/, 26];
|
|
3650
|
+
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3651
|
+
case 26:
|
|
3652
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3653
|
+
_v.label = 27;
|
|
3654
|
+
case 27:
|
|
3655
|
+
_v.trys.push([27, 41, 42, 43]);
|
|
3656
|
+
_o = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3657
|
+
_v.label = 28;
|
|
3658
|
+
case 28:
|
|
3659
|
+
if (!!_p.done) return [3 /*break*/, 40];
|
|
3660
|
+
functionName = _p.value;
|
|
3661
|
+
// TODO: DRY [1]
|
|
3662
|
+
scriptPipelineExecutionErrors = [];
|
|
3663
|
+
postprocessingError = null;
|
|
3664
|
+
_v.label = 29;
|
|
3665
|
+
case 29:
|
|
3666
|
+
_v.trys.push([29, 36, 37, 38]);
|
|
3667
|
+
_q = (e_3 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3668
|
+
_v.label = 30;
|
|
3669
|
+
case 30:
|
|
3670
|
+
if (!!_r.done) return [3 /*break*/, 35];
|
|
3671
|
+
scriptTools = _r.value;
|
|
3672
|
+
_v.label = 31;
|
|
3673
|
+
case 31:
|
|
3674
|
+
_v.trys.push([31, 33, , 34]);
|
|
3675
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
3676
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3677
|
+
script: "".concat(functionName, "(resultString)"),
|
|
3678
|
+
parameters: {
|
|
3679
|
+
resultString: resultString || '',
|
|
3680
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
3681
|
+
},
|
|
3682
|
+
})];
|
|
3683
|
+
case 32:
|
|
3684
|
+
resultString = _v.sent();
|
|
3685
|
+
postprocessingError = null;
|
|
3686
|
+
return [3 /*break*/, 35];
|
|
3687
|
+
case 33:
|
|
3688
|
+
error_2 = _v.sent();
|
|
3689
|
+
if (!(error_2 instanceof Error)) {
|
|
3690
|
+
throw error_2;
|
|
3691
|
+
}
|
|
3692
|
+
if (error_2 instanceof UnexpectedError) {
|
|
3693
|
+
throw error_2;
|
|
3694
|
+
}
|
|
3695
|
+
postprocessingError = error_2;
|
|
3696
|
+
scriptPipelineExecutionErrors.push(error_2);
|
|
3697
|
+
return [3 /*break*/, 34];
|
|
3698
|
+
case 34:
|
|
3699
|
+
_r = _q.next();
|
|
3700
|
+
return [3 /*break*/, 30];
|
|
3701
|
+
case 35: return [3 /*break*/, 38];
|
|
3702
|
+
case 36:
|
|
3703
|
+
e_3_1 = _v.sent();
|
|
3704
|
+
e_3 = { error: e_3_1 };
|
|
3705
|
+
return [3 /*break*/, 38];
|
|
3706
|
+
case 37:
|
|
3707
|
+
try {
|
|
3708
|
+
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3709
|
+
}
|
|
3710
|
+
finally { if (e_3) throw e_3.error; }
|
|
3711
|
+
return [7 /*endfinally*/];
|
|
3712
|
+
case 38:
|
|
3713
|
+
if (postprocessingError) {
|
|
3714
|
+
throw postprocessingError;
|
|
3715
|
+
}
|
|
3716
|
+
_v.label = 39;
|
|
3717
|
+
case 39:
|
|
3718
|
+
_p = _o.next();
|
|
3719
|
+
return [3 /*break*/, 28];
|
|
3720
|
+
case 40: return [3 /*break*/, 43];
|
|
3721
|
+
case 41:
|
|
3722
|
+
e_4_1 = _v.sent();
|
|
3723
|
+
e_4 = { error: e_4_1 };
|
|
3724
|
+
return [3 /*break*/, 43];
|
|
3725
|
+
case 42:
|
|
3726
|
+
try {
|
|
3727
|
+
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3728
|
+
}
|
|
3729
|
+
finally { if (e_4) throw e_4.error; }
|
|
3730
|
+
return [7 /*endfinally*/];
|
|
3731
|
+
case 43:
|
|
3732
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
3733
|
+
if (currentTemplate.format) {
|
|
3734
|
+
if (currentTemplate.format === 'JSON') {
|
|
3735
|
+
if (!isValidJsonString(resultString || '')) {
|
|
3736
|
+
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3737
|
+
try {
|
|
3738
|
+
resultString = extractJsonBlock(resultString || '');
|
|
3739
|
+
}
|
|
3740
|
+
catch (error) {
|
|
3741
|
+
keepUnused(error);
|
|
3742
|
+
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3743
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3744
|
+
}
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
else {
|
|
3748
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
3752
|
+
if (currentTemplate.expectations) {
|
|
3753
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3754
|
+
}
|
|
3755
|
+
return [2 /*return*/, "break-attempts"];
|
|
3756
|
+
case 44:
|
|
3757
|
+
error_3 = _v.sent();
|
|
3758
|
+
if (!(error_3 instanceof ExpectError)) {
|
|
3759
|
+
throw error_3;
|
|
3760
|
+
}
|
|
3761
|
+
expectError = error_3;
|
|
3762
|
+
return [3 /*break*/, 46];
|
|
3763
|
+
case 45:
|
|
3764
|
+
if (!isJokerAttempt &&
|
|
3765
|
+
currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
|
|
3766
|
+
prompt
|
|
3767
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3768
|
+
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
3769
|
+
) {
|
|
3770
|
+
// TODO: [🧠] Maybe put other templateTypes into report
|
|
3771
|
+
$executionReport.promptExecutions.push({
|
|
3772
|
+
prompt: __assign({}, prompt),
|
|
3773
|
+
result: result || undefined,
|
|
3774
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3775
|
+
});
|
|
3776
|
+
}
|
|
3777
|
+
return [7 /*endfinally*/];
|
|
3778
|
+
case 46:
|
|
3779
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3780
|
+
throw new PipelineExecutionError(spaceTrim.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
|
|
3781
|
+
.split('\n')
|
|
3782
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3783
|
+
.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) || '')
|
|
3784
|
+
.split('\n')
|
|
3785
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3786
|
+
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3787
|
+
? 'null'
|
|
3788
|
+
: resultString
|
|
3789
|
+
.split('\n')
|
|
3790
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3791
|
+
.join('\n')), "\n ---\n "); }));
|
|
3792
|
+
}
|
|
3793
|
+
return [2 /*return*/];
|
|
3794
|
+
}
|
|
3795
|
+
});
|
|
3796
|
+
};
|
|
3797
|
+
attempt = -jokerParameterNames.length;
|
|
3798
|
+
_h.label = 3;
|
|
3799
|
+
case 3:
|
|
3800
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 6];
|
|
3801
|
+
return [5 /*yield**/, _loop_2(attempt)];
|
|
3802
|
+
case 4:
|
|
3803
|
+
state_1 = _h.sent();
|
|
3804
|
+
switch (state_1) {
|
|
3805
|
+
case "break-attempts": return [3 /*break*/, 6];
|
|
3806
|
+
}
|
|
3807
|
+
_h.label = 5;
|
|
3808
|
+
case 5:
|
|
3809
|
+
attempt++;
|
|
3810
|
+
return [3 /*break*/, 3];
|
|
3811
|
+
case 6:
|
|
3812
|
+
//------------------------------------
|
|
3813
|
+
/*
|
|
3814
|
+
|
|
3815
|
+
|
|
3816
|
+
|
|
3817
|
+
|
|
3818
|
+
|
|
3819
|
+
|
|
3820
|
+
|
|
3821
|
+
|
|
3822
|
+
|
|
3823
|
+
*/
|
|
3824
|
+
//------------------------------------
|
|
3825
|
+
if (resultString === null) {
|
|
3826
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3827
|
+
}
|
|
3828
|
+
return [4 /*yield*/, onProgress({
|
|
3829
|
+
name: name,
|
|
3830
|
+
title: title,
|
|
3831
|
+
isStarted: true,
|
|
3832
|
+
isDone: true,
|
|
3833
|
+
templateType: currentTemplate.templateType,
|
|
3834
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
3835
|
+
parameterValue: resultString,
|
|
3836
|
+
// <- [🍸]
|
|
3837
|
+
})];
|
|
3838
|
+
case 7:
|
|
3839
|
+
_h.sent();
|
|
3840
|
+
return [2 /*return*/, Object.freeze((_g = {},
|
|
3841
|
+
_g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3842
|
+
_g))];
|
|
3843
|
+
}
|
|
3844
|
+
});
|
|
3845
|
+
});
|
|
3199
3846
|
}
|
|
3200
|
-
|
|
3201
3847
|
/**
|
|
3202
|
-
*
|
|
3203
|
-
*
|
|
3204
|
-
* @public exported from `@promptbook/utils`
|
|
3848
|
+
* TODO: [🤹♂️]
|
|
3205
3849
|
*/
|
|
3206
|
-
var CountUtils = {
|
|
3207
|
-
CHARACTERS: countCharacters,
|
|
3208
|
-
WORDS: countWords,
|
|
3209
|
-
SENTENCES: countSentences,
|
|
3210
|
-
PARAGRAPHS: countParagraphs,
|
|
3211
|
-
LINES: countLines,
|
|
3212
|
-
PAGES: countPages,
|
|
3213
|
-
};
|
|
3214
3850
|
|
|
3215
3851
|
/**
|
|
3216
|
-
*
|
|
3217
|
-
*
|
|
3218
|
-
* Note: There are two simmilar functions:
|
|
3219
|
-
* - `checkExpectations` which throws an error if the expectations are not met
|
|
3220
|
-
* - `isPassingExpectations` which returns a boolean
|
|
3221
|
-
*
|
|
3222
|
-
* @throws {ExpectError} if the expectations are not met
|
|
3223
|
-
* @returns {void} Nothing
|
|
3224
|
-
* @private internal function of `createPipelineExecutor`
|
|
3852
|
+
* @private @@@
|
|
3225
3853
|
*/
|
|
3226
|
-
function
|
|
3854
|
+
function filterJustOutputParameters(preparedPipeline, parametersToPass, $warnings, pipelineIdentification) {
|
|
3227
3855
|
var e_1, _a;
|
|
3856
|
+
var outputParameters = {};
|
|
3857
|
+
var _loop_1 = function (parameter) {
|
|
3858
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3859
|
+
// [4]
|
|
3860
|
+
$warnings.push(new PipelineExecutionError(spaceTrim.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 "); })));
|
|
3861
|
+
return "continue";
|
|
3862
|
+
}
|
|
3863
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3864
|
+
};
|
|
3228
3865
|
try {
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
var
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
3237
|
-
}
|
|
3866
|
+
// Note: Filter ONLY output parameters
|
|
3867
|
+
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
3868
|
+
var isOutput = _a.isOutput;
|
|
3869
|
+
return isOutput;
|
|
3870
|
+
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3871
|
+
var parameter = _c.value;
|
|
3872
|
+
_loop_1(parameter);
|
|
3238
3873
|
}
|
|
3239
3874
|
}
|
|
3240
3875
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -3244,32 +3879,8 @@
|
|
|
3244
3879
|
}
|
|
3245
3880
|
finally { if (e_1) throw e_1.error; }
|
|
3246
3881
|
}
|
|
3882
|
+
return outputParameters;
|
|
3247
3883
|
}
|
|
3248
|
-
/**
|
|
3249
|
-
* Function checkExpectations will check if the expectations on given value are met
|
|
3250
|
-
*
|
|
3251
|
-
* Note: There are two simmilar functions:
|
|
3252
|
-
* - `checkExpectations` which throws an error if the expectations are not met
|
|
3253
|
-
* - `isPassingExpectations` which returns a boolean
|
|
3254
|
-
*
|
|
3255
|
-
* @returns {boolean} True if the expectations are met
|
|
3256
|
-
* @public exported from `@promptbook/core`
|
|
3257
|
-
*/
|
|
3258
|
-
function isPassingExpectations(expectations, value) {
|
|
3259
|
-
try {
|
|
3260
|
-
checkExpectations(expectations, value);
|
|
3261
|
-
return true;
|
|
3262
|
-
}
|
|
3263
|
-
catch (error) {
|
|
3264
|
-
if (!(error instanceof ExpectError)) {
|
|
3265
|
-
throw error;
|
|
3266
|
-
}
|
|
3267
|
-
return false;
|
|
3268
|
-
}
|
|
3269
|
-
}
|
|
3270
|
-
/**
|
|
3271
|
-
* TODO: [💝] Unite object for expecting amount and format
|
|
3272
|
-
*/
|
|
3273
3884
|
|
|
3274
3885
|
/**
|
|
3275
3886
|
* Creates executor function from pipeline and execution tools.
|
|
@@ -3303,558 +3914,6 @@
|
|
|
3303
3914
|
console.warn(spaceTrim.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 "); }));
|
|
3304
3915
|
}
|
|
3305
3916
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
3306
|
-
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
3307
|
-
function getContextForTemplate(template) {
|
|
3308
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3309
|
-
return __generator(this, function (_a) {
|
|
3310
|
-
TODO_USE(template);
|
|
3311
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
3312
|
-
});
|
|
3313
|
-
});
|
|
3314
|
-
}
|
|
3315
|
-
function getKnowledgeForTemplate(template) {
|
|
3316
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3317
|
-
return __generator(this, function (_a) {
|
|
3318
|
-
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3319
|
-
TODO_USE(template);
|
|
3320
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
3321
|
-
var content = _a.content;
|
|
3322
|
-
return "- ".concat(content);
|
|
3323
|
-
}).join('\n')];
|
|
3324
|
-
});
|
|
3325
|
-
});
|
|
3326
|
-
}
|
|
3327
|
-
function getSamplesForTemplate(template) {
|
|
3328
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3329
|
-
return __generator(this, function (_a) {
|
|
3330
|
-
// TODO: [♨] Implement Better - use real index and keyword search
|
|
3331
|
-
TODO_USE(template);
|
|
3332
|
-
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
3333
|
-
});
|
|
3334
|
-
});
|
|
3335
|
-
}
|
|
3336
|
-
function getReservedParametersForTemplate(template) {
|
|
3337
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3338
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_3, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3339
|
-
var e_3, _a;
|
|
3340
|
-
return __generator(this, function (_b) {
|
|
3341
|
-
switch (_b.label) {
|
|
3342
|
-
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
3343
|
-
case 1:
|
|
3344
|
-
context = _b.sent();
|
|
3345
|
-
return [4 /*yield*/, getKnowledgeForTemplate(template)];
|
|
3346
|
-
case 2:
|
|
3347
|
-
knowledge = _b.sent();
|
|
3348
|
-
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
3349
|
-
case 3:
|
|
3350
|
-
samples = _b.sent();
|
|
3351
|
-
currentDate = new Date().toISOString();
|
|
3352
|
-
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
3353
|
-
reservedParameters = {
|
|
3354
|
-
content: RESERVED_PARAMETER_RESTRICTED,
|
|
3355
|
-
context: context,
|
|
3356
|
-
knowledge: knowledge,
|
|
3357
|
-
samples: samples,
|
|
3358
|
-
currentDate: currentDate,
|
|
3359
|
-
modelName: modelName,
|
|
3360
|
-
};
|
|
3361
|
-
_loop_3 = function (parameterName) {
|
|
3362
|
-
if (reservedParameters[parameterName] === undefined) {
|
|
3363
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3364
|
-
}
|
|
3365
|
-
};
|
|
3366
|
-
try {
|
|
3367
|
-
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
3368
|
-
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()) {
|
|
3369
|
-
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
3370
|
-
_loop_3(parameterName);
|
|
3371
|
-
}
|
|
3372
|
-
}
|
|
3373
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
3374
|
-
finally {
|
|
3375
|
-
try {
|
|
3376
|
-
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
3377
|
-
}
|
|
3378
|
-
finally { if (e_3) throw e_3.error; }
|
|
3379
|
-
}
|
|
3380
|
-
return [2 /*return*/, reservedParameters];
|
|
3381
|
-
}
|
|
3382
|
-
});
|
|
3383
|
-
});
|
|
3384
|
-
}
|
|
3385
|
-
function executeSingleTemplate(currentTemplate) {
|
|
3386
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3387
|
-
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;
|
|
3388
|
-
var e_4, _f, _g;
|
|
3389
|
-
return __generator(this, function (_h) {
|
|
3390
|
-
switch (_h.label) {
|
|
3391
|
-
case 0:
|
|
3392
|
-
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3393
|
-
title = currentTemplate.title;
|
|
3394
|
-
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3395
|
-
if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
3396
|
-
progress_1 = {
|
|
3397
|
-
name: name,
|
|
3398
|
-
title: title,
|
|
3399
|
-
isStarted: false,
|
|
3400
|
-
isDone: false,
|
|
3401
|
-
templateType: currentTemplate.templateType,
|
|
3402
|
-
parameterName: currentTemplate.resultingParameterName,
|
|
3403
|
-
parameterValue: null,
|
|
3404
|
-
// <- [3]
|
|
3405
|
-
};
|
|
3406
|
-
if (isReturned) {
|
|
3407
|
-
throw new UnexpectedError(spaceTrim.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)
|
|
3408
|
-
.split('\n')
|
|
3409
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3410
|
-
.join('\n')), "\n "); }));
|
|
3411
|
-
}
|
|
3412
|
-
return [4 /*yield*/, onProgress(progress_1)];
|
|
3413
|
-
case 1:
|
|
3414
|
-
_h.sent();
|
|
3415
|
-
_h.label = 2;
|
|
3416
|
-
case 2:
|
|
3417
|
-
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3418
|
-
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3419
|
-
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3420
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
|
|
3421
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3422
|
-
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3423
|
-
.map(function (name) { return "{".concat(name, "}"); })
|
|
3424
|
-
.join(', '), "\n\n "); }));
|
|
3425
|
-
}
|
|
3426
|
-
_b = (_a = Object).freeze;
|
|
3427
|
-
_c = [{}];
|
|
3428
|
-
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
3429
|
-
case 3:
|
|
3430
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3431
|
-
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
3432
|
-
parameters = {};
|
|
3433
|
-
_loop_4 = function (parameterName) {
|
|
3434
|
-
// Situation: Parameter is defined and used
|
|
3435
|
-
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3436
|
-
parameters[parameterName] = definedParameters[parameterName];
|
|
3437
|
-
}
|
|
3438
|
-
// Situation: Parameter is defined but NOT used
|
|
3439
|
-
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
|
|
3440
|
-
// Situation: Parameter is NOT defined BUT used
|
|
3441
|
-
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
3442
|
-
// Houston, we have a problem
|
|
3443
|
-
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
3444
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3445
|
-
}
|
|
3446
|
-
};
|
|
3447
|
-
try {
|
|
3448
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
3449
|
-
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3450
|
-
parameterName = _e.value;
|
|
3451
|
-
_loop_4(parameterName);
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3454
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
3455
|
-
finally {
|
|
3456
|
-
try {
|
|
3457
|
-
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
3458
|
-
}
|
|
3459
|
-
finally { if (e_4) throw e_4.error; }
|
|
3460
|
-
}
|
|
3461
|
-
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3462
|
-
Object.freeze(parameters);
|
|
3463
|
-
result = null;
|
|
3464
|
-
resultString = null;
|
|
3465
|
-
expectError = null;
|
|
3466
|
-
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3467
|
-
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3468
|
-
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3469
|
-
.split('{content}')
|
|
3470
|
-
.join(currentTemplate.content);
|
|
3471
|
-
_loop_5 = function (attempt) {
|
|
3472
|
-
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;
|
|
3473
|
-
var e_5, _s, e_7, _t, e_6, _u;
|
|
3474
|
-
return __generator(this, function (_v) {
|
|
3475
|
-
switch (_v.label) {
|
|
3476
|
-
case 0:
|
|
3477
|
-
isJokerAttempt = attempt < 0;
|
|
3478
|
-
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3479
|
-
if (isJokerAttempt && !jokerParameterName) {
|
|
3480
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3481
|
-
}
|
|
3482
|
-
result = null;
|
|
3483
|
-
resultString = null;
|
|
3484
|
-
expectError = null;
|
|
3485
|
-
if (isJokerAttempt) {
|
|
3486
|
-
if (parameters[jokerParameterName] === undefined) {
|
|
3487
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3488
|
-
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3489
|
-
}
|
|
3490
|
-
else {
|
|
3491
|
-
resultString = parameters[jokerParameterName];
|
|
3492
|
-
}
|
|
3493
|
-
}
|
|
3494
|
-
_v.label = 1;
|
|
3495
|
-
case 1:
|
|
3496
|
-
_v.trys.push([1, 44, 45, 46]);
|
|
3497
|
-
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3498
|
-
_j = currentTemplate.templateType;
|
|
3499
|
-
switch (_j) {
|
|
3500
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3501
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3502
|
-
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
3503
|
-
case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
|
|
3504
|
-
}
|
|
3505
|
-
return [3 /*break*/, 25];
|
|
3506
|
-
case 2:
|
|
3507
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3508
|
-
return [3 /*break*/, 26];
|
|
3509
|
-
case 3:
|
|
3510
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (pipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
|
|
3511
|
-
prompt = {
|
|
3512
|
-
title: currentTemplate.title,
|
|
3513
|
-
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3514
|
-
? preparedPipeline.pipelineUrl
|
|
3515
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3516
|
-
parameters: parameters,
|
|
3517
|
-
content: preparedContent,
|
|
3518
|
-
modelRequirements: modelRequirements,
|
|
3519
|
-
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3520
|
-
var name = _a.name;
|
|
3521
|
-
return name === currentTemplate.personaName;
|
|
3522
|
-
}) || {})), currentTemplate.expectations),
|
|
3523
|
-
format: currentTemplate.format,
|
|
3524
|
-
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3525
|
-
}; // <- TODO: Not very good type guard
|
|
3526
|
-
_k = modelRequirements.modelVariant;
|
|
3527
|
-
switch (_k) {
|
|
3528
|
-
case 'CHAT': return [3 /*break*/, 4];
|
|
3529
|
-
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3530
|
-
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3531
|
-
}
|
|
3532
|
-
return [3 /*break*/, 10];
|
|
3533
|
-
case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
|
|
3534
|
-
case 5:
|
|
3535
|
-
chatResult = _v.sent();
|
|
3536
|
-
// TODO: [🍬] Destroy chatThread
|
|
3537
|
-
result = chatResult;
|
|
3538
|
-
resultString = chatResult.content;
|
|
3539
|
-
return [3 /*break*/, 11];
|
|
3540
|
-
case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
|
|
3541
|
-
case 7:
|
|
3542
|
-
completionResult = _v.sent();
|
|
3543
|
-
result = completionResult;
|
|
3544
|
-
resultString = completionResult.content;
|
|
3545
|
-
return [3 /*break*/, 11];
|
|
3546
|
-
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
|
|
3547
|
-
case 9:
|
|
3548
|
-
embeddingResult = _v.sent();
|
|
3549
|
-
result = embeddingResult;
|
|
3550
|
-
resultString = embeddingResult.content.join(',');
|
|
3551
|
-
return [3 /*break*/, 11];
|
|
3552
|
-
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements
|
|
3553
|
-
.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3554
|
-
case 11: return [3 /*break*/, 26];
|
|
3555
|
-
case 12:
|
|
3556
|
-
if (arrayableToArray(tools.script).length === 0) {
|
|
3557
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3558
|
-
}
|
|
3559
|
-
if (!currentTemplate.contentLanguage) {
|
|
3560
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3561
|
-
}
|
|
3562
|
-
// TODO: DRY [1]
|
|
3563
|
-
scriptPipelineExecutionErrors = [];
|
|
3564
|
-
_v.label = 13;
|
|
3565
|
-
case 13:
|
|
3566
|
-
_v.trys.push([13, 20, 21, 22]);
|
|
3567
|
-
_l = (e_5 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
|
|
3568
|
-
_v.label = 14;
|
|
3569
|
-
case 14:
|
|
3570
|
-
if (!!_m.done) return [3 /*break*/, 19];
|
|
3571
|
-
scriptTools = _m.value;
|
|
3572
|
-
_v.label = 15;
|
|
3573
|
-
case 15:
|
|
3574
|
-
_v.trys.push([15, 17, , 18]);
|
|
3575
|
-
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3576
|
-
scriptLanguage: currentTemplate.contentLanguage,
|
|
3577
|
-
script: preparedContent,
|
|
3578
|
-
parameters: parameters,
|
|
3579
|
-
}))];
|
|
3580
|
-
case 16:
|
|
3581
|
-
resultString = _v.sent();
|
|
3582
|
-
return [3 /*break*/, 19];
|
|
3583
|
-
case 17:
|
|
3584
|
-
error_2 = _v.sent();
|
|
3585
|
-
if (!(error_2 instanceof Error)) {
|
|
3586
|
-
throw error_2;
|
|
3587
|
-
}
|
|
3588
|
-
if (error_2 instanceof UnexpectedError) {
|
|
3589
|
-
throw error_2;
|
|
3590
|
-
}
|
|
3591
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3592
|
-
return [3 /*break*/, 18];
|
|
3593
|
-
case 18:
|
|
3594
|
-
_m = _l.next();
|
|
3595
|
-
return [3 /*break*/, 14];
|
|
3596
|
-
case 19: return [3 /*break*/, 22];
|
|
3597
|
-
case 20:
|
|
3598
|
-
e_5_1 = _v.sent();
|
|
3599
|
-
e_5 = { error: e_5_1 };
|
|
3600
|
-
return [3 /*break*/, 22];
|
|
3601
|
-
case 21:
|
|
3602
|
-
try {
|
|
3603
|
-
if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
|
|
3604
|
-
}
|
|
3605
|
-
finally { if (e_5) throw e_5.error; }
|
|
3606
|
-
return [7 /*endfinally*/];
|
|
3607
|
-
case 22:
|
|
3608
|
-
if (resultString !== null) {
|
|
3609
|
-
return [3 /*break*/, 26];
|
|
3610
|
-
}
|
|
3611
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3612
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3613
|
-
}
|
|
3614
|
-
else {
|
|
3615
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block(scriptPipelineExecutionErrors
|
|
3616
|
-
.map(function (error) { return '- ' + error.message; })
|
|
3617
|
-
.join('\n\n')), "\n "); }));
|
|
3618
|
-
}
|
|
3619
|
-
case 23:
|
|
3620
|
-
if (tools.userInterface === undefined) {
|
|
3621
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3622
|
-
}
|
|
3623
|
-
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3624
|
-
promptTitle: currentTemplate.title,
|
|
3625
|
-
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3626
|
-
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3627
|
-
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
3628
|
-
placeholder: undefined,
|
|
3629
|
-
priority: priority,
|
|
3630
|
-
}))];
|
|
3631
|
-
case 24:
|
|
3632
|
-
// TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3633
|
-
resultString = _v.sent();
|
|
3634
|
-
return [3 /*break*/, 26];
|
|
3635
|
-
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3636
|
-
case 26:
|
|
3637
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3638
|
-
_v.label = 27;
|
|
3639
|
-
case 27:
|
|
3640
|
-
_v.trys.push([27, 41, 42, 43]);
|
|
3641
|
-
_o = (e_7 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
|
|
3642
|
-
_v.label = 28;
|
|
3643
|
-
case 28:
|
|
3644
|
-
if (!!_p.done) return [3 /*break*/, 40];
|
|
3645
|
-
functionName = _p.value;
|
|
3646
|
-
// TODO: DRY [1]
|
|
3647
|
-
scriptPipelineExecutionErrors = [];
|
|
3648
|
-
postprocessingError = null;
|
|
3649
|
-
_v.label = 29;
|
|
3650
|
-
case 29:
|
|
3651
|
-
_v.trys.push([29, 36, 37, 38]);
|
|
3652
|
-
_q = (e_6 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
|
|
3653
|
-
_v.label = 30;
|
|
3654
|
-
case 30:
|
|
3655
|
-
if (!!_r.done) return [3 /*break*/, 35];
|
|
3656
|
-
scriptTools = _r.value;
|
|
3657
|
-
_v.label = 31;
|
|
3658
|
-
case 31:
|
|
3659
|
-
_v.trys.push([31, 33, , 34]);
|
|
3660
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
3661
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3662
|
-
script: "".concat(functionName, "(resultString)"),
|
|
3663
|
-
parameters: {
|
|
3664
|
-
resultString: resultString || '',
|
|
3665
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
3666
|
-
},
|
|
3667
|
-
})];
|
|
3668
|
-
case 32:
|
|
3669
|
-
resultString = _v.sent();
|
|
3670
|
-
postprocessingError = null;
|
|
3671
|
-
return [3 /*break*/, 35];
|
|
3672
|
-
case 33:
|
|
3673
|
-
error_3 = _v.sent();
|
|
3674
|
-
if (!(error_3 instanceof Error)) {
|
|
3675
|
-
throw error_3;
|
|
3676
|
-
}
|
|
3677
|
-
if (error_3 instanceof UnexpectedError) {
|
|
3678
|
-
throw error_3;
|
|
3679
|
-
}
|
|
3680
|
-
postprocessingError = error_3;
|
|
3681
|
-
scriptPipelineExecutionErrors.push(error_3);
|
|
3682
|
-
return [3 /*break*/, 34];
|
|
3683
|
-
case 34:
|
|
3684
|
-
_r = _q.next();
|
|
3685
|
-
return [3 /*break*/, 30];
|
|
3686
|
-
case 35: return [3 /*break*/, 38];
|
|
3687
|
-
case 36:
|
|
3688
|
-
e_6_1 = _v.sent();
|
|
3689
|
-
e_6 = { error: e_6_1 };
|
|
3690
|
-
return [3 /*break*/, 38];
|
|
3691
|
-
case 37:
|
|
3692
|
-
try {
|
|
3693
|
-
if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
|
|
3694
|
-
}
|
|
3695
|
-
finally { if (e_6) throw e_6.error; }
|
|
3696
|
-
return [7 /*endfinally*/];
|
|
3697
|
-
case 38:
|
|
3698
|
-
if (postprocessingError) {
|
|
3699
|
-
throw postprocessingError;
|
|
3700
|
-
}
|
|
3701
|
-
_v.label = 39;
|
|
3702
|
-
case 39:
|
|
3703
|
-
_p = _o.next();
|
|
3704
|
-
return [3 /*break*/, 28];
|
|
3705
|
-
case 40: return [3 /*break*/, 43];
|
|
3706
|
-
case 41:
|
|
3707
|
-
e_7_1 = _v.sent();
|
|
3708
|
-
e_7 = { error: e_7_1 };
|
|
3709
|
-
return [3 /*break*/, 43];
|
|
3710
|
-
case 42:
|
|
3711
|
-
try {
|
|
3712
|
-
if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
|
|
3713
|
-
}
|
|
3714
|
-
finally { if (e_7) throw e_7.error; }
|
|
3715
|
-
return [7 /*endfinally*/];
|
|
3716
|
-
case 43:
|
|
3717
|
-
// TODO: [💝] Unite object for expecting amount and format
|
|
3718
|
-
if (currentTemplate.format) {
|
|
3719
|
-
if (currentTemplate.format === 'JSON') {
|
|
3720
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3721
|
-
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3722
|
-
try {
|
|
3723
|
-
resultString = extractJsonBlock(resultString || '');
|
|
3724
|
-
}
|
|
3725
|
-
catch (error) {
|
|
3726
|
-
keepUnused(error);
|
|
3727
|
-
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3728
|
-
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3729
|
-
}
|
|
3730
|
-
}
|
|
3731
|
-
}
|
|
3732
|
-
else {
|
|
3733
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3734
|
-
}
|
|
3735
|
-
}
|
|
3736
|
-
// TODO: [💝] Unite object for expecting amount and format
|
|
3737
|
-
if (currentTemplate.expectations) {
|
|
3738
|
-
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3739
|
-
}
|
|
3740
|
-
return [2 /*return*/, "break-attempts"];
|
|
3741
|
-
case 44:
|
|
3742
|
-
error_4 = _v.sent();
|
|
3743
|
-
if (!(error_4 instanceof ExpectError)) {
|
|
3744
|
-
throw error_4;
|
|
3745
|
-
}
|
|
3746
|
-
expectError = error_4;
|
|
3747
|
-
return [3 /*break*/, 46];
|
|
3748
|
-
case 45:
|
|
3749
|
-
if (!isJokerAttempt &&
|
|
3750
|
-
currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
|
|
3751
|
-
prompt
|
|
3752
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3753
|
-
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
3754
|
-
) {
|
|
3755
|
-
// TODO: [🧠] Maybe put other templateTypes into report
|
|
3756
|
-
executionReport.promptExecutions.push({
|
|
3757
|
-
prompt: __assign({}, prompt),
|
|
3758
|
-
result: result || undefined,
|
|
3759
|
-
error: expectError === null ? undefined : serializeError(expectError),
|
|
3760
|
-
});
|
|
3761
|
-
}
|
|
3762
|
-
return [7 /*endfinally*/];
|
|
3763
|
-
case 46:
|
|
3764
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3765
|
-
throw new PipelineExecutionError(spaceTrim.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
|
|
3766
|
-
.split('\n')
|
|
3767
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3768
|
-
.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) || '')
|
|
3769
|
-
.split('\n')
|
|
3770
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3771
|
-
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3772
|
-
? 'null'
|
|
3773
|
-
: resultString
|
|
3774
|
-
.split('\n')
|
|
3775
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3776
|
-
.join('\n')), "\n ---\n "); }));
|
|
3777
|
-
}
|
|
3778
|
-
return [2 /*return*/];
|
|
3779
|
-
}
|
|
3780
|
-
});
|
|
3781
|
-
};
|
|
3782
|
-
attempt = -jokerParameterNames.length;
|
|
3783
|
-
_h.label = 4;
|
|
3784
|
-
case 4:
|
|
3785
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/, 7];
|
|
3786
|
-
return [5 /*yield**/, _loop_5(attempt)];
|
|
3787
|
-
case 5:
|
|
3788
|
-
state_2 = _h.sent();
|
|
3789
|
-
switch (state_2) {
|
|
3790
|
-
case "break-attempts": return [3 /*break*/, 7];
|
|
3791
|
-
}
|
|
3792
|
-
_h.label = 6;
|
|
3793
|
-
case 6:
|
|
3794
|
-
attempt++;
|
|
3795
|
-
return [3 /*break*/, 4];
|
|
3796
|
-
case 7:
|
|
3797
|
-
if (resultString === null) {
|
|
3798
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3799
|
-
}
|
|
3800
|
-
if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 9]; /* <- [3] */
|
|
3801
|
-
progress_2 = {
|
|
3802
|
-
name: name,
|
|
3803
|
-
title: title,
|
|
3804
|
-
isStarted: true,
|
|
3805
|
-
isDone: true,
|
|
3806
|
-
templateType: currentTemplate.templateType,
|
|
3807
|
-
parameterName: currentTemplate.resultingParameterName,
|
|
3808
|
-
parameterValue: resultString,
|
|
3809
|
-
// <- [3]
|
|
3810
|
-
};
|
|
3811
|
-
if (isReturned) {
|
|
3812
|
-
throw new UnexpectedError(spaceTrim.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)
|
|
3813
|
-
.split('\n')
|
|
3814
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3815
|
-
.join('\n')), "\n\n "); }));
|
|
3816
|
-
}
|
|
3817
|
-
return [4 /*yield*/, onProgress(progress_2)];
|
|
3818
|
-
case 8:
|
|
3819
|
-
_h.sent();
|
|
3820
|
-
_h.label = 9;
|
|
3821
|
-
case 9:
|
|
3822
|
-
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)));
|
|
3823
|
-
return [2 /*return*/];
|
|
3824
|
-
}
|
|
3825
|
-
});
|
|
3826
|
-
});
|
|
3827
|
-
}
|
|
3828
|
-
function filterJustOutputParameters() {
|
|
3829
|
-
var e_8, _a;
|
|
3830
|
-
var outputParameters = {};
|
|
3831
|
-
var _loop_6 = function (parameter) {
|
|
3832
|
-
if (parametersToPass[parameter.name] === undefined) {
|
|
3833
|
-
// [4]
|
|
3834
|
-
warnings.push(new PipelineExecutionError(spaceTrim.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 "); })));
|
|
3835
|
-
return "continue";
|
|
3836
|
-
}
|
|
3837
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3838
|
-
};
|
|
3839
|
-
try {
|
|
3840
|
-
// Note: Filter ONLY output parameters
|
|
3841
|
-
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
3842
|
-
var isOutput = _a.isOutput;
|
|
3843
|
-
return isOutput;
|
|
3844
|
-
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3845
|
-
var parameter = _c.value;
|
|
3846
|
-
_loop_6(parameter);
|
|
3847
|
-
}
|
|
3848
|
-
}
|
|
3849
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
3850
|
-
finally {
|
|
3851
|
-
try {
|
|
3852
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3853
|
-
}
|
|
3854
|
-
finally { if (e_8) throw e_8.error; }
|
|
3855
|
-
}
|
|
3856
|
-
return outputParameters;
|
|
3857
|
-
}
|
|
3858
3917
|
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;
|
|
3859
3918
|
var e_1, _e, e_2, _f;
|
|
3860
3919
|
return __generator(this, function (_g) {
|
|
@@ -4036,14 +4095,35 @@
|
|
|
4036
4095
|
.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 "); }));
|
|
4037
4096
|
case 1:
|
|
4038
4097
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
4039
|
-
/* [
|
|
4098
|
+
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
4040
4099
|
case 2:
|
|
4041
|
-
/* [
|
|
4100
|
+
/* [🤹♂️] */ _j.sent();
|
|
4042
4101
|
return [3 /*break*/, 4];
|
|
4043
4102
|
case 3:
|
|
4044
4103
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
4045
|
-
work_1 = executeSingleTemplate(
|
|
4046
|
-
|
|
4104
|
+
work_1 = executeSingleTemplate({
|
|
4105
|
+
currentTemplate: currentTemplate,
|
|
4106
|
+
preparedPipeline: preparedPipeline,
|
|
4107
|
+
parametersToPass: parametersToPass,
|
|
4108
|
+
tools: tools,
|
|
4109
|
+
llmTools: llmTools,
|
|
4110
|
+
onProgress: function (progress) {
|
|
4111
|
+
if (isReturned) {
|
|
4112
|
+
throw new UnexpectedError(spaceTrim.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)
|
|
4113
|
+
.split('\n')
|
|
4114
|
+
.map(function (line) { return "> ".concat(line); })
|
|
4115
|
+
.join('\n')), "\n "); }));
|
|
4116
|
+
}
|
|
4117
|
+
if (onProgress) {
|
|
4118
|
+
onProgress(progress);
|
|
4119
|
+
}
|
|
4120
|
+
},
|
|
4121
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
4122
|
+
$executionReport: executionReport,
|
|
4123
|
+
pipelineIdentification: pipelineIdentification,
|
|
4124
|
+
})
|
|
4125
|
+
.then(function (newParametersToPass) {
|
|
4126
|
+
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
4047
4127
|
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
|
|
4048
4128
|
})
|
|
4049
4129
|
.then(function () {
|
|
@@ -4075,7 +4155,7 @@
|
|
|
4075
4155
|
var result = _a.result;
|
|
4076
4156
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
4077
4157
|
})), false));
|
|
4078
|
-
outputParameters_1 = filterJustOutputParameters();
|
|
4158
|
+
outputParameters_1 = filterJustOutputParameters(preparedPipeline, parametersToPass, warnings, pipelineIdentification);
|
|
4079
4159
|
isReturned = true;
|
|
4080
4160
|
if (!(onProgress !== undefined)) return [3 /*break*/, 27];
|
|
4081
4161
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -4098,7 +4178,7 @@
|
|
|
4098
4178
|
var result = _a.result;
|
|
4099
4179
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
4100
4180
|
})), false));
|
|
4101
|
-
outputParameters = filterJustOutputParameters();
|
|
4181
|
+
outputParameters = filterJustOutputParameters(preparedPipeline, parametersToPass, warnings, pipelineIdentification);
|
|
4102
4182
|
isReturned = true;
|
|
4103
4183
|
if (!(onProgress !== undefined)) return [3 /*break*/, 30];
|
|
4104
4184
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -4122,6 +4202,7 @@
|
|
|
4122
4202
|
return pipelineExecutor;
|
|
4123
4203
|
}
|
|
4124
4204
|
/**
|
|
4205
|
+
* TODO: [🤹♂️] Make some smarter system for limiting concurrent executions MAX_PARALLEL_TOTAL, MAX_PARALLEL_PER_LLM
|
|
4125
4206
|
* TODO: !!! Identify not only pipeline BUT exact template ${block(pipelineIdentification)}
|
|
4126
4207
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
4127
4208
|
* TODO: [🧠][🌳] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
@@ -4130,7 +4211,7 @@
|
|
|
4130
4211
|
* TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
|
|
4131
4212
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
4132
4213
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
4133
|
-
* TODO: [🧠][
|
|
4214
|
+
* TODO: [🧠][🍸] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
4134
4215
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4135
4216
|
* TODO: [🧠][💷] `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result BUT maybe NOT to preserve pure JSON object
|
|
4136
4217
|
*/
|
|
@@ -5303,20 +5384,21 @@
|
|
|
5303
5384
|
* Example usages of the FOREACH command
|
|
5304
5385
|
*/
|
|
5305
5386
|
examples: [
|
|
5306
|
-
'FOREACH List Line -> `{customer}`',
|
|
5307
|
-
'FOR List Line -> `{customer}`',
|
|
5308
|
-
'EACH List Line -> `{customer}`',
|
|
5387
|
+
'FOREACH List Line `{customers}` -> `{customer}`',
|
|
5388
|
+
'FOR List Line `{customers}` -> `{customer}`',
|
|
5389
|
+
'EACH List Line `{customers}` -> `{customer}`',
|
|
5309
5390
|
// <- TODO: [🍭] !!!!!! More
|
|
5310
5391
|
],
|
|
5311
5392
|
/**
|
|
5312
5393
|
* Parses the FOREACH command
|
|
5313
5394
|
*/
|
|
5314
5395
|
parse: function (input) {
|
|
5315
|
-
var args = input.args
|
|
5396
|
+
var args = input.args;
|
|
5316
5397
|
var formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
|
|
5317
5398
|
var cellName = normalizeTo_SCREAMING_CASE(args[1] || '');
|
|
5318
|
-
var
|
|
5319
|
-
var
|
|
5399
|
+
var parameterNameWrapped = args[2];
|
|
5400
|
+
var assignSign = args[3];
|
|
5401
|
+
var subparameterNameWrapped = args[4];
|
|
5320
5402
|
if (![
|
|
5321
5403
|
'LIST',
|
|
5322
5404
|
'CSV',
|
|
@@ -5331,7 +5413,7 @@
|
|
|
5331
5413
|
'ROW',
|
|
5332
5414
|
'COLUMN',
|
|
5333
5415
|
'CELL',
|
|
5334
|
-
// <- TODO: [🏢] Unhardcode format
|
|
5416
|
+
// <- TODO: [🏢] Unhardcode format cells
|
|
5335
5417
|
].includes(cellName)) {
|
|
5336
5418
|
console.info({ args: args, cellName: cellName });
|
|
5337
5419
|
throw new Error("Format ".concat(formatName, " does not support cell \"").concat(cellName, "\""));
|
|
@@ -5341,24 +5423,27 @@
|
|
|
5341
5423
|
console.info({ args: args, assignSign: assignSign });
|
|
5342
5424
|
throw new Error("FOREACH command must have '->' to assign the value to the parameter");
|
|
5343
5425
|
}
|
|
5344
|
-
|
|
5345
|
-
if (
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
//
|
|
5352
|
-
) {
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5426
|
+
// TODO: !!!!!! Replace with propper parameter name validation
|
|
5427
|
+
if ((parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1)) !== '{' ||
|
|
5428
|
+
(parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length)) !== '}') {
|
|
5429
|
+
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));
|
|
5430
|
+
throw new Error("!!!!!! 1 Here will be error (with rules and precise error) from validateParameterName");
|
|
5431
|
+
}
|
|
5432
|
+
var parameterName = parameterNameWrapped.substring(1, parameterNameWrapped.length - 1);
|
|
5433
|
+
// TODO: !!!!!! Replace with propper parameter name validation
|
|
5434
|
+
if ((subparameterNameWrapped === null || subparameterNameWrapped === void 0 ? void 0 : subparameterNameWrapped.substring(0, 1)) !== '{' ||
|
|
5435
|
+
(subparameterNameWrapped === null || subparameterNameWrapped === void 0 ? void 0 : subparameterNameWrapped.substring(subparameterNameWrapped.length - 1, subparameterNameWrapped.length)) !==
|
|
5436
|
+
'}') {
|
|
5437
|
+
console.info({ args: args, subparameterNameWrapped: subparameterNameWrapped });
|
|
5438
|
+
throw new Error("!!!!!! 2 Here will be error (with rules and precise error) from validateParameterName");
|
|
5439
|
+
}
|
|
5440
|
+
var subparameterName = subparameterNameWrapped.substring(1, subparameterNameWrapped.length - 1);
|
|
5357
5441
|
return {
|
|
5358
5442
|
type: 'FOREACH',
|
|
5359
5443
|
formatName: formatName,
|
|
5360
5444
|
cellName: cellName,
|
|
5361
5445
|
parameterName: parameterName,
|
|
5446
|
+
subparameterName: subparameterName,
|
|
5362
5447
|
};
|
|
5363
5448
|
},
|
|
5364
5449
|
/**
|
|
@@ -5367,8 +5452,12 @@
|
|
|
5367
5452
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5368
5453
|
*/
|
|
5369
5454
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5370
|
-
|
|
5371
|
-
//
|
|
5455
|
+
var formatName = command.formatName, cellName = command.cellName, parameterName = command.parameterName, subparameterName = command.subparameterName;
|
|
5456
|
+
// TODO: !!!!!! Detect double use
|
|
5457
|
+
// TODO: !!!!!! Detect usage with JOKER and don't allow it
|
|
5458
|
+
$templateJson.foreach = { formatName: formatName, cellName: cellName, parameterName: parameterName, subparameterName: subparameterName };
|
|
5459
|
+
keepUnused($pipelineJson); // <- TODO: !!!!!! BUT Maybe register subparameter from foreach into parameters of the pipeline
|
|
5460
|
+
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
5372
5461
|
},
|
|
5373
5462
|
/**
|
|
5374
5463
|
* Converts the FOREACH command back to string
|
|
@@ -5377,8 +5466,7 @@
|
|
|
5377
5466
|
*/
|
|
5378
5467
|
stringify: function (command) {
|
|
5379
5468
|
keepUnused(command);
|
|
5380
|
-
return "";
|
|
5381
|
-
// <- TODO: [🍭] !!!!!! Implement
|
|
5469
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5382
5470
|
},
|
|
5383
5471
|
/**
|
|
5384
5472
|
* Reads the FOREACH command from the `TemplateJson`
|
|
@@ -5387,8 +5475,7 @@
|
|
|
5387
5475
|
*/
|
|
5388
5476
|
takeFromTemplateJson: function ($templateJson) {
|
|
5389
5477
|
keepUnused($templateJson);
|
|
5390
|
-
|
|
5391
|
-
// <- TODO: [🍭] !!!!!! Implement
|
|
5478
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5392
5479
|
},
|
|
5393
5480
|
};
|
|
5394
5481
|
/**
|
|
@@ -5503,6 +5590,7 @@
|
|
|
5503
5590
|
*/
|
|
5504
5591
|
parse: function (input) {
|
|
5505
5592
|
var args = input.args;
|
|
5593
|
+
// TODO: !!!!!! Replace with propper parameter name validation
|
|
5506
5594
|
var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
5507
5595
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
5508
5596
|
throw new ParseError("Invalid joker");
|
|
@@ -5632,6 +5720,7 @@
|
|
|
5632
5720
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
5633
5721
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
5634
5722
|
console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
|
|
5723
|
+
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
5635
5724
|
}
|
|
5636
5725
|
else {
|
|
5637
5726
|
throw new ParseError(spaceTrim__default["default"]("\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 ")));
|
|
@@ -7387,6 +7476,9 @@
|
|
|
7387
7476
|
return promptbookMermaid;
|
|
7388
7477
|
}
|
|
7389
7478
|
/**
|
|
7479
|
+
* TODO: !!!!!! FOREACH in mermaid graph
|
|
7480
|
+
* TODO: !!!!!! Knowledge in mermaid graph
|
|
7481
|
+
* TODO: !!!!!! Personas in mermaid graph
|
|
7390
7482
|
* TODO: Maybe use some Mermaid package instead of string templating
|
|
7391
7483
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
7392
7484
|
*/
|