@promptbook/documents 0.88.0 → 0.89.0-11
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 +7 -1
- package/esm/index.es.js +164 -88
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +18 -6
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +18 -10
- package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +15 -0
- package/esm/typings/src/config.d.ts +15 -8
- package/esm/typings/src/errors/0-index.d.ts +6 -0
- package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
- package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -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/register/$provideEnvFilename.d.ts +12 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +36 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- 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/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- 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/playground.d.ts +5 -0
- package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +5 -4
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +2 -2
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +88 -6
- package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +37 -0
- package/esm/typings/src/types/typeAliases.d.ts +8 -2
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +2 -2
- package/umd/index.umd.js +164 -88
- 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).
|
|
@@ -199,7 +203,7 @@ Each part of the book defines one of 3 circles:
|
|
|
199
203
|
|
|
200
204
|
### **What:** Workflows, Tasks and Parameters
|
|
201
205
|
|
|
202
|
-
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.
|
|
203
207
|
|
|
204
208
|
**Related commands:**
|
|
205
209
|
|
|
@@ -309,6 +313,8 @@ The following glossary is used to clarify certain concepts:
|
|
|
309
313
|
|
|
310
314
|
|
|
311
315
|
|
|
316
|
+
|
|
317
|
+
|
|
312
318
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
313
319
|
|
|
314
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.
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
|
|
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
|
|
@@ -162,6 +162,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
162
162
|
*/
|
|
163
163
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
164
164
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
165
|
+
// TODO: !!!!!! Just .promptbook dir, hardocode others
|
|
165
166
|
/**
|
|
166
167
|
* Where to store the temporary downloads
|
|
167
168
|
*
|
|
@@ -213,7 +214,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
213
214
|
true);
|
|
214
215
|
/**
|
|
215
216
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
216
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
217
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
217
218
|
*/
|
|
218
219
|
|
|
219
220
|
/**
|
|
@@ -432,6 +433,7 @@ function $execCommand(options) {
|
|
|
432
433
|
}
|
|
433
434
|
else {
|
|
434
435
|
console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
|
|
436
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
435
437
|
resolve('Command exceeded time limit');
|
|
436
438
|
}
|
|
437
439
|
});
|
|
@@ -457,6 +459,7 @@ function $execCommand(options) {
|
|
|
457
459
|
output.push(stderr.toString());
|
|
458
460
|
if (isVerbose && stderr.toString().trim()) {
|
|
459
461
|
console.warn(stderr.toString());
|
|
462
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
460
463
|
}
|
|
461
464
|
});
|
|
462
465
|
const finishWithCode = (code) => {
|
|
@@ -468,6 +471,7 @@ function $execCommand(options) {
|
|
|
468
471
|
else {
|
|
469
472
|
if (isVerbose) {
|
|
470
473
|
console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
|
|
474
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
471
475
|
}
|
|
472
476
|
resolve(spaceTrim(output.join('\n')));
|
|
473
477
|
}
|
|
@@ -489,6 +493,7 @@ function $execCommand(options) {
|
|
|
489
493
|
else {
|
|
490
494
|
if (isVerbose) {
|
|
491
495
|
console.warn(error);
|
|
496
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
492
497
|
}
|
|
493
498
|
resolve(spaceTrim(output.join('\n')));
|
|
494
499
|
}
|
|
@@ -2304,6 +2309,19 @@ class CsvFormatError extends AbstractFormatError {
|
|
|
2304
2309
|
}
|
|
2305
2310
|
}
|
|
2306
2311
|
|
|
2312
|
+
/**
|
|
2313
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
2314
|
+
*
|
|
2315
|
+
* @public exported from `@promptbook/core`
|
|
2316
|
+
*/
|
|
2317
|
+
class AuthenticationError extends Error {
|
|
2318
|
+
constructor(message) {
|
|
2319
|
+
super(message);
|
|
2320
|
+
this.name = 'AuthenticationError';
|
|
2321
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2307
2325
|
/**
|
|
2308
2326
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2309
2327
|
*
|
|
@@ -2369,6 +2387,19 @@ class NotYetImplementedError extends Error {
|
|
|
2369
2387
|
}
|
|
2370
2388
|
}
|
|
2371
2389
|
|
|
2390
|
+
/**
|
|
2391
|
+
* Error thrown when a fetch request fails
|
|
2392
|
+
*
|
|
2393
|
+
* @public exported from `@promptbook/core`
|
|
2394
|
+
*/
|
|
2395
|
+
class PromptbookFetchError extends Error {
|
|
2396
|
+
constructor(message) {
|
|
2397
|
+
super(message);
|
|
2398
|
+
this.name = 'PromptbookFetchError';
|
|
2399
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2372
2403
|
/**
|
|
2373
2404
|
* Index of all custom errors
|
|
2374
2405
|
*
|
|
@@ -2406,6 +2437,8 @@ const COMMON_JAVASCRIPT_ERRORS = {
|
|
|
2406
2437
|
TypeError,
|
|
2407
2438
|
URIError,
|
|
2408
2439
|
AggregateError,
|
|
2440
|
+
AuthenticationError,
|
|
2441
|
+
PromptbookFetchError,
|
|
2409
2442
|
/*
|
|
2410
2443
|
Note: Not widely supported
|
|
2411
2444
|
> InternalError,
|
|
@@ -2467,6 +2500,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2467
2500
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
2468
2501
|
for (const warning of warnings) {
|
|
2469
2502
|
console.warn(warning.message);
|
|
2503
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2470
2504
|
}
|
|
2471
2505
|
if (isSuccessful === true) {
|
|
2472
2506
|
return;
|
|
@@ -2604,6 +2638,10 @@ function serializeError(error) {
|
|
|
2604
2638
|
|
|
2605
2639
|
Cannot serialize error with name "${name}"
|
|
2606
2640
|
|
|
2641
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2642
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2643
|
+
|
|
2644
|
+
|
|
2607
2645
|
${block(stack || message)}
|
|
2608
2646
|
|
|
2609
2647
|
`));
|
|
@@ -2645,30 +2683,42 @@ async function forEachAsync(array, options, callbackfunction) {
|
|
|
2645
2683
|
await Promise.all(tasks);
|
|
2646
2684
|
}
|
|
2647
2685
|
|
|
2686
|
+
/**
|
|
2687
|
+
* Represents the uncertain value
|
|
2688
|
+
*
|
|
2689
|
+
* @public exported from `@promptbook/core`
|
|
2690
|
+
*/
|
|
2691
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2692
|
+
/**
|
|
2693
|
+
* Represents the uncertain value
|
|
2694
|
+
*
|
|
2695
|
+
* @public exported from `@promptbook/core`
|
|
2696
|
+
*/
|
|
2697
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2648
2698
|
/**
|
|
2649
2699
|
* Represents the usage with no resources consumed
|
|
2650
2700
|
*
|
|
2651
2701
|
* @public exported from `@promptbook/core`
|
|
2652
2702
|
*/
|
|
2653
2703
|
const ZERO_USAGE = $deepFreeze({
|
|
2654
|
-
price:
|
|
2704
|
+
price: ZERO_VALUE,
|
|
2655
2705
|
input: {
|
|
2656
|
-
tokensCount:
|
|
2657
|
-
charactersCount:
|
|
2658
|
-
wordsCount:
|
|
2659
|
-
sentencesCount:
|
|
2660
|
-
linesCount:
|
|
2661
|
-
paragraphsCount:
|
|
2662
|
-
pagesCount:
|
|
2706
|
+
tokensCount: ZERO_VALUE,
|
|
2707
|
+
charactersCount: ZERO_VALUE,
|
|
2708
|
+
wordsCount: ZERO_VALUE,
|
|
2709
|
+
sentencesCount: ZERO_VALUE,
|
|
2710
|
+
linesCount: ZERO_VALUE,
|
|
2711
|
+
paragraphsCount: ZERO_VALUE,
|
|
2712
|
+
pagesCount: ZERO_VALUE,
|
|
2663
2713
|
},
|
|
2664
2714
|
output: {
|
|
2665
|
-
tokensCount:
|
|
2666
|
-
charactersCount:
|
|
2667
|
-
wordsCount:
|
|
2668
|
-
sentencesCount:
|
|
2669
|
-
linesCount:
|
|
2670
|
-
paragraphsCount:
|
|
2671
|
-
pagesCount:
|
|
2715
|
+
tokensCount: ZERO_VALUE,
|
|
2716
|
+
charactersCount: ZERO_VALUE,
|
|
2717
|
+
wordsCount: ZERO_VALUE,
|
|
2718
|
+
sentencesCount: ZERO_VALUE,
|
|
2719
|
+
linesCount: ZERO_VALUE,
|
|
2720
|
+
paragraphsCount: ZERO_VALUE,
|
|
2721
|
+
pagesCount: ZERO_VALUE,
|
|
2672
2722
|
},
|
|
2673
2723
|
});
|
|
2674
2724
|
/**
|
|
@@ -2677,24 +2727,24 @@ const ZERO_USAGE = $deepFreeze({
|
|
|
2677
2727
|
* @public exported from `@promptbook/core`
|
|
2678
2728
|
*/
|
|
2679
2729
|
$deepFreeze({
|
|
2680
|
-
price:
|
|
2730
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2681
2731
|
input: {
|
|
2682
|
-
tokensCount:
|
|
2683
|
-
charactersCount:
|
|
2684
|
-
wordsCount:
|
|
2685
|
-
sentencesCount:
|
|
2686
|
-
linesCount:
|
|
2687
|
-
paragraphsCount:
|
|
2688
|
-
pagesCount:
|
|
2732
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2733
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2734
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2735
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2736
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2737
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2738
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2689
2739
|
},
|
|
2690
2740
|
output: {
|
|
2691
|
-
tokensCount:
|
|
2692
|
-
charactersCount:
|
|
2693
|
-
wordsCount:
|
|
2694
|
-
sentencesCount:
|
|
2695
|
-
linesCount:
|
|
2696
|
-
paragraphsCount:
|
|
2697
|
-
pagesCount:
|
|
2741
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2742
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2743
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2744
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2745
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2746
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2747
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2698
2748
|
},
|
|
2699
2749
|
});
|
|
2700
2750
|
/**
|
|
@@ -2755,8 +2805,9 @@ function addUsage(...usageItems) {
|
|
|
2755
2805
|
* @returns LLM tools with same functionality with added total cost counting
|
|
2756
2806
|
* @public exported from `@promptbook/core`
|
|
2757
2807
|
*/
|
|
2758
|
-
function
|
|
2808
|
+
function countUsage(llmTools) {
|
|
2759
2809
|
let totalUsage = ZERO_USAGE;
|
|
2810
|
+
const spending = new Subject();
|
|
2760
2811
|
const proxyTools = {
|
|
2761
2812
|
get title() {
|
|
2762
2813
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -2766,12 +2817,15 @@ function countTotalUsage(llmTools) {
|
|
|
2766
2817
|
// TODO: [🧠] Maybe put here some suffix
|
|
2767
2818
|
return llmTools.description;
|
|
2768
2819
|
},
|
|
2769
|
-
|
|
2820
|
+
checkConfiguration() {
|
|
2770
2821
|
return /* not await */ llmTools.checkConfiguration();
|
|
2771
2822
|
},
|
|
2772
2823
|
listModels() {
|
|
2773
2824
|
return /* not await */ llmTools.listModels();
|
|
2774
2825
|
},
|
|
2826
|
+
spending() {
|
|
2827
|
+
return spending.asObservable();
|
|
2828
|
+
},
|
|
2775
2829
|
getTotalUsage() {
|
|
2776
2830
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2777
2831
|
return totalUsage;
|
|
@@ -2782,6 +2836,7 @@ function countTotalUsage(llmTools) {
|
|
|
2782
2836
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
2783
2837
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
2784
2838
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2839
|
+
spending.next(promptResult.usage);
|
|
2785
2840
|
return promptResult;
|
|
2786
2841
|
};
|
|
2787
2842
|
}
|
|
@@ -2790,6 +2845,7 @@ function countTotalUsage(llmTools) {
|
|
|
2790
2845
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
2791
2846
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
2792
2847
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2848
|
+
spending.next(promptResult.usage);
|
|
2793
2849
|
return promptResult;
|
|
2794
2850
|
};
|
|
2795
2851
|
}
|
|
@@ -2798,6 +2854,7 @@ function countTotalUsage(llmTools) {
|
|
|
2798
2854
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
2799
2855
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
2800
2856
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2857
|
+
spending.next(promptResult.usage);
|
|
2801
2858
|
return promptResult;
|
|
2802
2859
|
};
|
|
2803
2860
|
}
|
|
@@ -2975,6 +3032,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
|
|
|
2975
3032
|
`);
|
|
2976
3033
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2977
3034
|
console.warn(warningMessage);
|
|
3035
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2978
3036
|
/*
|
|
2979
3037
|
return {
|
|
2980
3038
|
async listModels() {
|
|
@@ -3350,17 +3408,24 @@ function mimeTypeToExtension(value) {
|
|
|
3350
3408
|
/**
|
|
3351
3409
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3352
3410
|
*
|
|
3353
|
-
* @
|
|
3411
|
+
* @public exported from `@promptbook/core`
|
|
3354
3412
|
*/
|
|
3355
|
-
const
|
|
3413
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3356
3414
|
try {
|
|
3357
|
-
return await fetch(
|
|
3415
|
+
return await fetch(urlOrRequest, init);
|
|
3358
3416
|
}
|
|
3359
3417
|
catch (error) {
|
|
3360
3418
|
if (!(error instanceof Error)) {
|
|
3361
3419
|
throw error;
|
|
3362
3420
|
}
|
|
3363
|
-
|
|
3421
|
+
let url;
|
|
3422
|
+
if (typeof urlOrRequest === 'string') {
|
|
3423
|
+
url = urlOrRequest;
|
|
3424
|
+
}
|
|
3425
|
+
else if (urlOrRequest instanceof Request) {
|
|
3426
|
+
url = urlOrRequest.url;
|
|
3427
|
+
}
|
|
3428
|
+
throw new PromptbookFetchError(spaceTrim$1((block) => `
|
|
3364
3429
|
Can not fetch "${url}"
|
|
3365
3430
|
|
|
3366
3431
|
Fetch error:
|
|
@@ -3381,7 +3446,7 @@ const scraperFetch = async (url, init) => {
|
|
|
3381
3446
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3382
3447
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3383
3448
|
var _a;
|
|
3384
|
-
const { fetch =
|
|
3449
|
+
const { fetch = promptbookFetch } = tools;
|
|
3385
3450
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3386
3451
|
let { name } = knowledgeSource;
|
|
3387
3452
|
const { rootDirname = null,
|
|
@@ -3522,63 +3587,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3522
3587
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3523
3588
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3524
3589
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3590
|
+
try {
|
|
3591
|
+
let partialPieces = null;
|
|
3592
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
3593
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
3594
|
+
for (const scraper of scrapers) {
|
|
3595
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
3596
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
3597
|
+
) {
|
|
3598
|
+
continue;
|
|
3599
|
+
}
|
|
3600
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
3601
|
+
if (partialPiecesUnchecked !== null) {
|
|
3602
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
3603
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3604
|
+
break;
|
|
3605
|
+
}
|
|
3606
|
+
console.warn(spaceTrim$1((block) => `
|
|
3607
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
3542
3608
|
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3609
|
+
The source:
|
|
3610
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3611
|
+
.split('\n')
|
|
3612
|
+
.map((line) => `> ${line}`)
|
|
3613
|
+
.join('\n'))}
|
|
3548
3614
|
|
|
3549
|
-
|
|
3615
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3550
3616
|
|
|
3551
3617
|
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3618
|
+
`));
|
|
3619
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3620
|
+
}
|
|
3621
|
+
if (partialPieces === null) {
|
|
3622
|
+
throw new KnowledgeScrapeError(spaceTrim$1((block) => `
|
|
3623
|
+
Cannot scrape knowledge
|
|
3557
3624
|
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3625
|
+
The source:
|
|
3626
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3627
|
+
.split('\n')
|
|
3628
|
+
.map((line) => `> ${line}`)
|
|
3629
|
+
.join('\n'))}
|
|
3563
3630
|
|
|
3564
|
-
|
|
3631
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3565
3632
|
|
|
3566
|
-
|
|
3633
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3567
3634
|
|
|
3568
3635
|
|
|
3569
|
-
|
|
3636
|
+
`));
|
|
3637
|
+
}
|
|
3638
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
3639
|
+
...partialPiece,
|
|
3640
|
+
sources: [
|
|
3641
|
+
{
|
|
3642
|
+
name: knowledgeSource.name,
|
|
3643
|
+
// line, column <- TODO: [☀]
|
|
3644
|
+
// <- TODO: [❎]
|
|
3645
|
+
},
|
|
3646
|
+
],
|
|
3647
|
+
}));
|
|
3648
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
3649
|
+
}
|
|
3650
|
+
catch (error) {
|
|
3651
|
+
if (!(error instanceof Error)) {
|
|
3652
|
+
throw error;
|
|
3653
|
+
}
|
|
3654
|
+
console.warn(error);
|
|
3655
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3570
3656
|
}
|
|
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
3657
|
});
|
|
3583
3658
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3584
3659
|
return knowledgePrepared;
|
|
@@ -3684,7 +3759,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
3684
3759
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
3685
3760
|
const _llms = arrayableToArray(tools.llm);
|
|
3686
3761
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
3687
|
-
const llmToolsWithUsage =
|
|
3762
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
3688
3763
|
// <- TODO: [🌯]
|
|
3689
3764
|
/*
|
|
3690
3765
|
TODO: [🧠][🪑][🔃] Should this be done or not
|
|
@@ -3996,7 +4071,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
3996
4071
|
if (parameterNames.has(subparameterName)) {
|
|
3997
4072
|
parameterNames.delete(subparameterName);
|
|
3998
4073
|
parameterNames.add(foreach.parameterName);
|
|
3999
|
-
// <- TODO: [
|
|
4074
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
4000
4075
|
}
|
|
4001
4076
|
}
|
|
4002
4077
|
}
|
|
@@ -5592,6 +5667,7 @@ function createPipelineExecutor(options) {
|
|
|
5592
5667
|
|
|
5593
5668
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5594
5669
|
`));
|
|
5670
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5595
5671
|
}
|
|
5596
5672
|
let runCount = 0;
|
|
5597
5673
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|