@promptbook/core 0.61.0-2 → 0.61.0-21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +1806 -957
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +200 -30
- package/esm/typings/src/_packages/core.index.d.ts +7 -2
- package/esm/typings/src/_packages/execute-javascript.index.d.ts +1 -1
- package/esm/typings/src/_packages/node.index.d.ts +2 -1
- package/esm/typings/src/_packages/types.index.d.ts +11 -7
- package/esm/typings/src/_packages/utils.index.d.ts +8 -6
- package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +3 -0
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -0
- package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
- package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +10 -10
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +8 -7
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
- package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
- package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +2 -2
- package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +42 -14
- package/esm/typings/src/config.d.ts +38 -1
- package/esm/typings/src/config.test.d.ts +4 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +9 -5
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +5 -3
- package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +13 -0
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +12 -3
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +10 -1
- package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
- package/esm/typings/src/errors/LimitReachedError.d.ts +7 -0
- package/esm/typings/src/errors/VersionMismatchError.d.ts +8 -0
- package/esm/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +10 -8
- package/esm/typings/src/execution/PipelineExecutor.d.ts +10 -8
- package/esm/typings/src/execution/PromptResult.d.ts +28 -58
- package/esm/typings/src/execution/PromptResultUsage.d.ts +26 -0
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +5 -4
- package/esm/typings/src/execution/UncertainNumber.d.ts +18 -0
- package/esm/typings/src/execution/UserInterfaceTools.d.ts +5 -5
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +20 -3
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
- package/esm/typings/src/execution/utils/addUsage.d.ts +58 -2
- package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +1 -1
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/esm/typings/src/execution/utils/uncertainNumber.d.ts +1 -1
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +2 -2
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +2 -1
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +2 -1
- package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +2 -1
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
- package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
- package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +9 -23
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +8 -14
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +30 -0
- package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +11 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-cost/limitTotalCost.d.ts +32 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -2
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +3 -3
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -4
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
- package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -5
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +7 -7
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +12 -8
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +7 -6
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +3 -2
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +9 -7
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/personas/preparePersona.d.ts +15 -0
- package/esm/typings/src/prepare/PrepareOptions.d.ts +22 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +10 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +18 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +9 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +2 -1
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
- package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
- package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
- package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
- package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
- package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
- package/esm/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
- package/esm/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
- package/esm/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +71 -11
- package/esm/typings/src/types/ModelVariant.d.ts +14 -0
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +9 -1
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +38 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +29 -4
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +21 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +5 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +5 -1
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +13 -4
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineString.d.ts +1 -1
- package/esm/typings/src/types/Prompt.d.ts +54 -10
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
- package/esm/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
- package/esm/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +114 -15
- package/esm/typings/src/utils/FromtoItems.d.ts +3 -3
- package/esm/typings/src/utils/currentDate.d.ts +7 -0
- package/esm/typings/src/utils/deepClone.d.ts +9 -0
- package/esm/typings/src/utils/deepFreeze.d.ts +22 -0
- package/esm/typings/src/utils/emojis.d.ts +2 -2
- package/esm/typings/src/utils/extractParameters.d.ts +2 -2
- package/esm/typings/src/utils/formatNumber.d.ts +1 -1
- package/esm/typings/src/utils/isRunningInWhatever.d.ts +3 -0
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +3 -3
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +7 -10
- package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +9 -2
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
- package/esm/typings/src/utils/normalization/parseKeywords.d.ts +2 -1
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +12 -0
- package/esm/typings/src/utils/organization/TODO_any.d.ts +6 -0
- package/esm/typings/src/utils/organization/TODO_object.d.ts +6 -0
- package/esm/typings/src/utils/organization/TODO_unknown.d.ts +6 -0
- package/esm/typings/src/utils/organization/___.d.ts +6 -0
- package/esm/typings/src/utils/{just.d.ts → organization/just.d.ts} +5 -1
- package/esm/typings/src/utils/organization/keepUnused.d.ts +16 -0
- package/esm/typings/src/utils/organization/really_any.d.ts +6 -0
- package/esm/typings/src/utils/organization/really_unknown.d.ts +6 -0
- package/esm/typings/src/utils/random/randomSeed.d.ts +7 -0
- package/{umd/typings/src/execution → esm/typings/src}/utils/replaceParameters.d.ts +2 -4
- package/esm/typings/src/utils/replaceParameters.test.d.ts +1 -0
- package/esm/typings/src/utils/sets/difference.d.ts +3 -0
- package/esm/typings/src/utils/validators/email/isValidEmail.d.ts +2 -1
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +2 -1
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -1
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -1
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -1
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -1
- package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +2 -1
- package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -1
- package/package.json +1 -1
- package/umd/index.umd.js +1809 -956
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +200 -30
- package/umd/typings/src/_packages/core.index.d.ts +7 -2
- package/umd/typings/src/_packages/execute-javascript.index.d.ts +1 -1
- package/umd/typings/src/_packages/node.index.d.ts +2 -1
- package/umd/typings/src/_packages/types.index.d.ts +11 -7
- package/umd/typings/src/_packages/utils.index.d.ts +8 -6
- package/umd/typings/src/cli/cli-commands/hello.d.ts +3 -0
- package/umd/typings/src/cli/cli-commands/make.d.ts +3 -0
- package/umd/typings/src/cli/cli-commands/prettify.d.ts +3 -0
- package/umd/typings/src/cli/promptbookCli.d.ts +1 -0
- package/umd/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/umd/typings/src/collection/SimplePipelineCollection.d.ts +10 -10
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +8 -7
- package/umd/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
- package/umd/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
- package/umd/typings/src/commands/MODEL/ModelCommand.d.ts +2 -2
- package/umd/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
- package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +42 -14
- package/umd/typings/src/config.d.ts +38 -1
- package/umd/typings/src/config.test.d.ts +4 -0
- package/umd/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +9 -5
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +5 -3
- package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/umd/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +13 -0
- package/umd/typings/src/conversion/utils/stringifyPipelineJson.test.d.ts +1 -0
- package/umd/typings/src/conversion/validation/_importPipeline.d.ts +12 -3
- package/umd/typings/src/conversion/validation/validatePipeline.d.ts +10 -1
- package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
- package/umd/typings/src/errors/LimitReachedError.d.ts +7 -0
- package/umd/typings/src/errors/VersionMismatchError.d.ts +8 -0
- package/umd/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
- package/umd/typings/src/execution/LlmExecutionTools.d.ts +10 -8
- package/umd/typings/src/execution/PipelineExecutor.d.ts +10 -8
- package/umd/typings/src/execution/PromptResult.d.ts +28 -58
- package/umd/typings/src/execution/PromptResultUsage.d.ts +26 -0
- package/umd/typings/src/execution/ScriptExecutionTools.d.ts +5 -4
- package/umd/typings/src/execution/UncertainNumber.d.ts +18 -0
- package/umd/typings/src/execution/UserInterfaceTools.d.ts +5 -5
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +20 -3
- package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
- package/umd/typings/src/execution/utils/addUsage.d.ts +58 -2
- package/umd/typings/src/execution/utils/computeUsageCounts.d.ts +1 -1
- package/umd/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/umd/typings/src/execution/utils/uncertainNumber.d.ts +1 -1
- package/umd/typings/src/execution/utils/usageToWorktime.d.ts +2 -2
- package/umd/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
- package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +2 -1
- package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +2 -1
- package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +2 -1
- package/umd/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
- package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
- package/umd/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +9 -23
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +8 -14
- package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +30 -0
- package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
- package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +11 -0
- package/umd/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
- package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
- package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
- package/umd/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
- package/umd/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
- package/umd/typings/src/llm-providers/_common/utils/count-total-cost/limitTotalCost.d.ts +32 -0
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -2
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +3 -3
- package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -4
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
- package/umd/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -5
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +7 -7
- package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +12 -8
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +7 -6
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
- package/umd/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +3 -2
- package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +9 -7
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/personas/preparePersona.d.ts +15 -0
- package/umd/typings/src/personas/preparePersona.test.d.ts +1 -0
- package/umd/typings/src/prepare/PrepareOptions.d.ts +22 -0
- package/umd/typings/src/prepare/isPipelinePrepared.d.ts +10 -0
- package/umd/typings/src/prepare/isPipelinePrepared.test.d.ts +1 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +18 -0
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +9 -0
- package/umd/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/umd/typings/src/scripting/javascript/utils/unknownToString.d.ts +2 -1
- package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
- package/umd/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
- package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
- package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
- package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
- package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
- package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
- package/umd/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
- package/umd/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
- package/umd/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
- package/umd/typings/src/types/ModelRequirements.d.ts +71 -11
- package/umd/typings/src/types/ModelVariant.d.ts +14 -0
- package/umd/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
- package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
- package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +9 -1
- package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +38 -0
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +29 -4
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +21 -0
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +5 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +5 -1
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +13 -4
- package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
- package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
- package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
- package/umd/typings/src/types/PipelineString.d.ts +1 -1
- package/umd/typings/src/types/Prompt.d.ts +54 -10
- package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
- package/umd/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
- package/umd/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/umd/typings/src/types/typeAliases.d.ts +114 -15
- package/umd/typings/src/utils/FromtoItems.d.ts +3 -3
- package/umd/typings/src/utils/currentDate.d.ts +7 -0
- package/umd/typings/src/utils/deepClone.d.ts +9 -0
- package/umd/typings/src/utils/deepFreeze.d.ts +22 -0
- package/umd/typings/src/utils/emojis.d.ts +2 -2
- package/umd/typings/src/utils/extractParameters.d.ts +2 -2
- package/umd/typings/src/utils/formatNumber.d.ts +1 -1
- package/umd/typings/src/utils/isRunningInWhatever.d.ts +3 -0
- package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +3 -3
- package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +7 -10
- package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +9 -2
- package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
- package/umd/typings/src/utils/normalization/parseKeywords.d.ts +2 -1
- package/umd/typings/src/utils/organization/TODO_USE.d.ts +12 -0
- package/umd/typings/src/utils/organization/TODO_any.d.ts +6 -0
- package/umd/typings/src/utils/organization/TODO_object.d.ts +6 -0
- package/umd/typings/src/utils/organization/TODO_unknown.d.ts +6 -0
- package/umd/typings/src/utils/organization/___.d.ts +6 -0
- package/umd/typings/src/utils/{just.d.ts → organization/just.d.ts} +5 -1
- package/umd/typings/src/utils/organization/keepUnused.d.ts +16 -0
- package/umd/typings/src/utils/organization/really_any.d.ts +6 -0
- package/umd/typings/src/utils/organization/really_unknown.d.ts +6 -0
- package/umd/typings/src/utils/random/randomSeed.d.ts +7 -0
- package/{esm/typings/src/execution → umd/typings/src}/utils/replaceParameters.d.ts +2 -4
- package/umd/typings/src/utils/replaceParameters.test.d.ts +1 -0
- package/umd/typings/src/utils/sets/difference.d.ts +3 -0
- package/umd/typings/src/utils/validators/email/isValidEmail.d.ts +2 -1
- package/umd/typings/src/utils/validators/filePath/isValidFilePath.d.ts +2 -1
- package/umd/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -1
- package/umd/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -1
- package/umd/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -1
- package/umd/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -1
- package/umd/typings/src/utils/validators/url/isValidUrl.d.ts +2 -1
- package/umd/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -1
- package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
- package/esm/typings/src/personas/personaToModelRequirements.d.ts +0 -6
- package/esm/typings/src/types/Parameters.d.ts +0 -14
- package/esm/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
- package/esm/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
- package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
- package/umd/typings/src/personas/personaToModelRequirements.d.ts +0 -6
- package/umd/typings/src/types/Parameters.d.ts +0 -14
- package/umd/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
- package/umd/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
- /package/esm/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
- /package/esm/typings/src/{execution/addPromptResultUsage.test.d.ts → conversion/utils/stringifyPipelineJson.test.d.ts} +0 -0
- /package/esm/typings/src/{execution/utils/replaceParameters.test.d.ts → knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts} +0 -0
- /package/{umd/typings/src/execution/addPromptResultUsage.test.d.ts → esm/typings/src/personas/preparePersona.test.d.ts} +0 -0
- /package/esm/typings/src/{utils/postprocessing → postprocessing/utils}/extractBlock.d.ts +0 -0
- /package/{umd/typings/src/execution/utils/replaceParameters.test.d.ts → esm/typings/src/prepare/isPipelinePrepared.test.d.ts} +0 -0
- /package/umd/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
- /package/umd/typings/src/{utils/postprocessing → postprocessing/utils}/extractBlock.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -251,7 +251,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
251
251
|
/* Note: Not using:> name, */
|
|
252
252
|
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
253
253
|
/* Note: dependentParameterNames, */
|
|
254
|
-
jokers = promptTemplate.
|
|
254
|
+
jokers = promptTemplate.jokerParameterNames, blockType = promptTemplate.blockType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessingFunctionNames, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
255
255
|
pipelineString += '\n\n';
|
|
256
256
|
pipelineString += "## ".concat(title_1);
|
|
257
257
|
if (description_1) {
|
|
@@ -385,23 +385,107 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
385
385
|
return parameterString;
|
|
386
386
|
}
|
|
387
387
|
/**
|
|
388
|
-
* TODO:
|
|
388
|
+
* TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
|
|
389
389
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
390
390
|
* TODO: Escape all
|
|
391
391
|
*/
|
|
392
392
|
|
|
393
|
+
/**
|
|
394
|
+
* @@@
|
|
395
|
+
*
|
|
396
|
+
* @returns The same object as the input, but deeply frozen
|
|
397
|
+
*
|
|
398
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
399
|
+
*/
|
|
400
|
+
function deepFreeze(objectValue) {
|
|
401
|
+
var e_1, _a;
|
|
402
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
403
|
+
try {
|
|
404
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
405
|
+
var propertyName = propertyNames_1_1.value;
|
|
406
|
+
var value = objectValue[propertyName];
|
|
407
|
+
if (value && typeof value === 'object') {
|
|
408
|
+
deepFreeze(value);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
413
|
+
finally {
|
|
414
|
+
try {
|
|
415
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
416
|
+
}
|
|
417
|
+
finally { if (e_1) throw e_1.error; }
|
|
418
|
+
}
|
|
419
|
+
return Object.freeze(objectValue);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* @@@
|
|
423
|
+
* @@@
|
|
424
|
+
*
|
|
425
|
+
* @returns The same object as the input, but deeply frozen
|
|
426
|
+
*
|
|
427
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
428
|
+
*/
|
|
429
|
+
function deepFreezeWithSameType(objectValue) {
|
|
430
|
+
return deepFreeze(objectValue);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* TODO: [🔼] Export from `@promptbook/utils`
|
|
434
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
435
|
+
*/
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Returns the same value that is passed as argument.
|
|
439
|
+
* No side effects.
|
|
440
|
+
*
|
|
441
|
+
* Note: It can be usefull for:
|
|
442
|
+
*
|
|
443
|
+
* 1) Leveling indentation
|
|
444
|
+
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
445
|
+
*
|
|
446
|
+
* @param value any values
|
|
447
|
+
* @returns the same values
|
|
448
|
+
* @private within the repository
|
|
449
|
+
*/
|
|
450
|
+
function just(value) {
|
|
451
|
+
if (value === undefined) {
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
|
454
|
+
return value;
|
|
455
|
+
}
|
|
456
|
+
|
|
393
457
|
/**
|
|
394
458
|
* The maximum number of iterations for a loops
|
|
395
459
|
*/
|
|
396
460
|
var LOOP_LIMIT = 1000;
|
|
461
|
+
/**
|
|
462
|
+
* The maximum number of (LLM) tasks running in parallel
|
|
463
|
+
*/
|
|
464
|
+
var MAX_PARALLEL_COUNT = 5;
|
|
465
|
+
/**
|
|
466
|
+
* The maximum number of attempts to execute LLM task before giving up
|
|
467
|
+
*/
|
|
468
|
+
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
397
469
|
/**
|
|
398
470
|
* The names of the parameters that are reserved for special purposes
|
|
399
471
|
*/
|
|
400
|
-
var RESERVED_PARAMETER_NAMES = [
|
|
472
|
+
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
401
473
|
'context',
|
|
474
|
+
'currentDate',
|
|
402
475
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
403
476
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
404
|
-
];
|
|
477
|
+
]);
|
|
478
|
+
/**
|
|
479
|
+
* Nonce which is used for replacing things in strings
|
|
480
|
+
*/
|
|
481
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
482
|
+
/*
|
|
483
|
+
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
484
|
+
*/
|
|
485
|
+
// [🟡][🟢][🔵][⚪]
|
|
486
|
+
/**
|
|
487
|
+
* TODO: [🔼] Export all to core
|
|
488
|
+
*/
|
|
405
489
|
|
|
406
490
|
/**
|
|
407
491
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -604,7 +688,7 @@ function isValidPipelineUrl(url) {
|
|
|
604
688
|
*/
|
|
605
689
|
function validatePipeline(pipeline) {
|
|
606
690
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
607
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
691
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
608
692
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
609
693
|
// <- Note: [🚲]
|
|
610
694
|
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\""));
|
|
@@ -641,19 +725,19 @@ function validatePipeline(pipeline) {
|
|
|
641
725
|
};
|
|
642
726
|
try {
|
|
643
727
|
// Note: Check each parameter individually
|
|
644
|
-
for (var
|
|
645
|
-
var parameter =
|
|
728
|
+
for (var _f = __values(pipeline.parameters), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
729
|
+
var parameter = _g.value;
|
|
646
730
|
_loop_1(parameter);
|
|
647
731
|
}
|
|
648
732
|
}
|
|
649
733
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
650
734
|
finally {
|
|
651
735
|
try {
|
|
652
|
-
if (
|
|
736
|
+
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
|
|
653
737
|
}
|
|
654
738
|
finally { if (e_1) throw e_1.error; }
|
|
655
739
|
}
|
|
656
|
-
// Note:
|
|
740
|
+
// Note: All input parameters are defined - so that they can be used as result of some template
|
|
657
741
|
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
658
742
|
var isInput = _a.isInput;
|
|
659
743
|
return isInput;
|
|
@@ -662,23 +746,27 @@ function validatePipeline(pipeline) {
|
|
|
662
746
|
return name;
|
|
663
747
|
}));
|
|
664
748
|
try {
|
|
665
|
-
|
|
666
|
-
|
|
749
|
+
// Note: Checking each template individually
|
|
750
|
+
for (var _h = __values(pipeline.promptTemplates), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
751
|
+
var template = _j.value;
|
|
667
752
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
668
753
|
throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
669
754
|
}
|
|
755
|
+
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
756
|
+
throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use fifferent name"));
|
|
757
|
+
}
|
|
670
758
|
definedParameters.add(template.resultingParameterName);
|
|
671
759
|
if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
672
760
|
throw new PipelineLogicError(spaceTrim$1("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
|
|
673
761
|
}
|
|
674
|
-
if (template.
|
|
762
|
+
if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
|
|
675
763
|
if (!template.expectFormat &&
|
|
676
764
|
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
677
765
|
throw new PipelineLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
|
|
678
766
|
}
|
|
679
767
|
try {
|
|
680
|
-
for (var
|
|
681
|
-
var joker =
|
|
768
|
+
for (var _k = (e_3 = void 0, __values(template.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
769
|
+
var joker = _l.value;
|
|
682
770
|
if (!template.dependentParameterNames.includes(joker)) {
|
|
683
771
|
throw new PipelineLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
684
772
|
}
|
|
@@ -687,15 +775,15 @@ function validatePipeline(pipeline) {
|
|
|
687
775
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
688
776
|
finally {
|
|
689
777
|
try {
|
|
690
|
-
if (
|
|
778
|
+
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
691
779
|
}
|
|
692
780
|
finally { if (e_3) throw e_3.error; }
|
|
693
781
|
}
|
|
694
782
|
}
|
|
695
783
|
if (template.expectations) {
|
|
696
784
|
try {
|
|
697
|
-
for (var
|
|
698
|
-
var
|
|
785
|
+
for (var _m = (e_4 = void 0, __values(Object.entries(template.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
786
|
+
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
699
787
|
if (min !== undefined && max !== undefined && min > max) {
|
|
700
788
|
throw new PipelineLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
701
789
|
}
|
|
@@ -710,7 +798,7 @@ function validatePipeline(pipeline) {
|
|
|
710
798
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
711
799
|
finally {
|
|
712
800
|
try {
|
|
713
|
-
if (
|
|
801
|
+
if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
|
|
714
802
|
}
|
|
715
803
|
finally { if (e_4) throw e_4.error; }
|
|
716
804
|
}
|
|
@@ -720,7 +808,7 @@ function validatePipeline(pipeline) {
|
|
|
720
808
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
721
809
|
finally {
|
|
722
810
|
try {
|
|
723
|
-
if (
|
|
811
|
+
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
724
812
|
}
|
|
725
813
|
finally { if (e_2) throw e_2.error; }
|
|
726
814
|
}
|
|
@@ -734,24 +822,42 @@ function validatePipeline(pipeline) {
|
|
|
734
822
|
var name = _a.name;
|
|
735
823
|
return name;
|
|
736
824
|
});
|
|
825
|
+
try {
|
|
826
|
+
// Note: All reserved parameters are resolved
|
|
827
|
+
for (var RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
|
|
828
|
+
var reservedParameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
829
|
+
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), [reservedParameterName], false);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
833
|
+
finally {
|
|
834
|
+
try {
|
|
835
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_e = RESERVED_PARAMETER_NAMES_1.return)) _e.call(RESERVED_PARAMETER_NAMES_1);
|
|
836
|
+
}
|
|
837
|
+
finally { if (e_5) throw e_5.error; }
|
|
838
|
+
}
|
|
737
839
|
var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
840
|
+
// <- TODO: [🧠][🥜]
|
|
738
841
|
var loopLimit = LOOP_LIMIT;
|
|
739
842
|
var _loop_2 = function () {
|
|
740
843
|
if (loopLimit-- < 0) {
|
|
844
|
+
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
741
845
|
throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePipeline`');
|
|
742
846
|
}
|
|
743
847
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
744
848
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
745
849
|
});
|
|
746
850
|
if (currentlyResovedTemplates.length === 0) {
|
|
747
|
-
throw new PipelineLogicError(
|
|
851
|
+
throw new PipelineLogicError(
|
|
852
|
+
// TODO: [🐎] DRY
|
|
853
|
+
spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
748
854
|
.map(function (_a) {
|
|
749
855
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
750
|
-
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
856
|
+
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
751
857
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
752
|
-
.join('
|
|
858
|
+
.join(' and '));
|
|
753
859
|
})
|
|
754
|
-
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
860
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
755
861
|
}
|
|
756
862
|
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
|
|
757
863
|
var resultingParameterName = _a.resultingParameterName;
|
|
@@ -773,7 +879,16 @@ function validatePipeline(pipeline) {
|
|
|
773
879
|
* > * It checks:
|
|
774
880
|
* > * - it has a valid structure
|
|
775
881
|
* > * - ...
|
|
776
|
-
* > ex port function validatePipeline(promptbook:
|
|
882
|
+
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
883
|
+
*/
|
|
884
|
+
/**
|
|
885
|
+
* TODO: [🧠][🐣] !!!! Validate that all samples match expectations
|
|
886
|
+
* TODO: [🧠][🐣] !!!! Validate that knowledge is valid (non-void)
|
|
887
|
+
* TODO: [🧠][🐣] !!!! Validate that persona can be used only with CHAT variant
|
|
888
|
+
* TODO: !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
889
|
+
* TODO: !!!! Validate that reserved parameter is not used as joker
|
|
890
|
+
* TODO: [🧠] !!! Validationg not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
891
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
777
892
|
*/
|
|
778
893
|
|
|
779
894
|
/**
|
|
@@ -805,79 +920,100 @@ var ReferenceError$1 = /** @class */ (function (_super) {
|
|
|
805
920
|
}(Error));
|
|
806
921
|
|
|
807
922
|
/**
|
|
808
|
-
*
|
|
809
|
-
|
|
923
|
+
* Unprepare just strips the preparation data of the pipeline
|
|
924
|
+
*/
|
|
925
|
+
function unpreparePipeline(pipeline) {
|
|
926
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
|
|
927
|
+
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
928
|
+
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
929
|
+
return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
933
|
+
* TODO: Write tests for `preparePipeline`
|
|
934
|
+
*/
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Library of pipelines that groups together pipelines for an application.
|
|
938
|
+
* This implementation is a very thin wrapper around the Array / Map of pipelines.
|
|
810
939
|
*
|
|
811
940
|
* @private use `createCollectionFromJson` instead
|
|
812
|
-
* @see https://github.com/webgptorg/
|
|
941
|
+
* @see https://github.com/webgptorg/pipeline#pipeline-collection
|
|
813
942
|
*/
|
|
814
943
|
var SimplePipelineCollection = /** @class */ (function () {
|
|
815
944
|
/**
|
|
816
|
-
* Constructs a pipeline collection from
|
|
945
|
+
* Constructs a pipeline collection from pipelines
|
|
817
946
|
*
|
|
818
|
-
* @param
|
|
947
|
+
* @param pipelines @@@
|
|
819
948
|
*
|
|
820
949
|
* @private Use instead `createCollectionFromJson`
|
|
821
|
-
* Note: During the construction logic of all
|
|
950
|
+
* Note: During the construction logic of all pipelines are validated
|
|
822
951
|
* Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
|
|
823
952
|
*/
|
|
824
953
|
function SimplePipelineCollection() {
|
|
825
954
|
var e_1, _a;
|
|
826
|
-
var
|
|
955
|
+
var pipelines = [];
|
|
827
956
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
828
|
-
|
|
957
|
+
pipelines[_i] = arguments[_i];
|
|
829
958
|
}
|
|
830
959
|
this.collection = new Map();
|
|
831
960
|
try {
|
|
832
|
-
for (var
|
|
833
|
-
var
|
|
834
|
-
|
|
835
|
-
|
|
961
|
+
for (var pipelines_1 = __values(pipelines), pipelines_1_1 = pipelines_1.next(); !pipelines_1_1.done; pipelines_1_1 = pipelines_1.next()) {
|
|
962
|
+
var pipeline = pipelines_1_1.value;
|
|
963
|
+
// TODO: [👠] DRY
|
|
964
|
+
if (pipeline.pipelineUrl === undefined) {
|
|
965
|
+
throw new ReferenceError$1(spaceTrim$1("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
|
|
836
966
|
}
|
|
837
|
-
|
|
967
|
+
// Note: [🐨]
|
|
968
|
+
validatePipeline(pipeline);
|
|
969
|
+
// TODO: [🦄] DRY
|
|
838
970
|
// Note: [🦄]
|
|
839
|
-
if (
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
971
|
+
if (
|
|
972
|
+
// TODO: [🐽]
|
|
973
|
+
this.collection.has(pipeline.pipelineUrl) &&
|
|
974
|
+
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
975
|
+
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
976
|
+
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
977
|
+
throw new ReferenceError$1(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
843
978
|
}
|
|
844
|
-
|
|
979
|
+
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
980
|
+
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
845
981
|
}
|
|
846
982
|
}
|
|
847
983
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
848
984
|
finally {
|
|
849
985
|
try {
|
|
850
|
-
if (
|
|
986
|
+
if (pipelines_1_1 && !pipelines_1_1.done && (_a = pipelines_1.return)) _a.call(pipelines_1);
|
|
851
987
|
}
|
|
852
988
|
finally { if (e_1) throw e_1.error; }
|
|
853
989
|
}
|
|
854
990
|
}
|
|
855
991
|
/**
|
|
856
|
-
* Gets all
|
|
992
|
+
* Gets all pipelines in the collection
|
|
857
993
|
*/
|
|
858
994
|
SimplePipelineCollection.prototype.listPipelines = function () {
|
|
859
995
|
return Array.from(this.collection.keys());
|
|
860
996
|
};
|
|
861
997
|
/**
|
|
862
|
-
* Gets
|
|
998
|
+
* Gets pipeline by its URL
|
|
863
999
|
*
|
|
864
1000
|
* Note: This is not a direct fetching from the URL, but a lookup in the collection
|
|
865
1001
|
*/
|
|
866
1002
|
SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
|
|
867
1003
|
var _this = this;
|
|
868
|
-
var
|
|
869
|
-
if (!
|
|
1004
|
+
var pipeline = this.collection.get(url);
|
|
1005
|
+
if (!pipeline) {
|
|
870
1006
|
if (this.listPipelines().length === 0) {
|
|
871
|
-
throw new NotFoundError(spaceTrim$1("\n
|
|
1007
|
+
throw new NotFoundError(spaceTrim$1("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
|
|
872
1008
|
}
|
|
873
|
-
throw new NotFoundError(spaceTrim$1(function (block) { return "\n
|
|
1009
|
+
throw new NotFoundError(spaceTrim$1(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
|
|
874
1010
|
.map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
|
|
875
1011
|
.join('\n')), "\n\n "); }));
|
|
876
1012
|
}
|
|
877
|
-
return
|
|
1013
|
+
return pipeline;
|
|
878
1014
|
};
|
|
879
1015
|
/**
|
|
880
|
-
* Checks whether given prompt was defined in any
|
|
1016
|
+
* Checks whether given prompt was defined in any pipeline in the collection
|
|
881
1017
|
*/
|
|
882
1018
|
SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
|
|
883
1019
|
return true;
|
|
@@ -1119,7 +1255,199 @@ var BlockTypes = [
|
|
|
1119
1255
|
// <- [🩻]
|
|
1120
1256
|
];
|
|
1121
1257
|
|
|
1122
|
-
|
|
1258
|
+
/**
|
|
1259
|
+
* @@@
|
|
1260
|
+
*/
|
|
1261
|
+
function deepClone(objectValue) {
|
|
1262
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
1263
|
+
/*
|
|
1264
|
+
TODO: [🧠] Is there a better implementation?
|
|
1265
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1266
|
+
> for (const propertyName of propertyNames) {
|
|
1267
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
1268
|
+
> if (value && typeof value === 'object') {
|
|
1269
|
+
> deepClone(value);
|
|
1270
|
+
> }
|
|
1271
|
+
> }
|
|
1272
|
+
> return Object.assign({}, objectValue);
|
|
1273
|
+
*/
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* TODO: [🔼] Export from `@promptbook/utils`
|
|
1277
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1278
|
+
*/
|
|
1279
|
+
|
|
1280
|
+
/**
|
|
1281
|
+
* @@@
|
|
1282
|
+
*
|
|
1283
|
+
* TODO: [🔼] Export with addUsage
|
|
1284
|
+
*/
|
|
1285
|
+
var ZERO_USAGE = deepFreeze({
|
|
1286
|
+
price: { value: 0 },
|
|
1287
|
+
input: {
|
|
1288
|
+
tokensCount: { value: 0 },
|
|
1289
|
+
charactersCount: { value: 0 },
|
|
1290
|
+
wordsCount: { value: 0 },
|
|
1291
|
+
sentencesCount: { value: 0 },
|
|
1292
|
+
linesCount: { value: 0 },
|
|
1293
|
+
paragraphsCount: { value: 0 },
|
|
1294
|
+
pagesCount: { value: 0 },
|
|
1295
|
+
},
|
|
1296
|
+
output: {
|
|
1297
|
+
tokensCount: { value: 0 },
|
|
1298
|
+
charactersCount: { value: 0 },
|
|
1299
|
+
wordsCount: { value: 0 },
|
|
1300
|
+
sentencesCount: { value: 0 },
|
|
1301
|
+
linesCount: { value: 0 },
|
|
1302
|
+
paragraphsCount: { value: 0 },
|
|
1303
|
+
pagesCount: { value: 0 },
|
|
1304
|
+
},
|
|
1305
|
+
});
|
|
1306
|
+
/**
|
|
1307
|
+
* Function `addUsage` will add multiple usages into one
|
|
1308
|
+
*
|
|
1309
|
+
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
1310
|
+
*/
|
|
1311
|
+
function addUsage() {
|
|
1312
|
+
var usageItems = [];
|
|
1313
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1314
|
+
usageItems[_i] = arguments[_i];
|
|
1315
|
+
}
|
|
1316
|
+
return usageItems.reduce(function (acc, item) {
|
|
1317
|
+
var e_1, _a, e_2, _b;
|
|
1318
|
+
var _c;
|
|
1319
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1320
|
+
try {
|
|
1321
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1322
|
+
var key = _e.value;
|
|
1323
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1324
|
+
//@ts-ignore
|
|
1325
|
+
if (item.input[key]) {
|
|
1326
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1327
|
+
//@ts-ignore
|
|
1328
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
1329
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1330
|
+
//@ts-ignore
|
|
1331
|
+
if (item.input[key].isUncertain) {
|
|
1332
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1333
|
+
//@ts-ignore
|
|
1334
|
+
acc.input[key].isUncertain = true;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1340
|
+
finally {
|
|
1341
|
+
try {
|
|
1342
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1343
|
+
}
|
|
1344
|
+
finally { if (e_1) throw e_1.error; }
|
|
1345
|
+
}
|
|
1346
|
+
try {
|
|
1347
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1348
|
+
var key = _g.value;
|
|
1349
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1350
|
+
//@ts-ignore
|
|
1351
|
+
if (item.output[key]) {
|
|
1352
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1353
|
+
//@ts-ignore
|
|
1354
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
1355
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1356
|
+
//@ts-ignore
|
|
1357
|
+
if (item.output[key].isUncertain) {
|
|
1358
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1359
|
+
//@ts-ignore
|
|
1360
|
+
acc.output[key].isUncertain = true;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1366
|
+
finally {
|
|
1367
|
+
try {
|
|
1368
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1369
|
+
}
|
|
1370
|
+
finally { if (e_2) throw e_2.error; }
|
|
1371
|
+
}
|
|
1372
|
+
return acc;
|
|
1373
|
+
}, deepClone(ZERO_USAGE));
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
/**
|
|
1377
|
+
* Async version of Array.forEach
|
|
1378
|
+
*
|
|
1379
|
+
* @param array - Array to iterate over
|
|
1380
|
+
* @param options - Options for the function
|
|
1381
|
+
* @param callbackfunction - Function to call for each item
|
|
1382
|
+
*/
|
|
1383
|
+
function forEachAsync(array, options, callbackfunction) {
|
|
1384
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1385
|
+
var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
|
|
1386
|
+
var e_1, _d;
|
|
1387
|
+
return __generator(this, function (_e) {
|
|
1388
|
+
switch (_e.label) {
|
|
1389
|
+
case 0:
|
|
1390
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
1391
|
+
index = 0;
|
|
1392
|
+
runningTasks = [];
|
|
1393
|
+
tasks = [];
|
|
1394
|
+
_loop_1 = function (item) {
|
|
1395
|
+
var currentIndex, task;
|
|
1396
|
+
return __generator(this, function (_f) {
|
|
1397
|
+
switch (_f.label) {
|
|
1398
|
+
case 0:
|
|
1399
|
+
currentIndex = index++;
|
|
1400
|
+
task = callbackfunction(item, currentIndex, array);
|
|
1401
|
+
tasks.push(task);
|
|
1402
|
+
runningTasks.push(task);
|
|
1403
|
+
/* not await */ Promise.resolve(task).then(function () {
|
|
1404
|
+
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
1405
|
+
});
|
|
1406
|
+
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
1407
|
+
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
1408
|
+
case 1:
|
|
1409
|
+
_f.sent();
|
|
1410
|
+
_f.label = 2;
|
|
1411
|
+
case 2: return [2 /*return*/];
|
|
1412
|
+
}
|
|
1413
|
+
});
|
|
1414
|
+
};
|
|
1415
|
+
_e.label = 1;
|
|
1416
|
+
case 1:
|
|
1417
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
1418
|
+
_b = __values(array), _c = _b.next();
|
|
1419
|
+
_e.label = 2;
|
|
1420
|
+
case 2:
|
|
1421
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
1422
|
+
item = _c.value;
|
|
1423
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
1424
|
+
case 3:
|
|
1425
|
+
_e.sent();
|
|
1426
|
+
_e.label = 4;
|
|
1427
|
+
case 4:
|
|
1428
|
+
_c = _b.next();
|
|
1429
|
+
return [3 /*break*/, 2];
|
|
1430
|
+
case 5: return [3 /*break*/, 8];
|
|
1431
|
+
case 6:
|
|
1432
|
+
e_1_1 = _e.sent();
|
|
1433
|
+
e_1 = { error: e_1_1 };
|
|
1434
|
+
return [3 /*break*/, 8];
|
|
1435
|
+
case 7:
|
|
1436
|
+
try {
|
|
1437
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
1438
|
+
}
|
|
1439
|
+
finally { if (e_1) throw e_1.error; }
|
|
1440
|
+
return [7 /*endfinally*/];
|
|
1441
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
1442
|
+
case 9:
|
|
1443
|
+
_e.sent();
|
|
1444
|
+
return [2 /*return*/];
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-20",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-20",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-20",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-20",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-20",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-20",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-20",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-20",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1123
1451
|
|
|
1124
1452
|
var defaultDiacriticsRemovalMap = [
|
|
1125
1453
|
{
|
|
@@ -1446,6 +1774,14 @@ function removeEmojis(text) {
|
|
|
1446
1774
|
* Function normalizes title to name which can be used as identifier
|
|
1447
1775
|
*/
|
|
1448
1776
|
function titleToName(value) {
|
|
1777
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
1778
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1779
|
+
return value;
|
|
1780
|
+
}
|
|
1781
|
+
if (value.startsWith('./') || value.startsWith('../')) {
|
|
1782
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1783
|
+
return value;
|
|
1784
|
+
}
|
|
1449
1785
|
value = removeEmojis(value);
|
|
1450
1786
|
value = normalizeToKebabCase(value);
|
|
1451
1787
|
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
@@ -1492,43 +1828,176 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1492
1828
|
*/
|
|
1493
1829
|
|
|
1494
1830
|
/**
|
|
1495
|
-
*
|
|
1831
|
+
* Parses the template and returns the list of all parameter names
|
|
1496
1832
|
*
|
|
1497
|
-
* @
|
|
1498
|
-
*
|
|
1833
|
+
* @param template the template with parameters in {curly} braces
|
|
1834
|
+
* @returns the list of parameter names
|
|
1499
1835
|
*/
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1836
|
+
function extractParameters(template) {
|
|
1837
|
+
var e_1, _a;
|
|
1838
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
1839
|
+
var parameterNames = new Set();
|
|
1840
|
+
try {
|
|
1841
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1842
|
+
var match = matches_1_1.value;
|
|
1843
|
+
var parameterName = match[0].slice(1, -1);
|
|
1844
|
+
parameterNames.add(parameterName);
|
|
1845
|
+
}
|
|
1507
1846
|
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1847
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1848
|
+
finally {
|
|
1849
|
+
try {
|
|
1850
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
1851
|
+
}
|
|
1852
|
+
finally { if (e_1) throw e_1.error; }
|
|
1853
|
+
}
|
|
1854
|
+
return parameterNames;
|
|
1855
|
+
}
|
|
1510
1856
|
|
|
1511
1857
|
/**
|
|
1512
|
-
*
|
|
1858
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
1859
|
+
*
|
|
1860
|
+
* @param script from which to extract the variables
|
|
1861
|
+
* @returns the list of variable names
|
|
1862
|
+
* @throws {ParsingError} if the script is invalid
|
|
1513
1863
|
*/
|
|
1514
|
-
function
|
|
1864
|
+
function extractVariables(script) {
|
|
1865
|
+
var variables = new Set();
|
|
1866
|
+
script = "(()=>{".concat(script, "})()");
|
|
1515
1867
|
try {
|
|
1516
|
-
|
|
1517
|
-
|
|
1868
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
1869
|
+
try {
|
|
1870
|
+
eval(script);
|
|
1871
|
+
}
|
|
1872
|
+
catch (error) {
|
|
1873
|
+
if (!(error instanceof ReferenceError)) {
|
|
1874
|
+
throw error;
|
|
1875
|
+
}
|
|
1876
|
+
var undefinedName = error.message.split(' ')[0];
|
|
1877
|
+
/*
|
|
1878
|
+
Note: Parsing the error
|
|
1879
|
+
[ReferenceError: thing is not defined]
|
|
1880
|
+
*/
|
|
1881
|
+
if (!undefinedName) {
|
|
1882
|
+
throw error;
|
|
1883
|
+
}
|
|
1884
|
+
if (script.includes(undefinedName + '(')) {
|
|
1885
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
1886
|
+
}
|
|
1887
|
+
else {
|
|
1888
|
+
variables.add(undefinedName);
|
|
1889
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1518
1892
|
}
|
|
1519
1893
|
catch (error) {
|
|
1520
1894
|
if (!(error instanceof Error)) {
|
|
1521
1895
|
throw error;
|
|
1522
1896
|
}
|
|
1523
|
-
|
|
1524
|
-
return false;
|
|
1525
|
-
}
|
|
1526
|
-
return false;
|
|
1897
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
1527
1898
|
}
|
|
1899
|
+
return variables;
|
|
1528
1900
|
}
|
|
1901
|
+
/**
|
|
1902
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
1903
|
+
*/
|
|
1529
1904
|
|
|
1530
1905
|
/**
|
|
1531
|
-
*
|
|
1906
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
1907
|
+
*
|
|
1908
|
+
* @param promptTemplate the template with used parameters
|
|
1909
|
+
* @returns the set of parameter names
|
|
1910
|
+
* @throws {ParsingError} if the script is invalid
|
|
1911
|
+
*/
|
|
1912
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
1913
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
1914
|
+
var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, jokerParameterNames = promptTemplate.jokerParameterNames;
|
|
1915
|
+
var parameterNames = new Set();
|
|
1916
|
+
try {
|
|
1917
|
+
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(title)), false), __read(extractParameters(description || '')), false), __read(extractParameters(content)), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1918
|
+
var parameterName = _e.value;
|
|
1919
|
+
parameterNames.add(parameterName);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1923
|
+
finally {
|
|
1924
|
+
try {
|
|
1925
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1926
|
+
}
|
|
1927
|
+
finally { if (e_1) throw e_1.error; }
|
|
1928
|
+
}
|
|
1929
|
+
if (blockType === 'SCRIPT') {
|
|
1930
|
+
try {
|
|
1931
|
+
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1932
|
+
var parameterName = _g.value;
|
|
1933
|
+
parameterNames.add(parameterName);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1937
|
+
finally {
|
|
1938
|
+
try {
|
|
1939
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1940
|
+
}
|
|
1941
|
+
finally { if (e_2) throw e_2.error; }
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
try {
|
|
1945
|
+
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
1946
|
+
var jokerName = _j.value;
|
|
1947
|
+
parameterNames.add(jokerName);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1951
|
+
finally {
|
|
1952
|
+
try {
|
|
1953
|
+
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
1954
|
+
}
|
|
1955
|
+
finally { if (e_3) throw e_3.error; }
|
|
1956
|
+
}
|
|
1957
|
+
return parameterNames;
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* TODO: [🔣] If script require contentLanguage
|
|
1961
|
+
*/
|
|
1962
|
+
|
|
1963
|
+
/**
|
|
1964
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
1965
|
+
*
|
|
1966
|
+
* @private Always catched and rethrown as `PipelineExecutionError`
|
|
1967
|
+
* Note: This is a kindof subtype of PipelineExecutionError
|
|
1968
|
+
*/
|
|
1969
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
1970
|
+
__extends(ExpectError, _super);
|
|
1971
|
+
function ExpectError(message) {
|
|
1972
|
+
var _this = _super.call(this, message) || this;
|
|
1973
|
+
_this.name = 'ExpectError';
|
|
1974
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
1975
|
+
return _this;
|
|
1976
|
+
}
|
|
1977
|
+
return ExpectError;
|
|
1978
|
+
}(Error));
|
|
1979
|
+
|
|
1980
|
+
/**
|
|
1981
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1982
|
+
*/
|
|
1983
|
+
function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
1984
|
+
try {
|
|
1985
|
+
JSON.parse(value);
|
|
1986
|
+
return true;
|
|
1987
|
+
}
|
|
1988
|
+
catch (error) {
|
|
1989
|
+
if (!(error instanceof Error)) {
|
|
1990
|
+
throw error;
|
|
1991
|
+
}
|
|
1992
|
+
if (error.message.includes('Unexpected token')) {
|
|
1993
|
+
return false;
|
|
1994
|
+
}
|
|
1995
|
+
return false;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
/**
|
|
2000
|
+
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
1532
2001
|
*
|
|
1533
2002
|
* @private Internal utility of `joinLlmExecutionTools`
|
|
1534
2003
|
*/
|
|
@@ -1657,7 +2126,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1657
2126
|
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n\n "); }));
|
|
1658
2127
|
}
|
|
1659
2128
|
else {
|
|
1660
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n
|
|
2129
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
|
|
1661
2130
|
.map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
|
|
1662
2131
|
.join('\n')), "\n\n "); }));
|
|
1663
2132
|
}
|
|
@@ -1667,7 +2136,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1667
2136
|
};
|
|
1668
2137
|
/**
|
|
1669
2138
|
* List all available models that can be used
|
|
1670
|
-
* This
|
|
2139
|
+
* This lists is a combination of all available models from all execution tools
|
|
1671
2140
|
*/
|
|
1672
2141
|
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
1673
2142
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1713,6 +2182,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1713
2182
|
}());
|
|
1714
2183
|
/**
|
|
1715
2184
|
* TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
|
|
2185
|
+
* TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
|
|
2186
|
+
* Look how `countTotalUsage` (and `cacheLlmTools`) implements it
|
|
1716
2187
|
*/
|
|
1717
2188
|
|
|
1718
2189
|
/**
|
|
@@ -1734,7 +2205,7 @@ function joinLlmExecutionTools() {
|
|
|
1734
2205
|
llmExecutionTools[_i] = arguments[_i];
|
|
1735
2206
|
}
|
|
1736
2207
|
if (llmExecutionTools.length === 0) {
|
|
1737
|
-
var warningMessage = spaceTrim("\n You have provided
|
|
2208
|
+
var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
|
|
1738
2209
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
1739
2210
|
console.warn(warningMessage);
|
|
1740
2211
|
/*
|
|
@@ -1761,6 +2232,31 @@ function joinLlmExecutionTools() {
|
|
|
1761
2232
|
return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
|
|
1762
2233
|
}
|
|
1763
2234
|
|
|
2235
|
+
/**
|
|
2236
|
+
* Determine if the pipeline is fully prepared
|
|
2237
|
+
*/
|
|
2238
|
+
function isPipelinePrepared(pipeline) {
|
|
2239
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2240
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2241
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2242
|
+
console.log('!!!!', 'Not all personas have modelRequirements');
|
|
2243
|
+
return false;
|
|
2244
|
+
}
|
|
2245
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2246
|
+
console.log('!!!!', 'Not all knowledgeSources have preparationIds');
|
|
2247
|
+
return false;
|
|
2248
|
+
}
|
|
2249
|
+
// TODO: !!!!! Is context in each template
|
|
2250
|
+
// TODO: !!!!! Are samples prepared
|
|
2251
|
+
// TODO: !!!!! Are templates prepared
|
|
2252
|
+
return true;
|
|
2253
|
+
}
|
|
2254
|
+
/**
|
|
2255
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2256
|
+
* TODO: [🔼] Export via core or utils
|
|
2257
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2258
|
+
*/
|
|
2259
|
+
|
|
1764
2260
|
/**
|
|
1765
2261
|
* Takes an item or an array of items and returns an array of items
|
|
1766
2262
|
*
|
|
@@ -1781,102 +2277,173 @@ function arrayableToArray(input) {
|
|
|
1781
2277
|
}
|
|
1782
2278
|
|
|
1783
2279
|
/**
|
|
1784
|
-
*
|
|
2280
|
+
* Just marks a place of place where should be something implemented
|
|
2281
|
+
* No side effects.
|
|
2282
|
+
*
|
|
2283
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2284
|
+
*
|
|
2285
|
+
* @param value any values
|
|
2286
|
+
* @returns void
|
|
2287
|
+
* @private within the repository
|
|
1785
2288
|
*/
|
|
1786
|
-
|
|
1787
|
-
|
|
2289
|
+
function TODO_USE() {
|
|
2290
|
+
var value = [];
|
|
2291
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2292
|
+
value[_i] = arguments[_i];
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
1788
2295
|
|
|
1789
2296
|
/**
|
|
1790
|
-
*
|
|
2297
|
+
* This error type indicates that some limit was reached
|
|
2298
|
+
*/
|
|
2299
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
2300
|
+
__extends(LimitReachedError, _super);
|
|
2301
|
+
function LimitReachedError(message) {
|
|
2302
|
+
var _this = _super.call(this, message) || this;
|
|
2303
|
+
_this.name = 'LimitReachedError';
|
|
2304
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2305
|
+
return _this;
|
|
2306
|
+
}
|
|
2307
|
+
return LimitReachedError;
|
|
2308
|
+
}(Error));
|
|
2309
|
+
|
|
2310
|
+
/**
|
|
2311
|
+
* Replaces parameters in template with values from parameters object
|
|
1791
2312
|
*
|
|
1792
|
-
*
|
|
2313
|
+
* @param template the template with parameters in {curly} braces
|
|
2314
|
+
* @param parameters the object with parameters
|
|
2315
|
+
* @returns the template with replaced parameters
|
|
2316
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
1793
2317
|
*/
|
|
1794
|
-
function
|
|
1795
|
-
var
|
|
1796
|
-
|
|
1797
|
-
|
|
2318
|
+
function replaceParameters(template, parameters) {
|
|
2319
|
+
var replacedTemplate = template;
|
|
2320
|
+
var match;
|
|
2321
|
+
var loopLimit = LOOP_LIMIT;
|
|
2322
|
+
var _loop_1 = function () {
|
|
2323
|
+
if (loopLimit-- < 0) {
|
|
2324
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
2325
|
+
}
|
|
2326
|
+
var precol = match.groups.precol;
|
|
2327
|
+
var parameterName = match.groups.parameterName;
|
|
2328
|
+
if (parameterName === '') {
|
|
2329
|
+
return "continue";
|
|
2330
|
+
}
|
|
2331
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
2332
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
2333
|
+
}
|
|
2334
|
+
if (parameters[parameterName] === undefined) {
|
|
2335
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2336
|
+
}
|
|
2337
|
+
var parameterValue = parameters[parameterName];
|
|
2338
|
+
if (parameterValue === undefined) {
|
|
2339
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2340
|
+
}
|
|
2341
|
+
parameterValue = parameterValue.toString();
|
|
2342
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2343
|
+
parameterValue = parameterValue
|
|
2344
|
+
.split('\n')
|
|
2345
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
2346
|
+
.join('\n');
|
|
2347
|
+
}
|
|
2348
|
+
replacedTemplate =
|
|
2349
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
2350
|
+
parameterValue +
|
|
2351
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
2352
|
+
};
|
|
2353
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
2354
|
+
.exec(replacedTemplate))) {
|
|
2355
|
+
_loop_1();
|
|
1798
2356
|
}
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
2357
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
2358
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
2359
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
2360
|
+
}
|
|
2361
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
2362
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
2363
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
2364
|
+
}
|
|
2365
|
+
return replacedTemplate;
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
/**
|
|
2369
|
+
* Create difference set of two sets.
|
|
2370
|
+
*
|
|
2371
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2372
|
+
*/
|
|
2373
|
+
function difference(a, b, isEqual) {
|
|
2374
|
+
var e_1, _a;
|
|
2375
|
+
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
2376
|
+
var diff = new Set();
|
|
2377
|
+
var _loop_1 = function (itemA) {
|
|
2378
|
+
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
2379
|
+
diff.add(itemA);
|
|
2380
|
+
}
|
|
1819
2381
|
};
|
|
1820
|
-
|
|
1821
|
-
var
|
|
1822
|
-
|
|
1823
|
-
|
|
2382
|
+
try {
|
|
2383
|
+
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2384
|
+
var itemA = _c.value;
|
|
2385
|
+
_loop_1(itemA);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2389
|
+
finally {
|
|
1824
2390
|
try {
|
|
1825
|
-
|
|
1826
|
-
var key = _e.value;
|
|
1827
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1828
|
-
//@ts-ignore
|
|
1829
|
-
if (item.input[key]) {
|
|
1830
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1831
|
-
//@ts-ignore
|
|
1832
|
-
acc.input[key].value += item.input[key].value || 0;
|
|
1833
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1834
|
-
//@ts-ignore
|
|
1835
|
-
if (item.input[key].isUncertain) {
|
|
1836
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1837
|
-
//@ts-ignore
|
|
1838
|
-
acc.input[key].isUncertain = true;
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
2391
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1842
2392
|
}
|
|
1843
|
-
|
|
1844
|
-
|
|
2393
|
+
finally { if (e_1) throw e_1.error; }
|
|
2394
|
+
}
|
|
2395
|
+
return diff;
|
|
2396
|
+
}
|
|
2397
|
+
/**
|
|
2398
|
+
* TODO: [🧠][💯] Maybe also implement symmetricDifference
|
|
2399
|
+
*/
|
|
2400
|
+
|
|
2401
|
+
/**
|
|
2402
|
+
* Creates a new set with all elements that are present in either set
|
|
2403
|
+
*
|
|
2404
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2405
|
+
*/
|
|
2406
|
+
function union() {
|
|
2407
|
+
var e_1, _a, e_2, _b;
|
|
2408
|
+
var sets = [];
|
|
2409
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2410
|
+
sets[_i] = arguments[_i];
|
|
2411
|
+
}
|
|
2412
|
+
var union = new Set();
|
|
2413
|
+
try {
|
|
2414
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2415
|
+
var set = sets_1_1.value;
|
|
1845
2416
|
try {
|
|
1846
|
-
|
|
2417
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2418
|
+
var item = _d.value;
|
|
2419
|
+
union.add(item);
|
|
2420
|
+
}
|
|
1847
2421
|
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
var key = _g.value;
|
|
1853
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1854
|
-
//@ts-ignore
|
|
1855
|
-
if (item.output[key]) {
|
|
1856
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1857
|
-
//@ts-ignore
|
|
1858
|
-
acc.output[key].value += item.output[key].value || 0;
|
|
1859
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1860
|
-
//@ts-ignore
|
|
1861
|
-
if (item.output[key].isUncertain) {
|
|
1862
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1863
|
-
//@ts-ignore
|
|
1864
|
-
acc.output[key].isUncertain = true;
|
|
1865
|
-
}
|
|
2422
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2423
|
+
finally {
|
|
2424
|
+
try {
|
|
2425
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1866
2426
|
}
|
|
2427
|
+
finally { if (e_2) throw e_2.error; }
|
|
1867
2428
|
}
|
|
1868
2429
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
finally { if (e_2) throw e_2.error; }
|
|
2430
|
+
}
|
|
2431
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2432
|
+
finally {
|
|
2433
|
+
try {
|
|
2434
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
1875
2435
|
}
|
|
1876
|
-
|
|
1877
|
-
}
|
|
2436
|
+
finally { if (e_1) throw e_1.error; }
|
|
2437
|
+
}
|
|
2438
|
+
return union;
|
|
1878
2439
|
}
|
|
1879
2440
|
|
|
2441
|
+
/**
|
|
2442
|
+
* The version of the Promptbook library
|
|
2443
|
+
*/
|
|
2444
|
+
var PROMPTBOOK_VERSION = '0.61.0-20';
|
|
2445
|
+
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2446
|
+
|
|
1880
2447
|
/**
|
|
1881
2448
|
* Counts number of characters in the text
|
|
1882
2449
|
*/
|
|
@@ -2008,66 +2575,6 @@ function isPassingExpectations(expectations, value) {
|
|
|
2008
2575
|
* TODO: [💝] Unite object for expecting amount and format
|
|
2009
2576
|
*/
|
|
2010
2577
|
|
|
2011
|
-
/**
|
|
2012
|
-
* Replaces parameters in template with values from parameters object
|
|
2013
|
-
*
|
|
2014
|
-
* @param template the template with parameters in {curly} braces
|
|
2015
|
-
* @param parameters the object with parameters
|
|
2016
|
-
* @returns the template with replaced parameters
|
|
2017
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2018
|
-
*
|
|
2019
|
-
* @private within the createPipelineExecutor
|
|
2020
|
-
*/
|
|
2021
|
-
function replaceParameters(template, parameters) {
|
|
2022
|
-
var replacedTemplate = template;
|
|
2023
|
-
var match;
|
|
2024
|
-
var loopLimit = LOOP_LIMIT;
|
|
2025
|
-
var _loop_1 = function () {
|
|
2026
|
-
if (loopLimit-- < 0) {
|
|
2027
|
-
throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
2028
|
-
}
|
|
2029
|
-
var precol = match.groups.precol;
|
|
2030
|
-
var parameterName = match.groups.parameterName;
|
|
2031
|
-
if (parameterName === '') {
|
|
2032
|
-
return "continue";
|
|
2033
|
-
}
|
|
2034
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
2035
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
2036
|
-
}
|
|
2037
|
-
if (parameters[parameterName] === undefined) {
|
|
2038
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2039
|
-
}
|
|
2040
|
-
var parameterValue = parameters[parameterName];
|
|
2041
|
-
if (parameterValue === undefined) {
|
|
2042
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2043
|
-
}
|
|
2044
|
-
parameterValue = parameterValue.toString();
|
|
2045
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2046
|
-
parameterValue = parameterValue
|
|
2047
|
-
.split('\n')
|
|
2048
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
2049
|
-
.join('\n');
|
|
2050
|
-
}
|
|
2051
|
-
replacedTemplate =
|
|
2052
|
-
replacedTemplate.substring(0, match.index + precol.length) +
|
|
2053
|
-
parameterValue +
|
|
2054
|
-
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
2055
|
-
};
|
|
2056
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
2057
|
-
.exec(replacedTemplate))) {
|
|
2058
|
-
_loop_1();
|
|
2059
|
-
}
|
|
2060
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
2061
|
-
if (/{\w+$/.test(replacedTemplate)) {
|
|
2062
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
2063
|
-
}
|
|
2064
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
2065
|
-
if (/^\w+}/.test(replacedTemplate)) {
|
|
2066
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
2067
|
-
}
|
|
2068
|
-
return replacedTemplate;
|
|
2069
|
-
}
|
|
2070
|
-
|
|
2071
2578
|
/**
|
|
2072
2579
|
* Creates executor function from pipeline and execution tools.
|
|
2073
2580
|
*
|
|
@@ -2076,21 +2583,73 @@ function replaceParameters(template, parameters) {
|
|
|
2076
2583
|
*/
|
|
2077
2584
|
function createPipelineExecutor(options) {
|
|
2078
2585
|
var _this = this;
|
|
2079
|
-
var
|
|
2080
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ?
|
|
2081
|
-
|
|
2082
|
-
validatePipeline(pipeline);
|
|
2083
|
-
// TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
|
|
2084
|
-
// TODO: !!!!! Do here personaToModelRequirements
|
|
2586
|
+
var rawPipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2587
|
+
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.isVerbose, isVerbose = _d === void 0 ? false : _d;
|
|
2588
|
+
validatePipeline(rawPipeline);
|
|
2085
2589
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2590
|
+
var pipeline;
|
|
2591
|
+
if (isPipelinePrepared(rawPipeline)) {
|
|
2592
|
+
pipeline = rawPipeline;
|
|
2593
|
+
}
|
|
2594
|
+
else {
|
|
2595
|
+
console.warn(spaceTrim$1("\n Pipeline ".concat(rawPipeline.pipelineUrl || rawPipeline.sourceFile || rawPipeline.title, " is not prepared\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
|
|
2596
|
+
}
|
|
2086
2597
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2598
|
+
function getContextForTemplate(// <- TODO: [🧠][🥜]
|
|
2599
|
+
template) {
|
|
2600
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2601
|
+
return __generator(this, function (_a) {
|
|
2602
|
+
// TODO: !!!!!! Implement Better - use real index and keyword search
|
|
2603
|
+
TODO_USE(template);
|
|
2604
|
+
return [2 /*return*/, pipeline.knowledgePieces.map(function (_a) {
|
|
2605
|
+
var content = _a.content;
|
|
2606
|
+
return "- ".concat(content);
|
|
2607
|
+
}).join('\n')];
|
|
2608
|
+
});
|
|
2609
|
+
});
|
|
2610
|
+
}
|
|
2611
|
+
function getReservedParametersForTemplate(template) {
|
|
2612
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2613
|
+
var context, currentDate, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2614
|
+
var e_3, _a;
|
|
2615
|
+
return __generator(this, function (_b) {
|
|
2616
|
+
switch (_b.label) {
|
|
2617
|
+
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
2618
|
+
case 1:
|
|
2619
|
+
context = _b.sent();
|
|
2620
|
+
currentDate = new Date().toISOString();
|
|
2621
|
+
reservedParameters = {
|
|
2622
|
+
context: context,
|
|
2623
|
+
currentDate: currentDate,
|
|
2624
|
+
};
|
|
2625
|
+
try {
|
|
2626
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
2627
|
+
for (RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
|
|
2628
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
2629
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
2630
|
+
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2635
|
+
finally {
|
|
2636
|
+
try {
|
|
2637
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
2638
|
+
}
|
|
2639
|
+
finally { if (e_3) throw e_3.error; }
|
|
2640
|
+
}
|
|
2641
|
+
return [2 /*return*/, reservedParameters];
|
|
2642
|
+
}
|
|
2643
|
+
});
|
|
2644
|
+
});
|
|
2645
|
+
}
|
|
2087
2646
|
function executeSingleTemplate(currentTemplate) {
|
|
2088
2647
|
return __awaiter(this, void 0, void 0, function () {
|
|
2089
|
-
var name, title, priority, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts,
|
|
2090
|
-
var
|
|
2648
|
+
var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
|
|
2649
|
+
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2091
2650
|
var _this = this;
|
|
2092
|
-
return __generator(this, function (
|
|
2093
|
-
switch (
|
|
2651
|
+
return __generator(this, function (_u) {
|
|
2652
|
+
switch (_u.label) {
|
|
2094
2653
|
case 0:
|
|
2095
2654
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
2096
2655
|
title = currentTemplate.title;
|
|
@@ -2107,61 +2666,108 @@ function createPipelineExecutor(options) {
|
|
|
2107
2666
|
// <- [3]
|
|
2108
2667
|
})];
|
|
2109
2668
|
case 1:
|
|
2110
|
-
|
|
2111
|
-
|
|
2669
|
+
_u.sent();
|
|
2670
|
+
_u.label = 2;
|
|
2112
2671
|
case 2:
|
|
2672
|
+
usedParameterNames = extractParametersFromPromptTemplate(currentTemplate);
|
|
2673
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2674
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2675
|
+
throw new UnexpectedError(spaceTrim$1("\n Dependent parameters are not consistent used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n ")));
|
|
2676
|
+
}
|
|
2677
|
+
_b = (_a = Object).freeze;
|
|
2678
|
+
_c = [{}];
|
|
2679
|
+
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
2680
|
+
case 3:
|
|
2681
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_u.sent())])), parametersToPass])]);
|
|
2682
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
2683
|
+
parameters = {};
|
|
2684
|
+
try {
|
|
2685
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
2686
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2687
|
+
parameterName = _e.value;
|
|
2688
|
+
// Situation: Parameter is defined and used
|
|
2689
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2690
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
2691
|
+
}
|
|
2692
|
+
// Situation: Parameter is defined but NOT used
|
|
2693
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
2694
|
+
// Do not pass this parameter to prompt
|
|
2695
|
+
}
|
|
2696
|
+
// Situation: Parameter is NOT defined BUT used
|
|
2697
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2698
|
+
// Houston, we have a problem
|
|
2699
|
+
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
2700
|
+
throw new UnexpectedError(spaceTrim$1("\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ")));
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
2705
|
+
finally {
|
|
2706
|
+
try {
|
|
2707
|
+
if (_e && !_e.done && (_p = _d.return)) _p.call(_d);
|
|
2708
|
+
}
|
|
2709
|
+
finally { if (e_7) throw e_7.error; }
|
|
2710
|
+
}
|
|
2711
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
2712
|
+
Object.freeze(parameters);
|
|
2113
2713
|
result = null;
|
|
2114
2714
|
resultString = null;
|
|
2115
2715
|
expectError = null;
|
|
2116
2716
|
maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
2117
|
-
|
|
2118
|
-
attempt = -
|
|
2119
|
-
|
|
2120
|
-
case
|
|
2121
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
2717
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
2718
|
+
attempt = -jokerParameterNames.length;
|
|
2719
|
+
_u.label = 4;
|
|
2720
|
+
case 4:
|
|
2721
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 52];
|
|
2122
2722
|
isJokerAttempt = attempt < 0;
|
|
2123
|
-
|
|
2124
|
-
if (isJokerAttempt && !
|
|
2723
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
2724
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
2125
2725
|
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
2126
2726
|
}
|
|
2127
2727
|
result = null;
|
|
2128
2728
|
resultString = null;
|
|
2129
2729
|
expectError = null;
|
|
2130
2730
|
if (isJokerAttempt) {
|
|
2131
|
-
if (
|
|
2132
|
-
throw new PipelineExecutionError("Joker parameter {".concat(
|
|
2731
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
2732
|
+
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
2733
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
2734
|
+
}
|
|
2735
|
+
else {
|
|
2736
|
+
resultString = parameters[jokerParameterName];
|
|
2133
2737
|
}
|
|
2134
|
-
resultString = parametersToPass[joker];
|
|
2135
|
-
}
|
|
2136
|
-
_o.label = 4;
|
|
2137
|
-
case 4:
|
|
2138
|
-
_o.trys.push([4, 47, 48, 49]);
|
|
2139
|
-
if (!!isJokerAttempt) return [3 /*break*/, 29];
|
|
2140
|
-
_a = currentTemplate.blockType;
|
|
2141
|
-
switch (_a) {
|
|
2142
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 5];
|
|
2143
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 6];
|
|
2144
|
-
case 'SCRIPT': return [3 /*break*/, 15];
|
|
2145
|
-
case 'PROMPT_DIALOG': return [3 /*break*/, 26];
|
|
2146
2738
|
}
|
|
2147
|
-
|
|
2739
|
+
_u.label = 5;
|
|
2148
2740
|
case 5:
|
|
2149
|
-
|
|
2741
|
+
_u.trys.push([5, 48, 49, 50]);
|
|
2742
|
+
if (!!isJokerAttempt) return [3 /*break*/, 30];
|
|
2743
|
+
_f = currentTemplate.blockType;
|
|
2744
|
+
switch (_f) {
|
|
2745
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
2746
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
2747
|
+
case 'SCRIPT': return [3 /*break*/, 16];
|
|
2748
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
2749
|
+
}
|
|
2150
2750
|
return [3 /*break*/, 29];
|
|
2151
2751
|
case 6:
|
|
2752
|
+
resultString = replaceParameters(currentTemplate.content, parameters);
|
|
2753
|
+
return [3 /*break*/, 30];
|
|
2754
|
+
case 7:
|
|
2152
2755
|
prompt = {
|
|
2153
2756
|
title: currentTemplate.title,
|
|
2154
2757
|
pipelineUrl: "".concat(pipeline.pipelineUrl
|
|
2155
2758
|
? pipeline.pipelineUrl
|
|
2156
2759
|
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
2157
|
-
parameters:
|
|
2158
|
-
content:
|
|
2760
|
+
parameters: parameters,
|
|
2761
|
+
content: currentTemplate.content,
|
|
2159
2762
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2160
|
-
expectations:
|
|
2763
|
+
expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
|
|
2764
|
+
var name = _a.name;
|
|
2765
|
+
return name === currentTemplate.personaName;
|
|
2766
|
+
}) || {})), currentTemplate.expectations),
|
|
2161
2767
|
expectFormat: currentTemplate.expectFormat,
|
|
2162
|
-
postprocessing: (currentTemplate.
|
|
2163
|
-
var errors, _a, _b, scriptTools, error_5,
|
|
2164
|
-
var
|
|
2768
|
+
postprocessing: (currentTemplate.postprocessingFunctionNames || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
2769
|
+
var errors, _a, _b, scriptTools, error_5, e_8_1;
|
|
2770
|
+
var e_8, _c;
|
|
2165
2771
|
return __generator(this, function (_d) {
|
|
2166
2772
|
switch (_d.label) {
|
|
2167
2773
|
case 0:
|
|
@@ -2182,7 +2788,7 @@ function createPipelineExecutor(options) {
|
|
|
2182
2788
|
script: "".concat(functionName, "(result)"),
|
|
2183
2789
|
parameters: {
|
|
2184
2790
|
result: result || '',
|
|
2185
|
-
// Note: No ...
|
|
2791
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2186
2792
|
},
|
|
2187
2793
|
})];
|
|
2188
2794
|
case 4: return [2 /*return*/, _d.sent()];
|
|
@@ -2191,6 +2797,9 @@ function createPipelineExecutor(options) {
|
|
|
2191
2797
|
if (!(error_5 instanceof Error)) {
|
|
2192
2798
|
throw error_5;
|
|
2193
2799
|
}
|
|
2800
|
+
if (error_5 instanceof UnexpectedError) {
|
|
2801
|
+
throw error_5;
|
|
2802
|
+
}
|
|
2194
2803
|
errors.push(error_5);
|
|
2195
2804
|
return [3 /*break*/, 6];
|
|
2196
2805
|
case 6:
|
|
@@ -2198,14 +2807,14 @@ function createPipelineExecutor(options) {
|
|
|
2198
2807
|
return [3 /*break*/, 2];
|
|
2199
2808
|
case 7: return [3 /*break*/, 10];
|
|
2200
2809
|
case 8:
|
|
2201
|
-
|
|
2202
|
-
|
|
2810
|
+
e_8_1 = _d.sent();
|
|
2811
|
+
e_8 = { error: e_8_1 };
|
|
2203
2812
|
return [3 /*break*/, 10];
|
|
2204
2813
|
case 9:
|
|
2205
2814
|
try {
|
|
2206
2815
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2207
2816
|
}
|
|
2208
|
-
finally { if (
|
|
2817
|
+
finally { if (e_8) throw e_8.error; }
|
|
2209
2818
|
return [7 /*endfinally*/];
|
|
2210
2819
|
case 10:
|
|
2211
2820
|
if (errors.length === 0) {
|
|
@@ -2221,35 +2830,35 @@ function createPipelineExecutor(options) {
|
|
|
2221
2830
|
});
|
|
2222
2831
|
}); }; }),
|
|
2223
2832
|
};
|
|
2224
|
-
|
|
2225
|
-
switch (
|
|
2226
|
-
case 'CHAT': return [3 /*break*/,
|
|
2227
|
-
case 'COMPLETION': return [3 /*break*/,
|
|
2228
|
-
case 'EMBEDDING': return [3 /*break*/,
|
|
2833
|
+
_g = currentTemplate.modelRequirements.modelVariant;
|
|
2834
|
+
switch (_g) {
|
|
2835
|
+
case 'CHAT': return [3 /*break*/, 8];
|
|
2836
|
+
case 'COMPLETION': return [3 /*break*/, 10];
|
|
2837
|
+
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
2229
2838
|
}
|
|
2230
|
-
return [3 /*break*/,
|
|
2231
|
-
case
|
|
2232
|
-
case
|
|
2233
|
-
chatResult =
|
|
2839
|
+
return [3 /*break*/, 14];
|
|
2840
|
+
case 8: return [4 /*yield*/, llmTools.callChatModel(deepFreeze(prompt))];
|
|
2841
|
+
case 9:
|
|
2842
|
+
chatResult = _u.sent();
|
|
2234
2843
|
// TODO: [🍬] Destroy chatThread
|
|
2235
2844
|
result = chatResult;
|
|
2236
2845
|
resultString = chatResult.content;
|
|
2237
|
-
return [3 /*break*/,
|
|
2238
|
-
case
|
|
2239
|
-
case
|
|
2240
|
-
completionResult =
|
|
2846
|
+
return [3 /*break*/, 15];
|
|
2847
|
+
case 10: return [4 /*yield*/, llmTools.callCompletionModel(deepFreeze(prompt))];
|
|
2848
|
+
case 11:
|
|
2849
|
+
completionResult = _u.sent();
|
|
2241
2850
|
result = completionResult;
|
|
2242
2851
|
resultString = completionResult.content;
|
|
2243
|
-
return [3 /*break*/,
|
|
2244
|
-
case
|
|
2245
|
-
case
|
|
2246
|
-
embeddingResult =
|
|
2852
|
+
return [3 /*break*/, 15];
|
|
2853
|
+
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel(deepFreeze(prompt))];
|
|
2854
|
+
case 13:
|
|
2855
|
+
embeddingResult = _u.sent();
|
|
2247
2856
|
result = embeddingResult;
|
|
2248
2857
|
resultString = embeddingResult.content.join(',');
|
|
2249
|
-
return [3 /*break*/,
|
|
2250
|
-
case
|
|
2251
|
-
case
|
|
2252
|
-
case
|
|
2858
|
+
return [3 /*break*/, 15];
|
|
2859
|
+
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
2860
|
+
case 15: return [3 /*break*/, 30];
|
|
2861
|
+
case 16:
|
|
2253
2862
|
if (arrayableToArray(tools.script).length === 0) {
|
|
2254
2863
|
throw new PipelineExecutionError('No script execution tools are available');
|
|
2255
2864
|
}
|
|
@@ -2258,49 +2867,52 @@ function createPipelineExecutor(options) {
|
|
|
2258
2867
|
}
|
|
2259
2868
|
// TODO: DRY [1]
|
|
2260
2869
|
scriptPipelineExecutionErrors = [];
|
|
2261
|
-
|
|
2262
|
-
case 16:
|
|
2263
|
-
_o.trys.push([16, 23, 24, 25]);
|
|
2264
|
-
_c = (e_2 = void 0, __values(arrayableToArray(tools.script))), _d = _c.next();
|
|
2265
|
-
_o.label = 17;
|
|
2870
|
+
_u.label = 17;
|
|
2266
2871
|
case 17:
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2872
|
+
_u.trys.push([17, 24, 25, 26]);
|
|
2873
|
+
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
2874
|
+
_u.label = 18;
|
|
2270
2875
|
case 18:
|
|
2271
|
-
|
|
2272
|
-
|
|
2876
|
+
if (!!_j.done) return [3 /*break*/, 23];
|
|
2877
|
+
scriptTools = _j.value;
|
|
2878
|
+
_u.label = 19;
|
|
2879
|
+
case 19:
|
|
2880
|
+
_u.trys.push([19, 21, , 22]);
|
|
2881
|
+
return [4 /*yield*/, scriptTools.execute(deepFreeze({
|
|
2273
2882
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
2274
2883
|
script: currentTemplate.content,
|
|
2275
|
-
parameters:
|
|
2276
|
-
})];
|
|
2277
|
-
case 19:
|
|
2278
|
-
resultString = _o.sent();
|
|
2279
|
-
return [3 /*break*/, 22];
|
|
2884
|
+
parameters: parameters,
|
|
2885
|
+
}))];
|
|
2280
2886
|
case 20:
|
|
2281
|
-
|
|
2887
|
+
resultString = _u.sent();
|
|
2888
|
+
return [3 /*break*/, 23];
|
|
2889
|
+
case 21:
|
|
2890
|
+
error_2 = _u.sent();
|
|
2282
2891
|
if (!(error_2 instanceof Error)) {
|
|
2283
2892
|
throw error_2;
|
|
2284
2893
|
}
|
|
2894
|
+
if (error_2 instanceof UnexpectedError) {
|
|
2895
|
+
throw error_2;
|
|
2896
|
+
}
|
|
2285
2897
|
scriptPipelineExecutionErrors.push(error_2);
|
|
2286
|
-
return [3 /*break*/,
|
|
2287
|
-
case
|
|
2288
|
-
|
|
2289
|
-
return [3 /*break*/,
|
|
2290
|
-
case
|
|
2291
|
-
case 23:
|
|
2292
|
-
e_2_1 = _o.sent();
|
|
2293
|
-
e_2 = { error: e_2_1 };
|
|
2294
|
-
return [3 /*break*/, 25];
|
|
2898
|
+
return [3 /*break*/, 22];
|
|
2899
|
+
case 22:
|
|
2900
|
+
_j = _h.next();
|
|
2901
|
+
return [3 /*break*/, 18];
|
|
2902
|
+
case 23: return [3 /*break*/, 26];
|
|
2295
2903
|
case 24:
|
|
2904
|
+
e_4_1 = _u.sent();
|
|
2905
|
+
e_4 = { error: e_4_1 };
|
|
2906
|
+
return [3 /*break*/, 26];
|
|
2907
|
+
case 25:
|
|
2296
2908
|
try {
|
|
2297
|
-
if (
|
|
2909
|
+
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
2298
2910
|
}
|
|
2299
|
-
finally { if (
|
|
2911
|
+
finally { if (e_4) throw e_4.error; }
|
|
2300
2912
|
return [7 /*endfinally*/];
|
|
2301
|
-
case
|
|
2913
|
+
case 26:
|
|
2302
2914
|
if (resultString !== null) {
|
|
2303
|
-
return [3 /*break*/,
|
|
2915
|
+
return [3 /*break*/, 30];
|
|
2304
2916
|
}
|
|
2305
2917
|
if (scriptPipelineExecutionErrors.length === 1) {
|
|
2306
2918
|
throw scriptPipelineExecutionErrors[0];
|
|
@@ -2310,101 +2922,104 @@ function createPipelineExecutor(options) {
|
|
|
2310
2922
|
.map(function (error) { return '- ' + error.message; })
|
|
2311
2923
|
.join('\n\n')), "\n "); }));
|
|
2312
2924
|
}
|
|
2313
|
-
case
|
|
2925
|
+
case 27:
|
|
2314
2926
|
if (tools.userInterface === undefined) {
|
|
2315
2927
|
throw new PipelineExecutionError('User interface tools are not available');
|
|
2316
2928
|
}
|
|
2317
|
-
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
2929
|
+
return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
|
|
2318
2930
|
promptTitle: currentTemplate.title,
|
|
2319
|
-
promptMessage: replaceParameters(currentTemplate.description || '',
|
|
2320
|
-
defaultValue: replaceParameters(currentTemplate.content,
|
|
2931
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
2932
|
+
defaultValue: replaceParameters(currentTemplate.content, parameters),
|
|
2321
2933
|
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
2322
2934
|
placeholder: undefined,
|
|
2323
2935
|
priority: priority,
|
|
2324
|
-
})];
|
|
2325
|
-
case
|
|
2936
|
+
}))];
|
|
2937
|
+
case 28:
|
|
2326
2938
|
// TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
2327
|
-
resultString =
|
|
2328
|
-
return [3 /*break*/,
|
|
2329
|
-
case
|
|
2330
|
-
case 29:
|
|
2331
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 46];
|
|
2332
|
-
_o.label = 30;
|
|
2939
|
+
resultString = _u.sent();
|
|
2940
|
+
return [3 /*break*/, 30];
|
|
2941
|
+
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
2333
2942
|
case 30:
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
_o.label = 31;
|
|
2943
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
2944
|
+
_u.label = 31;
|
|
2337
2945
|
case 31:
|
|
2338
|
-
|
|
2339
|
-
|
|
2946
|
+
_u.trys.push([31, 45, 46, 47]);
|
|
2947
|
+
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
2948
|
+
_u.label = 32;
|
|
2949
|
+
case 32:
|
|
2950
|
+
if (!!_l.done) return [3 /*break*/, 44];
|
|
2951
|
+
functionName = _l.value;
|
|
2340
2952
|
// TODO: DRY [1]
|
|
2341
2953
|
scriptPipelineExecutionErrors = [];
|
|
2342
2954
|
postprocessingError = null;
|
|
2343
|
-
|
|
2344
|
-
case 32:
|
|
2345
|
-
_o.trys.push([32, 39, 40, 41]);
|
|
2346
|
-
_g = (e_3 = void 0, __values(arrayableToArray(tools.script))), _h = _g.next();
|
|
2347
|
-
_o.label = 33;
|
|
2955
|
+
_u.label = 33;
|
|
2348
2956
|
case 33:
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2957
|
+
_u.trys.push([33, 40, 41, 42]);
|
|
2958
|
+
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
2959
|
+
_u.label = 34;
|
|
2352
2960
|
case 34:
|
|
2353
|
-
_o.
|
|
2961
|
+
if (!!_o.done) return [3 /*break*/, 39];
|
|
2962
|
+
scriptTools = _o.value;
|
|
2963
|
+
_u.label = 35;
|
|
2964
|
+
case 35:
|
|
2965
|
+
_u.trys.push([35, 37, , 38]);
|
|
2354
2966
|
return [4 /*yield*/, scriptTools.execute({
|
|
2355
2967
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2356
2968
|
script: "".concat(functionName, "(resultString)"),
|
|
2357
2969
|
parameters: {
|
|
2358
2970
|
resultString: resultString || '',
|
|
2359
|
-
// Note: No ...
|
|
2971
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2360
2972
|
},
|
|
2361
2973
|
})];
|
|
2362
|
-
case 35:
|
|
2363
|
-
resultString = _o.sent();
|
|
2364
|
-
postprocessingError = null;
|
|
2365
|
-
return [3 /*break*/, 38];
|
|
2366
2974
|
case 36:
|
|
2367
|
-
|
|
2975
|
+
resultString = _u.sent();
|
|
2976
|
+
postprocessingError = null;
|
|
2977
|
+
return [3 /*break*/, 39];
|
|
2978
|
+
case 37:
|
|
2979
|
+
error_3 = _u.sent();
|
|
2368
2980
|
if (!(error_3 instanceof Error)) {
|
|
2369
2981
|
throw error_3;
|
|
2370
2982
|
}
|
|
2983
|
+
if (error_3 instanceof UnexpectedError) {
|
|
2984
|
+
throw error_3;
|
|
2985
|
+
}
|
|
2371
2986
|
postprocessingError = error_3;
|
|
2372
2987
|
scriptPipelineExecutionErrors.push(error_3);
|
|
2373
|
-
return [3 /*break*/,
|
|
2374
|
-
case
|
|
2375
|
-
|
|
2376
|
-
return [3 /*break*/,
|
|
2377
|
-
case
|
|
2378
|
-
case 39:
|
|
2379
|
-
e_3_1 = _o.sent();
|
|
2380
|
-
e_3 = { error: e_3_1 };
|
|
2381
|
-
return [3 /*break*/, 41];
|
|
2988
|
+
return [3 /*break*/, 38];
|
|
2989
|
+
case 38:
|
|
2990
|
+
_o = _m.next();
|
|
2991
|
+
return [3 /*break*/, 34];
|
|
2992
|
+
case 39: return [3 /*break*/, 42];
|
|
2382
2993
|
case 40:
|
|
2994
|
+
e_5_1 = _u.sent();
|
|
2995
|
+
e_5 = { error: e_5_1 };
|
|
2996
|
+
return [3 /*break*/, 42];
|
|
2997
|
+
case 41:
|
|
2383
2998
|
try {
|
|
2384
|
-
if (
|
|
2999
|
+
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
2385
3000
|
}
|
|
2386
|
-
finally { if (
|
|
3001
|
+
finally { if (e_5) throw e_5.error; }
|
|
2387
3002
|
return [7 /*endfinally*/];
|
|
2388
|
-
case
|
|
3003
|
+
case 42:
|
|
2389
3004
|
if (postprocessingError) {
|
|
2390
3005
|
throw postprocessingError;
|
|
2391
3006
|
}
|
|
2392
|
-
|
|
2393
|
-
case
|
|
2394
|
-
|
|
2395
|
-
return [3 /*break*/,
|
|
2396
|
-
case
|
|
2397
|
-
case 44:
|
|
2398
|
-
e_4_1 = _o.sent();
|
|
2399
|
-
e_4 = { error: e_4_1 };
|
|
2400
|
-
return [3 /*break*/, 46];
|
|
3007
|
+
_u.label = 43;
|
|
3008
|
+
case 43:
|
|
3009
|
+
_l = _k.next();
|
|
3010
|
+
return [3 /*break*/, 32];
|
|
3011
|
+
case 44: return [3 /*break*/, 47];
|
|
2401
3012
|
case 45:
|
|
3013
|
+
e_6_1 = _u.sent();
|
|
3014
|
+
e_6 = { error: e_6_1 };
|
|
3015
|
+
return [3 /*break*/, 47];
|
|
3016
|
+
case 46:
|
|
2402
3017
|
try {
|
|
2403
|
-
if (
|
|
3018
|
+
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
2404
3019
|
}
|
|
2405
|
-
finally { if (
|
|
3020
|
+
finally { if (e_6) throw e_6.error; }
|
|
2406
3021
|
return [7 /*endfinally*/];
|
|
2407
|
-
case
|
|
3022
|
+
case 47:
|
|
2408
3023
|
// TODO: [💝] Unite object for expecting amount and format
|
|
2409
3024
|
if (currentTemplate.expectFormat) {
|
|
2410
3025
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
@@ -2417,15 +3032,18 @@ function createPipelineExecutor(options) {
|
|
|
2417
3032
|
if (currentTemplate.expectations) {
|
|
2418
3033
|
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
2419
3034
|
}
|
|
2420
|
-
return [3 /*break*/,
|
|
2421
|
-
case
|
|
2422
|
-
error_4 =
|
|
3035
|
+
return [3 /*break*/, 52];
|
|
3036
|
+
case 48:
|
|
3037
|
+
error_4 = _u.sent();
|
|
2423
3038
|
if (!(error_4 instanceof ExpectError)) {
|
|
2424
3039
|
throw error_4;
|
|
2425
3040
|
}
|
|
3041
|
+
if (error_4 instanceof UnexpectedError) {
|
|
3042
|
+
throw error_4;
|
|
3043
|
+
}
|
|
2426
3044
|
expectError = error_4;
|
|
2427
|
-
return [3 /*break*/,
|
|
2428
|
-
case
|
|
3045
|
+
return [3 /*break*/, 50];
|
|
3046
|
+
case 49:
|
|
2429
3047
|
if (!isJokerAttempt &&
|
|
2430
3048
|
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
2431
3049
|
prompt
|
|
@@ -2447,15 +3065,15 @@ function createPipelineExecutor(options) {
|
|
|
2447
3065
|
});
|
|
2448
3066
|
}
|
|
2449
3067
|
return [7 /*endfinally*/];
|
|
2450
|
-
case
|
|
3068
|
+
case 50:
|
|
2451
3069
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
2452
3070
|
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
2453
3071
|
}
|
|
2454
|
-
|
|
2455
|
-
case 50:
|
|
2456
|
-
attempt++;
|
|
2457
|
-
return [3 /*break*/, 3];
|
|
3072
|
+
_u.label = 51;
|
|
2458
3073
|
case 51:
|
|
3074
|
+
attempt++;
|
|
3075
|
+
return [3 /*break*/, 4];
|
|
3076
|
+
case 52:
|
|
2459
3077
|
if (resultString === null) {
|
|
2460
3078
|
throw new UnexpectedError('Something went wrong and prompt result is null');
|
|
2461
3079
|
}
|
|
@@ -2471,18 +3089,54 @@ function createPipelineExecutor(options) {
|
|
|
2471
3089
|
// <- [3]
|
|
2472
3090
|
});
|
|
2473
3091
|
}
|
|
2474
|
-
parametersToPass = __assign(__assign({}, parametersToPass), (
|
|
3092
|
+
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (_t = {}, _t[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _t)));
|
|
2475
3093
|
return [2 /*return*/];
|
|
2476
3094
|
}
|
|
2477
3095
|
});
|
|
2478
3096
|
});
|
|
2479
3097
|
}
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
3098
|
+
function filterJustOutputParameters() {
|
|
3099
|
+
var e_9, _a;
|
|
3100
|
+
var outputParameters = {};
|
|
3101
|
+
try {
|
|
3102
|
+
// Note: Filter ONLY output parameters
|
|
3103
|
+
for (var _b = __values(pipeline.parameters.filter(function (_a) {
|
|
3104
|
+
var isOutput = _a.isOutput;
|
|
3105
|
+
return isOutput;
|
|
3106
|
+
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3107
|
+
var parameter = _c.value;
|
|
3108
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3109
|
+
// [4]
|
|
3110
|
+
errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an output parameter but not set in the pipeline")));
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
3113
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
3117
|
+
finally {
|
|
3118
|
+
try {
|
|
3119
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3120
|
+
}
|
|
3121
|
+
finally { if (e_9) throw e_9.error; }
|
|
3122
|
+
}
|
|
3123
|
+
return outputParameters;
|
|
3124
|
+
}
|
|
3125
|
+
var executionReport, _a, _b, parameter, errors, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameters_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
3126
|
+
var e_1, _e, e_2, _f;
|
|
3127
|
+
return __generator(this, function (_g) {
|
|
3128
|
+
switch (_g.label) {
|
|
2484
3129
|
case 0:
|
|
2485
|
-
|
|
3130
|
+
if (!(pipeline === undefined)) return [3 /*break*/, 2];
|
|
3131
|
+
return [4 /*yield*/, preparePipeline(rawPipeline, {
|
|
3132
|
+
llmTools: llmTools,
|
|
3133
|
+
isVerbose: isVerbose,
|
|
3134
|
+
maxParallelCount: maxParallelCount,
|
|
3135
|
+
})];
|
|
3136
|
+
case 1:
|
|
3137
|
+
pipeline = _g.sent();
|
|
3138
|
+
_g.label = 2;
|
|
3139
|
+
case 2:
|
|
2486
3140
|
executionReport = {
|
|
2487
3141
|
pipelineUrl: pipeline.pipelineUrl,
|
|
2488
3142
|
title: pipeline.title,
|
|
@@ -2491,9 +3145,76 @@ function createPipelineExecutor(options) {
|
|
|
2491
3145
|
description: pipeline.description,
|
|
2492
3146
|
promptExecutions: [],
|
|
2493
3147
|
};
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
3148
|
+
try {
|
|
3149
|
+
// Note: Check that all input input parameters are defined
|
|
3150
|
+
for (_a = __values(pipeline.parameters.filter(function (_a) {
|
|
3151
|
+
var isInput = _a.isInput;
|
|
3152
|
+
return isInput;
|
|
3153
|
+
})), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3154
|
+
parameter = _b.value;
|
|
3155
|
+
if (inputParameters[parameter.name] === undefined) {
|
|
3156
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
3157
|
+
isSuccessful: false,
|
|
3158
|
+
errors: [
|
|
3159
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
|
|
3160
|
+
// <- TODO: !!!!! Test this error
|
|
3161
|
+
],
|
|
3162
|
+
executionReport: executionReport,
|
|
3163
|
+
outputParameters: {},
|
|
3164
|
+
usage: ZERO_USAGE,
|
|
3165
|
+
})];
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3170
|
+
finally {
|
|
3171
|
+
try {
|
|
3172
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
3173
|
+
}
|
|
3174
|
+
finally { if (e_1) throw e_1.error; }
|
|
3175
|
+
}
|
|
3176
|
+
errors = [];
|
|
3177
|
+
_loop_1 = function (parameterName) {
|
|
3178
|
+
var parameter = pipeline.parameters.find(function (_a) {
|
|
3179
|
+
var name = _a.name;
|
|
3180
|
+
return name === parameterName;
|
|
3181
|
+
});
|
|
3182
|
+
if (parameter === undefined) {
|
|
3183
|
+
errors.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is passed as input parameter")));
|
|
3184
|
+
}
|
|
3185
|
+
else if (parameter.isInput === false) {
|
|
3186
|
+
return { value: deepFreezeWithSameType({
|
|
3187
|
+
isSuccessful: false,
|
|
3188
|
+
errors: [
|
|
3189
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but is not input")),
|
|
3190
|
+
// <- TODO: !!!!! Test this error
|
|
3191
|
+
],
|
|
3192
|
+
executionReport: executionReport,
|
|
3193
|
+
outputParameters: {},
|
|
3194
|
+
usage: ZERO_USAGE,
|
|
3195
|
+
}) };
|
|
3196
|
+
}
|
|
3197
|
+
};
|
|
3198
|
+
try {
|
|
3199
|
+
// Note: Check that no extra input parameters are passed
|
|
3200
|
+
for (_c = __values(Object.keys(inputParameters)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3201
|
+
parameterName = _d.value;
|
|
3202
|
+
state_1 = _loop_1(parameterName);
|
|
3203
|
+
if (typeof state_1 === "object")
|
|
3204
|
+
return [2 /*return*/, state_1.value];
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
3207
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3208
|
+
finally {
|
|
3209
|
+
try {
|
|
3210
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
3211
|
+
}
|
|
3212
|
+
finally { if (e_2) throw e_2.error; }
|
|
3213
|
+
}
|
|
3214
|
+
parametersToPass = inputParameters;
|
|
3215
|
+
_g.label = 3;
|
|
3216
|
+
case 3:
|
|
3217
|
+
_g.trys.push([3, 8, , 9]);
|
|
2497
3218
|
resovedParameters_1 = pipeline.parameters
|
|
2498
3219
|
.filter(function (_a) {
|
|
2499
3220
|
var isInput = _a.isInput;
|
|
@@ -2503,30 +3224,40 @@ function createPipelineExecutor(options) {
|
|
|
2503
3224
|
var name = _a.name;
|
|
2504
3225
|
return name;
|
|
2505
3226
|
});
|
|
2506
|
-
|
|
3227
|
+
unresovedTemplates_1 = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
2507
3228
|
resolving_1 = [];
|
|
2508
3229
|
loopLimit = LOOP_LIMIT;
|
|
2509
|
-
|
|
3230
|
+
_loop_2 = function () {
|
|
2510
3231
|
var currentTemplate, work_1;
|
|
2511
|
-
return __generator(this, function (
|
|
2512
|
-
switch (
|
|
3232
|
+
return __generator(this, function (_h) {
|
|
3233
|
+
switch (_h.label) {
|
|
2513
3234
|
case 0:
|
|
2514
3235
|
if (loopLimit-- < 0) {
|
|
3236
|
+
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
2515
3237
|
throw new UnexpectedError('Loop limit reached during resolving parameters pipeline execution');
|
|
2516
3238
|
}
|
|
2517
|
-
currentTemplate =
|
|
3239
|
+
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
2518
3240
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
2519
3241
|
});
|
|
2520
3242
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
2521
|
-
throw new UnexpectedError(
|
|
3243
|
+
throw new UnexpectedError(
|
|
3244
|
+
// TODO: [🐎] DRY
|
|
3245
|
+
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3246
|
+
.map(function (_a) {
|
|
3247
|
+
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3248
|
+
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
3249
|
+
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
3250
|
+
.join(' and '));
|
|
3251
|
+
})
|
|
3252
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
|
|
2522
3253
|
case 1:
|
|
2523
3254
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
2524
3255
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
2525
3256
|
case 2:
|
|
2526
|
-
/* [5] */
|
|
3257
|
+
/* [5] */ _h.sent();
|
|
2527
3258
|
return [3 /*break*/, 4];
|
|
2528
3259
|
case 3:
|
|
2529
|
-
|
|
3260
|
+
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
2530
3261
|
work_1 = executeSingleTemplate(currentTemplate)
|
|
2531
3262
|
.then(function () {
|
|
2532
3263
|
resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
|
|
@@ -2535,120 +3266,113 @@ function createPipelineExecutor(options) {
|
|
|
2535
3266
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
2536
3267
|
});
|
|
2537
3268
|
resolving_1.push(work_1);
|
|
2538
|
-
|
|
3269
|
+
_h.label = 4;
|
|
2539
3270
|
case 4: return [2 /*return*/];
|
|
2540
3271
|
}
|
|
2541
3272
|
});
|
|
2542
3273
|
};
|
|
2543
|
-
|
|
2544
|
-
case
|
|
2545
|
-
if (!(
|
|
2546
|
-
return [5 /*yield**/,
|
|
2547
|
-
case 3:
|
|
2548
|
-
_d.sent();
|
|
2549
|
-
return [3 /*break*/, 2];
|
|
2550
|
-
case 4: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
3274
|
+
_g.label = 4;
|
|
3275
|
+
case 4:
|
|
3276
|
+
if (!(unresovedTemplates_1.length > 0)) return [3 /*break*/, 6];
|
|
3277
|
+
return [5 /*yield**/, _loop_2()];
|
|
2551
3278
|
case 5:
|
|
2552
|
-
|
|
2553
|
-
return [3 /*break*/,
|
|
2554
|
-
case 6:
|
|
2555
|
-
|
|
3279
|
+
_g.sent();
|
|
3280
|
+
return [3 /*break*/, 4];
|
|
3281
|
+
case 6: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
3282
|
+
case 7:
|
|
3283
|
+
_g.sent();
|
|
3284
|
+
return [3 /*break*/, 9];
|
|
3285
|
+
case 8:
|
|
3286
|
+
error_1 = _g.sent();
|
|
2556
3287
|
if (!(error_1 instanceof Error)) {
|
|
2557
3288
|
throw error_1;
|
|
2558
3289
|
}
|
|
2559
3290
|
usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
2560
3291
|
var result = _a.result;
|
|
2561
|
-
return (result === null || result === void 0 ? void 0 : result.usage) ||
|
|
3292
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2562
3293
|
})), false));
|
|
2563
|
-
|
|
3294
|
+
outputParameters_1 = filterJustOutputParameters();
|
|
3295
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2564
3296
|
isSuccessful: false,
|
|
2565
|
-
errors: [error_1],
|
|
3297
|
+
errors: __spreadArray([error_1], __read(errors), false),
|
|
2566
3298
|
usage: usage_1,
|
|
2567
3299
|
executionReport: executionReport,
|
|
2568
|
-
outputParameters:
|
|
2569
|
-
}];
|
|
2570
|
-
case
|
|
2571
|
-
try {
|
|
2572
|
-
// Note: Filter ONLY output parameters
|
|
2573
|
-
for (_a = __values(pipeline.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
2574
|
-
parameter = _b.value;
|
|
2575
|
-
if (parameter.isOutput) {
|
|
2576
|
-
continue;
|
|
2577
|
-
}
|
|
2578
|
-
delete parametersToPass[parameter.name];
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2582
|
-
finally {
|
|
2583
|
-
try {
|
|
2584
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2585
|
-
}
|
|
2586
|
-
finally { if (e_1) throw e_1.error; }
|
|
2587
|
-
}
|
|
3300
|
+
outputParameters: outputParameters_1,
|
|
3301
|
+
})];
|
|
3302
|
+
case 9:
|
|
2588
3303
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
2589
3304
|
var result = _a.result;
|
|
2590
|
-
return (result === null || result === void 0 ? void 0 : result.usage) ||
|
|
3305
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2591
3306
|
})), false));
|
|
2592
|
-
|
|
3307
|
+
outputParameters = filterJustOutputParameters();
|
|
3308
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2593
3309
|
isSuccessful: true,
|
|
2594
|
-
errors:
|
|
3310
|
+
errors: errors,
|
|
2595
3311
|
usage: usage,
|
|
2596
3312
|
executionReport: executionReport,
|
|
2597
|
-
outputParameters:
|
|
2598
|
-
}];
|
|
3313
|
+
outputParameters: outputParameters,
|
|
3314
|
+
})];
|
|
2599
3315
|
}
|
|
2600
3316
|
});
|
|
2601
3317
|
}); };
|
|
2602
3318
|
return pipelineExecutor;
|
|
2603
3319
|
}
|
|
2604
3320
|
/**
|
|
3321
|
+
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3322
|
+
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
3323
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
2605
3324
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2606
3325
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2607
3326
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2608
3327
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
3328
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3329
|
+
* TODO: [💷] !!!! `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result
|
|
2609
3330
|
*/
|
|
2610
3331
|
|
|
2611
|
-
|
|
3332
|
+
/**
|
|
3333
|
+
* @@@
|
|
3334
|
+
*/
|
|
3335
|
+
function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
2612
3336
|
return __awaiter(this, void 0, void 0, function () {
|
|
2613
|
-
var
|
|
2614
|
-
var
|
|
3337
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
3338
|
+
var _f, _g, _h;
|
|
2615
3339
|
var _this = this;
|
|
2616
|
-
return __generator(this, function (
|
|
2617
|
-
switch (
|
|
3340
|
+
return __generator(this, function (_j) {
|
|
3341
|
+
switch (_j.label) {
|
|
2618
3342
|
case 0:
|
|
2619
|
-
|
|
3343
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
3344
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2620
3345
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2621
|
-
_b = createPipelineExecutor;
|
|
2622
|
-
_e = {};
|
|
2623
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2624
|
-
case 1:
|
|
2625
|
-
prepareKnowledgeFromMarkdownExecutor = _b.apply(void 0, [(_e.pipeline = _h.sent(),
|
|
2626
|
-
_e.tools = {
|
|
2627
|
-
llm: llmTools,
|
|
2628
|
-
},
|
|
2629
|
-
_e)]);
|
|
2630
3346
|
_c = createPipelineExecutor;
|
|
2631
3347
|
_f = {};
|
|
2632
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2633
|
-
case
|
|
2634
|
-
|
|
3348
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
3349
|
+
case 1:
|
|
3350
|
+
prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
|
|
2635
3351
|
_f.tools = {
|
|
2636
3352
|
llm: llmTools,
|
|
2637
3353
|
},
|
|
2638
3354
|
_f)]);
|
|
2639
3355
|
_d = createPipelineExecutor;
|
|
2640
3356
|
_g = {};
|
|
2641
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2642
|
-
case
|
|
2643
|
-
|
|
3357
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
|
|
3358
|
+
case 2:
|
|
3359
|
+
prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
|
|
2644
3360
|
_g.tools = {
|
|
2645
3361
|
llm: llmTools,
|
|
2646
3362
|
},
|
|
2647
3363
|
_g)]);
|
|
3364
|
+
_e = createPipelineExecutor;
|
|
3365
|
+
_h = {};
|
|
3366
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
|
|
3367
|
+
case 3:
|
|
3368
|
+
prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
|
|
3369
|
+
_h.tools = {
|
|
3370
|
+
llm: llmTools,
|
|
3371
|
+
},
|
|
3372
|
+
_h)]);
|
|
2648
3373
|
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
|
|
2649
3374
|
case 4:
|
|
2650
|
-
result =
|
|
2651
|
-
// TODO: [0] !!! Aggeregate usage
|
|
3375
|
+
result = _j.sent();
|
|
2652
3376
|
assertsExecutionSuccessful(result);
|
|
2653
3377
|
outputParameters = result.outputParameters;
|
|
2654
3378
|
knowledgeRaw = outputParameters.knowledge;
|
|
@@ -2657,9 +3381,9 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2657
3381
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
2658
3382
|
}
|
|
2659
3383
|
return [4 /*yield*/, Promise.all(
|
|
2660
|
-
// TODO:
|
|
3384
|
+
// TODO: [🪂] !! Do not send all at once but in chunks
|
|
2661
3385
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2662
|
-
var name, title, content, keywords, index,
|
|
3386
|
+
var name, title, content, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
2663
3387
|
return __generator(this, function (_c) {
|
|
2664
3388
|
switch (_c.label) {
|
|
2665
3389
|
case 0:
|
|
@@ -2668,12 +3392,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2668
3392
|
content = spaceTrim(knowledgeTextPiece);
|
|
2669
3393
|
keywords = [];
|
|
2670
3394
|
index = [];
|
|
2671
|
-
sources = [
|
|
2672
|
-
{
|
|
2673
|
-
title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
|
|
2674
|
-
href: '#' /* <- TODO: !!! Unhardcode */,
|
|
2675
|
-
},
|
|
2676
|
-
];
|
|
2677
3395
|
_c.label = 1;
|
|
2678
3396
|
case 1:
|
|
2679
3397
|
_c.trys.push([1, 7, , 8]);
|
|
@@ -2708,7 +3426,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2708
3426
|
})];
|
|
2709
3427
|
case 5:
|
|
2710
3428
|
embeddingResult = _c.sent();
|
|
2711
|
-
// TODO: [0] !!! Aggeregate usage embeddingResult.usage
|
|
2712
3429
|
index.push({
|
|
2713
3430
|
modelName: embeddingResult.modelName,
|
|
2714
3431
|
position: embeddingResult.content,
|
|
@@ -2726,21 +3443,403 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2726
3443
|
content: content,
|
|
2727
3444
|
keywords: keywords,
|
|
2728
3445
|
index: index,
|
|
2729
|
-
|
|
3446
|
+
// <- TODO: [☀] sources,
|
|
2730
3447
|
}];
|
|
2731
3448
|
}
|
|
2732
3449
|
});
|
|
2733
3450
|
}); }))];
|
|
2734
3451
|
case 5:
|
|
2735
|
-
knowledge =
|
|
3452
|
+
knowledge = _j.sent();
|
|
2736
3453
|
return [2 /*return*/, knowledge];
|
|
2737
3454
|
}
|
|
2738
3455
|
});
|
|
2739
|
-
});
|
|
2740
|
-
}
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
/**
|
|
3459
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/markdown`
|
|
3460
|
+
* TODO: [🪂] Do it in parallel 11:11
|
|
3461
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
3462
|
+
*/
|
|
3463
|
+
|
|
3464
|
+
/**
|
|
3465
|
+
* Prepares the knowle
|
|
3466
|
+
*
|
|
3467
|
+
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
3468
|
+
*/
|
|
3469
|
+
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
3470
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3471
|
+
var _a, maxParallelCount, knowledgePrepared;
|
|
3472
|
+
var _this = this;
|
|
3473
|
+
return __generator(this, function (_b) {
|
|
3474
|
+
switch (_b.label) {
|
|
3475
|
+
case 0:
|
|
3476
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3477
|
+
knowledgePrepared = [];
|
|
3478
|
+
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
|
|
3479
|
+
var partialPieces, pieces;
|
|
3480
|
+
return __generator(this, function (_a) {
|
|
3481
|
+
switch (_a.label) {
|
|
3482
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is
|
|
3483
|
+
options)];
|
|
3484
|
+
case 1:
|
|
3485
|
+
partialPieces = _a.sent();
|
|
3486
|
+
pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
|
|
3487
|
+
{
|
|
3488
|
+
name: knowledgeSource.name,
|
|
3489
|
+
// line, column <- TODO: [☀]
|
|
3490
|
+
// <- TODO: [❎]
|
|
3491
|
+
},
|
|
3492
|
+
] })); });
|
|
3493
|
+
knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
|
|
3494
|
+
return [2 /*return*/];
|
|
3495
|
+
}
|
|
3496
|
+
});
|
|
3497
|
+
}); })];
|
|
3498
|
+
case 1:
|
|
3499
|
+
_b.sent();
|
|
3500
|
+
return [2 /*return*/, knowledgePrepared];
|
|
3501
|
+
}
|
|
3502
|
+
});
|
|
3503
|
+
});
|
|
3504
|
+
}
|
|
3505
|
+
/*
|
|
3506
|
+
TODO: [🧊] This is how it can look in future
|
|
3507
|
+
> type PrepareKnowledgeKnowledge = {
|
|
3508
|
+
> /**
|
|
3509
|
+
> * Unprepared knowledge
|
|
3510
|
+
> * /
|
|
3511
|
+
> readonly knowledgeSources: Array<KnowledgeSourceJson>;
|
|
3512
|
+
> };
|
|
3513
|
+
>
|
|
3514
|
+
> export async function prepareKnowledgePieces(
|
|
3515
|
+
> knowledge: PrepareKnowledgeKnowledge,
|
|
3516
|
+
> options: PrepareOptions,
|
|
3517
|
+
> ):
|
|
3518
|
+
*/
|
|
3519
|
+
/**
|
|
3520
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/core`
|
|
3521
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3522
|
+
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
3523
|
+
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
3524
|
+
* TODO: [🧠][❎] Do here propper M:N mapping
|
|
3525
|
+
* [x] One source can make multiple pieces
|
|
3526
|
+
* [ ] One piece can have multiple sources
|
|
3527
|
+
*/
|
|
3528
|
+
|
|
3529
|
+
/**
|
|
3530
|
+
* Prepares the persona for the pipeline
|
|
3531
|
+
*
|
|
3532
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
3533
|
+
*/
|
|
3534
|
+
function preparePersona(personaDescription, options) {
|
|
3535
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3536
|
+
var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
3537
|
+
var _c;
|
|
3538
|
+
return __generator(this, function (_d) {
|
|
3539
|
+
switch (_d.label) {
|
|
3540
|
+
case 0:
|
|
3541
|
+
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
3542
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
3543
|
+
_b = createPipelineExecutor;
|
|
3544
|
+
_c = {};
|
|
3545
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
|
|
3546
|
+
case 1:
|
|
3547
|
+
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
3548
|
+
_c.tools = {
|
|
3549
|
+
llm: llmTools,
|
|
3550
|
+
},
|
|
3551
|
+
_c)]);
|
|
3552
|
+
return [4 /*yield*/, llmTools.listModels()];
|
|
3553
|
+
case 2:
|
|
3554
|
+
availableModels = _d.sent();
|
|
3555
|
+
availableModelNames = availableModels
|
|
3556
|
+
.filter(function (_a) {
|
|
3557
|
+
var modelVariant = _a.modelVariant;
|
|
3558
|
+
return modelVariant === 'CHAT';
|
|
3559
|
+
})
|
|
3560
|
+
.map(function (_a) {
|
|
3561
|
+
var modelName = _a.modelName;
|
|
3562
|
+
return modelName;
|
|
3563
|
+
})
|
|
3564
|
+
.join(',');
|
|
3565
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
3566
|
+
case 3:
|
|
3567
|
+
result = _d.sent();
|
|
3568
|
+
assertsExecutionSuccessful(result);
|
|
3569
|
+
outputParameters = result.outputParameters;
|
|
3570
|
+
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
3571
|
+
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
3572
|
+
if (isVerbose) {
|
|
3573
|
+
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
3574
|
+
}
|
|
3575
|
+
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
3576
|
+
return [2 /*return*/, {
|
|
3577
|
+
modelVariant: 'CHAT',
|
|
3578
|
+
modelName: modelName,
|
|
3579
|
+
systemMessage: systemMessage,
|
|
3580
|
+
temperature: temperature,
|
|
3581
|
+
}];
|
|
3582
|
+
}
|
|
3583
|
+
});
|
|
3584
|
+
});
|
|
3585
|
+
}
|
|
3586
|
+
/**
|
|
3587
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3588
|
+
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
3589
|
+
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
3590
|
+
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
3591
|
+
*/
|
|
3592
|
+
|
|
3593
|
+
/**
|
|
3594
|
+
* Prepare pipeline from string (markdown) format to JSON format
|
|
3595
|
+
*
|
|
3596
|
+
* Note: This function does not validate logic of the pipeline
|
|
3597
|
+
* Note: This function acts as part of compilation process
|
|
3598
|
+
*/
|
|
3599
|
+
function preparePipeline(pipeline, options) {
|
|
3600
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3601
|
+
var _a, maxParallelCount,
|
|
3602
|
+
/*
|
|
3603
|
+
<- TODO: [🧠][0] `promptbookVersion` */
|
|
3604
|
+
knowledgeSources /*
|
|
3605
|
+
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3606
|
+
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
|
|
3607
|
+
var _this = this;
|
|
3608
|
+
return __generator(this, function (_b) {
|
|
3609
|
+
switch (_b.label) {
|
|
3610
|
+
case 0:
|
|
3611
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3612
|
+
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3613
|
+
currentPreparation = {
|
|
3614
|
+
id: 1,
|
|
3615
|
+
// TODO: [🍥]> date: $currentDate(),
|
|
3616
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
3617
|
+
modelUsage: ZERO_USAGE,
|
|
3618
|
+
};
|
|
3619
|
+
preparations = [
|
|
3620
|
+
// ...preparations
|
|
3621
|
+
// <- TODO: [🧊]
|
|
3622
|
+
currentPreparation,
|
|
3623
|
+
];
|
|
3624
|
+
preparedPersonas = new Array(personas.length);
|
|
3625
|
+
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 () {
|
|
3626
|
+
var modelRequirements, preparedPersona;
|
|
3627
|
+
return __generator(this, function (_a) {
|
|
3628
|
+
switch (_a.label) {
|
|
3629
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
|
|
3630
|
+
case 1:
|
|
3631
|
+
modelRequirements = _a.sent();
|
|
3632
|
+
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
3633
|
+
preparedPersonas[index] = preparedPersona;
|
|
3634
|
+
return [2 /*return*/];
|
|
3635
|
+
}
|
|
3636
|
+
});
|
|
3637
|
+
}); })];
|
|
3638
|
+
case 1:
|
|
3639
|
+
_b.sent();
|
|
3640
|
+
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3641
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
|
|
3642
|
+
case 2:
|
|
3643
|
+
partialknowledgePiecesPrepared = _b.sent();
|
|
3644
|
+
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3645
|
+
// ----- /Knowledge preparation -----
|
|
3646
|
+
// TODO: !!!!! Add context to each template (if missing)
|
|
3647
|
+
// TODO: !!!!! Apply samples to each template (if missing)
|
|
3648
|
+
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3649
|
+
}
|
|
3650
|
+
});
|
|
3651
|
+
});
|
|
3652
|
+
}
|
|
3653
|
+
/**
|
|
3654
|
+
* TODO: !!!!! Index the samples and maybe templates
|
|
3655
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3656
|
+
* TODO: Write tests for `preparePipeline`
|
|
3657
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3658
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3659
|
+
* TODO: [🎐] !!!! Use here countTotalUsage
|
|
3660
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3661
|
+
*/
|
|
3662
|
+
|
|
3663
|
+
/**
|
|
3664
|
+
* Tests if given string is valid URL.
|
|
3665
|
+
*
|
|
3666
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
3667
|
+
*/
|
|
3668
|
+
function isValidFilePath(filePath) {
|
|
3669
|
+
if (typeof filePath !== 'string') {
|
|
3670
|
+
return false;
|
|
3671
|
+
}
|
|
3672
|
+
var filePathSlashes = filePath.split('\\').join('/');
|
|
3673
|
+
// Absolute Unix path: /hello.txt
|
|
3674
|
+
if (/^(\/)/i.test(filePathSlashes)) {
|
|
3675
|
+
return true;
|
|
3676
|
+
}
|
|
3677
|
+
// Absolute Windows path: /hello.txt
|
|
3678
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
3679
|
+
return true;
|
|
3680
|
+
}
|
|
3681
|
+
// Relative path: ./hello.txt
|
|
3682
|
+
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
3683
|
+
return true;
|
|
3684
|
+
}
|
|
3685
|
+
return false;
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3688
|
+
/**
|
|
3689
|
+
* Parses the knowledge command
|
|
3690
|
+
*
|
|
3691
|
+
* @see ./KNOWLEDGE-README.md for more details
|
|
3692
|
+
* @private within the commands folder
|
|
3693
|
+
*/
|
|
3694
|
+
var knowledgeCommandParser = {
|
|
3695
|
+
/**
|
|
3696
|
+
* Name of the command
|
|
3697
|
+
*/
|
|
3698
|
+
name: 'KNOWLEDGE',
|
|
3699
|
+
/**
|
|
3700
|
+
* BOILERPLATE command can be used in:
|
|
3701
|
+
*/
|
|
3702
|
+
usagePlaces: ['PIPELINE_HEAD'],
|
|
3703
|
+
/**
|
|
3704
|
+
* Description of the KNOWLEDGE command
|
|
3705
|
+
*/
|
|
3706
|
+
description: "Tells promptbook which external knowledge to use",
|
|
3707
|
+
/**
|
|
3708
|
+
* Link to discussion
|
|
3709
|
+
*/
|
|
3710
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3711
|
+
/**
|
|
3712
|
+
* Example usages of the KNOWLEDGE command
|
|
3713
|
+
*/
|
|
3714
|
+
examples: [
|
|
3715
|
+
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
3716
|
+
'KNOWLEDGE ./hejny-cv.txt',
|
|
3717
|
+
'KNOWLEDGE ./hejny-cv.md',
|
|
3718
|
+
'KNOWLEDGE ./hejny-cv.pdf',
|
|
3719
|
+
'KNOWLEDGE ./hejny-cv.docx',
|
|
3720
|
+
],
|
|
3721
|
+
/**
|
|
3722
|
+
* Parses the KNOWLEDGE command
|
|
3723
|
+
*/
|
|
3724
|
+
parse: function (input) {
|
|
3725
|
+
var args = input.args;
|
|
3726
|
+
var source = args[0];
|
|
3727
|
+
if (source === undefined) {
|
|
3728
|
+
throw new ParsingError("Source is not defined");
|
|
3729
|
+
}
|
|
3730
|
+
if (source.startsWith('http://')) {
|
|
3731
|
+
throw new ParsingError("Source is not secure");
|
|
3732
|
+
}
|
|
3733
|
+
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
3734
|
+
throw new ParsingError("Source not valid");
|
|
3735
|
+
}
|
|
3736
|
+
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
3737
|
+
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
3738
|
+
}
|
|
3739
|
+
return {
|
|
3740
|
+
type: 'KNOWLEDGE',
|
|
3741
|
+
source: source,
|
|
3742
|
+
};
|
|
3743
|
+
},
|
|
3744
|
+
/**
|
|
3745
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3746
|
+
*/
|
|
3747
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3748
|
+
var source = personaCommand.source;
|
|
3749
|
+
var pipelineJson = subjects.pipelineJson;
|
|
3750
|
+
var name = titleToName(source);
|
|
3751
|
+
pipelineJson.knowledgeSources.push({
|
|
3752
|
+
name: name,
|
|
3753
|
+
source: source,
|
|
3754
|
+
});
|
|
3755
|
+
},
|
|
3756
|
+
};
|
|
3757
|
+
|
|
2741
3758
|
/**
|
|
2742
|
-
*
|
|
3759
|
+
* Parses the persona command
|
|
3760
|
+
*
|
|
3761
|
+
* @see ./PERSONA-README.md for more details
|
|
3762
|
+
* @private within the commands folder
|
|
2743
3763
|
*/
|
|
3764
|
+
var personaCommandParser = {
|
|
3765
|
+
/**
|
|
3766
|
+
* Name of the command
|
|
3767
|
+
*/
|
|
3768
|
+
name: 'PERSONA',
|
|
3769
|
+
/**
|
|
3770
|
+
* Aliases for the PERSONA command
|
|
3771
|
+
*/
|
|
3772
|
+
aliasNames: ['PERSON'],
|
|
3773
|
+
/**
|
|
3774
|
+
* PERSONA command can be used in:
|
|
3775
|
+
*/
|
|
3776
|
+
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3777
|
+
/**
|
|
3778
|
+
* Description of the PERSONA command
|
|
3779
|
+
*/
|
|
3780
|
+
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
3781
|
+
/**
|
|
3782
|
+
* Link to discussion
|
|
3783
|
+
*/
|
|
3784
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3785
|
+
/**
|
|
3786
|
+
* Example usages of the PERSONA command
|
|
3787
|
+
*/
|
|
3788
|
+
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
3789
|
+
/**
|
|
3790
|
+
* Parses the PERSONA command
|
|
3791
|
+
*/
|
|
3792
|
+
parse: function (input) {
|
|
3793
|
+
var rawArgs = input.rawArgs;
|
|
3794
|
+
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
3795
|
+
var personaName = (personaNameRaw || '').trim();
|
|
3796
|
+
if (personaName === '') {
|
|
3797
|
+
throw new ParsingError("You must set name for the persona");
|
|
3798
|
+
}
|
|
3799
|
+
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
3800
|
+
if (personaDescription === '') {
|
|
3801
|
+
personaDescription = null;
|
|
3802
|
+
}
|
|
3803
|
+
return {
|
|
3804
|
+
type: 'PERSONA',
|
|
3805
|
+
personaName: personaName,
|
|
3806
|
+
personaDescription: personaDescription,
|
|
3807
|
+
};
|
|
3808
|
+
},
|
|
3809
|
+
/**
|
|
3810
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3811
|
+
*/
|
|
3812
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3813
|
+
var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
|
|
3814
|
+
var pipelineJson = subjects.pipelineJson, templateJson = subjects.templateJson;
|
|
3815
|
+
if (templateJson !== null) {
|
|
3816
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
3817
|
+
throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
|
|
3818
|
+
}
|
|
3819
|
+
templateJson.personaName = personaName;
|
|
3820
|
+
}
|
|
3821
|
+
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
3822
|
+
if (persona === undefined) {
|
|
3823
|
+
pipelineJson.personas.push({
|
|
3824
|
+
name: personaName,
|
|
3825
|
+
description: personaDescription || '',
|
|
3826
|
+
});
|
|
3827
|
+
return;
|
|
3828
|
+
}
|
|
3829
|
+
if (persona.description === personaDescription) {
|
|
3830
|
+
return;
|
|
3831
|
+
}
|
|
3832
|
+
if (personaDescription === null) {
|
|
3833
|
+
return;
|
|
3834
|
+
}
|
|
3835
|
+
if (persona.description === '') {
|
|
3836
|
+
persona.description = personaDescription;
|
|
3837
|
+
return;
|
|
3838
|
+
}
|
|
3839
|
+
console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
|
|
3840
|
+
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
3841
|
+
},
|
|
3842
|
+
};
|
|
2744
3843
|
|
|
2745
3844
|
/**
|
|
2746
3845
|
* Removes Markdown formatting tags from a string.
|
|
@@ -2860,7 +3959,7 @@ var blockCommandParser = {
|
|
|
2860
3959
|
/**
|
|
2861
3960
|
* Link to discussion
|
|
2862
3961
|
*/
|
|
2863
|
-
|
|
3962
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
|
|
2864
3963
|
/**
|
|
2865
3964
|
* Example usages of the BLOCK command
|
|
2866
3965
|
*/
|
|
@@ -2880,7 +3979,7 @@ var blockCommandParser = {
|
|
|
2880
3979
|
'Knowledge BLOCK',
|
|
2881
3980
|
// 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
|
|
2882
3981
|
//---
|
|
2883
|
-
/*
|
|
3982
|
+
/* Note: Not implemented block types will be in examples in future -> */
|
|
2884
3983
|
'Instrument BLOCK',
|
|
2885
3984
|
// 'Instrument', // <- Note: [⛱]
|
|
2886
3985
|
'Action BLOCK',
|
|
@@ -2888,6 +3987,7 @@ var blockCommandParser = {
|
|
|
2888
3987
|
//---
|
|
2889
3988
|
/* <- TODO: [🧠] Maybe dynamic */
|
|
2890
3989
|
],
|
|
3990
|
+
// TODO: [♓️] order: -10 /* <- Note: Putting before other commands */
|
|
2891
3991
|
/**
|
|
2892
3992
|
* Parses the BLOCK command
|
|
2893
3993
|
*/
|
|
@@ -2896,19 +3996,19 @@ var blockCommandParser = {
|
|
|
2896
3996
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
2897
3997
|
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
2898
3998
|
if (blockTypes.length !== 1) {
|
|
2899
|
-
// console.log('!!!', { blockType });
|
|
2900
3999
|
throw new ParsingError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
|
|
2901
4000
|
}
|
|
2902
|
-
|
|
4001
|
+
var blockType = blockTypes[0];
|
|
2903
4002
|
return {
|
|
2904
4003
|
type: 'BLOCK',
|
|
2905
|
-
blockType:
|
|
4004
|
+
blockType: blockType,
|
|
2906
4005
|
};
|
|
2907
4006
|
},
|
|
2908
4007
|
};
|
|
2909
4008
|
|
|
2910
4009
|
/**
|
|
2911
4010
|
* Units of text measurement
|
|
4011
|
+
* @see https://github.com/webgptorg/promptbook/discussions/30
|
|
2912
4012
|
*/
|
|
2913
4013
|
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2914
4014
|
/**
|
|
@@ -3004,7 +4104,7 @@ var expectCommandParser = {
|
|
|
3004
4104
|
/**
|
|
3005
4105
|
* Link to discussion
|
|
3006
4106
|
*/
|
|
3007
|
-
|
|
4107
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
|
|
3008
4108
|
/**
|
|
3009
4109
|
* Example usages of the EXPECT command
|
|
3010
4110
|
*/
|
|
@@ -3122,7 +4222,7 @@ var jokerCommandParser = {
|
|
|
3122
4222
|
/**
|
|
3123
4223
|
* Link to discussion
|
|
3124
4224
|
*/
|
|
3125
|
-
|
|
4225
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
|
|
3126
4226
|
/**
|
|
3127
4227
|
* Example usages of the JOKER command
|
|
3128
4228
|
*/
|
|
@@ -3145,94 +4245,11 @@ var jokerCommandParser = {
|
|
|
3145
4245
|
};
|
|
3146
4246
|
|
|
3147
4247
|
/**
|
|
3148
|
-
*
|
|
3149
|
-
*
|
|
3150
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
3151
|
-
*/
|
|
3152
|
-
function isValidFilePath(filePath) {
|
|
3153
|
-
if (typeof filePath !== 'string') {
|
|
3154
|
-
return false;
|
|
3155
|
-
}
|
|
3156
|
-
var filePathSlashes = filePath.split('\\').join('/');
|
|
3157
|
-
// Absolute Unix path: /hello.txt
|
|
3158
|
-
if (/^(\/)/i.test(filePathSlashes)) {
|
|
3159
|
-
return true;
|
|
3160
|
-
}
|
|
3161
|
-
// Absolute Windows path: /hello.txt
|
|
3162
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
3163
|
-
return true;
|
|
3164
|
-
}
|
|
3165
|
-
// Relative path: ./hello.txt
|
|
3166
|
-
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
3167
|
-
return true;
|
|
3168
|
-
}
|
|
3169
|
-
return false;
|
|
3170
|
-
}
|
|
3171
|
-
|
|
3172
|
-
/**
|
|
3173
|
-
* Parses the knowledge command
|
|
4248
|
+
* @@@
|
|
3174
4249
|
*
|
|
3175
|
-
* @
|
|
3176
|
-
* @private within the commands folder
|
|
4250
|
+
* @private for `ModelVariant` and `modelCommandParser`
|
|
3177
4251
|
*/
|
|
3178
|
-
var knowledgeCommandParser = {
|
|
3179
|
-
/**
|
|
3180
|
-
* Name of the command
|
|
3181
|
-
*/
|
|
3182
|
-
name: 'KNOWLEDGE',
|
|
3183
|
-
/**
|
|
3184
|
-
* BOILERPLATE command can be used in:
|
|
3185
|
-
*/
|
|
3186
|
-
usagePlaces: ['PIPELINE_HEAD'],
|
|
3187
|
-
/**
|
|
3188
|
-
* Description of the KNOWLEDGE command
|
|
3189
|
-
*/
|
|
3190
|
-
description: "Tells promptbook which external knowledge to use",
|
|
3191
|
-
/**
|
|
3192
|
-
* Link to discussion
|
|
3193
|
-
*/
|
|
3194
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3195
|
-
/**
|
|
3196
|
-
* Example usages of the KNOWLEDGE command
|
|
3197
|
-
*/
|
|
3198
|
-
examples: [
|
|
3199
|
-
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
3200
|
-
'KNOWLEDGE ./hejny-cv.txt',
|
|
3201
|
-
'KNOWLEDGE ./hejny-cv.md',
|
|
3202
|
-
'KNOWLEDGE ./hejny-cv.pdf',
|
|
3203
|
-
'KNOWLEDGE ./hejny-cv.docx',
|
|
3204
|
-
],
|
|
3205
|
-
/**
|
|
3206
|
-
* Parses the KNOWLEDGE command
|
|
3207
|
-
*/
|
|
3208
|
-
parse: function (input) {
|
|
3209
|
-
var args = input.args;
|
|
3210
|
-
var source = args[0];
|
|
3211
|
-
if (source === undefined) {
|
|
3212
|
-
throw new ParsingError("Source is not defined");
|
|
3213
|
-
}
|
|
3214
|
-
if (source.startsWith('http://')) {
|
|
3215
|
-
throw new ParsingError("Source is not secure");
|
|
3216
|
-
}
|
|
3217
|
-
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
3218
|
-
throw new ParsingError("Source not valid");
|
|
3219
|
-
}
|
|
3220
|
-
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
3221
|
-
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
3222
|
-
}
|
|
3223
|
-
return {
|
|
3224
|
-
type: 'KNOWLEDGE',
|
|
3225
|
-
source: source,
|
|
3226
|
-
};
|
|
3227
|
-
},
|
|
3228
|
-
};
|
|
3229
|
-
|
|
3230
4252
|
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
3231
|
-
/**
|
|
3232
|
-
* TODO: Maybe figure out better word than "variant"
|
|
3233
|
-
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
3234
|
-
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
3235
|
-
*/
|
|
3236
4253
|
|
|
3237
4254
|
/**
|
|
3238
4255
|
* Parses the model command
|
|
@@ -3248,7 +4265,11 @@ var modelCommandParser = {
|
|
|
3248
4265
|
/**
|
|
3249
4266
|
* BOILERPLATE command can be used in:
|
|
3250
4267
|
*/
|
|
3251
|
-
usagePlaces: [
|
|
4268
|
+
usagePlaces: [
|
|
4269
|
+
'PIPELINE_HEAD',
|
|
4270
|
+
// <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
|
|
4271
|
+
'PIPELINE_TEMPLATE',
|
|
4272
|
+
],
|
|
3252
4273
|
/**
|
|
3253
4274
|
* Description of the MODEL command
|
|
3254
4275
|
*/
|
|
@@ -3256,7 +4277,7 @@ var modelCommandParser = {
|
|
|
3256
4277
|
/**
|
|
3257
4278
|
* Link to discussion
|
|
3258
4279
|
*/
|
|
3259
|
-
|
|
4280
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
|
|
3260
4281
|
/**
|
|
3261
4282
|
* Example usages of the MODEL command
|
|
3262
4283
|
*/
|
|
@@ -3336,7 +4357,7 @@ var parameterCommandParser = {
|
|
|
3336
4357
|
/**
|
|
3337
4358
|
* Link to discussion
|
|
3338
4359
|
*/
|
|
3339
|
-
|
|
4360
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/68',
|
|
3340
4361
|
/**
|
|
3341
4362
|
* Example usages of the PARAMETER command
|
|
3342
4363
|
*/
|
|
@@ -3370,59 +4391,6 @@ var parameterCommandParser = {
|
|
|
3370
4391
|
},
|
|
3371
4392
|
};
|
|
3372
4393
|
|
|
3373
|
-
/**
|
|
3374
|
-
* Parses the persona command
|
|
3375
|
-
*
|
|
3376
|
-
* @see ./PERSONA-README.md for more details
|
|
3377
|
-
* @private within the commands folder
|
|
3378
|
-
*/
|
|
3379
|
-
var personaCommandParser = {
|
|
3380
|
-
/**
|
|
3381
|
-
* Name of the command
|
|
3382
|
-
*/
|
|
3383
|
-
name: 'PERSONA',
|
|
3384
|
-
/**
|
|
3385
|
-
* Aliases for the PERSONA command
|
|
3386
|
-
*/
|
|
3387
|
-
aliasNames: ['PERSON'],
|
|
3388
|
-
/**
|
|
3389
|
-
* PERSONA command can be used in:
|
|
3390
|
-
*/
|
|
3391
|
-
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3392
|
-
/**
|
|
3393
|
-
* Description of the PERSONA command
|
|
3394
|
-
*/
|
|
3395
|
-
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
3396
|
-
/**
|
|
3397
|
-
* Link to discussion
|
|
3398
|
-
*/
|
|
3399
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3400
|
-
/**
|
|
3401
|
-
* Example usages of the PERSONA command
|
|
3402
|
-
*/
|
|
3403
|
-
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
3404
|
-
/**
|
|
3405
|
-
* Parses the PERSONA command
|
|
3406
|
-
*/
|
|
3407
|
-
parse: function (input) {
|
|
3408
|
-
var rawArgs = input.rawArgs;
|
|
3409
|
-
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
3410
|
-
var personaName = (personaNameRaw || '').trim();
|
|
3411
|
-
if (personaName === '') {
|
|
3412
|
-
throw new ParsingError("You must set name for the persona");
|
|
3413
|
-
}
|
|
3414
|
-
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
3415
|
-
if (personaDescription === '') {
|
|
3416
|
-
personaDescription = null;
|
|
3417
|
-
}
|
|
3418
|
-
return {
|
|
3419
|
-
type: 'PERSONA',
|
|
3420
|
-
personaName: personaName,
|
|
3421
|
-
personaDescription: personaDescription,
|
|
3422
|
-
};
|
|
3423
|
-
},
|
|
3424
|
-
};
|
|
3425
|
-
|
|
3426
4394
|
function isValidJavascriptName(javascriptName) {
|
|
3427
4395
|
if (typeof javascriptName !== 'string') {
|
|
3428
4396
|
return false;
|
|
@@ -3453,7 +4421,7 @@ var postprocessCommandParser = {
|
|
|
3453
4421
|
/**
|
|
3454
4422
|
* Link to discussion
|
|
3455
4423
|
*/
|
|
3456
|
-
|
|
4424
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/31',
|
|
3457
4425
|
/**
|
|
3458
4426
|
* Example usages of the POSTPROCESS command
|
|
3459
4427
|
*/
|
|
@@ -3508,7 +4476,7 @@ var promptbookVersionCommandParser = {
|
|
|
3508
4476
|
/**
|
|
3509
4477
|
* Link to discussion
|
|
3510
4478
|
*/
|
|
3511
|
-
|
|
4479
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/69',
|
|
3512
4480
|
/**
|
|
3513
4481
|
* Example usages of the PROMPTBOOK_VERSION command
|
|
3514
4482
|
*/
|
|
@@ -3561,7 +4529,7 @@ var urlCommandParser = {
|
|
|
3561
4529
|
/**
|
|
3562
4530
|
* Link to discussion
|
|
3563
4531
|
*/
|
|
3564
|
-
|
|
4532
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/70',
|
|
3565
4533
|
/**
|
|
3566
4534
|
* Example usages of the URL command
|
|
3567
4535
|
*/
|
|
@@ -3609,22 +4577,6 @@ var urlCommandParser = {
|
|
|
3609
4577
|
},
|
|
3610
4578
|
};
|
|
3611
4579
|
|
|
3612
|
-
/**
|
|
3613
|
-
* Returns the same value that is passed as argument.
|
|
3614
|
-
* No side effects.
|
|
3615
|
-
*
|
|
3616
|
-
* Note: It can be usefull for leveling indentation
|
|
3617
|
-
*
|
|
3618
|
-
* @param value any values
|
|
3619
|
-
* @returns the same values
|
|
3620
|
-
*/
|
|
3621
|
-
function just(value) {
|
|
3622
|
-
if (value === undefined) {
|
|
3623
|
-
return undefined;
|
|
3624
|
-
}
|
|
3625
|
-
return value;
|
|
3626
|
-
}
|
|
3627
|
-
|
|
3628
4580
|
/**
|
|
3629
4581
|
* Parses the action command
|
|
3630
4582
|
*
|
|
@@ -3647,7 +4599,7 @@ var actionCommandParser = {
|
|
|
3647
4599
|
/**
|
|
3648
4600
|
* Link to discussion
|
|
3649
4601
|
*/
|
|
3650
|
-
|
|
4602
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/72',
|
|
3651
4603
|
/**
|
|
3652
4604
|
* Example usages of the ACTION command
|
|
3653
4605
|
*/
|
|
@@ -3656,7 +4608,8 @@ var actionCommandParser = {
|
|
|
3656
4608
|
* Parses the ACTION command
|
|
3657
4609
|
*/
|
|
3658
4610
|
parse: function (input) {
|
|
3659
|
-
input.args;
|
|
4611
|
+
var args = input.args;
|
|
4612
|
+
TODO_USE(args);
|
|
3660
4613
|
return {
|
|
3661
4614
|
type: 'ACTION',
|
|
3662
4615
|
};
|
|
@@ -3685,7 +4638,7 @@ var instrumentCommandParser = {
|
|
|
3685
4638
|
/**
|
|
3686
4639
|
* Link to discussion
|
|
3687
4640
|
*/
|
|
3688
|
-
|
|
4641
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/71',
|
|
3689
4642
|
/**
|
|
3690
4643
|
* Example usages of the INSTRUMENT command
|
|
3691
4644
|
*/
|
|
@@ -3694,7 +4647,8 @@ var instrumentCommandParser = {
|
|
|
3694
4647
|
* Parses the INSTRUMENT command
|
|
3695
4648
|
*/
|
|
3696
4649
|
parse: function (input) {
|
|
3697
|
-
input.args;
|
|
4650
|
+
var args = input.args;
|
|
4651
|
+
TODO_USE(args);
|
|
3698
4652
|
return {
|
|
3699
4653
|
type: 'INSTRUMENT',
|
|
3700
4654
|
};
|
|
@@ -3727,7 +4681,7 @@ var boilerplateCommandParser = {
|
|
|
3727
4681
|
/**
|
|
3728
4682
|
* Link to discussion
|
|
3729
4683
|
*/
|
|
3730
|
-
|
|
4684
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
3731
4685
|
/**
|
|
3732
4686
|
* Example usages of the BOILERPLATE command
|
|
3733
4687
|
*/
|
|
@@ -3752,6 +4706,7 @@ var boilerplateCommandParser = {
|
|
|
3752
4706
|
};
|
|
3753
4707
|
/**
|
|
3754
4708
|
* TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
|
|
4709
|
+
* Note: [⚪] This should never be in any released package
|
|
3755
4710
|
*/
|
|
3756
4711
|
|
|
3757
4712
|
/**
|
|
@@ -3770,7 +4725,7 @@ var COMMANDS = [
|
|
|
3770
4725
|
actionCommandParser,
|
|
3771
4726
|
instrumentCommandParser,
|
|
3772
4727
|
personaCommandParser,
|
|
3773
|
-
boilerplateCommandParser, // <- TODO:
|
|
4728
|
+
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
3774
4729
|
];
|
|
3775
4730
|
|
|
3776
4731
|
/**
|
|
@@ -3856,18 +4811,18 @@ function parseCommand(raw, usagePlace) {
|
|
|
3856
4811
|
}));
|
|
3857
4812
|
}
|
|
3858
4813
|
/**
|
|
3859
|
-
*
|
|
4814
|
+
* @@@
|
|
3860
4815
|
*/
|
|
3861
4816
|
function getSupportedCommandsMessage() {
|
|
3862
4817
|
return COMMANDS.flatMap(function (_a) {
|
|
3863
|
-
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description,
|
|
4818
|
+
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
|
|
3864
4819
|
return __spreadArray([
|
|
3865
|
-
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(
|
|
4820
|
+
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
|
|
3866
4821
|
], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
|
|
3867
4822
|
}).join('\n');
|
|
3868
4823
|
}
|
|
3869
4824
|
/**
|
|
3870
|
-
*
|
|
4825
|
+
* @@@
|
|
3871
4826
|
*/
|
|
3872
4827
|
function parseCommandVariant(input) {
|
|
3873
4828
|
var e_1, _a;
|
|
@@ -3876,7 +4831,6 @@ function parseCommandVariant(input) {
|
|
|
3876
4831
|
var _loop_1 = function (commandParser) {
|
|
3877
4832
|
var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
|
|
3878
4833
|
var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
|
|
3879
|
-
// console.log('!!!', { commandName, names });
|
|
3880
4834
|
if (names.includes(commandName)) {
|
|
3881
4835
|
try {
|
|
3882
4836
|
return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
|
|
@@ -3986,25 +4940,42 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
3986
4940
|
var e_1, _a;
|
|
3987
4941
|
var codeBlocks = [];
|
|
3988
4942
|
var lines = markdown.split('\n');
|
|
4943
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
4944
|
+
lines.push('');
|
|
3989
4945
|
var currentCodeBlock = null;
|
|
3990
4946
|
try {
|
|
3991
4947
|
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
3992
4948
|
var line = lines_1_1.value;
|
|
4949
|
+
if (line.startsWith('> ') || line === '>') {
|
|
4950
|
+
if (currentCodeBlock === null) {
|
|
4951
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
4952
|
+
} /* not else */
|
|
4953
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
4954
|
+
if (currentCodeBlock.content !== '') {
|
|
4955
|
+
currentCodeBlock.content += '\n';
|
|
4956
|
+
}
|
|
4957
|
+
currentCodeBlock.content += line.slice(2);
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4960
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
4961
|
+
codeBlocks.push(currentCodeBlock);
|
|
4962
|
+
currentCodeBlock = null;
|
|
4963
|
+
}
|
|
4964
|
+
/* not else */
|
|
3993
4965
|
if (line.startsWith('```')) {
|
|
3994
4966
|
var language = line.slice(3).trim() || null;
|
|
3995
4967
|
if (currentCodeBlock === null) {
|
|
3996
|
-
currentCodeBlock = { language: language, content: '' };
|
|
4968
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
3997
4969
|
}
|
|
3998
4970
|
else {
|
|
3999
4971
|
if (language !== null) {
|
|
4000
|
-
|
|
4001
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4972
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4002
4973
|
}
|
|
4003
4974
|
codeBlocks.push(currentCodeBlock);
|
|
4004
4975
|
currentCodeBlock = null;
|
|
4005
4976
|
}
|
|
4006
4977
|
}
|
|
4007
|
-
else if (currentCodeBlock !== null) {
|
|
4978
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
4008
4979
|
if (currentCodeBlock.content !== '') {
|
|
4009
4980
|
currentCodeBlock.content += '\n';
|
|
4010
4981
|
}
|
|
@@ -4020,11 +4991,13 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4020
4991
|
finally { if (e_1) throw e_1.error; }
|
|
4021
4992
|
}
|
|
4022
4993
|
if (currentCodeBlock !== null) {
|
|
4023
|
-
|
|
4024
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4994
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4025
4995
|
}
|
|
4026
4996
|
return codeBlocks;
|
|
4027
4997
|
}
|
|
4998
|
+
/**
|
|
4999
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
5000
|
+
*/
|
|
4028
5001
|
|
|
4029
5002
|
/**
|
|
4030
5003
|
* Extracts exactly ONE code block from markdown.
|
|
@@ -4042,13 +5015,12 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4042
5015
|
function extractOneBlockFromMarkdown(markdown) {
|
|
4043
5016
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
4044
5017
|
if (codeBlocks.length !== 1) {
|
|
4045
|
-
|
|
4046
|
-
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
5018
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
4047
5019
|
}
|
|
4048
5020
|
return codeBlocks[0];
|
|
4049
5021
|
}
|
|
4050
5022
|
/***
|
|
4051
|
-
* TODO: [🍓][🌻]
|
|
5023
|
+
* TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
|
|
4052
5024
|
*/
|
|
4053
5025
|
|
|
4054
5026
|
/**
|
|
@@ -4058,13 +5030,13 @@ function parseMarkdownSection(value) {
|
|
|
4058
5030
|
var _a, _b;
|
|
4059
5031
|
var lines = value.split('\n');
|
|
4060
5032
|
if (!lines[0].startsWith('#')) {
|
|
4061
|
-
throw new
|
|
5033
|
+
throw new ParsingError('Markdown section must start with heading');
|
|
4062
5034
|
}
|
|
4063
5035
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
4064
5036
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
4065
5037
|
var content = spaceTrim(lines.slice(1).join('\n'));
|
|
4066
5038
|
if (level < 1 || level > 6) {
|
|
4067
|
-
throw new
|
|
5039
|
+
throw new ParsingError('Markdown section must have heading level between 1 and 6');
|
|
4068
5040
|
}
|
|
4069
5041
|
return { title: title, level: level, content: content };
|
|
4070
5042
|
}
|
|
@@ -4201,203 +5173,14 @@ function removeContentComments(content) {
|
|
|
4201
5173
|
}
|
|
4202
5174
|
|
|
4203
5175
|
/**
|
|
4204
|
-
*
|
|
4205
|
-
*
|
|
4206
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
4207
|
-
*/
|
|
4208
|
-
function difference(a, b, isEqual) {
|
|
4209
|
-
var e_1, _a;
|
|
4210
|
-
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
4211
|
-
var diff = new Set();
|
|
4212
|
-
var _loop_1 = function (itemA) {
|
|
4213
|
-
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
4214
|
-
diff.add(itemA);
|
|
4215
|
-
}
|
|
4216
|
-
};
|
|
4217
|
-
try {
|
|
4218
|
-
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
4219
|
-
var itemA = _c.value;
|
|
4220
|
-
_loop_1(itemA);
|
|
4221
|
-
}
|
|
4222
|
-
}
|
|
4223
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4224
|
-
finally {
|
|
4225
|
-
try {
|
|
4226
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4227
|
-
}
|
|
4228
|
-
finally { if (e_1) throw e_1.error; }
|
|
4229
|
-
}
|
|
4230
|
-
return diff;
|
|
4231
|
-
}
|
|
4232
|
-
|
|
4233
|
-
/**
|
|
4234
|
-
* Creates a new set with all elements that are present in either set
|
|
4235
|
-
*
|
|
4236
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
4237
|
-
*/
|
|
4238
|
-
function union() {
|
|
4239
|
-
var e_1, _a, e_2, _b;
|
|
4240
|
-
var sets = [];
|
|
4241
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4242
|
-
sets[_i] = arguments[_i];
|
|
4243
|
-
}
|
|
4244
|
-
var union = new Set();
|
|
4245
|
-
try {
|
|
4246
|
-
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
4247
|
-
var set = sets_1_1.value;
|
|
4248
|
-
try {
|
|
4249
|
-
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4250
|
-
var item = _d.value;
|
|
4251
|
-
union.add(item);
|
|
4252
|
-
}
|
|
4253
|
-
}
|
|
4254
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4255
|
-
finally {
|
|
4256
|
-
try {
|
|
4257
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
4258
|
-
}
|
|
4259
|
-
finally { if (e_2) throw e_2.error; }
|
|
4260
|
-
}
|
|
4261
|
-
}
|
|
4262
|
-
}
|
|
4263
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4264
|
-
finally {
|
|
4265
|
-
try {
|
|
4266
|
-
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
4267
|
-
}
|
|
4268
|
-
finally { if (e_1) throw e_1.error; }
|
|
4269
|
-
}
|
|
4270
|
-
return union;
|
|
4271
|
-
}
|
|
4272
|
-
|
|
4273
|
-
/**
|
|
4274
|
-
* Parses the template and returns the list of all parameter names
|
|
4275
|
-
*
|
|
4276
|
-
* @param template the template with parameters in {curly} braces
|
|
4277
|
-
* @returns the list of parameter names
|
|
4278
|
-
*/
|
|
4279
|
-
function extractParameters(template) {
|
|
4280
|
-
var e_1, _a;
|
|
4281
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
4282
|
-
var parameterNames = new Set();
|
|
4283
|
-
try {
|
|
4284
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
4285
|
-
var match = matches_1_1.value;
|
|
4286
|
-
var parameterName = match[0].slice(1, -1);
|
|
4287
|
-
parameterNames.add(parameterName);
|
|
4288
|
-
}
|
|
4289
|
-
}
|
|
4290
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4291
|
-
finally {
|
|
4292
|
-
try {
|
|
4293
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
4294
|
-
}
|
|
4295
|
-
finally { if (e_1) throw e_1.error; }
|
|
4296
|
-
}
|
|
4297
|
-
return parameterNames;
|
|
4298
|
-
}
|
|
4299
|
-
|
|
4300
|
-
/**
|
|
4301
|
-
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4302
|
-
*
|
|
4303
|
-
* @param script from which to extract the variables
|
|
4304
|
-
* @returns the list of variable names
|
|
4305
|
-
* @throws {ParsingError} if the script is invalid
|
|
4306
|
-
*/
|
|
4307
|
-
function extractVariables(script) {
|
|
4308
|
-
var variables = new Set();
|
|
4309
|
-
script = "(()=>{".concat(script, "})()");
|
|
4310
|
-
try {
|
|
4311
|
-
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
4312
|
-
try {
|
|
4313
|
-
eval(script);
|
|
4314
|
-
}
|
|
4315
|
-
catch (error) {
|
|
4316
|
-
if (!(error instanceof ReferenceError)) {
|
|
4317
|
-
throw error;
|
|
4318
|
-
}
|
|
4319
|
-
var undefinedName = error.message.split(' ')[0];
|
|
4320
|
-
/*
|
|
4321
|
-
Note: Parsing the error
|
|
4322
|
-
[ReferenceError: thing is not defined]
|
|
4323
|
-
*/
|
|
4324
|
-
if (!undefinedName) {
|
|
4325
|
-
throw error;
|
|
4326
|
-
}
|
|
4327
|
-
if (script.includes(undefinedName + '(')) {
|
|
4328
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
4329
|
-
}
|
|
4330
|
-
else {
|
|
4331
|
-
variables.add(undefinedName);
|
|
4332
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
4333
|
-
}
|
|
4334
|
-
}
|
|
4335
|
-
}
|
|
4336
|
-
catch (error) {
|
|
4337
|
-
if (!(error instanceof Error)) {
|
|
4338
|
-
throw error;
|
|
4339
|
-
}
|
|
4340
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
4341
|
-
}
|
|
4342
|
-
return variables;
|
|
4343
|
-
}
|
|
4344
|
-
/**
|
|
4345
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
4346
|
-
*/
|
|
4347
|
-
|
|
4348
|
-
/**
|
|
4349
|
-
* Parses the prompt template and returns the set of all used parameters
|
|
4350
|
-
*
|
|
4351
|
-
* @param promptTemplate the template with used parameters
|
|
4352
|
-
* @returns the set of parameter names
|
|
4353
|
-
* @throws {ParsingError} if the script is invalid
|
|
4354
|
-
*/
|
|
4355
|
-
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
4356
|
-
var e_1, _a, e_2, _b;
|
|
4357
|
-
var parameterNames = new Set();
|
|
4358
|
-
try {
|
|
4359
|
-
for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4360
|
-
var parameterName = _d.value;
|
|
4361
|
-
parameterNames.add(parameterName);
|
|
4362
|
-
}
|
|
4363
|
-
}
|
|
4364
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4365
|
-
finally {
|
|
4366
|
-
try {
|
|
4367
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
4368
|
-
}
|
|
4369
|
-
finally { if (e_1) throw e_1.error; }
|
|
4370
|
-
}
|
|
4371
|
-
if (promptTemplate.blockType === 'SCRIPT') {
|
|
4372
|
-
try {
|
|
4373
|
-
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
4374
|
-
var parameterName = _f.value;
|
|
4375
|
-
parameterNames.add(parameterName);
|
|
4376
|
-
}
|
|
4377
|
-
}
|
|
4378
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4379
|
-
finally {
|
|
4380
|
-
try {
|
|
4381
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
4382
|
-
}
|
|
4383
|
-
finally { if (e_2) throw e_2.error; }
|
|
4384
|
-
}
|
|
4385
|
-
}
|
|
4386
|
-
return parameterNames;
|
|
4387
|
-
}
|
|
4388
|
-
/**
|
|
4389
|
-
* TODO: [🔣] If script require contentLanguage
|
|
4390
|
-
*/
|
|
4391
|
-
|
|
4392
|
-
/**
|
|
4393
|
-
* Compile promptbook from string (markdown) format to JSON format synchronously
|
|
5176
|
+
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4394
5177
|
*
|
|
4395
|
-
* Note: There are
|
|
5178
|
+
* Note: There are 3 similar functions:
|
|
4396
5179
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4397
5180
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5181
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4398
5182
|
*
|
|
4399
5183
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4400
|
-
* @param options - Options and tools for the compilation
|
|
4401
5184
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
4402
5185
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
4403
5186
|
*
|
|
@@ -4413,7 +5196,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4413
5196
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
4414
5197
|
parameters: [],
|
|
4415
5198
|
promptTemplates: [],
|
|
4416
|
-
|
|
5199
|
+
knowledgeSources: [],
|
|
5200
|
+
knowledgePieces: [],
|
|
5201
|
+
personas: [],
|
|
5202
|
+
preparations: [],
|
|
4417
5203
|
};
|
|
4418
5204
|
// =============================================================
|
|
4419
5205
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
@@ -4443,7 +5229,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4443
5229
|
existingParameter.description &&
|
|
4444
5230
|
existingParameter.description !== parameterDescription &&
|
|
4445
5231
|
parameterDescription) {
|
|
4446
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description
|
|
5232
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
4447
5233
|
}
|
|
4448
5234
|
if (existingParameter) {
|
|
4449
5235
|
if (parameterDescription) {
|
|
@@ -4462,11 +5248,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4462
5248
|
// =============================================================
|
|
4463
5249
|
// Note: 3️⃣ Process pipeline head
|
|
4464
5250
|
pipelineJson.title = pipelineHead.title;
|
|
4465
|
-
// TODO: [1] DRY description
|
|
5251
|
+
// TODO: [🎾][1] DRY description
|
|
4466
5252
|
var description = pipelineHead.content;
|
|
4467
|
-
// Note: Remove codeblocks - TODO:
|
|
5253
|
+
// Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
|
|
4468
5254
|
description = description.split(/^```.*^```/gms).join('');
|
|
4469
|
-
|
|
5255
|
+
description = description.split(/^>.*$/gm).join('');
|
|
5256
|
+
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
4470
5257
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4471
5258
|
description = spaceTrim$1(description);
|
|
4472
5259
|
if (description === '') {
|
|
@@ -4494,7 +5281,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4494
5281
|
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
4495
5282
|
break;
|
|
4496
5283
|
case 'KNOWLEDGE':
|
|
4497
|
-
|
|
5284
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
4498
5285
|
break;
|
|
4499
5286
|
case 'ACTION':
|
|
4500
5287
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
@@ -4503,7 +5290,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4503
5290
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4504
5291
|
break;
|
|
4505
5292
|
case 'PERSONA':
|
|
4506
|
-
|
|
5293
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5294
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4507
5295
|
break;
|
|
4508
5296
|
case 'BOILERPLATE':
|
|
4509
5297
|
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
@@ -4526,29 +5314,83 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4526
5314
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
4527
5315
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
4528
5316
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
4529
|
-
var
|
|
4530
|
-
var
|
|
4531
|
-
var
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
5317
|
+
var lastLine = section.content.split('\n').pop();
|
|
5318
|
+
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
5319
|
+
var resultingParameterName = null;
|
|
5320
|
+
if (resultingParameterNameMatch &&
|
|
5321
|
+
resultingParameterNameMatch.groups !== undefined &&
|
|
5322
|
+
resultingParameterNameMatch.groups.resultingParamName !== undefined) {
|
|
5323
|
+
resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
|
|
5324
|
+
}
|
|
5325
|
+
var expectResultingParameterName = function () {
|
|
5326
|
+
if (resultingParameterName !== null) {
|
|
5327
|
+
return resultingParameterName;
|
|
5328
|
+
}
|
|
5329
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
5330
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
5331
|
+
section.content
|
|
5332
|
+
.split('\n')
|
|
5333
|
+
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
5334
|
+
.join('\n')), "\n "); }));
|
|
5335
|
+
};
|
|
5336
|
+
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
5337
|
+
// TODO: [🎾][1] DRY description
|
|
5338
|
+
var description_1 = section.content;
|
|
5339
|
+
// Note: Remove codeblocks - TODO: [🎾]
|
|
5340
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
5341
|
+
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5342
|
+
//Note: Remove lists and return statement - TODO: [🎾]
|
|
5343
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5344
|
+
description_1 = spaceTrim$1(description_1);
|
|
5345
|
+
if (description_1 === '') {
|
|
5346
|
+
description_1 = undefined;
|
|
5347
|
+
}
|
|
5348
|
+
var templateJson = {
|
|
5349
|
+
blockType: 'PROMPT_TEMPLATE',
|
|
5350
|
+
name: titleToName(section.title),
|
|
5351
|
+
title: section.title,
|
|
5352
|
+
description: description_1,
|
|
5353
|
+
modelRequirements: templateModelRequirements,
|
|
5354
|
+
content: content,
|
|
5355
|
+
};
|
|
5356
|
+
/**
|
|
5357
|
+
* This is nessesary because block type can be
|
|
5358
|
+
* - Set zero times, so anticipate 'PROMPT_TEMPLATE'
|
|
5359
|
+
* - Set one time
|
|
5360
|
+
* - Set more times - throw error
|
|
5361
|
+
*
|
|
5362
|
+
* Note: [2]
|
|
5363
|
+
*/
|
|
5364
|
+
var isBlockTypeSet = false;
|
|
4536
5365
|
try {
|
|
4537
5366
|
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
4538
5367
|
var listItem = listItems_2_1.value;
|
|
4539
5368
|
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
5369
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
4540
5370
|
switch (command.type) {
|
|
4541
5371
|
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
4542
5372
|
case 'BLOCK':
|
|
4543
|
-
if (
|
|
5373
|
+
if (isBlockTypeSet) {
|
|
4544
5374
|
throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
|
|
4545
5375
|
}
|
|
4546
5376
|
if (command.blockType === 'SAMPLE') {
|
|
4547
|
-
|
|
5377
|
+
expectResultingParameterName();
|
|
5378
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
5379
|
+
if (parameter === undefined) {
|
|
5380
|
+
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
5381
|
+
}
|
|
5382
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
5383
|
+
parameter.sampleValues.push(content);
|
|
4548
5384
|
return "continue-templates";
|
|
4549
5385
|
}
|
|
4550
5386
|
if (command.blockType === 'KNOWLEDGE') {
|
|
4551
|
-
|
|
5387
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
5388
|
+
type: 'KNOWLEDGE',
|
|
5389
|
+
source: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5390
|
+
}, {
|
|
5391
|
+
pipelineJson: pipelineJson,
|
|
5392
|
+
templateJson: templateJson,
|
|
5393
|
+
});
|
|
4552
5394
|
return "continue-templates";
|
|
4553
5395
|
}
|
|
4554
5396
|
if (command.blockType === 'ACTION') {
|
|
@@ -4559,35 +5401,37 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4559
5401
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4560
5402
|
return "continue-templates";
|
|
4561
5403
|
}
|
|
4562
|
-
|
|
4563
|
-
|
|
5404
|
+
expectResultingParameterName();
|
|
5405
|
+
templateJson.blockType = command.blockType;
|
|
5406
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
4564
5407
|
break;
|
|
4565
5408
|
case 'EXPECT_AMOUNT':
|
|
4566
5409
|
// eslint-disable-next-line no-case-declarations
|
|
4567
5410
|
var unit = command.unit.toLowerCase();
|
|
4568
|
-
|
|
5411
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
5412
|
+
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
4569
5413
|
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
4570
|
-
if (
|
|
4571
|
-
throw new ParsingError("Already defined minumum ".concat(
|
|
5414
|
+
if (templateJson.expectations[unit].min !== undefined) {
|
|
5415
|
+
throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
4572
5416
|
}
|
|
4573
|
-
|
|
5417
|
+
templateJson.expectations[unit].min = command.amount;
|
|
4574
5418
|
} /* not else */
|
|
4575
5419
|
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
4576
|
-
if (
|
|
4577
|
-
throw new ParsingError("Already defined maximum ".concat(
|
|
5420
|
+
if (templateJson.expectations[unit].max !== undefined) {
|
|
5421
|
+
throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
4578
5422
|
}
|
|
4579
|
-
|
|
5423
|
+
templateJson.expectations[unit].max = command.amount;
|
|
4580
5424
|
}
|
|
4581
5425
|
break;
|
|
4582
5426
|
case 'EXPECT_FORMAT':
|
|
4583
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
4584
|
-
throw new ParsingError("Expect format is already defined to \"".concat(expectFormat, "\"
|
|
5427
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5428
|
+
throw new ParsingError(spaceTrim$1("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
|
|
4585
5429
|
}
|
|
4586
|
-
expectFormat = command.format;
|
|
5430
|
+
templateJson.expectFormat = command.format;
|
|
4587
5431
|
break;
|
|
4588
5432
|
case 'JOKER':
|
|
4589
|
-
|
|
4590
|
-
|
|
5433
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
5434
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
4591
5435
|
break;
|
|
4592
5436
|
case 'MODEL':
|
|
4593
5437
|
templateModelRequirements[command.key] = command.value;
|
|
@@ -4597,19 +5441,24 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4597
5441
|
defineParam(command);
|
|
4598
5442
|
break;
|
|
4599
5443
|
case 'POSTPROCESS':
|
|
4600
|
-
|
|
5444
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
5445
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
4601
5446
|
break;
|
|
4602
5447
|
case 'KNOWLEDGE':
|
|
4603
|
-
|
|
5448
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
5449
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
4604
5450
|
break;
|
|
4605
5451
|
case 'ACTION':
|
|
5452
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
4606
5453
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
4607
5454
|
break;
|
|
4608
5455
|
case 'INSTRUMENT':
|
|
5456
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
4609
5457
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4610
5458
|
break;
|
|
4611
5459
|
case 'PERSONA':
|
|
4612
|
-
|
|
5460
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
5461
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4613
5462
|
break;
|
|
4614
5463
|
case 'BOILERPLATE':
|
|
4615
5464
|
console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
|
|
@@ -4627,70 +5476,29 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4627
5476
|
}
|
|
4628
5477
|
finally { if (e_3) throw e_3.error; }
|
|
4629
5478
|
}
|
|
4630
|
-
|
|
4631
|
-
if (blockType === 'SCRIPT') {
|
|
5479
|
+
// TODO: [🍧] Should be done in BLOCK command
|
|
5480
|
+
if (templateJson.blockType === 'SCRIPT') {
|
|
4632
5481
|
if (!language) {
|
|
4633
5482
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
4634
5483
|
}
|
|
4635
|
-
|
|
5484
|
+
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
4636
5485
|
throw new ParsingError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
4637
5486
|
}
|
|
5487
|
+
templateJson.contentLanguage = language;
|
|
4638
5488
|
}
|
|
4639
|
-
|
|
4640
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4641
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
4642
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Each section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
4643
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
4644
|
-
section.content
|
|
4645
|
-
.split('\n')
|
|
4646
|
-
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
4647
|
-
.join('\n')), "\n "); }));
|
|
4648
|
-
}
|
|
4649
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
4650
|
-
// TODO: [1] DRY description
|
|
4651
|
-
var description_1 = section.content;
|
|
4652
|
-
// Note: Remove codeblocks
|
|
4653
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
4654
|
-
//Note: Remove lists and return statement
|
|
4655
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4656
|
-
description_1 = spaceTrim$1(description_1);
|
|
4657
|
-
if (description_1 === '') {
|
|
4658
|
-
description_1 = undefined;
|
|
4659
|
-
}
|
|
4660
|
-
if (Object.keys(jokers).length === 0) {
|
|
4661
|
-
jokers = undefined;
|
|
4662
|
-
}
|
|
4663
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
4664
|
-
expectAmount = undefined;
|
|
4665
|
-
}
|
|
4666
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
4667
|
-
postprocessing = undefined;
|
|
4668
|
-
}
|
|
4669
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, blockType: blockType, content: content })));
|
|
5489
|
+
// TODO: [🍧][❔] Should be done in BLOCK command
|
|
4670
5490
|
if (templateModelRequirements.modelVariant === undefined) {
|
|
4671
5491
|
templateModelRequirements.modelVariant = 'CHAT';
|
|
4672
5492
|
}
|
|
4673
|
-
dependentParameterNames =
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
description: description_1,
|
|
4678
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
4679
|
-
blockType: blockType,
|
|
4680
|
-
jokers: jokers,
|
|
4681
|
-
postprocessing: postprocessing,
|
|
4682
|
-
expectations: expectAmount,
|
|
4683
|
-
expectFormat: expectFormat,
|
|
4684
|
-
modelRequirements: templateModelRequirements,
|
|
4685
|
-
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4686
|
-
content: content,
|
|
4687
|
-
resultingParameterName: resultingParameterName,
|
|
4688
|
-
};
|
|
4689
|
-
if (blockType !== 'PROMPT_TEMPLATE') {
|
|
4690
|
-
delete template.modelRequirements;
|
|
5493
|
+
templateJson.dependentParameterNames = Array.from(extractParametersFromPromptTemplate(templateJson));
|
|
5494
|
+
// TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
|
|
5495
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
5496
|
+
delete templateJson.modelRequirements;
|
|
4691
5497
|
}
|
|
5498
|
+
// TODO: [🍧] Make this better - for example each command parser can call and apply this
|
|
5499
|
+
templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
|
|
4692
5500
|
// TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
|
|
4693
|
-
pipelineJson.promptTemplates.push(
|
|
5501
|
+
pipelineJson.promptTemplates.push(templateJson);
|
|
4694
5502
|
};
|
|
4695
5503
|
try {
|
|
4696
5504
|
// =============================================================
|
|
@@ -4757,14 +5565,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4757
5565
|
* TODO: Use spaceTrim more effectively
|
|
4758
5566
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
4759
5567
|
* TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
5568
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
5569
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4760
5570
|
*/
|
|
4761
5571
|
|
|
4762
5572
|
/**
|
|
4763
|
-
* Compile
|
|
5573
|
+
* Compile pipeline from string (markdown) format to JSON format
|
|
4764
5574
|
*
|
|
4765
|
-
* Note: There are
|
|
5575
|
+
* Note: There are 3 similar functions:
|
|
4766
5576
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4767
5577
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5578
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4768
5579
|
*
|
|
4769
5580
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4770
5581
|
* @param options - Options and tools for the compilation
|
|
@@ -4775,22 +5586,18 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4775
5586
|
* Note: This function acts as compilation process
|
|
4776
5587
|
*/
|
|
4777
5588
|
function pipelineStringToJson(pipelineString, options) {
|
|
4778
|
-
if (options === void 0) { options = {}; }
|
|
5589
|
+
if (options === void 0) { options = { llmTools: null }; }
|
|
4779
5590
|
return __awaiter(this, void 0, void 0, function () {
|
|
4780
|
-
var llmTools, pipelineJson
|
|
5591
|
+
var llmTools, pipelineJson;
|
|
4781
5592
|
return __generator(this, function (_a) {
|
|
4782
5593
|
switch (_a.label) {
|
|
4783
5594
|
case 0:
|
|
4784
5595
|
llmTools = options.llmTools;
|
|
4785
5596
|
pipelineJson = pipelineStringToJsonSync(pipelineString);
|
|
4786
|
-
if (!llmTools) return [3 /*break*/, 2];
|
|
4787
|
-
return [4 /*yield*/,
|
|
4788
|
-
content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
|
|
4789
|
-
llmTools: llmTools,
|
|
4790
|
-
})];
|
|
5597
|
+
if (!(llmTools !== null)) return [3 /*break*/, 2];
|
|
5598
|
+
return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
|
|
4791
5599
|
case 1:
|
|
4792
|
-
|
|
4793
|
-
pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
|
|
5600
|
+
pipelineJson = _a.sent();
|
|
4794
5601
|
_a.label = 2;
|
|
4795
5602
|
case 2: return [2 /*return*/, pipelineJson];
|
|
4796
5603
|
}
|
|
@@ -4799,12 +5606,13 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
4799
5606
|
}
|
|
4800
5607
|
/**
|
|
4801
5608
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
5609
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4802
5610
|
*/
|
|
4803
5611
|
|
|
4804
5612
|
/**
|
|
4805
5613
|
* Add or modify an auto-generated section in a markdown file
|
|
4806
5614
|
*
|
|
4807
|
-
* @private within the
|
|
5615
|
+
* @private within the repository
|
|
4808
5616
|
*/
|
|
4809
5617
|
function addAutoGeneratedSection(content, options) {
|
|
4810
5618
|
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
@@ -4816,7 +5624,10 @@ function addAutoGeneratedSection(content, options) {
|
|
|
4816
5624
|
}
|
|
4817
5625
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
4818
5626
|
if (!placeForSection) {
|
|
4819
|
-
throw new
|
|
5627
|
+
throw new ParsingError(
|
|
5628
|
+
// <- [🧠] Maybe something better than `ParsingError`
|
|
5629
|
+
"No place where to put the section <!--".concat(sectionName, "-->"));
|
|
5630
|
+
// <- [🚞]
|
|
4820
5631
|
}
|
|
4821
5632
|
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
4822
5633
|
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
@@ -4973,6 +5784,27 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
4973
5784
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
4974
5785
|
*/
|
|
4975
5786
|
|
|
5787
|
+
/**
|
|
5788
|
+
* Stringify the PipelineJson with proper formatting
|
|
5789
|
+
*
|
|
5790
|
+
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
5791
|
+
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
5792
|
+
*/
|
|
5793
|
+
function stringifyPipelineJson(pipeline) {
|
|
5794
|
+
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
5795
|
+
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
5796
|
+
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
5797
|
+
}
|
|
5798
|
+
pipelineJsonStringified = pipelineJsonStringified.split(REPLACING_NONCE).join(', ');
|
|
5799
|
+
pipelineJsonStringified += '\n';
|
|
5800
|
+
return pipelineJsonStringified;
|
|
5801
|
+
}
|
|
5802
|
+
/**
|
|
5803
|
+
* TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
5804
|
+
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
5805
|
+
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
5806
|
+
*/
|
|
5807
|
+
|
|
4976
5808
|
/**
|
|
4977
5809
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
4978
5810
|
*/
|
|
@@ -4987,6 +5819,20 @@ var CollectionError = /** @class */ (function (_super) {
|
|
|
4987
5819
|
return CollectionError;
|
|
4988
5820
|
}(Error));
|
|
4989
5821
|
|
|
5822
|
+
/**
|
|
5823
|
+
* This error type indicates that the version of the pipeline is not matching the expected version
|
|
5824
|
+
*/
|
|
5825
|
+
var VersionMismatchError = /** @class */ (function (_super) {
|
|
5826
|
+
__extends(VersionMismatchError, _super);
|
|
5827
|
+
function VersionMismatchError(message, expectedVersion) {
|
|
5828
|
+
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n This error indicates that there is error with compatibility\n\n Expected version:\n ").concat(expectedVersion, "\n\n Current version:\n ").concat(PROMPTBOOK_VERSION, "\n\n "); })) || this;
|
|
5829
|
+
_this.name = 'UnexpectedError';
|
|
5830
|
+
Object.setPrototypeOf(_this, VersionMismatchError.prototype);
|
|
5831
|
+
return _this;
|
|
5832
|
+
}
|
|
5833
|
+
return VersionMismatchError;
|
|
5834
|
+
}(Error));
|
|
5835
|
+
|
|
4990
5836
|
/**
|
|
4991
5837
|
* Pretty print an embedding vector for logging
|
|
4992
5838
|
*/
|
|
@@ -5074,6 +5920,9 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
|
5074
5920
|
};
|
|
5075
5921
|
return SimplePromptInterfaceTools;
|
|
5076
5922
|
}());
|
|
5923
|
+
/**
|
|
5924
|
+
* Note: [🔵] This code should never be published outside of `@promptbook/browser`
|
|
5925
|
+
*/
|
|
5077
5926
|
|
|
5078
5927
|
/**
|
|
5079
5928
|
* Default options for generating an execution report string
|
|
@@ -5086,7 +5935,7 @@ var ExecutionReportStringOptionsDefaults = {
|
|
|
5086
5935
|
/**
|
|
5087
5936
|
* Format either small or big number
|
|
5088
5937
|
*
|
|
5089
|
-
* @private within the
|
|
5938
|
+
* @private within the repository
|
|
5090
5939
|
*/
|
|
5091
5940
|
function formatNumber(value) {
|
|
5092
5941
|
if (value === 0) {
|
|
@@ -5106,7 +5955,7 @@ function formatNumber(value) {
|
|
|
5106
5955
|
/**
|
|
5107
5956
|
* Create a markdown table from a 2D array of strings
|
|
5108
5957
|
*
|
|
5109
|
-
* @private within the
|
|
5958
|
+
* @private within the repository
|
|
5110
5959
|
*/
|
|
5111
5960
|
function createMarkdownTable(table) {
|
|
5112
5961
|
var columnWidths = table.reduce(function (widths, row) {
|
|
@@ -5134,7 +5983,7 @@ function createMarkdownTable(table) {
|
|
|
5134
5983
|
/**
|
|
5135
5984
|
* Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
|
|
5136
5985
|
*
|
|
5137
|
-
* @private within the
|
|
5986
|
+
* @private within the repository
|
|
5138
5987
|
*/
|
|
5139
5988
|
function createMarkdownChart(options) {
|
|
5140
5989
|
var e_1, _a;
|
|
@@ -5187,7 +6036,7 @@ var MOMENT_ARG_THRESHOLDS = {
|
|
|
5187
6036
|
/**
|
|
5188
6037
|
* Count the duration of working time
|
|
5189
6038
|
*
|
|
5190
|
-
* @private within the
|
|
6039
|
+
* @private within the repository
|
|
5191
6040
|
*/
|
|
5192
6041
|
function countWorkingDuration(items) {
|
|
5193
6042
|
var e_1, _a;
|
|
@@ -5385,5 +6234,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
5385
6234
|
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
5386
6235
|
*/
|
|
5387
6236
|
|
|
5388
|
-
export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prettifyPipelineString, usageToWorktime, validatePipeline };
|
|
6237
|
+
export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatchError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, preparePipeline, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToWorktime, validatePipeline };
|
|
5389
6238
|
//# sourceMappingURL=index.es.js.map
|