@promptbook/legacy-documents 0.72.0-9 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -252
- package/esm/index.es.js +186 -170
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +24 -18
- package/esm/typings/src/_packages/node.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +18 -12
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +2 -2
- package/esm/typings/src/collection/collectionToJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -1
- package/esm/typings/src/commands/TEMPLATE/TemplateTypes.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +5 -5
- package/esm/typings/src/config.d.ts +22 -15
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +2 -2
- package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +12 -0
- package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +11 -0
- package/esm/typings/src/executables/apps/locatePandoc.d.ts +11 -0
- package/esm/typings/src/executables/locateApp.d.ts +33 -0
- package/esm/typings/src/executables/locateApp.test.d.ts +1 -0
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +12 -0
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +12 -0
- package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +12 -0
- package/esm/typings/src/execution/EmbeddingVector.d.ts +1 -1
- package/esm/typings/src/execution/Executables.d.ts +18 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +9 -3
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +2 -2
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -2
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +29 -6
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -11
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +4 -13
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +9 -14
- package/esm/typings/src/execution/createPipelineExecutor/{getSamplesForTemplate.d.ts → getExamplesForTemplate.d.ts} +1 -1
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -3
- package/esm/typings/src/execution/utils/addUsage.d.ts +1 -1
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +4 -4
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForCli.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +7 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +4 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -2
- 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 +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +4 -5
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +0 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +4 -4
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +15 -6
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Response.d.ts +4 -4
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +6 -12
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Response.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +9 -14
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +23 -8
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +4 -23
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +2 -2
- package/esm/typings/src/prepare/prepareTemplates.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +2 -9
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
- package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +2 -2
- package/esm/typings/src/scrapers/document/DocumentScraper.test.d.ts +1 -1
- package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +3 -3
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.test.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.test.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +2 -2
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +6 -3
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/website/utils/createShowdownConverter.d.ts +7 -0
- package/esm/typings/src/scrapers/website/utils/createShowdownConverter.test.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +1 -1
- package/esm/typings/src/types/Arrayable.d.ts +1 -1
- package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +7 -0
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +4 -4
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/Prompt.d.ts +2 -1
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +11 -8
- package/esm/typings/src/utils/$Register.d.ts +1 -1
- package/esm/typings/src/utils/FromtoItems.d.ts +1 -1
- package/esm/typings/src/utils/arrayableToArray.d.ts +1 -1
- package/esm/typings/src/utils/emojis.d.ts +1 -1
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +4 -2
- package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +12 -0
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +1 -0
- package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +45 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/esm/typings/src/utils/files/isExecutable.d.ts +11 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +1 -1
- package/esm/typings/src/utils/normalization/IKeywords.d.ts +2 -2
- package/esm/typings/src/utils/normalization/parseKeywords.d.ts +2 -2
- package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +2 -2
- package/esm/typings/src/utils/normalization/searchKeywords.d.ts +2 -2
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
- package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
- package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
- package/esm/typings/src/utils/sets/intersection.d.ts +1 -1
- package/esm/typings/src/utils/sets/union.d.ts +1 -1
- package/esm/typings/src/utils/unwrapResult.d.ts +4 -4
- package/package.json +6 -4
- package/umd/index.umd.js +186 -170
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +0 -29
- package/esm/typings/src/scrapers/website/utils/markdownConverter.d.ts +0 -12
- package/esm/typings/src/utils/execCommand/IExecCommandOptions.d.ts +0 -23
- package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.d.ts +0 -10
- /package/esm/typings/src/{scrapers/website/WebsiteScraper.test.d.ts → executables/apps/locateLibreoffice.test.d.ts} +0 -0
- /package/esm/typings/src/{scrapers/website/utils/markdownConverter.test.d.ts → executables/apps/locatePandoc.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
/**
|
|
16
16
|
* The version of the Promptbook library
|
|
17
17
|
*/
|
|
18
|
-
var PROMPTBOOK_VERSION = '0.72.0
|
|
18
|
+
var PROMPTBOOK_VERSION = '0.72.0';
|
|
19
19
|
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
20
20
|
|
|
21
21
|
/*! *****************************************************************************
|
|
@@ -363,18 +363,25 @@
|
|
|
363
363
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
364
364
|
*/
|
|
365
365
|
var IMMEDIATE_TIME = 10;
|
|
366
|
+
/**
|
|
367
|
+
* Strategy for caching the intermediate results for knowledge sources
|
|
368
|
+
*
|
|
369
|
+
* @public exported from `@promptbook/core`
|
|
370
|
+
*/
|
|
371
|
+
var DEFAULT_INTERMEDIATE_FILES_STRATEGY = 'HIDE_AND_KEEP';
|
|
372
|
+
// <- TODO: [😡] Change to 'VISIBLE'
|
|
366
373
|
/**
|
|
367
374
|
* The maximum number of (LLM) tasks running in parallel
|
|
368
375
|
*
|
|
369
376
|
* @public exported from `@promptbook/core`
|
|
370
377
|
*/
|
|
371
|
-
var
|
|
378
|
+
var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
372
379
|
/**
|
|
373
380
|
* The maximum number of attempts to execute LLM task before giving up
|
|
374
381
|
*
|
|
375
382
|
* @public exported from `@promptbook/core`
|
|
376
383
|
*/
|
|
377
|
-
var
|
|
384
|
+
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
378
385
|
/**
|
|
379
386
|
* Where to store the scrape cache
|
|
380
387
|
*
|
|
@@ -382,7 +389,7 @@
|
|
|
382
389
|
*
|
|
383
390
|
* @public exported from `@promptbook/core`
|
|
384
391
|
*/
|
|
385
|
-
var
|
|
392
|
+
var DEFAULT_SCRAPE_CACHE_DIRNAME = '/.promptbook/scrape-cache';
|
|
386
393
|
/**
|
|
387
394
|
* Nonce which is used for replacing things in strings
|
|
388
395
|
*
|
|
@@ -398,10 +405,10 @@
|
|
|
398
405
|
'content',
|
|
399
406
|
'context',
|
|
400
407
|
'knowledge',
|
|
401
|
-
'
|
|
408
|
+
'examples',
|
|
402
409
|
'modelName',
|
|
403
410
|
'currentDate',
|
|
404
|
-
// <- TODO:
|
|
411
|
+
// <- TODO: list here all command names
|
|
405
412
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
406
413
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
407
414
|
]);
|
|
@@ -434,7 +441,7 @@
|
|
|
434
441
|
*
|
|
435
442
|
* @public exported from `@promptbook/core`
|
|
436
443
|
*/
|
|
437
|
-
var
|
|
444
|
+
var DEFAULT_IS_VERBOSE = false;
|
|
438
445
|
/**
|
|
439
446
|
* @@@
|
|
440
447
|
*
|
|
@@ -508,22 +515,26 @@
|
|
|
508
515
|
/**
|
|
509
516
|
* Normalize options for `execCommand` and `execCommands`
|
|
510
517
|
*
|
|
518
|
+
* Note: `$` is used to indicate that this function behaves differently according to `process.platform`
|
|
519
|
+
*
|
|
511
520
|
* @private internal utility of `execCommand` and `execCommands`
|
|
512
521
|
*/
|
|
513
|
-
function execCommandNormalizeOptions(options) {
|
|
522
|
+
function $execCommandNormalizeOptions(options) {
|
|
514
523
|
var _a;
|
|
515
|
-
var _b, _c, _d;
|
|
524
|
+
var _b, _c, _d, _e;
|
|
516
525
|
var command;
|
|
517
526
|
var cwd;
|
|
518
527
|
var crashOnError;
|
|
519
528
|
var args = [];
|
|
520
529
|
var timeout;
|
|
530
|
+
var isVerbose;
|
|
521
531
|
if (typeof options === 'string') {
|
|
522
532
|
// TODO: [1] DRY default values
|
|
523
533
|
command = options;
|
|
524
534
|
cwd = process.cwd();
|
|
525
535
|
crashOnError = true;
|
|
526
|
-
timeout = Infinity;
|
|
536
|
+
timeout = Infinity; // <- TODO: [⏳]
|
|
537
|
+
isVerbose = DEFAULT_IS_VERBOSE;
|
|
527
538
|
}
|
|
528
539
|
else {
|
|
529
540
|
/*
|
|
@@ -539,6 +550,7 @@
|
|
|
539
550
|
cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
540
551
|
crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
|
|
541
552
|
timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
|
|
553
|
+
isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
|
|
542
554
|
}
|
|
543
555
|
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
544
556
|
var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
@@ -560,16 +572,21 @@
|
|
|
560
572
|
if (['ts-node'].includes(humanReadableCommand)) {
|
|
561
573
|
humanReadableCommand += " ".concat(args[1]);
|
|
562
574
|
}
|
|
563
|
-
|
|
575
|
+
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
576
|
+
command = "".concat(command, ".cmd");
|
|
577
|
+
}
|
|
578
|
+
return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
|
|
564
579
|
}
|
|
565
580
|
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
566
581
|
|
|
567
582
|
/**
|
|
568
583
|
* Run one command in a shell
|
|
569
584
|
*
|
|
585
|
+
*
|
|
570
586
|
* Note: There are 2 similar functions in the codebase:
|
|
571
587
|
* - `$execCommand` which runs a single command
|
|
572
588
|
* - `$execCommands` which runs multiple commands
|
|
589
|
+
* Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
|
|
573
590
|
*
|
|
574
591
|
* @public exported from `@promptbook/node`
|
|
575
592
|
*/
|
|
@@ -579,7 +596,7 @@
|
|
|
579
596
|
}
|
|
580
597
|
return new Promise(function (resolve, reject) {
|
|
581
598
|
// eslint-disable-next-line prefer-const
|
|
582
|
-
var _a = execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout;
|
|
599
|
+
var _a = $execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout, _b = _a.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
583
600
|
if (timeout !== Infinity) {
|
|
584
601
|
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
585
602
|
waitasecond.forTime(timeout).then(function () {
|
|
@@ -592,24 +609,26 @@
|
|
|
592
609
|
}
|
|
593
610
|
});
|
|
594
611
|
}
|
|
595
|
-
if (
|
|
596
|
-
|
|
612
|
+
if (isVerbose) {
|
|
613
|
+
console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
|
|
597
614
|
}
|
|
598
|
-
// !!!!!! Verbose mode - to all consoles
|
|
599
|
-
console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
|
|
600
615
|
try {
|
|
601
616
|
var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
617
|
+
if (isVerbose) {
|
|
618
|
+
commandProcess.on('message', function (message) {
|
|
619
|
+
console.info({ message: message });
|
|
620
|
+
});
|
|
621
|
+
}
|
|
605
622
|
var output_1 = [];
|
|
606
623
|
commandProcess.stdout.on('data', function (stdout) {
|
|
607
624
|
output_1.push(stdout.toString());
|
|
608
|
-
|
|
625
|
+
if (isVerbose) {
|
|
626
|
+
console.info(stdout.toString());
|
|
627
|
+
}
|
|
609
628
|
});
|
|
610
629
|
commandProcess.stderr.on('data', function (stderr) {
|
|
611
630
|
output_1.push(stderr.toString());
|
|
612
|
-
if (stderr.toString().trim()) {
|
|
631
|
+
if (isVerbose && stderr.toString().trim()) {
|
|
613
632
|
console.warn(stderr.toString());
|
|
614
633
|
}
|
|
615
634
|
});
|
|
@@ -620,7 +639,9 @@
|
|
|
620
639
|
"Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
|
|
621
640
|
}
|
|
622
641
|
else {
|
|
623
|
-
|
|
642
|
+
if (isVerbose) {
|
|
643
|
+
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
644
|
+
}
|
|
624
645
|
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
625
646
|
}
|
|
626
647
|
}
|
|
@@ -639,7 +660,9 @@
|
|
|
639
660
|
reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
|
|
640
661
|
}
|
|
641
662
|
else {
|
|
642
|
-
|
|
663
|
+
if (isVerbose) {
|
|
664
|
+
console.warn(error);
|
|
665
|
+
}
|
|
643
666
|
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
644
667
|
}
|
|
645
668
|
});
|
|
@@ -1150,12 +1173,12 @@
|
|
|
1150
1173
|
*/
|
|
1151
1174
|
function getScraperIntermediateSource(source, options) {
|
|
1152
1175
|
return __awaiter(this, void 0, void 0, function () {
|
|
1153
|
-
var sourceFilename, url, rootDirname, cacheDirname,
|
|
1176
|
+
var sourceFilename, url, rootDirname, cacheDirname, intermediateFilesStrategy, extension, isVerbose, hash, semanticName, pieces, name, cacheFilename, isDestroyed, fileHandler;
|
|
1154
1177
|
return __generator(this, function (_a) {
|
|
1155
1178
|
switch (_a.label) {
|
|
1156
1179
|
case 0:
|
|
1157
1180
|
sourceFilename = source.filename, url = source.url;
|
|
1158
|
-
rootDirname = options.rootDirname, cacheDirname = options.cacheDirname,
|
|
1181
|
+
rootDirname = options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, extension = options.extension, isVerbose = options.isVerbose;
|
|
1159
1182
|
hash = cryptoJs.SHA256(
|
|
1160
1183
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
1161
1184
|
hexEncoder__default["default"].parse(sourceFilename || url || 'untitled'))
|
|
@@ -1165,7 +1188,7 @@
|
|
|
1165
1188
|
pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
|
|
1166
1189
|
name = pieces.join('-').split('--').join('-');
|
|
1167
1190
|
// <- TODO: Use MAX_FILENAME_LENGTH
|
|
1168
|
-
TODO_USE(rootDirname); // <- TODO:
|
|
1191
|
+
TODO_USE(rootDirname); // <- TODO: [😡]
|
|
1169
1192
|
cacheFilename = path.join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
|
|
1170
1193
|
cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
|
|
1171
1194
|
.join('/') +
|
|
@@ -1185,7 +1208,7 @@
|
|
|
1185
1208
|
return __generator(this, function (_a) {
|
|
1186
1209
|
switch (_a.label) {
|
|
1187
1210
|
case 0:
|
|
1188
|
-
if (!
|
|
1211
|
+
if (!(intermediateFilesStrategy === 'HIDE_AND_CLEAN')) return [3 /*break*/, 2];
|
|
1189
1212
|
if (isVerbose) {
|
|
1190
1213
|
console.info('legacyDocumentScraper: Clening cache');
|
|
1191
1214
|
}
|
|
@@ -1209,12 +1232,12 @@
|
|
|
1209
1232
|
/**
|
|
1210
1233
|
* Note: Not using `FileCacheStorage` for two reasons:
|
|
1211
1234
|
* 1) Need to store more than serialized JSONs
|
|
1212
|
-
* 2) Need to switch between a `rootDirname` and `cacheDirname` <- TODO:
|
|
1235
|
+
* 2) Need to switch between a `rootDirname` and `cacheDirname` <- TODO: [😡]
|
|
1213
1236
|
* TODO: [🐱🐉][🧠] Make some smart crop
|
|
1214
1237
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
1215
1238
|
*/
|
|
1216
1239
|
|
|
1217
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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- Title should be concise and clear\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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",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}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n##
|
|
1240
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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- Title should be concise and clear\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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",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}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1218
1241
|
|
|
1219
1242
|
/**
|
|
1220
1243
|
* Prettify the html code
|
|
@@ -1274,7 +1297,6 @@
|
|
|
1274
1297
|
pipelineString += '\n\n';
|
|
1275
1298
|
pipelineString += description;
|
|
1276
1299
|
}
|
|
1277
|
-
// TODO:> const commands: Array<Command>
|
|
1278
1300
|
var commands = [];
|
|
1279
1301
|
if (pipelineUrl) {
|
|
1280
1302
|
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
@@ -1330,7 +1352,6 @@
|
|
|
1330
1352
|
pipelineString += '\n\n';
|
|
1331
1353
|
pipelineString += description_1;
|
|
1332
1354
|
}
|
|
1333
|
-
// TODO:> const commands: Array<Command>
|
|
1334
1355
|
var commands_1 = [];
|
|
1335
1356
|
var contentLanguage = 'text';
|
|
1336
1357
|
if (templateType === 'PROMPT_TEMPLATE') {
|
|
@@ -1860,7 +1881,7 @@
|
|
|
1860
1881
|
}
|
|
1861
1882
|
}
|
|
1862
1883
|
/**
|
|
1863
|
-
* TODO:
|
|
1884
|
+
* TODO: !! [🧞♀️] Do not allow joker + foreach
|
|
1864
1885
|
* TODO: [🧠] Work with promptbookVersion
|
|
1865
1886
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
1866
1887
|
* > /**
|
|
@@ -1872,7 +1893,7 @@
|
|
|
1872
1893
|
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
1873
1894
|
*/
|
|
1874
1895
|
/**
|
|
1875
|
-
* TODO: [🧳][main] !!!! Validate that all
|
|
1896
|
+
* TODO: [🧳][main] !!!! Validate that all examples match expectations
|
|
1876
1897
|
* TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
|
|
1877
1898
|
* TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
|
|
1878
1899
|
* TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
@@ -2215,6 +2236,7 @@
|
|
|
2215
2236
|
}
|
|
2216
2237
|
}
|
|
2217
2238
|
/**
|
|
2239
|
+
* TODO: [🐚] This function should be removed OR changed OR be completely rewritten
|
|
2218
2240
|
* TODO: [🧠] Can this return type be better typed than void
|
|
2219
2241
|
*/
|
|
2220
2242
|
|
|
@@ -2241,12 +2263,12 @@
|
|
|
2241
2263
|
return true;
|
|
2242
2264
|
}
|
|
2243
2265
|
/**
|
|
2244
|
-
* TODO: [🔃][main]
|
|
2266
|
+
* TODO: [🔃][main] !! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2245
2267
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2246
2268
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2247
2269
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2248
2270
|
* - [🏍] ? Is context in each template
|
|
2249
|
-
* - [♨] Are
|
|
2271
|
+
* - [♨] Are examples prepared
|
|
2250
2272
|
* - [♨] Are templates prepared
|
|
2251
2273
|
*/
|
|
2252
2274
|
|
|
@@ -2400,8 +2422,7 @@
|
|
|
2400
2422
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2401
2423
|
*
|
|
2402
2424
|
* Note: Internal utility of `joinLlmExecutionTools` but exposed type
|
|
2403
|
-
* @public exported from `@promptbook/
|
|
2404
|
-
* TODO: !!!!!! Export as runtime class not just type
|
|
2425
|
+
* @public exported from `@promptbook/core`
|
|
2405
2426
|
*/
|
|
2406
2427
|
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
2407
2428
|
/**
|
|
@@ -2903,7 +2924,7 @@
|
|
|
2903
2924
|
return __generator(this, function (_d) {
|
|
2904
2925
|
switch (_d.label) {
|
|
2905
2926
|
case 0:
|
|
2906
|
-
_a = options.isVerbose, isVerbose = _a === void 0 ?
|
|
2927
|
+
_a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
|
|
2907
2928
|
if (tools === undefined || tools.llm === undefined) {
|
|
2908
2929
|
throw new MissingToolsError('LLM tools are required for preparing persona');
|
|
2909
2930
|
}
|
|
@@ -2952,7 +2973,7 @@
|
|
|
2952
2973
|
});
|
|
2953
2974
|
}
|
|
2954
2975
|
/**
|
|
2955
|
-
* TODO: [🔃][main]
|
|
2976
|
+
* TODO: [🔃][main] !! If the persona was prepared with different version or different set of models, prepare it once again
|
|
2956
2977
|
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
2957
2978
|
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
2958
2979
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
@@ -3069,7 +3090,7 @@
|
|
|
3069
3090
|
this.storage = globalScope[storageName];
|
|
3070
3091
|
}
|
|
3071
3092
|
$Register.prototype.list = function () {
|
|
3072
|
-
// <- TODO: ReadonlyDeep<
|
|
3093
|
+
// <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
|
|
3073
3094
|
return this.storage;
|
|
3074
3095
|
};
|
|
3075
3096
|
$Register.prototype.register = function (registered) {
|
|
@@ -3121,7 +3142,6 @@
|
|
|
3121
3142
|
* TODO: [®] DRY Register logic
|
|
3122
3143
|
*/
|
|
3123
3144
|
|
|
3124
|
-
// TODO: !!!!!! Maybe delete this function
|
|
3125
3145
|
/**
|
|
3126
3146
|
* Creates a message with all registered scrapers
|
|
3127
3147
|
*
|
|
@@ -3229,7 +3249,6 @@
|
|
|
3229
3249
|
* @private within the repository
|
|
3230
3250
|
*/
|
|
3231
3251
|
function sourceContentToName(sourceContent) {
|
|
3232
|
-
// TODO: !!!!!! Better name for source than gibberish hash
|
|
3233
3252
|
var hash = cryptoJs.SHA256(hexEncoder__default["default"].parse(JSON.stringify(sourceContent)))
|
|
3234
3253
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
3235
3254
|
.toString( /* hex */)
|
|
@@ -3257,20 +3276,20 @@
|
|
|
3257
3276
|
/**
|
|
3258
3277
|
* @@@
|
|
3259
3278
|
*
|
|
3260
|
-
* @
|
|
3279
|
+
* @public exported from `@promptbook/core`
|
|
3261
3280
|
*/
|
|
3262
3281
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3263
3282
|
var _a;
|
|
3264
3283
|
return __awaiter(this, void 0, void 0, function () {
|
|
3265
3284
|
var sourceContent, name, _b, _c, rootDirname, _d,
|
|
3266
3285
|
// <- TODO: process.cwd() if running in Node.js
|
|
3267
|
-
isVerbose, url, response_1, mimeType, filename_1, fileExtension,
|
|
3286
|
+
isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3268
3287
|
return __generator(this, function (_e) {
|
|
3269
3288
|
switch (_e.label) {
|
|
3270
3289
|
case 0:
|
|
3271
3290
|
sourceContent = knowledgeSource.sourceContent;
|
|
3272
3291
|
name = knowledgeSource.name;
|
|
3273
|
-
_b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _d = _b.isVerbose, isVerbose = _d === void 0 ?
|
|
3292
|
+
_b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _d = _b.isVerbose, isVerbose = _d === void 0 ? DEFAULT_IS_VERBOSE : _d;
|
|
3274
3293
|
TODO_USE(isVerbose);
|
|
3275
3294
|
if (!name) {
|
|
3276
3295
|
name = sourceContentToName(sourceContent);
|
|
@@ -3286,19 +3305,14 @@
|
|
|
3286
3305
|
filename: null,
|
|
3287
3306
|
url: url,
|
|
3288
3307
|
mimeType: mimeType,
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
return [2 /*return*/, content];
|
|
3298
|
-
}
|
|
3299
|
-
});
|
|
3300
|
-
});
|
|
3301
|
-
},
|
|
3308
|
+
/*
|
|
3309
|
+
TODO: [🥽]
|
|
3310
|
+
> async asBlob() {
|
|
3311
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3312
|
+
> const content = await response.blob();
|
|
3313
|
+
> return content;
|
|
3314
|
+
> },
|
|
3315
|
+
*/
|
|
3302
3316
|
asJson: function () {
|
|
3303
3317
|
return __awaiter(this, void 0, void 0, function () {
|
|
3304
3318
|
var content;
|
|
@@ -3338,34 +3352,31 @@
|
|
|
3338
3352
|
}
|
|
3339
3353
|
filename_1 = path.join(rootDirname, sourceContent).split('\\').join('/');
|
|
3340
3354
|
fileExtension = getFileExtension(filename_1);
|
|
3341
|
-
|
|
3355
|
+
mimeType = extensionToMimeType(fileExtension || '');
|
|
3342
3356
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3343
3357
|
case 3:
|
|
3344
3358
|
if (!(_e.sent())) {
|
|
3345
3359
|
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
3346
3360
|
}
|
|
3347
|
-
// TODO:
|
|
3361
|
+
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
3348
3362
|
return [2 /*return*/, {
|
|
3349
3363
|
source: name,
|
|
3350
3364
|
filename: filename_1,
|
|
3351
3365
|
url: null,
|
|
3352
|
-
mimeType:
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
});
|
|
3367
|
-
});
|
|
3368
|
-
},
|
|
3366
|
+
mimeType: mimeType,
|
|
3367
|
+
/*
|
|
3368
|
+
TODO: [🥽]
|
|
3369
|
+
> async asBlob() {
|
|
3370
|
+
> const content = await tools.fs!.readFile(filename);
|
|
3371
|
+
> return new Blob(
|
|
3372
|
+
> [
|
|
3373
|
+
> content,
|
|
3374
|
+
> // <- TODO: [🥽] This is NOT tested, test it
|
|
3375
|
+
> ],
|
|
3376
|
+
> { type: mimeType },
|
|
3377
|
+
> );
|
|
3378
|
+
> },
|
|
3379
|
+
*/
|
|
3369
3380
|
asJson: function () {
|
|
3370
3381
|
return __awaiter(this, void 0, void 0, function () {
|
|
3371
3382
|
var _a, _b;
|
|
@@ -3401,9 +3412,14 @@
|
|
|
3401
3412
|
asJson: function () {
|
|
3402
3413
|
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
|
|
3403
3414
|
},
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3415
|
+
/*
|
|
3416
|
+
TODO: [🥽]
|
|
3417
|
+
> asBlob() {
|
|
3418
|
+
> throw new UnexpectedError(
|
|
3419
|
+
> 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
|
|
3420
|
+
> );
|
|
3421
|
+
> },
|
|
3422
|
+
*/
|
|
3407
3423
|
}];
|
|
3408
3424
|
}
|
|
3409
3425
|
});
|
|
@@ -3423,7 +3439,7 @@
|
|
|
3423
3439
|
return __generator(this, function (_c) {
|
|
3424
3440
|
switch (_c.label) {
|
|
3425
3441
|
case 0:
|
|
3426
|
-
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ?
|
|
3442
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, rootDirname = options.rootDirname, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
3427
3443
|
knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3428
3444
|
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3429
3445
|
var partialPieces, sourceHandler, _a, _b, scraper, partialPiecesUnchecked, e_1_1, pieces;
|
|
@@ -3452,7 +3468,8 @@
|
|
|
3452
3468
|
case 4:
|
|
3453
3469
|
partialPiecesUnchecked = _d.sent();
|
|
3454
3470
|
if (partialPiecesUnchecked !== null) {
|
|
3455
|
-
partialPieces = partialPiecesUnchecked;
|
|
3471
|
+
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
3472
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3456
3473
|
return [3 /*break*/, 6];
|
|
3457
3474
|
}
|
|
3458
3475
|
_d.label = 5;
|
|
@@ -3500,7 +3517,7 @@
|
|
|
3500
3517
|
> /**
|
|
3501
3518
|
> * Unprepared knowledge
|
|
3502
3519
|
> * /
|
|
3503
|
-
> readonly knowledgeSources:
|
|
3520
|
+
> readonly knowledgeSources: ReadonlyArray<KnowledgeSourceJson>;
|
|
3504
3521
|
> };
|
|
3505
3522
|
>
|
|
3506
3523
|
> export async function prepareKnowledgePieces(
|
|
@@ -3558,9 +3575,9 @@
|
|
|
3558
3575
|
return __generator(this, function (_b) {
|
|
3559
3576
|
switch (_b.label) {
|
|
3560
3577
|
case 0:
|
|
3561
|
-
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ?
|
|
3578
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
|
|
3562
3579
|
templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3563
|
-
// TODO: [main]
|
|
3580
|
+
// TODO: [main] !! Apply examples to each template (if missing and is for the template defined)
|
|
3564
3581
|
TODO_USE(parameters);
|
|
3565
3582
|
templatesPrepared = new Array(templates.length);
|
|
3566
3583
|
return [4 /*yield*/, forEachAsync(templates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -3590,7 +3607,7 @@
|
|
|
3590
3607
|
/**
|
|
3591
3608
|
* TODO: [🧠] Add context to each template (if missing)
|
|
3592
3609
|
* TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
3593
|
-
* TODO: [♨][main] !!! Prepare index the
|
|
3610
|
+
* TODO: [♨][main] !!! Prepare index the examples and maybe templates
|
|
3594
3611
|
* TODO: Write tests for `preparePipeline`
|
|
3595
3612
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3596
3613
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3620,7 +3637,7 @@
|
|
|
3620
3637
|
if (isPipelinePrepared(pipeline)) {
|
|
3621
3638
|
return [2 /*return*/, pipeline];
|
|
3622
3639
|
}
|
|
3623
|
-
rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ?
|
|
3640
|
+
rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
3624
3641
|
parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3625
3642
|
if (tools === undefined || tools.llm === undefined) {
|
|
3626
3643
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
@@ -3678,7 +3695,9 @@
|
|
|
3678
3695
|
// ----- /Templates preparation -----
|
|
3679
3696
|
// Note: Count total usage
|
|
3680
3697
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
3681
|
-
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates:
|
|
3698
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates: __spreadArray([], __read(templatesPrepared), false),
|
|
3699
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just ` templates: templatesPrepared`
|
|
3700
|
+
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }))];
|
|
3682
3701
|
}
|
|
3683
3702
|
});
|
|
3684
3703
|
});
|
|
@@ -4649,12 +4668,11 @@
|
|
|
4649
4668
|
*/
|
|
4650
4669
|
function executeAttempts(options) {
|
|
4651
4670
|
return __awaiter(this, void 0, void 0, function () {
|
|
4652
|
-
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools,
|
|
4671
|
+
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTemplateResult, _llms, llmTools, _loop_1, attempt, state_1;
|
|
4653
4672
|
return __generator(this, function (_a) {
|
|
4654
4673
|
switch (_a.label) {
|
|
4655
4674
|
case 0:
|
|
4656
|
-
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools,
|
|
4657
|
-
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
4675
|
+
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, maxExecutionAttempts = options.maxExecutionAttempts;
|
|
4658
4676
|
$ongoingTemplateResult = {
|
|
4659
4677
|
$result: null,
|
|
4660
4678
|
$resultString: null,
|
|
@@ -5020,12 +5038,12 @@
|
|
|
5020
5038
|
*/
|
|
5021
5039
|
function executeFormatSubvalues(options) {
|
|
5022
5040
|
return __awaiter(this, void 0, void 0, function () {
|
|
5023
|
-
var template, jokerParameterNames, parameters, priority,
|
|
5041
|
+
var template, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
|
|
5024
5042
|
var _this = this;
|
|
5025
5043
|
return __generator(this, function (_a) {
|
|
5026
5044
|
switch (_a.label) {
|
|
5027
5045
|
case 0:
|
|
5028
|
-
template = options.template, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority,
|
|
5046
|
+
template = options.template, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, csvSettings = options.csvSettings, pipelineIdentification = options.pipelineIdentification;
|
|
5029
5047
|
if (template.foreach === undefined) {
|
|
5030
5048
|
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
5031
5049
|
}
|
|
@@ -5055,7 +5073,7 @@
|
|
|
5055
5073
|
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
5056
5074
|
}
|
|
5057
5075
|
if (formatDefinition.formatName === 'CSV') {
|
|
5058
|
-
formatSettings =
|
|
5076
|
+
formatSettings = csvSettings;
|
|
5059
5077
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
5060
5078
|
}
|
|
5061
5079
|
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -5119,7 +5137,7 @@
|
|
|
5119
5137
|
var preparedPipeline, template;
|
|
5120
5138
|
return __generator(this, function (_a) {
|
|
5121
5139
|
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
5122
|
-
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {
|
|
5140
|
+
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {examples}
|
|
5123
5141
|
TODO_USE(template);
|
|
5124
5142
|
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
5125
5143
|
var content = _a.content;
|
|
@@ -5134,7 +5152,7 @@
|
|
|
5134
5152
|
*
|
|
5135
5153
|
* @private internal utility of `createPipelineExecutor`
|
|
5136
5154
|
*/
|
|
5137
|
-
function
|
|
5155
|
+
function getExamplesForTemplate(template) {
|
|
5138
5156
|
return __awaiter(this, void 0, void 0, function () {
|
|
5139
5157
|
return __generator(this, function (_a) {
|
|
5140
5158
|
// TODO: [♨] Implement Better - use real index and keyword search
|
|
@@ -5151,7 +5169,7 @@
|
|
|
5151
5169
|
*/
|
|
5152
5170
|
function getReservedParametersForTemplate(options) {
|
|
5153
5171
|
return __awaiter(this, void 0, void 0, function () {
|
|
5154
|
-
var preparedPipeline, template, pipelineIdentification, context, knowledge,
|
|
5172
|
+
var preparedPipeline, template, pipelineIdentification, context, knowledge, examples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
5155
5173
|
var e_1, _a;
|
|
5156
5174
|
return __generator(this, function (_b) {
|
|
5157
5175
|
switch (_b.label) {
|
|
@@ -5163,16 +5181,16 @@
|
|
|
5163
5181
|
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
5164
5182
|
case 2:
|
|
5165
5183
|
knowledge = _b.sent();
|
|
5166
|
-
return [4 /*yield*/,
|
|
5184
|
+
return [4 /*yield*/, getExamplesForTemplate(template)];
|
|
5167
5185
|
case 3:
|
|
5168
|
-
|
|
5186
|
+
examples = _b.sent();
|
|
5169
5187
|
currentDate = new Date().toISOString();
|
|
5170
5188
|
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
5171
5189
|
reservedParameters = {
|
|
5172
5190
|
content: RESERVED_PARAMETER_RESTRICTED,
|
|
5173
5191
|
context: context,
|
|
5174
5192
|
knowledge: knowledge,
|
|
5175
|
-
|
|
5193
|
+
examples: examples,
|
|
5176
5194
|
currentDate: currentDate,
|
|
5177
5195
|
modelName: modelName,
|
|
5178
5196
|
};
|
|
@@ -5208,13 +5226,12 @@
|
|
|
5208
5226
|
*/
|
|
5209
5227
|
function executeTemplate(options) {
|
|
5210
5228
|
return __awaiter(this, void 0, void 0, function () {
|
|
5211
|
-
var currentTemplate, preparedPipeline, parametersToPass, tools, onProgress,
|
|
5212
|
-
var e_1,
|
|
5213
|
-
return __generator(this, function (
|
|
5214
|
-
switch (
|
|
5229
|
+
var currentTemplate, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, _a, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _b, _c, _d, definedParameterNames, parameters, _loop_1, _e, _f, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
|
|
5230
|
+
var e_1, _g, _h;
|
|
5231
|
+
return __generator(this, function (_j) {
|
|
5232
|
+
switch (_j.label) {
|
|
5215
5233
|
case 0:
|
|
5216
|
-
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress,
|
|
5217
|
-
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
5234
|
+
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a;
|
|
5218
5235
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
5219
5236
|
title = currentTemplate.title;
|
|
5220
5237
|
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
@@ -5229,7 +5246,7 @@
|
|
|
5229
5246
|
// <- [🍸]
|
|
5230
5247
|
})];
|
|
5231
5248
|
case 1:
|
|
5232
|
-
|
|
5249
|
+
_j.sent();
|
|
5233
5250
|
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
5234
5251
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
5235
5252
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
@@ -5240,15 +5257,15 @@
|
|
|
5240
5257
|
.map(function (name) { return "{".concat(name, "}"); })
|
|
5241
5258
|
.join(', '), "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
5242
5259
|
}
|
|
5243
|
-
|
|
5244
|
-
|
|
5260
|
+
_c = (_b = Object).freeze;
|
|
5261
|
+
_d = [{}];
|
|
5245
5262
|
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
5246
5263
|
preparedPipeline: preparedPipeline,
|
|
5247
5264
|
template: currentTemplate,
|
|
5248
5265
|
pipelineIdentification: pipelineIdentification,
|
|
5249
5266
|
})];
|
|
5250
5267
|
case 2:
|
|
5251
|
-
definedParameters =
|
|
5268
|
+
definedParameters = _c.apply(_b, [__assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_j.sent())])), parametersToPass])]);
|
|
5252
5269
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
5253
5270
|
parameters = {};
|
|
5254
5271
|
_loop_1 = function (parameterName) {
|
|
@@ -5268,15 +5285,15 @@
|
|
|
5268
5285
|
try {
|
|
5269
5286
|
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
5270
5287
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
5271
|
-
for (
|
|
5272
|
-
parameterName =
|
|
5288
|
+
for (_e = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
5289
|
+
parameterName = _f.value;
|
|
5273
5290
|
_loop_1(parameterName);
|
|
5274
5291
|
}
|
|
5275
5292
|
}
|
|
5276
5293
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5277
5294
|
finally {
|
|
5278
5295
|
try {
|
|
5279
|
-
if (
|
|
5296
|
+
if (_f && !_f.done && (_g = _e.return)) _g.call(_e);
|
|
5280
5297
|
}
|
|
5281
5298
|
finally { if (e_1) throw e_1.error; }
|
|
5282
5299
|
}
|
|
@@ -5296,12 +5313,11 @@
|
|
|
5296
5313
|
template: currentTemplate,
|
|
5297
5314
|
preparedPipeline: preparedPipeline,
|
|
5298
5315
|
tools: tools,
|
|
5299
|
-
settings: settings,
|
|
5300
5316
|
$executionReport: $executionReport,
|
|
5301
5317
|
pipelineIdentification: pipelineIdentification,
|
|
5302
5318
|
})];
|
|
5303
5319
|
case 3:
|
|
5304
|
-
resultString =
|
|
5320
|
+
resultString = _j.sent();
|
|
5305
5321
|
return [4 /*yield*/, onProgress({
|
|
5306
5322
|
name: name,
|
|
5307
5323
|
title: title,
|
|
@@ -5313,12 +5329,12 @@
|
|
|
5313
5329
|
// <- [🍸]
|
|
5314
5330
|
})];
|
|
5315
5331
|
case 4:
|
|
5316
|
-
|
|
5317
|
-
return [2 /*return*/, Object.freeze((
|
|
5318
|
-
|
|
5332
|
+
_j.sent();
|
|
5333
|
+
return [2 /*return*/, Object.freeze((_h = {},
|
|
5334
|
+
_h[currentTemplate.resultingParameterName] =
|
|
5319
5335
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5320
5336
|
resultString,
|
|
5321
|
-
|
|
5337
|
+
_h))];
|
|
5322
5338
|
}
|
|
5323
5339
|
});
|
|
5324
5340
|
});
|
|
@@ -5377,13 +5393,12 @@
|
|
|
5377
5393
|
*/
|
|
5378
5394
|
function executePipeline(options) {
|
|
5379
5395
|
return __awaiter(this, void 0, void 0, function () {
|
|
5380
|
-
var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification,
|
|
5396
|
+
var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, maxParallelCount, rootDirname, _a, isVerbose, preparedPipeline, errors, warnings, executionReport, isReturned, _b, _c, parameter, e_1_1, _loop_1, _d, _e, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
5381
5397
|
var e_1, _f, e_2, _g;
|
|
5382
5398
|
return __generator(this, function (_h) {
|
|
5383
5399
|
switch (_h.label) {
|
|
5384
5400
|
case 0:
|
|
5385
|
-
inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification,
|
|
5386
|
-
maxParallelCount = settings.maxParallelCount, rootDirname = settings.rootDirname, _a = settings.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
5401
|
+
inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification, maxParallelCount = options.maxParallelCount, rootDirname = options.rootDirname, _a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
|
|
5387
5402
|
preparedPipeline = options.preparedPipeline;
|
|
5388
5403
|
if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
|
|
5389
5404
|
return [4 /*yield*/, preparePipeline(pipeline, tools, {
|
|
@@ -5568,12 +5583,7 @@
|
|
|
5568
5583
|
return [3 /*break*/, 4];
|
|
5569
5584
|
case 3:
|
|
5570
5585
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
5571
|
-
work_1 = executeTemplate({
|
|
5572
|
-
currentTemplate: currentTemplate,
|
|
5573
|
-
preparedPipeline: preparedPipeline,
|
|
5574
|
-
parametersToPass: parametersToPass,
|
|
5575
|
-
tools: tools,
|
|
5576
|
-
onProgress: function (progress) {
|
|
5586
|
+
work_1 = executeTemplate(__assign(__assign({}, options), { currentTemplate: currentTemplate, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
|
|
5577
5587
|
if (isReturned) {
|
|
5578
5588
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
|
|
5579
5589
|
.split('\n')
|
|
@@ -5583,11 +5593,7 @@
|
|
|
5583
5593
|
if (onProgress) {
|
|
5584
5594
|
onProgress(progress);
|
|
5585
5595
|
}
|
|
5586
|
-
},
|
|
5587
|
-
settings: settings,
|
|
5588
|
-
$executionReport: executionReport,
|
|
5589
|
-
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
5590
|
-
})
|
|
5596
|
+
}, $executionReport: executionReport, pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }) }))
|
|
5591
5597
|
.then(function (newParametersToPass) {
|
|
5592
5598
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
5593
5599
|
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
|
|
@@ -5691,8 +5697,7 @@
|
|
|
5691
5697
|
*/
|
|
5692
5698
|
function createPipelineExecutor(options) {
|
|
5693
5699
|
var _this = this;
|
|
5694
|
-
var pipeline = options.pipeline, tools = options.tools, _a = options.
|
|
5695
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.csvSettings, csvSettings = _d === void 0 ? DEFAULT_CSV_SETTINGS : _d, _e = settings.isVerbose, isVerbose = _e === void 0 ? IS_VERBOSE : _e, _f = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _f === void 0 ? false : _f, _g = settings.rootDirname, rootDirname = _g === void 0 ? null : _g;
|
|
5700
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a, _b = options.maxParallelCount, maxParallelCount = _b === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _b, _c = options.csvSettings, csvSettings = _c === void 0 ? DEFAULT_CSV_SETTINGS : _c, _d = options.isVerbose, isVerbose = _d === void 0 ? DEFAULT_IS_VERBOSE : _d, _e = options.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e, _f = options.rootDirname, rootDirname = _f === void 0 ? null : _f;
|
|
5696
5701
|
validatePipeline(pipeline);
|
|
5697
5702
|
var pipelineIdentification = (function () {
|
|
5698
5703
|
// Note: This is a 😐 implementation of [🚞]
|
|
@@ -5726,14 +5731,12 @@
|
|
|
5726
5731
|
tools: tools,
|
|
5727
5732
|
onProgress: onProgress,
|
|
5728
5733
|
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
rootDirname: rootDirname,
|
|
5736
|
-
},
|
|
5734
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
5735
|
+
maxParallelCount: maxParallelCount,
|
|
5736
|
+
csvSettings: csvSettings,
|
|
5737
|
+
isVerbose: isVerbose,
|
|
5738
|
+
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
5739
|
+
rootDirname: rootDirname,
|
|
5737
5740
|
})];
|
|
5738
5741
|
});
|
|
5739
5742
|
}); };
|
|
@@ -5755,7 +5758,7 @@
|
|
|
5755
5758
|
mimeTypes: ['text/markdown', 'text/plain'],
|
|
5756
5759
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
5757
5760
|
isAvilableInBrowser: true,
|
|
5758
|
-
requiredExecutables: [
|
|
5761
|
+
requiredExecutables: [],
|
|
5759
5762
|
}); /* <- TODO: [🤛] */
|
|
5760
5763
|
/**
|
|
5761
5764
|
* Registration of known scraper metadata
|
|
@@ -5799,7 +5802,7 @@
|
|
|
5799
5802
|
return __generator(this, function (_k) {
|
|
5800
5803
|
switch (_k.label) {
|
|
5801
5804
|
case 0:
|
|
5802
|
-
_a = this.options, _b = _a.maxParallelCount, maxParallelCount = _b === void 0 ?
|
|
5805
|
+
_a = this.options, _b = _a.maxParallelCount, maxParallelCount = _b === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
|
|
5803
5806
|
llm = this.tools.llm;
|
|
5804
5807
|
if (llm === undefined) {
|
|
5805
5808
|
throw new MissingToolsError('LLM tools are required for scraping external files');
|
|
@@ -5846,7 +5849,7 @@
|
|
|
5846
5849
|
outputParameters = result.outputParameters;
|
|
5847
5850
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
5848
5851
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
5849
|
-
// <- TODO: [main]
|
|
5852
|
+
// <- TODO: [main] !! Smarter split and filter out empty pieces
|
|
5850
5853
|
if (isVerbose) {
|
|
5851
5854
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
5852
5855
|
}
|
|
@@ -5898,7 +5901,8 @@
|
|
|
5898
5901
|
embeddingResult = _c.sent();
|
|
5899
5902
|
index.push({
|
|
5900
5903
|
modelName: embeddingResult.modelName,
|
|
5901
|
-
position: embeddingResult.content,
|
|
5904
|
+
position: __spreadArray([], __read(embeddingResult.content), false),
|
|
5905
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `position: embeddingResult.content`
|
|
5902
5906
|
});
|
|
5903
5907
|
_c.label = 6;
|
|
5904
5908
|
case 6: return [3 /*break*/, 8];
|
|
@@ -5949,7 +5953,7 @@
|
|
|
5949
5953
|
mimeTypes: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
5950
5954
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
5951
5955
|
isAvilableInBrowser: false,
|
|
5952
|
-
requiredExecutables: ['
|
|
5956
|
+
requiredExecutables: ['Pandoc'],
|
|
5953
5957
|
}); /* <- TODO: [🤛] */
|
|
5954
5958
|
/**
|
|
5955
5959
|
* Registration of known scraper metadata
|
|
@@ -5989,12 +5993,13 @@
|
|
|
5989
5993
|
* Note: `$` is used to indicate that this function is not a pure function - it leaves files on the disk and you are responsible for cleaning them by calling `destroy` method of returned object
|
|
5990
5994
|
*/
|
|
5991
5995
|
DocumentScraper.prototype.$convert = function (source) {
|
|
5996
|
+
var _a;
|
|
5992
5997
|
return __awaiter(this, void 0, void 0, function () {
|
|
5993
|
-
var
|
|
5998
|
+
var _b, _c, rootDirname, _d, cacheDirname, _e, intermediateFilesStrategy, _f, isVerbose, extension, cacheFilehandler, command_1;
|
|
5994
5999
|
return __generator(this, function (_g) {
|
|
5995
6000
|
switch (_g.label) {
|
|
5996
6001
|
case 0:
|
|
5997
|
-
|
|
6002
|
+
_b = this.options, _c = _b.rootDirname, rootDirname = _c === void 0 ? process.cwd() : _c, _d = _b.cacheDirname, cacheDirname = _d === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _d, _e = _b.intermediateFilesStrategy, intermediateFilesStrategy = _e === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _e, _f = _b.isVerbose, isVerbose = _f === void 0 ? DEFAULT_IS_VERBOSE : _f;
|
|
5998
6003
|
if (!$isRunningInNode()) {
|
|
5999
6004
|
throw new KnowledgeScrapeError('Scraping .docx files is only supported in Node environment');
|
|
6000
6005
|
}
|
|
@@ -6002,7 +6007,7 @@
|
|
|
6002
6007
|
throw new EnvironmentMismatchError('Can not scrape documents without filesystem tools');
|
|
6003
6008
|
// <- TODO: [🧠] What is the best error type here`
|
|
6004
6009
|
}
|
|
6005
|
-
if (
|
|
6010
|
+
if (((_a = this.tools.executables) === null || _a === void 0 ? void 0 : _a.pandocPath) === undefined) {
|
|
6006
6011
|
throw new MissingToolsError('Pandoc is required for scraping .docx files');
|
|
6007
6012
|
}
|
|
6008
6013
|
if (source.filename === null) {
|
|
@@ -6013,7 +6018,7 @@
|
|
|
6013
6018
|
return [4 /*yield*/, getScraperIntermediateSource(source, {
|
|
6014
6019
|
rootDirname: rootDirname,
|
|
6015
6020
|
cacheDirname: cacheDirname,
|
|
6016
|
-
|
|
6021
|
+
intermediateFilesStrategy: intermediateFilesStrategy,
|
|
6017
6022
|
extension: 'md',
|
|
6018
6023
|
isVerbose: isVerbose,
|
|
6019
6024
|
})];
|
|
@@ -6022,11 +6027,9 @@
|
|
|
6022
6027
|
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
6023
6028
|
case 2:
|
|
6024
6029
|
if (!!(_g.sent())) return [3 /*break*/, 5];
|
|
6025
|
-
command_1 = "\"".concat(
|
|
6026
|
-
// TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook
|
|
6030
|
+
command_1 = "\"".concat(this.tools.executables.pandocPath, "\" -f ").concat(extension, " -t markdown \"").concat(source.filename, "\" -o \"").concat(cacheFilehandler.filename, "\"");
|
|
6027
6031
|
return [4 /*yield*/, $execCommand(command_1)];
|
|
6028
6032
|
case 3:
|
|
6029
|
-
// TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook
|
|
6030
6033
|
_g.sent();
|
|
6031
6034
|
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
6032
6035
|
case 4:
|
|
@@ -6071,9 +6074,14 @@
|
|
|
6071
6074
|
asJson: function () {
|
|
6072
6075
|
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
|
|
6073
6076
|
},
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
+
/*
|
|
6078
|
+
TODO: [🥽]
|
|
6079
|
+
> asBlob() {
|
|
6080
|
+
> throw new UnexpectedError(
|
|
6081
|
+
> 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
|
|
6082
|
+
> );
|
|
6083
|
+
> },
|
|
6084
|
+
*/
|
|
6077
6085
|
};
|
|
6078
6086
|
knowledge = this.markdownScraper.scrape(markdownSource);
|
|
6079
6087
|
return [4 /*yield*/, cacheFilehandler.destroy()];
|
|
@@ -6105,7 +6113,11 @@
|
|
|
6105
6113
|
mimeTypes: ['application/msword', 'text/rtf'],
|
|
6106
6114
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
6107
6115
|
isAvilableInBrowser: false,
|
|
6108
|
-
requiredExecutables: [
|
|
6116
|
+
requiredExecutables: [
|
|
6117
|
+
'Pandoc',
|
|
6118
|
+
'LibreOffice',
|
|
6119
|
+
// <- TODO: [🧠] Should be 'LibreOffice' here, its dependency of dependency
|
|
6120
|
+
],
|
|
6109
6121
|
}); /* <- TODO: [🤛] */
|
|
6110
6122
|
/**
|
|
6111
6123
|
* Registration of known scraper metadata
|
|
@@ -6118,7 +6130,7 @@
|
|
|
6118
6130
|
$scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
|
|
6119
6131
|
|
|
6120
6132
|
/**
|
|
6121
|
-
* Scraper for .
|
|
6133
|
+
* Scraper for old document files (like .doc and .rtf)
|
|
6122
6134
|
*
|
|
6123
6135
|
* @see `documentationUrl` for more details
|
|
6124
6136
|
* @public exported from `@promptbook/legacy-documents`
|
|
@@ -6145,12 +6157,13 @@
|
|
|
6145
6157
|
* Note: `$` is used to indicate that this function is not a pure function - it leaves files on the disk and you are responsible for cleaning them by calling `destroy` method of returned object
|
|
6146
6158
|
*/
|
|
6147
6159
|
LegacyDocumentScraper.prototype.$convert = function (source) {
|
|
6160
|
+
var _a;
|
|
6148
6161
|
return __awaiter(this, void 0, void 0, function () {
|
|
6149
|
-
var
|
|
6162
|
+
var _b, _c, rootDirname, _d, cacheDirname, _e, intermediateFilesStrategy, _f, isVerbose, extension, cacheFilehandler, documentSourceOutdirPathForLibreOffice_1, command_1, files_1, file;
|
|
6150
6163
|
return __generator(this, function (_g) {
|
|
6151
6164
|
switch (_g.label) {
|
|
6152
6165
|
case 0:
|
|
6153
|
-
|
|
6166
|
+
_b = this.options, _c = _b.rootDirname, rootDirname = _c === void 0 ? process.cwd() : _c, _d = _b.cacheDirname, cacheDirname = _d === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _d, _e = _b.intermediateFilesStrategy, intermediateFilesStrategy = _e === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _e, _f = _b.isVerbose, isVerbose = _f === void 0 ? DEFAULT_IS_VERBOSE : _f;
|
|
6154
6167
|
if (!$isRunningInNode()) {
|
|
6155
6168
|
throw new KnowledgeScrapeError('Scraping .doc files is only supported in Node environment');
|
|
6156
6169
|
}
|
|
@@ -6158,7 +6171,7 @@
|
|
|
6158
6171
|
throw new EnvironmentMismatchError('Can not scrape (legacy) documents without filesystem tools');
|
|
6159
6172
|
// <- TODO: [🧠] What is the best error type here`
|
|
6160
6173
|
}
|
|
6161
|
-
if (
|
|
6174
|
+
if (((_a = this.tools.executables) === null || _a === void 0 ? void 0 : _a.libreOfficePath) === undefined) {
|
|
6162
6175
|
throw new MissingToolsError('LibreOffice is required for scraping .doc and .rtf files');
|
|
6163
6176
|
}
|
|
6164
6177
|
if (source.filename === null) {
|
|
@@ -6169,7 +6182,7 @@
|
|
|
6169
6182
|
return [4 /*yield*/, getScraperIntermediateSource(source, {
|
|
6170
6183
|
rootDirname: rootDirname,
|
|
6171
6184
|
cacheDirname: cacheDirname,
|
|
6172
|
-
|
|
6185
|
+
intermediateFilesStrategy: intermediateFilesStrategy,
|
|
6173
6186
|
extension: 'docx',
|
|
6174
6187
|
isVerbose: isVerbose,
|
|
6175
6188
|
})];
|
|
@@ -6184,11 +6197,9 @@
|
|
|
6184
6197
|
documentSourceOutdirPathForLibreOffice_1 = path.join(path.dirname(cacheFilehandler.filename), 'libreoffice')
|
|
6185
6198
|
.split('\\')
|
|
6186
6199
|
.join('/');
|
|
6187
|
-
command_1 = "\"".concat(
|
|
6188
|
-
// TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook - this should trigger build polution error
|
|
6200
|
+
command_1 = "\"".concat(this.tools.executables.libreOfficePath, "\" --headless --convert-to docx \"").concat(source.filename, "\" --outdir \"").concat(documentSourceOutdirPathForLibreOffice_1, "\"");
|
|
6189
6201
|
return [4 /*yield*/, $execCommand(command_1)];
|
|
6190
6202
|
case 3:
|
|
6191
|
-
// TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook - this should trigger build polution error
|
|
6192
6203
|
_g.sent();
|
|
6193
6204
|
return [4 /*yield*/, promises.readdir(documentSourceOutdirPathForLibreOffice_1)];
|
|
6194
6205
|
case 4:
|
|
@@ -6236,9 +6247,14 @@
|
|
|
6236
6247
|
asJson: function () {
|
|
6237
6248
|
throw new UnexpectedError('Did not expect that `documentScraper` would need to get the content `asJson`');
|
|
6238
6249
|
},
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6250
|
+
/*
|
|
6251
|
+
TODO: [🥽]
|
|
6252
|
+
> asBlob() {
|
|
6253
|
+
> throw new UnexpectedError(
|
|
6254
|
+
> 'Did not expect that `documentScraper` would need to get the content `asBlob`',
|
|
6255
|
+
> );
|
|
6256
|
+
> },
|
|
6257
|
+
*/
|
|
6242
6258
|
};
|
|
6243
6259
|
knowledge = this.documentScraper.scrape(markdownSource);
|
|
6244
6260
|
return [4 /*yield*/, cacheFilehandler.destroy()];
|