@promptbook/documents 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.
@@ -32,6 +32,7 @@ import { DEFAULT_IS_VERBOSE } from '../config';
32
32
  import { SET_IS_VERBOSE } from '../config';
33
33
  import { DEFAULT_IS_AUTO_INSTALLED } from '../config';
34
34
  import { DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME } from '../config';
35
+ import { DEFAULT_RPM } from '../config';
35
36
  import { ORDER_OF_PIPELINE_JSON } from '../constants';
36
37
  import { RESERVED_PARAMETER_NAMES } from '../constants';
37
38
  import { compilePipeline } from '../conversion/compilePipeline';
@@ -81,6 +82,7 @@ import { MANDATORY_CSV_SETTINGS } from '../formats/csv/CsvSettings';
81
82
  import { TextFormatParser } from '../formats/text/TextFormatParser';
82
83
  import { BoilerplateFormfactorDefinition } from '../formfactors/_boilerplate/BoilerplateFormfactorDefinition';
83
84
  import { ChatbotFormfactorDefinition } from '../formfactors/chatbot/ChatbotFormfactorDefinition';
85
+ import { CompletionFormfactorDefinition } from '../formfactors/completion/CompletionFormfactorDefinition';
84
86
  import { GeneratorFormfactorDefinition } from '../formfactors/generator/GeneratorFormfactorDefinition';
85
87
  import { GenericFormfactorDefinition } from '../formfactors/generic/GenericFormfactorDefinition';
86
88
  import { ImageGeneratorFormfactorDefinition } from '../formfactors/image-generator/ImageGeneratorFormfactorDefinition';
@@ -175,6 +177,7 @@ export { DEFAULT_IS_VERBOSE };
175
177
  export { SET_IS_VERBOSE };
176
178
  export { DEFAULT_IS_AUTO_INSTALLED };
177
179
  export { DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME };
180
+ export { DEFAULT_RPM };
178
181
  export { ORDER_OF_PIPELINE_JSON };
179
182
  export { RESERVED_PARAMETER_NAMES };
180
183
  export { compilePipeline };
@@ -224,6 +227,7 @@ export { MANDATORY_CSV_SETTINGS };
224
227
  export { TextFormatParser };
225
228
  export { BoilerplateFormfactorDefinition };
226
229
  export { ChatbotFormfactorDefinition };
230
+ export { CompletionFormfactorDefinition };
227
231
  export { GeneratorFormfactorDefinition };
228
232
  export { GenericFormfactorDefinition };
229
233
  export { ImageGeneratorFormfactorDefinition };
@@ -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 };
@@ -265,6 +265,14 @@ export declare const DEFAULT_IS_AUTO_INSTALLED = false;
265
265
  * @public exported from `@promptbook/core`
266
266
  */
267
267
  export declare const DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = "getPipelineCollection";
268
+ /**
269
+ * Default rate limits (requests per minute)
270
+ *
271
+ * Note: Adjust based on the provider tier you are have
272
+ *
273
+ * @public exported from `@promptbook/core`
274
+ */
275
+ export declare const DEFAULT_RPM = 60;
268
276
  /**
269
277
  * @@@
270
278
  *
@@ -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(value: TValue, outputParameterName: string_parameter_name, settings: TSettings, mapCallback: (subvalues: Parameters, index: number) => Promisable<string>): Promise<string>;
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: [πŸ‘©πŸΎβ€πŸ€β€πŸ§‘πŸ½]
@@ -6,6 +6,3 @@
6
6
  * @public exported from `@promptbook/utils`
7
7
  */
8
8
  export declare function jsonParse<T>(value: string): T;
9
- /**
10
- * TODO: !!!! Use in Promptbook.studio
11
- */
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Completion is formfactor that emulates completion models
3
+ *
4
+ * @public exported from `@promptbook/core`
5
+ */
6
+ export declare const CompletionFormfactorDefinition: {
7
+ readonly name: "COMPLETION";
8
+ readonly description: "@@@";
9
+ readonly documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@";
10
+ readonly pipelineInterface: {
11
+ readonly inputParameters: readonly [{
12
+ readonly name: "inputText";
13
+ readonly description: "Input text to be completed";
14
+ readonly isInput: true;
15
+ readonly isOutput: false;
16
+ }, {
17
+ readonly name: "instructions";
18
+ readonly description: "Additional instructions for the model, for example the required length, empty by default";
19
+ readonly isInput: true;
20
+ readonly isOutput: false;
21
+ }];
22
+ readonly outputParameters: readonly [{
23
+ readonly name: "followingText";
24
+ readonly description: "Text that follows the input text";
25
+ readonly isInput: false;
26
+ readonly isOutput: true;
27
+ }];
28
+ };
29
+ };
@@ -36,9 +36,6 @@ export declare const FORMFACTOR_DEFINITIONS: readonly [{
36
36
  readonly outputParameters: readonly [{
37
37
  readonly name: "title";
38
38
  readonly description: "Title of the conversation";
39
- /**
40
- * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
41
- */
42
39
  readonly isInput: false;
43
40
  readonly isOutput: true;
44
41
  }, {
@@ -132,6 +129,11 @@ export declare const FORMFACTOR_DEFINITIONS: readonly [{
132
129
  readonly isInput: true;
133
130
  readonly isOutput: false;
134
131
  }];
132
+ /**
133
+ * All available formfactor definitions
134
+ *
135
+ * @public exported from `@promptbook/core`
136
+ */
135
137
  readonly outputParameters: readonly [{
136
138
  readonly name: "prompt";
137
139
  readonly description: "Prompt to be used for image generation";
@@ -139,6 +141,29 @@ export declare const FORMFACTOR_DEFINITIONS: readonly [{
139
141
  readonly isOutput: true;
140
142
  }];
141
143
  };
144
+ }, {
145
+ readonly name: "COMPLETION";
146
+ readonly description: "@@@";
147
+ readonly documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@";
148
+ readonly pipelineInterface: {
149
+ readonly inputParameters: readonly [{
150
+ readonly name: "inputText";
151
+ readonly description: "Input text to be completed";
152
+ readonly isInput: true;
153
+ readonly isOutput: false;
154
+ }, {
155
+ readonly name: "instructions";
156
+ readonly description: "Additional instructions for the model, for example the required length, empty by default";
157
+ readonly isInput: true;
158
+ readonly isOutput: false;
159
+ }];
160
+ readonly outputParameters: readonly [{
161
+ readonly name: "followingText";
162
+ readonly description: "Text that follows the input text";
163
+ readonly isInput: false;
164
+ readonly isOutput: true;
165
+ }];
166
+ };
142
167
  }];
143
168
  /**
144
169
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -23,7 +23,7 @@ export declare const HIGH_LEVEL_ABSTRACTIONS: readonly [{
23
23
  path: string | null;
24
24
  content: import("../pipeline/PipelineString").PipelineString;
25
25
  }[];
26
- readonly formfactorName?: "CHATBOT" | "GENERATOR" | "GENERIC" | "IMAGE_GENERATOR" | "EXPERIMENTAL_MATCHER" | "SHEETS" | "TRANSLATOR" | undefined;
26
+ readonly formfactorName?: "CHATBOT" | "COMPLETION" | "GENERATOR" | "GENERIC" | "IMAGE_GENERATOR" | "EXPERIMENTAL_MATCHER" | "SHEETS" | "TRANSLATOR" | undefined;
27
27
  }>): void;
28
28
  }, {
29
29
  type: "SYNC";
@@ -45,7 +45,7 @@ export declare const HIGH_LEVEL_ABSTRACTIONS: readonly [{
45
45
  path: string | null;
46
46
  content: import("../pipeline/PipelineString").PipelineString;
47
47
  }[];
48
- readonly formfactorName?: "CHATBOT" | "GENERATOR" | "GENERIC" | "IMAGE_GENERATOR" | "EXPERIMENTAL_MATCHER" | "SHEETS" | "TRANSLATOR" | undefined;
48
+ readonly formfactorName?: "CHATBOT" | "COMPLETION" | "GENERATOR" | "GENERIC" | "IMAGE_GENERATOR" | "EXPERIMENTAL_MATCHER" | "SHEETS" | "TRANSLATOR" | undefined;
49
49
  }>): void;
50
50
  }];
51
51
  /**
@@ -2,6 +2,8 @@ import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
2
2
  /**
3
3
  * Migrates the pipeline to the latest version
4
4
  *
5
+ * Note: Migration does not do heavy lifting like calling the LLMs, just lightweight changes of the structure
6
+ *
5
7
  * @public exported from `@promptbook/core`
6
8
  */
7
9
  export declare function migratePipeline(deprecatedPipeline: PipelineJson): PipelineJson;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/documents",
3
- "version": "0.92.0-20",
3
+ "version": "0.92.0-22",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
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/documents.index.d.ts",
53
53
  "peerDependencies": {
54
- "@promptbook/core": "0.92.0-20"
54
+ "@promptbook/core": "0.92.0-22"
55
55
  },
56
56
  "dependencies": {
57
57
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -26,7 +26,7 @@
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-20';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -2543,15 +2543,12 @@
2543
2543
  }
2544
2544
  throw new Error(spaceTrim__default["default"]((block) => `
2545
2545
  ${block(error.message)}
2546
-
2546
+
2547
2547
  The JSON text:
2548
2548
  ${block(value)}
2549
2549
  `));
2550
2550
  }
2551
2551
  }
2552
- /**
2553
- * TODO: !!!! Use in Promptbook.studio
2554
- */
2555
2552
 
2556
2553
  /**
2557
2554
  * Recursively converts JSON strings to JSON objects
@@ -4303,7 +4300,8 @@
4303
4300
  subvalueParsers: [
4304
4301
  {
4305
4302
  subvalueName: 'ROW',
4306
- async mapValues(value, outputParameterName, settings, mapCallback) {
4303
+ async mapValues(options) {
4304
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4307
4305
  const csv = csvParse(value, settings);
4308
4306
  if (csv.errors.length !== 0) {
4309
4307
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
@@ -4319,21 +4317,29 @@
4319
4317
  ${block(value)}
4320
4318
  `));
4321
4319
  }
4322
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4320
+ const mappedData = [];
4321
+ for (let index = 0; index < csv.data.length; index++) {
4322
+ const row = csv.data[index];
4323
4323
  if (row[outputParameterName]) {
4324
4324
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4325
4325
  }
4326
- return {
4326
+ const mappedRow = {
4327
4327
  ...row,
4328
4328
  [outputParameterName]: await mapCallback(row, index),
4329
4329
  };
4330
- }));
4330
+ mappedData.push(mappedRow);
4331
+ if (onProgress) {
4332
+ // Note: Report the CSV with all rows mapped so far
4333
+ await onProgress(papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4334
+ }
4335
+ }
4331
4336
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4332
4337
  },
4333
4338
  },
4334
4339
  {
4335
4340
  subvalueName: 'CELL',
4336
- async mapValues(value, outputParameterName, settings, mapCallback) {
4341
+ async mapValues(options) {
4342
+ const { value, settings, mapCallback, onProgress } = options;
4337
4343
  const csv = csvParse(value, settings);
4338
4344
  if (csv.errors.length !== 0) {
4339
4345
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
@@ -4420,7 +4426,8 @@
4420
4426
  subvalueParsers: [
4421
4427
  {
4422
4428
  subvalueName: 'LINE',
4423
- async mapValues(value, outputParameterName, settings, mapCallback) {
4429
+ async mapValues(options) {
4430
+ const { value, mapCallback, onProgress } = options;
4424
4431
  const lines = value.split('\n');
4425
4432
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4426
4433
  // TODO: [🧠] Maybe option to skip empty line
@@ -5241,7 +5248,7 @@
5241
5248
  * @private internal utility of `createPipelineExecutor`
5242
5249
  */
5243
5250
  async function executeFormatSubvalues(options) {
5244
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5251
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5245
5252
  if (task.foreach === undefined) {
5246
5253
  return /* not await */ executeAttempts(options);
5247
5254
  }
@@ -5295,21 +5302,32 @@
5295
5302
  formatSettings = csvSettings;
5296
5303
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5297
5304
  }
5298
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5299
- let mappedParameters;
5300
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5301
- // TODO: When done [🐚] Report progress also for each subvalue here
5302
- try {
5303
- mappedParameters = mapAvailableToExpectedParameters({
5304
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5305
- availableParameters: subparameters,
5306
- });
5307
- }
5308
- catch (error) {
5309
- if (!(error instanceof PipelineExecutionError)) {
5310
- throw error;
5305
+ const resultString = await subvalueParser.mapValues({
5306
+ value: parameterValue,
5307
+ outputParameterName: task.foreach.outputSubparameterName,
5308
+ settings: formatSettings,
5309
+ onProgress(partialResultString) {
5310
+ return onProgress(Object.freeze({
5311
+ [task.resultingParameterName]:
5312
+ // <- Note: [πŸ‘©β€πŸ‘©β€πŸ‘§] No need to detect parameter collision here because pipeline checks logic consistency during construction
5313
+ partialResultString,
5314
+ }));
5315
+ },
5316
+ async mapCallback(subparameters, index) {
5317
+ let mappedParameters;
5318
+ // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5319
+ // TODO: When done [🐚] Report progress also for each subvalue here
5320
+ try {
5321
+ mappedParameters = mapAvailableToExpectedParameters({
5322
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5323
+ availableParameters: subparameters,
5324
+ });
5311
5325
  }
5312
- throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5326
+ catch (error) {
5327
+ if (!(error instanceof PipelineExecutionError)) {
5328
+ throw error;
5329
+ }
5330
+ throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5313
5331
  ${error.message}
5314
5332
 
5315
5333
  This is error in FOREACH command
@@ -5318,23 +5336,24 @@
5318
5336
  ${block(pipelineIdentification)}
5319
5337
  Subparameter index: ${index}
5320
5338
  `));
5321
- }
5322
- const allSubparameters = {
5323
- ...parameters,
5324
- ...mappedParameters,
5325
- };
5326
- // 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
5327
- Object.freeze(allSubparameters);
5328
- const subresultString = await executeAttempts({
5329
- ...options,
5330
- priority: priority + index,
5331
- parameters: allSubparameters,
5332
- pipelineIdentification: spaceTrim__default["default"]((block) => `
5339
+ }
5340
+ const allSubparameters = {
5341
+ ...parameters,
5342
+ ...mappedParameters,
5343
+ };
5344
+ // 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
5345
+ Object.freeze(allSubparameters);
5346
+ const subresultString = await executeAttempts({
5347
+ ...options,
5348
+ priority: priority + index,
5349
+ parameters: allSubparameters,
5350
+ pipelineIdentification: spaceTrim__default["default"]((block) => `
5333
5351
  ${block(pipelineIdentification)}
5334
5352
  Subparameter index: ${index}
5335
5353
  `),
5336
- });
5337
- return subresultString;
5354
+ });
5355
+ return subresultString;
5356
+ },
5338
5357
  });
5339
5358
  return resultString;
5340
5359
  }
@@ -5508,11 +5527,6 @@
5508
5527
  async function executeTask(options) {
5509
5528
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5510
5529
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5511
- await onProgress({
5512
- outputParameters: {
5513
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5514
- },
5515
- });
5516
5530
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5517
5531
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5518
5532
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5587,6 +5601,7 @@
5587
5601
  preparedPipeline,
5588
5602
  tools,
5589
5603
  $executionReport,
5604
+ onProgress,
5590
5605
  pipelineIdentification,
5591
5606
  maxExecutionAttempts,
5592
5607
  maxParallelCount,