@promptbook/website-crawler 0.92.0-3 → 0.92.0-31
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/esm/index.es.js +557 -276
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/browser.index.d.ts +2 -0
- package/esm/typings/src/_packages/core.index.d.ts +22 -6
- package/esm/typings/src/_packages/deepseek.index.d.ts +2 -0
- package/esm/typings/src/_packages/google.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -2
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +1 -1
- package/esm/typings/src/collection/PipelineCollection.d.ts +0 -2
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +0 -2
- package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +36 -28
- package/esm/typings/src/config.d.ts +41 -11
- package/esm/typings/src/constants.d.ts +43 -2
- package/esm/typings/src/conversion/archive/loadArchive.d.ts +2 -2
- package/esm/typings/src/errors/0-BoilerplateError.d.ts +2 -2
- package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +1 -1
- package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +2 -1
- package/esm/typings/src/executables/apps/locatePandoc.d.ts +2 -1
- package/esm/typings/src/executables/locateApp.d.ts +2 -2
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +2 -1
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +2 -1
- package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +2 -1
- package/esm/typings/src/execution/AbstractTaskResult.d.ts +1 -1
- package/esm/typings/src/execution/CommonToolsOptions.d.ts +5 -1
- package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +2 -1
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +4 -2
- package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +12 -9
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +13 -10
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +12 -9
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -3
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +20 -14
- package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +7 -6
- package/esm/typings/src/execution/createPipelineExecutor/getContextForTask.d.ts +5 -1
- package/esm/typings/src/execution/createPipelineExecutor/getExamplesForTask.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +21 -5
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +19 -5
- package/esm/typings/src/execution/createPipelineExecutor/knowledgePiecesToString.d.ts +9 -0
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +4 -4
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/esm/typings/src/execution/utils/uncertainNumber.d.ts +3 -2
- package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +8 -6
- package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +66 -0
- package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
- package/esm/typings/src/formats/csv/CsvSettings.d.ts +2 -2
- package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
- package/esm/typings/src/formats/index.d.ts +2 -2
- package/esm/typings/src/formats/json/{JsonFormatDefinition.d.ts → JsonFormatParser.d.ts} +6 -6
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
- package/esm/typings/src/formats/json/utils/jsonParse.d.ts +8 -0
- package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
- package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
- package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +3 -2
- package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +16 -7
- package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +3 -1
- package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +2 -1
- package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +2 -2
- package/esm/typings/src/formfactors/completion/CompletionFormfactorDefinition.d.ts +29 -0
- package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +2 -1
- package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +2 -2
- package/esm/typings/src/formfactors/index.d.ts +33 -8
- package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +4 -2
- package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +3 -2
- package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +3 -2
- package/esm/typings/src/high-level-abstractions/index.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +4 -4
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +4 -3
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +17 -4
- package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +11 -4
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +27 -5
- package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +9 -2
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +12 -3
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +10 -5
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +5 -3
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +5 -5
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +23 -0
- package/esm/typings/src/llm-providers/google/google-models.d.ts +23 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -2
- package/esm/typings/src/migrations/migratePipeline.d.ts +9 -0
- package/esm/typings/src/other/templates/getBookTemplates.d.ts +2 -2
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +3 -3
- package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +5 -4
- package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +9 -6
- package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +4 -2
- package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +3 -2
- package/esm/typings/src/pipeline/PipelineString.d.ts +3 -1
- package/esm/typings/src/pipeline/book-notation.d.ts +2 -2
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTasks.d.ts +7 -4
- package/esm/typings/src/remote-server/openapi-types.d.ts +348 -6
- package/esm/typings/src/remote-server/openapi.d.ts +398 -4
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +2 -1
- package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +3 -3
- package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/Converter.d.ts +3 -1
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +4 -3
- package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +4 -2
- package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +2 -1
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +6 -3
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +3 -5
- package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
- package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +3 -2
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +8 -5
- package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +2 -1
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +6 -5
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -1
- package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +2 -1
- package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +4 -1
- package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +2 -1
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -4
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +5 -1
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +12 -5
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +4 -2
- package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +2 -1
- package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +10 -0
- package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +7 -0
- package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +2 -1
- package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +2 -1
- package/esm/typings/src/types/ModelVariant.d.ts +5 -5
- package/esm/typings/src/types/typeAliases.d.ts +17 -13
- package/esm/typings/src/utils/$Register.d.ts +8 -7
- package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +2 -2
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +4 -1
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +2 -1
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
- package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +4 -4
- package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +4 -4
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -3
- package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +3 -3
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +4 -4
- package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +3 -3
- package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +3 -3
- package/esm/typings/src/utils/normalization/searchKeywords.d.ts +4 -1
- package/esm/typings/src/utils/normalization/titleToName.d.ts +4 -4
- package/esm/typings/src/utils/organization/empty_object.d.ts +2 -2
- package/esm/typings/src/utils/organization/just_empty_object.d.ts +4 -4
- package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
- package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
- package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
- package/esm/typings/src/version.d.ts +2 -1
- package/package.json +2 -2
- package/umd/index.umd.js +557 -276
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +0 -31
- package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
package/esm/index.es.js
CHANGED
|
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
29
29
|
* @generated
|
|
30
30
|
* @see https://github.com/webgptorg/promptbook
|
|
31
31
|
*/
|
|
32
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
32
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-31';
|
|
33
33
|
/**
|
|
34
34
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
35
35
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -132,6 +132,21 @@ const DEFAULT_BOOK_TITLE = `✨ Untitled Book`;
|
|
|
132
132
|
* @public exported from `@promptbook/core`
|
|
133
133
|
*/
|
|
134
134
|
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
135
|
+
/**
|
|
136
|
+
* Threshold value that determines when a dataset is considered "big"
|
|
137
|
+
* and may require special handling or optimizations
|
|
138
|
+
*
|
|
139
|
+
* For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
|
|
140
|
+
*
|
|
141
|
+
* @public exported from `@promptbook/core`
|
|
142
|
+
*/
|
|
143
|
+
const BIG_DATASET_TRESHOLD = 50;
|
|
144
|
+
/**
|
|
145
|
+
* Placeholder text used to represent a placeholder value of failed operation
|
|
146
|
+
*
|
|
147
|
+
* @public exported from `@promptbook/core`
|
|
148
|
+
*/
|
|
149
|
+
const FAILED_VALUE_PLACEHOLDER = '!?';
|
|
135
150
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
136
151
|
/**
|
|
137
152
|
* The maximum number of iterations for a loops
|
|
@@ -211,7 +226,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
|
211
226
|
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
212
227
|
// <- TODO: [🧜♂️]
|
|
213
228
|
/**
|
|
214
|
-
*
|
|
229
|
+
* Default settings for parsing and generating CSV files in Promptbook.
|
|
215
230
|
*
|
|
216
231
|
* @public exported from `@promptbook/core`
|
|
217
232
|
*/
|
|
@@ -222,19 +237,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
|
222
237
|
skipEmptyLines: true,
|
|
223
238
|
});
|
|
224
239
|
/**
|
|
225
|
-
*
|
|
240
|
+
* Controls whether verbose logging is enabled by default throughout the application.
|
|
226
241
|
*
|
|
227
242
|
* @public exported from `@promptbook/core`
|
|
228
243
|
*/
|
|
229
244
|
let DEFAULT_IS_VERBOSE = false;
|
|
230
245
|
/**
|
|
231
|
-
*
|
|
246
|
+
* Controls whether auto-installation of dependencies is enabled by default.
|
|
232
247
|
*
|
|
233
248
|
* @public exported from `@promptbook/core`
|
|
234
249
|
*/
|
|
235
250
|
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
236
251
|
/**
|
|
237
|
-
*
|
|
252
|
+
* Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
|
|
238
253
|
*
|
|
239
254
|
* @private within the repository
|
|
240
255
|
*/
|
|
@@ -339,7 +354,8 @@ class UnexpectedError extends Error {
|
|
|
339
354
|
}
|
|
340
355
|
|
|
341
356
|
/**
|
|
342
|
-
*
|
|
357
|
+
* Safely retrieves the global scope object (window in browser, global in Node.js)
|
|
358
|
+
* regardless of the JavaScript environment in which the code is running
|
|
343
359
|
*
|
|
344
360
|
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
345
361
|
*
|
|
@@ -350,10 +366,10 @@ function $getGlobalScope() {
|
|
|
350
366
|
}
|
|
351
367
|
|
|
352
368
|
/**
|
|
353
|
-
*
|
|
369
|
+
* Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
|
|
354
370
|
*
|
|
355
|
-
* @param text
|
|
356
|
-
* @returns
|
|
371
|
+
* @param text The text string to be converted to SCREAMING_CASE format.
|
|
372
|
+
* @returns The normalized text in SCREAMING_CASE format.
|
|
357
373
|
* @example 'HELLO_WORLD'
|
|
358
374
|
* @example 'I_LOVE_PROMPTBOOK'
|
|
359
375
|
* @public exported from `@promptbook/utils`
|
|
@@ -405,10 +421,10 @@ function normalizeTo_SCREAMING_CASE(text) {
|
|
|
405
421
|
*/
|
|
406
422
|
|
|
407
423
|
/**
|
|
408
|
-
*
|
|
424
|
+
* Normalizes a text string to snake_case format.
|
|
409
425
|
*
|
|
410
|
-
* @param text
|
|
411
|
-
* @returns
|
|
426
|
+
* @param text The text string to be converted to snake_case format.
|
|
427
|
+
* @returns The normalized text in snake_case format.
|
|
412
428
|
* @example 'hello_world'
|
|
413
429
|
* @example 'i_love_promptbook'
|
|
414
430
|
* @public exported from `@promptbook/utils`
|
|
@@ -418,11 +434,11 @@ function normalizeTo_snake_case(text) {
|
|
|
418
434
|
}
|
|
419
435
|
|
|
420
436
|
/**
|
|
421
|
-
*
|
|
437
|
+
* Global registry for storing and managing registered entities of a given type.
|
|
422
438
|
*
|
|
423
439
|
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
424
440
|
*
|
|
425
|
-
* @private internal utility, exported are only
|
|
441
|
+
* @private internal utility, exported are only singleton instances of this class
|
|
426
442
|
*/
|
|
427
443
|
class $Register {
|
|
428
444
|
constructor(registerName) {
|
|
@@ -466,10 +482,10 @@ class $Register {
|
|
|
466
482
|
}
|
|
467
483
|
|
|
468
484
|
/**
|
|
469
|
-
*
|
|
485
|
+
* Global registry for storing metadata about all available scrapers and converters.
|
|
470
486
|
*
|
|
471
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
472
|
-
* @singleton Only one instance of each register is created per build, but
|
|
487
|
+
* Note: `$` is used to indicate that this interacts with the global scope.
|
|
488
|
+
* @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
|
|
473
489
|
* @public exported from `@promptbook/core`
|
|
474
490
|
*/
|
|
475
491
|
const $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
@@ -533,7 +549,8 @@ class KnowledgeScrapeError extends Error {
|
|
|
533
549
|
}
|
|
534
550
|
|
|
535
551
|
/**
|
|
536
|
-
*
|
|
552
|
+
* Converts a name to a properly formatted subfolder path for cache storage.
|
|
553
|
+
* Handles normalization and path formatting to create consistent cache directory structures.
|
|
537
554
|
*
|
|
538
555
|
* @private for `FileCacheStorage`
|
|
539
556
|
*/
|
|
@@ -786,10 +803,10 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
|
786
803
|
*/
|
|
787
804
|
|
|
788
805
|
/**
|
|
789
|
-
*
|
|
806
|
+
* Removes diacritic marks (accents) from characters in a string.
|
|
790
807
|
*
|
|
791
|
-
* @param input
|
|
792
|
-
* @returns
|
|
808
|
+
* @param input The string containing diacritics to be normalized.
|
|
809
|
+
* @returns The string with diacritics removed or normalized.
|
|
793
810
|
* @public exported from `@promptbook/utils`
|
|
794
811
|
*/
|
|
795
812
|
function removeDiacritics(input) {
|
|
@@ -803,10 +820,10 @@ function removeDiacritics(input) {
|
|
|
803
820
|
*/
|
|
804
821
|
|
|
805
822
|
/**
|
|
806
|
-
*
|
|
823
|
+
* Converts a given text to kebab-case format.
|
|
807
824
|
*
|
|
808
|
-
* @param text
|
|
809
|
-
* @returns
|
|
825
|
+
* @param text The text to be converted.
|
|
826
|
+
* @returns The kebab-case formatted string.
|
|
810
827
|
* @example 'hello-world'
|
|
811
828
|
* @example 'i-love-promptbook'
|
|
812
829
|
* @public exported from `@promptbook/utils`
|
|
@@ -948,11 +965,11 @@ function isValidUrl(url) {
|
|
|
948
965
|
}
|
|
949
966
|
|
|
950
967
|
/**
|
|
951
|
-
*
|
|
968
|
+
* Converts a title string into a normalized name.
|
|
952
969
|
*
|
|
953
|
-
* @param value
|
|
954
|
-
* @returns
|
|
955
|
-
* @example
|
|
970
|
+
* @param value The title string to be converted to a name.
|
|
971
|
+
* @returns A normalized name derived from the input title.
|
|
972
|
+
* @example 'Hello World!' -> 'hello-world'
|
|
956
973
|
* @public exported from `@promptbook/utils`
|
|
957
974
|
*/
|
|
958
975
|
function titleToName(value) {
|
|
@@ -972,9 +989,8 @@ function titleToName(value) {
|
|
|
972
989
|
}
|
|
973
990
|
|
|
974
991
|
/**
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
* Note: It also checks if directory exists and creates it if not
|
|
992
|
+
* Retrieves an intermediate source for a scraper based on the knowledge source.
|
|
993
|
+
* Manages the caching and retrieval of intermediate scraper results for optimized performance.
|
|
978
994
|
*
|
|
979
995
|
* @private as internal utility for scrapers
|
|
980
996
|
*/
|
|
@@ -1025,7 +1041,7 @@ async function getScraperIntermediateSource(source, options) {
|
|
|
1025
1041
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
1026
1042
|
*/
|
|
1027
1043
|
|
|
1028
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book"}];
|
|
1044
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",formfactorName:"GENERIC",parameters:[{name:"availableModels",description:"List of available model names together with their descriptions as JSON",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelsRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n```json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n```\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n```json\n{availableModels}\n```\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelsRequirements",format:"JSON",dependentParameterNames:["availableModels","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book`\n- INPUT PARAMETER `{availableModels}` List of available model names together with their descriptions as JSON\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelsRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n\\`\\`\\`json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n\\`\\`\\`json\n{availableModels}\n\\`\\`\\`\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelsRequirements}`\n"}],sourceFile:"./books/prepare-persona.book"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book"}];
|
|
1029
1045
|
|
|
1030
1046
|
/**
|
|
1031
1047
|
* Checks if value is valid email
|
|
@@ -1110,7 +1126,7 @@ function assertsError(whatWasThrown) {
|
|
|
1110
1126
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1111
1127
|
*
|
|
1112
1128
|
* @param value The string to check
|
|
1113
|
-
* @returns
|
|
1129
|
+
* @returns `true` if the string is a valid JSON string, false otherwise
|
|
1114
1130
|
*
|
|
1115
1131
|
* @public exported from `@promptbook/utils`
|
|
1116
1132
|
*/
|
|
@@ -1494,8 +1510,12 @@ function checkSerializableAsJson(options) {
|
|
|
1494
1510
|
*/
|
|
1495
1511
|
|
|
1496
1512
|
/**
|
|
1497
|
-
*
|
|
1513
|
+
* Creates a deep clone of the given object
|
|
1498
1514
|
*
|
|
1515
|
+
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
|
1516
|
+
*
|
|
1517
|
+
* @param objectValue The object to clone.
|
|
1518
|
+
* @returns A deep, writable clone of the input object.
|
|
1499
1519
|
* @public exported from `@promptbook/utils`
|
|
1500
1520
|
*/
|
|
1501
1521
|
function deepClone(objectValue) {
|
|
@@ -1577,13 +1597,13 @@ const ORDER_OF_PIPELINE_JSON = [
|
|
|
1577
1597
|
*/
|
|
1578
1598
|
const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
1579
1599
|
/**
|
|
1580
|
-
*
|
|
1600
|
+
* Placeholder value indicating a parameter is missing its value.
|
|
1581
1601
|
*
|
|
1582
1602
|
* @private within the repository
|
|
1583
1603
|
*/
|
|
1584
1604
|
const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
1585
1605
|
/**
|
|
1586
|
-
*
|
|
1606
|
+
* Placeholder value indicating a parameter is restricted and cannot be used directly.
|
|
1587
1607
|
*
|
|
1588
1608
|
* @private within the repository
|
|
1589
1609
|
*/
|
|
@@ -2041,7 +2061,7 @@ function extractParameterNames(template) {
|
|
|
2041
2061
|
*/
|
|
2042
2062
|
function unpreparePipeline(pipeline) {
|
|
2043
2063
|
let { personas, knowledgeSources, tasks } = pipeline;
|
|
2044
|
-
personas = personas.map((persona) => ({ ...persona,
|
|
2064
|
+
personas = personas.map((persona) => ({ ...persona, modelsRequirements: undefined, preparationIds: undefined }));
|
|
2045
2065
|
knowledgeSources = knowledgeSources.map((knowledgeSource) => ({ ...knowledgeSource, preparationIds: undefined }));
|
|
2046
2066
|
tasks = tasks.map((task) => {
|
|
2047
2067
|
let { dependentParameterNames } = task;
|
|
@@ -2082,7 +2102,7 @@ class SimplePipelineCollection {
|
|
|
2082
2102
|
/**
|
|
2083
2103
|
* Constructs a pipeline collection from pipelines
|
|
2084
2104
|
*
|
|
2085
|
-
* @param pipelines
|
|
2105
|
+
* @param pipelines Array of pipeline JSON objects to include in the collection
|
|
2086
2106
|
*
|
|
2087
2107
|
* Note: During the construction logic of all pipelines are validated
|
|
2088
2108
|
* Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
|
|
@@ -2246,15 +2266,21 @@ class PipelineExecutionError extends Error {
|
|
|
2246
2266
|
* @public exported from `@promptbook/core`
|
|
2247
2267
|
*/
|
|
2248
2268
|
function isPipelinePrepared(pipeline) {
|
|
2249
|
-
// Note: Ignoring `pipeline.preparations`
|
|
2250
|
-
// Note: Ignoring `pipeline.knowledgePieces`
|
|
2269
|
+
// Note: Ignoring `pipeline.preparations`
|
|
2270
|
+
// Note: Ignoring `pipeline.knowledgePieces`
|
|
2251
2271
|
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2272
|
+
// TODO: !!! Comment this out
|
|
2273
|
+
console.log('Pipeline is not prepared because title is undefined or empty', pipeline);
|
|
2252
2274
|
return false;
|
|
2253
2275
|
}
|
|
2254
|
-
if (!pipeline.personas.every((persona) => persona.
|
|
2276
|
+
if (!pipeline.personas.every((persona) => persona.modelsRequirements !== undefined)) {
|
|
2277
|
+
// TODO: !!! Comment this out
|
|
2278
|
+
console.log('Pipeline is not prepared because personas are not prepared', pipeline.personas);
|
|
2255
2279
|
return false;
|
|
2256
2280
|
}
|
|
2257
2281
|
if (!pipeline.knowledgeSources.every((knowledgeSource) => knowledgeSource.preparationIds !== undefined)) {
|
|
2282
|
+
// TODO: !!! Comment this out
|
|
2283
|
+
console.log('Pipeline is not prepared because knowledge sources are not prepared', pipeline.knowledgeSources);
|
|
2258
2284
|
return false;
|
|
2259
2285
|
}
|
|
2260
2286
|
/*
|
|
@@ -2275,36 +2301,6 @@ function isPipelinePrepared(pipeline) {
|
|
|
2275
2301
|
* - [♨] Are tasks prepared
|
|
2276
2302
|
*/
|
|
2277
2303
|
|
|
2278
|
-
/**
|
|
2279
|
-
* Recursively converts JSON strings to JSON objects
|
|
2280
|
-
|
|
2281
|
-
* @public exported from `@promptbook/utils`
|
|
2282
|
-
*/
|
|
2283
|
-
function jsonStringsToJsons(object) {
|
|
2284
|
-
if (object === null) {
|
|
2285
|
-
return object;
|
|
2286
|
-
}
|
|
2287
|
-
if (Array.isArray(object)) {
|
|
2288
|
-
return object.map(jsonStringsToJsons);
|
|
2289
|
-
}
|
|
2290
|
-
if (typeof object !== 'object') {
|
|
2291
|
-
return object;
|
|
2292
|
-
}
|
|
2293
|
-
const newObject = { ...object };
|
|
2294
|
-
for (const [key, value] of Object.entries(object)) {
|
|
2295
|
-
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
2296
|
-
newObject[key] = JSON.parse(value);
|
|
2297
|
-
}
|
|
2298
|
-
else {
|
|
2299
|
-
newObject[key] = jsonStringsToJsons(value);
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
return newObject;
|
|
2303
|
-
}
|
|
2304
|
-
/**
|
|
2305
|
-
* TODO: Type the return type correctly
|
|
2306
|
-
*/
|
|
2307
|
-
|
|
2308
2304
|
/**
|
|
2309
2305
|
* This error indicates problems parsing the format value
|
|
2310
2306
|
*
|
|
@@ -2465,6 +2461,101 @@ const ALL_ERRORS = {
|
|
|
2465
2461
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2466
2462
|
*/
|
|
2467
2463
|
|
|
2464
|
+
/**
|
|
2465
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2466
|
+
*
|
|
2467
|
+
* @public exported from `@promptbook/utils`
|
|
2468
|
+
*/
|
|
2469
|
+
function serializeError(error) {
|
|
2470
|
+
const { name, message, stack } = error;
|
|
2471
|
+
const { id } = error;
|
|
2472
|
+
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2473
|
+
console.error(spaceTrim$1((block) => `
|
|
2474
|
+
|
|
2475
|
+
Cannot serialize error with name "${name}"
|
|
2476
|
+
|
|
2477
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2478
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2479
|
+
|
|
2480
|
+
|
|
2481
|
+
${block(stack || message)}
|
|
2482
|
+
|
|
2483
|
+
`));
|
|
2484
|
+
}
|
|
2485
|
+
return {
|
|
2486
|
+
name: name,
|
|
2487
|
+
message,
|
|
2488
|
+
stack,
|
|
2489
|
+
id, // Include id in the serialized object
|
|
2490
|
+
};
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* Converts a JavaScript Object Notation (JSON) string into an object.
|
|
2495
|
+
*
|
|
2496
|
+
* Note: This is wrapper around `JSON.parse()` with better error and type handling
|
|
2497
|
+
*
|
|
2498
|
+
* @public exported from `@promptbook/utils`
|
|
2499
|
+
*/
|
|
2500
|
+
function jsonParse(value) {
|
|
2501
|
+
if (value === undefined) {
|
|
2502
|
+
throw new Error(`Can not parse JSON from undefined value.`);
|
|
2503
|
+
}
|
|
2504
|
+
else if (typeof value !== 'string') {
|
|
2505
|
+
console.error('Can not parse JSON from non-string value.', { text: value });
|
|
2506
|
+
throw new Error(spaceTrim$1(`
|
|
2507
|
+
Can not parse JSON from non-string value.
|
|
2508
|
+
|
|
2509
|
+
The value type: ${typeof value}
|
|
2510
|
+
See more in console.
|
|
2511
|
+
`));
|
|
2512
|
+
}
|
|
2513
|
+
try {
|
|
2514
|
+
return JSON.parse(value);
|
|
2515
|
+
}
|
|
2516
|
+
catch (error) {
|
|
2517
|
+
if (!(error instanceof Error)) {
|
|
2518
|
+
throw error;
|
|
2519
|
+
}
|
|
2520
|
+
throw new Error(spaceTrim$1((block) => `
|
|
2521
|
+
${block(error.message)}
|
|
2522
|
+
|
|
2523
|
+
The JSON text:
|
|
2524
|
+
${block(value)}
|
|
2525
|
+
`));
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
/**
|
|
2530
|
+
* Recursively converts JSON strings to JSON objects
|
|
2531
|
+
|
|
2532
|
+
* @public exported from `@promptbook/utils`
|
|
2533
|
+
*/
|
|
2534
|
+
function jsonStringsToJsons(object) {
|
|
2535
|
+
if (object === null) {
|
|
2536
|
+
return object;
|
|
2537
|
+
}
|
|
2538
|
+
if (Array.isArray(object)) {
|
|
2539
|
+
return object.map(jsonStringsToJsons);
|
|
2540
|
+
}
|
|
2541
|
+
if (typeof object !== 'object') {
|
|
2542
|
+
return object;
|
|
2543
|
+
}
|
|
2544
|
+
const newObject = { ...object };
|
|
2545
|
+
for (const [key, value] of Object.entries(object)) {
|
|
2546
|
+
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
2547
|
+
newObject[key] = jsonParse(value);
|
|
2548
|
+
}
|
|
2549
|
+
else {
|
|
2550
|
+
newObject[key] = jsonStringsToJsons(value);
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
return newObject;
|
|
2554
|
+
}
|
|
2555
|
+
/**
|
|
2556
|
+
* TODO: Type the return type correctly
|
|
2557
|
+
*/
|
|
2558
|
+
|
|
2468
2559
|
/**
|
|
2469
2560
|
* Deserializes the error object
|
|
2470
2561
|
*
|
|
@@ -2630,64 +2721,6 @@ function createTask(options) {
|
|
|
2630
2721
|
* TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
|
|
2631
2722
|
*/
|
|
2632
2723
|
|
|
2633
|
-
/**
|
|
2634
|
-
* Serializes an error into a [🚉] JSON-serializable object
|
|
2635
|
-
*
|
|
2636
|
-
* @public exported from `@promptbook/utils`
|
|
2637
|
-
*/
|
|
2638
|
-
function serializeError(error) {
|
|
2639
|
-
const { name, message, stack } = error;
|
|
2640
|
-
const { id } = error;
|
|
2641
|
-
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2642
|
-
console.error(spaceTrim$1((block) => `
|
|
2643
|
-
|
|
2644
|
-
Cannot serialize error with name "${name}"
|
|
2645
|
-
|
|
2646
|
-
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2647
|
-
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
${block(stack || message)}
|
|
2651
|
-
|
|
2652
|
-
`));
|
|
2653
|
-
}
|
|
2654
|
-
return {
|
|
2655
|
-
name: name,
|
|
2656
|
-
message,
|
|
2657
|
-
stack,
|
|
2658
|
-
id, // Include id in the serialized object
|
|
2659
|
-
};
|
|
2660
|
-
}
|
|
2661
|
-
|
|
2662
|
-
/**
|
|
2663
|
-
* Async version of Array.forEach
|
|
2664
|
-
*
|
|
2665
|
-
* @param array - Array to iterate over
|
|
2666
|
-
* @param options - Options for the function
|
|
2667
|
-
* @param callbackfunction - Function to call for each item
|
|
2668
|
-
* @public exported from `@promptbook/utils`
|
|
2669
|
-
* @deprecated [🪂] Use queues instead
|
|
2670
|
-
*/
|
|
2671
|
-
async function forEachAsync(array, options, callbackfunction) {
|
|
2672
|
-
const { maxParallelCount = Infinity } = options;
|
|
2673
|
-
let index = 0;
|
|
2674
|
-
let runningTasks = [];
|
|
2675
|
-
const tasks = [];
|
|
2676
|
-
for (const item of array) {
|
|
2677
|
-
const currentIndex = index++;
|
|
2678
|
-
const task = callbackfunction(item, currentIndex, array);
|
|
2679
|
-
tasks.push(task);
|
|
2680
|
-
runningTasks.push(task);
|
|
2681
|
-
/* not await */ Promise.resolve(task).then(() => {
|
|
2682
|
-
runningTasks = runningTasks.filter((t) => t !== task);
|
|
2683
|
-
});
|
|
2684
|
-
if (maxParallelCount < runningTasks.length) {
|
|
2685
|
-
await Promise.race(runningTasks);
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
await Promise.all(tasks);
|
|
2689
|
-
}
|
|
2690
|
-
|
|
2691
2724
|
/**
|
|
2692
2725
|
* Represents the uncertain value
|
|
2693
2726
|
*
|
|
@@ -2731,7 +2764,7 @@ const ZERO_USAGE = $deepFreeze({
|
|
|
2731
2764
|
*
|
|
2732
2765
|
* @public exported from `@promptbook/core`
|
|
2733
2766
|
*/
|
|
2734
|
-
$deepFreeze({
|
|
2767
|
+
const UNCERTAIN_USAGE = $deepFreeze({
|
|
2735
2768
|
price: UNCERTAIN_ZERO_VALUE,
|
|
2736
2769
|
input: {
|
|
2737
2770
|
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
@@ -2756,6 +2789,35 @@ $deepFreeze({
|
|
|
2756
2789
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2757
2790
|
*/
|
|
2758
2791
|
|
|
2792
|
+
/**
|
|
2793
|
+
* Async version of Array.forEach
|
|
2794
|
+
*
|
|
2795
|
+
* @param array - Array to iterate over
|
|
2796
|
+
* @param options - Options for the function
|
|
2797
|
+
* @param callbackfunction - Function to call for each item
|
|
2798
|
+
* @public exported from `@promptbook/utils`
|
|
2799
|
+
* @deprecated [🪂] Use queues instead
|
|
2800
|
+
*/
|
|
2801
|
+
async function forEachAsync(array, options, callbackfunction) {
|
|
2802
|
+
const { maxParallelCount = Infinity } = options;
|
|
2803
|
+
let index = 0;
|
|
2804
|
+
let runningTasks = [];
|
|
2805
|
+
const tasks = [];
|
|
2806
|
+
for (const item of array) {
|
|
2807
|
+
const currentIndex = index++;
|
|
2808
|
+
const task = callbackfunction(item, currentIndex, array);
|
|
2809
|
+
tasks.push(task);
|
|
2810
|
+
runningTasks.push(task);
|
|
2811
|
+
/* not await */ Promise.resolve(task).then(() => {
|
|
2812
|
+
runningTasks = runningTasks.filter((t) => t !== task);
|
|
2813
|
+
});
|
|
2814
|
+
if (maxParallelCount < runningTasks.length) {
|
|
2815
|
+
await Promise.race(runningTasks);
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
await Promise.all(tasks);
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2759
2821
|
/**
|
|
2760
2822
|
* Function `addUsage` will add multiple usages into one
|
|
2761
2823
|
*
|
|
@@ -3102,27 +3164,48 @@ async function preparePersona(personaDescription, tools, options) {
|
|
|
3102
3164
|
pipeline: await collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book'),
|
|
3103
3165
|
tools,
|
|
3104
3166
|
});
|
|
3105
|
-
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
3106
3167
|
const _llms = arrayableToArray(tools.llm);
|
|
3107
3168
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
3108
|
-
const availableModels = await llmTools.listModels()
|
|
3109
|
-
const availableModelNames = availableModels
|
|
3169
|
+
const availableModels = (await llmTools.listModels())
|
|
3110
3170
|
.filter(({ modelVariant }) => modelVariant === 'CHAT')
|
|
3111
|
-
.map(({ modelName }) =>
|
|
3112
|
-
|
|
3113
|
-
|
|
3171
|
+
.map(({ modelName, modelDescription }) => ({
|
|
3172
|
+
modelName,
|
|
3173
|
+
modelDescription,
|
|
3174
|
+
// <- Note: `modelTitle` and `modelVariant` is not relevant for this task
|
|
3175
|
+
}));
|
|
3176
|
+
const result = await preparePersonaExecutor({
|
|
3177
|
+
availableModels /* <- Note: Passing as JSON */,
|
|
3178
|
+
personaDescription,
|
|
3179
|
+
}).asPromise();
|
|
3114
3180
|
const { outputParameters } = result;
|
|
3115
|
-
const {
|
|
3116
|
-
|
|
3181
|
+
const { modelsRequirements: modelsRequirementsJson } = outputParameters;
|
|
3182
|
+
let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
|
|
3117
3183
|
if (isVerbose) {
|
|
3118
|
-
console.info(`PERSONA ${personaDescription}`,
|
|
3184
|
+
console.info(`PERSONA ${personaDescription}`, modelsRequirementsUnchecked);
|
|
3119
3185
|
}
|
|
3120
|
-
|
|
3121
|
-
|
|
3186
|
+
if (!Array.isArray(modelsRequirementsUnchecked)) {
|
|
3187
|
+
// <- TODO: Book should have syntax and system to enforce shape of JSON
|
|
3188
|
+
modelsRequirementsUnchecked = [modelsRequirementsUnchecked];
|
|
3189
|
+
/*
|
|
3190
|
+
throw new UnexpectedError(
|
|
3191
|
+
spaceTrim(
|
|
3192
|
+
(block) => `
|
|
3193
|
+
Invalid \`modelsRequirements\`:
|
|
3194
|
+
|
|
3195
|
+
\`\`\`json
|
|
3196
|
+
${block(JSON.stringify(modelsRequirementsUnchecked, null, 4))}
|
|
3197
|
+
\`\`\`
|
|
3198
|
+
`,
|
|
3199
|
+
),
|
|
3200
|
+
);
|
|
3201
|
+
*/
|
|
3202
|
+
}
|
|
3203
|
+
const modelsRequirements = modelsRequirementsUnchecked.map((modelRequirements) => ({
|
|
3122
3204
|
modelVariant: 'CHAT',
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3205
|
+
...modelRequirements,
|
|
3206
|
+
}));
|
|
3207
|
+
return {
|
|
3208
|
+
modelsRequirements,
|
|
3126
3209
|
};
|
|
3127
3210
|
}
|
|
3128
3211
|
/**
|
|
@@ -3133,10 +3216,11 @@ async function preparePersona(personaDescription, tools, options) {
|
|
|
3133
3216
|
*/
|
|
3134
3217
|
|
|
3135
3218
|
/**
|
|
3136
|
-
*
|
|
3219
|
+
* Registry for all available scrapers in the system.
|
|
3220
|
+
* Central point for registering and accessing different types of content scrapers.
|
|
3137
3221
|
*
|
|
3138
3222
|
* Note: `$` is used to indicate that this interacts with the global scope
|
|
3139
|
-
* @singleton Only one instance of each register is created per build, but
|
|
3223
|
+
* @singleton Only one instance of each register is created per build, but there can be more than one in different build modules
|
|
3140
3224
|
* @public exported from `@promptbook/core`
|
|
3141
3225
|
*/
|
|
3142
3226
|
const $scrapersRegister = new $Register('scraper_constructors');
|
|
@@ -3339,7 +3423,9 @@ const promptbookFetch = async (urlOrRequest, init) => {
|
|
|
3339
3423
|
*/
|
|
3340
3424
|
|
|
3341
3425
|
/**
|
|
3342
|
-
*
|
|
3426
|
+
* Factory function that creates a handler for processing knowledge sources.
|
|
3427
|
+
* Provides standardized processing of different types of knowledge sources
|
|
3428
|
+
* across various scraper implementations.
|
|
3343
3429
|
*
|
|
3344
3430
|
* @public exported from `@promptbook/core`
|
|
3345
3431
|
*/
|
|
@@ -3446,7 +3532,7 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3446
3532
|
> },
|
|
3447
3533
|
*/
|
|
3448
3534
|
async asJson() {
|
|
3449
|
-
return
|
|
3535
|
+
return jsonParse(await tools.fs.readFile(filename, 'utf-8'));
|
|
3450
3536
|
},
|
|
3451
3537
|
async asText() {
|
|
3452
3538
|
return await tools.fs.readFile(filename, 'utf-8');
|
|
@@ -3580,9 +3666,12 @@ TODO: [🧊] This is how it can look in future
|
|
|
3580
3666
|
*/
|
|
3581
3667
|
|
|
3582
3668
|
/**
|
|
3583
|
-
*
|
|
3669
|
+
* Prepares tasks by adding knowledge to the prompt and ensuring all necessary parameters are included.
|
|
3584
3670
|
*
|
|
3585
|
-
* @
|
|
3671
|
+
* @param tasks Sequence of tasks that are chained together to form a pipeline
|
|
3672
|
+
* @returns A promise that resolves to the prepared tasks.
|
|
3673
|
+
*
|
|
3674
|
+
* @private internal utility of `preparePipeline`
|
|
3586
3675
|
*/
|
|
3587
3676
|
async function prepareTasks(pipeline, tools, options) {
|
|
3588
3677
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT } = options;
|
|
@@ -3704,14 +3793,14 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
3704
3793
|
// TODO: [🖌][🧠] Implement some `mapAsync` function
|
|
3705
3794
|
const preparedPersonas = new Array(personas.length);
|
|
3706
3795
|
await forEachAsync(personas, { maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, async (persona, index) => {
|
|
3707
|
-
const
|
|
3796
|
+
const { modelsRequirements } = await preparePersona(persona.description, { ...tools, llm: llmToolsWithUsage }, {
|
|
3708
3797
|
rootDirname,
|
|
3709
3798
|
maxParallelCount /* <- TODO: [🪂] */,
|
|
3710
3799
|
isVerbose,
|
|
3711
3800
|
});
|
|
3712
3801
|
const preparedPersona = {
|
|
3713
3802
|
...persona,
|
|
3714
|
-
|
|
3803
|
+
modelsRequirements,
|
|
3715
3804
|
preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id],
|
|
3716
3805
|
// <- TODO: [🍙] Make some standard order of json properties
|
|
3717
3806
|
};
|
|
@@ -4019,7 +4108,7 @@ function union(...sets) {
|
|
|
4019
4108
|
}
|
|
4020
4109
|
|
|
4021
4110
|
/**
|
|
4022
|
-
*
|
|
4111
|
+
* Contains configuration options for parsing and generating CSV files, such as delimiters and quoting rules.
|
|
4023
4112
|
*
|
|
4024
4113
|
* @public exported from `@promptbook/core`
|
|
4025
4114
|
*/
|
|
@@ -4028,11 +4117,29 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
4028
4117
|
// encoding: 'utf-8',
|
|
4029
4118
|
});
|
|
4030
4119
|
|
|
4120
|
+
/**
|
|
4121
|
+
* Converts a CSV string into an object
|
|
4122
|
+
*
|
|
4123
|
+
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
4124
|
+
*
|
|
4125
|
+
* @private - for now until `@promptbook/csv` is released
|
|
4126
|
+
*/
|
|
4127
|
+
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
4128
|
+
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
4129
|
+
// Note: Autoheal invalid '\n' characters
|
|
4130
|
+
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
4131
|
+
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
4132
|
+
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
4133
|
+
}
|
|
4134
|
+
const csv = parse(value, settings);
|
|
4135
|
+
return csv;
|
|
4136
|
+
}
|
|
4137
|
+
|
|
4031
4138
|
/**
|
|
4032
4139
|
* Function to check if a string is valid CSV
|
|
4033
4140
|
*
|
|
4034
4141
|
* @param value The string to check
|
|
4035
|
-
* @returns
|
|
4142
|
+
* @returns `true` if the string is a valid CSV string, false otherwise
|
|
4036
4143
|
*
|
|
4037
4144
|
* @public exported from `@promptbook/utils`
|
|
4038
4145
|
*/
|
|
@@ -4056,7 +4163,7 @@ function isValidCsvString(value) {
|
|
|
4056
4163
|
* @public exported from `@promptbook/core`
|
|
4057
4164
|
* <- TODO: [🏢] Export from package `@promptbook/csv`
|
|
4058
4165
|
*/
|
|
4059
|
-
const
|
|
4166
|
+
const CsvFormatParser = {
|
|
4060
4167
|
formatName: 'CSV',
|
|
4061
4168
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
4062
4169
|
isValid(value, settings, schema) {
|
|
@@ -4068,12 +4175,12 @@ const CsvFormatDefinition = {
|
|
|
4068
4175
|
heal(value, settings, schema) {
|
|
4069
4176
|
throw new Error('Not implemented');
|
|
4070
4177
|
},
|
|
4071
|
-
|
|
4178
|
+
subvalueParsers: [
|
|
4072
4179
|
{
|
|
4073
4180
|
subvalueName: 'ROW',
|
|
4074
|
-
async mapValues(
|
|
4075
|
-
|
|
4076
|
-
const csv =
|
|
4181
|
+
async mapValues(options) {
|
|
4182
|
+
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
4183
|
+
const csv = csvParse(value, settings);
|
|
4077
4184
|
if (csv.errors.length !== 0) {
|
|
4078
4185
|
throw new CsvFormatError(spaceTrim$1((block) => `
|
|
4079
4186
|
CSV parsing error
|
|
@@ -4088,23 +4195,37 @@ const CsvFormatDefinition = {
|
|
|
4088
4195
|
${block(value)}
|
|
4089
4196
|
`));
|
|
4090
4197
|
}
|
|
4091
|
-
const mappedData =
|
|
4198
|
+
const mappedData = [];
|
|
4199
|
+
const length = csv.data.length;
|
|
4200
|
+
for (let index = 0; index < length; index++) {
|
|
4201
|
+
const row = csv.data[index];
|
|
4092
4202
|
if (row[outputParameterName]) {
|
|
4093
4203
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4094
4204
|
}
|
|
4095
|
-
|
|
4205
|
+
const mappedRow = {
|
|
4096
4206
|
...row,
|
|
4097
|
-
[outputParameterName]: await mapCallback(row, index),
|
|
4207
|
+
[outputParameterName]: await mapCallback(row, index, length),
|
|
4098
4208
|
};
|
|
4099
|
-
|
|
4209
|
+
mappedData.push(mappedRow);
|
|
4210
|
+
if (onProgress) {
|
|
4211
|
+
// Note: Report the CSV with all rows mapped so far
|
|
4212
|
+
/*
|
|
4213
|
+
// TODO: [🛕] Report progress with all the rows including the pending ones
|
|
4214
|
+
const progressData = mappedData.map((row, i) =>
|
|
4215
|
+
i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
|
|
4216
|
+
);
|
|
4217
|
+
*/
|
|
4218
|
+
await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
4100
4221
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4101
4222
|
},
|
|
4102
4223
|
},
|
|
4103
4224
|
{
|
|
4104
4225
|
subvalueName: 'CELL',
|
|
4105
|
-
async mapValues(
|
|
4106
|
-
|
|
4107
|
-
const csv =
|
|
4226
|
+
async mapValues(options) {
|
|
4227
|
+
const { value, settings, mapCallback, onProgress } = options;
|
|
4228
|
+
const csv = csvParse(value, settings);
|
|
4108
4229
|
if (csv.errors.length !== 0) {
|
|
4109
4230
|
throw new CsvFormatError(spaceTrim$1((block) => `
|
|
4110
4231
|
CSV parsing error
|
|
@@ -4120,9 +4241,9 @@ const CsvFormatDefinition = {
|
|
|
4120
4241
|
`));
|
|
4121
4242
|
}
|
|
4122
4243
|
const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
|
|
4123
|
-
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
|
|
4244
|
+
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
|
|
4124
4245
|
const index = rowIndex * Object.keys(row).length + columnIndex;
|
|
4125
|
-
return /* not await */ mapCallback({ [key]: value }, index);
|
|
4246
|
+
return /* not await */ mapCallback({ [key]: value }, index, array.length);
|
|
4126
4247
|
}));
|
|
4127
4248
|
}));
|
|
4128
4249
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
@@ -4131,10 +4252,10 @@ const CsvFormatDefinition = {
|
|
|
4131
4252
|
],
|
|
4132
4253
|
};
|
|
4133
4254
|
/**
|
|
4134
|
-
* TODO: [🍓] In `
|
|
4135
|
-
* TODO: [🍓] In `
|
|
4136
|
-
* TODO: [🍓] In `
|
|
4137
|
-
* TODO: [🍓] In `
|
|
4255
|
+
* TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
|
|
4256
|
+
* TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
|
|
4257
|
+
* TODO: [🍓] In `CsvFormatParser` implement `heal
|
|
4258
|
+
* TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
|
|
4138
4259
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
4139
4260
|
*/
|
|
4140
4261
|
|
|
@@ -4143,7 +4264,7 @@ const CsvFormatDefinition = {
|
|
|
4143
4264
|
*
|
|
4144
4265
|
* @private still in development [🏢]
|
|
4145
4266
|
*/
|
|
4146
|
-
const
|
|
4267
|
+
const JsonFormatParser = {
|
|
4147
4268
|
formatName: 'JSON',
|
|
4148
4269
|
mimeType: 'application/json',
|
|
4149
4270
|
isValid(value, settings, schema) {
|
|
@@ -4155,28 +4276,28 @@ const JsonFormatDefinition = {
|
|
|
4155
4276
|
heal(value, settings, schema) {
|
|
4156
4277
|
throw new Error('Not implemented');
|
|
4157
4278
|
},
|
|
4158
|
-
|
|
4279
|
+
subvalueParsers: [],
|
|
4159
4280
|
};
|
|
4160
4281
|
/**
|
|
4161
4282
|
* TODO: [🧠] Maybe propper instance of object
|
|
4162
4283
|
* TODO: [0] Make string_serialized_json
|
|
4163
4284
|
* TODO: [1] Make type for JSON Settings and Schema
|
|
4164
4285
|
* TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
|
|
4165
|
-
* TODO: [🍓] In `
|
|
4166
|
-
* TODO: [🍓] In `
|
|
4167
|
-
* TODO: [🍓] In `
|
|
4168
|
-
* TODO: [🍓] In `
|
|
4286
|
+
* TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
|
|
4287
|
+
* TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
|
|
4288
|
+
* TODO: [🍓] In `JsonFormatParser` implement `heal
|
|
4289
|
+
* TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
|
|
4169
4290
|
* TODO: [🏢] Allow to expect something inside JSON objects and other formats
|
|
4170
4291
|
*/
|
|
4171
4292
|
|
|
4172
4293
|
/**
|
|
4173
4294
|
* Definition for any text - this will be always valid
|
|
4174
4295
|
*
|
|
4175
|
-
* Note: This is not useful for validation, but for splitting and mapping with `
|
|
4296
|
+
* Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
|
|
4176
4297
|
*
|
|
4177
4298
|
* @public exported from `@promptbook/core`
|
|
4178
4299
|
*/
|
|
4179
|
-
const
|
|
4300
|
+
const TextFormatParser = {
|
|
4180
4301
|
formatName: 'TEXT',
|
|
4181
4302
|
isValid(value) {
|
|
4182
4303
|
return typeof value === 'string';
|
|
@@ -4185,19 +4306,20 @@ const TextFormatDefinition = {
|
|
|
4185
4306
|
return typeof partialValue === 'string';
|
|
4186
4307
|
},
|
|
4187
4308
|
heal() {
|
|
4188
|
-
throw new UnexpectedError('It does not make sense to call `
|
|
4309
|
+
throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
|
|
4189
4310
|
},
|
|
4190
|
-
|
|
4311
|
+
subvalueParsers: [
|
|
4191
4312
|
{
|
|
4192
4313
|
subvalueName: 'LINE',
|
|
4193
|
-
async mapValues(
|
|
4314
|
+
async mapValues(options) {
|
|
4315
|
+
const { value, mapCallback, onProgress } = options;
|
|
4194
4316
|
const lines = value.split('\n');
|
|
4195
|
-
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4317
|
+
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
|
|
4196
4318
|
// TODO: [🧠] Maybe option to skip empty line
|
|
4197
4319
|
/* not await */ mapCallback({
|
|
4198
4320
|
lineContent,
|
|
4199
4321
|
// TODO: [🧠] Maybe also put here `lineNumber`
|
|
4200
|
-
}, lineNumber)));
|
|
4322
|
+
}, lineNumber, array.length)));
|
|
4201
4323
|
return mappedLines.join('\n');
|
|
4202
4324
|
},
|
|
4203
4325
|
},
|
|
@@ -4207,10 +4329,10 @@ const TextFormatDefinition = {
|
|
|
4207
4329
|
/**
|
|
4208
4330
|
* TODO: [1] Make type for XML Text and Schema
|
|
4209
4331
|
* TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
|
|
4210
|
-
* TODO: [🍓] In `
|
|
4211
|
-
* TODO: [🍓] In `
|
|
4212
|
-
* TODO: [🍓] In `
|
|
4213
|
-
* TODO: [🍓] In `
|
|
4332
|
+
* TODO: [🍓] In `TextFormatParser` implement simple `isValid`
|
|
4333
|
+
* TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
|
|
4334
|
+
* TODO: [🍓] In `TextFormatParser` implement `heal
|
|
4335
|
+
* TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
|
|
4214
4336
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
4215
4337
|
*/
|
|
4216
4338
|
|
|
@@ -4218,7 +4340,7 @@ const TextFormatDefinition = {
|
|
|
4218
4340
|
* Function to check if a string is valid XML
|
|
4219
4341
|
*
|
|
4220
4342
|
* @param value
|
|
4221
|
-
* @returns
|
|
4343
|
+
* @returns `true` if the string is a valid XML string, false otherwise
|
|
4222
4344
|
*
|
|
4223
4345
|
* @public exported from `@promptbook/utils`
|
|
4224
4346
|
*/
|
|
@@ -4243,7 +4365,7 @@ function isValidXmlString(value) {
|
|
|
4243
4365
|
*
|
|
4244
4366
|
* @private still in development [🏢]
|
|
4245
4367
|
*/
|
|
4246
|
-
const
|
|
4368
|
+
const XmlFormatParser = {
|
|
4247
4369
|
formatName: 'XML',
|
|
4248
4370
|
mimeType: 'application/xml',
|
|
4249
4371
|
isValid(value, settings, schema) {
|
|
@@ -4255,17 +4377,17 @@ const XmlFormatDefinition = {
|
|
|
4255
4377
|
heal(value, settings, schema) {
|
|
4256
4378
|
throw new Error('Not implemented');
|
|
4257
4379
|
},
|
|
4258
|
-
|
|
4380
|
+
subvalueParsers: [],
|
|
4259
4381
|
};
|
|
4260
4382
|
/**
|
|
4261
4383
|
* TODO: [🧠] Maybe propper instance of object
|
|
4262
4384
|
* TODO: [0] Make string_serialized_xml
|
|
4263
4385
|
* TODO: [1] Make type for XML Settings and Schema
|
|
4264
4386
|
* TODO: [🧠] What to use for validating XMLs - XSD,...
|
|
4265
|
-
* TODO: [🍓] In `
|
|
4266
|
-
* TODO: [🍓] In `
|
|
4267
|
-
* TODO: [🍓] In `
|
|
4268
|
-
* TODO: [🍓] In `
|
|
4387
|
+
* TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
|
|
4388
|
+
* TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
|
|
4389
|
+
* TODO: [🍓] In `XmlFormatParser` implement `heal
|
|
4390
|
+
* TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
|
|
4269
4391
|
* TODO: [🏢] Allow to expect something inside XML and other formats
|
|
4270
4392
|
*/
|
|
4271
4393
|
|
|
@@ -4274,24 +4396,19 @@ const XmlFormatDefinition = {
|
|
|
4274
4396
|
*
|
|
4275
4397
|
* @private internal index of `...` <- TODO [🏢]
|
|
4276
4398
|
*/
|
|
4277
|
-
const FORMAT_DEFINITIONS = [
|
|
4278
|
-
JsonFormatDefinition,
|
|
4279
|
-
XmlFormatDefinition,
|
|
4280
|
-
TextFormatDefinition,
|
|
4281
|
-
CsvFormatDefinition,
|
|
4282
|
-
];
|
|
4399
|
+
const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
|
|
4283
4400
|
/**
|
|
4284
4401
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4285
4402
|
*/
|
|
4286
4403
|
|
|
4287
4404
|
/**
|
|
4288
|
-
* Maps available parameters to expected parameters
|
|
4405
|
+
* Maps available parameters to expected parameters for a pipeline task.
|
|
4289
4406
|
*
|
|
4290
4407
|
* The strategy is:
|
|
4291
|
-
* 1)
|
|
4292
|
-
* 2)
|
|
4408
|
+
* 1) First, match parameters by name where both available and expected.
|
|
4409
|
+
* 2) Then, if there are unmatched expected and available parameters, map them by order.
|
|
4293
4410
|
*
|
|
4294
|
-
* @throws {PipelineExecutionError}
|
|
4411
|
+
* @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
|
|
4295
4412
|
* @private within the repository used in `createPipelineExecutor`
|
|
4296
4413
|
*/
|
|
4297
4414
|
function mapAvailableToExpectedParameters(options) {
|
|
@@ -4314,7 +4431,7 @@ function mapAvailableToExpectedParameters(options) {
|
|
|
4314
4431
|
else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) ;
|
|
4315
4432
|
}
|
|
4316
4433
|
if (expectedParameterNames.size === 0) {
|
|
4317
|
-
// Note: [👨👨👧] Now we can freeze `mappedParameters` to prevent
|
|
4434
|
+
// Note: [👨👨👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
|
|
4318
4435
|
Object.freeze(mappedParameters);
|
|
4319
4436
|
return mappedParameters;
|
|
4320
4437
|
}
|
|
@@ -4345,7 +4462,7 @@ function mapAvailableToExpectedParameters(options) {
|
|
|
4345
4462
|
for (let i = 0; i < expectedParameterNames.size; i++) {
|
|
4346
4463
|
mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
|
|
4347
4464
|
}
|
|
4348
|
-
// Note: [👨👨👧] Now we can freeze `mappedParameters` to prevent
|
|
4465
|
+
// Note: [👨👨👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
|
|
4349
4466
|
Object.freeze(mappedParameters);
|
|
4350
4467
|
return mappedParameters;
|
|
4351
4468
|
}
|
|
@@ -4449,7 +4566,7 @@ function extractJsonBlock(markdown) {
|
|
|
4449
4566
|
}
|
|
4450
4567
|
/**
|
|
4451
4568
|
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
4452
|
-
* TODO: [🏢] Make this logic part of `
|
|
4569
|
+
* TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
|
|
4453
4570
|
*/
|
|
4454
4571
|
|
|
4455
4572
|
/**
|
|
@@ -4492,10 +4609,12 @@ function templateParameters(template, parameters) {
|
|
|
4492
4609
|
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
4493
4610
|
}
|
|
4494
4611
|
if (parameters[parameterName] === undefined) {
|
|
4612
|
+
console.log('!!! templateParameters 1', { parameterName, template, parameters });
|
|
4495
4613
|
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
4496
4614
|
}
|
|
4497
4615
|
let parameterValue = parameters[parameterName];
|
|
4498
4616
|
if (parameterValue === undefined) {
|
|
4617
|
+
console.log('!!! templateParameters 2', { parameterName, template, parameters });
|
|
4499
4618
|
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
4500
4619
|
}
|
|
4501
4620
|
parameterValue = valueToString(parameterValue);
|
|
@@ -4651,7 +4770,7 @@ const CountUtils = {
|
|
|
4651
4770
|
PAGES: countPages,
|
|
4652
4771
|
};
|
|
4653
4772
|
/**
|
|
4654
|
-
* TODO: [🧠][🤠] This should be probbably as part of `
|
|
4773
|
+
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatParser`
|
|
4655
4774
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4656
4775
|
*/
|
|
4657
4776
|
|
|
@@ -4679,13 +4798,17 @@ function checkExpectations(expectations, value) {
|
|
|
4679
4798
|
}
|
|
4680
4799
|
/**
|
|
4681
4800
|
* TODO: [💝] Unite object for expecting amount and format
|
|
4682
|
-
* TODO: [🧠][🤠] This should be part of `
|
|
4801
|
+
* TODO: [🧠][🤠] This should be part of `TextFormatParser`
|
|
4683
4802
|
* Note: [💝] and [🤠] are interconnected together
|
|
4684
4803
|
*/
|
|
4685
4804
|
|
|
4686
4805
|
/**
|
|
4687
|
-
*
|
|
4806
|
+
* Executes a pipeline task with multiple attempts, including joker and retry logic. Handles different task types
|
|
4807
|
+
* (prompt, script, dialog, etc.), applies postprocessing, checks expectations, and updates the execution report.
|
|
4808
|
+
* Throws errors if execution fails after all attempts.
|
|
4688
4809
|
*
|
|
4810
|
+
* @param options - The options for execution, including task, parameters, pipeline, and configuration.
|
|
4811
|
+
* @returns The result string of the executed task.
|
|
4689
4812
|
* @private internal utility of `createPipelineExecutor`
|
|
4690
4813
|
*/
|
|
4691
4814
|
async function executeAttempts(options) {
|
|
@@ -4907,7 +5030,7 @@ async function executeAttempts(options) {
|
|
|
4907
5030
|
if (task.format) {
|
|
4908
5031
|
if (task.format === 'JSON') {
|
|
4909
5032
|
if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
|
|
4910
|
-
// TODO: [🏢] Do more universally via `
|
|
5033
|
+
// TODO: [🏢] Do more universally via `FormatParser`
|
|
4911
5034
|
try {
|
|
4912
5035
|
$ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
|
|
4913
5036
|
}
|
|
@@ -5009,12 +5132,16 @@ async function executeAttempts(options) {
|
|
|
5009
5132
|
*/
|
|
5010
5133
|
|
|
5011
5134
|
/**
|
|
5012
|
-
*
|
|
5135
|
+
* Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
|
|
5136
|
+
* Handles format and subformat resolution, error handling, and progress reporting.
|
|
5137
|
+
*
|
|
5138
|
+
* @param options - Options for execution, including task details and progress callback.
|
|
5139
|
+
* @returns The result of the subvalue mapping or execution attempts.
|
|
5013
5140
|
*
|
|
5014
5141
|
* @private internal utility of `createPipelineExecutor`
|
|
5015
5142
|
*/
|
|
5016
5143
|
async function executeFormatSubvalues(options) {
|
|
5017
|
-
const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
|
|
5144
|
+
const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
|
|
5018
5145
|
if (task.foreach === undefined) {
|
|
5019
5146
|
return /* not await */ executeAttempts(options);
|
|
5020
5147
|
}
|
|
@@ -5045,16 +5172,16 @@ async function executeFormatSubvalues(options) {
|
|
|
5045
5172
|
${block(pipelineIdentification)}
|
|
5046
5173
|
`));
|
|
5047
5174
|
}
|
|
5048
|
-
const
|
|
5049
|
-
if (
|
|
5175
|
+
const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(task.foreach.subformatName));
|
|
5176
|
+
if (subvalueParser === undefined) {
|
|
5050
5177
|
throw new UnexpectedError(
|
|
5051
5178
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
5052
5179
|
spaceTrim$1((block) => `
|
|
5053
5180
|
Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
|
|
5054
5181
|
|
|
5055
5182
|
Available subformat names for format "${formatDefinition.formatName}":
|
|
5056
|
-
${block(formatDefinition.
|
|
5057
|
-
.map((
|
|
5183
|
+
${block(formatDefinition.subvalueParsers
|
|
5184
|
+
.map((subvalueParser) => subvalueParser.subvalueName)
|
|
5058
5185
|
.map((subvalueName) => `- ${subvalueName}`)
|
|
5059
5186
|
.join('\n'))}
|
|
5060
5187
|
|
|
@@ -5068,53 +5195,83 @@ async function executeFormatSubvalues(options) {
|
|
|
5068
5195
|
formatSettings = csvSettings;
|
|
5069
5196
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
5070
5197
|
}
|
|
5071
|
-
const resultString = await
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5198
|
+
const resultString = await subvalueParser.mapValues({
|
|
5199
|
+
value: parameterValue,
|
|
5200
|
+
outputParameterName: task.foreach.outputSubparameterName,
|
|
5201
|
+
settings: formatSettings,
|
|
5202
|
+
onProgress(partialResultString) {
|
|
5203
|
+
return onProgress(Object.freeze({
|
|
5204
|
+
[task.resultingParameterName]: partialResultString,
|
|
5205
|
+
}));
|
|
5206
|
+
},
|
|
5207
|
+
async mapCallback(subparameters, index, length) {
|
|
5208
|
+
let mappedParameters;
|
|
5209
|
+
try {
|
|
5210
|
+
mappedParameters = mapAvailableToExpectedParameters({
|
|
5211
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
5212
|
+
availableParameters: subparameters,
|
|
5213
|
+
});
|
|
5084
5214
|
}
|
|
5085
|
-
|
|
5086
|
-
|
|
5215
|
+
catch (error) {
|
|
5216
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
5217
|
+
throw error;
|
|
5218
|
+
}
|
|
5219
|
+
const highLevelError = new PipelineExecutionError(spaceTrim$1((block) => `
|
|
5220
|
+
${error.message}
|
|
5087
5221
|
|
|
5088
|
-
|
|
5089
|
-
|
|
5222
|
+
This is error in FOREACH command when mapping ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
|
|
5223
|
+
You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
|
|
5090
5224
|
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5225
|
+
${block(pipelineIdentification)}
|
|
5226
|
+
`));
|
|
5227
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5228
|
+
console.error(highLevelError);
|
|
5229
|
+
return FAILED_VALUE_PLACEHOLDER;
|
|
5230
|
+
}
|
|
5231
|
+
throw highLevelError;
|
|
5232
|
+
}
|
|
5233
|
+
const allSubparameters = {
|
|
5234
|
+
...parameters,
|
|
5235
|
+
...mappedParameters,
|
|
5236
|
+
};
|
|
5237
|
+
Object.freeze(allSubparameters);
|
|
5238
|
+
try {
|
|
5239
|
+
const subresultString = await executeAttempts({
|
|
5240
|
+
...options,
|
|
5241
|
+
priority: priority + index,
|
|
5242
|
+
parameters: allSubparameters,
|
|
5243
|
+
pipelineIdentification: spaceTrim$1((block) => `
|
|
5244
|
+
${block(pipelineIdentification)}
|
|
5245
|
+
Subparameter index: ${index}
|
|
5246
|
+
`),
|
|
5247
|
+
});
|
|
5248
|
+
return subresultString;
|
|
5249
|
+
}
|
|
5250
|
+
catch (error) {
|
|
5251
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5252
|
+
console.error(spaceTrim$1((block) => `
|
|
5253
|
+
${error.message}
|
|
5254
|
+
|
|
5255
|
+
This is error in FOREACH command when processing ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
|
|
5256
|
+
|
|
5257
|
+
${block(pipelineIdentification)}
|
|
5258
|
+
`));
|
|
5259
|
+
return FAILED_VALUE_PLACEHOLDER;
|
|
5260
|
+
}
|
|
5261
|
+
throw error;
|
|
5262
|
+
}
|
|
5263
|
+
},
|
|
5111
5264
|
});
|
|
5112
5265
|
return resultString;
|
|
5113
5266
|
}
|
|
5114
5267
|
|
|
5115
5268
|
/**
|
|
5116
|
-
*
|
|
5269
|
+
* Returns the context for a given task, typically used to provide additional information or variables
|
|
5270
|
+
* required for the execution of the task within a pipeline. The context is returned as a string value
|
|
5271
|
+
* that may include markdown formatting.
|
|
5117
5272
|
*
|
|
5273
|
+
* @param task - The task for which the context is being generated. This should be a deeply immutable TaskJson object.
|
|
5274
|
+
* @returns The context as a string, formatted as markdown and parameter value.
|
|
5118
5275
|
* @private internal utility of `createPipelineExecutor`
|
|
5119
5276
|
*/
|
|
5120
5277
|
async function getContextForTask(task) {
|
|
@@ -5122,7 +5279,7 @@ async function getContextForTask(task) {
|
|
|
5122
5279
|
}
|
|
5123
5280
|
|
|
5124
5281
|
/**
|
|
5125
|
-
*
|
|
5282
|
+
* Retrieves example values or templates for a given task, used to guide or validate pipeline execution.
|
|
5126
5283
|
*
|
|
5127
5284
|
* @private internal utility of `createPipelineExecutor`
|
|
5128
5285
|
*/
|
|
@@ -5131,25 +5288,127 @@ async function getExamplesForTask(task) {
|
|
|
5131
5288
|
}
|
|
5132
5289
|
|
|
5133
5290
|
/**
|
|
5134
|
-
*
|
|
5291
|
+
* Computes the cosine similarity between two embedding vectors
|
|
5292
|
+
*
|
|
5293
|
+
* Note: This is helping function for RAG (retrieval-augmented generation)
|
|
5294
|
+
*
|
|
5295
|
+
* @param embeddingVector1
|
|
5296
|
+
* @param embeddingVector2
|
|
5297
|
+
* @returns Cosine similarity between the two vectors
|
|
5298
|
+
*
|
|
5299
|
+
* @public exported from `@promptbook/core`
|
|
5300
|
+
*/
|
|
5301
|
+
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
5302
|
+
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
5303
|
+
throw new TypeError('Embedding vectors must have the same length');
|
|
5304
|
+
}
|
|
5305
|
+
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
5306
|
+
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
5307
|
+
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
5308
|
+
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
5309
|
+
}
|
|
5310
|
+
|
|
5311
|
+
/**
|
|
5312
|
+
*
|
|
5313
|
+
* @param knowledgePieces
|
|
5314
|
+
* @returns
|
|
5315
|
+
*
|
|
5316
|
+
* @private internal utility of `createPipelineExecutor`
|
|
5317
|
+
*/
|
|
5318
|
+
function knowledgePiecesToString(knowledgePieces) {
|
|
5319
|
+
return knowledgePieces
|
|
5320
|
+
.map((knowledgePiece) => {
|
|
5321
|
+
const { content } = knowledgePiece;
|
|
5322
|
+
return `- ${content}`;
|
|
5323
|
+
})
|
|
5324
|
+
.join('\n');
|
|
5325
|
+
// <- TODO: [🧠] Some smarter aggregation of knowledge pieces, single-line vs multi-line vs mixed
|
|
5326
|
+
}
|
|
5327
|
+
|
|
5328
|
+
/**
|
|
5329
|
+
* Retrieves the most relevant knowledge pieces for a given task using embedding-based similarity search.
|
|
5330
|
+
* This is where retrieval-augmented generation (RAG) is performed to enhance the task with external knowledge.
|
|
5135
5331
|
*
|
|
5136
5332
|
* @private internal utility of `createPipelineExecutor`
|
|
5137
5333
|
*/
|
|
5138
5334
|
async function getKnowledgeForTask(options) {
|
|
5139
|
-
const { preparedPipeline, task } = options;
|
|
5140
|
-
|
|
5141
|
-
|
|
5335
|
+
const { tools, preparedPipeline, task, parameters } = options;
|
|
5336
|
+
const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
|
|
5337
|
+
const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
|
|
5338
|
+
// <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
|
|
5339
|
+
if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
|
|
5340
|
+
return ''; // <- Note: Np knowledge present, return empty string
|
|
5341
|
+
}
|
|
5342
|
+
try {
|
|
5343
|
+
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
5344
|
+
const _llms = arrayableToArray(tools.llm);
|
|
5345
|
+
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
5346
|
+
const taskEmbeddingPrompt = {
|
|
5347
|
+
title: 'Knowledge Search',
|
|
5348
|
+
modelRequirements: {
|
|
5349
|
+
modelVariant: 'EMBEDDING',
|
|
5350
|
+
modelName: firstKnowlegeIndex.modelName,
|
|
5351
|
+
},
|
|
5352
|
+
content: task.content,
|
|
5353
|
+
parameters,
|
|
5354
|
+
};
|
|
5355
|
+
const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
|
|
5356
|
+
const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
|
|
5357
|
+
const { index } = knowledgePiece;
|
|
5358
|
+
const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
|
|
5359
|
+
// <- TODO: Do not use just first knowledge piece and first index to determine embedding model
|
|
5360
|
+
if (knowledgePieceIndex === undefined) {
|
|
5361
|
+
return {
|
|
5362
|
+
content: knowledgePiece.content,
|
|
5363
|
+
relevance: 0,
|
|
5364
|
+
};
|
|
5365
|
+
}
|
|
5366
|
+
const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
|
|
5367
|
+
return {
|
|
5368
|
+
content: knowledgePiece.content,
|
|
5369
|
+
relevance,
|
|
5370
|
+
};
|
|
5371
|
+
});
|
|
5372
|
+
const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
|
|
5373
|
+
const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
|
|
5374
|
+
console.log('!!! Embedding', {
|
|
5375
|
+
task,
|
|
5376
|
+
taskEmbeddingPrompt,
|
|
5377
|
+
taskEmbeddingResult,
|
|
5378
|
+
firstKnowlegePiece,
|
|
5379
|
+
firstKnowlegeIndex,
|
|
5380
|
+
knowledgePiecesWithRelevance,
|
|
5381
|
+
knowledgePiecesSorted,
|
|
5382
|
+
knowledgePiecesLimited,
|
|
5383
|
+
});
|
|
5384
|
+
return knowledgePiecesToString(knowledgePiecesLimited);
|
|
5385
|
+
}
|
|
5386
|
+
catch (error) {
|
|
5387
|
+
assertsError(error);
|
|
5388
|
+
console.error('Error in `getKnowledgeForTask`', error);
|
|
5389
|
+
// Note: If the LLM fails, just return all knowledge pieces
|
|
5390
|
+
return knowledgePiecesToString(preparedPipeline.knowledgePieces);
|
|
5391
|
+
}
|
|
5142
5392
|
}
|
|
5393
|
+
/**
|
|
5394
|
+
* TODO: !!!! Verify if this is working
|
|
5395
|
+
* TODO: [♨] Implement Better - use keyword search
|
|
5396
|
+
* TODO: [♨] Examples of values
|
|
5397
|
+
*/
|
|
5143
5398
|
|
|
5144
5399
|
/**
|
|
5145
|
-
*
|
|
5400
|
+
* Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
|
|
5401
|
+
* Ensures all reserved parameters are defined and throws if any are missing.
|
|
5402
|
+
*
|
|
5403
|
+
* @param options - Options including tools, pipeline, task, and context.
|
|
5404
|
+
* @returns An object containing all reserved parameters for the task.
|
|
5146
5405
|
*
|
|
5147
5406
|
* @private internal utility of `createPipelineExecutor`
|
|
5148
5407
|
*/
|
|
5149
5408
|
async function getReservedParametersForTask(options) {
|
|
5150
|
-
const { preparedPipeline, task, pipelineIdentification } = options;
|
|
5409
|
+
const { tools, preparedPipeline, task, parameters, pipelineIdentification } = options;
|
|
5151
5410
|
const context = await getContextForTask(); // <- [🏍]
|
|
5152
|
-
const knowledge = await getKnowledgeForTask({ preparedPipeline, task });
|
|
5411
|
+
const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task, parameters });
|
|
5153
5412
|
const examples = await getExamplesForTask();
|
|
5154
5413
|
const currentDate = new Date().toISOString(); // <- TODO: [🧠][💩] Better
|
|
5155
5414
|
const modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
@@ -5175,23 +5434,21 @@ async function getReservedParametersForTask(options) {
|
|
|
5175
5434
|
}
|
|
5176
5435
|
|
|
5177
5436
|
/**
|
|
5178
|
-
*
|
|
5437
|
+
* Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
|
|
5438
|
+
*
|
|
5439
|
+
* @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
|
|
5440
|
+
* @returns The output parameters produced by the task.
|
|
5179
5441
|
*
|
|
5180
5442
|
* @private internal utility of `createPipelineExecutor`
|
|
5181
5443
|
*/
|
|
5182
5444
|
async function executeTask(options) {
|
|
5183
5445
|
const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
|
|
5184
5446
|
const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5185
|
-
await onProgress({
|
|
5186
|
-
outputParameters: {
|
|
5187
|
-
[currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
|
|
5188
|
-
},
|
|
5189
|
-
});
|
|
5190
5447
|
// Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
|
|
5191
5448
|
const usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5192
5449
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
5193
5450
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
5194
|
-
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
5451
|
+
if (difference(union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)), new Set(RESERVED_PARAMETER_NAMES)).size !== 0) {
|
|
5195
5452
|
throw new UnexpectedError(spaceTrim((block) => `
|
|
5196
5453
|
Dependent parameters are not consistent with used parameters:
|
|
5197
5454
|
|
|
@@ -5211,9 +5468,11 @@ async function executeTask(options) {
|
|
|
5211
5468
|
}
|
|
5212
5469
|
const definedParameters = Object.freeze({
|
|
5213
5470
|
...(await getReservedParametersForTask({
|
|
5471
|
+
tools,
|
|
5214
5472
|
preparedPipeline,
|
|
5215
5473
|
task: currentTask,
|
|
5216
5474
|
pipelineIdentification,
|
|
5475
|
+
parameters: parametersToPass,
|
|
5217
5476
|
})),
|
|
5218
5477
|
...parametersToPass,
|
|
5219
5478
|
});
|
|
@@ -5259,6 +5518,7 @@ async function executeTask(options) {
|
|
|
5259
5518
|
preparedPipeline,
|
|
5260
5519
|
tools,
|
|
5261
5520
|
$executionReport,
|
|
5521
|
+
onProgress,
|
|
5262
5522
|
pipelineIdentification,
|
|
5263
5523
|
maxExecutionAttempts,
|
|
5264
5524
|
maxParallelCount,
|
|
@@ -5286,7 +5546,8 @@ async function executeTask(options) {
|
|
|
5286
5546
|
*/
|
|
5287
5547
|
|
|
5288
5548
|
/**
|
|
5289
|
-
*
|
|
5549
|
+
* Filters and returns only the output parameters from the provided pipeline execution options.
|
|
5550
|
+
* Adds warnings for any expected output parameters that are missing.
|
|
5290
5551
|
*
|
|
5291
5552
|
* @private internal utility of `createPipelineExecutor`
|
|
5292
5553
|
*/
|
|
@@ -5311,9 +5572,12 @@ function filterJustOutputParameters(options) {
|
|
|
5311
5572
|
}
|
|
5312
5573
|
|
|
5313
5574
|
/**
|
|
5314
|
-
*
|
|
5575
|
+
* Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
|
|
5315
5576
|
*
|
|
5316
|
-
* Note: This is not a `PipelineExecutor` (which is
|
|
5577
|
+
* Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
|
|
5578
|
+
*
|
|
5579
|
+
* @param options - Options for execution, including input parameters, pipeline, and callbacks.
|
|
5580
|
+
* @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
|
|
5317
5581
|
*
|
|
5318
5582
|
* @private internal utility of `createPipelineExecutor`
|
|
5319
5583
|
*/
|
|
@@ -5636,6 +5900,22 @@ function createPipelineExecutor(options) {
|
|
|
5636
5900
|
cacheDirname,
|
|
5637
5901
|
intermediateFilesStrategy,
|
|
5638
5902
|
isAutoInstalled,
|
|
5903
|
+
}).catch((error) => {
|
|
5904
|
+
assertsError(error);
|
|
5905
|
+
return exportJson({
|
|
5906
|
+
name: 'pipelineExecutorResult',
|
|
5907
|
+
message: `Unuccessful PipelineExecutorResult, last catch`,
|
|
5908
|
+
order: [],
|
|
5909
|
+
value: {
|
|
5910
|
+
isSuccessful: false,
|
|
5911
|
+
errors: [serializeError(error)],
|
|
5912
|
+
warnings: [],
|
|
5913
|
+
usage: UNCERTAIN_USAGE,
|
|
5914
|
+
executionReport: null,
|
|
5915
|
+
outputParameters: {},
|
|
5916
|
+
preparedPipeline,
|
|
5917
|
+
},
|
|
5918
|
+
});
|
|
5639
5919
|
});
|
|
5640
5920
|
};
|
|
5641
5921
|
const pipelineExecutor = (inputParameters) => createTask({
|
|
@@ -5937,7 +6217,8 @@ class WebsiteScraper {
|
|
|
5937
6217
|
*/
|
|
5938
6218
|
|
|
5939
6219
|
/**
|
|
5940
|
-
*
|
|
6220
|
+
* Factory function to create an instance of WebsiteScraper.
|
|
6221
|
+
* It bundles the scraper class with its metadata.
|
|
5941
6222
|
*
|
|
5942
6223
|
* @public exported from `@promptbook/website-crawler`
|
|
5943
6224
|
*/
|