@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
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.69.0-
|
|
3
|
+
"version": "0.69.0-21",
|
|
4
4
|
"description": "Supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"module": "./esm/index.es.js",
|
|
52
52
|
"typings": "./esm/typings/src/_packages/node.index.d.ts",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@promptbook/core": "0.69.0-
|
|
54
|
+
"@promptbook/core": "0.69.0-21"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
/**
|
|
36
36
|
* The version of the Promptbook library
|
|
37
37
|
*/
|
|
38
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
38
|
+
var PROMPTBOOK_VERSION = '0.69.0-20';
|
|
39
39
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
40
40
|
|
|
41
41
|
/*! *****************************************************************************
|
|
@@ -2547,7 +2547,7 @@
|
|
|
2547
2547
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2548
2548
|
if (foreach !== undefined) {
|
|
2549
2549
|
try {
|
|
2550
|
-
for (var _l = __values(foreach.
|
|
2550
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
2551
2551
|
var subparameterName = _m.value;
|
|
2552
2552
|
if (parameterNames.has(subparameterName)) {
|
|
2553
2553
|
parameterNames.delete(subparameterName);
|
|
@@ -2703,7 +2703,7 @@
|
|
|
2703
2703
|
subvalueDefinitions: [
|
|
2704
2704
|
{
|
|
2705
2705
|
subvalueName: 'ROW',
|
|
2706
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2706
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2707
2707
|
return __awaiter(this, void 0, void 0, function () {
|
|
2708
2708
|
var csv, mappedData;
|
|
2709
2709
|
var _this = this;
|
|
@@ -2716,20 +2716,20 @@
|
|
|
2716
2716
|
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 "); }));
|
|
2717
2717
|
}
|
|
2718
2718
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2719
|
-
var _a;
|
|
2720
|
-
var
|
|
2721
|
-
return __generator(this, function (
|
|
2722
|
-
switch (
|
|
2719
|
+
var _a, _b;
|
|
2720
|
+
var _c;
|
|
2721
|
+
return __generator(this, function (_d) {
|
|
2722
|
+
switch (_d.label) {
|
|
2723
2723
|
case 0:
|
|
2724
|
+
if (row[outputParameterName]) {
|
|
2725
|
+
throw new ParseError(// <- TODO: !!!!!! Split PipelineParseError and FormatParseError -> CsvParseError
|
|
2726
|
+
"Can not overwrite existing column \"".concat(outputParameterName, "\" in CSV row"));
|
|
2727
|
+
}
|
|
2724
2728
|
_a = [__assign({}, row)];
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2729
|
+
_c = {};
|
|
2730
|
+
_b = outputParameterName;
|
|
2728
2731
|
return [4 /*yield*/, mapCallback(row, index)];
|
|
2729
|
-
case 1: return [2 /*return*/,
|
|
2730
|
-
// <- TODO: !!!!!! Dynamic new column name and position
|
|
2731
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2732
|
-
_c.sent(), _b)])))];
|
|
2732
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c[_b] = _d.sent(), _c)]))];
|
|
2733
2733
|
}
|
|
2734
2734
|
});
|
|
2735
2735
|
}); }))];
|
|
@@ -2743,7 +2743,7 @@
|
|
|
2743
2743
|
},
|
|
2744
2744
|
{
|
|
2745
2745
|
subvalueName: 'CELL',
|
|
2746
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2746
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2747
2747
|
return __awaiter(this, void 0, void 0, function () {
|
|
2748
2748
|
var csv, mappedData;
|
|
2749
2749
|
var _this = this;
|
|
@@ -2870,7 +2870,7 @@
|
|
|
2870
2870
|
subvalueDefinitions: [
|
|
2871
2871
|
{
|
|
2872
2872
|
subvalueName: 'LINE',
|
|
2873
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2873
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2874
2874
|
return __awaiter(this, void 0, void 0, function () {
|
|
2875
2875
|
var lines, mappedLines;
|
|
2876
2876
|
return __generator(this, function (_a) {
|
|
@@ -3782,7 +3782,7 @@
|
|
|
3782
3782
|
formatSettings = settings.csvSettings;
|
|
3783
3783
|
// <- TODO: !!!!!! More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
3784
3784
|
}
|
|
3785
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3785
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3786
3786
|
var mappedParameters, allSubparameters, subresultString;
|
|
3787
3787
|
return __generator(this, function (_a) {
|
|
3788
3788
|
switch (_a.label) {
|
|
@@ -3791,7 +3791,7 @@
|
|
|
3791
3791
|
// TODO: !!!!!!! Report progress
|
|
3792
3792
|
try {
|
|
3793
3793
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
3794
|
-
expectedParameters: Object.fromEntries(template.foreach.
|
|
3794
|
+
expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
3795
3795
|
availableParameters: subparameters,
|
|
3796
3796
|
});
|
|
3797
3797
|
}
|
|
@@ -3799,12 +3799,12 @@
|
|
|
3799
3799
|
if (!(error instanceof PipelineExecutionError)) {
|
|
3800
3800
|
throw error;
|
|
3801
3801
|
}
|
|
3802
|
-
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 "); }));
|
|
3802
|
+
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 "); }));
|
|
3803
3803
|
}
|
|
3804
3804
|
allSubparameters = __assign(__assign({}, parameters), mappedParameters);
|
|
3805
3805
|
// 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
|
|
3806
3806
|
Object.freeze(allSubparameters);
|
|
3807
|
-
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: pipelineIdentification }))];
|
|
3807
|
+
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 "); }) }))];
|
|
3808
3808
|
case 1:
|
|
3809
3809
|
subresultString = _a.sent();
|
|
3810
3810
|
return [2 /*return*/, subresultString];
|
|
@@ -4314,7 +4314,7 @@
|
|
|
4314
4314
|
},
|
|
4315
4315
|
settings: settings,
|
|
4316
4316
|
$executionReport: executionReport,
|
|
4317
|
-
pipelineIdentification: pipelineIdentification,
|
|
4317
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
4318
4318
|
})
|
|
4319
4319
|
.then(function (newParametersToPass) {
|
|
4320
4320
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
@@ -4437,9 +4437,11 @@
|
|
|
4437
4437
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
4438
4438
|
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 "); }));
|
|
4439
4439
|
}
|
|
4440
|
+
var runCount = 0;
|
|
4440
4441
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4441
4442
|
return __generator(this, function (_a) {
|
|
4442
|
-
|
|
4443
|
+
runCount++;
|
|
4444
|
+
return [2 /*return*/, /* not await */ executePipeline({
|
|
4443
4445
|
pipeline: pipeline,
|
|
4444
4446
|
preparedPipeline: preparedPipeline,
|
|
4445
4447
|
setPreparedPipeline: function (newPreparedPipeline) {
|
|
@@ -4448,7 +4450,7 @@
|
|
|
4448
4450
|
inputParameters: inputParameters,
|
|
4449
4451
|
tools: tools,
|
|
4450
4452
|
onProgress: onProgress,
|
|
4451
|
-
pipelineIdentification: pipelineIdentification,
|
|
4453
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
4452
4454
|
settings: {
|
|
4453
4455
|
maxExecutionAttempts: maxExecutionAttempts,
|
|
4454
4456
|
maxParallelCount: maxParallelCount,
|
|
@@ -5819,8 +5821,10 @@
|
|
|
5819
5821
|
*/
|
|
5820
5822
|
examples: [
|
|
5821
5823
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
5822
|
-
'
|
|
5823
|
-
'
|
|
5824
|
+
'FOREACH Csv Cell `{customers}` -> `{cell}`',
|
|
5825
|
+
'FOREACH Csv Row `{customers}` -> `{firstName}`, `{lastName}`, `+{email}`',
|
|
5826
|
+
'FOR Text Line `{customers}` -> `{customer}`',
|
|
5827
|
+
'EACH Text Line `{customers}` -> `{customer}`',
|
|
5824
5828
|
],
|
|
5825
5829
|
/**
|
|
5826
5830
|
* Parses the FOREACH command
|
|
@@ -5854,20 +5858,49 @@
|
|
|
5854
5858
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
5855
5859
|
}
|
|
5856
5860
|
var parameterName = validateParameterName(parameterNameArg);
|
|
5857
|
-
var
|
|
5861
|
+
var outputSubparameterName = null;
|
|
5862
|
+
// TODO: [4] DRY
|
|
5863
|
+
var inputSubparameterNames = args
|
|
5858
5864
|
.slice(4)
|
|
5859
5865
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
5866
|
+
.filter(function (parameterName) { return !parameterName.includes('+'); })
|
|
5860
5867
|
.filter(function (parameterName) { return parameterName !== ''; })
|
|
5861
5868
|
.map(validateParameterName);
|
|
5862
|
-
|
|
5863
|
-
|
|
5869
|
+
// TODO: [4] DRY
|
|
5870
|
+
var outputSubparameterNames = args
|
|
5871
|
+
.slice(4)
|
|
5872
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
5873
|
+
.filter(function (parameterName) { return parameterName.includes('+'); })
|
|
5874
|
+
.map(function (parameterName) { return parameterName.split('+').join(''); })
|
|
5875
|
+
.map(validateParameterName);
|
|
5876
|
+
if (outputSubparameterNames.length === 1) {
|
|
5877
|
+
outputSubparameterName = outputSubparameterNames[0];
|
|
5878
|
+
}
|
|
5879
|
+
else if (outputSubparameterNames.length > 1) {
|
|
5880
|
+
throw new ParseError("FOREACH command can not have more than one output subparameter");
|
|
5881
|
+
}
|
|
5882
|
+
if (inputSubparameterNames.length === 0) {
|
|
5883
|
+
throw new ParseError("FOREACH command must have at least one input subparameter");
|
|
5884
|
+
}
|
|
5885
|
+
if (outputSubparameterName === null) {
|
|
5886
|
+
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
5887
|
+
if (formatName === 'CSV' && subformatName === 'CELL') {
|
|
5888
|
+
outputSubparameterName = 'newCell';
|
|
5889
|
+
}
|
|
5890
|
+
else if (formatName === 'TEXT' && subformatName === 'LINE') {
|
|
5891
|
+
outputSubparameterName = 'newLine';
|
|
5892
|
+
}
|
|
5893
|
+
else {
|
|
5894
|
+
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 ")));
|
|
5895
|
+
}
|
|
5864
5896
|
}
|
|
5865
5897
|
return {
|
|
5866
5898
|
type: 'FOREACH',
|
|
5867
5899
|
formatName: formatName,
|
|
5868
5900
|
subformatName: subformatName,
|
|
5869
5901
|
parameterName: parameterName,
|
|
5870
|
-
|
|
5902
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
5903
|
+
outputSubparameterName: outputSubparameterName,
|
|
5871
5904
|
};
|
|
5872
5905
|
},
|
|
5873
5906
|
/**
|
|
@@ -5876,10 +5909,16 @@
|
|
|
5876
5909
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5877
5910
|
*/
|
|
5878
5911
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5879
|
-
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName,
|
|
5912
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
5880
5913
|
// TODO: [🍭] Detect double use
|
|
5881
5914
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
5882
|
-
$templateJson.foreach = {
|
|
5915
|
+
$templateJson.foreach = {
|
|
5916
|
+
formatName: formatName,
|
|
5917
|
+
subformatName: subformatName,
|
|
5918
|
+
parameterName: parameterName,
|
|
5919
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
5920
|
+
outputSubparameterName: outputSubparameterName,
|
|
5921
|
+
};
|
|
5883
5922
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
5884
5923
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
5885
5924
|
},
|