@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
|
@@ -19,5 +19,9 @@ export type ForeachJson = {
|
|
|
19
19
|
/**
|
|
20
20
|
* @@@
|
|
21
21
|
*/
|
|
22
|
-
readonly
|
|
22
|
+
readonly inputSubparameterNames: Array<string_parameter_name>;
|
|
23
|
+
/**
|
|
24
|
+
* @@@
|
|
25
|
+
*/
|
|
26
|
+
readonly outputSubparameterName: string_parameter_name;
|
|
23
27
|
};
|
|
@@ -4,4 +4,4 @@ import type { EmbeddingVector } from './EmbeddingVector';
|
|
|
4
4
|
*
|
|
5
5
|
* @public exported from `@promptbook/core`
|
|
6
6
|
*/
|
|
7
|
-
export declare function embeddingVectorToString(embeddingVector: EmbeddingVector): string;
|
|
7
|
+
export declare function embeddingVectorToString(embeddingVector: Readonly<EmbeddingVector>): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Promisable } from 'type-fest';
|
|
2
2
|
import type { Parameters } from '../../types/typeAliases';
|
|
3
|
+
import type { string_parameter_name } from '../../types/typeAliases';
|
|
3
4
|
import type { string_name } from '../../types/typeAliases';
|
|
4
5
|
import type { string_SCREAMING_CASE } from '../../utils/normalization/normalizeTo_SCREAMING_CASE';
|
|
5
6
|
import type { empty_object } from '../../utils/organization/empty_object';
|
|
@@ -23,7 +24,7 @@ export type FormatSubvalueDefinition<TValue extends string, TSettings extends em
|
|
|
23
24
|
* For example, if you have a JSON object and you want to map all values to uppercase
|
|
24
25
|
* Or iterate over all CSV cells @@@
|
|
25
26
|
*/
|
|
26
|
-
mapValues(value: TValue, settings: TSettings, mapCallback: (subvalues: Parameters, index: number) => Promisable<string>): Promise<string>;
|
|
27
|
+
mapValues(value: TValue, outputParameterName: string_parameter_name, settings: TSettings, mapCallback: (subvalues: Parameters, index: number) => Promisable<string>): Promise<string>;
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* Note: [👩🏾🤝🧑🏽]
|
|
@@ -33,7 +33,7 @@ export type ParameterJson = {
|
|
|
33
33
|
readonly sampleValues?: Array<string_parameter_value>;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
|
-
* TODO: [🧠]
|
|
36
|
+
* TODO: [🧠] Should be here registered subparameters from foreach or not?
|
|
37
37
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
38
38
|
* TODO: [🍙] Make some standard order of json properties
|
|
39
39
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
1
2
|
import type { ExecutionReportJson } from './ExecutionReportJson';
|
|
2
3
|
import type { ExecutionReportString } from './ExecutionReportString';
|
|
3
4
|
import type { ExecutionReportStringOptions } from './ExecutionReportStringOptions';
|
|
@@ -6,7 +7,7 @@ import type { ExecutionReportStringOptions } from './ExecutionReportStringOption
|
|
|
6
7
|
*
|
|
7
8
|
* @public exported from `@promptbook/core`
|
|
8
9
|
*/
|
|
9
|
-
export declare function executionReportJsonToString(executionReportJson: ExecutionReportJson
|
|
10
|
+
export declare function executionReportJsonToString(executionReportJson: ReadonlyDeep<ExecutionReportJson>, options?: Partial<ExecutionReportStringOptions>): ExecutionReportString;
|
|
10
11
|
/**
|
|
11
12
|
* TODO: Add mermaid chart for every report
|
|
12
13
|
* TODO: [🧠] Allow to filter out some parts of the report by options
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
/**
|
|
40
40
|
* The version of the Promptbook library
|
|
41
41
|
*/
|
|
42
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
42
|
+
var PROMPTBOOK_VERSION = '0.69.0-20';
|
|
43
43
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
44
44
|
|
|
45
45
|
/*! *****************************************************************************
|
|
@@ -2695,7 +2695,7 @@
|
|
|
2695
2695
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2696
2696
|
if (foreach !== undefined) {
|
|
2697
2697
|
try {
|
|
2698
|
-
for (var _l = __values(foreach.
|
|
2698
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
2699
2699
|
var subparameterName = _m.value;
|
|
2700
2700
|
if (parameterNames.has(subparameterName)) {
|
|
2701
2701
|
parameterNames.delete(subparameterName);
|
|
@@ -2851,7 +2851,7 @@
|
|
|
2851
2851
|
subvalueDefinitions: [
|
|
2852
2852
|
{
|
|
2853
2853
|
subvalueName: 'ROW',
|
|
2854
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2854
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2855
2855
|
return __awaiter(this, void 0, void 0, function () {
|
|
2856
2856
|
var csv, mappedData;
|
|
2857
2857
|
var _this = this;
|
|
@@ -2864,20 +2864,20 @@
|
|
|
2864
2864
|
spaceTrim__default["default"](function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2865
2865
|
}
|
|
2866
2866
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2867
|
-
var _a;
|
|
2868
|
-
var
|
|
2869
|
-
return __generator(this, function (
|
|
2870
|
-
switch (
|
|
2867
|
+
var _a, _b;
|
|
2868
|
+
var _c;
|
|
2869
|
+
return __generator(this, function (_d) {
|
|
2870
|
+
switch (_d.label) {
|
|
2871
2871
|
case 0:
|
|
2872
|
+
if (row[outputParameterName]) {
|
|
2873
|
+
throw new ParseError(// <- TODO: !!!!!! Split PipelineParseError and FormatParseError -> CsvParseError
|
|
2874
|
+
"Can not overwrite existing column \"".concat(outputParameterName, "\" in CSV row"));
|
|
2875
|
+
}
|
|
2872
2876
|
_a = [__assign({}, row)];
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2877
|
+
_c = {};
|
|
2878
|
+
_b = outputParameterName;
|
|
2876
2879
|
return [4 /*yield*/, mapCallback(row, index)];
|
|
2877
|
-
case 1: return [2 /*return*/,
|
|
2878
|
-
// <- TODO: !!!!!! Dynamic new column name and position
|
|
2879
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2880
|
-
_c.sent(), _b)])))];
|
|
2880
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c[_b] = _d.sent(), _c)]))];
|
|
2881
2881
|
}
|
|
2882
2882
|
});
|
|
2883
2883
|
}); }))];
|
|
@@ -2891,7 +2891,7 @@
|
|
|
2891
2891
|
},
|
|
2892
2892
|
{
|
|
2893
2893
|
subvalueName: 'CELL',
|
|
2894
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2894
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2895
2895
|
return __awaiter(this, void 0, void 0, function () {
|
|
2896
2896
|
var csv, mappedData;
|
|
2897
2897
|
var _this = this;
|
|
@@ -3018,7 +3018,7 @@
|
|
|
3018
3018
|
subvalueDefinitions: [
|
|
3019
3019
|
{
|
|
3020
3020
|
subvalueName: 'LINE',
|
|
3021
|
-
mapValues: function (value, settings, mapCallback) {
|
|
3021
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
3022
3022
|
return __awaiter(this, void 0, void 0, function () {
|
|
3023
3023
|
var lines, mappedLines;
|
|
3024
3024
|
return __generator(this, function (_a) {
|
|
@@ -3930,7 +3930,7 @@
|
|
|
3930
3930
|
formatSettings = settings.csvSettings;
|
|
3931
3931
|
// <- TODO: !!!!!! More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
3932
3932
|
}
|
|
3933
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3933
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3934
3934
|
var mappedParameters, allSubparameters, subresultString;
|
|
3935
3935
|
return __generator(this, function (_a) {
|
|
3936
3936
|
switch (_a.label) {
|
|
@@ -3939,7 +3939,7 @@
|
|
|
3939
3939
|
// TODO: !!!!!!! Report progress
|
|
3940
3940
|
try {
|
|
3941
3941
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
3942
|
-
expectedParameters: Object.fromEntries(template.foreach.
|
|
3942
|
+
expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
3943
3943
|
availableParameters: subparameters,
|
|
3944
3944
|
});
|
|
3945
3945
|
}
|
|
@@ -3947,12 +3947,12 @@
|
|
|
3947
3947
|
if (!(error instanceof PipelineExecutionError)) {
|
|
3948
3948
|
throw error;
|
|
3949
3949
|
}
|
|
3950
|
-
throw new PipelineExecutionError(spaceTrim__default["default"](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 "); }));
|
|
3950
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](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 "); }));
|
|
3951
3951
|
}
|
|
3952
3952
|
allSubparameters = __assign(__assign({}, parameters), mappedParameters);
|
|
3953
3953
|
// 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
|
|
3954
3954
|
Object.freeze(allSubparameters);
|
|
3955
|
-
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: pipelineIdentification }))];
|
|
3955
|
+
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim__default["default"](function (block) { return "\n ".concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }) }))];
|
|
3956
3956
|
case 1:
|
|
3957
3957
|
subresultString = _a.sent();
|
|
3958
3958
|
return [2 /*return*/, subresultString];
|
|
@@ -4462,7 +4462,7 @@
|
|
|
4462
4462
|
},
|
|
4463
4463
|
settings: settings,
|
|
4464
4464
|
$executionReport: executionReport,
|
|
4465
|
-
pipelineIdentification: pipelineIdentification,
|
|
4465
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
4466
4466
|
})
|
|
4467
4467
|
.then(function (newParametersToPass) {
|
|
4468
4468
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
@@ -4585,9 +4585,11 @@
|
|
|
4585
4585
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
4586
4586
|
console.warn(spaceTrim.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 "); }));
|
|
4587
4587
|
}
|
|
4588
|
+
var runCount = 0;
|
|
4588
4589
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4589
4590
|
return __generator(this, function (_a) {
|
|
4590
|
-
|
|
4591
|
+
runCount++;
|
|
4592
|
+
return [2 /*return*/, /* not await */ executePipeline({
|
|
4591
4593
|
pipeline: pipeline,
|
|
4592
4594
|
preparedPipeline: preparedPipeline,
|
|
4593
4595
|
setPreparedPipeline: function (newPreparedPipeline) {
|
|
@@ -4596,7 +4598,7 @@
|
|
|
4596
4598
|
inputParameters: inputParameters,
|
|
4597
4599
|
tools: tools,
|
|
4598
4600
|
onProgress: onProgress,
|
|
4599
|
-
pipelineIdentification: pipelineIdentification,
|
|
4601
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
4600
4602
|
settings: {
|
|
4601
4603
|
maxExecutionAttempts: maxExecutionAttempts,
|
|
4602
4604
|
maxParallelCount: maxParallelCount,
|
|
@@ -5967,8 +5969,10 @@
|
|
|
5967
5969
|
*/
|
|
5968
5970
|
examples: [
|
|
5969
5971
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
5970
|
-
'
|
|
5971
|
-
'
|
|
5972
|
+
'FOREACH Csv Cell `{customers}` -> `{cell}`',
|
|
5973
|
+
'FOREACH Csv Row `{customers}` -> `{firstName}`, `{lastName}`, `+{email}`',
|
|
5974
|
+
'FOR Text Line `{customers}` -> `{customer}`',
|
|
5975
|
+
'EACH Text Line `{customers}` -> `{customer}`',
|
|
5972
5976
|
],
|
|
5973
5977
|
/**
|
|
5974
5978
|
* Parses the FOREACH command
|
|
@@ -6002,20 +6006,49 @@
|
|
|
6002
6006
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
6003
6007
|
}
|
|
6004
6008
|
var parameterName = validateParameterName(parameterNameArg);
|
|
6005
|
-
var
|
|
6009
|
+
var outputSubparameterName = null;
|
|
6010
|
+
// TODO: [4] DRY
|
|
6011
|
+
var inputSubparameterNames = args
|
|
6006
6012
|
.slice(4)
|
|
6007
6013
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6014
|
+
.filter(function (parameterName) { return !parameterName.includes('+'); })
|
|
6008
6015
|
.filter(function (parameterName) { return parameterName !== ''; })
|
|
6009
6016
|
.map(validateParameterName);
|
|
6010
|
-
|
|
6011
|
-
|
|
6017
|
+
// TODO: [4] DRY
|
|
6018
|
+
var outputSubparameterNames = args
|
|
6019
|
+
.slice(4)
|
|
6020
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6021
|
+
.filter(function (parameterName) { return parameterName.includes('+'); })
|
|
6022
|
+
.map(function (parameterName) { return parameterName.split('+').join(''); })
|
|
6023
|
+
.map(validateParameterName);
|
|
6024
|
+
if (outputSubparameterNames.length === 1) {
|
|
6025
|
+
outputSubparameterName = outputSubparameterNames[0];
|
|
6026
|
+
}
|
|
6027
|
+
else if (outputSubparameterNames.length > 1) {
|
|
6028
|
+
throw new ParseError("FOREACH command can not have more than one output subparameter");
|
|
6029
|
+
}
|
|
6030
|
+
if (inputSubparameterNames.length === 0) {
|
|
6031
|
+
throw new ParseError("FOREACH command must have at least one input subparameter");
|
|
6032
|
+
}
|
|
6033
|
+
if (outputSubparameterName === null) {
|
|
6034
|
+
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
6035
|
+
if (formatName === 'CSV' && subformatName === 'CELL') {
|
|
6036
|
+
outputSubparameterName = 'newCell';
|
|
6037
|
+
}
|
|
6038
|
+
else if (formatName === 'TEXT' && subformatName === 'LINE') {
|
|
6039
|
+
outputSubparameterName = 'newLine';
|
|
6040
|
+
}
|
|
6041
|
+
else {
|
|
6042
|
+
throw new ParseError(spaceTrim__default["default"]("\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 ")));
|
|
6043
|
+
}
|
|
6012
6044
|
}
|
|
6013
6045
|
return {
|
|
6014
6046
|
type: 'FOREACH',
|
|
6015
6047
|
formatName: formatName,
|
|
6016
6048
|
subformatName: subformatName,
|
|
6017
6049
|
parameterName: parameterName,
|
|
6018
|
-
|
|
6050
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6051
|
+
outputSubparameterName: outputSubparameterName,
|
|
6019
6052
|
};
|
|
6020
6053
|
},
|
|
6021
6054
|
/**
|
|
@@ -6024,10 +6057,16 @@
|
|
|
6024
6057
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
6025
6058
|
*/
|
|
6026
6059
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
6027
|
-
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName,
|
|
6060
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
6028
6061
|
// TODO: [🍭] Detect double use
|
|
6029
6062
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
6030
|
-
$templateJson.foreach = {
|
|
6063
|
+
$templateJson.foreach = {
|
|
6064
|
+
formatName: formatName,
|
|
6065
|
+
subformatName: subformatName,
|
|
6066
|
+
parameterName: parameterName,
|
|
6067
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6068
|
+
outputSubparameterName: outputSubparameterName,
|
|
6069
|
+
};
|
|
6031
6070
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
6032
6071
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
6033
6072
|
},
|