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