@promptbook/documents 0.89.0-1 → 0.89.0-3
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/README.md +3 -1
- package/esm/index.es.js +108 -79
- 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 +6 -4
- package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptResult.d.ts +2 -2
- package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
- package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
- package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
- package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
- package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
- package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
- package/esm/typings/src/playground/BrjappConnector.d.ts +3 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/package.json +2 -2
- package/umd/index.umd.js +108 -79
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -203,7 +203,7 @@ Each part of the book defines one of 3 circles:
|
|
|
203
203
|
|
|
204
204
|
### **What:** Workflows, Tasks and Parameters
|
|
205
205
|
|
|
206
|
-
What work needs to be done. Each book defines a workflow, which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
|
|
206
|
+
What work needs to be done. Each book defines a [workflow *(scenario or pipeline)*](https://github.com/webgptorg/promptbook/discussions/88), which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
|
|
207
207
|
|
|
208
208
|
**Related commands:**
|
|
209
209
|
|
|
@@ -313,6 +313,8 @@ The following glossary is used to clarify certain concepts:
|
|
|
313
313
|
|
|
314
314
|
|
|
315
315
|
|
|
316
|
+
|
|
317
|
+
|
|
316
318
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
317
319
|
|
|
318
320
|
|
package/esm/index.es.js
CHANGED
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-3';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -432,6 +432,7 @@ function $execCommand(options) {
|
|
|
432
432
|
}
|
|
433
433
|
else {
|
|
434
434
|
console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
|
|
435
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
435
436
|
resolve('Command exceeded time limit');
|
|
436
437
|
}
|
|
437
438
|
});
|
|
@@ -457,6 +458,7 @@ function $execCommand(options) {
|
|
|
457
458
|
output.push(stderr.toString());
|
|
458
459
|
if (isVerbose && stderr.toString().trim()) {
|
|
459
460
|
console.warn(stderr.toString());
|
|
461
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
460
462
|
}
|
|
461
463
|
});
|
|
462
464
|
const finishWithCode = (code) => {
|
|
@@ -468,6 +470,7 @@ function $execCommand(options) {
|
|
|
468
470
|
else {
|
|
469
471
|
if (isVerbose) {
|
|
470
472
|
console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
|
|
473
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
471
474
|
}
|
|
472
475
|
resolve(spaceTrim(output.join('\n')));
|
|
473
476
|
}
|
|
@@ -489,6 +492,7 @@ function $execCommand(options) {
|
|
|
489
492
|
else {
|
|
490
493
|
if (isVerbose) {
|
|
491
494
|
console.warn(error);
|
|
495
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
492
496
|
}
|
|
493
497
|
resolve(spaceTrim(output.join('\n')));
|
|
494
498
|
}
|
|
@@ -2467,6 +2471,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2467
2471
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
2468
2472
|
for (const warning of warnings) {
|
|
2469
2473
|
console.warn(warning.message);
|
|
2474
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2470
2475
|
}
|
|
2471
2476
|
if (isSuccessful === true) {
|
|
2472
2477
|
return;
|
|
@@ -2645,30 +2650,42 @@ async function forEachAsync(array, options, callbackfunction) {
|
|
|
2645
2650
|
await Promise.all(tasks);
|
|
2646
2651
|
}
|
|
2647
2652
|
|
|
2653
|
+
/**
|
|
2654
|
+
* Represents the uncertain value
|
|
2655
|
+
*
|
|
2656
|
+
* @public exported from `@promptbook/core`
|
|
2657
|
+
*/
|
|
2658
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2659
|
+
/**
|
|
2660
|
+
* Represents the uncertain value
|
|
2661
|
+
*
|
|
2662
|
+
* @public exported from `@promptbook/core`
|
|
2663
|
+
*/
|
|
2664
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2648
2665
|
/**
|
|
2649
2666
|
* Represents the usage with no resources consumed
|
|
2650
2667
|
*
|
|
2651
2668
|
* @public exported from `@promptbook/core`
|
|
2652
2669
|
*/
|
|
2653
2670
|
const ZERO_USAGE = $deepFreeze({
|
|
2654
|
-
price:
|
|
2671
|
+
price: ZERO_VALUE,
|
|
2655
2672
|
input: {
|
|
2656
|
-
tokensCount:
|
|
2657
|
-
charactersCount:
|
|
2658
|
-
wordsCount:
|
|
2659
|
-
sentencesCount:
|
|
2660
|
-
linesCount:
|
|
2661
|
-
paragraphsCount:
|
|
2662
|
-
pagesCount:
|
|
2673
|
+
tokensCount: ZERO_VALUE,
|
|
2674
|
+
charactersCount: ZERO_VALUE,
|
|
2675
|
+
wordsCount: ZERO_VALUE,
|
|
2676
|
+
sentencesCount: ZERO_VALUE,
|
|
2677
|
+
linesCount: ZERO_VALUE,
|
|
2678
|
+
paragraphsCount: ZERO_VALUE,
|
|
2679
|
+
pagesCount: ZERO_VALUE,
|
|
2663
2680
|
},
|
|
2664
2681
|
output: {
|
|
2665
|
-
tokensCount:
|
|
2666
|
-
charactersCount:
|
|
2667
|
-
wordsCount:
|
|
2668
|
-
sentencesCount:
|
|
2669
|
-
linesCount:
|
|
2670
|
-
paragraphsCount:
|
|
2671
|
-
pagesCount:
|
|
2682
|
+
tokensCount: ZERO_VALUE,
|
|
2683
|
+
charactersCount: ZERO_VALUE,
|
|
2684
|
+
wordsCount: ZERO_VALUE,
|
|
2685
|
+
sentencesCount: ZERO_VALUE,
|
|
2686
|
+
linesCount: ZERO_VALUE,
|
|
2687
|
+
paragraphsCount: ZERO_VALUE,
|
|
2688
|
+
pagesCount: ZERO_VALUE,
|
|
2672
2689
|
},
|
|
2673
2690
|
});
|
|
2674
2691
|
/**
|
|
@@ -2677,24 +2694,24 @@ const ZERO_USAGE = $deepFreeze({
|
|
|
2677
2694
|
* @public exported from `@promptbook/core`
|
|
2678
2695
|
*/
|
|
2679
2696
|
$deepFreeze({
|
|
2680
|
-
price:
|
|
2697
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2681
2698
|
input: {
|
|
2682
|
-
tokensCount:
|
|
2683
|
-
charactersCount:
|
|
2684
|
-
wordsCount:
|
|
2685
|
-
sentencesCount:
|
|
2686
|
-
linesCount:
|
|
2687
|
-
paragraphsCount:
|
|
2688
|
-
pagesCount:
|
|
2699
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2700
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2701
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2702
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2703
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2704
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2705
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2689
2706
|
},
|
|
2690
2707
|
output: {
|
|
2691
|
-
tokensCount:
|
|
2692
|
-
charactersCount:
|
|
2693
|
-
wordsCount:
|
|
2694
|
-
sentencesCount:
|
|
2695
|
-
linesCount:
|
|
2696
|
-
paragraphsCount:
|
|
2697
|
-
pagesCount:
|
|
2708
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2709
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2710
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2711
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2712
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2713
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2714
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2698
2715
|
},
|
|
2699
2716
|
});
|
|
2700
2717
|
/**
|
|
@@ -2982,6 +2999,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
|
|
|
2982
2999
|
`);
|
|
2983
3000
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2984
3001
|
console.warn(warningMessage);
|
|
3002
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2985
3003
|
/*
|
|
2986
3004
|
return {
|
|
2987
3005
|
async listModels() {
|
|
@@ -3529,63 +3547,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3529
3547
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3530
3548
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3531
3549
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3550
|
+
try {
|
|
3551
|
+
let partialPieces = null;
|
|
3552
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
3553
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
3554
|
+
for (const scraper of scrapers) {
|
|
3555
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
3556
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
3557
|
+
) {
|
|
3558
|
+
continue;
|
|
3559
|
+
}
|
|
3560
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
3561
|
+
if (partialPiecesUnchecked !== null) {
|
|
3562
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
3563
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3564
|
+
break;
|
|
3565
|
+
}
|
|
3566
|
+
console.warn(spaceTrim$1((block) => `
|
|
3567
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
3549
3568
|
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3569
|
+
The source:
|
|
3570
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3571
|
+
.split('\n')
|
|
3572
|
+
.map((line) => `> ${line}`)
|
|
3573
|
+
.join('\n'))}
|
|
3555
3574
|
|
|
3556
|
-
|
|
3575
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3557
3576
|
|
|
3558
3577
|
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3578
|
+
`));
|
|
3579
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3580
|
+
}
|
|
3581
|
+
if (partialPieces === null) {
|
|
3582
|
+
throw new KnowledgeScrapeError(spaceTrim$1((block) => `
|
|
3583
|
+
Cannot scrape knowledge
|
|
3564
3584
|
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3585
|
+
The source:
|
|
3586
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3587
|
+
.split('\n')
|
|
3588
|
+
.map((line) => `> ${line}`)
|
|
3589
|
+
.join('\n'))}
|
|
3570
3590
|
|
|
3571
|
-
|
|
3591
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3572
3592
|
|
|
3573
|
-
|
|
3593
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3574
3594
|
|
|
3575
3595
|
|
|
3576
|
-
|
|
3596
|
+
`));
|
|
3597
|
+
}
|
|
3598
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
3599
|
+
...partialPiece,
|
|
3600
|
+
sources: [
|
|
3601
|
+
{
|
|
3602
|
+
name: knowledgeSource.name,
|
|
3603
|
+
// line, column <- TODO: [☀]
|
|
3604
|
+
// <- TODO: [❎]
|
|
3605
|
+
},
|
|
3606
|
+
],
|
|
3607
|
+
}));
|
|
3608
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
3609
|
+
}
|
|
3610
|
+
catch (error) {
|
|
3611
|
+
if (!(error instanceof Error)) {
|
|
3612
|
+
throw error;
|
|
3613
|
+
}
|
|
3614
|
+
console.warn(error);
|
|
3615
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3577
3616
|
}
|
|
3578
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
3579
|
-
...partialPiece,
|
|
3580
|
-
sources: [
|
|
3581
|
-
{
|
|
3582
|
-
name: knowledgeSource.name,
|
|
3583
|
-
// line, column <- TODO: [☀]
|
|
3584
|
-
// <- TODO: [❎]
|
|
3585
|
-
},
|
|
3586
|
-
],
|
|
3587
|
-
}));
|
|
3588
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
3589
3617
|
});
|
|
3590
3618
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3591
3619
|
return knowledgePrepared;
|
|
@@ -4003,7 +4031,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
4003
4031
|
if (parameterNames.has(subparameterName)) {
|
|
4004
4032
|
parameterNames.delete(subparameterName);
|
|
4005
4033
|
parameterNames.add(foreach.parameterName);
|
|
4006
|
-
// <- TODO: [
|
|
4034
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
4007
4035
|
}
|
|
4008
4036
|
}
|
|
4009
4037
|
}
|
|
@@ -5599,6 +5627,7 @@ function createPipelineExecutor(options) {
|
|
|
5599
5627
|
|
|
5600
5628
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5601
5629
|
`));
|
|
5630
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5602
5631
|
}
|
|
5603
5632
|
let runCount = 0;
|
|
5604
5633
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|