@promptbook/markitdown 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/markitdown`
|
|
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
|
|
@@ -2297,6 +2297,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2297
2297
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
2298
2298
|
for (const warning of warnings) {
|
|
2299
2299
|
console.warn(warning.message);
|
|
2300
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2300
2301
|
}
|
|
2301
2302
|
if (isSuccessful === true) {
|
|
2302
2303
|
return;
|
|
@@ -2475,30 +2476,42 @@ async function forEachAsync(array, options, callbackfunction) {
|
|
|
2475
2476
|
await Promise.all(tasks);
|
|
2476
2477
|
}
|
|
2477
2478
|
|
|
2479
|
+
/**
|
|
2480
|
+
* Represents the uncertain value
|
|
2481
|
+
*
|
|
2482
|
+
* @public exported from `@promptbook/core`
|
|
2483
|
+
*/
|
|
2484
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2485
|
+
/**
|
|
2486
|
+
* Represents the uncertain value
|
|
2487
|
+
*
|
|
2488
|
+
* @public exported from `@promptbook/core`
|
|
2489
|
+
*/
|
|
2490
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2478
2491
|
/**
|
|
2479
2492
|
* Represents the usage with no resources consumed
|
|
2480
2493
|
*
|
|
2481
2494
|
* @public exported from `@promptbook/core`
|
|
2482
2495
|
*/
|
|
2483
2496
|
const ZERO_USAGE = $deepFreeze({
|
|
2484
|
-
price:
|
|
2497
|
+
price: ZERO_VALUE,
|
|
2485
2498
|
input: {
|
|
2486
|
-
tokensCount:
|
|
2487
|
-
charactersCount:
|
|
2488
|
-
wordsCount:
|
|
2489
|
-
sentencesCount:
|
|
2490
|
-
linesCount:
|
|
2491
|
-
paragraphsCount:
|
|
2492
|
-
pagesCount:
|
|
2499
|
+
tokensCount: ZERO_VALUE,
|
|
2500
|
+
charactersCount: ZERO_VALUE,
|
|
2501
|
+
wordsCount: ZERO_VALUE,
|
|
2502
|
+
sentencesCount: ZERO_VALUE,
|
|
2503
|
+
linesCount: ZERO_VALUE,
|
|
2504
|
+
paragraphsCount: ZERO_VALUE,
|
|
2505
|
+
pagesCount: ZERO_VALUE,
|
|
2493
2506
|
},
|
|
2494
2507
|
output: {
|
|
2495
|
-
tokensCount:
|
|
2496
|
-
charactersCount:
|
|
2497
|
-
wordsCount:
|
|
2498
|
-
sentencesCount:
|
|
2499
|
-
linesCount:
|
|
2500
|
-
paragraphsCount:
|
|
2501
|
-
pagesCount:
|
|
2508
|
+
tokensCount: ZERO_VALUE,
|
|
2509
|
+
charactersCount: ZERO_VALUE,
|
|
2510
|
+
wordsCount: ZERO_VALUE,
|
|
2511
|
+
sentencesCount: ZERO_VALUE,
|
|
2512
|
+
linesCount: ZERO_VALUE,
|
|
2513
|
+
paragraphsCount: ZERO_VALUE,
|
|
2514
|
+
pagesCount: ZERO_VALUE,
|
|
2502
2515
|
},
|
|
2503
2516
|
});
|
|
2504
2517
|
/**
|
|
@@ -2507,24 +2520,24 @@ const ZERO_USAGE = $deepFreeze({
|
|
|
2507
2520
|
* @public exported from `@promptbook/core`
|
|
2508
2521
|
*/
|
|
2509
2522
|
$deepFreeze({
|
|
2510
|
-
price:
|
|
2523
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2511
2524
|
input: {
|
|
2512
|
-
tokensCount:
|
|
2513
|
-
charactersCount:
|
|
2514
|
-
wordsCount:
|
|
2515
|
-
sentencesCount:
|
|
2516
|
-
linesCount:
|
|
2517
|
-
paragraphsCount:
|
|
2518
|
-
pagesCount:
|
|
2525
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2526
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2527
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2528
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2529
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2530
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2531
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2519
2532
|
},
|
|
2520
2533
|
output: {
|
|
2521
|
-
tokensCount:
|
|
2522
|
-
charactersCount:
|
|
2523
|
-
wordsCount:
|
|
2524
|
-
sentencesCount:
|
|
2525
|
-
linesCount:
|
|
2526
|
-
paragraphsCount:
|
|
2527
|
-
pagesCount:
|
|
2534
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2535
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2536
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2537
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2538
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2539
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2540
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2528
2541
|
},
|
|
2529
2542
|
});
|
|
2530
2543
|
/**
|
|
@@ -2585,8 +2598,9 @@ function addUsage(...usageItems) {
|
|
|
2585
2598
|
* @returns LLM tools with same functionality with added total cost counting
|
|
2586
2599
|
* @public exported from `@promptbook/core`
|
|
2587
2600
|
*/
|
|
2588
|
-
function
|
|
2601
|
+
function countUsage(llmTools) {
|
|
2589
2602
|
let totalUsage = ZERO_USAGE;
|
|
2603
|
+
const spending = new Subject();
|
|
2590
2604
|
const proxyTools = {
|
|
2591
2605
|
get title() {
|
|
2592
2606
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -2596,12 +2610,15 @@ function countTotalUsage(llmTools) {
|
|
|
2596
2610
|
// TODO: [🧠] Maybe put here some suffix
|
|
2597
2611
|
return llmTools.description;
|
|
2598
2612
|
},
|
|
2599
|
-
|
|
2613
|
+
checkConfiguration() {
|
|
2600
2614
|
return /* not await */ llmTools.checkConfiguration();
|
|
2601
2615
|
},
|
|
2602
2616
|
listModels() {
|
|
2603
2617
|
return /* not await */ llmTools.listModels();
|
|
2604
2618
|
},
|
|
2619
|
+
spending() {
|
|
2620
|
+
return spending.asObservable();
|
|
2621
|
+
},
|
|
2605
2622
|
getTotalUsage() {
|
|
2606
2623
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2607
2624
|
return totalUsage;
|
|
@@ -2612,6 +2629,7 @@ function countTotalUsage(llmTools) {
|
|
|
2612
2629
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
2613
2630
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
2614
2631
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2632
|
+
spending.next(promptResult.usage);
|
|
2615
2633
|
return promptResult;
|
|
2616
2634
|
};
|
|
2617
2635
|
}
|
|
@@ -2620,6 +2638,7 @@ function countTotalUsage(llmTools) {
|
|
|
2620
2638
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
2621
2639
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
2622
2640
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2641
|
+
spending.next(promptResult.usage);
|
|
2623
2642
|
return promptResult;
|
|
2624
2643
|
};
|
|
2625
2644
|
}
|
|
@@ -2628,6 +2647,7 @@ function countTotalUsage(llmTools) {
|
|
|
2628
2647
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
2629
2648
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
2630
2649
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2650
|
+
spending.next(promptResult.usage);
|
|
2631
2651
|
return promptResult;
|
|
2632
2652
|
};
|
|
2633
2653
|
}
|
|
@@ -2805,6 +2825,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
|
|
|
2805
2825
|
`);
|
|
2806
2826
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2807
2827
|
console.warn(warningMessage);
|
|
2828
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2808
2829
|
/*
|
|
2809
2830
|
return {
|
|
2810
2831
|
async listModels() {
|
|
@@ -3362,63 +3383,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3362
3383
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3363
3384
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3364
3385
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3386
|
+
try {
|
|
3387
|
+
let partialPieces = null;
|
|
3388
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
3389
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
3390
|
+
for (const scraper of scrapers) {
|
|
3391
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
3392
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
3393
|
+
) {
|
|
3394
|
+
continue;
|
|
3395
|
+
}
|
|
3396
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
3397
|
+
if (partialPiecesUnchecked !== null) {
|
|
3398
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
3399
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3400
|
+
break;
|
|
3401
|
+
}
|
|
3402
|
+
console.warn(spaceTrim((block) => `
|
|
3403
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
3382
3404
|
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3405
|
+
The source:
|
|
3406
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3407
|
+
.split('\n')
|
|
3408
|
+
.map((line) => `> ${line}`)
|
|
3409
|
+
.join('\n'))}
|
|
3388
3410
|
|
|
3389
|
-
|
|
3411
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3390
3412
|
|
|
3391
3413
|
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3414
|
+
`));
|
|
3415
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3416
|
+
}
|
|
3417
|
+
if (partialPieces === null) {
|
|
3418
|
+
throw new KnowledgeScrapeError(spaceTrim((block) => `
|
|
3419
|
+
Cannot scrape knowledge
|
|
3397
3420
|
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3421
|
+
The source:
|
|
3422
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3423
|
+
.split('\n')
|
|
3424
|
+
.map((line) => `> ${line}`)
|
|
3425
|
+
.join('\n'))}
|
|
3403
3426
|
|
|
3404
|
-
|
|
3427
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3405
3428
|
|
|
3406
|
-
|
|
3429
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3407
3430
|
|
|
3408
3431
|
|
|
3409
|
-
|
|
3432
|
+
`));
|
|
3433
|
+
}
|
|
3434
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
3435
|
+
...partialPiece,
|
|
3436
|
+
sources: [
|
|
3437
|
+
{
|
|
3438
|
+
name: knowledgeSource.name,
|
|
3439
|
+
// line, column <- TODO: [☀]
|
|
3440
|
+
// <- TODO: [❎]
|
|
3441
|
+
},
|
|
3442
|
+
],
|
|
3443
|
+
}));
|
|
3444
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
3445
|
+
}
|
|
3446
|
+
catch (error) {
|
|
3447
|
+
if (!(error instanceof Error)) {
|
|
3448
|
+
throw error;
|
|
3449
|
+
}
|
|
3450
|
+
console.warn(error);
|
|
3451
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3410
3452
|
}
|
|
3411
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
3412
|
-
...partialPiece,
|
|
3413
|
-
sources: [
|
|
3414
|
-
{
|
|
3415
|
-
name: knowledgeSource.name,
|
|
3416
|
-
// line, column <- TODO: [☀]
|
|
3417
|
-
// <- TODO: [❎]
|
|
3418
|
-
},
|
|
3419
|
-
],
|
|
3420
|
-
}));
|
|
3421
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
3422
3453
|
});
|
|
3423
3454
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3424
3455
|
return knowledgePrepared;
|
|
@@ -3524,7 +3555,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
3524
3555
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
3525
3556
|
const _llms = arrayableToArray(tools.llm);
|
|
3526
3557
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
3527
|
-
const llmToolsWithUsage =
|
|
3558
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
3528
3559
|
// <- TODO: [🌯]
|
|
3529
3560
|
/*
|
|
3530
3561
|
TODO: [🧠][🪑][🔃] Should this be done or not
|
|
@@ -3836,7 +3867,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
3836
3867
|
if (parameterNames.has(subparameterName)) {
|
|
3837
3868
|
parameterNames.delete(subparameterName);
|
|
3838
3869
|
parameterNames.add(foreach.parameterName);
|
|
3839
|
-
// <- TODO: [
|
|
3870
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
3840
3871
|
}
|
|
3841
3872
|
}
|
|
3842
3873
|
}
|
|
@@ -5432,6 +5463,7 @@ function createPipelineExecutor(options) {
|
|
|
5432
5463
|
|
|
5433
5464
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5434
5465
|
`));
|
|
5466
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5435
5467
|
}
|
|
5436
5468
|
let runCount = 0;
|
|
5437
5469
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|