@promptbook/node 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 +63 -42
- 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 +2 -2
- package/umd/index.umd.js +63 -42
- package/umd/index.umd.js.map +1 -1
|
@@ -11,7 +11,7 @@ export type ForeachJson = {
|
|
|
11
11
|
/**
|
|
12
12
|
* @@@
|
|
13
13
|
*/
|
|
14
|
-
readonly
|
|
14
|
+
readonly subformatName: TODO_string;
|
|
15
15
|
/**
|
|
16
16
|
* @@@
|
|
17
17
|
*/
|
|
@@ -21,6 +21,3 @@ export type ForeachJson = {
|
|
|
21
21
|
*/
|
|
22
22
|
readonly subparameterNames: Array<string_parameter_name>;
|
|
23
23
|
};
|
|
24
|
-
/**
|
|
25
|
-
* TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
|
|
26
|
-
*/
|
|
@@ -10,6 +10,5 @@ import type { ForeachCommand } from './ForeachCommand';
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const foreachCommandParser: PipelineTemplateCommandParser<ForeachCommand>;
|
|
12
12
|
/**
|
|
13
|
-
* TODO: [
|
|
14
|
-
* TODO: [🍭] !!!!!! Make .ptbk.md file with examples of the FOREACH command and also with wrong parsing and logic
|
|
13
|
+
* TODO: [🍭] Make .ptbk.md file with examples of the FOREACH with wrong parsing and logic
|
|
15
14
|
*/
|
|
@@ -22,9 +22,9 @@ export type renderPipelineMermaidOptions = {
|
|
|
22
22
|
*/
|
|
23
23
|
export declare function renderPromptbookMermaid(pipelineJson: PipelineJson, options?: renderPipelineMermaidOptions): string;
|
|
24
24
|
/**
|
|
25
|
-
* TODO:
|
|
26
|
-
* TODO:
|
|
27
|
-
* TODO:
|
|
25
|
+
* TODO: !!!!! FOREACH in mermaid graph
|
|
26
|
+
* TODO: !!!!! Knowledge in mermaid graph
|
|
27
|
+
* TODO: !!!!! Personas in mermaid graph
|
|
28
28
|
* TODO: Maybe use some Mermaid package instead of string templating
|
|
29
29
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
30
30
|
*/
|
|
@@ -61,7 +61,6 @@ export type FormatDefinition<TValue extends TPartialValue, TPartialValue extends
|
|
|
61
61
|
readonly subvalueDefinitions: Array<FormatSubvalueDefinition<TValue, TSettings>>;
|
|
62
62
|
};
|
|
63
63
|
/**
|
|
64
|
-
* TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
|
|
65
64
|
* TODO: [♏] Add some prepare hook to modify prompt according to the format
|
|
66
65
|
* TODO: [🍓]`name` and `aliases` should be UPPERCASE only and interpreted as case-insensitive (via normalization)
|
|
67
66
|
* TODO: [🍓][👨⚖️] Compute TPartialValue dynamically - PartialString<TValue>
|
|
@@ -26,6 +26,5 @@ export type FormatSubvalueDefinition<TValue extends string, TSettings extends em
|
|
|
26
26
|
mapValues(value: TValue, settings: TSettings, mapCallback: (subvalues: Parameters, index: number) => Promisable<string>): Promise<string>;
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
|
-
* TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
|
|
30
29
|
* Note: [👩🏾🤝🧑🏽]
|
|
31
30
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.69.0-
|
|
3
|
+
"version": "0.69.0-19",
|
|
4
4
|
"description": "Supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"module": "./esm/index.es.js",
|
|
52
52
|
"typings": "./esm/typings/src/_packages/node.index.d.ts",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@promptbook/core": "0.69.0-
|
|
54
|
+
"@promptbook/core": "0.69.0-19"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
/**
|
|
36
36
|
* The version of the Promptbook library
|
|
37
37
|
*/
|
|
38
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
38
|
+
var PROMPTBOOK_VERSION = '0.69.0-18';
|
|
39
39
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
40
40
|
|
|
41
41
|
/*! *****************************************************************************
|
|
@@ -3768,15 +3768,15 @@
|
|
|
3768
3768
|
.join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3769
3769
|
}
|
|
3770
3770
|
subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
3771
|
-
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.
|
|
3771
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.subformatName);
|
|
3772
3772
|
});
|
|
3773
3773
|
if (subvalueDefinition === undefined) {
|
|
3774
3774
|
throw new UnexpectedError(
|
|
3775
3775
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
3776
|
-
spaceTrim__default["default"](function (block) { return "\n Unsupported
|
|
3776
|
+
spaceTrim__default["default"](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
|
|
3777
3777
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
3778
3778
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
3779
|
-
.join('\n')), "\n\n [\u26F7] This should never happen because
|
|
3779
|
+
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3780
3780
|
}
|
|
3781
3781
|
if (formatDefinition.formatName === 'CSV') {
|
|
3782
3782
|
formatSettings = settings.csvSettings;
|
|
@@ -3821,8 +3821,6 @@
|
|
|
3821
3821
|
/**
|
|
3822
3822
|
* TODO: !!!!!! Make pipelineIdentification more precise
|
|
3823
3823
|
* TODO: !!!!!! How FOREACH execution looks in the report
|
|
3824
|
-
* TODO: [🧠][🦥] Better (less confusing) name for "cell" / "subvalue" / "subparameter"
|
|
3825
|
-
* TODO: []
|
|
3826
3824
|
*/
|
|
3827
3825
|
|
|
3828
3826
|
/**
|
|
@@ -5685,6 +5683,29 @@
|
|
|
5685
5683
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
5686
5684
|
*/
|
|
5687
5685
|
|
|
5686
|
+
/**
|
|
5687
|
+
* Removes quotes from a string
|
|
5688
|
+
*
|
|
5689
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
5690
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
5691
|
+
* Note: There are two simmilar functions:
|
|
5692
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
5693
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
5694
|
+
*
|
|
5695
|
+
* @param text optionally quoted text
|
|
5696
|
+
* @returns text without quotes
|
|
5697
|
+
* @public exported from `@promptbook/utils`
|
|
5698
|
+
*/
|
|
5699
|
+
function removeQuotes(text) {
|
|
5700
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
|
5701
|
+
return text.slice(1, -1);
|
|
5702
|
+
}
|
|
5703
|
+
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
5704
|
+
return text.slice(1, -1);
|
|
5705
|
+
}
|
|
5706
|
+
return text;
|
|
5707
|
+
}
|
|
5708
|
+
|
|
5688
5709
|
/**
|
|
5689
5710
|
* Function `validateParameterName` will @@@
|
|
5690
5711
|
*
|
|
@@ -5743,6 +5764,9 @@
|
|
|
5743
5764
|
parameterName.includes(']')) {
|
|
5744
5765
|
throw new ParseError("Parameter name cannot contain braces");
|
|
5745
5766
|
}
|
|
5767
|
+
parameterName = removeDiacritics(parameterName);
|
|
5768
|
+
parameterName = removeEmojis(parameterName);
|
|
5769
|
+
parameterName = removeQuotes(parameterName);
|
|
5746
5770
|
parameterName = normalizeTo_camelCase(parameterName);
|
|
5747
5771
|
if (parameterName === '') {
|
|
5748
5772
|
throw new ParseError("Parameter name cannot be empty");
|
|
@@ -5796,7 +5820,7 @@
|
|
|
5796
5820
|
examples: [
|
|
5797
5821
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
5798
5822
|
'FOR Csv Row `{customers}` -> `{firstName}`, `{lastName}`',
|
|
5799
|
-
'EACH Csv Cell `{customers}` -> `{
|
|
5823
|
+
'EACH Csv Cell `{customers}` -> `{subformat}`',
|
|
5800
5824
|
],
|
|
5801
5825
|
/**
|
|
5802
5826
|
* Parses the FOREACH command
|
|
@@ -5804,8 +5828,8 @@
|
|
|
5804
5828
|
parse: function (input) {
|
|
5805
5829
|
var args = input.args;
|
|
5806
5830
|
var formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
|
|
5807
|
-
var
|
|
5808
|
-
var
|
|
5831
|
+
var subformatName = normalizeTo_SCREAMING_CASE(args[1] || '');
|
|
5832
|
+
var parameterNameArg = args[2] || '';
|
|
5809
5833
|
var assignSign = args[3];
|
|
5810
5834
|
var formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
|
|
5811
5835
|
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
|
|
@@ -5817,24 +5841,19 @@
|
|
|
5817
5841
|
// <- TODO: [🏢] List all supported format names
|
|
5818
5842
|
}
|
|
5819
5843
|
var subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
5820
|
-
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(
|
|
5844
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
|
|
5821
5845
|
});
|
|
5822
5846
|
if (subvalueDefinition === undefined) {
|
|
5823
|
-
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Unsupported
|
|
5847
|
+
throw new ParseError(spaceTrim__default["default"](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
|
|
5824
5848
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
5825
5849
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
5826
5850
|
.join('\n')), "\n "); }));
|
|
5827
|
-
// <- TODO: [🏢] List all supported
|
|
5851
|
+
// <- TODO: [🏢] List all supported subformat names for the format
|
|
5828
5852
|
}
|
|
5829
5853
|
if (assignSign !== '->') {
|
|
5830
5854
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
5831
5855
|
}
|
|
5832
|
-
|
|
5833
|
-
if ((parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1)) !== '{' ||
|
|
5834
|
-
(parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length)) !== '}') {
|
|
5835
|
-
throw new ParseError("Invalid parameter name \"".concat(parameterNameWrapped, "\" - must be wrapped in curly brackets: {parameterName}"));
|
|
5836
|
-
}
|
|
5837
|
-
var parameterName = parameterNameWrapped.substring(1, parameterNameWrapped.length - 1);
|
|
5856
|
+
var parameterName = validateParameterName(parameterNameArg);
|
|
5838
5857
|
var subparameterNames = args
|
|
5839
5858
|
.slice(4)
|
|
5840
5859
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
@@ -5846,7 +5865,7 @@
|
|
|
5846
5865
|
return {
|
|
5847
5866
|
type: 'FOREACH',
|
|
5848
5867
|
formatName: formatName,
|
|
5849
|
-
|
|
5868
|
+
subformatName: subformatName,
|
|
5850
5869
|
parameterName: parameterName,
|
|
5851
5870
|
subparameterNames: subparameterNames,
|
|
5852
5871
|
};
|
|
@@ -5857,10 +5876,10 @@
|
|
|
5857
5876
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5858
5877
|
*/
|
|
5859
5878
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5860
|
-
var formatName = command.formatName,
|
|
5861
|
-
// TODO:
|
|
5862
|
-
// TODO:
|
|
5863
|
-
$templateJson.foreach = { formatName: formatName,
|
|
5879
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, subparameterNames = command.subparameterNames;
|
|
5880
|
+
// TODO: [🍭] Detect double use
|
|
5881
|
+
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
5882
|
+
$templateJson.foreach = { formatName: formatName, subformatName: subformatName, parameterName: parameterName, subparameterNames: subparameterNames };
|
|
5864
5883
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
5865
5884
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
5866
5885
|
},
|
|
@@ -5884,8 +5903,7 @@
|
|
|
5884
5903
|
},
|
|
5885
5904
|
};
|
|
5886
5905
|
/**
|
|
5887
|
-
* TODO: [
|
|
5888
|
-
* TODO: [🍭] !!!!!! Make .ptbk.md file with examples of the FOREACH command and also with wrong parsing and logic
|
|
5906
|
+
* TODO: [🍭] Make .ptbk.md file with examples of the FOREACH with wrong parsing and logic
|
|
5889
5907
|
*/
|
|
5890
5908
|
|
|
5891
5909
|
/**
|
|
@@ -5995,12 +6013,11 @@
|
|
|
5995
6013
|
*/
|
|
5996
6014
|
parse: function (input) {
|
|
5997
6015
|
var args = input.args;
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
6001
|
-
throw new ParseError("Invalid joker");
|
|
6016
|
+
if (args.length !== 1) {
|
|
6017
|
+
throw new ParseError("JOKE command expects exactly one parameter name");
|
|
6002
6018
|
}
|
|
6003
|
-
var
|
|
6019
|
+
var parameterNameArg = args[0] || '';
|
|
6020
|
+
var parameterName = validateParameterName(parameterNameArg);
|
|
6004
6021
|
return {
|
|
6005
6022
|
type: 'JOKER',
|
|
6006
6023
|
parameterName: parameterName,
|
|
@@ -6224,14 +6241,13 @@
|
|
|
6224
6241
|
* Parses the PARAMETER command
|
|
6225
6242
|
*/
|
|
6226
6243
|
parse: function (input) {
|
|
6227
|
-
var normalized = input.normalized, raw = input.raw;
|
|
6228
|
-
var
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
|
|
6244
|
+
var normalized = input.normalized, args = input.args, raw = input.raw;
|
|
6245
|
+
var parameterNameRaw = args.shift() || '';
|
|
6246
|
+
var parameterDescriptionRaw = args.join(' ');
|
|
6247
|
+
// <- TODO: When [🥶] fixed, change to:
|
|
6248
|
+
// > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
|
|
6249
|
+
if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
|
|
6250
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Parameter {".concat(parameterNameRaw, "} can not contain another parameter in description\n\n The description:\n ").concat(block(parameterDescriptionRaw), "\n "); }));
|
|
6235
6251
|
}
|
|
6236
6252
|
var isInput = normalized.startsWith('INPUT');
|
|
6237
6253
|
var isOutput = normalized.startsWith('OUTPUT');
|
|
@@ -6239,11 +6255,12 @@
|
|
|
6239
6255
|
isInput = false;
|
|
6240
6256
|
isOutput = false;
|
|
6241
6257
|
}
|
|
6242
|
-
|
|
6258
|
+
var parameterName = validateParameterName(parameterNameRaw);
|
|
6259
|
+
var parameterDescription = parameterDescriptionRaw.trim() || null;
|
|
6243
6260
|
return {
|
|
6244
6261
|
type: 'PARAMETER',
|
|
6245
6262
|
parameterName: parameterName,
|
|
6246
|
-
parameterDescription: parameterDescription
|
|
6263
|
+
parameterDescription: parameterDescription,
|
|
6247
6264
|
isInput: isInput,
|
|
6248
6265
|
isOutput: isOutput,
|
|
6249
6266
|
};
|
|
@@ -7051,7 +7068,9 @@
|
|
|
7051
7068
|
for (var commandNameSegmentsCount = 0; commandNameSegmentsCount < Math.min(items.length, 3); commandNameSegmentsCount++) {
|
|
7052
7069
|
var commandNameRaw = items.slice(0, commandNameSegmentsCount + 1).join('_');
|
|
7053
7070
|
var args = items.slice(commandNameSegmentsCount + 1);
|
|
7054
|
-
var rawArgs = raw
|
|
7071
|
+
var rawArgs = raw
|
|
7072
|
+
.substring(commandNameRaw.length)
|
|
7073
|
+
.trim();
|
|
7055
7074
|
var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
|
|
7056
7075
|
if (command !== null) {
|
|
7057
7076
|
return command;
|
|
@@ -7062,7 +7081,9 @@
|
|
|
7062
7081
|
{
|
|
7063
7082
|
var commandNameRaw = items.slice(-1).join('_');
|
|
7064
7083
|
var args = items.slice(0, -1); // <- Note: This is probbably not correct
|
|
7065
|
-
var rawArgs = raw
|
|
7084
|
+
var rawArgs = raw
|
|
7085
|
+
.substring(0, raw.length - commandNameRaw.length)
|
|
7086
|
+
.trim();
|
|
7066
7087
|
var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
|
|
7067
7088
|
if (command !== null) {
|
|
7068
7089
|
return command;
|