@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
|
@@ -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
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* The version of the Promptbook library
|
|
18
18
|
*/
|
|
19
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
19
|
+
var PROMPTBOOK_VERSION = '0.69.0-20';
|
|
20
20
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
21
21
|
|
|
22
22
|
/*! *****************************************************************************
|
|
@@ -2830,7 +2830,7 @@
|
|
|
2830
2830
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2831
2831
|
if (foreach !== undefined) {
|
|
2832
2832
|
try {
|
|
2833
|
-
for (var _l = __values(foreach.
|
|
2833
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
2834
2834
|
var subparameterName = _m.value;
|
|
2835
2835
|
if (parameterNames.has(subparameterName)) {
|
|
2836
2836
|
parameterNames.delete(subparameterName);
|
|
@@ -2986,7 +2986,7 @@
|
|
|
2986
2986
|
subvalueDefinitions: [
|
|
2987
2987
|
{
|
|
2988
2988
|
subvalueName: 'ROW',
|
|
2989
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2989
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2990
2990
|
return __awaiter(this, void 0, void 0, function () {
|
|
2991
2991
|
var csv, mappedData;
|
|
2992
2992
|
var _this = this;
|
|
@@ -2999,20 +2999,20 @@
|
|
|
2999
2999
|
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 "); }));
|
|
3000
3000
|
}
|
|
3001
3001
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3002
|
-
var _a;
|
|
3003
|
-
var
|
|
3004
|
-
return __generator(this, function (
|
|
3005
|
-
switch (
|
|
3002
|
+
var _a, _b;
|
|
3003
|
+
var _c;
|
|
3004
|
+
return __generator(this, function (_d) {
|
|
3005
|
+
switch (_d.label) {
|
|
3006
3006
|
case 0:
|
|
3007
|
+
if (row[outputParameterName]) {
|
|
3008
|
+
throw new ParseError(// <- TODO: !!!!!! Split PipelineParseError and FormatParseError -> CsvParseError
|
|
3009
|
+
"Can not overwrite existing column \"".concat(outputParameterName, "\" in CSV row"));
|
|
3010
|
+
}
|
|
3007
3011
|
_a = [__assign({}, row)];
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
// <- TODO: !!!!!! Check name collisions
|
|
3012
|
+
_c = {};
|
|
3013
|
+
_b = outputParameterName;
|
|
3011
3014
|
return [4 /*yield*/, mapCallback(row, index)];
|
|
3012
|
-
case 1: return [2 /*return*/,
|
|
3013
|
-
// <- TODO: !!!!!! Dynamic new column name and position
|
|
3014
|
-
// <- TODO: !!!!!! Check name collisions
|
|
3015
|
-
_c.sent(), _b)])))];
|
|
3015
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c[_b] = _d.sent(), _c)]))];
|
|
3016
3016
|
}
|
|
3017
3017
|
});
|
|
3018
3018
|
}); }))];
|
|
@@ -3026,7 +3026,7 @@
|
|
|
3026
3026
|
},
|
|
3027
3027
|
{
|
|
3028
3028
|
subvalueName: 'CELL',
|
|
3029
|
-
mapValues: function (value, settings, mapCallback) {
|
|
3029
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
3030
3030
|
return __awaiter(this, void 0, void 0, function () {
|
|
3031
3031
|
var csv, mappedData;
|
|
3032
3032
|
var _this = this;
|
|
@@ -3153,7 +3153,7 @@
|
|
|
3153
3153
|
subvalueDefinitions: [
|
|
3154
3154
|
{
|
|
3155
3155
|
subvalueName: 'LINE',
|
|
3156
|
-
mapValues: function (value, settings, mapCallback) {
|
|
3156
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
3157
3157
|
return __awaiter(this, void 0, void 0, function () {
|
|
3158
3158
|
var lines, mappedLines;
|
|
3159
3159
|
return __generator(this, function (_a) {
|
|
@@ -4087,7 +4087,7 @@
|
|
|
4087
4087
|
formatSettings = settings.csvSettings;
|
|
4088
4088
|
// <- TODO: !!!!!! More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
4089
4089
|
}
|
|
4090
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4090
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4091
4091
|
var mappedParameters, allSubparameters, subresultString;
|
|
4092
4092
|
return __generator(this, function (_a) {
|
|
4093
4093
|
switch (_a.label) {
|
|
@@ -4096,7 +4096,7 @@
|
|
|
4096
4096
|
// TODO: !!!!!!! Report progress
|
|
4097
4097
|
try {
|
|
4098
4098
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
4099
|
-
expectedParameters: Object.fromEntries(template.foreach.
|
|
4099
|
+
expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
4100
4100
|
availableParameters: subparameters,
|
|
4101
4101
|
});
|
|
4102
4102
|
}
|
|
@@ -4104,12 +4104,12 @@
|
|
|
4104
4104
|
if (!(error instanceof PipelineExecutionError)) {
|
|
4105
4105
|
throw error;
|
|
4106
4106
|
}
|
|
4107
|
-
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 "); }));
|
|
4107
|
+
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 "); }));
|
|
4108
4108
|
}
|
|
4109
4109
|
allSubparameters = __assign(__assign({}, parameters), mappedParameters);
|
|
4110
4110
|
// 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
|
|
4111
4111
|
Object.freeze(allSubparameters);
|
|
4112
|
-
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: pipelineIdentification }))];
|
|
4112
|
+
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 "); }) }))];
|
|
4113
4113
|
case 1:
|
|
4114
4114
|
subresultString = _a.sent();
|
|
4115
4115
|
return [2 /*return*/, subresultString];
|
|
@@ -4619,7 +4619,7 @@
|
|
|
4619
4619
|
},
|
|
4620
4620
|
settings: settings,
|
|
4621
4621
|
$executionReport: executionReport,
|
|
4622
|
-
pipelineIdentification: pipelineIdentification,
|
|
4622
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
4623
4623
|
})
|
|
4624
4624
|
.then(function (newParametersToPass) {
|
|
4625
4625
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
@@ -4742,9 +4742,11 @@
|
|
|
4742
4742
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
4743
4743
|
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 "); }));
|
|
4744
4744
|
}
|
|
4745
|
+
var runCount = 0;
|
|
4745
4746
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4746
4747
|
return __generator(this, function (_a) {
|
|
4747
|
-
|
|
4748
|
+
runCount++;
|
|
4749
|
+
return [2 /*return*/, /* not await */ executePipeline({
|
|
4748
4750
|
pipeline: pipeline,
|
|
4749
4751
|
preparedPipeline: preparedPipeline,
|
|
4750
4752
|
setPreparedPipeline: function (newPreparedPipeline) {
|
|
@@ -4753,7 +4755,7 @@
|
|
|
4753
4755
|
inputParameters: inputParameters,
|
|
4754
4756
|
tools: tools,
|
|
4755
4757
|
onProgress: onProgress,
|
|
4756
|
-
pipelineIdentification: pipelineIdentification,
|
|
4758
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
4757
4759
|
settings: {
|
|
4758
4760
|
maxExecutionAttempts: maxExecutionAttempts,
|
|
4759
4761
|
maxParallelCount: maxParallelCount,
|
|
@@ -6106,8 +6108,10 @@
|
|
|
6106
6108
|
*/
|
|
6107
6109
|
examples: [
|
|
6108
6110
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
6109
|
-
'
|
|
6110
|
-
'
|
|
6111
|
+
'FOREACH Csv Cell `{customers}` -> `{cell}`',
|
|
6112
|
+
'FOREACH Csv Row `{customers}` -> `{firstName}`, `{lastName}`, `+{email}`',
|
|
6113
|
+
'FOR Text Line `{customers}` -> `{customer}`',
|
|
6114
|
+
'EACH Text Line `{customers}` -> `{customer}`',
|
|
6111
6115
|
],
|
|
6112
6116
|
/**
|
|
6113
6117
|
* Parses the FOREACH command
|
|
@@ -6141,20 +6145,49 @@
|
|
|
6141
6145
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
6142
6146
|
}
|
|
6143
6147
|
var parameterName = validateParameterName(parameterNameArg);
|
|
6144
|
-
var
|
|
6148
|
+
var outputSubparameterName = null;
|
|
6149
|
+
// TODO: [4] DRY
|
|
6150
|
+
var inputSubparameterNames = args
|
|
6145
6151
|
.slice(4)
|
|
6146
6152
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6153
|
+
.filter(function (parameterName) { return !parameterName.includes('+'); })
|
|
6147
6154
|
.filter(function (parameterName) { return parameterName !== ''; })
|
|
6148
6155
|
.map(validateParameterName);
|
|
6149
|
-
|
|
6150
|
-
|
|
6156
|
+
// TODO: [4] DRY
|
|
6157
|
+
var outputSubparameterNames = args
|
|
6158
|
+
.slice(4)
|
|
6159
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6160
|
+
.filter(function (parameterName) { return parameterName.includes('+'); })
|
|
6161
|
+
.map(function (parameterName) { return parameterName.split('+').join(''); })
|
|
6162
|
+
.map(validateParameterName);
|
|
6163
|
+
if (outputSubparameterNames.length === 1) {
|
|
6164
|
+
outputSubparameterName = outputSubparameterNames[0];
|
|
6165
|
+
}
|
|
6166
|
+
else if (outputSubparameterNames.length > 1) {
|
|
6167
|
+
throw new ParseError("FOREACH command can not have more than one output subparameter");
|
|
6168
|
+
}
|
|
6169
|
+
if (inputSubparameterNames.length === 0) {
|
|
6170
|
+
throw new ParseError("FOREACH command must have at least one input subparameter");
|
|
6171
|
+
}
|
|
6172
|
+
if (outputSubparameterName === null) {
|
|
6173
|
+
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
6174
|
+
if (formatName === 'CSV' && subformatName === 'CELL') {
|
|
6175
|
+
outputSubparameterName = 'newCell';
|
|
6176
|
+
}
|
|
6177
|
+
else if (formatName === 'TEXT' && subformatName === 'LINE') {
|
|
6178
|
+
outputSubparameterName = 'newLine';
|
|
6179
|
+
}
|
|
6180
|
+
else {
|
|
6181
|
+
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 ")));
|
|
6182
|
+
}
|
|
6151
6183
|
}
|
|
6152
6184
|
return {
|
|
6153
6185
|
type: 'FOREACH',
|
|
6154
6186
|
formatName: formatName,
|
|
6155
6187
|
subformatName: subformatName,
|
|
6156
6188
|
parameterName: parameterName,
|
|
6157
|
-
|
|
6189
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6190
|
+
outputSubparameterName: outputSubparameterName,
|
|
6158
6191
|
};
|
|
6159
6192
|
},
|
|
6160
6193
|
/**
|
|
@@ -6163,10 +6196,16 @@
|
|
|
6163
6196
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
6164
6197
|
*/
|
|
6165
6198
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
6166
|
-
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName,
|
|
6199
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
6167
6200
|
// TODO: [🍭] Detect double use
|
|
6168
6201
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
6169
|
-
$templateJson.foreach = {
|
|
6202
|
+
$templateJson.foreach = {
|
|
6203
|
+
formatName: formatName,
|
|
6204
|
+
subformatName: subformatName,
|
|
6205
|
+
parameterName: parameterName,
|
|
6206
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6207
|
+
outputSubparameterName: outputSubparameterName,
|
|
6208
|
+
};
|
|
6170
6209
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
6171
6210
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
6172
6211
|
},
|