@promptbook/core 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 +1 -1
- package/umd/index.umd.js +70 -31
- 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-20';
|
|
15
15
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
16
16
|
|
|
17
17
|
/*! *****************************************************************************
|
|
@@ -2825,7 +2825,7 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
2825
2825
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2826
2826
|
if (foreach !== undefined) {
|
|
2827
2827
|
try {
|
|
2828
|
-
for (var _l = __values(foreach.
|
|
2828
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
2829
2829
|
var subparameterName = _m.value;
|
|
2830
2830
|
if (parameterNames.has(subparameterName)) {
|
|
2831
2831
|
parameterNames.delete(subparameterName);
|
|
@@ -2981,7 +2981,7 @@ var CsvFormatDefinition = {
|
|
|
2981
2981
|
subvalueDefinitions: [
|
|
2982
2982
|
{
|
|
2983
2983
|
subvalueName: 'ROW',
|
|
2984
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2984
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2985
2985
|
return __awaiter(this, void 0, void 0, function () {
|
|
2986
2986
|
var csv, mappedData;
|
|
2987
2987
|
var _this = this;
|
|
@@ -2994,20 +2994,20 @@ var CsvFormatDefinition = {
|
|
|
2994
2994
|
spaceTrim(function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2995
2995
|
}
|
|
2996
2996
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2997
|
-
var _a;
|
|
2998
|
-
var
|
|
2999
|
-
return __generator(this, function (
|
|
3000
|
-
switch (
|
|
2997
|
+
var _a, _b;
|
|
2998
|
+
var _c;
|
|
2999
|
+
return __generator(this, function (_d) {
|
|
3000
|
+
switch (_d.label) {
|
|
3001
3001
|
case 0:
|
|
3002
|
+
if (row[outputParameterName]) {
|
|
3003
|
+
throw new ParseError(// <- TODO: !!!!!! Split PipelineParseError and FormatParseError -> CsvParseError
|
|
3004
|
+
"Can not overwrite existing column \"".concat(outputParameterName, "\" in CSV row"));
|
|
3005
|
+
}
|
|
3002
3006
|
_a = [__assign({}, row)];
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
// <- TODO: !!!!!! Check name collisions
|
|
3007
|
+
_c = {};
|
|
3008
|
+
_b = outputParameterName;
|
|
3006
3009
|
return [4 /*yield*/, mapCallback(row, index)];
|
|
3007
|
-
case 1: return [2 /*return*/,
|
|
3008
|
-
// <- TODO: !!!!!! Dynamic new column name and position
|
|
3009
|
-
// <- TODO: !!!!!! Check name collisions
|
|
3010
|
-
_c.sent(), _b)])))];
|
|
3010
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c[_b] = _d.sent(), _c)]))];
|
|
3011
3011
|
}
|
|
3012
3012
|
});
|
|
3013
3013
|
}); }))];
|
|
@@ -3021,7 +3021,7 @@ var CsvFormatDefinition = {
|
|
|
3021
3021
|
},
|
|
3022
3022
|
{
|
|
3023
3023
|
subvalueName: 'CELL',
|
|
3024
|
-
mapValues: function (value, settings, mapCallback) {
|
|
3024
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
3025
3025
|
return __awaiter(this, void 0, void 0, function () {
|
|
3026
3026
|
var csv, mappedData;
|
|
3027
3027
|
var _this = this;
|
|
@@ -3148,7 +3148,7 @@ var TextFormatDefinition = {
|
|
|
3148
3148
|
subvalueDefinitions: [
|
|
3149
3149
|
{
|
|
3150
3150
|
subvalueName: 'LINE',
|
|
3151
|
-
mapValues: function (value, settings, mapCallback) {
|
|
3151
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
3152
3152
|
return __awaiter(this, void 0, void 0, function () {
|
|
3153
3153
|
var lines, mappedLines;
|
|
3154
3154
|
return __generator(this, function (_a) {
|
|
@@ -4082,7 +4082,7 @@ function executeFormatCells(options) {
|
|
|
4082
4082
|
formatSettings = settings.csvSettings;
|
|
4083
4083
|
// <- TODO: !!!!!! More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
4084
4084
|
}
|
|
4085
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4085
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4086
4086
|
var mappedParameters, allSubparameters, subresultString;
|
|
4087
4087
|
return __generator(this, function (_a) {
|
|
4088
4088
|
switch (_a.label) {
|
|
@@ -4091,7 +4091,7 @@ function executeFormatCells(options) {
|
|
|
4091
4091
|
// TODO: !!!!!!! Report progress
|
|
4092
4092
|
try {
|
|
4093
4093
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
4094
|
-
expectedParameters: Object.fromEntries(template.foreach.
|
|
4094
|
+
expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
4095
4095
|
availableParameters: subparameters,
|
|
4096
4096
|
});
|
|
4097
4097
|
}
|
|
@@ -4099,12 +4099,12 @@ function executeFormatCells(options) {
|
|
|
4099
4099
|
if (!(error instanceof PipelineExecutionError)) {
|
|
4100
4100
|
throw error;
|
|
4101
4101
|
}
|
|
4102
|
-
throw new PipelineExecutionError(spaceTrim(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 "); }));
|
|
4102
|
+
throw new PipelineExecutionError(spaceTrim(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 "); }));
|
|
4103
4103
|
}
|
|
4104
4104
|
allSubparameters = __assign(__assign({}, parameters), mappedParameters);
|
|
4105
4105
|
// 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
|
|
4106
4106
|
Object.freeze(allSubparameters);
|
|
4107
|
-
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: pipelineIdentification }))];
|
|
4107
|
+
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }) }))];
|
|
4108
4108
|
case 1:
|
|
4109
4109
|
subresultString = _a.sent();
|
|
4110
4110
|
return [2 /*return*/, subresultString];
|
|
@@ -4614,7 +4614,7 @@ function executePipeline(options) {
|
|
|
4614
4614
|
},
|
|
4615
4615
|
settings: settings,
|
|
4616
4616
|
$executionReport: executionReport,
|
|
4617
|
-
pipelineIdentification: pipelineIdentification,
|
|
4617
|
+
pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
4618
4618
|
})
|
|
4619
4619
|
.then(function (newParametersToPass) {
|
|
4620
4620
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
@@ -4737,9 +4737,11 @@ function createPipelineExecutor(options) {
|
|
|
4737
4737
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
4738
4738
|
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 "); }));
|
|
4739
4739
|
}
|
|
4740
|
+
var runCount = 0;
|
|
4740
4741
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4741
4742
|
return __generator(this, function (_a) {
|
|
4742
|
-
|
|
4743
|
+
runCount++;
|
|
4744
|
+
return [2 /*return*/, /* not await */ executePipeline({
|
|
4743
4745
|
pipeline: pipeline,
|
|
4744
4746
|
preparedPipeline: preparedPipeline,
|
|
4745
4747
|
setPreparedPipeline: function (newPreparedPipeline) {
|
|
@@ -4748,7 +4750,7 @@ function createPipelineExecutor(options) {
|
|
|
4748
4750
|
inputParameters: inputParameters,
|
|
4749
4751
|
tools: tools,
|
|
4750
4752
|
onProgress: onProgress,
|
|
4751
|
-
pipelineIdentification: pipelineIdentification,
|
|
4753
|
+
pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
4752
4754
|
settings: {
|
|
4753
4755
|
maxExecutionAttempts: maxExecutionAttempts,
|
|
4754
4756
|
maxParallelCount: maxParallelCount,
|
|
@@ -6101,8 +6103,10 @@ var foreachCommandParser = {
|
|
|
6101
6103
|
*/
|
|
6102
6104
|
examples: [
|
|
6103
6105
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
6104
|
-
'
|
|
6105
|
-
'
|
|
6106
|
+
'FOREACH Csv Cell `{customers}` -> `{cell}`',
|
|
6107
|
+
'FOREACH Csv Row `{customers}` -> `{firstName}`, `{lastName}`, `+{email}`',
|
|
6108
|
+
'FOR Text Line `{customers}` -> `{customer}`',
|
|
6109
|
+
'EACH Text Line `{customers}` -> `{customer}`',
|
|
6106
6110
|
],
|
|
6107
6111
|
/**
|
|
6108
6112
|
* Parses the FOREACH command
|
|
@@ -6136,20 +6140,49 @@ var foreachCommandParser = {
|
|
|
6136
6140
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
6137
6141
|
}
|
|
6138
6142
|
var parameterName = validateParameterName(parameterNameArg);
|
|
6139
|
-
var
|
|
6143
|
+
var outputSubparameterName = null;
|
|
6144
|
+
// TODO: [4] DRY
|
|
6145
|
+
var inputSubparameterNames = args
|
|
6140
6146
|
.slice(4)
|
|
6141
6147
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6148
|
+
.filter(function (parameterName) { return !parameterName.includes('+'); })
|
|
6142
6149
|
.filter(function (parameterName) { return parameterName !== ''; })
|
|
6143
6150
|
.map(validateParameterName);
|
|
6144
|
-
|
|
6145
|
-
|
|
6151
|
+
// TODO: [4] DRY
|
|
6152
|
+
var outputSubparameterNames = args
|
|
6153
|
+
.slice(4)
|
|
6154
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6155
|
+
.filter(function (parameterName) { return parameterName.includes('+'); })
|
|
6156
|
+
.map(function (parameterName) { return parameterName.split('+').join(''); })
|
|
6157
|
+
.map(validateParameterName);
|
|
6158
|
+
if (outputSubparameterNames.length === 1) {
|
|
6159
|
+
outputSubparameterName = outputSubparameterNames[0];
|
|
6160
|
+
}
|
|
6161
|
+
else if (outputSubparameterNames.length > 1) {
|
|
6162
|
+
throw new ParseError("FOREACH command can not have more than one output subparameter");
|
|
6163
|
+
}
|
|
6164
|
+
if (inputSubparameterNames.length === 0) {
|
|
6165
|
+
throw new ParseError("FOREACH command must have at least one input subparameter");
|
|
6166
|
+
}
|
|
6167
|
+
if (outputSubparameterName === null) {
|
|
6168
|
+
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
6169
|
+
if (formatName === 'CSV' && subformatName === 'CELL') {
|
|
6170
|
+
outputSubparameterName = 'newCell';
|
|
6171
|
+
}
|
|
6172
|
+
else if (formatName === 'TEXT' && subformatName === 'LINE') {
|
|
6173
|
+
outputSubparameterName = 'newLine';
|
|
6174
|
+
}
|
|
6175
|
+
else {
|
|
6176
|
+
throw new ParseError(spaceTrim("\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 ")));
|
|
6177
|
+
}
|
|
6146
6178
|
}
|
|
6147
6179
|
return {
|
|
6148
6180
|
type: 'FOREACH',
|
|
6149
6181
|
formatName: formatName,
|
|
6150
6182
|
subformatName: subformatName,
|
|
6151
6183
|
parameterName: parameterName,
|
|
6152
|
-
|
|
6184
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6185
|
+
outputSubparameterName: outputSubparameterName,
|
|
6153
6186
|
};
|
|
6154
6187
|
},
|
|
6155
6188
|
/**
|
|
@@ -6158,10 +6191,16 @@ var foreachCommandParser = {
|
|
|
6158
6191
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
6159
6192
|
*/
|
|
6160
6193
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
6161
|
-
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName,
|
|
6194
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
6162
6195
|
// TODO: [🍭] Detect double use
|
|
6163
6196
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
6164
|
-
$templateJson.foreach = {
|
|
6197
|
+
$templateJson.foreach = {
|
|
6198
|
+
formatName: formatName,
|
|
6199
|
+
subformatName: subformatName,
|
|
6200
|
+
parameterName: parameterName,
|
|
6201
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6202
|
+
outputSubparameterName: outputSubparameterName,
|
|
6203
|
+
};
|
|
6165
6204
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
6166
6205
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
6167
6206
|
},
|