@promptbook/core 0.71.0-0 → 0.71.0-13
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 +10 -0
- package/esm/index.es.js +1964 -1407
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/browser.index.d.ts +3 -1
- package/esm/typings/src/_packages/cli.index.d.ts +20 -0
- package/esm/typings/src/_packages/core.index.d.ts +36 -14
- package/esm/typings/src/_packages/documents.index.d.ts +8 -0
- package/esm/typings/src/_packages/legacy-documents.index.d.ts +8 -0
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +6 -0
- package/esm/typings/src/_packages/node.index.d.ts +14 -6
- package/esm/typings/src/_packages/pdf.index.d.ts +8 -0
- package/esm/typings/src/_packages/types.index.d.ts +41 -25
- package/esm/typings/src/_packages/website-crawler.index.d.ts +8 -0
- package/esm/typings/src/cli/cli-commands/about.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/hello.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +13 -0
- package/esm/typings/src/cli/main.d.ts +1 -1
- package/esm/typings/src/cli/promptbookCli.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +11 -6
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +5 -1
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/KNOWLEDGE/utils/sourceContentToName.d.ts +11 -0
- package/esm/typings/src/commands/KNOWLEDGE/utils/sourceContentToName.test.d.ts +4 -0
- package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/TEMPLATE/templateCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/URL/urlCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
- package/esm/typings/src/config.d.ts +16 -0
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +4 -15
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -1
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +5 -5
- package/esm/typings/src/{knowledge/dialogs → dialogs}/callback/CallbackInterfaceTools.d.ts +2 -2
- package/esm/typings/src/{knowledge/dialogs → dialogs}/callback/CallbackInterfaceToolsOptions.d.ts +3 -3
- package/esm/typings/src/{knowledge/dialogs → dialogs}/simple-prompt/SimplePromptInterfaceTools.d.ts +5 -5
- package/esm/typings/src/errors/AbstractFormatError.d.ts +11 -0
- package/esm/typings/src/errors/KnowledgeScrapeError.d.ts +9 -0
- package/esm/typings/src/errors/MissingToolsError.d.ts +9 -0
- package/esm/typings/src/execution/{CommonExecutionToolsOptions.d.ts → CommonToolsOptions.d.ts} +1 -1
- package/esm/typings/src/execution/ExecutionTools.d.ts +20 -8
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +5 -2
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +2 -13
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +5 -2
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +4 -6
- package/esm/typings/src/execution/createPipelineExecutor/{30-executeFormatCells.d.ts → 30-executeFormatSubvalues.d.ts} +2 -6
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +1 -6
- package/esm/typings/src/execution/embeddingVectorToString.d.ts +1 -1
- package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +3 -0
- package/esm/typings/src/execution/utils/$provideExecutionToolsForNode.d.ts +13 -0
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -0
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +2 -1
- package/esm/typings/src/formats/csv/CsvFormatError.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/{$llmToolsMetadataRegister.d.ts → register/$llmToolsMetadataRegister.d.ts} +4 -1
- package/esm/typings/src/llm-providers/_common/{$llmToolsRegister.d.ts → register/$llmToolsRegister.d.ts} +5 -2
- package/esm/typings/src/llm-providers/_common/{createLlmToolsFromConfigurationFromEnv.d.ts → register/$provideLlmToolsConfigurationFromEnv.d.ts} +3 -3
- package/esm/typings/src/llm-providers/_common/{getLlmToolsForCli.d.ts → register/$provideLlmToolsForCli.d.ts} +4 -3
- package/esm/typings/src/llm-providers/_common/{getLlmToolsForTestingAndScriptsAndPlayground.d.ts → register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts} +4 -3
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +27 -0
- package/esm/typings/src/llm-providers/_common/{$registeredLlmToolsMessage.d.ts → register/$registeredLlmToolsMessage.d.ts} +5 -2
- package/esm/typings/src/llm-providers/_common/{LlmToolsConfiguration.d.ts → register/LlmToolsConfiguration.d.ts} +5 -4
- package/esm/typings/src/llm-providers/_common/{LlmToolsMetadata.d.ts → register/LlmToolsMetadata.d.ts} +5 -4
- package/esm/typings/src/llm-providers/_common/{LlmToolsOptions.d.ts → register/LlmToolsOptions.d.ts} +4 -1
- package/esm/typings/src/llm-providers/_common/{createLlmToolsFromConfiguration.d.ts → register/createLlmToolsFromConfiguration.d.ts} +5 -4
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +3 -3
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +4 -3
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +4 -3
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +8 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +4 -3
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +4 -3
- package/esm/typings/src/llm-providers/langtail/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/multiple/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +2 -1
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +4 -3
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +4 -3
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/remote/playground/playground.d.ts +3 -0
- package/esm/typings/src/personas/preparePersona.d.ts +3 -2
- package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +68 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +3 -2
- package/esm/typings/src/prepare/prepareTemplates.d.ts +3 -2
- package/esm/typings/src/scrapers/_common/Converter.d.ts +22 -0
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +66 -0
- package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +11 -0
- package/esm/typings/src/{knowledge/prepare-knowledge → scrapers}/_common/prepareKnowledgePieces.d.ts +5 -4
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +12 -0
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +15 -0
- package/esm/typings/src/scrapers/_common/register/$registeredScrapersMessage.d.ts +12 -0
- package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +13 -0
- package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +13 -0
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +41 -0
- package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +12 -0
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +33 -0
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.test.d.ts +4 -0
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +13 -0
- package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/document/DocumentScraper.test.d.ts +4 -0
- package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/document/playground/document-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.test.d.ts +4 -0
- package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/document-legacy/playground/legacy-document-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +29 -0
- package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/markdown/playground/markdown-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +40 -0
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/pdf/playground/pdf-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +47 -0
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/website/playground/website-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/website/utils/markdownConverter.d.ts +12 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/scripting/python/PythonExecutionTools.d.ts +2 -2
- package/esm/typings/src/scripting/typescript/TypescriptExecutionTools.d.ts +2 -2
- package/esm/typings/src/storage/{files-storage/FilesStorage.d.ts → file-cache-storage/FileCacheStorage.d.ts} +4 -4
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +10 -0
- package/esm/typings/src/storage/{files-storage → file-cache-storage}/utils/nameToSubfolderPath.d.ts +1 -1
- package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +1 -1
- package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +1 -1
- package/esm/typings/src/storage/{utils → memory/utils}/PrefixStorage.d.ts +1 -1
- package/esm/typings/src/storage/{utils → memory/utils}/makePromptbookStorageFromWebStorage.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +2 -2
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +0 -3
- package/esm/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -1
- package/esm/typings/src/types/typeAliases.d.ts +16 -12
- package/esm/typings/src/utils/$Register.d.ts +19 -6
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +14 -0
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +17 -0
- package/esm/typings/src/utils/execCommand/IExecCommandOptions.d.ts +23 -0
- package/esm/typings/src/utils/execCommand/execCommand.test.d.ts +1 -0
- package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.d.ts +10 -0
- package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.test.d.ts +1 -0
- package/esm/typings/src/utils/files/$isDirectoryExisting.d.ts +3 -3
- package/esm/typings/src/utils/files/$isFileExisting.d.ts +3 -3
- package/esm/typings/src/utils/files/$listAllFiles.d.ts +5 -4
- package/esm/typings/src/utils/files/extensionToMimeType.d.ts +8 -0
- package/esm/typings/src/utils/files/extensionToMimeType.test.d.ts +1 -0
- package/esm/typings/src/utils/files/getFileExtension.d.ts +8 -0
- package/esm/typings/src/utils/files/getFileExtension.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +2 -2
- package/package.json +2 -1
- package/umd/index.umd.js +1976 -1411
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +0 -37
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +0 -2
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +0 -14
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +0 -15
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +0 -25
- package/esm/typings/src/prepare/PrepareOptions.d.ts +0 -22
- package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +0 -10
- /package/esm/typings/src/{knowledge/dialogs → dialogs}/user-interface-execution-tools.test.d.ts +0 -0
- /package/esm/typings/src/{knowledge/prepare-knowledge → scrapers}/_common/prepareKnowledgePieces.test.d.ts +0 -0
- /package/esm/typings/src/{knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts → scrapers/markdown/MarkdownScraper.test.d.ts} +0 -0
- /package/esm/typings/src/{knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts → scrapers/website/WebsiteScraper.test.d.ts} +0 -0
- /package/esm/typings/src/{storage/files-storage/utils/nameToSubfolderPath.test.d.ts → scrapers/website/utils/markdownConverter.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('moment')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'moment'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.moment));
|
|
5
|
-
})(this, (function (exports, spaceTrim, prettier, parserHtml, waitasecond, papaparse, hexEncoder, sha256, moment) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('papaparse'), require('fs/promises'), require('path'), require('crypto-js'), require('crypto-js/enc-hex'), require('mime-types'), require('crypto-js/sha256'), require('moment')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'waitasecond', 'papaparse', 'fs/promises', 'path', 'crypto-js', 'crypto-js/enc-hex', 'mime-types', 'crypto-js/sha256', 'moment'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.waitasecond, global.papaparse, global.promises, global.path, global.cryptoJs, global.hexEncoder, global.mimeTypes, global.sha256, global.moment));
|
|
5
|
+
})(this, (function (exports, spaceTrim, prettier, parserHtml, waitasecond, papaparse, promises, path, cryptoJs, hexEncoder, mimeTypes, sha256, moment) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* The version of the Promptbook library
|
|
18
18
|
*/
|
|
19
|
-
var PROMPTBOOK_VERSION = '0.
|
|
20
|
-
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
19
|
+
var PROMPTBOOK_VERSION = '0.71.0-12';
|
|
20
|
+
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
21
21
|
|
|
22
22
|
/*! *****************************************************************************
|
|
23
23
|
Copyright (c) Microsoft Corporation.
|
|
@@ -229,7 +229,7 @@
|
|
|
229
229
|
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
230
230
|
}
|
|
231
231
|
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
232
|
-
// TODO:[main] !!! This increase size of the bundle and is probbably not necessary
|
|
232
|
+
// TODO: [main] !!! This increase size of the bundle and is probbably not necessary
|
|
233
233
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
234
234
|
try {
|
|
235
235
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -377,12 +377,12 @@
|
|
|
377
377
|
pipelineString += '```' + contentLanguage;
|
|
378
378
|
pipelineString += '\n';
|
|
379
379
|
pipelineString += spaceTrim__default["default"](content);
|
|
380
|
-
// <- TODO:[main] !!! Escape
|
|
380
|
+
// <- TODO: [main] !!! Escape
|
|
381
381
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
382
382
|
pipelineString += '\n';
|
|
383
383
|
pipelineString += '```';
|
|
384
384
|
pipelineString += '\n\n';
|
|
385
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO:[main] !!! If the parameter here has description, add it and use templateParameterJsonToString
|
|
385
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use templateParameterJsonToString
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
388
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -688,9 +688,19 @@
|
|
|
688
688
|
/**
|
|
689
689
|
* Where to store the cache of executions for promptbook CLI
|
|
690
690
|
*
|
|
691
|
+
* Note: When the folder does not exist, it is created recursively
|
|
692
|
+
*
|
|
691
693
|
* @public exported from `@promptbook/core`
|
|
692
694
|
*/
|
|
693
695
|
var EXECUTIONS_CACHE_DIRNAME = '/.promptbook/executions-cache';
|
|
696
|
+
/**
|
|
697
|
+
* Where to store the scrape cache
|
|
698
|
+
*
|
|
699
|
+
* Note: When the folder does not exist, it is created recursively
|
|
700
|
+
*
|
|
701
|
+
* @public exported from `@promptbook/core`
|
|
702
|
+
*/
|
|
703
|
+
var SCRAPE_CACHE_DIRNAME = '/.promptbook/scrape-cache';
|
|
694
704
|
/**
|
|
695
705
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
696
706
|
*
|
|
@@ -770,6 +780,12 @@
|
|
|
770
780
|
* @public exported from `@promptbook/core`
|
|
771
781
|
*/
|
|
772
782
|
var IS_VERBOSE = false;
|
|
783
|
+
/**
|
|
784
|
+
* @@@
|
|
785
|
+
*
|
|
786
|
+
* @public exported from `@promptbook/core`
|
|
787
|
+
*/
|
|
788
|
+
var IS_AUTO_INSTALLED = false;
|
|
773
789
|
/**
|
|
774
790
|
* @@@
|
|
775
791
|
*
|
|
@@ -856,7 +872,7 @@
|
|
|
856
872
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
857
873
|
return false;
|
|
858
874
|
}
|
|
859
|
-
// <- TODO:[main] !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
875
|
+
// <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
860
876
|
return true;
|
|
861
877
|
}
|
|
862
878
|
|
|
@@ -1220,11 +1236,11 @@
|
|
|
1220
1236
|
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
1221
1237
|
*/
|
|
1222
1238
|
/**
|
|
1223
|
-
* TODO: [
|
|
1224
|
-
* TODO: [
|
|
1225
|
-
* TODO: [
|
|
1226
|
-
* TODO: [
|
|
1227
|
-
* TODO: [
|
|
1239
|
+
* TODO: [🧳][main] !!!! Validate that all samples match expectations
|
|
1240
|
+
* TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
|
|
1241
|
+
* TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
|
|
1242
|
+
* TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
1243
|
+
* TODO: [🧳][main] !!!! Validate that reserved parameter is not used as joker
|
|
1228
1244
|
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
1229
1245
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
1230
1246
|
*/
|
|
@@ -1538,7 +1554,7 @@
|
|
|
1538
1554
|
});
|
|
1539
1555
|
}
|
|
1540
1556
|
/**
|
|
1541
|
-
* TODO:[main] !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
1557
|
+
* TODO: [main] !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
1542
1558
|
*/
|
|
1543
1559
|
|
|
1544
1560
|
/**
|
|
@@ -1639,6 +1655,22 @@
|
|
|
1639
1655
|
// <- [🅱]
|
|
1640
1656
|
];
|
|
1641
1657
|
|
|
1658
|
+
/**
|
|
1659
|
+
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
1660
|
+
*
|
|
1661
|
+
* @public exported from `@promptbook/core`
|
|
1662
|
+
*/
|
|
1663
|
+
var MissingToolsError = /** @class */ (function (_super) {
|
|
1664
|
+
__extends(MissingToolsError, _super);
|
|
1665
|
+
function MissingToolsError(message) {
|
|
1666
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
|
|
1667
|
+
_this.name = 'MissingToolsError';
|
|
1668
|
+
Object.setPrototypeOf(_this, MissingToolsError.prototype);
|
|
1669
|
+
return _this;
|
|
1670
|
+
}
|
|
1671
|
+
return MissingToolsError;
|
|
1672
|
+
}(Error));
|
|
1673
|
+
|
|
1642
1674
|
/**
|
|
1643
1675
|
* @@@
|
|
1644
1676
|
*
|
|
@@ -1767,6 +1799,7 @@
|
|
|
1767
1799
|
* @param options - Options for the function
|
|
1768
1800
|
* @param callbackfunction - Function to call for each item
|
|
1769
1801
|
* @public exported from `@promptbook/utils`
|
|
1802
|
+
* @deprecated [🪂] Use queues instead
|
|
1770
1803
|
*/
|
|
1771
1804
|
function forEachAsync(array, options, callbackfunction) {
|
|
1772
1805
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1835,370 +1868,92 @@
|
|
|
1835
1868
|
});
|
|
1836
1869
|
}
|
|
1837
1870
|
|
|
1838
|
-
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## Sample\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"}];
|
|
1839
|
-
|
|
1840
|
-
var defaultDiacriticsRemovalMap = [
|
|
1841
|
-
{
|
|
1842
|
-
base: 'A',
|
|
1843
|
-
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
1844
|
-
},
|
|
1845
|
-
{ base: 'AA', letters: '\uA732' },
|
|
1846
|
-
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
1847
|
-
{ base: 'AO', letters: '\uA734' },
|
|
1848
|
-
{ base: 'AU', letters: '\uA736' },
|
|
1849
|
-
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
1850
|
-
{ base: 'AY', letters: '\uA73C' },
|
|
1851
|
-
{
|
|
1852
|
-
base: 'B',
|
|
1853
|
-
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
1854
|
-
},
|
|
1855
|
-
{
|
|
1856
|
-
base: 'C',
|
|
1857
|
-
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
1858
|
-
},
|
|
1859
|
-
{
|
|
1860
|
-
base: 'D',
|
|
1861
|
-
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
1862
|
-
},
|
|
1863
|
-
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
1864
|
-
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
1865
|
-
{
|
|
1866
|
-
base: 'E',
|
|
1867
|
-
letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
|
|
1868
|
-
},
|
|
1869
|
-
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
1870
|
-
{
|
|
1871
|
-
base: 'G',
|
|
1872
|
-
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
1873
|
-
},
|
|
1874
|
-
{
|
|
1875
|
-
base: 'H',
|
|
1876
|
-
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
1877
|
-
},
|
|
1878
|
-
{
|
|
1879
|
-
base: 'I',
|
|
1880
|
-
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
1881
|
-
},
|
|
1882
|
-
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
1883
|
-
{
|
|
1884
|
-
base: 'K',
|
|
1885
|
-
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
1886
|
-
},
|
|
1887
|
-
{
|
|
1888
|
-
base: 'L',
|
|
1889
|
-
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
1890
|
-
},
|
|
1891
|
-
{ base: 'LJ', letters: '\u01C7' },
|
|
1892
|
-
{ base: 'Lj', letters: '\u01C8' },
|
|
1893
|
-
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
1894
|
-
{
|
|
1895
|
-
base: 'N',
|
|
1896
|
-
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
1897
|
-
},
|
|
1898
|
-
{ base: 'NJ', letters: '\u01CA' },
|
|
1899
|
-
{ base: 'Nj', letters: '\u01CB' },
|
|
1900
|
-
{
|
|
1901
|
-
base: 'O',
|
|
1902
|
-
letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
|
|
1903
|
-
},
|
|
1904
|
-
{ base: 'OI', letters: '\u01A2' },
|
|
1905
|
-
{ base: 'OO', letters: '\uA74E' },
|
|
1906
|
-
{ base: 'OU', letters: '\u0222' },
|
|
1907
|
-
{ base: 'OE', letters: '\u008C\u0152' },
|
|
1908
|
-
{ base: 'oe', letters: '\u009C\u0153' },
|
|
1909
|
-
{
|
|
1910
|
-
base: 'P',
|
|
1911
|
-
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
1912
|
-
},
|
|
1913
|
-
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
1914
|
-
{
|
|
1915
|
-
base: 'R',
|
|
1916
|
-
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
1917
|
-
},
|
|
1918
|
-
{
|
|
1919
|
-
base: 'S',
|
|
1920
|
-
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
1921
|
-
},
|
|
1922
|
-
{
|
|
1923
|
-
base: 'T',
|
|
1924
|
-
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
1925
|
-
},
|
|
1926
|
-
{ base: 'TZ', letters: '\uA728' },
|
|
1927
|
-
{
|
|
1928
|
-
base: 'U',
|
|
1929
|
-
letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
|
|
1930
|
-
},
|
|
1931
|
-
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
1932
|
-
{ base: 'VY', letters: '\uA760' },
|
|
1933
|
-
{
|
|
1934
|
-
base: 'W',
|
|
1935
|
-
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
1936
|
-
},
|
|
1937
|
-
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
1938
|
-
{
|
|
1939
|
-
base: 'Y',
|
|
1940
|
-
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
1941
|
-
},
|
|
1942
|
-
{
|
|
1943
|
-
base: 'Z',
|
|
1944
|
-
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
1945
|
-
},
|
|
1946
|
-
{
|
|
1947
|
-
base: 'a',
|
|
1948
|
-
letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
|
|
1949
|
-
},
|
|
1950
|
-
{ base: 'aa', letters: '\uA733' },
|
|
1951
|
-
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
1952
|
-
{ base: 'ao', letters: '\uA735' },
|
|
1953
|
-
{ base: 'au', letters: '\uA737' },
|
|
1954
|
-
{ base: 'av', letters: '\uA739\uA73B' },
|
|
1955
|
-
{ base: 'ay', letters: '\uA73D' },
|
|
1956
|
-
{
|
|
1957
|
-
base: 'b',
|
|
1958
|
-
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
1959
|
-
},
|
|
1960
|
-
{
|
|
1961
|
-
base: 'c',
|
|
1962
|
-
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
1963
|
-
},
|
|
1964
|
-
{
|
|
1965
|
-
base: 'd',
|
|
1966
|
-
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
1967
|
-
},
|
|
1968
|
-
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
1969
|
-
{
|
|
1970
|
-
base: 'e',
|
|
1971
|
-
letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
|
|
1972
|
-
},
|
|
1973
|
-
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
1974
|
-
{
|
|
1975
|
-
base: 'g',
|
|
1976
|
-
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
1977
|
-
},
|
|
1978
|
-
{
|
|
1979
|
-
base: 'h',
|
|
1980
|
-
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
1981
|
-
},
|
|
1982
|
-
{ base: 'hv', letters: '\u0195' },
|
|
1983
|
-
{
|
|
1984
|
-
base: 'i',
|
|
1985
|
-
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
1986
|
-
},
|
|
1987
|
-
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
1988
|
-
{
|
|
1989
|
-
base: 'k',
|
|
1990
|
-
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
1991
|
-
},
|
|
1992
|
-
{
|
|
1993
|
-
base: 'l',
|
|
1994
|
-
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
1995
|
-
},
|
|
1996
|
-
{ base: 'lj', letters: '\u01C9' },
|
|
1997
|
-
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
1998
|
-
{
|
|
1999
|
-
base: 'n',
|
|
2000
|
-
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
2001
|
-
},
|
|
2002
|
-
{ base: 'nj', letters: '\u01CC' },
|
|
2003
|
-
{
|
|
2004
|
-
base: 'o',
|
|
2005
|
-
letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
|
|
2006
|
-
},
|
|
2007
|
-
{ base: 'oi', letters: '\u01A3' },
|
|
2008
|
-
{ base: 'ou', letters: '\u0223' },
|
|
2009
|
-
{ base: 'oo', letters: '\uA74F' },
|
|
2010
|
-
{
|
|
2011
|
-
base: 'p',
|
|
2012
|
-
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
2013
|
-
},
|
|
2014
|
-
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
2015
|
-
{
|
|
2016
|
-
base: 'r',
|
|
2017
|
-
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
2018
|
-
},
|
|
2019
|
-
{
|
|
2020
|
-
base: 's',
|
|
2021
|
-
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
2022
|
-
},
|
|
2023
|
-
{
|
|
2024
|
-
base: 't',
|
|
2025
|
-
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
2026
|
-
},
|
|
2027
|
-
{ base: 'tz', letters: '\uA729' },
|
|
2028
|
-
{
|
|
2029
|
-
base: 'u',
|
|
2030
|
-
letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
|
|
2031
|
-
},
|
|
2032
|
-
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
2033
|
-
{ base: 'vy', letters: '\uA761' },
|
|
2034
|
-
{
|
|
2035
|
-
base: 'w',
|
|
2036
|
-
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
2037
|
-
},
|
|
2038
|
-
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
2039
|
-
{
|
|
2040
|
-
base: 'y',
|
|
2041
|
-
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
2042
|
-
},
|
|
2043
|
-
{
|
|
2044
|
-
base: 'z',
|
|
2045
|
-
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
2046
|
-
},
|
|
2047
|
-
];
|
|
2048
1871
|
/**
|
|
2049
|
-
*
|
|
2050
|
-
* Contains lowercase and uppercase separatelly
|
|
2051
|
-
*
|
|
2052
|
-
* > "á" => "a"
|
|
2053
|
-
* > "ě" => "e"
|
|
2054
|
-
* > "Ă" => "A"
|
|
2055
|
-
* > ...
|
|
1872
|
+
* Intercepts LLM tools and counts total usage of the tools
|
|
2056
1873
|
*
|
|
2057
|
-
* @
|
|
1874
|
+
* @param llmTools LLM tools to be intercepted with usage counting
|
|
1875
|
+
* @returns LLM tools with same functionality with added total cost counting
|
|
1876
|
+
* @public exported from `@promptbook/core`
|
|
2058
1877
|
*/
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
var
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
*/
|
|
2100
|
-
|
|
2101
|
-
/**
|
|
2102
|
-
* @@@
|
|
2103
|
-
*
|
|
2104
|
-
* @param text @@@
|
|
2105
|
-
* @returns @@@
|
|
2106
|
-
* @example 'hello-world'
|
|
2107
|
-
* @example 'i-love-promptbook'
|
|
2108
|
-
* @public exported from `@promptbook/utils`
|
|
2109
|
-
*/
|
|
2110
|
-
function normalizeToKebabCase(text) {
|
|
2111
|
-
var e_1, _a;
|
|
2112
|
-
text = removeDiacritics(text);
|
|
2113
|
-
var charType;
|
|
2114
|
-
var lastCharType = 'OTHER';
|
|
2115
|
-
var normalizedName = '';
|
|
2116
|
-
try {
|
|
2117
|
-
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
2118
|
-
var char = text_1_1.value;
|
|
2119
|
-
var normalizedChar = void 0;
|
|
2120
|
-
if (/^[a-z]$/.test(char)) {
|
|
2121
|
-
charType = 'LOWERCASE';
|
|
2122
|
-
normalizedChar = char;
|
|
2123
|
-
}
|
|
2124
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
2125
|
-
charType = 'UPPERCASE';
|
|
2126
|
-
normalizedChar = char.toLowerCase();
|
|
2127
|
-
}
|
|
2128
|
-
else if (/^[0-9]$/.test(char)) {
|
|
2129
|
-
charType = 'NUMBER';
|
|
2130
|
-
normalizedChar = char;
|
|
2131
|
-
}
|
|
2132
|
-
else if (/^\/$/.test(char)) {
|
|
2133
|
-
charType = 'SLASH';
|
|
2134
|
-
normalizedChar = char;
|
|
2135
|
-
}
|
|
2136
|
-
else {
|
|
2137
|
-
charType = 'OTHER';
|
|
2138
|
-
normalizedChar = '-';
|
|
2139
|
-
}
|
|
2140
|
-
if (charType !== lastCharType &&
|
|
2141
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
2142
|
-
!(lastCharType === 'NUMBER') &&
|
|
2143
|
-
!(charType === 'NUMBER')) {
|
|
2144
|
-
normalizedName += '-';
|
|
2145
|
-
}
|
|
2146
|
-
normalizedName += normalizedChar;
|
|
2147
|
-
lastCharType = charType;
|
|
2148
|
-
}
|
|
1878
|
+
function countTotalUsage(llmTools) {
|
|
1879
|
+
var _this = this;
|
|
1880
|
+
var totalUsage = ZERO_USAGE;
|
|
1881
|
+
var proxyTools = {
|
|
1882
|
+
get title() {
|
|
1883
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
1884
|
+
return llmTools.title;
|
|
1885
|
+
},
|
|
1886
|
+
get description() {
|
|
1887
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
1888
|
+
return llmTools.description;
|
|
1889
|
+
},
|
|
1890
|
+
checkConfiguration: function () {
|
|
1891
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1892
|
+
return __generator(this, function (_a) {
|
|
1893
|
+
return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
|
|
1894
|
+
});
|
|
1895
|
+
});
|
|
1896
|
+
},
|
|
1897
|
+
listModels: function () {
|
|
1898
|
+
return /* not await */ llmTools.listModels();
|
|
1899
|
+
},
|
|
1900
|
+
getTotalUsage: function () {
|
|
1901
|
+
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
1902
|
+
return totalUsage;
|
|
1903
|
+
},
|
|
1904
|
+
};
|
|
1905
|
+
if (llmTools.callChatModel !== undefined) {
|
|
1906
|
+
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
1907
|
+
var promptResult;
|
|
1908
|
+
return __generator(this, function (_a) {
|
|
1909
|
+
switch (_a.label) {
|
|
1910
|
+
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
1911
|
+
case 1:
|
|
1912
|
+
promptResult = _a.sent();
|
|
1913
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
1914
|
+
return [2 /*return*/, promptResult];
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
}); };
|
|
2149
1918
|
}
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
1919
|
+
if (llmTools.callCompletionModel !== undefined) {
|
|
1920
|
+
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
1921
|
+
var promptResult;
|
|
1922
|
+
return __generator(this, function (_a) {
|
|
1923
|
+
switch (_a.label) {
|
|
1924
|
+
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
1925
|
+
case 1:
|
|
1926
|
+
promptResult = _a.sent();
|
|
1927
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
1928
|
+
return [2 /*return*/, promptResult];
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
}); };
|
|
2156
1932
|
}
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
2174
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
2175
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
2176
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
2177
|
-
return text;
|
|
1933
|
+
if (llmTools.callEmbeddingModel !== undefined) {
|
|
1934
|
+
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
1935
|
+
var promptResult;
|
|
1936
|
+
return __generator(this, function (_a) {
|
|
1937
|
+
switch (_a.label) {
|
|
1938
|
+
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
1939
|
+
case 1:
|
|
1940
|
+
promptResult = _a.sent();
|
|
1941
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
1942
|
+
return [2 /*return*/, promptResult];
|
|
1943
|
+
}
|
|
1944
|
+
});
|
|
1945
|
+
}); };
|
|
1946
|
+
}
|
|
1947
|
+
// <- Note: [🤖]
|
|
1948
|
+
return proxyTools;
|
|
2178
1949
|
}
|
|
2179
|
-
|
|
2180
1950
|
/**
|
|
2181
|
-
*
|
|
2182
|
-
*
|
|
2183
|
-
*
|
|
2184
|
-
*
|
|
2185
|
-
*
|
|
2186
|
-
* @public exported from `@promptbook/utils`
|
|
1951
|
+
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
1952
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
1953
|
+
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
1954
|
+
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
1955
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2187
1956
|
*/
|
|
2188
|
-
function titleToName(value) {
|
|
2189
|
-
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
2190
|
-
// TODO: Maybe check against some list unallowed characters
|
|
2191
|
-
return value;
|
|
2192
|
-
}
|
|
2193
|
-
if (value.startsWith('./') || value.startsWith('../')) {
|
|
2194
|
-
// TODO: Maybe check against some list unallowed characters
|
|
2195
|
-
return value;
|
|
2196
|
-
}
|
|
2197
|
-
value = removeEmojis(value);
|
|
2198
|
-
value = normalizeToKebabCase(value);
|
|
2199
|
-
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
2200
|
-
return value;
|
|
2201
|
-
}
|
|
2202
1957
|
|
|
2203
1958
|
/**
|
|
2204
1959
|
* This error indicates errors during the execution of the pipeline
|
|
@@ -2217,217 +1972,22 @@
|
|
|
2217
1972
|
}(Error));
|
|
2218
1973
|
|
|
2219
1974
|
/**
|
|
2220
|
-
*
|
|
2221
|
-
*
|
|
2222
|
-
* @public exported from `@promptbook/core`
|
|
2223
|
-
*/
|
|
2224
|
-
var CollectionError = /** @class */ (function (_super) {
|
|
2225
|
-
__extends(CollectionError, _super);
|
|
2226
|
-
function CollectionError(message) {
|
|
2227
|
-
var _this = _super.call(this, message) || this;
|
|
2228
|
-
_this.name = 'CollectionError';
|
|
2229
|
-
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
2230
|
-
return _this;
|
|
2231
|
-
}
|
|
2232
|
-
return CollectionError;
|
|
2233
|
-
}(Error));
|
|
2234
|
-
|
|
2235
|
-
/**
|
|
2236
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
2237
|
-
*
|
|
2238
|
-
* @public exported from `@promptbook/core`
|
|
2239
|
-
*/
|
|
2240
|
-
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
2241
|
-
__extends(EnvironmentMismatchError, _super);
|
|
2242
|
-
function EnvironmentMismatchError(message) {
|
|
2243
|
-
var _this = _super.call(this, message) || this;
|
|
2244
|
-
_this.name = 'EnvironmentMismatchError';
|
|
2245
|
-
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
2246
|
-
return _this;
|
|
2247
|
-
}
|
|
2248
|
-
return EnvironmentMismatchError;
|
|
2249
|
-
}(Error));
|
|
2250
|
-
|
|
2251
|
-
/**
|
|
2252
|
-
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
1975
|
+
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2253
1976
|
*
|
|
2254
|
-
*
|
|
2255
|
-
*
|
|
2256
|
-
*
|
|
2257
|
-
* Note: This is a kindof subtype of PipelineExecutionError
|
|
1977
|
+
* Note: Internal utility of `joinLlmExecutionTools` but exposed type
|
|
1978
|
+
* @public exported from `@promptbook/types`
|
|
1979
|
+
* TODO: !!!!!! Export as runtime class not just type
|
|
2258
1980
|
*/
|
|
2259
|
-
var
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
/**
|
|
2271
|
-
* This error type indicates that some limit was reached
|
|
2272
|
-
*
|
|
2273
|
-
* @public exported from `@promptbook/core`
|
|
2274
|
-
*/
|
|
2275
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
2276
|
-
__extends(LimitReachedError, _super);
|
|
2277
|
-
function LimitReachedError(message) {
|
|
2278
|
-
var _this = _super.call(this, message) || this;
|
|
2279
|
-
_this.name = 'LimitReachedError';
|
|
2280
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2281
|
-
return _this;
|
|
2282
|
-
}
|
|
2283
|
-
return LimitReachedError;
|
|
2284
|
-
}(Error));
|
|
2285
|
-
|
|
2286
|
-
/**
|
|
2287
|
-
* This error type indicates that some part of the code is not implemented yet
|
|
2288
|
-
*
|
|
2289
|
-
* @public exported from `@promptbook/core`
|
|
2290
|
-
*/
|
|
2291
|
-
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
2292
|
-
__extends(NotYetImplementedError, _super);
|
|
2293
|
-
function NotYetImplementedError(message) {
|
|
2294
|
-
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
2295
|
-
_this.name = 'NotYetImplementedError';
|
|
2296
|
-
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
2297
|
-
return _this;
|
|
2298
|
-
}
|
|
2299
|
-
return NotYetImplementedError;
|
|
2300
|
-
}(Error));
|
|
2301
|
-
|
|
2302
|
-
/**
|
|
2303
|
-
* Index of all custom errors
|
|
2304
|
-
*
|
|
2305
|
-
* @public exported from `@promptbook/core`
|
|
2306
|
-
*/
|
|
2307
|
-
var ERRORS = {
|
|
2308
|
-
ExpectError: ExpectError,
|
|
2309
|
-
CollectionError: CollectionError,
|
|
2310
|
-
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
2311
|
-
LimitReachedError: LimitReachedError,
|
|
2312
|
-
NotFoundError: NotFoundError,
|
|
2313
|
-
NotYetImplementedError: NotYetImplementedError,
|
|
2314
|
-
ParseError: ParseError,
|
|
2315
|
-
PipelineExecutionError: PipelineExecutionError,
|
|
2316
|
-
PipelineLogicError: PipelineLogicError,
|
|
2317
|
-
PipelineUrlError: PipelineUrlError,
|
|
2318
|
-
UnexpectedError: UnexpectedError,
|
|
2319
|
-
// TODO: [🪑]> VersionMismatchError,
|
|
2320
|
-
};
|
|
2321
|
-
|
|
2322
|
-
/**
|
|
2323
|
-
* Deserializes the error object
|
|
2324
|
-
*
|
|
2325
|
-
* @public exported from `@promptbook/utils`
|
|
2326
|
-
*/
|
|
2327
|
-
function deserializeError(error) {
|
|
2328
|
-
if (error.name === 'Error') {
|
|
2329
|
-
return new Error(error.message);
|
|
2330
|
-
}
|
|
2331
|
-
var CustomError = ERRORS[error.name];
|
|
2332
|
-
return new CustomError(error.message);
|
|
2333
|
-
}
|
|
2334
|
-
|
|
2335
|
-
/**
|
|
2336
|
-
* Asserts that the execution of a Promptbook is successful
|
|
2337
|
-
*
|
|
2338
|
-
* @param executionResult - The partial result of the Promptbook execution
|
|
2339
|
-
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2340
|
-
* @public exported from `@promptbook/core`
|
|
2341
|
-
*/
|
|
2342
|
-
function assertsExecutionSuccessful(executionResult) {
|
|
2343
|
-
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
2344
|
-
if (isSuccessful === true) {
|
|
2345
|
-
return;
|
|
2346
|
-
}
|
|
2347
|
-
if (errors.length === 0) {
|
|
2348
|
-
throw new PipelineExecutionError("Promptbook Execution failed because of unknown reason");
|
|
2349
|
-
}
|
|
2350
|
-
else if (errors.length === 1) {
|
|
2351
|
-
throw deserializeError(errors[0]);
|
|
2352
|
-
}
|
|
2353
|
-
else {
|
|
2354
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
|
|
2355
|
-
.map(function (_a, index) {
|
|
2356
|
-
var name = _a.name, stack = _a.stack, message = _a.message;
|
|
2357
|
-
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
|
|
2358
|
-
})
|
|
2359
|
-
.join('\n')), "\n "); }));
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
/**
|
|
2363
|
-
* TODO: [🧠] Can this return type be better typed than void
|
|
2364
|
-
*/
|
|
2365
|
-
|
|
2366
|
-
/**
|
|
2367
|
-
* Determine if the pipeline is fully prepared
|
|
2368
|
-
*
|
|
2369
|
-
* @public exported from `@promptbook/core`
|
|
2370
|
-
*/
|
|
2371
|
-
function isPipelinePrepared(pipeline) {
|
|
2372
|
-
// Note: Ignoring `pipeline.preparations` @@@
|
|
2373
|
-
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2374
|
-
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2375
|
-
return false;
|
|
2376
|
-
}
|
|
2377
|
-
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2378
|
-
return false;
|
|
2379
|
-
}
|
|
2380
|
-
/*
|
|
2381
|
-
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2382
|
-
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2383
|
-
> return false;
|
|
2384
|
-
> }
|
|
2385
|
-
*/
|
|
2386
|
-
return true;
|
|
2387
|
-
}
|
|
2388
|
-
/**
|
|
2389
|
-
* TODO: [🔃][main] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2390
|
-
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2391
|
-
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2392
|
-
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2393
|
-
* - [🏍] ? Is context in each template
|
|
2394
|
-
* - [♨] Are samples prepared
|
|
2395
|
-
* - [♨] Are templates prepared
|
|
2396
|
-
*/
|
|
2397
|
-
|
|
2398
|
-
/**
|
|
2399
|
-
* Serializes an error into a [🚉] JSON-serializable object
|
|
2400
|
-
*
|
|
2401
|
-
* @public exported from `@promptbook/utils`
|
|
2402
|
-
*/
|
|
2403
|
-
function serializeError(error) {
|
|
2404
|
-
var name = error.name, message = error.message, stack = error.stack;
|
|
2405
|
-
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2406
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2407
|
-
}
|
|
2408
|
-
return {
|
|
2409
|
-
name: name,
|
|
2410
|
-
message: message,
|
|
2411
|
-
stack: stack,
|
|
2412
|
-
};
|
|
2413
|
-
}
|
|
2414
|
-
|
|
2415
|
-
/**
|
|
2416
|
-
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2417
|
-
*
|
|
2418
|
-
* Note: Internal utility of `joinLlmExecutionTools` but exposed type
|
|
2419
|
-
* @public exported from `@promptbook/types`
|
|
2420
|
-
*/
|
|
2421
|
-
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
2422
|
-
/**
|
|
2423
|
-
* Gets array of execution tools in order of priority
|
|
2424
|
-
*/
|
|
2425
|
-
function MultipleLlmExecutionTools() {
|
|
2426
|
-
var llmExecutionTools = [];
|
|
2427
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2428
|
-
llmExecutionTools[_i] = arguments[_i];
|
|
2429
|
-
}
|
|
2430
|
-
this.llmExecutionTools = llmExecutionTools;
|
|
1981
|
+
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
1982
|
+
/**
|
|
1983
|
+
* Gets array of execution tools in order of priority
|
|
1984
|
+
*/
|
|
1985
|
+
function MultipleLlmExecutionTools() {
|
|
1986
|
+
var llmExecutionTools = [];
|
|
1987
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1988
|
+
llmExecutionTools[_i] = arguments[_i];
|
|
1989
|
+
}
|
|
1990
|
+
this.llmExecutionTools = llmExecutionTools;
|
|
2431
1991
|
}
|
|
2432
1992
|
Object.defineProperty(MultipleLlmExecutionTools.prototype, "title", {
|
|
2433
1993
|
get: function () {
|
|
@@ -2704,79 +2264,258 @@
|
|
|
2704
2264
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2705
2265
|
*/
|
|
2706
2266
|
|
|
2267
|
+
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## Sample\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"}];
|
|
2268
|
+
|
|
2707
2269
|
/**
|
|
2708
|
-
*
|
|
2709
|
-
*
|
|
2710
|
-
* 1) Any item except array and undefined returns array with that one item (also null)
|
|
2711
|
-
* 2) Undefined returns empty array
|
|
2712
|
-
* 3) Array returns itself
|
|
2270
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2713
2271
|
*
|
|
2714
|
-
* @
|
|
2272
|
+
* @public exported from `@promptbook/core`
|
|
2715
2273
|
*/
|
|
2716
|
-
function
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2274
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
2275
|
+
__extends(CollectionError, _super);
|
|
2276
|
+
function CollectionError(message) {
|
|
2277
|
+
var _this = _super.call(this, message) || this;
|
|
2278
|
+
_this.name = 'CollectionError';
|
|
2279
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
2280
|
+
return _this;
|
|
2722
2281
|
}
|
|
2723
|
-
return
|
|
2724
|
-
}
|
|
2282
|
+
return CollectionError;
|
|
2283
|
+
}(Error));
|
|
2725
2284
|
|
|
2726
2285
|
/**
|
|
2727
|
-
*
|
|
2286
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
2728
2287
|
*
|
|
2729
|
-
* @
|
|
2730
|
-
* @returns the list of variable names
|
|
2731
|
-
* @throws {ParseError} if the script is invalid
|
|
2732
|
-
* @public exported from `@promptbook/utils`
|
|
2288
|
+
* @public exported from `@promptbook/core`
|
|
2733
2289
|
*/
|
|
2734
|
-
function
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
}
|
|
2742
|
-
catch (error) {
|
|
2743
|
-
if (!(error instanceof ReferenceError)) {
|
|
2744
|
-
throw error;
|
|
2745
|
-
}
|
|
2746
|
-
var undefinedName = error.message.split(' ')[0];
|
|
2747
|
-
/*
|
|
2748
|
-
Note: Parsing the error
|
|
2749
|
-
[PipelineUrlError: thing is not defined]
|
|
2750
|
-
*/
|
|
2751
|
-
if (!undefinedName) {
|
|
2752
|
-
throw error;
|
|
2753
|
-
}
|
|
2754
|
-
if (script.includes(undefinedName + '(')) {
|
|
2755
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2756
|
-
}
|
|
2757
|
-
else {
|
|
2758
|
-
variables.add(undefinedName);
|
|
2759
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2760
|
-
}
|
|
2761
|
-
}
|
|
2762
|
-
}
|
|
2763
|
-
catch (error) {
|
|
2764
|
-
if (!(error instanceof Error)) {
|
|
2765
|
-
throw error;
|
|
2766
|
-
}
|
|
2767
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
2290
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
2291
|
+
__extends(EnvironmentMismatchError, _super);
|
|
2292
|
+
function EnvironmentMismatchError(message) {
|
|
2293
|
+
var _this = _super.call(this, message) || this;
|
|
2294
|
+
_this.name = 'EnvironmentMismatchError';
|
|
2295
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
2296
|
+
return _this;
|
|
2768
2297
|
}
|
|
2769
|
-
return
|
|
2770
|
-
}
|
|
2298
|
+
return EnvironmentMismatchError;
|
|
2299
|
+
}(Error));
|
|
2300
|
+
|
|
2771
2301
|
/**
|
|
2772
|
-
*
|
|
2302
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
2303
|
+
*
|
|
2304
|
+
* @public exported from `@promptbook/core`
|
|
2305
|
+
* Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
|
|
2306
|
+
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
2307
|
+
* Note: This is a kindof subtype of PipelineExecutionError
|
|
2773
2308
|
*/
|
|
2309
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
2310
|
+
__extends(ExpectError, _super);
|
|
2311
|
+
function ExpectError(message) {
|
|
2312
|
+
var _this = _super.call(this, message) || this;
|
|
2313
|
+
_this.name = 'ExpectError';
|
|
2314
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
2315
|
+
return _this;
|
|
2316
|
+
}
|
|
2317
|
+
return ExpectError;
|
|
2318
|
+
}(Error));
|
|
2774
2319
|
|
|
2775
2320
|
/**
|
|
2776
|
-
*
|
|
2321
|
+
* This error type indicates that some limit was reached
|
|
2777
2322
|
*
|
|
2778
|
-
* @
|
|
2779
|
-
|
|
2323
|
+
* @public exported from `@promptbook/core`
|
|
2324
|
+
*/
|
|
2325
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
2326
|
+
__extends(LimitReachedError, _super);
|
|
2327
|
+
function LimitReachedError(message) {
|
|
2328
|
+
var _this = _super.call(this, message) || this;
|
|
2329
|
+
_this.name = 'LimitReachedError';
|
|
2330
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2331
|
+
return _this;
|
|
2332
|
+
}
|
|
2333
|
+
return LimitReachedError;
|
|
2334
|
+
}(Error));
|
|
2335
|
+
|
|
2336
|
+
/**
|
|
2337
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
2338
|
+
*
|
|
2339
|
+
* @public exported from `@promptbook/core`
|
|
2340
|
+
*/
|
|
2341
|
+
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
2342
|
+
__extends(NotYetImplementedError, _super);
|
|
2343
|
+
function NotYetImplementedError(message) {
|
|
2344
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
2345
|
+
_this.name = 'NotYetImplementedError';
|
|
2346
|
+
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
2347
|
+
return _this;
|
|
2348
|
+
}
|
|
2349
|
+
return NotYetImplementedError;
|
|
2350
|
+
}(Error));
|
|
2351
|
+
|
|
2352
|
+
/**
|
|
2353
|
+
* Index of all custom errors
|
|
2354
|
+
*
|
|
2355
|
+
* @public exported from `@promptbook/core`
|
|
2356
|
+
*/
|
|
2357
|
+
var ERRORS = {
|
|
2358
|
+
ExpectError: ExpectError,
|
|
2359
|
+
CollectionError: CollectionError,
|
|
2360
|
+
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
2361
|
+
LimitReachedError: LimitReachedError,
|
|
2362
|
+
NotFoundError: NotFoundError,
|
|
2363
|
+
NotYetImplementedError: NotYetImplementedError,
|
|
2364
|
+
ParseError: ParseError,
|
|
2365
|
+
PipelineExecutionError: PipelineExecutionError,
|
|
2366
|
+
PipelineLogicError: PipelineLogicError,
|
|
2367
|
+
PipelineUrlError: PipelineUrlError,
|
|
2368
|
+
UnexpectedError: UnexpectedError,
|
|
2369
|
+
// TODO: [🪑]> VersionMismatchError,
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
/**
|
|
2373
|
+
* Deserializes the error object
|
|
2374
|
+
*
|
|
2375
|
+
* @public exported from `@promptbook/utils`
|
|
2376
|
+
*/
|
|
2377
|
+
function deserializeError(error) {
|
|
2378
|
+
if (error.name === 'Error') {
|
|
2379
|
+
return new Error(error.message);
|
|
2380
|
+
}
|
|
2381
|
+
var CustomError = ERRORS[error.name];
|
|
2382
|
+
return new CustomError(error.message);
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
/**
|
|
2386
|
+
* Asserts that the execution of a Promptbook is successful
|
|
2387
|
+
*
|
|
2388
|
+
* @param executionResult - The partial result of the Promptbook execution
|
|
2389
|
+
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2390
|
+
* @public exported from `@promptbook/core`
|
|
2391
|
+
*/
|
|
2392
|
+
function assertsExecutionSuccessful(executionResult) {
|
|
2393
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
2394
|
+
if (isSuccessful === true) {
|
|
2395
|
+
return;
|
|
2396
|
+
}
|
|
2397
|
+
if (errors.length === 0) {
|
|
2398
|
+
throw new PipelineExecutionError("Promptbook Execution failed because of unknown reason");
|
|
2399
|
+
}
|
|
2400
|
+
else if (errors.length === 1) {
|
|
2401
|
+
throw deserializeError(errors[0]);
|
|
2402
|
+
}
|
|
2403
|
+
else {
|
|
2404
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
|
|
2405
|
+
.map(function (_a, index) {
|
|
2406
|
+
var name = _a.name, stack = _a.stack, message = _a.message;
|
|
2407
|
+
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
|
|
2408
|
+
})
|
|
2409
|
+
.join('\n')), "\n "); }));
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
/**
|
|
2413
|
+
* TODO: [🧠] Can this return type be better typed than void
|
|
2414
|
+
*/
|
|
2415
|
+
|
|
2416
|
+
/**
|
|
2417
|
+
* Determine if the pipeline is fully prepared
|
|
2418
|
+
*
|
|
2419
|
+
* @public exported from `@promptbook/core`
|
|
2420
|
+
*/
|
|
2421
|
+
function isPipelinePrepared(pipeline) {
|
|
2422
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2423
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2424
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2425
|
+
return false;
|
|
2426
|
+
}
|
|
2427
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2428
|
+
return false;
|
|
2429
|
+
}
|
|
2430
|
+
/*
|
|
2431
|
+
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2432
|
+
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2433
|
+
> return false;
|
|
2434
|
+
> }
|
|
2435
|
+
*/
|
|
2436
|
+
return true;
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* TODO: [🔃][main] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2440
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2441
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2442
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2443
|
+
* - [🏍] ? Is context in each template
|
|
2444
|
+
* - [♨] Are samples prepared
|
|
2445
|
+
* - [♨] Are templates prepared
|
|
2446
|
+
*/
|
|
2447
|
+
|
|
2448
|
+
/**
|
|
2449
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2450
|
+
*
|
|
2451
|
+
* @public exported from `@promptbook/utils`
|
|
2452
|
+
*/
|
|
2453
|
+
function serializeError(error) {
|
|
2454
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2455
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2456
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2457
|
+
}
|
|
2458
|
+
return {
|
|
2459
|
+
name: name,
|
|
2460
|
+
message: message,
|
|
2461
|
+
stack: stack,
|
|
2462
|
+
};
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
/**
|
|
2466
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
2467
|
+
*
|
|
2468
|
+
* @param script from which to extract the variables
|
|
2469
|
+
* @returns the list of variable names
|
|
2470
|
+
* @throws {ParseError} if the script is invalid
|
|
2471
|
+
* @public exported from `@promptbook/utils`
|
|
2472
|
+
*/
|
|
2473
|
+
function extractVariables(script) {
|
|
2474
|
+
var variables = new Set();
|
|
2475
|
+
script = "(()=>{".concat(script, "})()");
|
|
2476
|
+
try {
|
|
2477
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2478
|
+
try {
|
|
2479
|
+
eval(script);
|
|
2480
|
+
}
|
|
2481
|
+
catch (error) {
|
|
2482
|
+
if (!(error instanceof ReferenceError)) {
|
|
2483
|
+
throw error;
|
|
2484
|
+
}
|
|
2485
|
+
var undefinedName = error.message.split(' ')[0];
|
|
2486
|
+
/*
|
|
2487
|
+
Note: Parsing the error
|
|
2488
|
+
[PipelineUrlError: thing is not defined]
|
|
2489
|
+
*/
|
|
2490
|
+
if (!undefinedName) {
|
|
2491
|
+
throw error;
|
|
2492
|
+
}
|
|
2493
|
+
if (script.includes(undefinedName + '(')) {
|
|
2494
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2495
|
+
}
|
|
2496
|
+
else {
|
|
2497
|
+
variables.add(undefinedName);
|
|
2498
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
catch (error) {
|
|
2503
|
+
if (!(error instanceof Error)) {
|
|
2504
|
+
throw error;
|
|
2505
|
+
}
|
|
2506
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
2507
|
+
}
|
|
2508
|
+
return variables;
|
|
2509
|
+
}
|
|
2510
|
+
/**
|
|
2511
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
2512
|
+
*/
|
|
2513
|
+
|
|
2514
|
+
/**
|
|
2515
|
+
* Parses the template and returns the set of all used parameters
|
|
2516
|
+
*
|
|
2517
|
+
* @param template the template with used parameters
|
|
2518
|
+
* @returns the set of parameter names
|
|
2780
2519
|
* @throws {ParseError} if the script is invalid
|
|
2781
2520
|
* @public exported from `@promptbook/utils`
|
|
2782
2521
|
*/
|
|
@@ -2830,7 +2569,7 @@
|
|
|
2830
2569
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2831
2570
|
if (foreach !== undefined) {
|
|
2832
2571
|
try {
|
|
2833
|
-
for (var _l = __values(foreach.
|
|
2572
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
2834
2573
|
var subparameterName = _m.value;
|
|
2835
2574
|
if (parameterNames.has(subparameterName)) {
|
|
2836
2575
|
parameterNames.delete(subparameterName);
|
|
@@ -2945,6 +2684,42 @@
|
|
|
2945
2684
|
}
|
|
2946
2685
|
}
|
|
2947
2686
|
|
|
2687
|
+
/**
|
|
2688
|
+
* This error indicates problems parsing the format value
|
|
2689
|
+
*
|
|
2690
|
+
* For example, when the format value is not a valid JSON or CSV
|
|
2691
|
+
* This is not thrown directly but in extended classes
|
|
2692
|
+
*
|
|
2693
|
+
* @public exported from `@promptbook/core`
|
|
2694
|
+
*/
|
|
2695
|
+
var AbstractFormatError = /** @class */ (function (_super) {
|
|
2696
|
+
__extends(AbstractFormatError, _super);
|
|
2697
|
+
// Note: To allow instanceof do not put here error `name`
|
|
2698
|
+
// public readonly name = 'AbstractFormatError';
|
|
2699
|
+
function AbstractFormatError(message) {
|
|
2700
|
+
var _this = _super.call(this, message) || this;
|
|
2701
|
+
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
2702
|
+
return _this;
|
|
2703
|
+
}
|
|
2704
|
+
return AbstractFormatError;
|
|
2705
|
+
}(Error));
|
|
2706
|
+
|
|
2707
|
+
/**
|
|
2708
|
+
* This error indicates problem with parsing of CSV
|
|
2709
|
+
*
|
|
2710
|
+
* @public exported from `@promptbook/core`
|
|
2711
|
+
*/
|
|
2712
|
+
var CsvFormatError = /** @class */ (function (_super) {
|
|
2713
|
+
__extends(CsvFormatError, _super);
|
|
2714
|
+
function CsvFormatError(message) {
|
|
2715
|
+
var _this = _super.call(this, message) || this;
|
|
2716
|
+
_this.name = 'CsvFormatError';
|
|
2717
|
+
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
2718
|
+
return _this;
|
|
2719
|
+
}
|
|
2720
|
+
return CsvFormatError;
|
|
2721
|
+
}(AbstractFormatError));
|
|
2722
|
+
|
|
2948
2723
|
/**
|
|
2949
2724
|
* @@@
|
|
2950
2725
|
*
|
|
@@ -2952,7 +2727,7 @@
|
|
|
2952
2727
|
*/
|
|
2953
2728
|
var MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
2954
2729
|
header: true,
|
|
2955
|
-
// encoding: '
|
|
2730
|
+
// encoding: 'utf-8',
|
|
2956
2731
|
});
|
|
2957
2732
|
|
|
2958
2733
|
/**
|
|
@@ -2965,7 +2740,7 @@
|
|
|
2965
2740
|
formatName: 'CSV',
|
|
2966
2741
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
2967
2742
|
isValid: function (value, settings, schema) {
|
|
2968
|
-
// TODO:
|
|
2743
|
+
// TODO: Implement CSV validation
|
|
2969
2744
|
TODO_USE(value /* <- TODO: Use value here */);
|
|
2970
2745
|
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
2971
2746
|
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
@@ -2986,7 +2761,7 @@
|
|
|
2986
2761
|
subvalueDefinitions: [
|
|
2987
2762
|
{
|
|
2988
2763
|
subvalueName: 'ROW',
|
|
2989
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2764
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2990
2765
|
return __awaiter(this, void 0, void 0, function () {
|
|
2991
2766
|
var csv, mappedData;
|
|
2992
2767
|
var _this = this;
|
|
@@ -2995,24 +2770,22 @@
|
|
|
2995
2770
|
case 0:
|
|
2996
2771
|
csv = papaparse.parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
2997
2772
|
if (csv.errors.length !== 0) {
|
|
2998
|
-
throw new
|
|
2999
|
-
spaceTrim__default["default"](function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2773
|
+
throw new CsvFormatError(spaceTrim__default["default"](function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
3000
2774
|
}
|
|
3001
2775
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3002
|
-
var _a;
|
|
3003
|
-
var
|
|
3004
|
-
return __generator(this, function (
|
|
3005
|
-
switch (
|
|
2776
|
+
var _a, _b;
|
|
2777
|
+
var _c;
|
|
2778
|
+
return __generator(this, function (_d) {
|
|
2779
|
+
switch (_d.label) {
|
|
3006
2780
|
case 0:
|
|
2781
|
+
if (row[outputParameterName]) {
|
|
2782
|
+
throw new CsvFormatError("Can not overwrite existing column \"".concat(outputParameterName, "\" in CSV row"));
|
|
2783
|
+
}
|
|
3007
2784
|
_a = [__assign({}, row)];
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
// <- TODO: !!!!!! Check name collisions
|
|
2785
|
+
_c = {};
|
|
2786
|
+
_b = outputParameterName;
|
|
3011
2787
|
return [4 /*yield*/, mapCallback(row, index)];
|
|
3012
|
-
case 1: return [2 /*return*/,
|
|
3013
|
-
// <- TODO: !!!!!! Dynamic new column name and position
|
|
3014
|
-
// <- TODO: !!!!!! Check name collisions
|
|
3015
|
-
_c.sent(), _b)])))];
|
|
2788
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c[_b] = _d.sent(), _c)]))];
|
|
3016
2789
|
}
|
|
3017
2790
|
});
|
|
3018
2791
|
}); }))];
|
|
@@ -3026,7 +2799,7 @@
|
|
|
3026
2799
|
},
|
|
3027
2800
|
{
|
|
3028
2801
|
subvalueName: 'CELL',
|
|
3029
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2802
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
3030
2803
|
return __awaiter(this, void 0, void 0, function () {
|
|
3031
2804
|
var csv, mappedData;
|
|
3032
2805
|
var _this = this;
|
|
@@ -3035,8 +2808,7 @@
|
|
|
3035
2808
|
case 0:
|
|
3036
2809
|
csv = papaparse.parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
3037
2810
|
if (csv.errors.length !== 0) {
|
|
3038
|
-
throw new
|
|
3039
|
-
spaceTrim__default["default"](function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2811
|
+
throw new CsvFormatError(spaceTrim__default["default"](function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
3040
2812
|
}
|
|
3041
2813
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, rowIndex) { return __awaiter(_this, void 0, void 0, function () {
|
|
3042
2814
|
var _this = this;
|
|
@@ -3153,7 +2925,7 @@
|
|
|
3153
2925
|
subvalueDefinitions: [
|
|
3154
2926
|
{
|
|
3155
2927
|
subvalueName: 'LINE',
|
|
3156
|
-
mapValues: function (value, settings, mapCallback) {
|
|
2928
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
3157
2929
|
return __awaiter(this, void 0, void 0, function () {
|
|
3158
2930
|
var lines, mappedLines;
|
|
3159
2931
|
return __generator(this, function (_a) {
|
|
@@ -3425,6 +3197,25 @@
|
|
|
3425
3197
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
3426
3198
|
*/
|
|
3427
3199
|
|
|
3200
|
+
/**
|
|
3201
|
+
* Takes an item or an array of items and returns an array of items
|
|
3202
|
+
*
|
|
3203
|
+
* 1) Any item except array and undefined returns array with that one item (also null)
|
|
3204
|
+
* 2) Undefined returns empty array
|
|
3205
|
+
* 3) Array returns itself
|
|
3206
|
+
*
|
|
3207
|
+
* @private internal utility
|
|
3208
|
+
*/
|
|
3209
|
+
function arrayableToArray(input) {
|
|
3210
|
+
if (input === undefined) {
|
|
3211
|
+
return [];
|
|
3212
|
+
}
|
|
3213
|
+
if (input instanceof Array) {
|
|
3214
|
+
return input;
|
|
3215
|
+
}
|
|
3216
|
+
return [input];
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3428
3219
|
/**
|
|
3429
3220
|
* Just says that the variable is not used but should be kept
|
|
3430
3221
|
* No side effects.
|
|
@@ -3590,69 +3381,330 @@
|
|
|
3590
3381
|
return splitIntoSentences(text).length;
|
|
3591
3382
|
}
|
|
3592
3383
|
|
|
3384
|
+
var defaultDiacriticsRemovalMap = [
|
|
3385
|
+
{
|
|
3386
|
+
base: 'A',
|
|
3387
|
+
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
3388
|
+
},
|
|
3389
|
+
{ base: 'AA', letters: '\uA732' },
|
|
3390
|
+
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
3391
|
+
{ base: 'AO', letters: '\uA734' },
|
|
3392
|
+
{ base: 'AU', letters: '\uA736' },
|
|
3393
|
+
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
3394
|
+
{ base: 'AY', letters: '\uA73C' },
|
|
3395
|
+
{
|
|
3396
|
+
base: 'B',
|
|
3397
|
+
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
3398
|
+
},
|
|
3399
|
+
{
|
|
3400
|
+
base: 'C',
|
|
3401
|
+
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
3402
|
+
},
|
|
3403
|
+
{
|
|
3404
|
+
base: 'D',
|
|
3405
|
+
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
3406
|
+
},
|
|
3407
|
+
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
3408
|
+
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
3409
|
+
{
|
|
3410
|
+
base: 'E',
|
|
3411
|
+
letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
|
|
3412
|
+
},
|
|
3413
|
+
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
3414
|
+
{
|
|
3415
|
+
base: 'G',
|
|
3416
|
+
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
3417
|
+
},
|
|
3418
|
+
{
|
|
3419
|
+
base: 'H',
|
|
3420
|
+
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
3421
|
+
},
|
|
3422
|
+
{
|
|
3423
|
+
base: 'I',
|
|
3424
|
+
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
3425
|
+
},
|
|
3426
|
+
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
3427
|
+
{
|
|
3428
|
+
base: 'K',
|
|
3429
|
+
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
3430
|
+
},
|
|
3431
|
+
{
|
|
3432
|
+
base: 'L',
|
|
3433
|
+
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
3434
|
+
},
|
|
3435
|
+
{ base: 'LJ', letters: '\u01C7' },
|
|
3436
|
+
{ base: 'Lj', letters: '\u01C8' },
|
|
3437
|
+
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
3438
|
+
{
|
|
3439
|
+
base: 'N',
|
|
3440
|
+
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
3441
|
+
},
|
|
3442
|
+
{ base: 'NJ', letters: '\u01CA' },
|
|
3443
|
+
{ base: 'Nj', letters: '\u01CB' },
|
|
3444
|
+
{
|
|
3445
|
+
base: 'O',
|
|
3446
|
+
letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
|
|
3447
|
+
},
|
|
3448
|
+
{ base: 'OI', letters: '\u01A2' },
|
|
3449
|
+
{ base: 'OO', letters: '\uA74E' },
|
|
3450
|
+
{ base: 'OU', letters: '\u0222' },
|
|
3451
|
+
{ base: 'OE', letters: '\u008C\u0152' },
|
|
3452
|
+
{ base: 'oe', letters: '\u009C\u0153' },
|
|
3453
|
+
{
|
|
3454
|
+
base: 'P',
|
|
3455
|
+
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
3456
|
+
},
|
|
3457
|
+
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
3458
|
+
{
|
|
3459
|
+
base: 'R',
|
|
3460
|
+
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
3461
|
+
},
|
|
3462
|
+
{
|
|
3463
|
+
base: 'S',
|
|
3464
|
+
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
3465
|
+
},
|
|
3466
|
+
{
|
|
3467
|
+
base: 'T',
|
|
3468
|
+
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
3469
|
+
},
|
|
3470
|
+
{ base: 'TZ', letters: '\uA728' },
|
|
3471
|
+
{
|
|
3472
|
+
base: 'U',
|
|
3473
|
+
letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
|
|
3474
|
+
},
|
|
3475
|
+
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
3476
|
+
{ base: 'VY', letters: '\uA760' },
|
|
3477
|
+
{
|
|
3478
|
+
base: 'W',
|
|
3479
|
+
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
3480
|
+
},
|
|
3481
|
+
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
3482
|
+
{
|
|
3483
|
+
base: 'Y',
|
|
3484
|
+
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
3485
|
+
},
|
|
3486
|
+
{
|
|
3487
|
+
base: 'Z',
|
|
3488
|
+
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
3489
|
+
},
|
|
3490
|
+
{
|
|
3491
|
+
base: 'a',
|
|
3492
|
+
letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
|
|
3493
|
+
},
|
|
3494
|
+
{ base: 'aa', letters: '\uA733' },
|
|
3495
|
+
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
3496
|
+
{ base: 'ao', letters: '\uA735' },
|
|
3497
|
+
{ base: 'au', letters: '\uA737' },
|
|
3498
|
+
{ base: 'av', letters: '\uA739\uA73B' },
|
|
3499
|
+
{ base: 'ay', letters: '\uA73D' },
|
|
3500
|
+
{
|
|
3501
|
+
base: 'b',
|
|
3502
|
+
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
3503
|
+
},
|
|
3504
|
+
{
|
|
3505
|
+
base: 'c',
|
|
3506
|
+
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
3507
|
+
},
|
|
3508
|
+
{
|
|
3509
|
+
base: 'd',
|
|
3510
|
+
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
3511
|
+
},
|
|
3512
|
+
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
3513
|
+
{
|
|
3514
|
+
base: 'e',
|
|
3515
|
+
letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
|
|
3516
|
+
},
|
|
3517
|
+
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
3518
|
+
{
|
|
3519
|
+
base: 'g',
|
|
3520
|
+
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
3521
|
+
},
|
|
3522
|
+
{
|
|
3523
|
+
base: 'h',
|
|
3524
|
+
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
3525
|
+
},
|
|
3526
|
+
{ base: 'hv', letters: '\u0195' },
|
|
3527
|
+
{
|
|
3528
|
+
base: 'i',
|
|
3529
|
+
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
3530
|
+
},
|
|
3531
|
+
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
3532
|
+
{
|
|
3533
|
+
base: 'k',
|
|
3534
|
+
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
3535
|
+
},
|
|
3536
|
+
{
|
|
3537
|
+
base: 'l',
|
|
3538
|
+
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
3539
|
+
},
|
|
3540
|
+
{ base: 'lj', letters: '\u01C9' },
|
|
3541
|
+
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
3542
|
+
{
|
|
3543
|
+
base: 'n',
|
|
3544
|
+
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
3545
|
+
},
|
|
3546
|
+
{ base: 'nj', letters: '\u01CC' },
|
|
3547
|
+
{
|
|
3548
|
+
base: 'o',
|
|
3549
|
+
letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
|
|
3550
|
+
},
|
|
3551
|
+
{ base: 'oi', letters: '\u01A3' },
|
|
3552
|
+
{ base: 'ou', letters: '\u0223' },
|
|
3553
|
+
{ base: 'oo', letters: '\uA74F' },
|
|
3554
|
+
{
|
|
3555
|
+
base: 'p',
|
|
3556
|
+
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
3557
|
+
},
|
|
3558
|
+
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
3559
|
+
{
|
|
3560
|
+
base: 'r',
|
|
3561
|
+
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
3562
|
+
},
|
|
3563
|
+
{
|
|
3564
|
+
base: 's',
|
|
3565
|
+
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
3566
|
+
},
|
|
3567
|
+
{
|
|
3568
|
+
base: 't',
|
|
3569
|
+
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
3570
|
+
},
|
|
3571
|
+
{ base: 'tz', letters: '\uA729' },
|
|
3572
|
+
{
|
|
3573
|
+
base: 'u',
|
|
3574
|
+
letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
|
|
3575
|
+
},
|
|
3576
|
+
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
3577
|
+
{ base: 'vy', letters: '\uA761' },
|
|
3578
|
+
{
|
|
3579
|
+
base: 'w',
|
|
3580
|
+
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
3581
|
+
},
|
|
3582
|
+
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
3583
|
+
{
|
|
3584
|
+
base: 'y',
|
|
3585
|
+
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
3586
|
+
},
|
|
3587
|
+
{
|
|
3588
|
+
base: 'z',
|
|
3589
|
+
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
3590
|
+
},
|
|
3591
|
+
];
|
|
3593
3592
|
/**
|
|
3594
|
-
*
|
|
3595
|
-
*
|
|
3596
|
-
* @public exported from `@promptbook/utils`
|
|
3597
|
-
*/
|
|
3598
|
-
function countWords(text) {
|
|
3599
|
-
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
3600
|
-
text = removeDiacritics(text);
|
|
3601
|
-
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
3602
|
-
}
|
|
3603
|
-
|
|
3604
|
-
/**
|
|
3605
|
-
* Index of all counter functions
|
|
3606
|
-
*
|
|
3607
|
-
* @public exported from `@promptbook/utils`
|
|
3608
|
-
*/
|
|
3609
|
-
var CountUtils = {
|
|
3610
|
-
CHARACTERS: countCharacters,
|
|
3611
|
-
WORDS: countWords,
|
|
3612
|
-
SENTENCES: countSentences,
|
|
3613
|
-
PARAGRAPHS: countParagraphs,
|
|
3614
|
-
LINES: countLines,
|
|
3615
|
-
PAGES: countPages,
|
|
3616
|
-
};
|
|
3617
|
-
/**
|
|
3618
|
-
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
3619
|
-
*/
|
|
3620
|
-
|
|
3621
|
-
/**
|
|
3622
|
-
* Function checkExpectations will check if the expectations on given value are met
|
|
3593
|
+
* Map of letters from diacritic variant to diacritless variant
|
|
3594
|
+
* Contains lowercase and uppercase separatelly
|
|
3623
3595
|
*
|
|
3624
|
-
*
|
|
3625
|
-
*
|
|
3626
|
-
*
|
|
3596
|
+
* > "á" => "a"
|
|
3597
|
+
* > "ě" => "e"
|
|
3598
|
+
* > "Ă" => "A"
|
|
3599
|
+
* > ...
|
|
3627
3600
|
*
|
|
3628
|
-
* @
|
|
3629
|
-
* @returns {void} Nothing
|
|
3630
|
-
* @private internal function of `createPipelineExecutor`
|
|
3601
|
+
* @public exported from `@promptbook/utils`
|
|
3631
3602
|
*/
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
|
|
3640
|
-
} /* not else */
|
|
3641
|
-
if (max && amount > max) {
|
|
3642
|
-
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
3643
|
-
}
|
|
3644
|
-
}
|
|
3645
|
-
}
|
|
3646
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3647
|
-
finally {
|
|
3648
|
-
try {
|
|
3649
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3650
|
-
}
|
|
3651
|
-
finally { if (e_1) throw e_1.error; }
|
|
3603
|
+
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
3604
|
+
// tslint:disable-next-line: prefer-for-of
|
|
3605
|
+
for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
3606
|
+
var letters = defaultDiacriticsRemovalMap[i].letters;
|
|
3607
|
+
// tslint:disable-next-line: prefer-for-of
|
|
3608
|
+
for (var j = 0; j < letters.length; j++) {
|
|
3609
|
+
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
3652
3610
|
}
|
|
3653
3611
|
}
|
|
3654
|
-
|
|
3655
|
-
|
|
3612
|
+
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
3613
|
+
/*
|
|
3614
|
+
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
3615
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
3616
|
+
you may not use this file except in compliance with the License.
|
|
3617
|
+
You may obtain a copy of the License at
|
|
3618
|
+
|
|
3619
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
3620
|
+
|
|
3621
|
+
Unless required by applicable law or agreed to in writing, software
|
|
3622
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
3623
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3624
|
+
See the License for the specific language governing permissions and
|
|
3625
|
+
limitations under the License.
|
|
3626
|
+
*/
|
|
3627
|
+
|
|
3628
|
+
/**
|
|
3629
|
+
* @@@
|
|
3630
|
+
*
|
|
3631
|
+
* @param input @@@
|
|
3632
|
+
* @returns @@@
|
|
3633
|
+
* @public exported from `@promptbook/utils`
|
|
3634
|
+
*/
|
|
3635
|
+
function removeDiacritics(input) {
|
|
3636
|
+
/*eslint no-control-regex: "off"*/
|
|
3637
|
+
return input.replace(/[^\u0000-\u007E]/g, function (a) {
|
|
3638
|
+
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
3639
|
+
});
|
|
3640
|
+
}
|
|
3641
|
+
/**
|
|
3642
|
+
* TODO: [Ж] Variant for cyrillic (and in general non-latin) letters
|
|
3643
|
+
*/
|
|
3644
|
+
|
|
3645
|
+
/**
|
|
3646
|
+
* Counts number of words in the text
|
|
3647
|
+
*
|
|
3648
|
+
* @public exported from `@promptbook/utils`
|
|
3649
|
+
*/
|
|
3650
|
+
function countWords(text) {
|
|
3651
|
+
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
3652
|
+
text = removeDiacritics(text);
|
|
3653
|
+
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
3654
|
+
}
|
|
3655
|
+
|
|
3656
|
+
/**
|
|
3657
|
+
* Index of all counter functions
|
|
3658
|
+
*
|
|
3659
|
+
* @public exported from `@promptbook/utils`
|
|
3660
|
+
*/
|
|
3661
|
+
var CountUtils = {
|
|
3662
|
+
CHARACTERS: countCharacters,
|
|
3663
|
+
WORDS: countWords,
|
|
3664
|
+
SENTENCES: countSentences,
|
|
3665
|
+
PARAGRAPHS: countParagraphs,
|
|
3666
|
+
LINES: countLines,
|
|
3667
|
+
PAGES: countPages,
|
|
3668
|
+
};
|
|
3669
|
+
/**
|
|
3670
|
+
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
3671
|
+
*/
|
|
3672
|
+
|
|
3673
|
+
/**
|
|
3674
|
+
* Function checkExpectations will check if the expectations on given value are met
|
|
3675
|
+
*
|
|
3676
|
+
* Note: There are two simmilar functions:
|
|
3677
|
+
* - `checkExpectations` which throws an error if the expectations are not met
|
|
3678
|
+
* - `isPassingExpectations` which returns a boolean
|
|
3679
|
+
*
|
|
3680
|
+
* @throws {ExpectError} if the expectations are not met
|
|
3681
|
+
* @returns {void} Nothing
|
|
3682
|
+
* @private internal function of `createPipelineExecutor`
|
|
3683
|
+
*/
|
|
3684
|
+
function checkExpectations(expectations, value) {
|
|
3685
|
+
var e_1, _a;
|
|
3686
|
+
try {
|
|
3687
|
+
for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3688
|
+
var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
|
|
3689
|
+
var amount = CountUtils[unit.toUpperCase()](value);
|
|
3690
|
+
if (min && amount < min) {
|
|
3691
|
+
throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
|
|
3692
|
+
} /* not else */
|
|
3693
|
+
if (max && amount > max) {
|
|
3694
|
+
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
3695
|
+
}
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3699
|
+
finally {
|
|
3700
|
+
try {
|
|
3701
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3702
|
+
}
|
|
3703
|
+
finally { if (e_1) throw e_1.error; }
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
/**
|
|
3707
|
+
* Function checkExpectations will check if the expectations on given value are met
|
|
3656
3708
|
*
|
|
3657
3709
|
* Note: There are two simmilar functions:
|
|
3658
3710
|
* - `checkExpectations` which throws an error if the expectations are not met
|
|
@@ -3686,11 +3738,11 @@
|
|
|
3686
3738
|
*/
|
|
3687
3739
|
function executeAttempts(options) {
|
|
3688
3740
|
return __awaiter(this, void 0, void 0, function () {
|
|
3689
|
-
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools,
|
|
3741
|
+
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTemplateResult, _llms, llmTools, _loop_1, attempt, state_1;
|
|
3690
3742
|
return __generator(this, function (_a) {
|
|
3691
3743
|
switch (_a.label) {
|
|
3692
3744
|
case 0:
|
|
3693
|
-
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools,
|
|
3745
|
+
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
|
|
3694
3746
|
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3695
3747
|
$ongoingTemplateResult = {
|
|
3696
3748
|
$result: null,
|
|
@@ -3698,6 +3750,8 @@
|
|
|
3698
3750
|
$expectError: null,
|
|
3699
3751
|
$scriptPipelineExecutionErrors: [],
|
|
3700
3752
|
};
|
|
3753
|
+
_llms = arrayableToArray(tools.llm);
|
|
3754
|
+
llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
|
|
3701
3755
|
_loop_1 = function (attempt) {
|
|
3702
3756
|
var isJokerAttempt, jokerParameterName, _b, modelRequirements, _c, _d, _e, _f, _g, scriptTools, _h, error_1, e_1_1, _j, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, _p, error_2, e_2_1, e_3_1, error_3;
|
|
3703
3757
|
var e_1, _q, e_3, _r, e_2, _s;
|
|
@@ -3743,7 +3797,9 @@
|
|
|
3743
3797
|
title: template.title,
|
|
3744
3798
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3745
3799
|
? preparedPipeline.pipelineUrl
|
|
3746
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name
|
|
3800
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name
|
|
3801
|
+
// <- TODO: Here should be maybe also subformat index to distinguish between same template with different subformat values
|
|
3802
|
+
),
|
|
3747
3803
|
parameters: parameters,
|
|
3748
3804
|
content: preparedContent,
|
|
3749
3805
|
modelRequirements: modelRequirements,
|
|
@@ -3764,7 +3820,9 @@
|
|
|
3764
3820
|
return [3 /*break*/, 9];
|
|
3765
3821
|
case 4:
|
|
3766
3822
|
_d = $ongoingTemplateResult;
|
|
3767
|
-
return [4 /*yield*/, llmTools.callChatModel(
|
|
3823
|
+
return [4 /*yield*/, llmTools.callChatModel(
|
|
3824
|
+
// <- TODO: [🧁] Check that `callChatModel` is defined
|
|
3825
|
+
$deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3768
3826
|
case 5:
|
|
3769
3827
|
_d.$chatResult = _t.sent();
|
|
3770
3828
|
// TODO: [🍬] Destroy chatThread
|
|
@@ -3773,7 +3831,9 @@
|
|
|
3773
3831
|
return [3 /*break*/, 10];
|
|
3774
3832
|
case 6:
|
|
3775
3833
|
_e = $ongoingTemplateResult;
|
|
3776
|
-
return [4 /*yield*/, llmTools.callCompletionModel(
|
|
3834
|
+
return [4 /*yield*/, llmTools.callCompletionModel(
|
|
3835
|
+
// <- TODO: [🧁] Check that `callCompletionModel` is defined
|
|
3836
|
+
$deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3777
3837
|
case 7:
|
|
3778
3838
|
_e.$completionResult = _t.sent();
|
|
3779
3839
|
$ongoingTemplateResult.$result = $ongoingTemplateResult.$completionResult;
|
|
@@ -4047,7 +4107,7 @@
|
|
|
4047
4107
|
*
|
|
4048
4108
|
* @private internal utility of `createPipelineExecutor`
|
|
4049
4109
|
*/
|
|
4050
|
-
function
|
|
4110
|
+
function executeFormatSubvalues(options) {
|
|
4051
4111
|
return __awaiter(this, void 0, void 0, function () {
|
|
4052
4112
|
var template, jokerParameterNames, parameters, priority, pipelineIdentification, settings, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
|
|
4053
4113
|
var _this = this;
|
|
@@ -4085,18 +4145,18 @@
|
|
|
4085
4145
|
}
|
|
4086
4146
|
if (formatDefinition.formatName === 'CSV') {
|
|
4087
4147
|
formatSettings = settings.csvSettings;
|
|
4088
|
-
// <- TODO:
|
|
4148
|
+
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
4089
4149
|
}
|
|
4090
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4150
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4091
4151
|
var mappedParameters, allSubparameters, subresultString;
|
|
4092
4152
|
return __generator(this, function (_a) {
|
|
4093
4153
|
switch (_a.label) {
|
|
4094
4154
|
case 0:
|
|
4095
|
-
// TODO:
|
|
4096
|
-
// TODO:
|
|
4155
|
+
// TODO: [🤹♂️][🪂] Limit to N concurrent executions
|
|
4156
|
+
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
4097
4157
|
try {
|
|
4098
4158
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
4099
|
-
expectedParameters: Object.fromEntries(template.foreach.
|
|
4159
|
+
expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
4100
4160
|
availableParameters: subparameters,
|
|
4101
4161
|
});
|
|
4102
4162
|
}
|
|
@@ -4104,12 +4164,12 @@
|
|
|
4104
4164
|
if (!(error instanceof PipelineExecutionError)) {
|
|
4105
4165
|
throw error;
|
|
4106
4166
|
}
|
|
4107
|
-
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4167
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }));
|
|
4108
4168
|
}
|
|
4109
4169
|
allSubparameters = __assign(__assign({}, parameters), mappedParameters);
|
|
4110
4170
|
// Note: [👨👨👧] Now we can freeze `subparameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
4111
4171
|
Object.freeze(allSubparameters);
|
|
4112
|
-
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: pipelineIdentification }))];
|
|
4172
|
+
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim__default["default"](function (block) { return "\n ".concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }) }))];
|
|
4113
4173
|
case 1:
|
|
4114
4174
|
subresultString = _a.sent();
|
|
4115
4175
|
return [2 /*return*/, subresultString];
|
|
@@ -4123,10 +4183,6 @@
|
|
|
4123
4183
|
});
|
|
4124
4184
|
});
|
|
4125
4185
|
}
|
|
4126
|
-
/**
|
|
4127
|
-
* TODO: !!!!!! Make pipelineIdentification more precise
|
|
4128
|
-
* TODO: !!!!!! How FOREACH execution looks in the report
|
|
4129
|
-
*/
|
|
4130
4186
|
|
|
4131
4187
|
/**
|
|
4132
4188
|
* @@@
|
|
@@ -4241,12 +4297,12 @@
|
|
|
4241
4297
|
*/
|
|
4242
4298
|
function executeTemplate(options) {
|
|
4243
4299
|
return __awaiter(this, void 0, void 0, function () {
|
|
4244
|
-
var currentTemplate, preparedPipeline, parametersToPass, tools,
|
|
4300
|
+
var currentTemplate, preparedPipeline, parametersToPass, tools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
|
|
4245
4301
|
var e_1, _f, _g;
|
|
4246
4302
|
return __generator(this, function (_h) {
|
|
4247
4303
|
switch (_h.label) {
|
|
4248
4304
|
case 0:
|
|
4249
|
-
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools,
|
|
4305
|
+
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
|
|
4250
4306
|
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
4251
4307
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
4252
4308
|
title = currentTemplate.title;
|
|
@@ -4320,7 +4376,7 @@
|
|
|
4320
4376
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
4321
4377
|
.split('{content}')
|
|
4322
4378
|
.join(currentTemplate.content);
|
|
4323
|
-
return [4 /*yield*/,
|
|
4379
|
+
return [4 /*yield*/, executeFormatSubvalues({
|
|
4324
4380
|
jokerParameterNames: jokerParameterNames,
|
|
4325
4381
|
priority: priority,
|
|
4326
4382
|
maxAttempts: maxAttempts,
|
|
@@ -4329,7 +4385,6 @@
|
|
|
4329
4385
|
template: currentTemplate,
|
|
4330
4386
|
preparedPipeline: preparedPipeline,
|
|
4331
4387
|
tools: tools,
|
|
4332
|
-
llmTools: llmTools,
|
|
4333
4388
|
settings: settings,
|
|
4334
4389
|
$executionReport: $executionReport,
|
|
4335
4390
|
pipelineIdentification: pipelineIdentification,
|
|
@@ -4360,6 +4415,9 @@
|
|
|
4360
4415
|
/**
|
|
4361
4416
|
* TODO: [🤹♂️]
|
|
4362
4417
|
*/
|
|
4418
|
+
/**
|
|
4419
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4420
|
+
*/
|
|
4363
4421
|
|
|
4364
4422
|
/**
|
|
4365
4423
|
* @@@
|
|
@@ -4408,25 +4466,24 @@
|
|
|
4408
4466
|
*/
|
|
4409
4467
|
function executePipeline(options) {
|
|
4410
4468
|
return __awaiter(this, void 0, void 0, function () {
|
|
4411
|
-
var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, settings, maxParallelCount, isVerbose, preparedPipeline,
|
|
4412
|
-
var e_1,
|
|
4413
|
-
return __generator(this, function (
|
|
4414
|
-
switch (
|
|
4469
|
+
var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, settings, 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;
|
|
4470
|
+
var e_1, _f, e_2, _g;
|
|
4471
|
+
return __generator(this, function (_h) {
|
|
4472
|
+
switch (_h.label) {
|
|
4415
4473
|
case 0:
|
|
4416
4474
|
inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification, settings = options.settings;
|
|
4417
|
-
maxParallelCount = settings.maxParallelCount,
|
|
4475
|
+
maxParallelCount = settings.maxParallelCount, rootDirname = settings.rootDirname, _a = settings.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
4418
4476
|
preparedPipeline = options.preparedPipeline;
|
|
4419
|
-
llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
4420
4477
|
if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
|
|
4421
|
-
return [4 /*yield*/, preparePipeline(pipeline, {
|
|
4422
|
-
|
|
4478
|
+
return [4 /*yield*/, preparePipeline(pipeline, tools, {
|
|
4479
|
+
rootDirname: rootDirname,
|
|
4423
4480
|
isVerbose: isVerbose,
|
|
4424
4481
|
maxParallelCount: maxParallelCount,
|
|
4425
4482
|
})];
|
|
4426
4483
|
case 1:
|
|
4427
|
-
preparedPipeline =
|
|
4484
|
+
preparedPipeline = _h.sent();
|
|
4428
4485
|
setPreparedPipeline(preparedPipeline);
|
|
4429
|
-
|
|
4486
|
+
_h.label = 2;
|
|
4430
4487
|
case 2:
|
|
4431
4488
|
errors = [];
|
|
4432
4489
|
warnings = [];
|
|
@@ -4439,17 +4496,17 @@
|
|
|
4439
4496
|
promptExecutions: [],
|
|
4440
4497
|
};
|
|
4441
4498
|
isReturned = false;
|
|
4442
|
-
|
|
4499
|
+
_h.label = 3;
|
|
4443
4500
|
case 3:
|
|
4444
|
-
|
|
4445
|
-
|
|
4501
|
+
_h.trys.push([3, 9, 10, 11]);
|
|
4502
|
+
_b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
4446
4503
|
var isInput = _a.isInput;
|
|
4447
4504
|
return isInput;
|
|
4448
|
-
})),
|
|
4449
|
-
|
|
4505
|
+
})), _c = _b.next();
|
|
4506
|
+
_h.label = 4;
|
|
4450
4507
|
case 4:
|
|
4451
|
-
if (!!
|
|
4452
|
-
parameter =
|
|
4508
|
+
if (!!_c.done) return [3 /*break*/, 8];
|
|
4509
|
+
parameter = _c.value;
|
|
4453
4510
|
if (!(inputParameters[parameter.name] === undefined)) return [3 /*break*/, 7];
|
|
4454
4511
|
isReturned = true;
|
|
4455
4512
|
if (!(onProgress !== undefined)) return [3 /*break*/, 6];
|
|
@@ -4457,8 +4514,8 @@
|
|
|
4457
4514
|
return [4 /*yield*/, waitasecond.forTime(IMMEDIATE_TIME)];
|
|
4458
4515
|
case 5:
|
|
4459
4516
|
// Note: Wait a short time to prevent race conditions
|
|
4460
|
-
|
|
4461
|
-
|
|
4517
|
+
_h.sent();
|
|
4518
|
+
_h.label = 6;
|
|
4462
4519
|
case 6: return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
4463
4520
|
isSuccessful: false,
|
|
4464
4521
|
errors: __spreadArray([
|
|
@@ -4471,24 +4528,24 @@
|
|
|
4471
4528
|
preparedPipeline: preparedPipeline,
|
|
4472
4529
|
})];
|
|
4473
4530
|
case 7:
|
|
4474
|
-
|
|
4531
|
+
_c = _b.next();
|
|
4475
4532
|
return [3 /*break*/, 4];
|
|
4476
4533
|
case 8: return [3 /*break*/, 11];
|
|
4477
4534
|
case 9:
|
|
4478
|
-
e_1_1 =
|
|
4535
|
+
e_1_1 = _h.sent();
|
|
4479
4536
|
e_1 = { error: e_1_1 };
|
|
4480
4537
|
return [3 /*break*/, 11];
|
|
4481
4538
|
case 10:
|
|
4482
4539
|
try {
|
|
4483
|
-
if (
|
|
4540
|
+
if (_c && !_c.done && (_f = _b.return)) _f.call(_b);
|
|
4484
4541
|
}
|
|
4485
4542
|
finally { if (e_1) throw e_1.error; }
|
|
4486
4543
|
return [7 /*endfinally*/];
|
|
4487
4544
|
case 11:
|
|
4488
4545
|
_loop_1 = function (parameterName) {
|
|
4489
4546
|
var parameter;
|
|
4490
|
-
return __generator(this, function (
|
|
4491
|
-
switch (
|
|
4547
|
+
return __generator(this, function (_j) {
|
|
4548
|
+
switch (_j.label) {
|
|
4492
4549
|
case 0:
|
|
4493
4550
|
parameter = preparedPipeline.parameters.find(function (_a) {
|
|
4494
4551
|
var name = _a.name;
|
|
@@ -4505,8 +4562,8 @@
|
|
|
4505
4562
|
return [4 /*yield*/, waitasecond.forTime(IMMEDIATE_TIME)];
|
|
4506
4563
|
case 2:
|
|
4507
4564
|
// Note: Wait a short time to prevent race conditions
|
|
4508
|
-
|
|
4509
|
-
|
|
4565
|
+
_j.sent();
|
|
4566
|
+
_j.label = 3;
|
|
4510
4567
|
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
4511
4568
|
isSuccessful: false,
|
|
4512
4569
|
errors: __spreadArray([
|
|
@@ -4522,39 +4579,39 @@
|
|
|
4522
4579
|
}
|
|
4523
4580
|
});
|
|
4524
4581
|
};
|
|
4525
|
-
|
|
4582
|
+
_h.label = 12;
|
|
4526
4583
|
case 12:
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4584
|
+
_h.trys.push([12, 17, 18, 19]);
|
|
4585
|
+
_d = __values(Object.keys(inputParameters)), _e = _d.next();
|
|
4586
|
+
_h.label = 13;
|
|
4530
4587
|
case 13:
|
|
4531
|
-
if (!!
|
|
4532
|
-
parameterName =
|
|
4588
|
+
if (!!_e.done) return [3 /*break*/, 16];
|
|
4589
|
+
parameterName = _e.value;
|
|
4533
4590
|
return [5 /*yield**/, _loop_1(parameterName)];
|
|
4534
4591
|
case 14:
|
|
4535
|
-
state_1 =
|
|
4592
|
+
state_1 = _h.sent();
|
|
4536
4593
|
if (typeof state_1 === "object")
|
|
4537
4594
|
return [2 /*return*/, state_1.value];
|
|
4538
|
-
|
|
4595
|
+
_h.label = 15;
|
|
4539
4596
|
case 15:
|
|
4540
|
-
|
|
4597
|
+
_e = _d.next();
|
|
4541
4598
|
return [3 /*break*/, 13];
|
|
4542
4599
|
case 16: return [3 /*break*/, 19];
|
|
4543
4600
|
case 17:
|
|
4544
|
-
e_2_1 =
|
|
4601
|
+
e_2_1 = _h.sent();
|
|
4545
4602
|
e_2 = { error: e_2_1 };
|
|
4546
4603
|
return [3 /*break*/, 19];
|
|
4547
4604
|
case 18:
|
|
4548
4605
|
try {
|
|
4549
|
-
if (
|
|
4606
|
+
if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
|
|
4550
4607
|
}
|
|
4551
4608
|
finally { if (e_2) throw e_2.error; }
|
|
4552
4609
|
return [7 /*endfinally*/];
|
|
4553
4610
|
case 19:
|
|
4554
4611
|
parametersToPass = inputParameters;
|
|
4555
|
-
|
|
4612
|
+
_h.label = 20;
|
|
4556
4613
|
case 20:
|
|
4557
|
-
|
|
4614
|
+
_h.trys.push([20, 25, , 28]);
|
|
4558
4615
|
resovedParameterNames_1 = preparedPipeline.parameters
|
|
4559
4616
|
.filter(function (_a) {
|
|
4560
4617
|
var isInput = _a.isInput;
|
|
@@ -4569,8 +4626,8 @@
|
|
|
4569
4626
|
loopLimit = LOOP_LIMIT;
|
|
4570
4627
|
_loop_2 = function () {
|
|
4571
4628
|
var currentTemplate, work_1;
|
|
4572
|
-
return __generator(this, function (
|
|
4573
|
-
switch (
|
|
4629
|
+
return __generator(this, function (_k) {
|
|
4630
|
+
switch (_k.label) {
|
|
4574
4631
|
case 0:
|
|
4575
4632
|
if (loopLimit-- < 0) {
|
|
4576
4633
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
@@ -4596,7 +4653,7 @@
|
|
|
4596
4653
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
4597
4654
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
4598
4655
|
case 2:
|
|
4599
|
-
/* [🤹♂️] */
|
|
4656
|
+
/* [🤹♂️] */ _k.sent();
|
|
4600
4657
|
return [3 /*break*/, 4];
|
|
4601
4658
|
case 3:
|
|
4602
4659
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
@@ -4605,7 +4662,6 @@
|
|
|
4605
4662
|
preparedPipeline: preparedPipeline,
|
|
4606
4663
|
parametersToPass: parametersToPass,
|
|
4607
4664
|
tools: tools,
|
|
4608
|
-
llmTools: llmTools,
|
|
4609
4665
|
onProgress: function (progress) {
|
|
4610
4666
|
if (isReturned) {
|
|
4611
4667
|
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)
|
|
@@ -4619,7 +4675,7 @@
|
|
|
4619
4675
|
},
|
|
4620
4676
|
settings: settings,
|
|
4621
4677
|
$executionReport: executionReport,
|
|
4622
|
-
pipelineIdentification: pipelineIdentification,
|
|
4678
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
4623
4679
|
})
|
|
4624
4680
|
.then(function (newParametersToPass) {
|
|
4625
4681
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
@@ -4631,24 +4687,24 @@
|
|
|
4631
4687
|
// <- Note: Errors are catched here [3]
|
|
4632
4688
|
// TODO: BUT if in multiple templates are errors, only the first one is catched so maybe we should catch errors here and save them to errors array here
|
|
4633
4689
|
resolving_1.push(work_1);
|
|
4634
|
-
|
|
4690
|
+
_k.label = 4;
|
|
4635
4691
|
case 4: return [2 /*return*/];
|
|
4636
4692
|
}
|
|
4637
4693
|
});
|
|
4638
4694
|
};
|
|
4639
|
-
|
|
4695
|
+
_h.label = 21;
|
|
4640
4696
|
case 21:
|
|
4641
4697
|
if (!(unresovedTemplates_1.length > 0)) return [3 /*break*/, 23];
|
|
4642
4698
|
return [5 /*yield**/, _loop_2()];
|
|
4643
4699
|
case 22:
|
|
4644
|
-
|
|
4700
|
+
_h.sent();
|
|
4645
4701
|
return [3 /*break*/, 21];
|
|
4646
4702
|
case 23: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
4647
4703
|
case 24:
|
|
4648
|
-
|
|
4704
|
+
_h.sent();
|
|
4649
4705
|
return [3 /*break*/, 28];
|
|
4650
4706
|
case 25:
|
|
4651
|
-
error_1 =
|
|
4707
|
+
error_1 = _h.sent();
|
|
4652
4708
|
if (!(error_1 instanceof Error)) {
|
|
4653
4709
|
throw error_1;
|
|
4654
4710
|
}
|
|
@@ -4668,8 +4724,8 @@
|
|
|
4668
4724
|
return [4 /*yield*/, waitasecond.forTime(IMMEDIATE_TIME)];
|
|
4669
4725
|
case 26:
|
|
4670
4726
|
// Note: Wait a short time to prevent race conditions
|
|
4671
|
-
|
|
4672
|
-
|
|
4727
|
+
_h.sent();
|
|
4728
|
+
_h.label = 27;
|
|
4673
4729
|
case 27: return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
|
|
4674
4730
|
isSuccessful: false,
|
|
4675
4731
|
errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
|
|
@@ -4696,8 +4752,8 @@
|
|
|
4696
4752
|
return [4 /*yield*/, waitasecond.forTime(IMMEDIATE_TIME)];
|
|
4697
4753
|
case 29:
|
|
4698
4754
|
// Note: Wait a short time to prevent race conditions
|
|
4699
|
-
|
|
4700
|
-
|
|
4755
|
+
_h.sent();
|
|
4756
|
+
_h.label = 30;
|
|
4701
4757
|
case 30: return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
|
|
4702
4758
|
isSuccessful: true,
|
|
4703
4759
|
errors: errors.map(serializeError),
|
|
@@ -4711,200 +4767,751 @@
|
|
|
4711
4767
|
});
|
|
4712
4768
|
});
|
|
4713
4769
|
}
|
|
4770
|
+
/**
|
|
4771
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4772
|
+
*/
|
|
4773
|
+
|
|
4774
|
+
/**
|
|
4775
|
+
* Creates executor function from pipeline and execution tools.
|
|
4776
|
+
*
|
|
4777
|
+
* @returns The executor function
|
|
4778
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
4779
|
+
* @public exported from `@promptbook/core`
|
|
4780
|
+
*/
|
|
4781
|
+
function createPipelineExecutor(options) {
|
|
4782
|
+
var _this = this;
|
|
4783
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
4784
|
+
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;
|
|
4785
|
+
validatePipeline(pipeline);
|
|
4786
|
+
var pipelineIdentification = (function () {
|
|
4787
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
4788
|
+
var _ = [];
|
|
4789
|
+
if (pipeline.sourceFile !== undefined) {
|
|
4790
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
4791
|
+
}
|
|
4792
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
4793
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
4794
|
+
}
|
|
4795
|
+
return _.join('\n');
|
|
4796
|
+
})();
|
|
4797
|
+
var preparedPipeline;
|
|
4798
|
+
if (isPipelinePrepared(pipeline)) {
|
|
4799
|
+
preparedPipeline = pipeline;
|
|
4800
|
+
}
|
|
4801
|
+
else if (isNotPreparedWarningSupressed !== true) {
|
|
4802
|
+
console.warn(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
4803
|
+
}
|
|
4804
|
+
var runCount = 0;
|
|
4805
|
+
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4806
|
+
return __generator(this, function (_a) {
|
|
4807
|
+
runCount++;
|
|
4808
|
+
return [2 /*return*/, /* not await */ executePipeline({
|
|
4809
|
+
pipeline: pipeline,
|
|
4810
|
+
preparedPipeline: preparedPipeline,
|
|
4811
|
+
setPreparedPipeline: function (newPreparedPipeline) {
|
|
4812
|
+
preparedPipeline = newPreparedPipeline;
|
|
4813
|
+
},
|
|
4814
|
+
inputParameters: inputParameters,
|
|
4815
|
+
tools: tools,
|
|
4816
|
+
onProgress: onProgress,
|
|
4817
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
4818
|
+
settings: {
|
|
4819
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
4820
|
+
maxParallelCount: maxParallelCount,
|
|
4821
|
+
csvSettings: csvSettings,
|
|
4822
|
+
isVerbose: isVerbose,
|
|
4823
|
+
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
4824
|
+
rootDirname: rootDirname,
|
|
4825
|
+
},
|
|
4826
|
+
})];
|
|
4827
|
+
});
|
|
4828
|
+
}); };
|
|
4829
|
+
return pipelineExecutor;
|
|
4830
|
+
}
|
|
4831
|
+
/**
|
|
4832
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4833
|
+
*/
|
|
4834
|
+
|
|
4835
|
+
/**
|
|
4836
|
+
* Prepares the persona for the pipeline
|
|
4837
|
+
*
|
|
4838
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
4839
|
+
* @public exported from `@promptbook/core`
|
|
4840
|
+
*/
|
|
4841
|
+
function preparePersona(personaDescription, tools, options) {
|
|
4842
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4843
|
+
var _a, isVerbose, collection, preparePersonaExecutor, _b, _llms, llmTools, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
4844
|
+
var _c;
|
|
4845
|
+
return __generator(this, function (_d) {
|
|
4846
|
+
switch (_d.label) {
|
|
4847
|
+
case 0:
|
|
4848
|
+
_a = options.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
4849
|
+
if (tools === undefined || tools.llm === undefined) {
|
|
4850
|
+
throw new MissingToolsError('LLM tools are required for preparing persona');
|
|
4851
|
+
}
|
|
4852
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
4853
|
+
_b = createPipelineExecutor;
|
|
4854
|
+
_c = {};
|
|
4855
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
|
|
4856
|
+
case 1:
|
|
4857
|
+
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
4858
|
+
_c.tools = tools,
|
|
4859
|
+
_c)]);
|
|
4860
|
+
_llms = arrayableToArray(tools.llm);
|
|
4861
|
+
llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
|
|
4862
|
+
return [4 /*yield*/, llmTools.listModels()];
|
|
4863
|
+
case 2:
|
|
4864
|
+
availableModels = _d.sent();
|
|
4865
|
+
availableModelNames = availableModels
|
|
4866
|
+
.filter(function (_a) {
|
|
4867
|
+
var modelVariant = _a.modelVariant;
|
|
4868
|
+
return modelVariant === 'CHAT';
|
|
4869
|
+
})
|
|
4870
|
+
.map(function (_a) {
|
|
4871
|
+
var modelName = _a.modelName;
|
|
4872
|
+
return modelName;
|
|
4873
|
+
})
|
|
4874
|
+
.join(',');
|
|
4875
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
4876
|
+
case 3:
|
|
4877
|
+
result = _d.sent();
|
|
4878
|
+
assertsExecutionSuccessful(result);
|
|
4879
|
+
outputParameters = result.outputParameters;
|
|
4880
|
+
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
4881
|
+
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
4882
|
+
if (isVerbose) {
|
|
4883
|
+
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
4884
|
+
}
|
|
4885
|
+
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
4886
|
+
return [2 /*return*/, {
|
|
4887
|
+
modelVariant: 'CHAT',
|
|
4888
|
+
modelName: modelName,
|
|
4889
|
+
systemMessage: systemMessage,
|
|
4890
|
+
temperature: temperature,
|
|
4891
|
+
}];
|
|
4892
|
+
}
|
|
4893
|
+
});
|
|
4894
|
+
});
|
|
4895
|
+
}
|
|
4896
|
+
/**
|
|
4897
|
+
* TODO: [🔃][main] !!!!! If the persona was prepared with different version or different set of models, prepare it once again
|
|
4898
|
+
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
4899
|
+
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
4900
|
+
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
4901
|
+
*/
|
|
4902
|
+
|
|
4903
|
+
/**
|
|
4904
|
+
* This error indicates that the promptbook can not retrieve knowledge from external sources
|
|
4905
|
+
*
|
|
4906
|
+
* @public exported from `@promptbook/core`
|
|
4907
|
+
*/
|
|
4908
|
+
var KnowledgeScrapeError = /** @class */ (function (_super) {
|
|
4909
|
+
__extends(KnowledgeScrapeError, _super);
|
|
4910
|
+
function KnowledgeScrapeError(message) {
|
|
4911
|
+
var _this = _super.call(this, message) || this;
|
|
4912
|
+
_this.name = 'KnowledgeScrapeError';
|
|
4913
|
+
Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
|
|
4914
|
+
return _this;
|
|
4915
|
+
}
|
|
4916
|
+
return KnowledgeScrapeError;
|
|
4917
|
+
}(Error));
|
|
4918
|
+
|
|
4919
|
+
/**
|
|
4920
|
+
* @@@
|
|
4921
|
+
*
|
|
4922
|
+
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
4923
|
+
*
|
|
4924
|
+
* @private internal function of `$Register`
|
|
4925
|
+
*/
|
|
4926
|
+
function $getGlobalScope() {
|
|
4927
|
+
return Function('return this')();
|
|
4928
|
+
}
|
|
4929
|
+
|
|
4930
|
+
/**
|
|
4931
|
+
* @@@
|
|
4932
|
+
*
|
|
4933
|
+
* @param text @@@
|
|
4934
|
+
* @returns @@@
|
|
4935
|
+
* @example 'HELLO_WORLD'
|
|
4936
|
+
* @example 'I_LOVE_PROMPTBOOK'
|
|
4937
|
+
* @public exported from `@promptbook/utils`
|
|
4938
|
+
*/
|
|
4939
|
+
function normalizeTo_SCREAMING_CASE(text) {
|
|
4940
|
+
var e_1, _a;
|
|
4941
|
+
var charType;
|
|
4942
|
+
var lastCharType = 'OTHER';
|
|
4943
|
+
var normalizedName = '';
|
|
4944
|
+
try {
|
|
4945
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
4946
|
+
var char = text_1_1.value;
|
|
4947
|
+
var normalizedChar = void 0;
|
|
4948
|
+
if (/^[a-z]$/.test(char)) {
|
|
4949
|
+
charType = 'LOWERCASE';
|
|
4950
|
+
normalizedChar = char.toUpperCase();
|
|
4951
|
+
}
|
|
4952
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
4953
|
+
charType = 'UPPERCASE';
|
|
4954
|
+
normalizedChar = char;
|
|
4955
|
+
}
|
|
4956
|
+
else if (/^[0-9]$/.test(char)) {
|
|
4957
|
+
charType = 'NUMBER';
|
|
4958
|
+
normalizedChar = char;
|
|
4959
|
+
}
|
|
4960
|
+
else {
|
|
4961
|
+
charType = 'OTHER';
|
|
4962
|
+
normalizedChar = '_';
|
|
4963
|
+
}
|
|
4964
|
+
if (charType !== lastCharType &&
|
|
4965
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
4966
|
+
!(lastCharType === 'NUMBER') &&
|
|
4967
|
+
!(charType === 'NUMBER')) {
|
|
4968
|
+
normalizedName += '_';
|
|
4969
|
+
}
|
|
4970
|
+
normalizedName += normalizedChar;
|
|
4971
|
+
lastCharType = charType;
|
|
4972
|
+
}
|
|
4973
|
+
}
|
|
4974
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4975
|
+
finally {
|
|
4976
|
+
try {
|
|
4977
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
4978
|
+
}
|
|
4979
|
+
finally { if (e_1) throw e_1.error; }
|
|
4980
|
+
}
|
|
4981
|
+
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
4982
|
+
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
4983
|
+
normalizedName = normalizedName.replace(/^_/, '');
|
|
4984
|
+
normalizedName = normalizedName.replace(/_$/, '');
|
|
4985
|
+
return normalizedName;
|
|
4986
|
+
}
|
|
4987
|
+
/**
|
|
4988
|
+
* TODO: Tests
|
|
4989
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
4990
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
4991
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
4992
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
4993
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
4994
|
+
*/
|
|
4995
|
+
|
|
4996
|
+
/**
|
|
4997
|
+
* @@@
|
|
4998
|
+
*
|
|
4999
|
+
* @param text @@@
|
|
5000
|
+
* @returns @@@
|
|
5001
|
+
* @example 'hello_world'
|
|
5002
|
+
* @example 'i_love_promptbook'
|
|
5003
|
+
* @public exported from `@promptbook/utils`
|
|
5004
|
+
*/
|
|
5005
|
+
function normalizeTo_snake_case(text) {
|
|
5006
|
+
return normalizeTo_SCREAMING_CASE(text).toLowerCase();
|
|
5007
|
+
}
|
|
5008
|
+
|
|
5009
|
+
/**
|
|
5010
|
+
* Register is @@@
|
|
5011
|
+
*
|
|
5012
|
+
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
5013
|
+
*
|
|
5014
|
+
* @private internal utility, exported are only signleton instances of this class
|
|
5015
|
+
*/
|
|
5016
|
+
var $Register = /** @class */ (function () {
|
|
5017
|
+
function $Register(registerName) {
|
|
5018
|
+
this.registerName = registerName;
|
|
5019
|
+
var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
|
|
5020
|
+
var globalScope = $getGlobalScope();
|
|
5021
|
+
if (globalScope[storageName] === undefined) {
|
|
5022
|
+
globalScope[storageName] = [];
|
|
5023
|
+
}
|
|
5024
|
+
else if (!Array.isArray(globalScope[storageName])) {
|
|
5025
|
+
throw new UnexpectedError("Expected (global) ".concat(storageName, " to be an array, but got ").concat(typeof globalScope[storageName]));
|
|
5026
|
+
}
|
|
5027
|
+
this.storage = globalScope[storageName];
|
|
5028
|
+
}
|
|
5029
|
+
$Register.prototype.list = function () {
|
|
5030
|
+
// <- TODO: ReadonlyDeep<Array<TRegistered>>
|
|
5031
|
+
return this.storage;
|
|
5032
|
+
};
|
|
5033
|
+
$Register.prototype.register = function (registered) {
|
|
5034
|
+
var packageName = registered.packageName, className = registered.className;
|
|
5035
|
+
var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
|
|
5036
|
+
var existingRegistration = this.storage[existingRegistrationIndex];
|
|
5037
|
+
if (!existingRegistration) {
|
|
5038
|
+
this.storage.push(registered);
|
|
5039
|
+
}
|
|
5040
|
+
else {
|
|
5041
|
+
this.storage[existingRegistrationIndex] = registered;
|
|
5042
|
+
}
|
|
5043
|
+
return {
|
|
5044
|
+
registerName: this.registerName,
|
|
5045
|
+
packageName: packageName,
|
|
5046
|
+
className: className,
|
|
5047
|
+
get isDestroyed() {
|
|
5048
|
+
return false;
|
|
5049
|
+
},
|
|
5050
|
+
destroy: function () {
|
|
5051
|
+
throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
|
|
5052
|
+
},
|
|
5053
|
+
};
|
|
5054
|
+
};
|
|
5055
|
+
return $Register;
|
|
5056
|
+
}());
|
|
5057
|
+
|
|
5058
|
+
/**
|
|
5059
|
+
* @@@
|
|
5060
|
+
*
|
|
5061
|
+
* Note: `$` is used to indicate that this interacts with the global scope
|
|
5062
|
+
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
5063
|
+
* @public exported from `@promptbook/core`
|
|
5064
|
+
*/
|
|
5065
|
+
var $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
5066
|
+
/**
|
|
5067
|
+
* TODO: [®] DRY Register logic
|
|
5068
|
+
*/
|
|
5069
|
+
|
|
5070
|
+
/**
|
|
5071
|
+
* @@@
|
|
5072
|
+
*
|
|
5073
|
+
* Note: `$` is used to indicate that this interacts with the global scope
|
|
5074
|
+
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
5075
|
+
* @public exported from `@promptbook/core`
|
|
5076
|
+
*/
|
|
5077
|
+
var $scrapersRegister = new $Register('scraper_constructors');
|
|
5078
|
+
/**
|
|
5079
|
+
* TODO: [®] DRY Register logic
|
|
5080
|
+
*/
|
|
5081
|
+
|
|
5082
|
+
// TODO: !!!!!! Maybe delete this function
|
|
5083
|
+
/**
|
|
5084
|
+
* Creates a message with all registered scrapers
|
|
5085
|
+
*
|
|
5086
|
+
* Note: This function is used to create a (error) message when there is no scraper for particular mime type
|
|
5087
|
+
*
|
|
5088
|
+
* @private internal function of `createScrapersFromConfiguration` and `createScrapersFromEnv`
|
|
5089
|
+
*/
|
|
5090
|
+
function $registeredScrapersMessage() {
|
|
5091
|
+
var e_1, _a, e_2, _b;
|
|
5092
|
+
/**
|
|
5093
|
+
* Mixes registered scrapers from $scrapersMetadataRegister and $scrapersRegister
|
|
5094
|
+
*/
|
|
5095
|
+
var all = [];
|
|
5096
|
+
var _loop_1 = function (packageName, className) {
|
|
5097
|
+
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
5098
|
+
return "continue";
|
|
5099
|
+
}
|
|
5100
|
+
all.push({ packageName: packageName, className: className });
|
|
5101
|
+
};
|
|
5102
|
+
try {
|
|
5103
|
+
for (var _c = __values($scrapersMetadataRegister.list()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
5104
|
+
var _e = _d.value, packageName = _e.packageName, className = _e.className;
|
|
5105
|
+
_loop_1(packageName, className);
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5109
|
+
finally {
|
|
5110
|
+
try {
|
|
5111
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
5112
|
+
}
|
|
5113
|
+
finally { if (e_1) throw e_1.error; }
|
|
5114
|
+
}
|
|
5115
|
+
var _loop_2 = function (packageName, className) {
|
|
5116
|
+
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
5117
|
+
return "continue";
|
|
5118
|
+
}
|
|
5119
|
+
all.push({ packageName: packageName, className: className });
|
|
5120
|
+
};
|
|
5121
|
+
try {
|
|
5122
|
+
for (var _f = __values($scrapersRegister.list()), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
5123
|
+
var _h = _g.value, packageName = _h.packageName, className = _h.className;
|
|
5124
|
+
_loop_2(packageName, className);
|
|
5125
|
+
}
|
|
5126
|
+
}
|
|
5127
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5128
|
+
finally {
|
|
5129
|
+
try {
|
|
5130
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
5131
|
+
}
|
|
5132
|
+
finally { if (e_2) throw e_2.error; }
|
|
5133
|
+
}
|
|
5134
|
+
var metadata = all.map(function (metadata) {
|
|
5135
|
+
var isMetadataAviailable = $scrapersMetadataRegister
|
|
5136
|
+
.list()
|
|
5137
|
+
.find(function (_a) {
|
|
5138
|
+
var packageName = _a.packageName, className = _a.className;
|
|
5139
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
5140
|
+
});
|
|
5141
|
+
var isInstalled = $scrapersRegister
|
|
5142
|
+
.list()
|
|
5143
|
+
.find(function (_a) {
|
|
5144
|
+
var packageName = _a.packageName, className = _a.className;
|
|
5145
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
5146
|
+
});
|
|
5147
|
+
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
|
|
5148
|
+
});
|
|
5149
|
+
if (metadata.length === 0) {
|
|
5150
|
+
return "No scrapers are available";
|
|
5151
|
+
}
|
|
5152
|
+
return spaceTrim__default["default"](function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
|
|
5153
|
+
.map(function (_a, i) {
|
|
5154
|
+
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
|
|
5155
|
+
var more;
|
|
5156
|
+
if (just(false)) {
|
|
5157
|
+
more = '';
|
|
5158
|
+
}
|
|
5159
|
+
else if (!isMetadataAviailable && !isInstalled) {
|
|
5160
|
+
// TODO: [�][�] Maybe do allow to do auto-install if package not registered and not found
|
|
5161
|
+
more = "(not installed and no metadata, looks like a unexpected behavior)";
|
|
5162
|
+
}
|
|
5163
|
+
else if (isMetadataAviailable && !isInstalled) {
|
|
5164
|
+
// TODO: [�][�]
|
|
5165
|
+
more = "(not installed)";
|
|
5166
|
+
}
|
|
5167
|
+
else if (!isMetadataAviailable && isInstalled) {
|
|
5168
|
+
more = "(no metadata, looks like a unexpected behavior)";
|
|
5169
|
+
}
|
|
5170
|
+
else if (isMetadataAviailable && isInstalled) {
|
|
5171
|
+
more = "(installed)";
|
|
5172
|
+
}
|
|
5173
|
+
else {
|
|
5174
|
+
more = "(unknown state, looks like a unexpected behavior)";
|
|
5175
|
+
}
|
|
5176
|
+
return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` ").concat(more);
|
|
5177
|
+
})
|
|
5178
|
+
.join('\n')), "\n "); });
|
|
5179
|
+
}
|
|
5180
|
+
/**
|
|
5181
|
+
* TODO: [®] DRY Register logic
|
|
5182
|
+
*/
|
|
4714
5183
|
|
|
4715
5184
|
/**
|
|
4716
|
-
*
|
|
5185
|
+
* @@@
|
|
4717
5186
|
*
|
|
4718
|
-
* @
|
|
4719
|
-
* @
|
|
4720
|
-
* @
|
|
5187
|
+
* @param text @@@
|
|
5188
|
+
* @returns @@@
|
|
5189
|
+
* @example 'hello-world'
|
|
5190
|
+
* @example 'i-love-promptbook'
|
|
5191
|
+
* @public exported from `@promptbook/utils`
|
|
4721
5192
|
*/
|
|
4722
|
-
function
|
|
4723
|
-
var
|
|
4724
|
-
|
|
4725
|
-
var
|
|
4726
|
-
|
|
4727
|
-
var
|
|
4728
|
-
|
|
4729
|
-
var
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
5193
|
+
function normalizeToKebabCase(text) {
|
|
5194
|
+
var e_1, _a;
|
|
5195
|
+
text = removeDiacritics(text);
|
|
5196
|
+
var charType;
|
|
5197
|
+
var lastCharType = 'OTHER';
|
|
5198
|
+
var normalizedName = '';
|
|
5199
|
+
try {
|
|
5200
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
5201
|
+
var char = text_1_1.value;
|
|
5202
|
+
var normalizedChar = void 0;
|
|
5203
|
+
if (/^[a-z]$/.test(char)) {
|
|
5204
|
+
charType = 'LOWERCASE';
|
|
5205
|
+
normalizedChar = char;
|
|
5206
|
+
}
|
|
5207
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
5208
|
+
charType = 'UPPERCASE';
|
|
5209
|
+
normalizedChar = char.toLowerCase();
|
|
5210
|
+
}
|
|
5211
|
+
else if (/^[0-9]$/.test(char)) {
|
|
5212
|
+
charType = 'NUMBER';
|
|
5213
|
+
normalizedChar = char;
|
|
5214
|
+
}
|
|
5215
|
+
else {
|
|
5216
|
+
charType = 'OTHER';
|
|
5217
|
+
normalizedChar = '-';
|
|
5218
|
+
}
|
|
5219
|
+
if (charType !== lastCharType &&
|
|
5220
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
5221
|
+
!(lastCharType === 'NUMBER') &&
|
|
5222
|
+
!(charType === 'NUMBER')) {
|
|
5223
|
+
normalizedName += '-';
|
|
5224
|
+
}
|
|
5225
|
+
normalizedName += normalizedChar;
|
|
5226
|
+
lastCharType = charType;
|
|
4735
5227
|
}
|
|
4736
|
-
return _.join('\n');
|
|
4737
|
-
})();
|
|
4738
|
-
var preparedPipeline;
|
|
4739
|
-
if (isPipelinePrepared(pipeline)) {
|
|
4740
|
-
preparedPipeline = pipeline;
|
|
4741
5228
|
}
|
|
4742
|
-
|
|
4743
|
-
|
|
5229
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5230
|
+
finally {
|
|
5231
|
+
try {
|
|
5232
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
5233
|
+
}
|
|
5234
|
+
finally { if (e_1) throw e_1.error; }
|
|
4744
5235
|
}
|
|
4745
|
-
|
|
5236
|
+
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
5237
|
+
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
5238
|
+
normalizedName = normalizedName.replace(/^-/, '');
|
|
5239
|
+
normalizedName = normalizedName.replace(/-$/, '');
|
|
5240
|
+
return normalizedName;
|
|
5241
|
+
}
|
|
5242
|
+
|
|
5243
|
+
/**
|
|
5244
|
+
* Creates unique name for the source
|
|
5245
|
+
*
|
|
5246
|
+
* @private within the repository
|
|
5247
|
+
*/
|
|
5248
|
+
function sourceContentToName(sourceContent) {
|
|
5249
|
+
// TODO: !!!!!! Better name for source than gibberish hash
|
|
5250
|
+
var hash = cryptoJs.SHA256(hexEncoder__default["default"].parse(JSON.stringify(sourceContent)))
|
|
5251
|
+
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
5252
|
+
.toString( /* hex */)
|
|
5253
|
+
.substring(0, 20);
|
|
5254
|
+
// <- TODO: [🥬] Make some system for hashes and ids of promptbook
|
|
5255
|
+
var semanticName = normalizeToKebabCase(sourceContent.substring(0, 20));
|
|
5256
|
+
var pieces = ['source', semanticName, hash].filter(function (piece) { return piece !== ''; });
|
|
5257
|
+
var name = pieces.join('-').split('--').join('-');
|
|
5258
|
+
// <- TODO: Use MAX_FILENAME_LENGTH
|
|
5259
|
+
return name;
|
|
5260
|
+
}
|
|
5261
|
+
/**
|
|
5262
|
+
* TODO: [🐱🐉][🧠] Make some smart crop NOT source-i-m-pavol-a-develop-... BUT source-i-m-pavol-a-developer-...
|
|
5263
|
+
*/
|
|
5264
|
+
|
|
5265
|
+
/**
|
|
5266
|
+
* Detects if the code is running in a Node.js environment
|
|
5267
|
+
*
|
|
5268
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
5269
|
+
*
|
|
5270
|
+
* @public exported from `@promptbook/utils`
|
|
5271
|
+
*/
|
|
5272
|
+
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
5273
|
+
|
|
5274
|
+
/**
|
|
5275
|
+
* Checks if the file exists
|
|
5276
|
+
*
|
|
5277
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
5278
|
+
*
|
|
5279
|
+
* @private within the repository
|
|
5280
|
+
*/
|
|
5281
|
+
function $isFileExisting(filename) {
|
|
5282
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5283
|
+
var isReadAccessAllowed, isFile;
|
|
4746
5284
|
return __generator(this, function (_a) {
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
5285
|
+
switch (_a.label) {
|
|
5286
|
+
case 0:
|
|
5287
|
+
if (!$isRunningInNode()) {
|
|
5288
|
+
throw new EnvironmentMismatchError('Function `$isFileExisting` works only in Node environment.js');
|
|
5289
|
+
}
|
|
5290
|
+
return [4 /*yield*/, promises.access(filename, promises.constants.R_OK)
|
|
5291
|
+
.then(function () { return true; })
|
|
5292
|
+
.catch(function () { return false; })];
|
|
5293
|
+
case 1:
|
|
5294
|
+
isReadAccessAllowed = _a.sent();
|
|
5295
|
+
if (!isReadAccessAllowed) {
|
|
5296
|
+
return [2 /*return*/, false];
|
|
5297
|
+
}
|
|
5298
|
+
return [4 /*yield*/, promises.stat(filename)
|
|
5299
|
+
.then(function (fileStat) { return fileStat.isFile(); })
|
|
5300
|
+
.catch(function () { return false; })];
|
|
5301
|
+
case 2:
|
|
5302
|
+
isFile = _a.sent();
|
|
5303
|
+
return [2 /*return*/, isFile];
|
|
5304
|
+
}
|
|
4765
5305
|
});
|
|
4766
|
-
});
|
|
4767
|
-
|
|
5306
|
+
});
|
|
5307
|
+
}
|
|
5308
|
+
/**
|
|
5309
|
+
* Note: [🟢 !!!!!! After fix makeKnowledgeSourceHandler] Code in this file should never be published outside of `@promptbook/node` and `@promptbook/cli`
|
|
5310
|
+
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
5311
|
+
* TODO: [🖇] What about symlinks?
|
|
5312
|
+
*/
|
|
5313
|
+
|
|
5314
|
+
/**
|
|
5315
|
+
* Convert file extension to mime type
|
|
5316
|
+
*
|
|
5317
|
+
* @private within the repository
|
|
5318
|
+
*/
|
|
5319
|
+
function extensionToMimeType(value) {
|
|
5320
|
+
return mimeTypes.lookup(value) || 'application/octet-stream';
|
|
5321
|
+
}
|
|
5322
|
+
|
|
5323
|
+
/**
|
|
5324
|
+
* Get the file extension from a file name
|
|
5325
|
+
*
|
|
5326
|
+
* @private within the repository
|
|
5327
|
+
*/
|
|
5328
|
+
function getFileExtension(value) {
|
|
5329
|
+
var match = value.match(/\.([0-9a-z]+)(?:[?#]|$)/i);
|
|
5330
|
+
return match ? match[1].toLowerCase() : null;
|
|
5331
|
+
}
|
|
5332
|
+
|
|
5333
|
+
/**
|
|
5334
|
+
* Tests if given string is valid URL.
|
|
5335
|
+
*
|
|
5336
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
5337
|
+
* @public exported from `@promptbook/utils`
|
|
5338
|
+
*/
|
|
5339
|
+
function isValidFilePath(filename) {
|
|
5340
|
+
if (typeof filename !== 'string') {
|
|
5341
|
+
return false;
|
|
5342
|
+
}
|
|
5343
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
5344
|
+
// Absolute Unix path: /hello.txt
|
|
5345
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
5346
|
+
return true;
|
|
5347
|
+
}
|
|
5348
|
+
// Absolute Windows path: /hello.txt
|
|
5349
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
5350
|
+
return true;
|
|
5351
|
+
}
|
|
5352
|
+
// Relative path: ./hello.txt
|
|
5353
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
5354
|
+
return true;
|
|
5355
|
+
}
|
|
5356
|
+
return false;
|
|
4768
5357
|
}
|
|
4769
5358
|
|
|
4770
5359
|
/**
|
|
4771
5360
|
* @@@
|
|
4772
5361
|
*
|
|
4773
|
-
* @
|
|
5362
|
+
* @private for scraper utilities
|
|
4774
5363
|
*/
|
|
4775
|
-
function
|
|
5364
|
+
function makeKnowledgeSourceHandler(knowledgeSource, options) {
|
|
5365
|
+
var _a;
|
|
4776
5366
|
return __awaiter(this, void 0, void 0, function () {
|
|
4777
|
-
var
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
return __generator(this, function (
|
|
4781
|
-
switch (
|
|
5367
|
+
var sourceContent, name, _b, _c, rootDirname, _d,
|
|
5368
|
+
// <- TODO: process.cwd() if running in Node.js
|
|
5369
|
+
isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType_1;
|
|
5370
|
+
return __generator(this, function (_e) {
|
|
5371
|
+
switch (_e.label) {
|
|
4782
5372
|
case 0:
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
5373
|
+
sourceContent = knowledgeSource.sourceContent;
|
|
5374
|
+
name = knowledgeSource.name;
|
|
5375
|
+
_b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _d = _b.isVerbose, isVerbose = _d === void 0 ? IS_VERBOSE : _d;
|
|
5376
|
+
TODO_USE(isVerbose);
|
|
5377
|
+
if (!name) {
|
|
5378
|
+
name = sourceContentToName(sourceContent);
|
|
5379
|
+
}
|
|
5380
|
+
if (!isValidUrl(sourceContent)) return [3 /*break*/, 2];
|
|
5381
|
+
url = sourceContent;
|
|
5382
|
+
return [4 /*yield*/, fetch(url)];
|
|
4789
5383
|
case 1:
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
5384
|
+
response_1 = _e.sent();
|
|
5385
|
+
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
5386
|
+
return [2 /*return*/, {
|
|
5387
|
+
source: name,
|
|
5388
|
+
filename: null,
|
|
5389
|
+
url: url,
|
|
5390
|
+
mimeType: mimeType,
|
|
5391
|
+
asBlob: function () {
|
|
5392
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5393
|
+
var content;
|
|
5394
|
+
return __generator(this, function (_a) {
|
|
5395
|
+
switch (_a.label) {
|
|
5396
|
+
case 0: return [4 /*yield*/, response_1.blob()];
|
|
5397
|
+
case 1:
|
|
5398
|
+
content = _a.sent();
|
|
5399
|
+
return [2 /*return*/, content];
|
|
5400
|
+
}
|
|
5401
|
+
});
|
|
5402
|
+
});
|
|
4793
5403
|
},
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
5404
|
+
asJson: function () {
|
|
5405
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5406
|
+
var content;
|
|
5407
|
+
return __generator(this, function (_a) {
|
|
5408
|
+
switch (_a.label) {
|
|
5409
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
5410
|
+
case 1:
|
|
5411
|
+
content = _a.sent();
|
|
5412
|
+
return [2 /*return*/, content];
|
|
5413
|
+
}
|
|
5414
|
+
});
|
|
5415
|
+
});
|
|
4802
5416
|
},
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
5417
|
+
asText: function () {
|
|
5418
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5419
|
+
var content;
|
|
5420
|
+
return __generator(this, function (_a) {
|
|
5421
|
+
switch (_a.label) {
|
|
5422
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
5423
|
+
case 1:
|
|
5424
|
+
content = _a.sent();
|
|
5425
|
+
return [2 /*return*/, content];
|
|
5426
|
+
}
|
|
5427
|
+
});
|
|
5428
|
+
});
|
|
4811
5429
|
},
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
outputParameters = result.outputParameters;
|
|
4818
|
-
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
4819
|
-
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
4820
|
-
// <- TODO:[main] !!!!! Smarter split and filter out empty pieces
|
|
4821
|
-
if (isVerbose) {
|
|
4822
|
-
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
5430
|
+
}];
|
|
5431
|
+
case 2:
|
|
5432
|
+
if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
|
|
5433
|
+
if (!$isRunningInNode()) {
|
|
5434
|
+
throw new EnvironmentMismatchError('Importing knowledge source file works only in Node.js environment');
|
|
4823
5435
|
}
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
console.info("Keywords for \"".concat(title, "\":"), keywords);
|
|
5436
|
+
if (rootDirname === null) {
|
|
5437
|
+
throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
|
|
5438
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
5439
|
+
}
|
|
5440
|
+
filename_1 = path.join(rootDirname, sourceContent).split('\\').join('/');
|
|
5441
|
+
fileExtension = getFileExtension(filename_1);
|
|
5442
|
+
mimeType_1 = extensionToMimeType(fileExtension || '');
|
|
5443
|
+
return [4 /*yield*/, $isFileExisting(filename_1)];
|
|
5444
|
+
case 3:
|
|
5445
|
+
if (!(_e.sent())) {
|
|
5446
|
+
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 "); }));
|
|
5447
|
+
}
|
|
5448
|
+
// TODO: !!!!!! Test security file - file is scoped to the project (maybe do this in `filesystemTools`)
|
|
5449
|
+
return [2 /*return*/, {
|
|
5450
|
+
source: name,
|
|
5451
|
+
filename: filename_1,
|
|
5452
|
+
url: null,
|
|
5453
|
+
mimeType: mimeType_1,
|
|
5454
|
+
asBlob: function () {
|
|
5455
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5456
|
+
var content;
|
|
5457
|
+
return __generator(this, function (_a) {
|
|
5458
|
+
switch (_a.label) {
|
|
5459
|
+
case 0: return [4 /*yield*/, promises.readFile(filename_1)];
|
|
5460
|
+
case 1:
|
|
5461
|
+
content = _a.sent();
|
|
5462
|
+
return [2 /*return*/, new Blob([
|
|
5463
|
+
content,
|
|
5464
|
+
// <- TODO: !!!!!! Maybe not working
|
|
5465
|
+
], { type: mimeType_1 })];
|
|
4855
5466
|
}
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
case 5:
|
|
4869
|
-
embeddingResult = _c.sent();
|
|
4870
|
-
index.push({
|
|
4871
|
-
modelName: embeddingResult.modelName,
|
|
4872
|
-
position: embeddingResult.content,
|
|
4873
|
-
});
|
|
4874
|
-
_c.label = 6;
|
|
4875
|
-
case 6: return [3 /*break*/, 8];
|
|
4876
|
-
case 7:
|
|
4877
|
-
error_1 = _c.sent();
|
|
4878
|
-
// Note: Here is expected error:
|
|
4879
|
-
// > PipelineExecutionError: You have not provided any `LlmExecutionTools` that support model variant "EMBEDDING
|
|
4880
|
-
if (!(error_1 instanceof PipelineExecutionError)) {
|
|
4881
|
-
throw error_1;
|
|
5467
|
+
});
|
|
5468
|
+
});
|
|
5469
|
+
},
|
|
5470
|
+
asJson: function () {
|
|
5471
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5472
|
+
var _a, _b;
|
|
5473
|
+
return __generator(this, function (_c) {
|
|
5474
|
+
switch (_c.label) {
|
|
5475
|
+
case 0:
|
|
5476
|
+
_b = (_a = JSON).parse;
|
|
5477
|
+
return [4 /*yield*/, promises.readFile(filename_1, 'utf-8')];
|
|
5478
|
+
case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
|
|
4882
5479
|
}
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
}
|
|
4895
|
-
}
|
|
4896
|
-
}
|
|
4897
|
-
case
|
|
4898
|
-
|
|
4899
|
-
|
|
5480
|
+
});
|
|
5481
|
+
});
|
|
5482
|
+
},
|
|
5483
|
+
asText: function () {
|
|
5484
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5485
|
+
return __generator(this, function (_a) {
|
|
5486
|
+
switch (_a.label) {
|
|
5487
|
+
case 0: return [4 /*yield*/, promises.readFile(filename_1, 'utf-8')];
|
|
5488
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5489
|
+
}
|
|
5490
|
+
});
|
|
5491
|
+
});
|
|
5492
|
+
},
|
|
5493
|
+
}];
|
|
5494
|
+
case 4: return [2 /*return*/, {
|
|
5495
|
+
source: name,
|
|
5496
|
+
filename: null,
|
|
5497
|
+
url: null,
|
|
5498
|
+
mimeType: 'text/markdown',
|
|
5499
|
+
asText: function () {
|
|
5500
|
+
return knowledgeSource.sourceContent;
|
|
5501
|
+
},
|
|
5502
|
+
asJson: function () {
|
|
5503
|
+
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
|
|
5504
|
+
},
|
|
5505
|
+
asBlob: function () {
|
|
5506
|
+
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asBlob`');
|
|
5507
|
+
},
|
|
5508
|
+
}];
|
|
4900
5509
|
}
|
|
4901
5510
|
});
|
|
4902
5511
|
});
|
|
4903
5512
|
}
|
|
4904
5513
|
/**
|
|
4905
|
-
* TODO:
|
|
4906
|
-
* TODO: [🪂] Do it in parallel 11:11
|
|
4907
|
-
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
5514
|
+
* TODO: !!!!!!! Maybe constrain to @promptbook/node bundle
|
|
4908
5515
|
*/
|
|
4909
5516
|
|
|
4910
5517
|
/**
|
|
@@ -4913,23 +5520,64 @@
|
|
|
4913
5520
|
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
4914
5521
|
* @public exported from `@promptbook/core`
|
|
4915
5522
|
*/
|
|
4916
|
-
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
5523
|
+
function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
4917
5524
|
return __awaiter(this, void 0, void 0, function () {
|
|
4918
|
-
var _a, maxParallelCount, knowledgePrepared;
|
|
5525
|
+
var _a, maxParallelCount, rootDirname, _b, isVerbose, knowledgePreparedUnflatten, knowledgePrepared;
|
|
4919
5526
|
var _this = this;
|
|
4920
|
-
return __generator(this, function (
|
|
4921
|
-
switch (
|
|
5527
|
+
return __generator(this, function (_c) {
|
|
5528
|
+
switch (_c.label) {
|
|
4922
5529
|
case 0:
|
|
4923
|
-
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
4924
|
-
|
|
4925
|
-
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
|
|
4926
|
-
var partialPieces, pieces;
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
5530
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, rootDirname = options.rootDirname, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
|
|
5531
|
+
knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
5532
|
+
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
5533
|
+
var partialPieces, sourceHandler, _a, _b, scraper, partialPiecesUnchecked, e_1_1, pieces;
|
|
5534
|
+
var e_1, _c;
|
|
5535
|
+
return __generator(this, function (_d) {
|
|
5536
|
+
switch (_d.label) {
|
|
5537
|
+
case 0:
|
|
5538
|
+
partialPieces = null;
|
|
5539
|
+
return [4 /*yield*/, makeKnowledgeSourceHandler(knowledgeSource, { rootDirname: rootDirname, isVerbose: isVerbose })];
|
|
4931
5540
|
case 1:
|
|
4932
|
-
|
|
5541
|
+
sourceHandler = _d.sent();
|
|
5542
|
+
_d.label = 2;
|
|
5543
|
+
case 2:
|
|
5544
|
+
_d.trys.push([2, 7, 8, 9]);
|
|
5545
|
+
_a = __values(arrayableToArray(tools.scrapers)), _b = _a.next();
|
|
5546
|
+
_d.label = 3;
|
|
5547
|
+
case 3:
|
|
5548
|
+
if (!!_b.done) return [3 /*break*/, 6];
|
|
5549
|
+
scraper = _b.value;
|
|
5550
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
5551
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
5552
|
+
) {
|
|
5553
|
+
return [3 /*break*/, 5];
|
|
5554
|
+
}
|
|
5555
|
+
return [4 /*yield*/, scraper.scrape(sourceHandler)];
|
|
5556
|
+
case 4:
|
|
5557
|
+
partialPiecesUnchecked = _d.sent();
|
|
5558
|
+
if (partialPiecesUnchecked !== null) {
|
|
5559
|
+
partialPieces = partialPiecesUnchecked;
|
|
5560
|
+
return [3 /*break*/, 6];
|
|
5561
|
+
}
|
|
5562
|
+
_d.label = 5;
|
|
5563
|
+
case 5:
|
|
5564
|
+
_b = _a.next();
|
|
5565
|
+
return [3 /*break*/, 3];
|
|
5566
|
+
case 6: return [3 /*break*/, 9];
|
|
5567
|
+
case 7:
|
|
5568
|
+
e_1_1 = _d.sent();
|
|
5569
|
+
e_1 = { error: e_1_1 };
|
|
5570
|
+
return [3 /*break*/, 9];
|
|
5571
|
+
case 8:
|
|
5572
|
+
try {
|
|
5573
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
5574
|
+
}
|
|
5575
|
+
finally { if (e_1) throw e_1.error; }
|
|
5576
|
+
return [7 /*endfinally*/];
|
|
5577
|
+
case 9:
|
|
5578
|
+
if (partialPieces === null) {
|
|
5579
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge from source: ".concat(knowledgeSource.sourceContent, "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage()), "\n\n\n "); }));
|
|
5580
|
+
}
|
|
4933
5581
|
pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
|
|
4934
5582
|
{
|
|
4935
5583
|
name: knowledgeSource.name,
|
|
@@ -4937,13 +5585,14 @@
|
|
|
4937
5585
|
// <- TODO: [❎]
|
|
4938
5586
|
},
|
|
4939
5587
|
] })); });
|
|
4940
|
-
|
|
5588
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
4941
5589
|
return [2 /*return*/];
|
|
4942
5590
|
}
|
|
4943
5591
|
});
|
|
4944
5592
|
}); })];
|
|
4945
5593
|
case 1:
|
|
4946
|
-
|
|
5594
|
+
_c.sent();
|
|
5595
|
+
knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
4947
5596
|
return [2 /*return*/, knowledgePrepared];
|
|
4948
5597
|
}
|
|
4949
5598
|
});
|
|
@@ -4960,7 +5609,7 @@
|
|
|
4960
5609
|
>
|
|
4961
5610
|
> export async function prepareKnowledgePieces(
|
|
4962
5611
|
> knowledge: PrepareKnowledgeKnowledge,
|
|
4963
|
-
> options:
|
|
5612
|
+
> options: PrepareAndScrapeOptions,
|
|
4964
5613
|
> ):
|
|
4965
5614
|
*/
|
|
4966
5615
|
/**
|
|
@@ -4972,158 +5621,6 @@
|
|
|
4972
5621
|
* [ ] One piece can have multiple sources
|
|
4973
5622
|
*/
|
|
4974
5623
|
|
|
4975
|
-
/**
|
|
4976
|
-
* Intercepts LLM tools and counts total usage of the tools
|
|
4977
|
-
*
|
|
4978
|
-
* @param llmTools LLM tools to be intercepted with usage counting
|
|
4979
|
-
* @returns LLM tools with same functionality with added total cost counting
|
|
4980
|
-
* @public exported from `@promptbook/core`
|
|
4981
|
-
*/
|
|
4982
|
-
function countTotalUsage(llmTools) {
|
|
4983
|
-
var _this = this;
|
|
4984
|
-
var totalUsage = ZERO_USAGE;
|
|
4985
|
-
var proxyTools = {
|
|
4986
|
-
get title() {
|
|
4987
|
-
// TODO: [🧠] Maybe put here some suffix
|
|
4988
|
-
return llmTools.title;
|
|
4989
|
-
},
|
|
4990
|
-
get description() {
|
|
4991
|
-
// TODO: [🧠] Maybe put here some suffix
|
|
4992
|
-
return llmTools.description;
|
|
4993
|
-
},
|
|
4994
|
-
checkConfiguration: function () {
|
|
4995
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
4996
|
-
return __generator(this, function (_a) {
|
|
4997
|
-
return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
|
|
4998
|
-
});
|
|
4999
|
-
});
|
|
5000
|
-
},
|
|
5001
|
-
listModels: function () {
|
|
5002
|
-
return /* not await */ llmTools.listModels();
|
|
5003
|
-
},
|
|
5004
|
-
getTotalUsage: function () {
|
|
5005
|
-
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
5006
|
-
return totalUsage;
|
|
5007
|
-
},
|
|
5008
|
-
};
|
|
5009
|
-
if (llmTools.callChatModel !== undefined) {
|
|
5010
|
-
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
5011
|
-
var promptResult;
|
|
5012
|
-
return __generator(this, function (_a) {
|
|
5013
|
-
switch (_a.label) {
|
|
5014
|
-
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
5015
|
-
case 1:
|
|
5016
|
-
promptResult = _a.sent();
|
|
5017
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
5018
|
-
return [2 /*return*/, promptResult];
|
|
5019
|
-
}
|
|
5020
|
-
});
|
|
5021
|
-
}); };
|
|
5022
|
-
}
|
|
5023
|
-
if (llmTools.callCompletionModel !== undefined) {
|
|
5024
|
-
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
5025
|
-
var promptResult;
|
|
5026
|
-
return __generator(this, function (_a) {
|
|
5027
|
-
switch (_a.label) {
|
|
5028
|
-
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
5029
|
-
case 1:
|
|
5030
|
-
promptResult = _a.sent();
|
|
5031
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
5032
|
-
return [2 /*return*/, promptResult];
|
|
5033
|
-
}
|
|
5034
|
-
});
|
|
5035
|
-
}); };
|
|
5036
|
-
}
|
|
5037
|
-
if (llmTools.callEmbeddingModel !== undefined) {
|
|
5038
|
-
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
5039
|
-
var promptResult;
|
|
5040
|
-
return __generator(this, function (_a) {
|
|
5041
|
-
switch (_a.label) {
|
|
5042
|
-
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
5043
|
-
case 1:
|
|
5044
|
-
promptResult = _a.sent();
|
|
5045
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
5046
|
-
return [2 /*return*/, promptResult];
|
|
5047
|
-
}
|
|
5048
|
-
});
|
|
5049
|
-
}); };
|
|
5050
|
-
}
|
|
5051
|
-
// <- Note: [🤖]
|
|
5052
|
-
return proxyTools;
|
|
5053
|
-
}
|
|
5054
|
-
/**
|
|
5055
|
-
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
5056
|
-
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
5057
|
-
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
5058
|
-
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
5059
|
-
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
5060
|
-
*/
|
|
5061
|
-
|
|
5062
|
-
/**
|
|
5063
|
-
* Prepares the persona for the pipeline
|
|
5064
|
-
*
|
|
5065
|
-
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
5066
|
-
* @public exported from `@promptbook/core`
|
|
5067
|
-
*/
|
|
5068
|
-
function preparePersona(personaDescription, options) {
|
|
5069
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
5070
|
-
var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
5071
|
-
var _c;
|
|
5072
|
-
return __generator(this, function (_d) {
|
|
5073
|
-
switch (_d.label) {
|
|
5074
|
-
case 0:
|
|
5075
|
-
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
5076
|
-
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
5077
|
-
_b = createPipelineExecutor;
|
|
5078
|
-
_c = {};
|
|
5079
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
|
|
5080
|
-
case 1:
|
|
5081
|
-
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
5082
|
-
_c.tools = {
|
|
5083
|
-
llm: llmTools,
|
|
5084
|
-
},
|
|
5085
|
-
_c)]);
|
|
5086
|
-
return [4 /*yield*/, llmTools.listModels()];
|
|
5087
|
-
case 2:
|
|
5088
|
-
availableModels = _d.sent();
|
|
5089
|
-
availableModelNames = availableModels
|
|
5090
|
-
.filter(function (_a) {
|
|
5091
|
-
var modelVariant = _a.modelVariant;
|
|
5092
|
-
return modelVariant === 'CHAT';
|
|
5093
|
-
})
|
|
5094
|
-
.map(function (_a) {
|
|
5095
|
-
var modelName = _a.modelName;
|
|
5096
|
-
return modelName;
|
|
5097
|
-
})
|
|
5098
|
-
.join(',');
|
|
5099
|
-
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
5100
|
-
case 3:
|
|
5101
|
-
result = _d.sent();
|
|
5102
|
-
assertsExecutionSuccessful(result);
|
|
5103
|
-
outputParameters = result.outputParameters;
|
|
5104
|
-
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
5105
|
-
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
5106
|
-
if (isVerbose) {
|
|
5107
|
-
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
5108
|
-
}
|
|
5109
|
-
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
5110
|
-
return [2 /*return*/, {
|
|
5111
|
-
modelVariant: 'CHAT',
|
|
5112
|
-
modelName: modelName,
|
|
5113
|
-
systemMessage: systemMessage,
|
|
5114
|
-
temperature: temperature,
|
|
5115
|
-
}];
|
|
5116
|
-
}
|
|
5117
|
-
});
|
|
5118
|
-
});
|
|
5119
|
-
}
|
|
5120
|
-
/**
|
|
5121
|
-
* TODO: [🔃][main] !!!!! If the persona was prepared with different version or different set of models, prepare it once again
|
|
5122
|
-
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
5123
|
-
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
5124
|
-
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
5125
|
-
*/
|
|
5126
|
-
|
|
5127
5624
|
/**
|
|
5128
5625
|
* @@@
|
|
5129
5626
|
*
|
|
@@ -5158,7 +5655,7 @@
|
|
|
5158
5655
|
*
|
|
5159
5656
|
* @public exported from `@promptbook/core`
|
|
5160
5657
|
*/
|
|
5161
|
-
function prepareTemplates(pipeline, options) {
|
|
5658
|
+
function prepareTemplates(pipeline, tools, options) {
|
|
5162
5659
|
return __awaiter(this, void 0, void 0, function () {
|
|
5163
5660
|
var _a, maxParallelCount, templates, parameters, knowledgePiecesCount, templatesPrepared;
|
|
5164
5661
|
var _this = this;
|
|
@@ -5167,11 +5664,9 @@
|
|
|
5167
5664
|
case 0:
|
|
5168
5665
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
5169
5666
|
templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
5170
|
-
// TODO:[main] !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
5667
|
+
// TODO: [main] !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
5171
5668
|
TODO_USE(parameters);
|
|
5172
|
-
templatesPrepared = new Array(
|
|
5173
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
5174
|
-
templates.length);
|
|
5669
|
+
templatesPrepared = new Array(templates.length);
|
|
5175
5670
|
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 () {
|
|
5176
5671
|
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
5177
5672
|
return __generator(this, function (_a) {
|
|
@@ -5214,14 +5709,14 @@
|
|
|
5214
5709
|
* Note: When the pipeline is already prepared, it returns the same pipeline
|
|
5215
5710
|
* @public exported from `@promptbook/core`
|
|
5216
5711
|
*/
|
|
5217
|
-
function preparePipeline(pipeline, options) {
|
|
5712
|
+
function preparePipeline(pipeline, tools, options) {
|
|
5218
5713
|
return __awaiter(this, void 0, void 0, function () {
|
|
5219
|
-
var
|
|
5714
|
+
var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters, templates,
|
|
5220
5715
|
/*
|
|
5221
5716
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
5222
5717
|
knowledgeSources /*
|
|
5223
5718
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
5224
|
-
<- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, templatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
5719
|
+
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, templatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
5225
5720
|
var _this = this;
|
|
5226
5721
|
return __generator(this, function (_c) {
|
|
5227
5722
|
switch (_c.label) {
|
|
@@ -5229,8 +5724,13 @@
|
|
|
5229
5724
|
if (isPipelinePrepared(pipeline)) {
|
|
5230
5725
|
return [2 /*return*/, pipeline];
|
|
5231
5726
|
}
|
|
5232
|
-
|
|
5727
|
+
rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
|
|
5233
5728
|
parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
5729
|
+
if (tools === undefined || tools.llm === undefined) {
|
|
5730
|
+
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
5731
|
+
}
|
|
5732
|
+
_llms = arrayableToArray(tools.llm);
|
|
5733
|
+
llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
|
|
5234
5734
|
llmToolsWithUsage = countTotalUsage(llmTools);
|
|
5235
5735
|
currentPreparation = {
|
|
5236
5736
|
id: 1,
|
|
@@ -5243,15 +5743,13 @@
|
|
|
5243
5743
|
// <- TODO: [🧊]
|
|
5244
5744
|
currentPreparation,
|
|
5245
5745
|
];
|
|
5246
|
-
preparedPersonas = new Array(
|
|
5247
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
5248
|
-
personas.length);
|
|
5746
|
+
preparedPersonas = new Array(personas.length);
|
|
5249
5747
|
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
5250
5748
|
var modelRequirements, preparedPersona;
|
|
5251
5749
|
return __generator(this, function (_a) {
|
|
5252
5750
|
switch (_a.label) {
|
|
5253
|
-
case 0: return [4 /*yield*/, preparePersona(persona.description, {
|
|
5254
|
-
|
|
5751
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
5752
|
+
rootDirname: rootDirname,
|
|
5255
5753
|
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
5256
5754
|
isVerbose: isVerbose,
|
|
5257
5755
|
})];
|
|
@@ -5266,11 +5764,7 @@
|
|
|
5266
5764
|
case 1:
|
|
5267
5765
|
_c.sent();
|
|
5268
5766
|
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
5269
|
-
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, {
|
|
5270
|
-
llmTools: llmToolsWithUsage,
|
|
5271
|
-
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
5272
|
-
isVerbose: isVerbose,
|
|
5273
|
-
})];
|
|
5767
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
|
|
5274
5768
|
case 2:
|
|
5275
5769
|
partialknowledgePiecesPrepared = _c.sent();
|
|
5276
5770
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
@@ -5278,8 +5772,8 @@
|
|
|
5278
5772
|
parameters: parameters,
|
|
5279
5773
|
templates: templates,
|
|
5280
5774
|
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
5281
|
-
}, {
|
|
5282
|
-
|
|
5775
|
+
}, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
5776
|
+
rootDirname: rootDirname,
|
|
5283
5777
|
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
5284
5778
|
isVerbose: isVerbose,
|
|
5285
5779
|
})];
|
|
@@ -5302,36 +5796,10 @@
|
|
|
5302
5796
|
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
5303
5797
|
*/
|
|
5304
5798
|
|
|
5305
|
-
/**
|
|
5306
|
-
* Tests if given string is valid URL.
|
|
5307
|
-
*
|
|
5308
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
5309
|
-
* @public exported from `@promptbook/utils`
|
|
5310
|
-
*/
|
|
5311
|
-
function isValidFilePath(filePath) {
|
|
5312
|
-
if (typeof filePath !== 'string') {
|
|
5313
|
-
return false;
|
|
5314
|
-
}
|
|
5315
|
-
var filePathSlashes = filePath.split('\\').join('/');
|
|
5316
|
-
// Absolute Unix path: /hello.txt
|
|
5317
|
-
if (/^(\/)/i.test(filePathSlashes)) {
|
|
5318
|
-
return true;
|
|
5319
|
-
}
|
|
5320
|
-
// Absolute Windows path: /hello.txt
|
|
5321
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
5322
|
-
return true;
|
|
5323
|
-
}
|
|
5324
|
-
// Relative path: ./hello.txt
|
|
5325
|
-
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
5326
|
-
return true;
|
|
5327
|
-
}
|
|
5328
|
-
return false;
|
|
5329
|
-
}
|
|
5330
|
-
|
|
5331
5799
|
/**
|
|
5332
5800
|
* Parses the knowledge command
|
|
5333
5801
|
*
|
|
5334
|
-
* @see
|
|
5802
|
+
* @see `documentationUrl` for more details
|
|
5335
5803
|
* @private within the commands folder
|
|
5336
5804
|
*/
|
|
5337
5805
|
var knowledgeCommandParser = {
|
|
@@ -5349,7 +5817,7 @@
|
|
|
5349
5817
|
*/
|
|
5350
5818
|
description: "Tells promptbook which external knowledge to use",
|
|
5351
5819
|
/**
|
|
5352
|
-
* Link to
|
|
5820
|
+
* Link to documentation
|
|
5353
5821
|
*/
|
|
5354
5822
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
5355
5823
|
/**
|
|
@@ -5371,7 +5839,7 @@
|
|
|
5371
5839
|
if (sourceContent === '') {
|
|
5372
5840
|
throw new ParseError("Source is not defined");
|
|
5373
5841
|
}
|
|
5374
|
-
// TODO:[main] !!!! Following checks should be applied every link in the `sourceContent`
|
|
5842
|
+
// TODO: [main] !!!! Following checks should be applied every link in the `sourceContent`
|
|
5375
5843
|
if (sourceContent.startsWith('http://')) {
|
|
5376
5844
|
throw new ParseError("Source is not secure");
|
|
5377
5845
|
}
|
|
@@ -5393,11 +5861,8 @@
|
|
|
5393
5861
|
*/
|
|
5394
5862
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5395
5863
|
var sourceContent = command.sourceContent;
|
|
5396
|
-
var name = 'source-' + sha256__default["default"](hexEncoder__default["default"].parse(JSON.stringify(sourceContent))).toString( /* hex */);
|
|
5397
|
-
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
5398
|
-
// <- TODO: This should be replaced with a better name later in preparation (done with some propper LLM summarization)
|
|
5399
5864
|
$pipelineJson.knowledgeSources.push({
|
|
5400
|
-
name:
|
|
5865
|
+
name: sourceContentToName(sourceContent),
|
|
5401
5866
|
sourceContent: sourceContent,
|
|
5402
5867
|
});
|
|
5403
5868
|
},
|
|
@@ -5427,7 +5892,7 @@
|
|
|
5427
5892
|
/**
|
|
5428
5893
|
* Parses the template command
|
|
5429
5894
|
*
|
|
5430
|
-
* @see
|
|
5895
|
+
* @see `documentationUrl` for more details
|
|
5431
5896
|
* @private within the commands folder
|
|
5432
5897
|
*/
|
|
5433
5898
|
var templateCommandParser = {
|
|
@@ -5463,7 +5928,7 @@
|
|
|
5463
5928
|
*/
|
|
5464
5929
|
description: "What should the code template template do",
|
|
5465
5930
|
/**
|
|
5466
|
-
* Link to
|
|
5931
|
+
* Link to documentation
|
|
5467
5932
|
*/
|
|
5468
5933
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
|
|
5469
5934
|
/**
|
|
@@ -5688,7 +6153,7 @@
|
|
|
5688
6153
|
/**
|
|
5689
6154
|
* Parses the expect command
|
|
5690
6155
|
*
|
|
5691
|
-
* @see
|
|
6156
|
+
* @see `documentationUrl` for more details
|
|
5692
6157
|
* @private within the commands folder
|
|
5693
6158
|
*/
|
|
5694
6159
|
var expectCommandParser = {
|
|
@@ -5706,7 +6171,7 @@
|
|
|
5706
6171
|
*/
|
|
5707
6172
|
description: spaceTrim__default["default"]("\n Expect command describes the desired output of the template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
5708
6173
|
/**
|
|
5709
|
-
* Link to
|
|
6174
|
+
* Link to documentation
|
|
5710
6175
|
*/
|
|
5711
6176
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
|
|
5712
6177
|
/**
|
|
@@ -5813,98 +6278,28 @@
|
|
|
5813
6278
|
if ($templateJson.expectations[unit].max !== undefined) {
|
|
5814
6279
|
throw new ParseError("Already defined maximum ".concat($templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
5815
6280
|
}
|
|
5816
|
-
$templateJson.expectations[unit].max = command.amount;
|
|
5817
|
-
}
|
|
5818
|
-
},
|
|
5819
|
-
/**
|
|
5820
|
-
* Converts the FORMAT command back to string
|
|
5821
|
-
*
|
|
5822
|
-
* Note: This is used in `pipelineJsonToString` utility
|
|
5823
|
-
*/
|
|
5824
|
-
stringify: function (command) {
|
|
5825
|
-
keepUnused(command);
|
|
5826
|
-
return "---"; // <- TODO: [🛋] Implement
|
|
5827
|
-
},
|
|
5828
|
-
/**
|
|
5829
|
-
* Reads the FORMAT command from the `TemplateJson`
|
|
5830
|
-
*
|
|
5831
|
-
* Note: This is used in `pipelineJsonToString` utility
|
|
5832
|
-
*/
|
|
5833
|
-
takeFromTemplateJson: function ($templateJson) {
|
|
5834
|
-
keepUnused($templateJson);
|
|
5835
|
-
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5836
|
-
},
|
|
5837
|
-
};
|
|
5838
|
-
|
|
5839
|
-
/**
|
|
5840
|
-
* @@@
|
|
5841
|
-
*
|
|
5842
|
-
* @param text @@@
|
|
5843
|
-
* @returns @@@
|
|
5844
|
-
* @example 'HELLO_WORLD'
|
|
5845
|
-
* @example 'I_LOVE_PROMPTBOOK'
|
|
5846
|
-
* @public exported from `@promptbook/utils`
|
|
5847
|
-
*/
|
|
5848
|
-
function normalizeTo_SCREAMING_CASE(text) {
|
|
5849
|
-
var e_1, _a;
|
|
5850
|
-
var charType;
|
|
5851
|
-
var lastCharType = 'OTHER';
|
|
5852
|
-
var normalizedName = '';
|
|
5853
|
-
try {
|
|
5854
|
-
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
5855
|
-
var char = text_1_1.value;
|
|
5856
|
-
var normalizedChar = void 0;
|
|
5857
|
-
if (/^[a-z]$/.test(char)) {
|
|
5858
|
-
charType = 'LOWERCASE';
|
|
5859
|
-
normalizedChar = char.toUpperCase();
|
|
5860
|
-
}
|
|
5861
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
5862
|
-
charType = 'UPPERCASE';
|
|
5863
|
-
normalizedChar = char;
|
|
5864
|
-
}
|
|
5865
|
-
else if (/^[0-9]$/.test(char)) {
|
|
5866
|
-
charType = 'NUMBER';
|
|
5867
|
-
normalizedChar = char;
|
|
5868
|
-
}
|
|
5869
|
-
else if (/^\/$/.test(char)) {
|
|
5870
|
-
charType = 'SLASH';
|
|
5871
|
-
normalizedChar = char;
|
|
5872
|
-
}
|
|
5873
|
-
else {
|
|
5874
|
-
charType = 'OTHER';
|
|
5875
|
-
normalizedChar = '_';
|
|
5876
|
-
}
|
|
5877
|
-
if (charType !== lastCharType &&
|
|
5878
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
5879
|
-
!(lastCharType === 'NUMBER') &&
|
|
5880
|
-
!(charType === 'NUMBER')) {
|
|
5881
|
-
normalizedName += '_';
|
|
5882
|
-
}
|
|
5883
|
-
normalizedName += normalizedChar;
|
|
5884
|
-
lastCharType = charType;
|
|
5885
|
-
}
|
|
5886
|
-
}
|
|
5887
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5888
|
-
finally {
|
|
5889
|
-
try {
|
|
5890
|
-
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
6281
|
+
$templateJson.expectations[unit].max = command.amount;
|
|
5891
6282
|
}
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
6283
|
+
},
|
|
6284
|
+
/**
|
|
6285
|
+
* Converts the FORMAT command back to string
|
|
6286
|
+
*
|
|
6287
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
6288
|
+
*/
|
|
6289
|
+
stringify: function (command) {
|
|
6290
|
+
keepUnused(command);
|
|
6291
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
6292
|
+
},
|
|
6293
|
+
/**
|
|
6294
|
+
* Reads the FORMAT command from the `TemplateJson`
|
|
6295
|
+
*
|
|
6296
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
6297
|
+
*/
|
|
6298
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
6299
|
+
keepUnused($templateJson);
|
|
6300
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
6301
|
+
},
|
|
6302
|
+
};
|
|
5908
6303
|
|
|
5909
6304
|
/**
|
|
5910
6305
|
* @@@
|
|
@@ -5970,6 +6365,22 @@
|
|
|
5970
6365
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
5971
6366
|
*/
|
|
5972
6367
|
|
|
6368
|
+
/**
|
|
6369
|
+
* Removes emojis from a string and fix whitespaces
|
|
6370
|
+
*
|
|
6371
|
+
* @param text with emojis
|
|
6372
|
+
* @returns text without emojis
|
|
6373
|
+
* @public exported from `@promptbook/utils`
|
|
6374
|
+
*/
|
|
6375
|
+
function removeEmojis(text) {
|
|
6376
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
6377
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
6378
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
6379
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
6380
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
6381
|
+
return text;
|
|
6382
|
+
}
|
|
6383
|
+
|
|
5973
6384
|
/**
|
|
5974
6385
|
* Removes quotes from a string
|
|
5975
6386
|
*
|
|
@@ -6076,7 +6487,7 @@
|
|
|
6076
6487
|
*
|
|
6077
6488
|
* Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.ptbk.md` file
|
|
6078
6489
|
*
|
|
6079
|
-
* @see
|
|
6490
|
+
* @see `documentationUrl` for more details
|
|
6080
6491
|
* @private within the commands folder
|
|
6081
6492
|
*/
|
|
6082
6493
|
var foreachCommandParser = {
|
|
@@ -6098,7 +6509,7 @@
|
|
|
6098
6509
|
*/
|
|
6099
6510
|
description: "@@",
|
|
6100
6511
|
/**
|
|
6101
|
-
* Link to
|
|
6512
|
+
* Link to documentation
|
|
6102
6513
|
*/
|
|
6103
6514
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/148',
|
|
6104
6515
|
/**
|
|
@@ -6106,8 +6517,10 @@
|
|
|
6106
6517
|
*/
|
|
6107
6518
|
examples: [
|
|
6108
6519
|
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
6109
|
-
'
|
|
6110
|
-
'
|
|
6520
|
+
'FOREACH Csv Cell `{customers}` -> `{cell}`',
|
|
6521
|
+
'FOREACH Csv Row `{customers}` -> `{firstName}`, `{lastName}`, `+{email}`',
|
|
6522
|
+
'FOR Text Line `{customers}` -> `{customer}`',
|
|
6523
|
+
'EACH Text Line `{customers}` -> `{customer}`',
|
|
6111
6524
|
],
|
|
6112
6525
|
/**
|
|
6113
6526
|
* Parses the FOREACH command
|
|
@@ -6141,20 +6554,49 @@
|
|
|
6141
6554
|
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
6142
6555
|
}
|
|
6143
6556
|
var parameterName = validateParameterName(parameterNameArg);
|
|
6144
|
-
var
|
|
6557
|
+
var outputSubparameterName = null;
|
|
6558
|
+
// TODO: [4] DRY
|
|
6559
|
+
var inputSubparameterNames = args
|
|
6145
6560
|
.slice(4)
|
|
6146
6561
|
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6562
|
+
.filter(function (parameterName) { return !parameterName.includes('+'); })
|
|
6147
6563
|
.filter(function (parameterName) { return parameterName !== ''; })
|
|
6148
6564
|
.map(validateParameterName);
|
|
6149
|
-
|
|
6150
|
-
|
|
6565
|
+
// TODO: [4] DRY
|
|
6566
|
+
var outputSubparameterNames = args
|
|
6567
|
+
.slice(4)
|
|
6568
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6569
|
+
.filter(function (parameterName) { return parameterName.includes('+'); })
|
|
6570
|
+
.map(function (parameterName) { return parameterName.split('+').join(''); })
|
|
6571
|
+
.map(validateParameterName);
|
|
6572
|
+
if (outputSubparameterNames.length === 1) {
|
|
6573
|
+
outputSubparameterName = outputSubparameterNames[0];
|
|
6574
|
+
}
|
|
6575
|
+
else if (outputSubparameterNames.length > 1) {
|
|
6576
|
+
throw new ParseError("FOREACH command can not have more than one output subparameter");
|
|
6577
|
+
}
|
|
6578
|
+
if (inputSubparameterNames.length === 0) {
|
|
6579
|
+
throw new ParseError("FOREACH command must have at least one input subparameter");
|
|
6580
|
+
}
|
|
6581
|
+
if (outputSubparameterName === null) {
|
|
6582
|
+
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
6583
|
+
if (formatName === 'CSV' && subformatName === 'CELL') {
|
|
6584
|
+
outputSubparameterName = 'newCell';
|
|
6585
|
+
}
|
|
6586
|
+
else if (formatName === 'TEXT' && subformatName === 'LINE') {
|
|
6587
|
+
outputSubparameterName = 'newLine';
|
|
6588
|
+
}
|
|
6589
|
+
else {
|
|
6590
|
+
throw new ParseError(spaceTrim__default["default"]("\n FOREACH ".concat(formatName, " ").concat(subformatName, " must specify output subparameter\n\n Correct example:\n - FOREACH ").concat(formatName, " ").concat(subformatName, " {").concat(parameterName, "} -> {inputSubparameterName1}, {inputSubparameterName2}, +{outputSubparameterName}\n\n ")));
|
|
6591
|
+
}
|
|
6151
6592
|
}
|
|
6152
6593
|
return {
|
|
6153
6594
|
type: 'FOREACH',
|
|
6154
6595
|
formatName: formatName,
|
|
6155
6596
|
subformatName: subformatName,
|
|
6156
6597
|
parameterName: parameterName,
|
|
6157
|
-
|
|
6598
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6599
|
+
outputSubparameterName: outputSubparameterName,
|
|
6158
6600
|
};
|
|
6159
6601
|
},
|
|
6160
6602
|
/**
|
|
@@ -6163,10 +6605,16 @@
|
|
|
6163
6605
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
6164
6606
|
*/
|
|
6165
6607
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
6166
|
-
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName,
|
|
6608
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
6167
6609
|
// TODO: [🍭] Detect double use
|
|
6168
6610
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
6169
|
-
$templateJson.foreach = {
|
|
6611
|
+
$templateJson.foreach = {
|
|
6612
|
+
formatName: formatName,
|
|
6613
|
+
subformatName: subformatName,
|
|
6614
|
+
parameterName: parameterName,
|
|
6615
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6616
|
+
outputSubparameterName: outputSubparameterName,
|
|
6617
|
+
};
|
|
6170
6618
|
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
6171
6619
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
6172
6620
|
},
|
|
@@ -6196,7 +6644,7 @@
|
|
|
6196
6644
|
/**
|
|
6197
6645
|
* Parses the format command
|
|
6198
6646
|
*
|
|
6199
|
-
* @see
|
|
6647
|
+
* @see `documentationUrl` for more details
|
|
6200
6648
|
* @private within the commands folder
|
|
6201
6649
|
*/
|
|
6202
6650
|
var formatCommandParser = {
|
|
@@ -6214,7 +6662,7 @@
|
|
|
6214
6662
|
*/
|
|
6215
6663
|
description: spaceTrim__default["default"]("\n Format command describes the desired output of the template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
6216
6664
|
/**
|
|
6217
|
-
* Link to
|
|
6665
|
+
* Link to documentation
|
|
6218
6666
|
*/
|
|
6219
6667
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
|
|
6220
6668
|
/**
|
|
@@ -6270,7 +6718,7 @@
|
|
|
6270
6718
|
/**
|
|
6271
6719
|
* Parses the joker command
|
|
6272
6720
|
*
|
|
6273
|
-
* @see
|
|
6721
|
+
* @see `documentationUrl` for more details
|
|
6274
6722
|
* @private within the commands folder
|
|
6275
6723
|
*/
|
|
6276
6724
|
var jokerCommandParser = {
|
|
@@ -6288,7 +6736,7 @@
|
|
|
6288
6736
|
*/
|
|
6289
6737
|
description: "Joker parameter is used instead of executing the template result if jokers value meets the expectations requirements",
|
|
6290
6738
|
/**
|
|
6291
|
-
* Link to
|
|
6739
|
+
* Link to documentation
|
|
6292
6740
|
*/
|
|
6293
6741
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
|
|
6294
6742
|
/**
|
|
@@ -6349,7 +6797,7 @@
|
|
|
6349
6797
|
/**
|
|
6350
6798
|
* Parses the model command
|
|
6351
6799
|
*
|
|
6352
|
-
* @see
|
|
6800
|
+
* @see `documentationUrl` for more details
|
|
6353
6801
|
* @private within the commands folder
|
|
6354
6802
|
*/
|
|
6355
6803
|
var modelCommandParser = {
|
|
@@ -6367,7 +6815,7 @@
|
|
|
6367
6815
|
*/
|
|
6368
6816
|
description: "Tells which `modelRequirements` (for example which model) to use for the prompt template execution",
|
|
6369
6817
|
/**
|
|
6370
|
-
* Link to
|
|
6818
|
+
* Link to documentation
|
|
6371
6819
|
*/
|
|
6372
6820
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
|
|
6373
6821
|
/**
|
|
@@ -6449,7 +6897,11 @@
|
|
|
6449
6897
|
// TODO: [🚜] DRY
|
|
6450
6898
|
if ($templateJson.modelRequirements[command.key] !== undefined) {
|
|
6451
6899
|
if ($templateJson.modelRequirements[command.key] === command.value) {
|
|
6452
|
-
console.warn("Multiple commands `MODEL ".concat(
|
|
6900
|
+
console.warn("Multiple commands `MODEL ".concat({
|
|
6901
|
+
modelName: 'NAME',
|
|
6902
|
+
modelVariant: 'VARIANT',
|
|
6903
|
+
maxTokens: '???',
|
|
6904
|
+
}[command.key], " ").concat(command.value, "` in the template \"").concat($templateJson.title || $templateJson.name, "\""));
|
|
6453
6905
|
}
|
|
6454
6906
|
else {
|
|
6455
6907
|
throw new ParseError(spaceTrim__default["default"]("\n Redefinition of MODEL `".concat(command.key, "` in the template \"").concat($templateJson.title || $templateJson.name, "\"\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($templateJson.modelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
|
|
@@ -6492,7 +6944,7 @@
|
|
|
6492
6944
|
/**
|
|
6493
6945
|
* Parses the parameter command
|
|
6494
6946
|
*
|
|
6495
|
-
* @see
|
|
6947
|
+
* @see `documentationUrl` for more details
|
|
6496
6948
|
* @private within the commands folder
|
|
6497
6949
|
*/
|
|
6498
6950
|
var parameterCommandParser = {
|
|
@@ -6517,7 +6969,7 @@
|
|
|
6517
6969
|
*/
|
|
6518
6970
|
description: "Describes one parameter of the template",
|
|
6519
6971
|
/**
|
|
6520
|
-
* Link to
|
|
6972
|
+
* Link to documentation
|
|
6521
6973
|
*/
|
|
6522
6974
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/68',
|
|
6523
6975
|
/**
|
|
@@ -6602,7 +7054,7 @@
|
|
|
6602
7054
|
/**
|
|
6603
7055
|
* Parses the persona command
|
|
6604
7056
|
*
|
|
6605
|
-
* @see
|
|
7057
|
+
* @see `documentationUrl` for more details
|
|
6606
7058
|
* @private within the commands folder
|
|
6607
7059
|
*/
|
|
6608
7060
|
var personaCommandParser = {
|
|
@@ -6624,7 +7076,7 @@
|
|
|
6624
7076
|
*/
|
|
6625
7077
|
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
6626
7078
|
/**
|
|
6627
|
-
* Link to
|
|
7079
|
+
* Link to documentation
|
|
6628
7080
|
*/
|
|
6629
7081
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
6630
7082
|
/**
|
|
@@ -6740,7 +7192,7 @@
|
|
|
6740
7192
|
/**
|
|
6741
7193
|
* Parses the postprocess command
|
|
6742
7194
|
*
|
|
6743
|
-
* @see
|
|
7195
|
+
* @see `documentationUrl` for more details
|
|
6744
7196
|
* @private within the commands folder
|
|
6745
7197
|
*/
|
|
6746
7198
|
var postprocessCommandParser = {
|
|
@@ -6759,7 +7211,7 @@
|
|
|
6759
7211
|
*/
|
|
6760
7212
|
description: "Defines the postprocess function to be used on the result from LLM and before the result is validated",
|
|
6761
7213
|
/**
|
|
6762
|
-
* Link to
|
|
7214
|
+
* Link to documentation
|
|
6763
7215
|
*/
|
|
6764
7216
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/31',
|
|
6765
7217
|
/**
|
|
@@ -6820,7 +7272,7 @@
|
|
|
6820
7272
|
/**
|
|
6821
7273
|
* Parses the PROMPTBOOK_VERSION command
|
|
6822
7274
|
*
|
|
6823
|
-
* @see
|
|
7275
|
+
* @see `documentationUrl` for more details
|
|
6824
7276
|
* @private within the commands folder
|
|
6825
7277
|
*/
|
|
6826
7278
|
var promptbookVersionCommandParser = {
|
|
@@ -6839,7 +7291,7 @@
|
|
|
6839
7291
|
*/
|
|
6840
7292
|
description: "Which version of the promptbook is the .ptbk.md using",
|
|
6841
7293
|
/**
|
|
6842
|
-
* Link to
|
|
7294
|
+
* Link to documentation
|
|
6843
7295
|
*/
|
|
6844
7296
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/69',
|
|
6845
7297
|
/**
|
|
@@ -6898,7 +7350,7 @@
|
|
|
6898
7350
|
/**
|
|
6899
7351
|
* Parses the url command
|
|
6900
7352
|
*
|
|
6901
|
-
* @see
|
|
7353
|
+
* @see `documentationUrl` for more details
|
|
6902
7354
|
* @private within the commands folder
|
|
6903
7355
|
*/
|
|
6904
7356
|
var urlCommandParser = {
|
|
@@ -6921,7 +7373,7 @@
|
|
|
6921
7373
|
*/
|
|
6922
7374
|
description: "Declares unique URL for the pipeline",
|
|
6923
7375
|
/**
|
|
6924
|
-
* Link to
|
|
7376
|
+
* Link to documentation
|
|
6925
7377
|
*/
|
|
6926
7378
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/70',
|
|
6927
7379
|
/**
|
|
@@ -7001,7 +7453,7 @@
|
|
|
7001
7453
|
/**
|
|
7002
7454
|
* Parses the action command
|
|
7003
7455
|
*
|
|
7004
|
-
* @see
|
|
7456
|
+
* @see `documentationUrl` for more details
|
|
7005
7457
|
* @private within the commands folder
|
|
7006
7458
|
*/
|
|
7007
7459
|
var actionCommandParser = {
|
|
@@ -7019,7 +7471,7 @@
|
|
|
7019
7471
|
*/
|
|
7020
7472
|
description: "Actions influences from the pipeline or template into external world. Like turning on a light, sending an email, etc.",
|
|
7021
7473
|
/**
|
|
7022
|
-
* Link to
|
|
7474
|
+
* Link to documentation
|
|
7023
7475
|
*/
|
|
7024
7476
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/72',
|
|
7025
7477
|
/**
|
|
@@ -7071,7 +7523,7 @@
|
|
|
7071
7523
|
/**
|
|
7072
7524
|
* Parses the instrument command
|
|
7073
7525
|
*
|
|
7074
|
-
* @see
|
|
7526
|
+
* @see `documentationUrl` for more details
|
|
7075
7527
|
* @private within the commands folder
|
|
7076
7528
|
*/
|
|
7077
7529
|
var instrumentCommandParser = {
|
|
@@ -7089,7 +7541,7 @@
|
|
|
7089
7541
|
*/
|
|
7090
7542
|
description: "Instrument command is used to specify the instrument to be used in the pipeline or template like search, calculate, etc.",
|
|
7091
7543
|
/**
|
|
7092
|
-
* Link to
|
|
7544
|
+
* Link to documentation
|
|
7093
7545
|
*/
|
|
7094
7546
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/71',
|
|
7095
7547
|
/**
|
|
@@ -7144,7 +7596,7 @@
|
|
|
7144
7596
|
*
|
|
7145
7597
|
* Note: @@@ This command is used as boilerplate for new commands - it should NOT be used in any `.ptbk.md` file
|
|
7146
7598
|
*
|
|
7147
|
-
* @see
|
|
7599
|
+
* @see `documentationUrl` for more details
|
|
7148
7600
|
* @private within the commands folder
|
|
7149
7601
|
*/
|
|
7150
7602
|
var boilerplateCommandParser = {
|
|
@@ -7166,7 +7618,7 @@
|
|
|
7166
7618
|
*/
|
|
7167
7619
|
description: "@@",
|
|
7168
7620
|
/**
|
|
7169
|
-
* Link to
|
|
7621
|
+
* Link to documentation
|
|
7170
7622
|
*/
|
|
7171
7623
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
7172
7624
|
/**
|
|
@@ -7676,6 +8128,30 @@
|
|
|
7676
8128
|
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
7677
8129
|
}
|
|
7678
8130
|
|
|
8131
|
+
/**
|
|
8132
|
+
* @@@
|
|
8133
|
+
*
|
|
8134
|
+
* @param value @@@
|
|
8135
|
+
* @returns @@@
|
|
8136
|
+
* @example @@@
|
|
8137
|
+
* @public exported from `@promptbook/utils`
|
|
8138
|
+
*/
|
|
8139
|
+
function titleToName(value) {
|
|
8140
|
+
if (isValidUrl(value)) {
|
|
8141
|
+
value = value.replace(/^https?:\/\//, '');
|
|
8142
|
+
value = value.replace(/\.html$/, '');
|
|
8143
|
+
}
|
|
8144
|
+
else if (isValidFilePath(value)) {
|
|
8145
|
+
value = path.basename(value);
|
|
8146
|
+
// Note: Keeping extension in the name
|
|
8147
|
+
}
|
|
8148
|
+
value = value.split('/').join('-');
|
|
8149
|
+
value = removeEmojis(value);
|
|
8150
|
+
value = normalizeToKebabCase(value);
|
|
8151
|
+
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
8152
|
+
return value;
|
|
8153
|
+
}
|
|
8154
|
+
|
|
7679
8155
|
/**
|
|
7680
8156
|
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
7681
8157
|
*
|
|
@@ -7988,7 +8464,7 @@
|
|
|
7988
8464
|
return $asDeeplyFrozenSerializableJson('pipelineJson', $pipelineJson);
|
|
7989
8465
|
}
|
|
7990
8466
|
/**
|
|
7991
|
-
* TODO:[main] !!!! Warn if used only sync version
|
|
8467
|
+
* TODO: [main] !!!! Warn if used only sync version
|
|
7992
8468
|
* TODO: [🚞] Report here line/column of error
|
|
7993
8469
|
* TODO: Use spaceTrim more effectively
|
|
7994
8470
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
@@ -8010,22 +8486,23 @@
|
|
|
8010
8486
|
* Note: This function acts as compilation process
|
|
8011
8487
|
*
|
|
8012
8488
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
8489
|
+
* @param tools - Tools for the preparation and scraping - if not provided together with `llm`, the preparation will be skipped
|
|
8013
8490
|
* @param options - Options and tools for the compilation
|
|
8014
8491
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
8015
8492
|
* @throws {ParseError} if the promptbook string is not valid
|
|
8016
8493
|
* @public exported from `@promptbook/core`
|
|
8017
8494
|
*/
|
|
8018
|
-
function pipelineStringToJson(pipelineString, options) {
|
|
8019
|
-
if (options === void 0) { options = { llmTools: null }; }
|
|
8495
|
+
function pipelineStringToJson(pipelineString, tools, options) {
|
|
8020
8496
|
return __awaiter(this, void 0, void 0, function () {
|
|
8021
|
-
var
|
|
8497
|
+
var pipelineJson;
|
|
8022
8498
|
return __generator(this, function (_a) {
|
|
8023
8499
|
switch (_a.label) {
|
|
8024
8500
|
case 0:
|
|
8025
|
-
llmTools = options.llmTools;
|
|
8026
8501
|
pipelineJson = pipelineStringToJsonSync(pipelineString);
|
|
8027
|
-
if (!(
|
|
8028
|
-
return [4 /*yield*/, preparePipeline(pipelineJson,
|
|
8502
|
+
if (!(tools !== undefined && tools.llm !== undefined)) return [3 /*break*/, 2];
|
|
8503
|
+
return [4 /*yield*/, preparePipeline(pipelineJson, tools, options || {
|
|
8504
|
+
rootDirname: null,
|
|
8505
|
+
})];
|
|
8029
8506
|
case 1:
|
|
8030
8507
|
pipelineJson = _a.sent();
|
|
8031
8508
|
_a.label = 2;
|
|
@@ -8233,6 +8710,38 @@
|
|
|
8233
8710
|
* TODO: [🍙] Make some standard order of json properties
|
|
8234
8711
|
*/
|
|
8235
8712
|
|
|
8713
|
+
/**
|
|
8714
|
+
* Delagates the user interaction to a async callback function
|
|
8715
|
+
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
8716
|
+
*
|
|
8717
|
+
* @public exported from `@promptbook/core`
|
|
8718
|
+
*/
|
|
8719
|
+
var CallbackInterfaceTools = /** @class */ (function () {
|
|
8720
|
+
function CallbackInterfaceTools(options) {
|
|
8721
|
+
this.options = options;
|
|
8722
|
+
}
|
|
8723
|
+
/**
|
|
8724
|
+
* Trigger the custom callback function
|
|
8725
|
+
*/
|
|
8726
|
+
CallbackInterfaceTools.prototype.promptDialog = function (options) {
|
|
8727
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
8728
|
+
var answer;
|
|
8729
|
+
return __generator(this, function (_a) {
|
|
8730
|
+
switch (_a.label) {
|
|
8731
|
+
case 0: return [4 /*yield*/, this.options.callback(options)];
|
|
8732
|
+
case 1:
|
|
8733
|
+
answer = _a.sent();
|
|
8734
|
+
if (this.options.isVerbose) {
|
|
8735
|
+
console.info(spaceTrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
|
|
8736
|
+
}
|
|
8737
|
+
return [2 /*return*/, answer];
|
|
8738
|
+
}
|
|
8739
|
+
});
|
|
8740
|
+
});
|
|
8741
|
+
};
|
|
8742
|
+
return CallbackInterfaceTools;
|
|
8743
|
+
}());
|
|
8744
|
+
|
|
8236
8745
|
/**
|
|
8237
8746
|
* Pretty print an embedding vector for logging
|
|
8238
8747
|
*
|
|
@@ -8308,88 +8817,6 @@
|
|
|
8308
8817
|
* TODO: [🏛] Maybe make some markdown builder
|
|
8309
8818
|
*/
|
|
8310
8819
|
|
|
8311
|
-
/**
|
|
8312
|
-
* Delagates the user interaction to a async callback function
|
|
8313
|
-
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
8314
|
-
*
|
|
8315
|
-
* @public exported from `@promptbook/core`
|
|
8316
|
-
*/
|
|
8317
|
-
var CallbackInterfaceTools = /** @class */ (function () {
|
|
8318
|
-
function CallbackInterfaceTools(options) {
|
|
8319
|
-
this.options = options;
|
|
8320
|
-
}
|
|
8321
|
-
/**
|
|
8322
|
-
* Trigger the custom callback function
|
|
8323
|
-
*/
|
|
8324
|
-
CallbackInterfaceTools.prototype.promptDialog = function (options) {
|
|
8325
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
8326
|
-
var answer;
|
|
8327
|
-
return __generator(this, function (_a) {
|
|
8328
|
-
switch (_a.label) {
|
|
8329
|
-
case 0: return [4 /*yield*/, this.options.callback(options)];
|
|
8330
|
-
case 1:
|
|
8331
|
-
answer = _a.sent();
|
|
8332
|
-
if (this.options.isVerbose) {
|
|
8333
|
-
console.info(spaceTrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
|
|
8334
|
-
}
|
|
8335
|
-
return [2 /*return*/, answer];
|
|
8336
|
-
}
|
|
8337
|
-
});
|
|
8338
|
-
});
|
|
8339
|
-
};
|
|
8340
|
-
return CallbackInterfaceTools;
|
|
8341
|
-
}());
|
|
8342
|
-
|
|
8343
|
-
/**
|
|
8344
|
-
* @@@
|
|
8345
|
-
*
|
|
8346
|
-
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
8347
|
-
*
|
|
8348
|
-
* @private internal function of `$Register`
|
|
8349
|
-
*/
|
|
8350
|
-
function $getGlobalScope() {
|
|
8351
|
-
return Function('return this')();
|
|
8352
|
-
}
|
|
8353
|
-
|
|
8354
|
-
/**
|
|
8355
|
-
* Register is @@@
|
|
8356
|
-
*
|
|
8357
|
-
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
8358
|
-
*
|
|
8359
|
-
* @private internal utility, exported are only signleton instances of this class
|
|
8360
|
-
*/
|
|
8361
|
-
var $Register = /** @class */ (function () {
|
|
8362
|
-
function $Register(storageName) {
|
|
8363
|
-
this.storageName = storageName;
|
|
8364
|
-
storageName = "_promptbook_".concat(storageName);
|
|
8365
|
-
var globalScope = $getGlobalScope();
|
|
8366
|
-
if (globalScope[storageName] === undefined) {
|
|
8367
|
-
globalScope[storageName] = [];
|
|
8368
|
-
}
|
|
8369
|
-
else if (!Array.isArray(globalScope[storageName])) {
|
|
8370
|
-
throw new UnexpectedError("Expected (global) ".concat(storageName, " to be an array, but got ").concat(typeof globalScope[storageName]));
|
|
8371
|
-
}
|
|
8372
|
-
this.storage = globalScope[storageName];
|
|
8373
|
-
}
|
|
8374
|
-
$Register.prototype.list = function () {
|
|
8375
|
-
// <- TODO: ReadonlyDeep<Array<TRegistered>>
|
|
8376
|
-
return this.storage;
|
|
8377
|
-
};
|
|
8378
|
-
$Register.prototype.register = function (registered) {
|
|
8379
|
-
// <- TODO: What to return here
|
|
8380
|
-
var packageName = registered.packageName, className = registered.className;
|
|
8381
|
-
var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
|
|
8382
|
-
var existingRegistration = this.storage[existingRegistrationIndex];
|
|
8383
|
-
if (!existingRegistration) {
|
|
8384
|
-
this.storage.push(registered);
|
|
8385
|
-
}
|
|
8386
|
-
else {
|
|
8387
|
-
this.storage[existingRegistrationIndex] = registered;
|
|
8388
|
-
}
|
|
8389
|
-
};
|
|
8390
|
-
return $Register;
|
|
8391
|
-
}());
|
|
8392
|
-
|
|
8393
8820
|
/**
|
|
8394
8821
|
* @@@
|
|
8395
8822
|
*
|
|
@@ -8398,6 +8825,9 @@
|
|
|
8398
8825
|
* @public exported from `@promptbook/core`
|
|
8399
8826
|
*/
|
|
8400
8827
|
var $llmToolsMetadataRegister = new $Register('llm_tools_metadata');
|
|
8828
|
+
/**
|
|
8829
|
+
* TODO: [®] DRY Register logic
|
|
8830
|
+
*/
|
|
8401
8831
|
|
|
8402
8832
|
/**
|
|
8403
8833
|
* @@@
|
|
@@ -8407,13 +8837,16 @@
|
|
|
8407
8837
|
* @public exported from `@promptbook/core`
|
|
8408
8838
|
*/
|
|
8409
8839
|
var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
|
|
8840
|
+
/**
|
|
8841
|
+
* TODO: [®] DRY Register logic
|
|
8842
|
+
*/
|
|
8410
8843
|
|
|
8411
8844
|
/**
|
|
8412
8845
|
* Creates a message with all registered LLM tools
|
|
8413
8846
|
*
|
|
8414
8847
|
* Note: This function is used to create a (error) message when there is no constructor for some LLM provider
|
|
8415
8848
|
*
|
|
8416
|
-
* @private internal function of `createLlmToolsFromConfiguration` and `
|
|
8849
|
+
* @private internal function of `createLlmToolsFromConfiguration` and `$provideLlmToolsFromEnv`
|
|
8417
8850
|
*/
|
|
8418
8851
|
function $registeredLlmToolsMessage() {
|
|
8419
8852
|
var e_1, _a, e_2, _b;
|
|
@@ -8505,6 +8938,9 @@
|
|
|
8505
8938
|
})
|
|
8506
8939
|
.join('\n')), "\n "); });
|
|
8507
8940
|
}
|
|
8941
|
+
/**
|
|
8942
|
+
* TODO: [®] DRY Register logic
|
|
8943
|
+
*/
|
|
8508
8944
|
|
|
8509
8945
|
/**
|
|
8510
8946
|
* @@@
|
|
@@ -8532,12 +8968,13 @@
|
|
|
8532
8968
|
return joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(llmTools), false));
|
|
8533
8969
|
}
|
|
8534
8970
|
/**
|
|
8535
|
-
* TODO: [🎌]
|
|
8971
|
+
* TODO: [🎌] Together with `createLlmToolsFromConfiguration` + 'EXECUTION_TOOLS_CLASSES' gets to `@promptbook/core` ALL model providers, make this more efficient
|
|
8536
8972
|
* TODO: [🧠][🎌] Dynamically install required providers
|
|
8537
8973
|
* TODO: @@@ write discussion about this - wizzard
|
|
8538
8974
|
* TODO: [🧠][🍛] Which name is better `createLlmToolsFromConfig` or `createLlmToolsFromConfiguration`?
|
|
8539
8975
|
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
8540
8976
|
* TODO: This should be maybe not under `_common` but under `utils`
|
|
8977
|
+
* TODO: [®] DRY Register logic
|
|
8541
8978
|
*/
|
|
8542
8979
|
|
|
8543
8980
|
/**
|
|
@@ -8616,11 +9053,7 @@
|
|
|
8616
9053
|
function cacheLlmTools(llmTools, options) {
|
|
8617
9054
|
var _this = this;
|
|
8618
9055
|
if (options === void 0) { options = {}; }
|
|
8619
|
-
var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a,
|
|
8620
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
8621
|
-
_b = options.isReloaded,
|
|
8622
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
8623
|
-
isReloaded = _b === void 0 ? false : _b;
|
|
9056
|
+
var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a, _b = options.isReloaded, isReloaded = _b === void 0 ? false : _b;
|
|
8624
9057
|
var proxyTools = __assign(__assign({}, llmTools), {
|
|
8625
9058
|
// <- Note: [🥫]
|
|
8626
9059
|
get title() {
|
|
@@ -8770,9 +9203,9 @@
|
|
|
8770
9203
|
*/
|
|
8771
9204
|
|
|
8772
9205
|
/**
|
|
8773
|
-
*
|
|
9206
|
+
* Registration of LLM provider metadata
|
|
8774
9207
|
*
|
|
8775
|
-
*
|
|
9208
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
8776
9209
|
*
|
|
8777
9210
|
* @public exported from `@promptbook/core`
|
|
8778
9211
|
* @public exported from `@promptbook/cli`
|
|
@@ -8810,9 +9243,9 @@
|
|
|
8810
9243
|
});
|
|
8811
9244
|
|
|
8812
9245
|
/**
|
|
8813
|
-
*
|
|
9246
|
+
* Registration of LLM provider metadata
|
|
8814
9247
|
*
|
|
8815
|
-
*
|
|
9248
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
8816
9249
|
*
|
|
8817
9250
|
* @public exported from `@promptbook/core`
|
|
8818
9251
|
* @public exported from `@promptbook/cli`
|
|
@@ -8849,16 +9282,16 @@
|
|
|
8849
9282
|
else if (typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ||
|
|
8850
9283
|
typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ||
|
|
8851
9284
|
typeof env.AZUREOPENAI_API_KEY === 'string') {
|
|
8852
|
-
throw new Error(spaceTrim__default["default"]("\n You must provide all of the following environment variables:\n
|
|
9285
|
+
throw new Error(spaceTrim__default["default"]("\n You must provide all of the following environment variables:\n\n - AZUREOPENAI_RESOURCE_NAME (".concat(typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_DEPLOYMENT_NAME (").concat(typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_API_KEY (").concat(typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined', ")\n ")));
|
|
8853
9286
|
}
|
|
8854
9287
|
return null;
|
|
8855
9288
|
},
|
|
8856
9289
|
});
|
|
8857
9290
|
|
|
8858
9291
|
/**
|
|
8859
|
-
*
|
|
9292
|
+
* Registration of LLM provider metadata
|
|
8860
9293
|
*
|
|
8861
|
-
*
|
|
9294
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
8862
9295
|
*
|
|
8863
9296
|
* @public exported from `@promptbook/core`
|
|
8864
9297
|
* @public exported from `@promptbook/cli`
|
|
@@ -8892,6 +9325,126 @@
|
|
|
8892
9325
|
},
|
|
8893
9326
|
});
|
|
8894
9327
|
|
|
9328
|
+
/**
|
|
9329
|
+
* Metadata of the scraper
|
|
9330
|
+
*
|
|
9331
|
+
* @private within the scraper directory
|
|
9332
|
+
*/
|
|
9333
|
+
var legacyDocumentScraperMetadata = $deepFreeze({
|
|
9334
|
+
title: 'LegacyDocument scraper',
|
|
9335
|
+
packageName: '@promptbook/legacy-documents',
|
|
9336
|
+
className: 'LegacyDocumentScraper',
|
|
9337
|
+
mimeTypes: ['application/msword', 'text/rtf'],
|
|
9338
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
9339
|
+
isAvilableInBrowser: false,
|
|
9340
|
+
requiredExecutables: ['!!!!!!'],
|
|
9341
|
+
}); /* <- TODO: [🤛] */
|
|
9342
|
+
/**
|
|
9343
|
+
* Registration of known scraper metadata
|
|
9344
|
+
*
|
|
9345
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
9346
|
+
*
|
|
9347
|
+
* @public exported from `@promptbook/core`
|
|
9348
|
+
* @public exported from `@promptbook/cli`
|
|
9349
|
+
*/
|
|
9350
|
+
var _LegacyDocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
|
|
9351
|
+
|
|
9352
|
+
/**
|
|
9353
|
+
* Metadata of the scraper
|
|
9354
|
+
*
|
|
9355
|
+
* @private within the scraper directory
|
|
9356
|
+
*/
|
|
9357
|
+
var documentScraperMetadata = $deepFreeze({
|
|
9358
|
+
title: 'Document scraper',
|
|
9359
|
+
packageName: '@promptbook/documents',
|
|
9360
|
+
className: 'DocumentScraper',
|
|
9361
|
+
mimeTypes: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
9362
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
9363
|
+
isAvilableInBrowser: false,
|
|
9364
|
+
requiredExecutables: ['!!!!!!'],
|
|
9365
|
+
}); /* <- TODO: [🤛] */
|
|
9366
|
+
/**
|
|
9367
|
+
* Registration of known scraper metadata
|
|
9368
|
+
*
|
|
9369
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
9370
|
+
*
|
|
9371
|
+
* @public exported from `@promptbook/core`
|
|
9372
|
+
* @public exported from `@promptbook/cli`
|
|
9373
|
+
*/
|
|
9374
|
+
var _DocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(documentScraperMetadata);
|
|
9375
|
+
|
|
9376
|
+
/**
|
|
9377
|
+
* Metadata of the scraper
|
|
9378
|
+
*
|
|
9379
|
+
* @private within the scraper directory
|
|
9380
|
+
*/
|
|
9381
|
+
var markdownScraperMetadata = $deepFreeze({
|
|
9382
|
+
title: 'Markdown scraper',
|
|
9383
|
+
packageName: '@promptbook/markdown-utils',
|
|
9384
|
+
className: 'MarkdownScraper',
|
|
9385
|
+
mimeTypes: ['text/markdown', 'text/plain'],
|
|
9386
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
9387
|
+
isAvilableInBrowser: true,
|
|
9388
|
+
requiredExecutables: ['!!!!!!'],
|
|
9389
|
+
}); /* <- TODO: [🤛] */
|
|
9390
|
+
/**
|
|
9391
|
+
* Registration of known scraper metadata
|
|
9392
|
+
*
|
|
9393
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
9394
|
+
*
|
|
9395
|
+
* @public exported from `@promptbook/core`
|
|
9396
|
+
* @public exported from `@promptbook/cli`
|
|
9397
|
+
*/
|
|
9398
|
+
var _MarkdownScraperMetadataRegistration = $scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
9399
|
+
|
|
9400
|
+
/**
|
|
9401
|
+
* Metadata of the scraper
|
|
9402
|
+
*
|
|
9403
|
+
* @private within the scraper directory
|
|
9404
|
+
*/
|
|
9405
|
+
var pdfScraperMetadata = $deepFreeze({
|
|
9406
|
+
title: 'Pdf scraper',
|
|
9407
|
+
packageName: '@promptbook/pdf',
|
|
9408
|
+
className: 'PdfScraper',
|
|
9409
|
+
mimeTypes: ['application/pdf'],
|
|
9410
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
9411
|
+
isAvilableInBrowser: true,
|
|
9412
|
+
requiredExecutables: ['!!!!!!'],
|
|
9413
|
+
}); /* <- TODO: [🤛] */
|
|
9414
|
+
/**
|
|
9415
|
+
* Registration of known scraper metadata
|
|
9416
|
+
*
|
|
9417
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
9418
|
+
*
|
|
9419
|
+
* @public exported from `@promptbook/core`
|
|
9420
|
+
* @public exported from `@promptbook/cli`
|
|
9421
|
+
*/
|
|
9422
|
+
var _PdfScraperMetadataRegistration = $scrapersMetadataRegister.register(pdfScraperMetadata);
|
|
9423
|
+
|
|
9424
|
+
/**
|
|
9425
|
+
* Metadata of the scraper
|
|
9426
|
+
*
|
|
9427
|
+
* @private within the scraper directory
|
|
9428
|
+
*/
|
|
9429
|
+
var websiteScraperMetadata = $deepFreeze({
|
|
9430
|
+
title: 'Website scraper',
|
|
9431
|
+
packageName: '@promptbook/website-crawler',
|
|
9432
|
+
className: 'WebsiteScraper',
|
|
9433
|
+
mimeTypes: ['text/html'],
|
|
9434
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
9435
|
+
isAvilableInBrowser: false,
|
|
9436
|
+
requiredExecutables: ['!!!!!!'],
|
|
9437
|
+
}); /* <- TODO: [🤛] */
|
|
9438
|
+
/**
|
|
9439
|
+
* Registration of known scraper metadata
|
|
9440
|
+
*
|
|
9441
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
9442
|
+
*
|
|
9443
|
+
* @public exported from `@promptbook/core`
|
|
9444
|
+
* @public exported from `@promptbook/cli`
|
|
9445
|
+
*/
|
|
9446
|
+
var _WebsiteScraperMetadataRegistration = $scrapersMetadataRegister.register(websiteScraperMetadata);
|
|
9447
|
+
|
|
8895
9448
|
/**
|
|
8896
9449
|
* This class behaves like LocalStorage but separates keys by prefix
|
|
8897
9450
|
*
|
|
@@ -9244,10 +9797,14 @@
|
|
|
9244
9797
|
|
|
9245
9798
|
exports.$llmToolsMetadataRegister = $llmToolsMetadataRegister;
|
|
9246
9799
|
exports.$llmToolsRegister = $llmToolsRegister;
|
|
9800
|
+
exports.$scrapersMetadataRegister = $scrapersMetadataRegister;
|
|
9801
|
+
exports.$scrapersRegister = $scrapersRegister;
|
|
9802
|
+
exports.AbstractFormatError = AbstractFormatError;
|
|
9247
9803
|
exports.CLAIM = CLAIM;
|
|
9248
9804
|
exports.CallbackInterfaceTools = CallbackInterfaceTools;
|
|
9249
9805
|
exports.CollectionError = CollectionError;
|
|
9250
9806
|
exports.CsvFormatDefinition = CsvFormatDefinition;
|
|
9807
|
+
exports.CsvFormatError = CsvFormatError;
|
|
9251
9808
|
exports.DEFAULT_CSV_SETTINGS = DEFAULT_CSV_SETTINGS;
|
|
9252
9809
|
exports.DEFAULT_REMOTE_URL = DEFAULT_REMOTE_URL;
|
|
9253
9810
|
exports.DEFAULT_REMOTE_URL_PATH = DEFAULT_REMOTE_URL_PATH;
|
|
@@ -9257,7 +9814,9 @@
|
|
|
9257
9814
|
exports.EnvironmentMismatchError = EnvironmentMismatchError;
|
|
9258
9815
|
exports.ExecutionReportStringOptionsDefaults = ExecutionReportStringOptionsDefaults;
|
|
9259
9816
|
exports.ExpectError = ExpectError;
|
|
9817
|
+
exports.IS_AUTO_INSTALLED = IS_AUTO_INSTALLED;
|
|
9260
9818
|
exports.IS_VERBOSE = IS_VERBOSE;
|
|
9819
|
+
exports.KnowledgeScrapeError = KnowledgeScrapeError;
|
|
9261
9820
|
exports.LimitReachedError = LimitReachedError;
|
|
9262
9821
|
exports.MANDATORY_CSV_SETTINGS = MANDATORY_CSV_SETTINGS;
|
|
9263
9822
|
exports.MAX_EXECUTION_ATTEMPTS = MAX_EXECUTION_ATTEMPTS;
|
|
@@ -9267,6 +9826,7 @@
|
|
|
9267
9826
|
exports.MAX_PARALLEL_COUNT = MAX_PARALLEL_COUNT;
|
|
9268
9827
|
exports.MODEL_VARIANTS = MODEL_VARIANTS;
|
|
9269
9828
|
exports.MemoryStorage = MemoryStorage;
|
|
9829
|
+
exports.MissingToolsError = MissingToolsError;
|
|
9270
9830
|
exports.NotFoundError = NotFoundError;
|
|
9271
9831
|
exports.NotYetImplementedError = NotYetImplementedError;
|
|
9272
9832
|
exports.PIPELINE_COLLECTION_BASE_FILENAME = PIPELINE_COLLECTION_BASE_FILENAME;
|
|
@@ -9277,13 +9837,19 @@
|
|
|
9277
9837
|
exports.PipelineUrlError = PipelineUrlError;
|
|
9278
9838
|
exports.PrefixStorage = PrefixStorage;
|
|
9279
9839
|
exports.RESERVED_PARAMETER_NAMES = RESERVED_PARAMETER_NAMES;
|
|
9840
|
+
exports.SCRAPE_CACHE_DIRNAME = SCRAPE_CACHE_DIRNAME;
|
|
9280
9841
|
exports.TemplateTypes = TemplateTypes;
|
|
9281
9842
|
exports.TextFormatDefinition = TextFormatDefinition;
|
|
9282
9843
|
exports.UnexpectedError = UnexpectedError;
|
|
9283
9844
|
exports.ZERO_USAGE = ZERO_USAGE;
|
|
9284
9845
|
exports._AnthropicClaudeMetadataRegistration = _AnthropicClaudeMetadataRegistration;
|
|
9285
9846
|
exports._AzureOpenAiMetadataRegistration = _AzureOpenAiMetadataRegistration;
|
|
9847
|
+
exports._DocumentScraperMetadataRegistration = _DocumentScraperMetadataRegistration;
|
|
9848
|
+
exports._LegacyDocumentScraperMetadataRegistration = _LegacyDocumentScraperMetadataRegistration;
|
|
9849
|
+
exports._MarkdownScraperMetadataRegistration = _MarkdownScraperMetadataRegistration;
|
|
9286
9850
|
exports._OpenAiMetadataRegistration = _OpenAiMetadataRegistration;
|
|
9851
|
+
exports._PdfScraperMetadataRegistration = _PdfScraperMetadataRegistration;
|
|
9852
|
+
exports._WebsiteScraperMetadataRegistration = _WebsiteScraperMetadataRegistration;
|
|
9287
9853
|
exports.addUsage = addUsage;
|
|
9288
9854
|
exports.assertsExecutionSuccessful = assertsExecutionSuccessful;
|
|
9289
9855
|
exports.cacheLlmTools = cacheLlmTools;
|
|
@@ -9304,7 +9870,6 @@
|
|
|
9304
9870
|
exports.pipelineJsonToString = pipelineJsonToString;
|
|
9305
9871
|
exports.pipelineStringToJson = pipelineStringToJson;
|
|
9306
9872
|
exports.pipelineStringToJsonSync = pipelineStringToJsonSync;
|
|
9307
|
-
exports.prepareKnowledgeFromMarkdown = prepareKnowledgeFromMarkdown;
|
|
9308
9873
|
exports.prepareKnowledgePieces = prepareKnowledgePieces;
|
|
9309
9874
|
exports.preparePersona = preparePersona;
|
|
9310
9875
|
exports.preparePipeline = preparePipeline;
|