@promptbook/documents 0.88.0 → 0.89.0-2
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 +4 -0
- package/esm/index.es.js +118 -82
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +6 -2
- package/esm/typings/src/_packages/types.index.d.ts +16 -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 +9 -2
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
- 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 +67 -0
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +12879 -0
- package/esm/typings/src/playground/playground.d.ts +5 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -1
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -3
- package/esm/typings/src/types/typeAliases.d.ts +8 -2
- package/package.json +2 -2
- package/umd/index.umd.js +118 -82
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
<blockquote style="color: #ff8811">
|
|
27
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
+
</blockquote>
|
|
29
|
+
|
|
26
30
|
## 📦 Package `@promptbook/documents`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
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.
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-2';
|
|
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
|
/**
|
|
@@ -2755,8 +2772,9 @@ function addUsage(...usageItems) {
|
|
|
2755
2772
|
* @returns LLM tools with same functionality with added total cost counting
|
|
2756
2773
|
* @public exported from `@promptbook/core`
|
|
2757
2774
|
*/
|
|
2758
|
-
function
|
|
2775
|
+
function countUsage(llmTools) {
|
|
2759
2776
|
let totalUsage = ZERO_USAGE;
|
|
2777
|
+
const spending = new Subject();
|
|
2760
2778
|
const proxyTools = {
|
|
2761
2779
|
get title() {
|
|
2762
2780
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -2766,12 +2784,15 @@ function countTotalUsage(llmTools) {
|
|
|
2766
2784
|
// TODO: [🧠] Maybe put here some suffix
|
|
2767
2785
|
return llmTools.description;
|
|
2768
2786
|
},
|
|
2769
|
-
|
|
2787
|
+
checkConfiguration() {
|
|
2770
2788
|
return /* not await */ llmTools.checkConfiguration();
|
|
2771
2789
|
},
|
|
2772
2790
|
listModels() {
|
|
2773
2791
|
return /* not await */ llmTools.listModels();
|
|
2774
2792
|
},
|
|
2793
|
+
spending() {
|
|
2794
|
+
return spending.asObservable();
|
|
2795
|
+
},
|
|
2775
2796
|
getTotalUsage() {
|
|
2776
2797
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2777
2798
|
return totalUsage;
|
|
@@ -2782,6 +2803,7 @@ function countTotalUsage(llmTools) {
|
|
|
2782
2803
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
2783
2804
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
2784
2805
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2806
|
+
spending.next(promptResult.usage);
|
|
2785
2807
|
return promptResult;
|
|
2786
2808
|
};
|
|
2787
2809
|
}
|
|
@@ -2790,6 +2812,7 @@ function countTotalUsage(llmTools) {
|
|
|
2790
2812
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
2791
2813
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
2792
2814
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2815
|
+
spending.next(promptResult.usage);
|
|
2793
2816
|
return promptResult;
|
|
2794
2817
|
};
|
|
2795
2818
|
}
|
|
@@ -2798,6 +2821,7 @@ function countTotalUsage(llmTools) {
|
|
|
2798
2821
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
2799
2822
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
2800
2823
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2824
|
+
spending.next(promptResult.usage);
|
|
2801
2825
|
return promptResult;
|
|
2802
2826
|
};
|
|
2803
2827
|
}
|
|
@@ -2975,6 +2999,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
|
|
|
2975
2999
|
`);
|
|
2976
3000
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2977
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
|
|
2978
3003
|
/*
|
|
2979
3004
|
return {
|
|
2980
3005
|
async listModels() {
|
|
@@ -3522,63 +3547,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3522
3547
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3523
3548
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3524
3549
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
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}".
|
|
3542
3568
|
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3569
|
+
The source:
|
|
3570
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3571
|
+
.split('\n')
|
|
3572
|
+
.map((line) => `> ${line}`)
|
|
3573
|
+
.join('\n'))}
|
|
3548
3574
|
|
|
3549
|
-
|
|
3575
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3550
3576
|
|
|
3551
3577
|
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
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
|
|
3557
3584
|
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3585
|
+
The source:
|
|
3586
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3587
|
+
.split('\n')
|
|
3588
|
+
.map((line) => `> ${line}`)
|
|
3589
|
+
.join('\n'))}
|
|
3563
3590
|
|
|
3564
|
-
|
|
3591
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3565
3592
|
|
|
3566
|
-
|
|
3593
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3567
3594
|
|
|
3568
3595
|
|
|
3569
|
-
|
|
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
|
|
3570
3616
|
}
|
|
3571
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
3572
|
-
...partialPiece,
|
|
3573
|
-
sources: [
|
|
3574
|
-
{
|
|
3575
|
-
name: knowledgeSource.name,
|
|
3576
|
-
// line, column <- TODO: [☀]
|
|
3577
|
-
// <- TODO: [❎]
|
|
3578
|
-
},
|
|
3579
|
-
],
|
|
3580
|
-
}));
|
|
3581
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
3582
3617
|
});
|
|
3583
3618
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3584
3619
|
return knowledgePrepared;
|
|
@@ -3684,7 +3719,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
3684
3719
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
3685
3720
|
const _llms = arrayableToArray(tools.llm);
|
|
3686
3721
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
3687
|
-
const llmToolsWithUsage =
|
|
3722
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
3688
3723
|
// <- TODO: [🌯]
|
|
3689
3724
|
/*
|
|
3690
3725
|
TODO: [🧠][🪑][🔃] Should this be done or not
|
|
@@ -3996,7 +4031,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
3996
4031
|
if (parameterNames.has(subparameterName)) {
|
|
3997
4032
|
parameterNames.delete(subparameterName);
|
|
3998
4033
|
parameterNames.add(foreach.parameterName);
|
|
3999
|
-
// <- TODO: [
|
|
4034
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
4000
4035
|
}
|
|
4001
4036
|
}
|
|
4002
4037
|
}
|
|
@@ -5592,6 +5627,7 @@ function createPipelineExecutor(options) {
|
|
|
5592
5627
|
|
|
5593
5628
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5594
5629
|
`));
|
|
5630
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5595
5631
|
}
|
|
5596
5632
|
let runCount = 0;
|
|
5597
5633
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|