@promptbook/cli 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
|
@@ -21,7 +21,7 @@ import OpenAI from 'openai';
|
|
|
21
21
|
/**
|
|
22
22
|
* The version of the Promptbook library
|
|
23
23
|
*/
|
|
24
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
24
|
+
var PROMPTBOOK_VERSION = '0.69.0-20';
|
|
25
25
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
26
26
|
|
|
27
27
|
/*! *****************************************************************************
|
|
@@ -2677,7 +2677,7 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
2677
2677
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2678
2678
|
if (foreach !== undefined) {
|
|
2679
2679
|
try {
|
|
2680
|
-
for (var _l = __values(foreach.
|
|
2680
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
2681
2681
|
var subparameterName = _m.value;
|
|
2682
2682
|
if (parameterNames.has(subparameterName)) {
|
|
2683
2683
|
parameterNames.delete(subparameterName);
|
|
@@ -2833,7 +2833,7 @@ var CsvFormatDefinition = {
|
|
|
2833
2833
|
subvalueDefinitions: [
|
|
2834
2834
|
{
|
|
2835
2835
|
subvalueName: 'ROW',
|
|
2836
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2836
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2837
2837
|
return __awaiter(this, void 0, void 0, function () {
|
|
2838
2838
|
var csv, mappedData;
|
|
2839
2839
|
var _this = this;
|
|
@@ -2846,20 +2846,20 @@ var CsvFormatDefinition = {
|
|
|
2846
2846
|
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 "); }));
|
|
2847
2847
|
}
|
|
2848
2848
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2849
|
-
var _a;
|
|
2850
|
-
var
|
|
2851
|
-
return __generator(this, function (
|
|
2852
|
-
switch (
|
|
2849
|
+
var _a, _b;
|
|
2850
|
+
var _c;
|
|
2851
|
+
return __generator(this, function (_d) {
|
|
2852
|
+
switch (_d.label) {
|
|
2853
2853
|
case 0:
|
|
2854
|
+
if (row[outputParameterName]) {
|
|
2855
|
+
throw new ParseError(// <- TODO: !!!!!! Split PipelineParseError and FormatParseError -> CsvParseError
|
|
2856
|
+
"Can not overwrite existing column \"".concat(outputParameterName, "\" in CSV row"));
|
|
2857
|
+
}
|
|
2854
2858
|
_a = [__assign({}, row)];
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2859
|
+
_c = {};
|
|
2860
|
+
_b = outputParameterName;
|
|
2858
2861
|
return [4 /*yield*/, mapCallback(row, index)];
|
|
2859
|
-
case 1: return [2 /*return*/,
|
|
2860
|
-
// <- TODO: !!!!!! Dynamic new column name and position
|
|
2861
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2862
|
-
_c.sent(), _b)])))];
|
|
2862
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c[_b] = _d.sent(), _c)]))];
|
|
2863
2863
|
}
|
|
2864
2864
|
});
|
|
2865
2865
|
}); }))];
|
|
@@ -2873,7 +2873,7 @@ var CsvFormatDefinition = {
|
|
|
2873
2873
|
},
|
|
2874
2874
|
{
|
|
2875
2875
|
subvalueName: 'CELL',
|
|
2876
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2876
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2877
2877
|
return __awaiter(this, void 0, void 0, function () {
|
|
2878
2878
|
var csv, mappedData;
|
|
2879
2879
|
var _this = this;
|
|
@@ -3000,7 +3000,7 @@ var TextFormatDefinition = {
|
|
|
3000
3000
|
subvalueDefinitions: [
|
|
3001
3001
|
{
|
|
3002
3002
|
subvalueName: 'LINE',
|
|
3003
|
-
mapValues: function (value, settings, mapCallback) {
|
|
3003
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
3004
3004
|
return __awaiter(this, void 0, void 0, function () {
|
|
3005
3005
|
var lines, mappedLines;
|
|
3006
3006
|
return __generator(this, function (_a) {
|
|
@@ -3912,7 +3912,7 @@ function executeFormatCells(options) {
|
|
|
3912
3912
|
formatSettings = settings.csvSettings;
|
|
3913
3913
|
// <- TODO: !!!!!! More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
3914
3914
|
}
|
|
3915
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3915
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3916
3916
|
var mappedParameters, allSubparameters, subresultString;
|
|
3917
3917
|
return __generator(this, function (_a) {
|
|
3918
3918
|
switch (_a.label) {
|
|
@@ -3921,7 +3921,7 @@ function executeFormatCells(options) {
|
|
|
3921
3921
|
// TODO: !!!!!!! Report progress
|
|
3922
3922
|
try {
|
|
3923
3923
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
3924
|
-
expectedParameters: Object.fromEntries(template.foreach.
|
|
3924
|
+
expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
3925
3925
|
availableParameters: subparameters,
|
|
3926
3926
|
});
|
|
3927
3927
|
}
|
|
@@ -3929,12 +3929,12 @@ function executeFormatCells(options) {
|
|
|
3929
3929
|
if (!(error instanceof PipelineExecutionError)) {
|
|
3930
3930
|
throw error;
|
|
3931
3931
|
}
|
|
3932
|
-
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 "); }));
|
|
3932
|
+
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 "); }));
|
|
3933
3933
|
}
|
|
3934
3934
|
allSubparameters = __assign(__assign({}, parameters), mappedParameters);
|
|
3935
3935
|
// 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
|
|
3936
3936
|
Object.freeze(allSubparameters);
|
|
3937
|
-
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: pipelineIdentification }))];
|
|
3937
|
+
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 "); }) }))];
|
|
3938
3938
|
case 1:
|
|
3939
3939
|
subresultString = _a.sent();
|
|
3940
3940
|
return [2 /*return*/, subresultString];
|
|
@@ -4444,7 +4444,7 @@ function executePipeline(options) {
|
|
|
4444
4444
|
},
|
|
4445
4445
|
settings: settings,
|
|
4446
4446
|
$executionReport: executionReport,
|
|
4447
|
-
pipelineIdentification: pipelineIdentification,
|
|
4447
|
+
pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
4448
4448
|
})
|
|
4449
4449
|
.then(function (newParametersToPass) {
|
|
4450
4450
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
@@ -4567,9 +4567,11 @@ function createPipelineExecutor(options) {
|
|
|
4567
4567
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
4568
4568
|
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 "); }));
|
|
4569
4569
|
}
|
|
4570
|
+
var runCount = 0;
|
|
4570
4571
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4571
4572
|
return __generator(this, function (_a) {
|
|
4572
|
-
|
|
4573
|
+
runCount++;
|
|
4574
|
+
return [2 /*return*/, /* not await */ executePipeline({
|
|
4573
4575
|
pipeline: pipeline,
|
|
4574
4576
|
preparedPipeline: preparedPipeline,
|
|
4575
4577
|
setPreparedPipeline: function (newPreparedPipeline) {
|
|
@@ -4578,7 +4580,7 @@ function createPipelineExecutor(options) {
|
|
|
4578
4580
|
inputParameters: inputParameters,
|
|
4579
4581
|
tools: tools,
|
|
4580
4582
|
onProgress: onProgress,
|
|
4581
|
-
pipelineIdentification: pipelineIdentification,
|
|
4583
|
+
pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
4582
4584
|
settings: {
|
|
4583
4585
|
maxExecutionAttempts: maxExecutionAttempts,
|
|
4584
4586
|
maxParallelCount: maxParallelCount,
|
|
@@ -5949,8 +5951,10 @@ var foreachCommandParser = {
|
|
|
5949
5951
|
*/
|
|
5950
5952
|
examples: [
|
|
5951
5953
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
5952
|
-
'
|
|
5953
|
-
'
|
|
5954
|
+
'FOREACH Csv Cell `{customers}` -> `{cell}`',
|
|
5955
|
+
'FOREACH Csv Row `{customers}` -> `{firstName}`, `{lastName}`, `+{email}`',
|
|
5956
|
+
'FOR Text Line `{customers}` -> `{customer}`',
|
|
5957
|
+
'EACH Text Line `{customers}` -> `{customer}`',
|
|
5954
5958
|
],
|
|
5955
5959
|
/**
|
|
5956
5960
|
* Parses the FOREACH command
|
|
@@ -5984,20 +5988,49 @@ var foreachCommandParser = {
|
|
|
5984
5988
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
5985
5989
|
}
|
|
5986
5990
|
var parameterName = validateParameterName(parameterNameArg);
|
|
5987
|
-
var
|
|
5991
|
+
var outputSubparameterName = null;
|
|
5992
|
+
// TODO: [4] DRY
|
|
5993
|
+
var inputSubparameterNames = args
|
|
5988
5994
|
.slice(4)
|
|
5989
5995
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
5996
|
+
.filter(function (parameterName) { return !parameterName.includes('+'); })
|
|
5990
5997
|
.filter(function (parameterName) { return parameterName !== ''; })
|
|
5991
5998
|
.map(validateParameterName);
|
|
5992
|
-
|
|
5993
|
-
|
|
5999
|
+
// TODO: [4] DRY
|
|
6000
|
+
var outputSubparameterNames = args
|
|
6001
|
+
.slice(4)
|
|
6002
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6003
|
+
.filter(function (parameterName) { return parameterName.includes('+'); })
|
|
6004
|
+
.map(function (parameterName) { return parameterName.split('+').join(''); })
|
|
6005
|
+
.map(validateParameterName);
|
|
6006
|
+
if (outputSubparameterNames.length === 1) {
|
|
6007
|
+
outputSubparameterName = outputSubparameterNames[0];
|
|
6008
|
+
}
|
|
6009
|
+
else if (outputSubparameterNames.length > 1) {
|
|
6010
|
+
throw new ParseError("FOREACH command can not have more than one output subparameter");
|
|
6011
|
+
}
|
|
6012
|
+
if (inputSubparameterNames.length === 0) {
|
|
6013
|
+
throw new ParseError("FOREACH command must have at least one input subparameter");
|
|
6014
|
+
}
|
|
6015
|
+
if (outputSubparameterName === null) {
|
|
6016
|
+
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
6017
|
+
if (formatName === 'CSV' && subformatName === 'CELL') {
|
|
6018
|
+
outputSubparameterName = 'newCell';
|
|
6019
|
+
}
|
|
6020
|
+
else if (formatName === 'TEXT' && subformatName === 'LINE') {
|
|
6021
|
+
outputSubparameterName = 'newLine';
|
|
6022
|
+
}
|
|
6023
|
+
else {
|
|
6024
|
+
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 ")));
|
|
6025
|
+
}
|
|
5994
6026
|
}
|
|
5995
6027
|
return {
|
|
5996
6028
|
type: 'FOREACH',
|
|
5997
6029
|
formatName: formatName,
|
|
5998
6030
|
subformatName: subformatName,
|
|
5999
6031
|
parameterName: parameterName,
|
|
6000
|
-
|
|
6032
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6033
|
+
outputSubparameterName: outputSubparameterName,
|
|
6001
6034
|
};
|
|
6002
6035
|
},
|
|
6003
6036
|
/**
|
|
@@ -6006,10 +6039,16 @@ var foreachCommandParser = {
|
|
|
6006
6039
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
6007
6040
|
*/
|
|
6008
6041
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
6009
|
-
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName,
|
|
6042
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
6010
6043
|
// TODO: [🍭] Detect double use
|
|
6011
6044
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
6012
|
-
$templateJson.foreach = {
|
|
6045
|
+
$templateJson.foreach = {
|
|
6046
|
+
formatName: formatName,
|
|
6047
|
+
subformatName: subformatName,
|
|
6048
|
+
parameterName: parameterName,
|
|
6049
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6050
|
+
outputSubparameterName: outputSubparameterName,
|
|
6051
|
+
};
|
|
6013
6052
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
6014
6053
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
6015
6054
|
},
|