@promptbook/pdf 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 +114 -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 +115 -83
- 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/pdf`
|
|
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
|
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-2';
|
|
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
|
|
@@ -2310,6 +2310,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2310
2310
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
2311
2311
|
for (const warning of warnings) {
|
|
2312
2312
|
console.warn(warning.message);
|
|
2313
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2313
2314
|
}
|
|
2314
2315
|
if (isSuccessful === true) {
|
|
2315
2316
|
return;
|
|
@@ -2488,30 +2489,42 @@ async function forEachAsync(array, options, callbackfunction) {
|
|
|
2488
2489
|
await Promise.all(tasks);
|
|
2489
2490
|
}
|
|
2490
2491
|
|
|
2492
|
+
/**
|
|
2493
|
+
* Represents the uncertain value
|
|
2494
|
+
*
|
|
2495
|
+
* @public exported from `@promptbook/core`
|
|
2496
|
+
*/
|
|
2497
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2498
|
+
/**
|
|
2499
|
+
* Represents the uncertain value
|
|
2500
|
+
*
|
|
2501
|
+
* @public exported from `@promptbook/core`
|
|
2502
|
+
*/
|
|
2503
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2491
2504
|
/**
|
|
2492
2505
|
* Represents the usage with no resources consumed
|
|
2493
2506
|
*
|
|
2494
2507
|
* @public exported from `@promptbook/core`
|
|
2495
2508
|
*/
|
|
2496
2509
|
const ZERO_USAGE = $deepFreeze({
|
|
2497
|
-
price:
|
|
2510
|
+
price: ZERO_VALUE,
|
|
2498
2511
|
input: {
|
|
2499
|
-
tokensCount:
|
|
2500
|
-
charactersCount:
|
|
2501
|
-
wordsCount:
|
|
2502
|
-
sentencesCount:
|
|
2503
|
-
linesCount:
|
|
2504
|
-
paragraphsCount:
|
|
2505
|
-
pagesCount:
|
|
2512
|
+
tokensCount: ZERO_VALUE,
|
|
2513
|
+
charactersCount: ZERO_VALUE,
|
|
2514
|
+
wordsCount: ZERO_VALUE,
|
|
2515
|
+
sentencesCount: ZERO_VALUE,
|
|
2516
|
+
linesCount: ZERO_VALUE,
|
|
2517
|
+
paragraphsCount: ZERO_VALUE,
|
|
2518
|
+
pagesCount: ZERO_VALUE,
|
|
2506
2519
|
},
|
|
2507
2520
|
output: {
|
|
2508
|
-
tokensCount:
|
|
2509
|
-
charactersCount:
|
|
2510
|
-
wordsCount:
|
|
2511
|
-
sentencesCount:
|
|
2512
|
-
linesCount:
|
|
2513
|
-
paragraphsCount:
|
|
2514
|
-
pagesCount:
|
|
2521
|
+
tokensCount: ZERO_VALUE,
|
|
2522
|
+
charactersCount: ZERO_VALUE,
|
|
2523
|
+
wordsCount: ZERO_VALUE,
|
|
2524
|
+
sentencesCount: ZERO_VALUE,
|
|
2525
|
+
linesCount: ZERO_VALUE,
|
|
2526
|
+
paragraphsCount: ZERO_VALUE,
|
|
2527
|
+
pagesCount: ZERO_VALUE,
|
|
2515
2528
|
},
|
|
2516
2529
|
});
|
|
2517
2530
|
/**
|
|
@@ -2520,24 +2533,24 @@ const ZERO_USAGE = $deepFreeze({
|
|
|
2520
2533
|
* @public exported from `@promptbook/core`
|
|
2521
2534
|
*/
|
|
2522
2535
|
$deepFreeze({
|
|
2523
|
-
price:
|
|
2536
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2524
2537
|
input: {
|
|
2525
|
-
tokensCount:
|
|
2526
|
-
charactersCount:
|
|
2527
|
-
wordsCount:
|
|
2528
|
-
sentencesCount:
|
|
2529
|
-
linesCount:
|
|
2530
|
-
paragraphsCount:
|
|
2531
|
-
pagesCount:
|
|
2538
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2539
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2540
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2541
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2542
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2543
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2544
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2532
2545
|
},
|
|
2533
2546
|
output: {
|
|
2534
|
-
tokensCount:
|
|
2535
|
-
charactersCount:
|
|
2536
|
-
wordsCount:
|
|
2537
|
-
sentencesCount:
|
|
2538
|
-
linesCount:
|
|
2539
|
-
paragraphsCount:
|
|
2540
|
-
pagesCount:
|
|
2547
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2548
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2549
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2550
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2551
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2552
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2553
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2541
2554
|
},
|
|
2542
2555
|
});
|
|
2543
2556
|
/**
|
|
@@ -2598,8 +2611,9 @@ function addUsage(...usageItems) {
|
|
|
2598
2611
|
* @returns LLM tools with same functionality with added total cost counting
|
|
2599
2612
|
* @public exported from `@promptbook/core`
|
|
2600
2613
|
*/
|
|
2601
|
-
function
|
|
2614
|
+
function countUsage(llmTools) {
|
|
2602
2615
|
let totalUsage = ZERO_USAGE;
|
|
2616
|
+
const spending = new Subject();
|
|
2603
2617
|
const proxyTools = {
|
|
2604
2618
|
get title() {
|
|
2605
2619
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -2609,12 +2623,15 @@ function countTotalUsage(llmTools) {
|
|
|
2609
2623
|
// TODO: [🧠] Maybe put here some suffix
|
|
2610
2624
|
return llmTools.description;
|
|
2611
2625
|
},
|
|
2612
|
-
|
|
2626
|
+
checkConfiguration() {
|
|
2613
2627
|
return /* not await */ llmTools.checkConfiguration();
|
|
2614
2628
|
},
|
|
2615
2629
|
listModels() {
|
|
2616
2630
|
return /* not await */ llmTools.listModels();
|
|
2617
2631
|
},
|
|
2632
|
+
spending() {
|
|
2633
|
+
return spending.asObservable();
|
|
2634
|
+
},
|
|
2618
2635
|
getTotalUsage() {
|
|
2619
2636
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2620
2637
|
return totalUsage;
|
|
@@ -2625,6 +2642,7 @@ function countTotalUsage(llmTools) {
|
|
|
2625
2642
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
2626
2643
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
2627
2644
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2645
|
+
spending.next(promptResult.usage);
|
|
2628
2646
|
return promptResult;
|
|
2629
2647
|
};
|
|
2630
2648
|
}
|
|
@@ -2633,6 +2651,7 @@ function countTotalUsage(llmTools) {
|
|
|
2633
2651
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
2634
2652
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
2635
2653
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2654
|
+
spending.next(promptResult.usage);
|
|
2636
2655
|
return promptResult;
|
|
2637
2656
|
};
|
|
2638
2657
|
}
|
|
@@ -2641,6 +2660,7 @@ function countTotalUsage(llmTools) {
|
|
|
2641
2660
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
2642
2661
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
2643
2662
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2663
|
+
spending.next(promptResult.usage);
|
|
2644
2664
|
return promptResult;
|
|
2645
2665
|
};
|
|
2646
2666
|
}
|
|
@@ -2818,6 +2838,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
|
|
|
2818
2838
|
`);
|
|
2819
2839
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2820
2840
|
console.warn(warningMessage);
|
|
2841
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2821
2842
|
/*
|
|
2822
2843
|
return {
|
|
2823
2844
|
async listModels() {
|
|
@@ -3375,63 +3396,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3375
3396
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3376
3397
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3377
3398
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3399
|
+
try {
|
|
3400
|
+
let partialPieces = null;
|
|
3401
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
3402
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
3403
|
+
for (const scraper of scrapers) {
|
|
3404
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
3405
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
3406
|
+
) {
|
|
3407
|
+
continue;
|
|
3408
|
+
}
|
|
3409
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
3410
|
+
if (partialPiecesUnchecked !== null) {
|
|
3411
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
3412
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3413
|
+
break;
|
|
3414
|
+
}
|
|
3415
|
+
console.warn(spaceTrim((block) => `
|
|
3416
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
3395
3417
|
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3418
|
+
The source:
|
|
3419
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3420
|
+
.split('\n')
|
|
3421
|
+
.map((line) => `> ${line}`)
|
|
3422
|
+
.join('\n'))}
|
|
3401
3423
|
|
|
3402
|
-
|
|
3424
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3403
3425
|
|
|
3404
3426
|
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3427
|
+
`));
|
|
3428
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3429
|
+
}
|
|
3430
|
+
if (partialPieces === null) {
|
|
3431
|
+
throw new KnowledgeScrapeError(spaceTrim((block) => `
|
|
3432
|
+
Cannot scrape knowledge
|
|
3410
3433
|
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3434
|
+
The source:
|
|
3435
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3436
|
+
.split('\n')
|
|
3437
|
+
.map((line) => `> ${line}`)
|
|
3438
|
+
.join('\n'))}
|
|
3416
3439
|
|
|
3417
|
-
|
|
3440
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3418
3441
|
|
|
3419
|
-
|
|
3442
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3420
3443
|
|
|
3421
3444
|
|
|
3422
|
-
|
|
3445
|
+
`));
|
|
3446
|
+
}
|
|
3447
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
3448
|
+
...partialPiece,
|
|
3449
|
+
sources: [
|
|
3450
|
+
{
|
|
3451
|
+
name: knowledgeSource.name,
|
|
3452
|
+
// line, column <- TODO: [☀]
|
|
3453
|
+
// <- TODO: [❎]
|
|
3454
|
+
},
|
|
3455
|
+
],
|
|
3456
|
+
}));
|
|
3457
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
3458
|
+
}
|
|
3459
|
+
catch (error) {
|
|
3460
|
+
if (!(error instanceof Error)) {
|
|
3461
|
+
throw error;
|
|
3462
|
+
}
|
|
3463
|
+
console.warn(error);
|
|
3464
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3423
3465
|
}
|
|
3424
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
3425
|
-
...partialPiece,
|
|
3426
|
-
sources: [
|
|
3427
|
-
{
|
|
3428
|
-
name: knowledgeSource.name,
|
|
3429
|
-
// line, column <- TODO: [☀]
|
|
3430
|
-
// <- TODO: [❎]
|
|
3431
|
-
},
|
|
3432
|
-
],
|
|
3433
|
-
}));
|
|
3434
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
3435
3466
|
});
|
|
3436
3467
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3437
3468
|
return knowledgePrepared;
|
|
@@ -3537,7 +3568,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
3537
3568
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
3538
3569
|
const _llms = arrayableToArray(tools.llm);
|
|
3539
3570
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
3540
|
-
const llmToolsWithUsage =
|
|
3571
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
3541
3572
|
// <- TODO: [🌯]
|
|
3542
3573
|
/*
|
|
3543
3574
|
TODO: [🧠][🪑][🔃] Should this be done or not
|
|
@@ -3849,7 +3880,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
3849
3880
|
if (parameterNames.has(subparameterName)) {
|
|
3850
3881
|
parameterNames.delete(subparameterName);
|
|
3851
3882
|
parameterNames.add(foreach.parameterName);
|
|
3852
|
-
// <- TODO: [
|
|
3883
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
3853
3884
|
}
|
|
3854
3885
|
}
|
|
3855
3886
|
}
|
|
@@ -5445,6 +5476,7 @@ function createPipelineExecutor(options) {
|
|
|
5445
5476
|
|
|
5446
5477
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5447
5478
|
`));
|
|
5479
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5448
5480
|
}
|
|
5449
5481
|
let runCount = 0;
|
|
5450
5482
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|