@promptbook/core 0.69.0-18 → 0.69.0-19
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 +71 -50
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +1 -4
- package/esm/typings/src/commands/FOREACH/foreachCommand.test.d.ts +0 -3
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -2
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatCells.d.ts +0 -2
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +0 -1
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +0 -1
- package/package.json +1 -1
- package/umd/index.umd.js +71 -50
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -11,7 +11,7 @@ import moment from 'moment';
|
|
|
11
11
|
/**
|
|
12
12
|
* The version of the Promptbook library
|
|
13
13
|
*/
|
|
14
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
14
|
+
var PROMPTBOOK_VERSION = '0.69.0-18';
|
|
15
15
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
16
16
|
|
|
17
17
|
/*! *****************************************************************************
|
|
@@ -4068,15 +4068,15 @@ function executeFormatCells(options) {
|
|
|
4068
4068
|
.join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4069
4069
|
}
|
|
4070
4070
|
subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
4071
|
-
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.
|
|
4071
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.subformatName);
|
|
4072
4072
|
});
|
|
4073
4073
|
if (subvalueDefinition === undefined) {
|
|
4074
4074
|
throw new UnexpectedError(
|
|
4075
4075
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
4076
|
-
spaceTrim(function (block) { return "\n Unsupported
|
|
4076
|
+
spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(template.foreach.subformatName, "\" for format \"").concat(template.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
|
|
4077
4077
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
4078
4078
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
4079
|
-
.join('\n')), "\n\n [\u26F7] This should never happen because
|
|
4079
|
+
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4080
4080
|
}
|
|
4081
4081
|
if (formatDefinition.formatName === 'CSV') {
|
|
4082
4082
|
formatSettings = settings.csvSettings;
|
|
@@ -4121,8 +4121,6 @@ function executeFormatCells(options) {
|
|
|
4121
4121
|
/**
|
|
4122
4122
|
* TODO: !!!!!! Make pipelineIdentification more precise
|
|
4123
4123
|
* TODO: !!!!!! How FOREACH execution looks in the report
|
|
4124
|
-
* TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
|
|
4125
|
-
* TODO: []
|
|
4126
4124
|
*/
|
|
4127
4125
|
|
|
4128
4126
|
/**
|
|
@@ -5967,6 +5965,29 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
|
5967
5965
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
5968
5966
|
*/
|
|
5969
5967
|
|
|
5968
|
+
/**
|
|
5969
|
+
* Removes quotes from a string
|
|
5970
|
+
*
|
|
5971
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
5972
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
5973
|
+
* Note: There are two simmilar functions:
|
|
5974
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
5975
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
5976
|
+
*
|
|
5977
|
+
* @param text optionally quoted text
|
|
5978
|
+
* @returns text without quotes
|
|
5979
|
+
* @public exported from `@promptbook/utils`
|
|
5980
|
+
*/
|
|
5981
|
+
function removeQuotes(text) {
|
|
5982
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
|
5983
|
+
return text.slice(1, -1);
|
|
5984
|
+
}
|
|
5985
|
+
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
5986
|
+
return text.slice(1, -1);
|
|
5987
|
+
}
|
|
5988
|
+
return text;
|
|
5989
|
+
}
|
|
5990
|
+
|
|
5970
5991
|
/**
|
|
5971
5992
|
* Function `validateParameterName` will @@@
|
|
5972
5993
|
*
|
|
@@ -6025,6 +6046,9 @@ function validateParameterName(parameterName) {
|
|
|
6025
6046
|
parameterName.includes(']')) {
|
|
6026
6047
|
throw new ParseError("Parameter name cannot contain braces");
|
|
6027
6048
|
}
|
|
6049
|
+
parameterName = removeDiacritics(parameterName);
|
|
6050
|
+
parameterName = removeEmojis(parameterName);
|
|
6051
|
+
parameterName = removeQuotes(parameterName);
|
|
6028
6052
|
parameterName = normalizeTo_camelCase(parameterName);
|
|
6029
6053
|
if (parameterName === '') {
|
|
6030
6054
|
throw new ParseError("Parameter name cannot be empty");
|
|
@@ -6078,7 +6102,7 @@ var foreachCommandParser = {
|
|
|
6078
6102
|
examples: [
|
|
6079
6103
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
6080
6104
|
'FOR Csv Row `{customers}` -> `{firstName}`, `{lastName}`',
|
|
6081
|
-
'EACH Csv Cell `{customers}` -> `{
|
|
6105
|
+
'EACH Csv Cell `{customers}` -> `{subformat}`',
|
|
6082
6106
|
],
|
|
6083
6107
|
/**
|
|
6084
6108
|
* Parses the FOREACH command
|
|
@@ -6086,8 +6110,8 @@ var foreachCommandParser = {
|
|
|
6086
6110
|
parse: function (input) {
|
|
6087
6111
|
var args = input.args;
|
|
6088
6112
|
var formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
|
|
6089
|
-
var
|
|
6090
|
-
var
|
|
6113
|
+
var subformatName = normalizeTo_SCREAMING_CASE(args[1] || '');
|
|
6114
|
+
var parameterNameArg = args[2] || '';
|
|
6091
6115
|
var assignSign = args[3];
|
|
6092
6116
|
var formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
|
|
6093
6117
|
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
|
|
@@ -6099,24 +6123,19 @@ var foreachCommandParser = {
|
|
|
6099
6123
|
// <- TODO: [🏢] List all supported format names
|
|
6100
6124
|
}
|
|
6101
6125
|
var subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
6102
|
-
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(
|
|
6126
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
|
|
6103
6127
|
});
|
|
6104
6128
|
if (subvalueDefinition === undefined) {
|
|
6105
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Unsupported
|
|
6129
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(subformatName, "\" for format \"").concat(formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
|
|
6106
6130
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
6107
6131
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
6108
6132
|
.join('\n')), "\n "); }));
|
|
6109
|
-
// <- TODO: [🏢] List all supported
|
|
6133
|
+
// <- TODO: [🏢] List all supported subformat names for the format
|
|
6110
6134
|
}
|
|
6111
6135
|
if (assignSign !== '->') {
|
|
6112
6136
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
6113
6137
|
}
|
|
6114
|
-
|
|
6115
|
-
if ((parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1)) !== '{' ||
|
|
6116
|
-
(parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length)) !== '}') {
|
|
6117
|
-
throw new ParseError("Invalid parameter name \"".concat(parameterNameWrapped, "\" - must be wrapped in curly brackets: {parameterName}"));
|
|
6118
|
-
}
|
|
6119
|
-
var parameterName = parameterNameWrapped.substring(1, parameterNameWrapped.length - 1);
|
|
6138
|
+
var parameterName = validateParameterName(parameterNameArg);
|
|
6120
6139
|
var subparameterNames = args
|
|
6121
6140
|
.slice(4)
|
|
6122
6141
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
@@ -6128,7 +6147,7 @@ var foreachCommandParser = {
|
|
|
6128
6147
|
return {
|
|
6129
6148
|
type: 'FOREACH',
|
|
6130
6149
|
formatName: formatName,
|
|
6131
|
-
|
|
6150
|
+
subformatName: subformatName,
|
|
6132
6151
|
parameterName: parameterName,
|
|
6133
6152
|
subparameterNames: subparameterNames,
|
|
6134
6153
|
};
|
|
@@ -6139,10 +6158,10 @@ var foreachCommandParser = {
|
|
|
6139
6158
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
6140
6159
|
*/
|
|
6141
6160
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
6142
|
-
var formatName = command.formatName,
|
|
6143
|
-
// TODO:
|
|
6144
|
-
// TODO:
|
|
6145
|
-
$templateJson.foreach = { formatName: formatName,
|
|
6161
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, subparameterNames = command.subparameterNames;
|
|
6162
|
+
// TODO: [🍭] Detect double use
|
|
6163
|
+
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
6164
|
+
$templateJson.foreach = { formatName: formatName, subformatName: subformatName, parameterName: parameterName, subparameterNames: subparameterNames };
|
|
6146
6165
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
6147
6166
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
6148
6167
|
},
|
|
@@ -6166,8 +6185,7 @@ var foreachCommandParser = {
|
|
|
6166
6185
|
},
|
|
6167
6186
|
};
|
|
6168
6187
|
/**
|
|
6169
|
-
* TODO: [
|
|
6170
|
-
* TODO: [🍭] !!!!!! Make .ptbk.md file with examples of the FOREACH command and also with wrong parsing and logic
|
|
6188
|
+
* TODO: [🍭] Make .ptbk.md file with examples of the FOREACH with wrong parsing and logic
|
|
6171
6189
|
*/
|
|
6172
6190
|
|
|
6173
6191
|
/**
|
|
@@ -6277,12 +6295,11 @@ var jokerCommandParser = {
|
|
|
6277
6295
|
*/
|
|
6278
6296
|
parse: function (input) {
|
|
6279
6297
|
var args = input.args;
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
6283
|
-
throw new ParseError("Invalid joker");
|
|
6298
|
+
if (args.length !== 1) {
|
|
6299
|
+
throw new ParseError("JOKE command expects exactly one parameter name");
|
|
6284
6300
|
}
|
|
6285
|
-
var
|
|
6301
|
+
var parameterNameArg = args[0] || '';
|
|
6302
|
+
var parameterName = validateParameterName(parameterNameArg);
|
|
6286
6303
|
return {
|
|
6287
6304
|
type: 'JOKER',
|
|
6288
6305
|
parameterName: parameterName,
|
|
@@ -6506,14 +6523,13 @@ var parameterCommandParser = {
|
|
|
6506
6523
|
* Parses the PARAMETER command
|
|
6507
6524
|
*/
|
|
6508
6525
|
parse: function (input) {
|
|
6509
|
-
var normalized = input.normalized, raw = input.raw;
|
|
6510
|
-
var
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
|
|
6526
|
+
var normalized = input.normalized, args = input.args, raw = input.raw;
|
|
6527
|
+
var parameterNameRaw = args.shift() || '';
|
|
6528
|
+
var parameterDescriptionRaw = args.join(' ');
|
|
6529
|
+
// <- TODO: When [🥶] fixed, change to:
|
|
6530
|
+
// > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
|
|
6531
|
+
if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
|
|
6532
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterNameRaw, "} can not contain another parameter in description\n\n The description:\n ").concat(block(parameterDescriptionRaw), "\n "); }));
|
|
6517
6533
|
}
|
|
6518
6534
|
var isInput = normalized.startsWith('INPUT');
|
|
6519
6535
|
var isOutput = normalized.startsWith('OUTPUT');
|
|
@@ -6521,11 +6537,12 @@ var parameterCommandParser = {
|
|
|
6521
6537
|
isInput = false;
|
|
6522
6538
|
isOutput = false;
|
|
6523
6539
|
}
|
|
6524
|
-
|
|
6540
|
+
var parameterName = validateParameterName(parameterNameRaw);
|
|
6541
|
+
var parameterDescription = parameterDescriptionRaw.trim() || null;
|
|
6525
6542
|
return {
|
|
6526
6543
|
type: 'PARAMETER',
|
|
6527
6544
|
parameterName: parameterName,
|
|
6528
|
-
parameterDescription: parameterDescription
|
|
6545
|
+
parameterDescription: parameterDescription,
|
|
6529
6546
|
isInput: isInput,
|
|
6530
6547
|
isOutput: isOutput,
|
|
6531
6548
|
};
|
|
@@ -7333,7 +7350,9 @@ function parseCommand(raw, usagePlace) {
|
|
|
7333
7350
|
for (var commandNameSegmentsCount = 0; commandNameSegmentsCount < Math.min(items.length, 3); commandNameSegmentsCount++) {
|
|
7334
7351
|
var commandNameRaw = items.slice(0, commandNameSegmentsCount + 1).join('_');
|
|
7335
7352
|
var args = items.slice(commandNameSegmentsCount + 1);
|
|
7336
|
-
var rawArgs = raw
|
|
7353
|
+
var rawArgs = raw
|
|
7354
|
+
.substring(commandNameRaw.length)
|
|
7355
|
+
.trim();
|
|
7337
7356
|
var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
|
|
7338
7357
|
if (command !== null) {
|
|
7339
7358
|
return command;
|
|
@@ -7344,7 +7363,9 @@ function parseCommand(raw, usagePlace) {
|
|
|
7344
7363
|
{
|
|
7345
7364
|
var commandNameRaw = items.slice(-1).join('_');
|
|
7346
7365
|
var args = items.slice(0, -1); // <- Note: This is probbably not correct
|
|
7347
|
-
var rawArgs = raw
|
|
7366
|
+
var rawArgs = raw
|
|
7367
|
+
.substring(0, raw.length - commandNameRaw.length)
|
|
7368
|
+
.trim();
|
|
7348
7369
|
var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
|
|
7349
7370
|
if (command !== null) {
|
|
7350
7371
|
return command;
|
|
@@ -8099,9 +8120,9 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
8099
8120
|
return promptbookMermaid;
|
|
8100
8121
|
}
|
|
8101
8122
|
/**
|
|
8102
|
-
* TODO:
|
|
8103
|
-
* TODO:
|
|
8104
|
-
* TODO:
|
|
8123
|
+
* TODO: !!!!! FOREACH in mermaid graph
|
|
8124
|
+
* TODO: !!!!! Knowledge in mermaid graph
|
|
8125
|
+
* TODO: !!!!! Personas in mermaid graph
|
|
8105
8126
|
* TODO: Maybe use some Mermaid package instead of string templating
|
|
8106
8127
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
8107
8128
|
*/
|
|
@@ -8926,8 +8947,8 @@ function formatNumber(value) {
|
|
|
8926
8947
|
*/
|
|
8927
8948
|
function createMarkdownTable(table) {
|
|
8928
8949
|
var columnWidths = table.reduce(function (widths, row) {
|
|
8929
|
-
row.forEach(function (
|
|
8930
|
-
var cellLength =
|
|
8950
|
+
row.forEach(function (subformat, columnIndex) {
|
|
8951
|
+
var cellLength = subformat.length;
|
|
8931
8952
|
if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
|
|
8932
8953
|
widths[columnIndex] = cellLength;
|
|
8933
8954
|
}
|
|
@@ -8935,12 +8956,12 @@ function createMarkdownTable(table) {
|
|
|
8935
8956
|
return widths;
|
|
8936
8957
|
}, []);
|
|
8937
8958
|
var header = "| ".concat(table[0]
|
|
8938
|
-
.map(function (
|
|
8959
|
+
.map(function (subformat, columnIndex) { return subformat.padEnd(columnWidths[columnIndex]); })
|
|
8939
8960
|
.join(' | '), " |");
|
|
8940
8961
|
var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
|
|
8941
8962
|
var rows = table.slice(1).map(function (row) {
|
|
8942
|
-
var paddedRow = row.map(function (
|
|
8943
|
-
return
|
|
8963
|
+
var paddedRow = row.map(function (subformat, columnIndex) {
|
|
8964
|
+
return subformat.padEnd(columnWidths[columnIndex]);
|
|
8944
8965
|
});
|
|
8945
8966
|
return "| ".concat(paddedRow.join(' | '), " |");
|
|
8946
8967
|
});
|