@promptbook/core 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
package/esm/index.es.js
CHANGED
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [π] Ignore a discrepancy between file name and entity name
|
|
@@ -2822,7 +2822,8 @@ const CsvFormatParser = {
|
|
|
2822
2822
|
subvalueParsers: [
|
|
2823
2823
|
{
|
|
2824
2824
|
subvalueName: 'ROW',
|
|
2825
|
-
async mapValues(
|
|
2825
|
+
async mapValues(options) {
|
|
2826
|
+
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
2826
2827
|
const csv = csvParse(value, settings);
|
|
2827
2828
|
if (csv.errors.length !== 0) {
|
|
2828
2829
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -2838,21 +2839,29 @@ const CsvFormatParser = {
|
|
|
2838
2839
|
${block(value)}
|
|
2839
2840
|
`));
|
|
2840
2841
|
}
|
|
2841
|
-
const mappedData =
|
|
2842
|
+
const mappedData = [];
|
|
2843
|
+
for (let index = 0; index < csv.data.length; index++) {
|
|
2844
|
+
const row = csv.data[index];
|
|
2842
2845
|
if (row[outputParameterName]) {
|
|
2843
2846
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
2844
2847
|
}
|
|
2845
|
-
|
|
2848
|
+
const mappedRow = {
|
|
2846
2849
|
...row,
|
|
2847
2850
|
[outputParameterName]: await mapCallback(row, index),
|
|
2848
2851
|
};
|
|
2849
|
-
|
|
2852
|
+
mappedData.push(mappedRow);
|
|
2853
|
+
if (onProgress) {
|
|
2854
|
+
// Note: Report the CSV with all rows mapped so far
|
|
2855
|
+
await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2850
2858
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
2851
2859
|
},
|
|
2852
2860
|
},
|
|
2853
2861
|
{
|
|
2854
2862
|
subvalueName: 'CELL',
|
|
2855
|
-
async mapValues(
|
|
2863
|
+
async mapValues(options) {
|
|
2864
|
+
const { value, settings, mapCallback, onProgress } = options;
|
|
2856
2865
|
const csv = csvParse(value, settings);
|
|
2857
2866
|
if (csv.errors.length !== 0) {
|
|
2858
2867
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -2939,7 +2948,8 @@ const TextFormatParser = {
|
|
|
2939
2948
|
subvalueParsers: [
|
|
2940
2949
|
{
|
|
2941
2950
|
subvalueName: 'LINE',
|
|
2942
|
-
async mapValues(
|
|
2951
|
+
async mapValues(options) {
|
|
2952
|
+
const { value, mapCallback, onProgress } = options;
|
|
2943
2953
|
const lines = value.split('\n');
|
|
2944
2954
|
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
2945
2955
|
// TODO: [π§ ] Maybe option to skip empty line
|
|
@@ -4271,7 +4281,7 @@ async function executeAttempts(options) {
|
|
|
4271
4281
|
* @private internal utility of `createPipelineExecutor`
|
|
4272
4282
|
*/
|
|
4273
4283
|
async function executeFormatSubvalues(options) {
|
|
4274
|
-
const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
|
|
4284
|
+
const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
|
|
4275
4285
|
if (task.foreach === undefined) {
|
|
4276
4286
|
return /* not await */ executeAttempts(options);
|
|
4277
4287
|
}
|
|
@@ -4325,21 +4335,32 @@ async function executeFormatSubvalues(options) {
|
|
|
4325
4335
|
formatSettings = csvSettings;
|
|
4326
4336
|
// <- TODO: [π€ΉββοΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
4327
4337
|
}
|
|
4328
|
-
const resultString = await subvalueParser.mapValues(
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4338
|
+
const resultString = await subvalueParser.mapValues({
|
|
4339
|
+
value: parameterValue,
|
|
4340
|
+
outputParameterName: task.foreach.outputSubparameterName,
|
|
4341
|
+
settings: formatSettings,
|
|
4342
|
+
onProgress(partialResultString) {
|
|
4343
|
+
return onProgress(Object.freeze({
|
|
4344
|
+
[task.resultingParameterName]:
|
|
4345
|
+
// <- Note: [π©βπ©βπ§] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
4346
|
+
partialResultString,
|
|
4347
|
+
}));
|
|
4348
|
+
},
|
|
4349
|
+
async mapCallback(subparameters, index) {
|
|
4350
|
+
let mappedParameters;
|
|
4351
|
+
// TODO: [π€ΉββοΈ][πͺ] Limit to N concurrent executions
|
|
4352
|
+
// TODO: When done [π] Report progress also for each subvalue here
|
|
4353
|
+
try {
|
|
4354
|
+
mappedParameters = mapAvailableToExpectedParameters({
|
|
4355
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
4356
|
+
availableParameters: subparameters,
|
|
4357
|
+
});
|
|
4341
4358
|
}
|
|
4342
|
-
|
|
4359
|
+
catch (error) {
|
|
4360
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
4361
|
+
throw error;
|
|
4362
|
+
}
|
|
4363
|
+
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
4343
4364
|
${error.message}
|
|
4344
4365
|
|
|
4345
4366
|
This is error in FOREACH command
|
|
@@ -4348,23 +4369,24 @@ async function executeFormatSubvalues(options) {
|
|
|
4348
4369
|
${block(pipelineIdentification)}
|
|
4349
4370
|
Subparameter index: ${index}
|
|
4350
4371
|
`));
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4372
|
+
}
|
|
4373
|
+
const allSubparameters = {
|
|
4374
|
+
...parameters,
|
|
4375
|
+
...mappedParameters,
|
|
4376
|
+
};
|
|
4377
|
+
// 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
|
|
4378
|
+
Object.freeze(allSubparameters);
|
|
4379
|
+
const subresultString = await executeAttempts({
|
|
4380
|
+
...options,
|
|
4381
|
+
priority: priority + index,
|
|
4382
|
+
parameters: allSubparameters,
|
|
4383
|
+
pipelineIdentification: spaceTrim((block) => `
|
|
4363
4384
|
${block(pipelineIdentification)}
|
|
4364
4385
|
Subparameter index: ${index}
|
|
4365
4386
|
`),
|
|
4366
|
-
|
|
4367
|
-
|
|
4387
|
+
});
|
|
4388
|
+
return subresultString;
|
|
4389
|
+
},
|
|
4368
4390
|
});
|
|
4369
4391
|
return resultString;
|
|
4370
4392
|
}
|
|
@@ -4538,11 +4560,6 @@ async function getReservedParametersForTask(options) {
|
|
|
4538
4560
|
async function executeTask(options) {
|
|
4539
4561
|
const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
|
|
4540
4562
|
const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
4541
|
-
await onProgress({
|
|
4542
|
-
outputParameters: {
|
|
4543
|
-
[currentTask.resultingParameterName]: '', // <- TODO: [π§ ] What is the best value here?
|
|
4544
|
-
},
|
|
4545
|
-
});
|
|
4546
4563
|
// Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but itβs good to doublecheck
|
|
4547
4564
|
const usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
4548
4565
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
@@ -4617,6 +4634,7 @@ async function executeTask(options) {
|
|
|
4617
4634
|
preparedPipeline,
|
|
4618
4635
|
tools,
|
|
4619
4636
|
$executionReport,
|
|
4637
|
+
onProgress,
|
|
4620
4638
|
pipelineIdentification,
|
|
4621
4639
|
maxExecutionAttempts,
|
|
4622
4640
|
maxParallelCount,
|