@promptbook/node 0.92.0-20 β 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 +99 -45
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/config.d.ts +8 -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/esm/typings/src/formats/json/utils/jsonParse.d.ts +0 -3
- package/esm/typings/src/formfactors/completion/CompletionFormfactorDefinition.d.ts +29 -0
- package/esm/typings/src/formfactors/index.d.ts +28 -3
- package/esm/typings/src/high-level-abstractions/index.d.ts +2 -2
- package/esm/typings/src/migrations/migratePipeline.d.ts +2 -0
- package/package.json +2 -2
- package/umd/index.umd.js +99 -45
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
30
30
|
* @generated
|
|
31
31
|
* @see https://github.com/webgptorg/promptbook
|
|
32
32
|
*/
|
|
33
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
33
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
|
|
34
34
|
/**
|
|
35
35
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
36
36
|
* Note: [π] Ignore a discrepancy between file name and entity name
|
|
@@ -328,15 +328,12 @@ function jsonParse(value) {
|
|
|
328
328
|
}
|
|
329
329
|
throw new Error(spaceTrim((block) => `
|
|
330
330
|
${block(error.message)}
|
|
331
|
-
|
|
331
|
+
|
|
332
332
|
The JSON text:
|
|
333
333
|
${block(value)}
|
|
334
334
|
`));
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
|
-
/**
|
|
338
|
-
* TODO: !!!! Use in Promptbook.studio
|
|
339
|
-
*/
|
|
340
337
|
|
|
341
338
|
/**
|
|
342
339
|
* Orders JSON object by keys
|
|
@@ -2588,7 +2585,8 @@ const CsvFormatParser = {
|
|
|
2588
2585
|
subvalueParsers: [
|
|
2589
2586
|
{
|
|
2590
2587
|
subvalueName: 'ROW',
|
|
2591
|
-
async mapValues(
|
|
2588
|
+
async mapValues(options) {
|
|
2589
|
+
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
2592
2590
|
const csv = csvParse(value, settings);
|
|
2593
2591
|
if (csv.errors.length !== 0) {
|
|
2594
2592
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -2604,21 +2602,29 @@ const CsvFormatParser = {
|
|
|
2604
2602
|
${block(value)}
|
|
2605
2603
|
`));
|
|
2606
2604
|
}
|
|
2607
|
-
const mappedData =
|
|
2605
|
+
const mappedData = [];
|
|
2606
|
+
for (let index = 0; index < csv.data.length; index++) {
|
|
2607
|
+
const row = csv.data[index];
|
|
2608
2608
|
if (row[outputParameterName]) {
|
|
2609
2609
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
2610
2610
|
}
|
|
2611
|
-
|
|
2611
|
+
const mappedRow = {
|
|
2612
2612
|
...row,
|
|
2613
2613
|
[outputParameterName]: await mapCallback(row, index),
|
|
2614
2614
|
};
|
|
2615
|
-
|
|
2615
|
+
mappedData.push(mappedRow);
|
|
2616
|
+
if (onProgress) {
|
|
2617
|
+
// Note: Report the CSV with all rows mapped so far
|
|
2618
|
+
await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2616
2621
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
2617
2622
|
},
|
|
2618
2623
|
},
|
|
2619
2624
|
{
|
|
2620
2625
|
subvalueName: 'CELL',
|
|
2621
|
-
async mapValues(
|
|
2626
|
+
async mapValues(options) {
|
|
2627
|
+
const { value, settings, mapCallback, onProgress } = options;
|
|
2622
2628
|
const csv = csvParse(value, settings);
|
|
2623
2629
|
if (csv.errors.length !== 0) {
|
|
2624
2630
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -2705,7 +2711,8 @@ const TextFormatParser = {
|
|
|
2705
2711
|
subvalueParsers: [
|
|
2706
2712
|
{
|
|
2707
2713
|
subvalueName: 'LINE',
|
|
2708
|
-
async mapValues(
|
|
2714
|
+
async mapValues(options) {
|
|
2715
|
+
const { value, mapCallback, onProgress } = options;
|
|
2709
2716
|
const lines = value.split('\n');
|
|
2710
2717
|
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
2711
2718
|
// TODO: [π§ ] Maybe option to skip empty line
|
|
@@ -4015,7 +4022,7 @@ async function executeAttempts(options) {
|
|
|
4015
4022
|
* @private internal utility of `createPipelineExecutor`
|
|
4016
4023
|
*/
|
|
4017
4024
|
async function executeFormatSubvalues(options) {
|
|
4018
|
-
const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
|
|
4025
|
+
const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
|
|
4019
4026
|
if (task.foreach === undefined) {
|
|
4020
4027
|
return /* not await */ executeAttempts(options);
|
|
4021
4028
|
}
|
|
@@ -4069,21 +4076,32 @@ async function executeFormatSubvalues(options) {
|
|
|
4069
4076
|
formatSettings = csvSettings;
|
|
4070
4077
|
// <- TODO: [π€ΉββοΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
4071
4078
|
}
|
|
4072
|
-
const resultString = await subvalueParser.mapValues(
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4079
|
+
const resultString = await subvalueParser.mapValues({
|
|
4080
|
+
value: parameterValue,
|
|
4081
|
+
outputParameterName: task.foreach.outputSubparameterName,
|
|
4082
|
+
settings: formatSettings,
|
|
4083
|
+
onProgress(partialResultString) {
|
|
4084
|
+
return onProgress(Object.freeze({
|
|
4085
|
+
[task.resultingParameterName]:
|
|
4086
|
+
// <- Note: [π©βπ©βπ§] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
4087
|
+
partialResultString,
|
|
4088
|
+
}));
|
|
4089
|
+
},
|
|
4090
|
+
async mapCallback(subparameters, index) {
|
|
4091
|
+
let mappedParameters;
|
|
4092
|
+
// TODO: [π€ΉββοΈ][πͺ] Limit to N concurrent executions
|
|
4093
|
+
// TODO: When done [π] Report progress also for each subvalue here
|
|
4094
|
+
try {
|
|
4095
|
+
mappedParameters = mapAvailableToExpectedParameters({
|
|
4096
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
4097
|
+
availableParameters: subparameters,
|
|
4098
|
+
});
|
|
4085
4099
|
}
|
|
4086
|
-
|
|
4100
|
+
catch (error) {
|
|
4101
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
4102
|
+
throw error;
|
|
4103
|
+
}
|
|
4104
|
+
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
4087
4105
|
${error.message}
|
|
4088
4106
|
|
|
4089
4107
|
This is error in FOREACH command
|
|
@@ -4092,23 +4110,24 @@ async function executeFormatSubvalues(options) {
|
|
|
4092
4110
|
${block(pipelineIdentification)}
|
|
4093
4111
|
Subparameter index: ${index}
|
|
4094
4112
|
`));
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4113
|
+
}
|
|
4114
|
+
const allSubparameters = {
|
|
4115
|
+
...parameters,
|
|
4116
|
+
...mappedParameters,
|
|
4117
|
+
};
|
|
4118
|
+
// 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
|
|
4119
|
+
Object.freeze(allSubparameters);
|
|
4120
|
+
const subresultString = await executeAttempts({
|
|
4121
|
+
...options,
|
|
4122
|
+
priority: priority + index,
|
|
4123
|
+
parameters: allSubparameters,
|
|
4124
|
+
pipelineIdentification: spaceTrim((block) => `
|
|
4107
4125
|
${block(pipelineIdentification)}
|
|
4108
4126
|
Subparameter index: ${index}
|
|
4109
4127
|
`),
|
|
4110
|
-
|
|
4111
|
-
|
|
4128
|
+
});
|
|
4129
|
+
return subresultString;
|
|
4130
|
+
},
|
|
4112
4131
|
});
|
|
4113
4132
|
return resultString;
|
|
4114
4133
|
}
|
|
@@ -4282,11 +4301,6 @@ async function getReservedParametersForTask(options) {
|
|
|
4282
4301
|
async function executeTask(options) {
|
|
4283
4302
|
const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
|
|
4284
4303
|
const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
4285
|
-
await onProgress({
|
|
4286
|
-
outputParameters: {
|
|
4287
|
-
[currentTask.resultingParameterName]: '', // <- TODO: [π§ ] What is the best value here?
|
|
4288
|
-
},
|
|
4289
|
-
});
|
|
4290
4304
|
// Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but itβs good to doublecheck
|
|
4291
4305
|
const usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
4292
4306
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
@@ -4361,6 +4375,7 @@ async function executeTask(options) {
|
|
|
4361
4375
|
preparedPipeline,
|
|
4362
4376
|
tools,
|
|
4363
4377
|
$executionReport,
|
|
4378
|
+
onProgress,
|
|
4364
4379
|
pipelineIdentification,
|
|
4365
4380
|
maxExecutionAttempts,
|
|
4366
4381
|
maxParallelCount,
|
|
@@ -6955,6 +6970,43 @@ const ChatbotFormfactorDefinition = {
|
|
|
6955
6970
|
},
|
|
6956
6971
|
};
|
|
6957
6972
|
|
|
6973
|
+
/**
|
|
6974
|
+
* Completion is formfactor that emulates completion models
|
|
6975
|
+
*
|
|
6976
|
+
* @public exported from `@promptbook/core`
|
|
6977
|
+
*/
|
|
6978
|
+
const CompletionFormfactorDefinition = {
|
|
6979
|
+
name: 'COMPLETION',
|
|
6980
|
+
description: `@@@`,
|
|
6981
|
+
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/@@`,
|
|
6982
|
+
// <- TODO: https://github.com/webgptorg/promptbook/discussions/new?category=concepts
|
|
6983
|
+
// "π Completion Formfactor"
|
|
6984
|
+
pipelineInterface: {
|
|
6985
|
+
inputParameters: [
|
|
6986
|
+
{
|
|
6987
|
+
name: 'inputText',
|
|
6988
|
+
description: `Input text to be completed`,
|
|
6989
|
+
isInput: true,
|
|
6990
|
+
isOutput: false,
|
|
6991
|
+
},
|
|
6992
|
+
{
|
|
6993
|
+
name: 'instructions',
|
|
6994
|
+
description: `Additional instructions for the model, for example the required length, empty by default`,
|
|
6995
|
+
isInput: true,
|
|
6996
|
+
isOutput: false,
|
|
6997
|
+
},
|
|
6998
|
+
],
|
|
6999
|
+
outputParameters: [
|
|
7000
|
+
{
|
|
7001
|
+
name: 'followingText',
|
|
7002
|
+
description: `Text that follows the input text`,
|
|
7003
|
+
isInput: false,
|
|
7004
|
+
isOutput: true,
|
|
7005
|
+
},
|
|
7006
|
+
],
|
|
7007
|
+
},
|
|
7008
|
+
};
|
|
7009
|
+
|
|
6958
7010
|
/**
|
|
6959
7011
|
* Generator is form of app that @@@
|
|
6960
7012
|
*
|
|
@@ -7139,6 +7191,8 @@ const FORMFACTOR_DEFINITIONS = [
|
|
|
7139
7191
|
MatcherFormfactorDefinition,
|
|
7140
7192
|
GeneratorFormfactorDefinition,
|
|
7141
7193
|
ImageGeneratorFormfactorDefinition,
|
|
7194
|
+
CompletionFormfactorDefinition,
|
|
7195
|
+
// <- [π¬] When making new formfactor, copy the _boilerplate and link it here
|
|
7142
7196
|
];
|
|
7143
7197
|
/**
|
|
7144
7198
|
* Note: [π] Ignore a discrepancy between file name and entity name
|