@promptbook/node 0.69.0-20 → 0.69.0-21
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 +70 -31
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +5 -1
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +1 -1
- package/esm/typings/src/execution/embeddingVectorToString.d.ts +1 -1
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +2 -1
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -1
- package/esm/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -1
- package/package.json +2 -2
- package/umd/index.umd.js +70 -31
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -15,7 +15,7 @@ import * as dotenv from 'dotenv';
|
|
|
15
15
|
/**
|
|
16
16
|
* The version of the Promptbook library
|
|
17
17
|
*/
|
|
18
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
18
|
+
var PROMPTBOOK_VERSION = '0.69.0-20';
|
|
19
19
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
20
20
|
|
|
21
21
|
/*! *****************************************************************************
|
|
@@ -2527,7 +2527,7 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
2527
2527
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2528
2528
|
if (foreach !== undefined) {
|
|
2529
2529
|
try {
|
|
2530
|
-
for (var _l = __values(foreach.
|
|
2530
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
2531
2531
|
var subparameterName = _m.value;
|
|
2532
2532
|
if (parameterNames.has(subparameterName)) {
|
|
2533
2533
|
parameterNames.delete(subparameterName);
|
|
@@ -2683,7 +2683,7 @@ var CsvFormatDefinition = {
|
|
|
2683
2683
|
subvalueDefinitions: [
|
|
2684
2684
|
{
|
|
2685
2685
|
subvalueName: 'ROW',
|
|
2686
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2686
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2687
2687
|
return __awaiter(this, void 0, void 0, function () {
|
|
2688
2688
|
var csv, mappedData;
|
|
2689
2689
|
var _this = this;
|
|
@@ -2696,20 +2696,20 @@ var CsvFormatDefinition = {
|
|
|
2696
2696
|
spaceTrim$1(function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2697
2697
|
}
|
|
2698
2698
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2699
|
-
var _a;
|
|
2700
|
-
var
|
|
2701
|
-
return __generator(this, function (
|
|
2702
|
-
switch (
|
|
2699
|
+
var _a, _b;
|
|
2700
|
+
var _c;
|
|
2701
|
+
return __generator(this, function (_d) {
|
|
2702
|
+
switch (_d.label) {
|
|
2703
2703
|
case 0:
|
|
2704
|
+
if (row[outputParameterName]) {
|
|
2705
|
+
throw new ParseError(// <- TODO: !!!!!! Split PipelineParseError and FormatParseError -> CsvParseError
|
|
2706
|
+
"Can not overwrite existing column \"".concat(outputParameterName, "\" in CSV row"));
|
|
2707
|
+
}
|
|
2704
2708
|
_a = [__assign({}, row)];
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2709
|
+
_c = {};
|
|
2710
|
+
_b = outputParameterName;
|
|
2708
2711
|
return [4 /*yield*/, mapCallback(row, index)];
|
|
2709
|
-
case 1: return [2 /*return*/,
|
|
2710
|
-
// <- TODO: !!!!!! Dynamic new column name and position
|
|
2711
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2712
|
-
_c.sent(), _b)])))];
|
|
2712
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c[_b] = _d.sent(), _c)]))];
|
|
2713
2713
|
}
|
|
2714
2714
|
});
|
|
2715
2715
|
}); }))];
|
|
@@ -2723,7 +2723,7 @@ var CsvFormatDefinition = {
|
|
|
2723
2723
|
},
|
|
2724
2724
|
{
|
|
2725
2725
|
subvalueName: 'CELL',
|
|
2726
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2726
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2727
2727
|
return __awaiter(this, void 0, void 0, function () {
|
|
2728
2728
|
var csv, mappedData;
|
|
2729
2729
|
var _this = this;
|
|
@@ -2850,7 +2850,7 @@ var TextFormatDefinition = {
|
|
|
2850
2850
|
subvalueDefinitions: [
|
|
2851
2851
|
{
|
|
2852
2852
|
subvalueName: 'LINE',
|
|
2853
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2853
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2854
2854
|
return __awaiter(this, void 0, void 0, function () {
|
|
2855
2855
|
var lines, mappedLines;
|
|
2856
2856
|
return __generator(this, function (_a) {
|
|
@@ -3762,7 +3762,7 @@ function executeFormatCells(options) {
|
|
|
3762
3762
|
formatSettings = settings.csvSettings;
|
|
3763
3763
|
// <- TODO: !!!!!! More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
3764
3764
|
}
|
|
3765
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3765
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3766
3766
|
var mappedParameters, allSubparameters, subresultString;
|
|
3767
3767
|
return __generator(this, function (_a) {
|
|
3768
3768
|
switch (_a.label) {
|
|
@@ -3771,7 +3771,7 @@ function executeFormatCells(options) {
|
|
|
3771
3771
|
// TODO: !!!!!!! Report progress
|
|
3772
3772
|
try {
|
|
3773
3773
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
3774
|
-
expectedParameters: Object.fromEntries(template.foreach.
|
|
3774
|
+
expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
3775
3775
|
availableParameters: subparameters,
|
|
3776
3776
|
});
|
|
3777
3777
|
}
|
|
@@ -3779,12 +3779,12 @@ function executeFormatCells(options) {
|
|
|
3779
3779
|
if (!(error instanceof PipelineExecutionError)) {
|
|
3780
3780
|
throw error;
|
|
3781
3781
|
}
|
|
3782
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3782
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }));
|
|
3783
3783
|
}
|
|
3784
3784
|
allSubparameters = __assign(__assign({}, parameters), mappedParameters);
|
|
3785
3785
|
// Note: [👨👨👧] Now we can freeze `subparameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
3786
3786
|
Object.freeze(allSubparameters);
|
|
3787
|
-
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: pipelineIdentification }))];
|
|
3787
|
+
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }) }))];
|
|
3788
3788
|
case 1:
|
|
3789
3789
|
subresultString = _a.sent();
|
|
3790
3790
|
return [2 /*return*/, subresultString];
|
|
@@ -4294,7 +4294,7 @@ function executePipeline(options) {
|
|
|
4294
4294
|
},
|
|
4295
4295
|
settings: settings,
|
|
4296
4296
|
$executionReport: executionReport,
|
|
4297
|
-
pipelineIdentification: pipelineIdentification,
|
|
4297
|
+
pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
4298
4298
|
})
|
|
4299
4299
|
.then(function (newParametersToPass) {
|
|
4300
4300
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
@@ -4417,9 +4417,11 @@ function createPipelineExecutor(options) {
|
|
|
4417
4417
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
4418
4418
|
console.warn(spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
4419
4419
|
}
|
|
4420
|
+
var runCount = 0;
|
|
4420
4421
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4421
4422
|
return __generator(this, function (_a) {
|
|
4422
|
-
|
|
4423
|
+
runCount++;
|
|
4424
|
+
return [2 /*return*/, /* not await */ executePipeline({
|
|
4423
4425
|
pipeline: pipeline,
|
|
4424
4426
|
preparedPipeline: preparedPipeline,
|
|
4425
4427
|
setPreparedPipeline: function (newPreparedPipeline) {
|
|
@@ -4428,7 +4430,7 @@ function createPipelineExecutor(options) {
|
|
|
4428
4430
|
inputParameters: inputParameters,
|
|
4429
4431
|
tools: tools,
|
|
4430
4432
|
onProgress: onProgress,
|
|
4431
|
-
pipelineIdentification: pipelineIdentification,
|
|
4433
|
+
pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
4432
4434
|
settings: {
|
|
4433
4435
|
maxExecutionAttempts: maxExecutionAttempts,
|
|
4434
4436
|
maxParallelCount: maxParallelCount,
|
|
@@ -5799,8 +5801,10 @@ var foreachCommandParser = {
|
|
|
5799
5801
|
*/
|
|
5800
5802
|
examples: [
|
|
5801
5803
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
5802
|
-
'
|
|
5803
|
-
'
|
|
5804
|
+
'FOREACH Csv Cell `{customers}` -> `{cell}`',
|
|
5805
|
+
'FOREACH Csv Row `{customers}` -> `{firstName}`, `{lastName}`, `+{email}`',
|
|
5806
|
+
'FOR Text Line `{customers}` -> `{customer}`',
|
|
5807
|
+
'EACH Text Line `{customers}` -> `{customer}`',
|
|
5804
5808
|
],
|
|
5805
5809
|
/**
|
|
5806
5810
|
* Parses the FOREACH command
|
|
@@ -5834,20 +5838,49 @@ var foreachCommandParser = {
|
|
|
5834
5838
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
5835
5839
|
}
|
|
5836
5840
|
var parameterName = validateParameterName(parameterNameArg);
|
|
5837
|
-
var
|
|
5841
|
+
var outputSubparameterName = null;
|
|
5842
|
+
// TODO: [4] DRY
|
|
5843
|
+
var inputSubparameterNames = args
|
|
5838
5844
|
.slice(4)
|
|
5839
5845
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
5846
|
+
.filter(function (parameterName) { return !parameterName.includes('+'); })
|
|
5840
5847
|
.filter(function (parameterName) { return parameterName !== ''; })
|
|
5841
5848
|
.map(validateParameterName);
|
|
5842
|
-
|
|
5843
|
-
|
|
5849
|
+
// TODO: [4] DRY
|
|
5850
|
+
var outputSubparameterNames = args
|
|
5851
|
+
.slice(4)
|
|
5852
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
5853
|
+
.filter(function (parameterName) { return parameterName.includes('+'); })
|
|
5854
|
+
.map(function (parameterName) { return parameterName.split('+').join(''); })
|
|
5855
|
+
.map(validateParameterName);
|
|
5856
|
+
if (outputSubparameterNames.length === 1) {
|
|
5857
|
+
outputSubparameterName = outputSubparameterNames[0];
|
|
5858
|
+
}
|
|
5859
|
+
else if (outputSubparameterNames.length > 1) {
|
|
5860
|
+
throw new ParseError("FOREACH command can not have more than one output subparameter");
|
|
5861
|
+
}
|
|
5862
|
+
if (inputSubparameterNames.length === 0) {
|
|
5863
|
+
throw new ParseError("FOREACH command must have at least one input subparameter");
|
|
5864
|
+
}
|
|
5865
|
+
if (outputSubparameterName === null) {
|
|
5866
|
+
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
5867
|
+
if (formatName === 'CSV' && subformatName === 'CELL') {
|
|
5868
|
+
outputSubparameterName = 'newCell';
|
|
5869
|
+
}
|
|
5870
|
+
else if (formatName === 'TEXT' && subformatName === 'LINE') {
|
|
5871
|
+
outputSubparameterName = 'newLine';
|
|
5872
|
+
}
|
|
5873
|
+
else {
|
|
5874
|
+
throw new ParseError(spaceTrim$1("\n FOREACH ".concat(formatName, " ").concat(subformatName, " must specify output subparameter\n\n Correct example:\n - FOREACH ").concat(formatName, " ").concat(subformatName, " {").concat(parameterName, "} -> {inputSubparameterName1}, {inputSubparameterName2}, +{outputSubparameterName}\n\n ")));
|
|
5875
|
+
}
|
|
5844
5876
|
}
|
|
5845
5877
|
return {
|
|
5846
5878
|
type: 'FOREACH',
|
|
5847
5879
|
formatName: formatName,
|
|
5848
5880
|
subformatName: subformatName,
|
|
5849
5881
|
parameterName: parameterName,
|
|
5850
|
-
|
|
5882
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
5883
|
+
outputSubparameterName: outputSubparameterName,
|
|
5851
5884
|
};
|
|
5852
5885
|
},
|
|
5853
5886
|
/**
|
|
@@ -5856,10 +5889,16 @@ var foreachCommandParser = {
|
|
|
5856
5889
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5857
5890
|
*/
|
|
5858
5891
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5859
|
-
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName,
|
|
5892
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
5860
5893
|
// TODO: [🍭] Detect double use
|
|
5861
5894
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
5862
|
-
$templateJson.foreach = {
|
|
5895
|
+
$templateJson.foreach = {
|
|
5896
|
+
formatName: formatName,
|
|
5897
|
+
subformatName: subformatName,
|
|
5898
|
+
parameterName: parameterName,
|
|
5899
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
5900
|
+
outputSubparameterName: outputSubparameterName,
|
|
5901
|
+
};
|
|
5863
5902
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
5864
5903
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
5865
5904
|
},
|