@promptbook/cli 0.92.0-21 β 0.92.0-22
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 +59 -41
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +8 -1
- package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +11 -1
- package/package.json +1 -1
- package/umd/index.umd.js +59 -41
- package/umd/index.umd.js.map +1 -1
|
@@ -62,6 +62,7 @@ import type { UsageCounts } from '../execution/Usage';
|
|
|
62
62
|
import type { UserInterfaceTools } from '../execution/UserInterfaceTools';
|
|
63
63
|
import type { UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools';
|
|
64
64
|
import type { FormatSubvalueParser } from '../formats/_common/FormatSubvalueParser';
|
|
65
|
+
import type { FormatSubvalueParserMapValuesOptions } from '../formats/_common/FormatSubvalueParser';
|
|
65
66
|
import type { CsvSettings } from '../formats/csv/CsvSettings';
|
|
66
67
|
import type { AbstractFormfactorDefinition } from '../formfactors/_common/AbstractFormfactorDefinition';
|
|
67
68
|
import type { FormfactorDefinition } from '../formfactors/_common/FormfactorDefinition';
|
|
@@ -358,6 +359,7 @@ export type { UsageCounts };
|
|
|
358
359
|
export type { UserInterfaceTools };
|
|
359
360
|
export type { UserInterfaceToolsPromptDialogOptions };
|
|
360
361
|
export type { FormatSubvalueParser };
|
|
362
|
+
export type { FormatSubvalueParserMapValuesOptions };
|
|
361
363
|
export type { CsvSettings };
|
|
362
364
|
export type { AbstractFormfactorDefinition };
|
|
363
365
|
export type { FormfactorDefinition };
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import type { PartialDeep, Promisable } from 'type-fest';
|
|
1
2
|
import type { TODO_any } from '../../utils/organization/TODO_any';
|
|
3
|
+
import type { PipelineExecutorResult } from '../PipelineExecutorResult';
|
|
2
4
|
import type { ExecuteAttemptsOptions } from './40-executeAttempts';
|
|
3
5
|
/**
|
|
4
6
|
* @@@
|
|
5
7
|
*
|
|
6
8
|
* @private internal type of `executeFormatSubvalues`
|
|
7
9
|
*/
|
|
8
|
-
type ExecuteFormatCellsOptions = ExecuteAttemptsOptions
|
|
10
|
+
type ExecuteFormatCellsOptions = ExecuteAttemptsOptions & {
|
|
11
|
+
/**
|
|
12
|
+
* @@@
|
|
13
|
+
*/
|
|
14
|
+
readonly onProgress: (newOngoingResult: PartialDeep<PipelineExecutorResult>) => Promisable<void>;
|
|
15
|
+
};
|
|
9
16
|
/**
|
|
10
17
|
* @@@
|
|
11
18
|
*
|
|
@@ -24,7 +24,17 @@ export type FormatSubvalueParser<TValue extends string, TSettings extends empty_
|
|
|
24
24
|
* For example, if you have a JSON object and you want to map all values to uppercase
|
|
25
25
|
* Or iterate over all CSV cells @@@
|
|
26
26
|
*/
|
|
27
|
-
mapValues(
|
|
27
|
+
mapValues(options: FormatSubvalueParserMapValuesOptions<TValue, TSettings>): Promise<string>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @@@
|
|
31
|
+
*/
|
|
32
|
+
export type FormatSubvalueParserMapValuesOptions<TValue extends string, TSettings extends empty_object> = {
|
|
33
|
+
readonly value: TValue;
|
|
34
|
+
readonly outputParameterName: string_parameter_name;
|
|
35
|
+
readonly settings: TSettings;
|
|
36
|
+
mapCallback: (subvalues: Parameters, index: number) => Promisable<TValue>;
|
|
37
|
+
onProgress(partialResultString: TValue): Promisable<void>;
|
|
28
38
|
};
|
|
29
39
|
/**
|
|
30
40
|
* Note: [π©πΎβπ€βπ§π½]
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
* @generated
|
|
58
58
|
* @see https://github.com/webgptorg/promptbook
|
|
59
59
|
*/
|
|
60
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
60
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
|
|
61
61
|
/**
|
|
62
62
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
63
63
|
* Note: [π] Ignore a discrepancy between file name and entity name
|
|
@@ -5475,7 +5475,8 @@
|
|
|
5475
5475
|
subvalueParsers: [
|
|
5476
5476
|
{
|
|
5477
5477
|
subvalueName: 'ROW',
|
|
5478
|
-
async mapValues(
|
|
5478
|
+
async mapValues(options) {
|
|
5479
|
+
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
5479
5480
|
const csv = csvParse(value, settings);
|
|
5480
5481
|
if (csv.errors.length !== 0) {
|
|
5481
5482
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
@@ -5491,21 +5492,29 @@
|
|
|
5491
5492
|
${block(value)}
|
|
5492
5493
|
`));
|
|
5493
5494
|
}
|
|
5494
|
-
const mappedData =
|
|
5495
|
+
const mappedData = [];
|
|
5496
|
+
for (let index = 0; index < csv.data.length; index++) {
|
|
5497
|
+
const row = csv.data[index];
|
|
5495
5498
|
if (row[outputParameterName]) {
|
|
5496
5499
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
5497
5500
|
}
|
|
5498
|
-
|
|
5501
|
+
const mappedRow = {
|
|
5499
5502
|
...row,
|
|
5500
5503
|
[outputParameterName]: await mapCallback(row, index),
|
|
5501
5504
|
};
|
|
5502
|
-
|
|
5505
|
+
mappedData.push(mappedRow);
|
|
5506
|
+
if (onProgress) {
|
|
5507
|
+
// Note: Report the CSV with all rows mapped so far
|
|
5508
|
+
await onProgress(papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
|
|
5509
|
+
}
|
|
5510
|
+
}
|
|
5503
5511
|
return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
5504
5512
|
},
|
|
5505
5513
|
},
|
|
5506
5514
|
{
|
|
5507
5515
|
subvalueName: 'CELL',
|
|
5508
|
-
async mapValues(
|
|
5516
|
+
async mapValues(options) {
|
|
5517
|
+
const { value, settings, mapCallback, onProgress } = options;
|
|
5509
5518
|
const csv = csvParse(value, settings);
|
|
5510
5519
|
if (csv.errors.length !== 0) {
|
|
5511
5520
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
@@ -5592,7 +5601,8 @@
|
|
|
5592
5601
|
subvalueParsers: [
|
|
5593
5602
|
{
|
|
5594
5603
|
subvalueName: 'LINE',
|
|
5595
|
-
async mapValues(
|
|
5604
|
+
async mapValues(options) {
|
|
5605
|
+
const { value, mapCallback, onProgress } = options;
|
|
5596
5606
|
const lines = value.split('\n');
|
|
5597
5607
|
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
5598
5608
|
// TODO: [π§ ] Maybe option to skip empty line
|
|
@@ -6432,7 +6442,7 @@
|
|
|
6432
6442
|
* @private internal utility of `createPipelineExecutor`
|
|
6433
6443
|
*/
|
|
6434
6444
|
async function executeFormatSubvalues(options) {
|
|
6435
|
-
const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
|
|
6445
|
+
const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
|
|
6436
6446
|
if (task.foreach === undefined) {
|
|
6437
6447
|
return /* not await */ executeAttempts(options);
|
|
6438
6448
|
}
|
|
@@ -6486,21 +6496,32 @@
|
|
|
6486
6496
|
formatSettings = csvSettings;
|
|
6487
6497
|
// <- TODO: [π€ΉββοΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
6488
6498
|
}
|
|
6489
|
-
const resultString = await subvalueParser.mapValues(
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6499
|
+
const resultString = await subvalueParser.mapValues({
|
|
6500
|
+
value: parameterValue,
|
|
6501
|
+
outputParameterName: task.foreach.outputSubparameterName,
|
|
6502
|
+
settings: formatSettings,
|
|
6503
|
+
onProgress(partialResultString) {
|
|
6504
|
+
return onProgress(Object.freeze({
|
|
6505
|
+
[task.resultingParameterName]:
|
|
6506
|
+
// <- Note: [π©βπ©βπ§] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
6507
|
+
partialResultString,
|
|
6508
|
+
}));
|
|
6509
|
+
},
|
|
6510
|
+
async mapCallback(subparameters, index) {
|
|
6511
|
+
let mappedParameters;
|
|
6512
|
+
// TODO: [π€ΉββοΈ][πͺ] Limit to N concurrent executions
|
|
6513
|
+
// TODO: When done [π] Report progress also for each subvalue here
|
|
6514
|
+
try {
|
|
6515
|
+
mappedParameters = mapAvailableToExpectedParameters({
|
|
6516
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
6517
|
+
availableParameters: subparameters,
|
|
6518
|
+
});
|
|
6502
6519
|
}
|
|
6503
|
-
|
|
6520
|
+
catch (error) {
|
|
6521
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
6522
|
+
throw error;
|
|
6523
|
+
}
|
|
6524
|
+
throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
|
|
6504
6525
|
${error.message}
|
|
6505
6526
|
|
|
6506
6527
|
This is error in FOREACH command
|
|
@@ -6509,23 +6530,24 @@
|
|
|
6509
6530
|
${block(pipelineIdentification)}
|
|
6510
6531
|
Subparameter index: ${index}
|
|
6511
6532
|
`));
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6533
|
+
}
|
|
6534
|
+
const allSubparameters = {
|
|
6535
|
+
...parameters,
|
|
6536
|
+
...mappedParameters,
|
|
6537
|
+
};
|
|
6538
|
+
// 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
|
|
6539
|
+
Object.freeze(allSubparameters);
|
|
6540
|
+
const subresultString = await executeAttempts({
|
|
6541
|
+
...options,
|
|
6542
|
+
priority: priority + index,
|
|
6543
|
+
parameters: allSubparameters,
|
|
6544
|
+
pipelineIdentification: spaceTrim__default["default"]((block) => `
|
|
6524
6545
|
${block(pipelineIdentification)}
|
|
6525
6546
|
Subparameter index: ${index}
|
|
6526
6547
|
`),
|
|
6527
|
-
|
|
6528
|
-
|
|
6548
|
+
});
|
|
6549
|
+
return subresultString;
|
|
6550
|
+
},
|
|
6529
6551
|
});
|
|
6530
6552
|
return resultString;
|
|
6531
6553
|
}
|
|
@@ -6699,11 +6721,6 @@
|
|
|
6699
6721
|
async function executeTask(options) {
|
|
6700
6722
|
const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
|
|
6701
6723
|
const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
6702
|
-
await onProgress({
|
|
6703
|
-
outputParameters: {
|
|
6704
|
-
[currentTask.resultingParameterName]: '', // <- TODO: [π§ ] What is the best value here?
|
|
6705
|
-
},
|
|
6706
|
-
});
|
|
6707
6724
|
// Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but itβs good to doublecheck
|
|
6708
6725
|
const usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
6709
6726
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
@@ -6778,6 +6795,7 @@
|
|
|
6778
6795
|
preparedPipeline,
|
|
6779
6796
|
tools,
|
|
6780
6797
|
$executionReport,
|
|
6798
|
+
onProgress,
|
|
6781
6799
|
pipelineIdentification,
|
|
6782
6800
|
maxExecutionAttempts,
|
|
6783
6801
|
maxParallelCount,
|