@promptbook/core 0.61.0-8 → 0.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/esm/index.es.js +2066 -1044
- 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 +12 -8
- package/esm/typings/src/_packages/utils.index.d.ts +11 -8
- 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 +7 -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 +46 -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 +6 -3
- package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/{umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts → esm/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts} +2 -2
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +14 -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 +48 -26
- package/esm/typings/src/execution/PromptResult.d.ts +39 -54
- package/esm/typings/src/execution/PromptResultUsage.d.ts +29 -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 +30 -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 +4 -3
- 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 +10 -8
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +2 -2
- 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 +14 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +17 -0
- package/esm/typings/src/prepare/prepareTemplates.d.ts +31 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +11 -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/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 +70 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +27 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +10 -1
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +41 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +31 -5
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +22 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +8 -2
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +5 -1
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +23 -4
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +12 -2
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +7 -2
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -2
- 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 → extractParameterNames.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.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/{umd/typings/src/utils → esm/typings/src/utils/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/esm/typings/src/{execution/utils → 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 +2069 -1043
- 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 +12 -8
- package/umd/typings/src/_packages/utils.index.d.ts +11 -8
- 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 +7 -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 +46 -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 +6 -3
- package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/{esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts → umd/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts} +2 -2
- package/umd/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.test.d.ts +1 -0
- package/umd/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +14 -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 +48 -26
- package/umd/typings/src/execution/PromptResult.d.ts +39 -54
- package/umd/typings/src/execution/PromptResultUsage.d.ts +29 -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 +30 -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 +4 -3
- 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 +10 -8
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +2 -2
- 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 +14 -0
- package/umd/typings/src/prepare/isPipelinePrepared.test.d.ts +1 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +17 -0
- package/umd/typings/src/prepare/prepareTemplates.d.ts +31 -0
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +11 -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 +70 -0
- package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +27 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +10 -1
- package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +41 -0
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +31 -5
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +22 -0
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +8 -2
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +5 -1
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +23 -4
- package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +12 -2
- package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +7 -2
- package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -2
- 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 → extractParameterNames.d.ts} +2 -2
- package/umd/typings/src/utils/extractParameterNames.test.d.ts +1 -0
- 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/{esm/typings/src/utils → umd/typings/src/utils/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/umd/typings/src/{execution/utils → 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/conversion/utils/{extractParametersFromPromptTemplate.test.d.ts → extractParameterNamesFromPromptTemplate.test.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/esm/typings/src/{utils/extractParameters.test.d.ts → personas/preparePersona.test.d.ts} +0 -0
- /package/esm/typings/src/{utils/postprocessing → postprocessing/utils}/extractBlock.d.ts +0 -0
- /package/{umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.test.d.ts → esm/typings/src/prepare/isPipelinePrepared.test.d.ts} +0 -0
- /package/{umd/typings/src/execution/addPromptResultUsage.test.d.ts → esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts} +0 -0
- /package/{umd/typings/src/execution/utils/replaceParameters.test.d.ts → esm/typings/src/utils/extractParameterNames.test.d.ts} +0 -0
- /package/{umd/typings/src/utils/extractParameters.test.d.ts → esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.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,119 @@ 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;
|
|
469
|
+
/**
|
|
470
|
+
* Nonce which is used for replacing things in strings
|
|
471
|
+
*/
|
|
472
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
397
473
|
/**
|
|
398
474
|
* The names of the parameters that are reserved for special purposes
|
|
399
475
|
*/
|
|
400
|
-
var RESERVED_PARAMETER_NAMES = [
|
|
476
|
+
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
477
|
+
'content',
|
|
401
478
|
'context',
|
|
479
|
+
'knowledge',
|
|
480
|
+
'samples',
|
|
481
|
+
'modelName',
|
|
482
|
+
'currentDate',
|
|
402
483
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
403
484
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
404
|
-
];
|
|
485
|
+
]);
|
|
486
|
+
/**
|
|
487
|
+
* @@@
|
|
488
|
+
*/
|
|
489
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
490
|
+
/**
|
|
491
|
+
* @@@
|
|
492
|
+
*/
|
|
493
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
494
|
+
/*
|
|
495
|
+
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
496
|
+
*/
|
|
497
|
+
// [🟡][🟢][🔵][⚪]
|
|
498
|
+
/**
|
|
499
|
+
* TODO: [🔼] Export all to core
|
|
500
|
+
*/
|
|
405
501
|
|
|
406
502
|
/**
|
|
407
503
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -479,7 +575,7 @@ function isValidPromptbookVersion(version) {
|
|
|
479
575
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
480
576
|
return false;
|
|
481
577
|
}
|
|
482
|
-
// <- TODO:
|
|
578
|
+
// <- TODO: !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
483
579
|
return true;
|
|
484
580
|
}
|
|
485
581
|
|
|
@@ -604,56 +700,67 @@ function isValidPipelineUrl(url) {
|
|
|
604
700
|
*/
|
|
605
701
|
function validatePipeline(pipeline) {
|
|
606
702
|
// 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
|
|
703
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
704
|
+
var pipelineIdentification = (function () {
|
|
705
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
706
|
+
var _ = [];
|
|
707
|
+
if (pipeline.sourceFile !== undefined) {
|
|
708
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
709
|
+
}
|
|
710
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
711
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
712
|
+
}
|
|
713
|
+
return _.join('\n');
|
|
714
|
+
})();
|
|
608
715
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
609
716
|
// <- Note: [🚲]
|
|
610
|
-
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\""));
|
|
717
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
611
718
|
}
|
|
612
719
|
if (!isValidPromptbookVersion(pipeline.promptbookVersion)) {
|
|
613
720
|
// <- Note: [🚲]
|
|
614
|
-
throw new PipelineLogicError("Invalid
|
|
721
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
615
722
|
}
|
|
616
723
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
617
724
|
if (!Array.isArray(pipeline.parameters)) {
|
|
618
725
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
619
|
-
throw new ParsingError(spaceTrim$1("\n
|
|
726
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
620
727
|
}
|
|
621
728
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
622
729
|
if (!Array.isArray(pipeline.promptTemplates)) {
|
|
623
730
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
624
|
-
throw new ParsingError(spaceTrim$1("\n
|
|
731
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.promptTemplates` expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
625
732
|
}
|
|
626
733
|
var _loop_1 = function (parameter) {
|
|
627
734
|
if (parameter.isInput && parameter.isOutput) {
|
|
628
|
-
throw new PipelineLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
|
|
735
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n\n Parameter {".concat(parameter.name, "} can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
629
736
|
}
|
|
630
737
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
631
738
|
if (!parameter.isInput &&
|
|
632
739
|
!parameter.isOutput &&
|
|
633
740
|
!pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
634
|
-
throw new PipelineLogicError(spaceTrim$1("\n
|
|
741
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
635
742
|
}
|
|
636
743
|
// Note: Testing that parameter is either input or result of some template
|
|
637
744
|
if (!parameter.isInput &&
|
|
638
745
|
!pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
639
|
-
throw new PipelineLogicError(spaceTrim$1("\n
|
|
746
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
640
747
|
}
|
|
641
748
|
};
|
|
642
749
|
try {
|
|
643
750
|
// Note: Check each parameter individually
|
|
644
|
-
for (var
|
|
645
|
-
var parameter =
|
|
751
|
+
for (var _d = __values(pipeline.parameters), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
752
|
+
var parameter = _e.value;
|
|
646
753
|
_loop_1(parameter);
|
|
647
754
|
}
|
|
648
755
|
}
|
|
649
756
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
650
757
|
finally {
|
|
651
758
|
try {
|
|
652
|
-
if (
|
|
759
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
653
760
|
}
|
|
654
761
|
finally { if (e_1) throw e_1.error; }
|
|
655
762
|
}
|
|
656
|
-
// Note:
|
|
763
|
+
// Note: All input parameters are defined - so that they can be used as result of some template
|
|
657
764
|
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
658
765
|
var isInput = _a.isInput;
|
|
659
766
|
return isInput;
|
|
@@ -661,66 +768,80 @@ function validatePipeline(pipeline) {
|
|
|
661
768
|
var name = _a.name;
|
|
662
769
|
return name;
|
|
663
770
|
}));
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
771
|
+
var _loop_2 = function (template) {
|
|
772
|
+
var e_4, _h, e_5, _j;
|
|
773
|
+
if (definedParameters.has(template.resultingParameterName)) {
|
|
774
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
775
|
+
}
|
|
776
|
+
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
777
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
778
|
+
}
|
|
779
|
+
definedParameters.add(template.resultingParameterName);
|
|
780
|
+
if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
781
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\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`").concat(/* <- TODO: Dynamic listing of command examples */ '', "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
782
|
+
}
|
|
783
|
+
if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
|
|
784
|
+
if (!template.expectFormat &&
|
|
785
|
+
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
786
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
669
787
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
788
|
+
var _loop_4 = function (joker) {
|
|
789
|
+
if (!template.dependentParameterNames.includes(joker)) {
|
|
790
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
try {
|
|
794
|
+
for (var _k = (e_4 = void 0, __values(template.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
795
|
+
var joker = _l.value;
|
|
796
|
+
_loop_4(joker);
|
|
678
797
|
}
|
|
798
|
+
}
|
|
799
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
800
|
+
finally {
|
|
679
801
|
try {
|
|
680
|
-
|
|
681
|
-
var joker = _k.value;
|
|
682
|
-
if (!template.dependentParameterNames.includes(joker)) {
|
|
683
|
-
throw new PipelineLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
684
|
-
}
|
|
685
|
-
}
|
|
802
|
+
if (_l && !_l.done && (_h = _k.return)) _h.call(_k);
|
|
686
803
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
804
|
+
finally { if (e_4) throw e_4.error; }
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
if (template.expectations) {
|
|
808
|
+
var _loop_5 = function (unit, min, max) {
|
|
809
|
+
if (min !== undefined && max !== undefined && min > max) {
|
|
810
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
811
|
+
}
|
|
812
|
+
if (min !== undefined && min < 0) {
|
|
813
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
814
|
+
}
|
|
815
|
+
if (max !== undefined && max <= 0) {
|
|
816
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
try {
|
|
820
|
+
for (var _m = (e_5 = void 0, __values(Object.entries(template.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
821
|
+
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
822
|
+
_loop_5(unit, min, max);
|
|
693
823
|
}
|
|
694
824
|
}
|
|
695
|
-
|
|
825
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
826
|
+
finally {
|
|
696
827
|
try {
|
|
697
|
-
|
|
698
|
-
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
699
|
-
if (min !== undefined && max !== undefined && min > max) {
|
|
700
|
-
throw new PipelineLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
701
|
-
}
|
|
702
|
-
if (min !== undefined && min < 0) {
|
|
703
|
-
throw new PipelineLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
|
|
704
|
-
}
|
|
705
|
-
if (max !== undefined && max <= 0) {
|
|
706
|
-
throw new PipelineLogicError("Max expectation of ".concat(unit, " must be positive"));
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
711
|
-
finally {
|
|
712
|
-
try {
|
|
713
|
-
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
714
|
-
}
|
|
715
|
-
finally { if (e_4) throw e_4.error; }
|
|
828
|
+
if (_o && !_o.done && (_j = _m.return)) _j.call(_m);
|
|
716
829
|
}
|
|
830
|
+
finally { if (e_5) throw e_5.error; }
|
|
717
831
|
}
|
|
718
832
|
}
|
|
833
|
+
};
|
|
834
|
+
try {
|
|
835
|
+
// Note: Checking each template individually
|
|
836
|
+
for (var _f = __values(pipeline.promptTemplates), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
837
|
+
var template = _g.value;
|
|
838
|
+
_loop_2(template);
|
|
839
|
+
}
|
|
719
840
|
}
|
|
720
841
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
721
842
|
finally {
|
|
722
843
|
try {
|
|
723
|
-
if (
|
|
844
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
724
845
|
}
|
|
725
846
|
finally { if (e_2) throw e_2.error; }
|
|
726
847
|
}
|
|
@@ -734,24 +855,42 @@ function validatePipeline(pipeline) {
|
|
|
734
855
|
var name = _a.name;
|
|
735
856
|
return name;
|
|
736
857
|
});
|
|
858
|
+
try {
|
|
859
|
+
// Note: All reserved parameters are resolved
|
|
860
|
+
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()) {
|
|
861
|
+
var reservedParameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
862
|
+
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), [reservedParameterName], false);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
866
|
+
finally {
|
|
867
|
+
try {
|
|
868
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_c = RESERVED_PARAMETER_NAMES_1.return)) _c.call(RESERVED_PARAMETER_NAMES_1);
|
|
869
|
+
}
|
|
870
|
+
finally { if (e_3) throw e_3.error; }
|
|
871
|
+
}
|
|
737
872
|
var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
873
|
+
// <- TODO: [🧠][🥜]
|
|
738
874
|
var loopLimit = LOOP_LIMIT;
|
|
739
|
-
var
|
|
875
|
+
var _loop_3 = function () {
|
|
740
876
|
if (loopLimit-- < 0) {
|
|
741
|
-
|
|
877
|
+
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
878
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
742
879
|
}
|
|
743
880
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
744
881
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
745
882
|
});
|
|
746
883
|
if (currentlyResovedTemplates.length === 0) {
|
|
747
|
-
throw new PipelineLogicError(
|
|
884
|
+
throw new PipelineLogicError(
|
|
885
|
+
// TODO: [🐎] DRY
|
|
886
|
+
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
887
|
.map(function (_a) {
|
|
749
888
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
750
|
-
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
889
|
+
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
751
890
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
752
|
-
.join('
|
|
891
|
+
.join(' and '));
|
|
753
892
|
})
|
|
754
|
-
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
893
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
755
894
|
}
|
|
756
895
|
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
|
|
757
896
|
var resultingParameterName = _a.resultingParameterName;
|
|
@@ -760,7 +899,7 @@ function validatePipeline(pipeline) {
|
|
|
760
899
|
unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
|
|
761
900
|
};
|
|
762
901
|
while (unresovedTemplates.length > 0) {
|
|
763
|
-
|
|
902
|
+
_loop_3();
|
|
764
903
|
}
|
|
765
904
|
return pipeline;
|
|
766
905
|
}
|
|
@@ -773,7 +912,16 @@ function validatePipeline(pipeline) {
|
|
|
773
912
|
* > * It checks:
|
|
774
913
|
* > * - it has a valid structure
|
|
775
914
|
* > * - ...
|
|
776
|
-
* > ex port function validatePipeline(promptbook:
|
|
915
|
+
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
916
|
+
*/
|
|
917
|
+
/**
|
|
918
|
+
* TODO: [🐣] !!!! Validate that all samples match expectations
|
|
919
|
+
* TODO: [🐣][🐝] !!!! Validate that knowledge is valid (non-void)
|
|
920
|
+
* TODO: [🐣] !!!! Validate that persona can be used only with CHAT variant
|
|
921
|
+
* TODO: [🐣] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
922
|
+
* TODO: [🐣] !!!! Validate that reserved parameter is not used as joker
|
|
923
|
+
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
924
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
777
925
|
*/
|
|
778
926
|
|
|
779
927
|
/**
|
|
@@ -805,79 +953,137 @@ var ReferenceError$1 = /** @class */ (function (_super) {
|
|
|
805
953
|
}(Error));
|
|
806
954
|
|
|
807
955
|
/**
|
|
808
|
-
*
|
|
809
|
-
*
|
|
956
|
+
* Parses the template and returns the list of all parameter names
|
|
957
|
+
*
|
|
958
|
+
* @param template the template with parameters in {curly} braces
|
|
959
|
+
* @returns the list of parameter names
|
|
960
|
+
*/
|
|
961
|
+
function extractParameterNames(template) {
|
|
962
|
+
var e_1, _a;
|
|
963
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
964
|
+
var parameterNames = new Set();
|
|
965
|
+
try {
|
|
966
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
967
|
+
var match = matches_1_1.value;
|
|
968
|
+
var parameterName = match[0].slice(1, -1);
|
|
969
|
+
parameterNames.add(parameterName);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
973
|
+
finally {
|
|
974
|
+
try {
|
|
975
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
976
|
+
}
|
|
977
|
+
finally { if (e_1) throw e_1.error; }
|
|
978
|
+
}
|
|
979
|
+
return parameterNames;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Unprepare just strips the preparation data of the pipeline
|
|
984
|
+
*/
|
|
985
|
+
function unpreparePipeline(pipeline) {
|
|
986
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
|
|
987
|
+
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
988
|
+
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
989
|
+
promptTemplates = promptTemplates.map(function (promptTemplate) {
|
|
990
|
+
var dependentParameterNames = promptTemplate.dependentParameterNames;
|
|
991
|
+
var parameterNames = extractParameterNames(promptTemplate.preparedContent || '');
|
|
992
|
+
dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
|
|
993
|
+
var promptTemplateUnprepared = __assign(__assign({}, promptTemplate), { dependentParameterNames: dependentParameterNames });
|
|
994
|
+
delete promptTemplateUnprepared.preparedContent;
|
|
995
|
+
return promptTemplateUnprepared;
|
|
996
|
+
});
|
|
997
|
+
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
1001
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
1002
|
+
* TODO: Write tests for `preparePipeline`
|
|
1003
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
1004
|
+
*/
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* Library of pipelines that groups together pipelines for an application.
|
|
1008
|
+
* This implementation is a very thin wrapper around the Array / Map of pipelines.
|
|
810
1009
|
*
|
|
811
1010
|
* @private use `createCollectionFromJson` instead
|
|
812
|
-
* @see https://github.com/webgptorg/
|
|
1011
|
+
* @see https://github.com/webgptorg/pipeline#pipeline-collection
|
|
813
1012
|
*/
|
|
814
1013
|
var SimplePipelineCollection = /** @class */ (function () {
|
|
815
1014
|
/**
|
|
816
|
-
* Constructs a pipeline collection from
|
|
1015
|
+
* Constructs a pipeline collection from pipelines
|
|
817
1016
|
*
|
|
818
|
-
* @param
|
|
1017
|
+
* @param pipelines @@@
|
|
819
1018
|
*
|
|
820
1019
|
* @private Use instead `createCollectionFromJson`
|
|
821
|
-
* Note: During the construction logic of all
|
|
1020
|
+
* Note: During the construction logic of all pipelines are validated
|
|
822
1021
|
* Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
|
|
823
1022
|
*/
|
|
824
1023
|
function SimplePipelineCollection() {
|
|
825
1024
|
var e_1, _a;
|
|
826
|
-
var
|
|
1025
|
+
var pipelines = [];
|
|
827
1026
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
828
|
-
|
|
1027
|
+
pipelines[_i] = arguments[_i];
|
|
829
1028
|
}
|
|
830
1029
|
this.collection = new Map();
|
|
831
1030
|
try {
|
|
832
|
-
for (var
|
|
833
|
-
var
|
|
834
|
-
|
|
835
|
-
|
|
1031
|
+
for (var pipelines_1 = __values(pipelines), pipelines_1_1 = pipelines_1.next(); !pipelines_1_1.done; pipelines_1_1 = pipelines_1.next()) {
|
|
1032
|
+
var pipeline = pipelines_1_1.value;
|
|
1033
|
+
// TODO: [👠] DRY
|
|
1034
|
+
if (pipeline.pipelineUrl === undefined) {
|
|
1035
|
+
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
1036
|
}
|
|
837
|
-
|
|
1037
|
+
// Note: [🐨]
|
|
1038
|
+
validatePipeline(pipeline);
|
|
1039
|
+
// TODO: [🦄] DRY
|
|
838
1040
|
// Note: [🦄]
|
|
839
|
-
if (
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1041
|
+
if (
|
|
1042
|
+
// TODO: [🐽]
|
|
1043
|
+
this.collection.has(pipeline.pipelineUrl) &&
|
|
1044
|
+
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1045
|
+
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1046
|
+
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1047
|
+
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
1048
|
}
|
|
844
|
-
|
|
1049
|
+
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1050
|
+
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
845
1051
|
}
|
|
846
1052
|
}
|
|
847
1053
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
848
1054
|
finally {
|
|
849
1055
|
try {
|
|
850
|
-
if (
|
|
1056
|
+
if (pipelines_1_1 && !pipelines_1_1.done && (_a = pipelines_1.return)) _a.call(pipelines_1);
|
|
851
1057
|
}
|
|
852
1058
|
finally { if (e_1) throw e_1.error; }
|
|
853
1059
|
}
|
|
854
1060
|
}
|
|
855
1061
|
/**
|
|
856
|
-
* Gets all
|
|
1062
|
+
* Gets all pipelines in the collection
|
|
857
1063
|
*/
|
|
858
1064
|
SimplePipelineCollection.prototype.listPipelines = function () {
|
|
859
1065
|
return Array.from(this.collection.keys());
|
|
860
1066
|
};
|
|
861
1067
|
/**
|
|
862
|
-
* Gets
|
|
1068
|
+
* Gets pipeline by its URL
|
|
863
1069
|
*
|
|
864
1070
|
* Note: This is not a direct fetching from the URL, but a lookup in the collection
|
|
865
1071
|
*/
|
|
866
1072
|
SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
|
|
867
1073
|
var _this = this;
|
|
868
|
-
var
|
|
869
|
-
if (!
|
|
1074
|
+
var pipeline = this.collection.get(url);
|
|
1075
|
+
if (!pipeline) {
|
|
870
1076
|
if (this.listPipelines().length === 0) {
|
|
871
|
-
throw new NotFoundError(spaceTrim$1("\n
|
|
1077
|
+
throw new NotFoundError(spaceTrim$1("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
|
|
872
1078
|
}
|
|
873
|
-
throw new NotFoundError(spaceTrim$1(function (block) { return "\n
|
|
1079
|
+
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
1080
|
.map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
|
|
875
1081
|
.join('\n')), "\n\n "); }));
|
|
876
1082
|
}
|
|
877
|
-
return
|
|
1083
|
+
return pipeline;
|
|
878
1084
|
};
|
|
879
1085
|
/**
|
|
880
|
-
* Checks whether given prompt was defined in any
|
|
1086
|
+
* Checks whether given prompt was defined in any pipeline in the collection
|
|
881
1087
|
*/
|
|
882
1088
|
SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
|
|
883
1089
|
return true;
|
|
@@ -1119,7 +1325,199 @@ var BlockTypes = [
|
|
|
1119
1325
|
// <- [🩻]
|
|
1120
1326
|
];
|
|
1121
1327
|
|
|
1122
|
-
|
|
1328
|
+
/**
|
|
1329
|
+
* @@@
|
|
1330
|
+
*/
|
|
1331
|
+
function deepClone(objectValue) {
|
|
1332
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
1333
|
+
/*
|
|
1334
|
+
TODO: [🧠] Is there a better implementation?
|
|
1335
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1336
|
+
> for (const propertyName of propertyNames) {
|
|
1337
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
1338
|
+
> if (value && typeof value === 'object') {
|
|
1339
|
+
> deepClone(value);
|
|
1340
|
+
> }
|
|
1341
|
+
> }
|
|
1342
|
+
> return Object.assign({}, objectValue);
|
|
1343
|
+
*/
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* TODO: [🔼] Export from `@promptbook/utils`
|
|
1347
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1348
|
+
*/
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* @@@
|
|
1352
|
+
*
|
|
1353
|
+
* TODO: [🔼] Export with addUsage
|
|
1354
|
+
*/
|
|
1355
|
+
var ZERO_USAGE = deepFreeze({
|
|
1356
|
+
price: { value: 0 },
|
|
1357
|
+
input: {
|
|
1358
|
+
tokensCount: { value: 0 },
|
|
1359
|
+
charactersCount: { value: 0 },
|
|
1360
|
+
wordsCount: { value: 0 },
|
|
1361
|
+
sentencesCount: { value: 0 },
|
|
1362
|
+
linesCount: { value: 0 },
|
|
1363
|
+
paragraphsCount: { value: 0 },
|
|
1364
|
+
pagesCount: { value: 0 },
|
|
1365
|
+
},
|
|
1366
|
+
output: {
|
|
1367
|
+
tokensCount: { value: 0 },
|
|
1368
|
+
charactersCount: { value: 0 },
|
|
1369
|
+
wordsCount: { value: 0 },
|
|
1370
|
+
sentencesCount: { value: 0 },
|
|
1371
|
+
linesCount: { value: 0 },
|
|
1372
|
+
paragraphsCount: { value: 0 },
|
|
1373
|
+
pagesCount: { value: 0 },
|
|
1374
|
+
},
|
|
1375
|
+
});
|
|
1376
|
+
/**
|
|
1377
|
+
* Function `addUsage` will add multiple usages into one
|
|
1378
|
+
*
|
|
1379
|
+
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
1380
|
+
*/
|
|
1381
|
+
function addUsage() {
|
|
1382
|
+
var usageItems = [];
|
|
1383
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1384
|
+
usageItems[_i] = arguments[_i];
|
|
1385
|
+
}
|
|
1386
|
+
return usageItems.reduce(function (acc, item) {
|
|
1387
|
+
var e_1, _a, e_2, _b;
|
|
1388
|
+
var _c;
|
|
1389
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1390
|
+
try {
|
|
1391
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1392
|
+
var key = _e.value;
|
|
1393
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1394
|
+
//@ts-ignore
|
|
1395
|
+
if (item.input[key]) {
|
|
1396
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1397
|
+
//@ts-ignore
|
|
1398
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
1399
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1400
|
+
//@ts-ignore
|
|
1401
|
+
if (item.input[key].isUncertain) {
|
|
1402
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1403
|
+
//@ts-ignore
|
|
1404
|
+
acc.input[key].isUncertain = true;
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1410
|
+
finally {
|
|
1411
|
+
try {
|
|
1412
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1413
|
+
}
|
|
1414
|
+
finally { if (e_1) throw e_1.error; }
|
|
1415
|
+
}
|
|
1416
|
+
try {
|
|
1417
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1418
|
+
var key = _g.value;
|
|
1419
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1420
|
+
//@ts-ignore
|
|
1421
|
+
if (item.output[key]) {
|
|
1422
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1423
|
+
//@ts-ignore
|
|
1424
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
1425
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1426
|
+
//@ts-ignore
|
|
1427
|
+
if (item.output[key].isUncertain) {
|
|
1428
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1429
|
+
//@ts-ignore
|
|
1430
|
+
acc.output[key].isUncertain = true;
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1436
|
+
finally {
|
|
1437
|
+
try {
|
|
1438
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1439
|
+
}
|
|
1440
|
+
finally { if (e_2) throw e_2.error; }
|
|
1441
|
+
}
|
|
1442
|
+
return acc;
|
|
1443
|
+
}, deepClone(ZERO_USAGE));
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* Async version of Array.forEach
|
|
1448
|
+
*
|
|
1449
|
+
* @param array - Array to iterate over
|
|
1450
|
+
* @param options - Options for the function
|
|
1451
|
+
* @param callbackfunction - Function to call for each item
|
|
1452
|
+
*/
|
|
1453
|
+
function forEachAsync(array, options, callbackfunction) {
|
|
1454
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1455
|
+
var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
|
|
1456
|
+
var e_1, _d;
|
|
1457
|
+
return __generator(this, function (_e) {
|
|
1458
|
+
switch (_e.label) {
|
|
1459
|
+
case 0:
|
|
1460
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
1461
|
+
index = 0;
|
|
1462
|
+
runningTasks = [];
|
|
1463
|
+
tasks = [];
|
|
1464
|
+
_loop_1 = function (item) {
|
|
1465
|
+
var currentIndex, task;
|
|
1466
|
+
return __generator(this, function (_f) {
|
|
1467
|
+
switch (_f.label) {
|
|
1468
|
+
case 0:
|
|
1469
|
+
currentIndex = index++;
|
|
1470
|
+
task = callbackfunction(item, currentIndex, array);
|
|
1471
|
+
tasks.push(task);
|
|
1472
|
+
runningTasks.push(task);
|
|
1473
|
+
/* not await */ Promise.resolve(task).then(function () {
|
|
1474
|
+
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
1475
|
+
});
|
|
1476
|
+
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
1477
|
+
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
1478
|
+
case 1:
|
|
1479
|
+
_f.sent();
|
|
1480
|
+
_f.label = 2;
|
|
1481
|
+
case 2: return [2 /*return*/];
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
};
|
|
1485
|
+
_e.label = 1;
|
|
1486
|
+
case 1:
|
|
1487
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
1488
|
+
_b = __values(array), _c = _b.next();
|
|
1489
|
+
_e.label = 2;
|
|
1490
|
+
case 2:
|
|
1491
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
1492
|
+
item = _c.value;
|
|
1493
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
1494
|
+
case 3:
|
|
1495
|
+
_e.sent();
|
|
1496
|
+
_e.label = 4;
|
|
1497
|
+
case 4:
|
|
1498
|
+
_c = _b.next();
|
|
1499
|
+
return [3 /*break*/, 2];
|
|
1500
|
+
case 5: return [3 /*break*/, 8];
|
|
1501
|
+
case 6:
|
|
1502
|
+
e_1_1 = _e.sent();
|
|
1503
|
+
e_1 = { error: e_1_1 };
|
|
1504
|
+
return [3 /*break*/, 8];
|
|
1505
|
+
case 7:
|
|
1506
|
+
try {
|
|
1507
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
1508
|
+
}
|
|
1509
|
+
finally { if (e_1) throw e_1.error; }
|
|
1510
|
+
return [7 /*endfinally*/];
|
|
1511
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
1512
|
+
case 9:
|
|
1513
|
+
_e.sent();
|
|
1514
|
+
return [2 /*return*/];
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-30",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",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> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",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-30",parameters:[{name:"knowledgePieceContent",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> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",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-30",parameters:[{name:"knowledgePieceContent",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> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",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-30",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-30",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
1521
|
|
|
1124
1522
|
var defaultDiacriticsRemovalMap = [
|
|
1125
1523
|
{
|
|
@@ -1446,6 +1844,14 @@ function removeEmojis(text) {
|
|
|
1446
1844
|
* Function normalizes title to name which can be used as identifier
|
|
1447
1845
|
*/
|
|
1448
1846
|
function titleToName(value) {
|
|
1847
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
1848
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1849
|
+
return value;
|
|
1850
|
+
}
|
|
1851
|
+
if (value.startsWith('./') || value.startsWith('../')) {
|
|
1852
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1853
|
+
return value;
|
|
1854
|
+
}
|
|
1449
1855
|
value = removeEmojis(value);
|
|
1450
1856
|
value = normalizeToKebabCase(value);
|
|
1451
1857
|
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
@@ -1484,7 +1890,11 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1484
1890
|
throw errors[0];
|
|
1485
1891
|
}
|
|
1486
1892
|
else {
|
|
1487
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors
|
|
1893
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors
|
|
1894
|
+
.map(function (error, index) {
|
|
1895
|
+
return spaceTrim$1(function (block) { return "\n Error ".concat(index + 1, ":\n ").concat(block(error.stack || error.message), "\n "); });
|
|
1896
|
+
})
|
|
1897
|
+
.join('\n')), "\n "); }));
|
|
1488
1898
|
}
|
|
1489
1899
|
}
|
|
1490
1900
|
/**
|
|
@@ -1492,26 +1902,134 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1492
1902
|
*/
|
|
1493
1903
|
|
|
1494
1904
|
/**
|
|
1495
|
-
*
|
|
1905
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
1496
1906
|
*
|
|
1497
|
-
* @
|
|
1498
|
-
*
|
|
1907
|
+
* @param script from which to extract the variables
|
|
1908
|
+
* @returns the list of variable names
|
|
1909
|
+
* @throws {ParsingError} if the script is invalid
|
|
1499
1910
|
*/
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1911
|
+
function extractVariables(script) {
|
|
1912
|
+
var variables = new Set();
|
|
1913
|
+
script = "(()=>{".concat(script, "})()");
|
|
1914
|
+
try {
|
|
1915
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
1916
|
+
try {
|
|
1917
|
+
eval(script);
|
|
1918
|
+
}
|
|
1919
|
+
catch (error) {
|
|
1920
|
+
if (!(error instanceof ReferenceError)) {
|
|
1921
|
+
throw error;
|
|
1922
|
+
}
|
|
1923
|
+
var undefinedName = error.message.split(' ')[0];
|
|
1924
|
+
/*
|
|
1925
|
+
Note: Parsing the error
|
|
1926
|
+
[ReferenceError: thing is not defined]
|
|
1927
|
+
*/
|
|
1928
|
+
if (!undefinedName) {
|
|
1929
|
+
throw error;
|
|
1930
|
+
}
|
|
1931
|
+
if (script.includes(undefinedName + '(')) {
|
|
1932
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
1933
|
+
}
|
|
1934
|
+
else {
|
|
1935
|
+
variables.add(undefinedName);
|
|
1936
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
catch (error) {
|
|
1941
|
+
if (!(error instanceof Error)) {
|
|
1942
|
+
throw error;
|
|
1943
|
+
}
|
|
1944
|
+
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 "); }));
|
|
1945
|
+
}
|
|
1946
|
+
return variables;
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
1950
|
+
*/
|
|
1951
|
+
|
|
1952
|
+
/**
|
|
1953
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
1954
|
+
*
|
|
1955
|
+
* @param promptTemplate the template with used parameters
|
|
1956
|
+
* @returns the set of parameter names
|
|
1957
|
+
* @throws {ParsingError} if the script is invalid
|
|
1958
|
+
*/
|
|
1959
|
+
function extractParameterNamesFromPromptTemplate(promptTemplate) {
|
|
1960
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
1961
|
+
var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, preparedContent = promptTemplate.preparedContent, jokerParameterNames = promptTemplate.jokerParameterNames;
|
|
1962
|
+
var parameterNames = new Set();
|
|
1963
|
+
try {
|
|
1964
|
+
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1965
|
+
var parameterName = _e.value;
|
|
1966
|
+
parameterNames.add(parameterName);
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1970
|
+
finally {
|
|
1971
|
+
try {
|
|
1972
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1973
|
+
}
|
|
1974
|
+
finally { if (e_1) throw e_1.error; }
|
|
1975
|
+
}
|
|
1976
|
+
if (blockType === 'SCRIPT') {
|
|
1977
|
+
try {
|
|
1978
|
+
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1979
|
+
var parameterName = _g.value;
|
|
1980
|
+
parameterNames.add(parameterName);
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1984
|
+
finally {
|
|
1985
|
+
try {
|
|
1986
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1987
|
+
}
|
|
1988
|
+
finally { if (e_2) throw e_2.error; }
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
try {
|
|
1992
|
+
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
1993
|
+
var jokerName = _j.value;
|
|
1994
|
+
parameterNames.add(jokerName);
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1998
|
+
finally {
|
|
1999
|
+
try {
|
|
2000
|
+
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
2001
|
+
}
|
|
2002
|
+
finally { if (e_3) throw e_3.error; }
|
|
2003
|
+
}
|
|
2004
|
+
parameterNames.delete('content');
|
|
2005
|
+
// <- Note {websiteContent} is used in `preparedContent`
|
|
2006
|
+
return parameterNames;
|
|
2007
|
+
}
|
|
2008
|
+
/**
|
|
2009
|
+
* TODO: [🔣] If script require contentLanguage
|
|
2010
|
+
*/
|
|
2011
|
+
|
|
2012
|
+
/**
|
|
2013
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
2014
|
+
*
|
|
2015
|
+
* @private Always catched and rethrown as `PipelineExecutionError`
|
|
2016
|
+
* Note: This is a kindof subtype of PipelineExecutionError
|
|
2017
|
+
*/
|
|
2018
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
2019
|
+
__extends(ExpectError, _super);
|
|
2020
|
+
function ExpectError(message) {
|
|
2021
|
+
var _this = _super.call(this, message) || this;
|
|
2022
|
+
_this.name = 'ExpectError';
|
|
2023
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
2024
|
+
return _this;
|
|
2025
|
+
}
|
|
2026
|
+
return ExpectError;
|
|
2027
|
+
}(Error));
|
|
1510
2028
|
|
|
1511
2029
|
/**
|
|
1512
2030
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1513
2031
|
*/
|
|
1514
|
-
function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
2032
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1515
2033
|
try {
|
|
1516
2034
|
JSON.parse(value);
|
|
1517
2035
|
return true;
|
|
@@ -1654,10 +2172,17 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1654
2172
|
throw errors[0];
|
|
1655
2173
|
}
|
|
1656
2174
|
else if (errors.length > 1) {
|
|
1657
|
-
throw new PipelineExecutionError(
|
|
2175
|
+
throw new PipelineExecutionError(
|
|
2176
|
+
// TODO: Tell which execution tools failed like
|
|
2177
|
+
// 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2178
|
+
// 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2179
|
+
// 3) ...
|
|
2180
|
+
spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2181
|
+
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
2182
|
+
.join('\n')), "\n\n "); }));
|
|
1658
2183
|
}
|
|
1659
2184
|
else {
|
|
1660
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n
|
|
2185
|
+
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
2186
|
.map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
|
|
1662
2187
|
.join('\n')), "\n\n "); }));
|
|
1663
2188
|
}
|
|
@@ -1667,7 +2192,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1667
2192
|
};
|
|
1668
2193
|
/**
|
|
1669
2194
|
* List all available models that can be used
|
|
1670
|
-
* This
|
|
2195
|
+
* This lists is a combination of all available models from all execution tools
|
|
1671
2196
|
*/
|
|
1672
2197
|
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
1673
2198
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1713,6 +2238,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1713
2238
|
}());
|
|
1714
2239
|
/**
|
|
1715
2240
|
* TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
|
|
2241
|
+
* 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
|
|
2242
|
+
* Look how `countTotalUsage` (and `cacheLlmTools`) implements it
|
|
1716
2243
|
*/
|
|
1717
2244
|
|
|
1718
2245
|
/**
|
|
@@ -1734,7 +2261,7 @@ function joinLlmExecutionTools() {
|
|
|
1734
2261
|
llmExecutionTools[_i] = arguments[_i];
|
|
1735
2262
|
}
|
|
1736
2263
|
if (llmExecutionTools.length === 0) {
|
|
1737
|
-
var warningMessage = spaceTrim("\n You have provided
|
|
2264
|
+
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
2265
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
1739
2266
|
console.warn(warningMessage);
|
|
1740
2267
|
/*
|
|
@@ -1761,6 +2288,36 @@ function joinLlmExecutionTools() {
|
|
|
1761
2288
|
return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
|
|
1762
2289
|
}
|
|
1763
2290
|
|
|
2291
|
+
/**
|
|
2292
|
+
* Determine if the pipeline is fully prepared
|
|
2293
|
+
*/
|
|
2294
|
+
function isPipelinePrepared(pipeline) {
|
|
2295
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2296
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2297
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2298
|
+
return false;
|
|
2299
|
+
}
|
|
2300
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2301
|
+
return false;
|
|
2302
|
+
}
|
|
2303
|
+
/*
|
|
2304
|
+
TODO: [🧠][🍫] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
|
|
2305
|
+
> if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2306
|
+
> return false;
|
|
2307
|
+
> }
|
|
2308
|
+
*/
|
|
2309
|
+
return true;
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2313
|
+
* TODO: [🔼] Export via core or utils
|
|
2314
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2315
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2316
|
+
* - [🏍] ? Is context in each template
|
|
2317
|
+
* - [♨] Are samples prepared
|
|
2318
|
+
* - [♨] Are templates prepared
|
|
2319
|
+
*/
|
|
2320
|
+
|
|
1764
2321
|
/**
|
|
1765
2322
|
* Takes an item or an array of items and returns an array of items
|
|
1766
2323
|
*
|
|
@@ -1781,106 +2338,197 @@ function arrayableToArray(input) {
|
|
|
1781
2338
|
}
|
|
1782
2339
|
|
|
1783
2340
|
/**
|
|
1784
|
-
*
|
|
2341
|
+
* Just marks a place of place where should be something implemented
|
|
2342
|
+
* No side effects.
|
|
2343
|
+
*
|
|
2344
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2345
|
+
*
|
|
2346
|
+
* @param value any values
|
|
2347
|
+
* @returns void
|
|
2348
|
+
* @private within the repository
|
|
1785
2349
|
*/
|
|
1786
|
-
|
|
1787
|
-
|
|
2350
|
+
function TODO_USE() {
|
|
2351
|
+
var value = [];
|
|
2352
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2353
|
+
value[_i] = arguments[_i];
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
1788
2356
|
|
|
1789
2357
|
/**
|
|
1790
|
-
*
|
|
1791
|
-
*
|
|
1792
|
-
* Note: If you provide 0 values, it returns void usage
|
|
2358
|
+
* This error type indicates that some limit was reached
|
|
1793
2359
|
*/
|
|
1794
|
-
function
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
2360
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
2361
|
+
__extends(LimitReachedError, _super);
|
|
2362
|
+
function LimitReachedError(message) {
|
|
2363
|
+
var _this = _super.call(this, message) || this;
|
|
2364
|
+
_this.name = 'LimitReachedError';
|
|
2365
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2366
|
+
return _this;
|
|
1798
2367
|
}
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
pagesCount: { value: 0 },
|
|
1818
|
-
},
|
|
1819
|
-
};
|
|
1820
|
-
return usageItems.reduce(function (acc, item) {
|
|
1821
|
-
var e_1, _a, e_2, _b;
|
|
1822
|
-
var _c;
|
|
1823
|
-
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1824
|
-
try {
|
|
1825
|
-
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
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
|
-
}
|
|
2368
|
+
return LimitReachedError;
|
|
2369
|
+
}(Error));
|
|
2370
|
+
|
|
2371
|
+
/**
|
|
2372
|
+
* Replaces parameters in template with values from parameters object
|
|
2373
|
+
*
|
|
2374
|
+
* @param template the template with parameters in {curly} braces
|
|
2375
|
+
* @param parameters the object with parameters
|
|
2376
|
+
* @returns the template with replaced parameters
|
|
2377
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2378
|
+
*/
|
|
2379
|
+
function replaceParameters(template, parameters) {
|
|
2380
|
+
var e_1, _a;
|
|
2381
|
+
try {
|
|
2382
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2383
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
2384
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
2385
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
|
|
1841
2386
|
}
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
try {
|
|
1846
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2387
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
2388
|
+
// TODO: [🍵]
|
|
2389
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
|
|
1847
2390
|
}
|
|
1848
|
-
finally { if (e_1) throw e_1.error; }
|
|
1849
2391
|
}
|
|
2392
|
+
}
|
|
2393
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2394
|
+
finally {
|
|
1850
2395
|
try {
|
|
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
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
2396
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1868
2397
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
2398
|
+
finally { if (e_1) throw e_1.error; }
|
|
2399
|
+
}
|
|
2400
|
+
var replacedTemplate = template;
|
|
2401
|
+
var match;
|
|
2402
|
+
var loopLimit = LOOP_LIMIT;
|
|
2403
|
+
var _loop_1 = function () {
|
|
2404
|
+
if (loopLimit-- < 0) {
|
|
2405
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
1875
2406
|
}
|
|
1876
|
-
|
|
1877
|
-
|
|
2407
|
+
var precol = match.groups.precol;
|
|
2408
|
+
var parameterName = match.groups.parameterName;
|
|
2409
|
+
if (parameterName === '') {
|
|
2410
|
+
return "continue";
|
|
2411
|
+
}
|
|
2412
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
2413
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
2414
|
+
}
|
|
2415
|
+
if (parameters[parameterName] === undefined) {
|
|
2416
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2417
|
+
}
|
|
2418
|
+
var parameterValue = parameters[parameterName];
|
|
2419
|
+
if (parameterValue === undefined) {
|
|
2420
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2421
|
+
}
|
|
2422
|
+
parameterValue = parameterValue.toString();
|
|
2423
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2424
|
+
parameterValue = parameterValue
|
|
2425
|
+
.split('\n')
|
|
2426
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
2427
|
+
.join('\n');
|
|
2428
|
+
}
|
|
2429
|
+
replacedTemplate =
|
|
2430
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
2431
|
+
parameterValue +
|
|
2432
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
2433
|
+
};
|
|
2434
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
2435
|
+
.exec(replacedTemplate))) {
|
|
2436
|
+
_loop_1();
|
|
2437
|
+
}
|
|
2438
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
2439
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
2440
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
2441
|
+
}
|
|
2442
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
2443
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
2444
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
2445
|
+
}
|
|
2446
|
+
return replacedTemplate;
|
|
1878
2447
|
}
|
|
1879
2448
|
|
|
1880
2449
|
/**
|
|
1881
|
-
*
|
|
2450
|
+
* Create difference set of two sets.
|
|
2451
|
+
*
|
|
2452
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1882
2453
|
*/
|
|
1883
|
-
function
|
|
2454
|
+
function difference(a, b, isEqual) {
|
|
2455
|
+
var e_1, _a;
|
|
2456
|
+
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
2457
|
+
var diff = new Set();
|
|
2458
|
+
var _loop_1 = function (itemA) {
|
|
2459
|
+
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
2460
|
+
diff.add(itemA);
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
try {
|
|
2464
|
+
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2465
|
+
var itemA = _c.value;
|
|
2466
|
+
_loop_1(itemA);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2470
|
+
finally {
|
|
2471
|
+
try {
|
|
2472
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2473
|
+
}
|
|
2474
|
+
finally { if (e_1) throw e_1.error; }
|
|
2475
|
+
}
|
|
2476
|
+
return diff;
|
|
2477
|
+
}
|
|
2478
|
+
/**
|
|
2479
|
+
* TODO: [🧠][💯] Maybe also implement symmetricDifference
|
|
2480
|
+
*/
|
|
2481
|
+
|
|
2482
|
+
/**
|
|
2483
|
+
* Creates a new set with all elements that are present in either set
|
|
2484
|
+
*
|
|
2485
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2486
|
+
*/
|
|
2487
|
+
function union() {
|
|
2488
|
+
var e_1, _a, e_2, _b;
|
|
2489
|
+
var sets = [];
|
|
2490
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2491
|
+
sets[_i] = arguments[_i];
|
|
2492
|
+
}
|
|
2493
|
+
var union = new Set();
|
|
2494
|
+
try {
|
|
2495
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2496
|
+
var set = sets_1_1.value;
|
|
2497
|
+
try {
|
|
2498
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2499
|
+
var item = _d.value;
|
|
2500
|
+
union.add(item);
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2504
|
+
finally {
|
|
2505
|
+
try {
|
|
2506
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
2507
|
+
}
|
|
2508
|
+
finally { if (e_2) throw e_2.error; }
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2513
|
+
finally {
|
|
2514
|
+
try {
|
|
2515
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
2516
|
+
}
|
|
2517
|
+
finally { if (e_1) throw e_1.error; }
|
|
2518
|
+
}
|
|
2519
|
+
return union;
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
/**
|
|
2523
|
+
* The version of the Promptbook library
|
|
2524
|
+
*/
|
|
2525
|
+
var PROMPTBOOK_VERSION = '0.61.0-30';
|
|
2526
|
+
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2527
|
+
|
|
2528
|
+
/**
|
|
2529
|
+
* Counts number of characters in the text
|
|
2530
|
+
*/
|
|
2531
|
+
function countCharacters(text) {
|
|
1884
2532
|
// Remove null characters
|
|
1885
2533
|
text = text.replace(/\0/g, '');
|
|
1886
2534
|
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
@@ -2008,66 +2656,6 @@ function isPassingExpectations(expectations, value) {
|
|
|
2008
2656
|
* TODO: [💝] Unite object for expecting amount and format
|
|
2009
2657
|
*/
|
|
2010
2658
|
|
|
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
2659
|
/**
|
|
2072
2660
|
* Creates executor function from pipeline and execution tools.
|
|
2073
2661
|
*
|
|
@@ -2077,24 +2665,107 @@ function replaceParameters(template, parameters) {
|
|
|
2077
2665
|
function createPipelineExecutor(options) {
|
|
2078
2666
|
var _this = this;
|
|
2079
2667
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2080
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ?
|
|
2081
|
-
// TODO: !!!!! Implement new commands
|
|
2668
|
+
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, _e = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e;
|
|
2082
2669
|
validatePipeline(pipeline);
|
|
2083
|
-
// TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
|
|
2084
|
-
// TODO: !!!!! Do here personaToModelRequirements
|
|
2085
2670
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2671
|
+
var preparedPipeline;
|
|
2672
|
+
if (isPipelinePrepared(pipeline)) {
|
|
2673
|
+
preparedPipeline = pipeline;
|
|
2674
|
+
}
|
|
2675
|
+
else if (isNotPreparedWarningSupressed !== true) {
|
|
2676
|
+
console.warn(spaceTrim$1("\n Pipeline ".concat(pipeline.pipelineUrl || pipeline.sourceFile || pipeline.title, " is not prepared\n\n ").concat(pipeline.sourceFile, "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
|
|
2677
|
+
}
|
|
2086
2678
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2679
|
+
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
2680
|
+
function getContextForTemplate(// <- TODO: [🧠][🥜]
|
|
2681
|
+
template) {
|
|
2682
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2683
|
+
return __generator(this, function (_a) {
|
|
2684
|
+
TODO_USE(template);
|
|
2685
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
2686
|
+
});
|
|
2687
|
+
});
|
|
2688
|
+
}
|
|
2689
|
+
function getKnowledgeForTemplate(// <- TODO: [🧠][🥜]
|
|
2690
|
+
template) {
|
|
2691
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2692
|
+
return __generator(this, function (_a) {
|
|
2693
|
+
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
2694
|
+
TODO_USE(template);
|
|
2695
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
2696
|
+
var content = _a.content;
|
|
2697
|
+
return "- ".concat(content);
|
|
2698
|
+
}).join('\n')];
|
|
2699
|
+
});
|
|
2700
|
+
});
|
|
2701
|
+
}
|
|
2702
|
+
function getSamplesForTemplate(// <- TODO: [🧠][🥜]
|
|
2703
|
+
template) {
|
|
2704
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2705
|
+
return __generator(this, function (_a) {
|
|
2706
|
+
// TODO: [♨] Implement Better - use real index and keyword search
|
|
2707
|
+
TODO_USE(template);
|
|
2708
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
2709
|
+
});
|
|
2710
|
+
});
|
|
2711
|
+
}
|
|
2712
|
+
function getReservedParametersForTemplate(template) {
|
|
2713
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2714
|
+
var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2715
|
+
var e_3, _a;
|
|
2716
|
+
return __generator(this, function (_b) {
|
|
2717
|
+
switch (_b.label) {
|
|
2718
|
+
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
2719
|
+
case 1:
|
|
2720
|
+
context = _b.sent();
|
|
2721
|
+
return [4 /*yield*/, getKnowledgeForTemplate(template)];
|
|
2722
|
+
case 2:
|
|
2723
|
+
knowledge = _b.sent();
|
|
2724
|
+
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
2725
|
+
case 3:
|
|
2726
|
+
samples = _b.sent();
|
|
2727
|
+
currentDate = new Date().toISOString();
|
|
2728
|
+
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
2729
|
+
reservedParameters = {
|
|
2730
|
+
content: RESERVED_PARAMETER_RESTRICTED,
|
|
2731
|
+
context: context,
|
|
2732
|
+
knowledge: knowledge,
|
|
2733
|
+
samples: samples,
|
|
2734
|
+
currentDate: currentDate,
|
|
2735
|
+
modelName: modelName,
|
|
2736
|
+
};
|
|
2737
|
+
try {
|
|
2738
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
2739
|
+
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()) {
|
|
2740
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
2741
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
2742
|
+
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2747
|
+
finally {
|
|
2748
|
+
try {
|
|
2749
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
2750
|
+
}
|
|
2751
|
+
finally { if (e_3) throw e_3.error; }
|
|
2752
|
+
}
|
|
2753
|
+
return [2 /*return*/, reservedParameters];
|
|
2754
|
+
}
|
|
2755
|
+
});
|
|
2756
|
+
});
|
|
2757
|
+
}
|
|
2087
2758
|
function executeSingleTemplate(currentTemplate) {
|
|
2088
2759
|
return __awaiter(this, void 0, void 0, function () {
|
|
2089
|
-
var name, title, priority, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts,
|
|
2090
|
-
var
|
|
2760
|
+
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, preparedContent, 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;
|
|
2761
|
+
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2091
2762
|
var _this = this;
|
|
2092
|
-
return __generator(this, function (
|
|
2093
|
-
switch (
|
|
2763
|
+
return __generator(this, function (_u) {
|
|
2764
|
+
switch (_u.label) {
|
|
2094
2765
|
case 0:
|
|
2095
2766
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
2096
2767
|
title = currentTemplate.title;
|
|
2097
|
-
priority =
|
|
2768
|
+
priority = preparedPipeline.promptTemplates.length - preparedPipeline.promptTemplates.indexOf(currentTemplate);
|
|
2098
2769
|
if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
2099
2770
|
return [4 /*yield*/, onProgress({
|
|
2100
2771
|
name: name,
|
|
@@ -2107,61 +2778,111 @@ function createPipelineExecutor(options) {
|
|
|
2107
2778
|
// <- [3]
|
|
2108
2779
|
})];
|
|
2109
2780
|
case 1:
|
|
2110
|
-
|
|
2111
|
-
|
|
2781
|
+
_u.sent();
|
|
2782
|
+
_u.label = 2;
|
|
2112
2783
|
case 2:
|
|
2784
|
+
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
2785
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2786
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2787
|
+
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 ")));
|
|
2788
|
+
}
|
|
2789
|
+
_b = (_a = Object).freeze;
|
|
2790
|
+
_c = [{}];
|
|
2791
|
+
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
2792
|
+
case 3:
|
|
2793
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_u.sent())])), parametersToPass])]);
|
|
2794
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
2795
|
+
parameters = {};
|
|
2796
|
+
try {
|
|
2797
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
2798
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2799
|
+
parameterName = _e.value;
|
|
2800
|
+
// Situation: Parameter is defined and used
|
|
2801
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2802
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
2803
|
+
}
|
|
2804
|
+
// Situation: Parameter is defined but NOT used
|
|
2805
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
2806
|
+
// Do not pass this parameter to prompt
|
|
2807
|
+
}
|
|
2808
|
+
// Situation: Parameter is NOT defined BUT used
|
|
2809
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2810
|
+
// Houston, we have a problem
|
|
2811
|
+
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
2812
|
+
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 ")));
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
2817
|
+
finally {
|
|
2818
|
+
try {
|
|
2819
|
+
if (_e && !_e.done && (_p = _d.return)) _p.call(_d);
|
|
2820
|
+
}
|
|
2821
|
+
finally { if (e_7) throw e_7.error; }
|
|
2822
|
+
}
|
|
2823
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
2824
|
+
Object.freeze(parameters);
|
|
2113
2825
|
result = null;
|
|
2114
2826
|
resultString = null;
|
|
2115
2827
|
expectError = null;
|
|
2116
2828
|
maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2829
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
2830
|
+
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
2831
|
+
.split('{content}')
|
|
2832
|
+
.join(currentTemplate.content);
|
|
2833
|
+
attempt = -jokerParameterNames.length;
|
|
2834
|
+
_u.label = 4;
|
|
2835
|
+
case 4:
|
|
2836
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 52];
|
|
2122
2837
|
isJokerAttempt = attempt < 0;
|
|
2123
|
-
|
|
2124
|
-
if (isJokerAttempt && !
|
|
2838
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
2839
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
2125
2840
|
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
2126
2841
|
}
|
|
2127
2842
|
result = null;
|
|
2128
2843
|
resultString = null;
|
|
2129
2844
|
expectError = null;
|
|
2130
2845
|
if (isJokerAttempt) {
|
|
2131
|
-
if (
|
|
2132
|
-
throw new PipelineExecutionError("Joker parameter {".concat(
|
|
2846
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
2847
|
+
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
2848
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
2849
|
+
}
|
|
2850
|
+
else {
|
|
2851
|
+
resultString = parameters[jokerParameterName];
|
|
2133
2852
|
}
|
|
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
2853
|
}
|
|
2147
|
-
|
|
2854
|
+
_u.label = 5;
|
|
2148
2855
|
case 5:
|
|
2149
|
-
|
|
2856
|
+
_u.trys.push([5, 48, 49, 50]);
|
|
2857
|
+
if (!!isJokerAttempt) return [3 /*break*/, 30];
|
|
2858
|
+
_f = currentTemplate.blockType;
|
|
2859
|
+
switch (_f) {
|
|
2860
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
2861
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
2862
|
+
case 'SCRIPT': return [3 /*break*/, 16];
|
|
2863
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
2864
|
+
}
|
|
2150
2865
|
return [3 /*break*/, 29];
|
|
2151
2866
|
case 6:
|
|
2867
|
+
resultString = replaceParameters(preparedContent, parameters);
|
|
2868
|
+
return [3 /*break*/, 30];
|
|
2869
|
+
case 7:
|
|
2152
2870
|
prompt = {
|
|
2153
2871
|
title: currentTemplate.title,
|
|
2154
|
-
pipelineUrl: "".concat(
|
|
2155
|
-
?
|
|
2872
|
+
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
2873
|
+
? preparedPipeline.pipelineUrl
|
|
2156
2874
|
: '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:
|
|
2875
|
+
parameters: parameters,
|
|
2876
|
+
content: preparedContent,
|
|
2159
2877
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2160
|
-
expectations:
|
|
2878
|
+
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
2879
|
+
var name = _a.name;
|
|
2880
|
+
return name === currentTemplate.personaName;
|
|
2881
|
+
}) || {})), currentTemplate.expectations),
|
|
2161
2882
|
expectFormat: currentTemplate.expectFormat,
|
|
2162
|
-
postprocessing: (currentTemplate.
|
|
2163
|
-
var errors, _a, _b, scriptTools, error_5,
|
|
2164
|
-
var
|
|
2883
|
+
postprocessing: (currentTemplate.postprocessingFunctionNames || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
2884
|
+
var errors, _a, _b, scriptTools, error_5, e_8_1;
|
|
2885
|
+
var e_8, _c;
|
|
2165
2886
|
return __generator(this, function (_d) {
|
|
2166
2887
|
switch (_d.label) {
|
|
2167
2888
|
case 0:
|
|
@@ -2182,7 +2903,7 @@ function createPipelineExecutor(options) {
|
|
|
2182
2903
|
script: "".concat(functionName, "(result)"),
|
|
2183
2904
|
parameters: {
|
|
2184
2905
|
result: result || '',
|
|
2185
|
-
// Note: No ...
|
|
2906
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2186
2907
|
},
|
|
2187
2908
|
})];
|
|
2188
2909
|
case 4: return [2 /*return*/, _d.sent()];
|
|
@@ -2191,6 +2912,9 @@ function createPipelineExecutor(options) {
|
|
|
2191
2912
|
if (!(error_5 instanceof Error)) {
|
|
2192
2913
|
throw error_5;
|
|
2193
2914
|
}
|
|
2915
|
+
if (error_5 instanceof UnexpectedError) {
|
|
2916
|
+
throw error_5;
|
|
2917
|
+
}
|
|
2194
2918
|
errors.push(error_5);
|
|
2195
2919
|
return [3 /*break*/, 6];
|
|
2196
2920
|
case 6:
|
|
@@ -2198,14 +2922,14 @@ function createPipelineExecutor(options) {
|
|
|
2198
2922
|
return [3 /*break*/, 2];
|
|
2199
2923
|
case 7: return [3 /*break*/, 10];
|
|
2200
2924
|
case 8:
|
|
2201
|
-
|
|
2202
|
-
|
|
2925
|
+
e_8_1 = _d.sent();
|
|
2926
|
+
e_8 = { error: e_8_1 };
|
|
2203
2927
|
return [3 /*break*/, 10];
|
|
2204
2928
|
case 9:
|
|
2205
2929
|
try {
|
|
2206
2930
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2207
2931
|
}
|
|
2208
|
-
finally { if (
|
|
2932
|
+
finally { if (e_8) throw e_8.error; }
|
|
2209
2933
|
return [7 /*endfinally*/];
|
|
2210
2934
|
case 10:
|
|
2211
2935
|
if (errors.length === 0) {
|
|
@@ -2221,35 +2945,35 @@ function createPipelineExecutor(options) {
|
|
|
2221
2945
|
});
|
|
2222
2946
|
}); }; }),
|
|
2223
2947
|
};
|
|
2224
|
-
|
|
2225
|
-
switch (
|
|
2226
|
-
case 'CHAT': return [3 /*break*/,
|
|
2227
|
-
case 'COMPLETION': return [3 /*break*/,
|
|
2228
|
-
case 'EMBEDDING': return [3 /*break*/,
|
|
2948
|
+
_g = currentTemplate.modelRequirements.modelVariant;
|
|
2949
|
+
switch (_g) {
|
|
2950
|
+
case 'CHAT': return [3 /*break*/, 8];
|
|
2951
|
+
case 'COMPLETION': return [3 /*break*/, 10];
|
|
2952
|
+
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
2229
2953
|
}
|
|
2230
|
-
return [3 /*break*/,
|
|
2231
|
-
case
|
|
2232
|
-
case
|
|
2233
|
-
chatResult =
|
|
2954
|
+
return [3 /*break*/, 14];
|
|
2955
|
+
case 8: return [4 /*yield*/, llmTools.callChatModel(deepFreeze(prompt))];
|
|
2956
|
+
case 9:
|
|
2957
|
+
chatResult = _u.sent();
|
|
2234
2958
|
// TODO: [🍬] Destroy chatThread
|
|
2235
2959
|
result = chatResult;
|
|
2236
2960
|
resultString = chatResult.content;
|
|
2237
|
-
return [3 /*break*/,
|
|
2238
|
-
case
|
|
2239
|
-
case
|
|
2240
|
-
completionResult =
|
|
2961
|
+
return [3 /*break*/, 15];
|
|
2962
|
+
case 10: return [4 /*yield*/, llmTools.callCompletionModel(deepFreeze(prompt))];
|
|
2963
|
+
case 11:
|
|
2964
|
+
completionResult = _u.sent();
|
|
2241
2965
|
result = completionResult;
|
|
2242
2966
|
resultString = completionResult.content;
|
|
2243
|
-
return [3 /*break*/,
|
|
2244
|
-
case
|
|
2245
|
-
case
|
|
2246
|
-
embeddingResult =
|
|
2967
|
+
return [3 /*break*/, 15];
|
|
2968
|
+
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel(deepFreeze(prompt))];
|
|
2969
|
+
case 13:
|
|
2970
|
+
embeddingResult = _u.sent();
|
|
2247
2971
|
result = embeddingResult;
|
|
2248
2972
|
resultString = embeddingResult.content.join(',');
|
|
2249
|
-
return [3 /*break*/,
|
|
2250
|
-
case
|
|
2251
|
-
case
|
|
2252
|
-
case
|
|
2973
|
+
return [3 /*break*/, 15];
|
|
2974
|
+
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
2975
|
+
case 15: return [3 /*break*/, 30];
|
|
2976
|
+
case 16:
|
|
2253
2977
|
if (arrayableToArray(tools.script).length === 0) {
|
|
2254
2978
|
throw new PipelineExecutionError('No script execution tools are available');
|
|
2255
2979
|
}
|
|
@@ -2258,49 +2982,52 @@ function createPipelineExecutor(options) {
|
|
|
2258
2982
|
}
|
|
2259
2983
|
// TODO: DRY [1]
|
|
2260
2984
|
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;
|
|
2985
|
+
_u.label = 17;
|
|
2266
2986
|
case 17:
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2987
|
+
_u.trys.push([17, 24, 25, 26]);
|
|
2988
|
+
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
2989
|
+
_u.label = 18;
|
|
2270
2990
|
case 18:
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
script: currentTemplate.content,
|
|
2275
|
-
parameters: parametersToPass,
|
|
2276
|
-
})];
|
|
2991
|
+
if (!!_j.done) return [3 /*break*/, 23];
|
|
2992
|
+
scriptTools = _j.value;
|
|
2993
|
+
_u.label = 19;
|
|
2277
2994
|
case 19:
|
|
2278
|
-
|
|
2279
|
-
return [
|
|
2995
|
+
_u.trys.push([19, 21, , 22]);
|
|
2996
|
+
return [4 /*yield*/, scriptTools.execute(deepFreeze({
|
|
2997
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
2998
|
+
script: preparedContent,
|
|
2999
|
+
parameters: parameters,
|
|
3000
|
+
}))];
|
|
2280
3001
|
case 20:
|
|
2281
|
-
|
|
3002
|
+
resultString = _u.sent();
|
|
3003
|
+
return [3 /*break*/, 23];
|
|
3004
|
+
case 21:
|
|
3005
|
+
error_2 = _u.sent();
|
|
2282
3006
|
if (!(error_2 instanceof Error)) {
|
|
2283
3007
|
throw error_2;
|
|
2284
3008
|
}
|
|
3009
|
+
if (error_2 instanceof UnexpectedError) {
|
|
3010
|
+
throw error_2;
|
|
3011
|
+
}
|
|
2285
3012
|
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];
|
|
3013
|
+
return [3 /*break*/, 22];
|
|
3014
|
+
case 22:
|
|
3015
|
+
_j = _h.next();
|
|
3016
|
+
return [3 /*break*/, 18];
|
|
3017
|
+
case 23: return [3 /*break*/, 26];
|
|
2295
3018
|
case 24:
|
|
3019
|
+
e_4_1 = _u.sent();
|
|
3020
|
+
e_4 = { error: e_4_1 };
|
|
3021
|
+
return [3 /*break*/, 26];
|
|
3022
|
+
case 25:
|
|
2296
3023
|
try {
|
|
2297
|
-
if (
|
|
3024
|
+
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
2298
3025
|
}
|
|
2299
|
-
finally { if (
|
|
3026
|
+
finally { if (e_4) throw e_4.error; }
|
|
2300
3027
|
return [7 /*endfinally*/];
|
|
2301
|
-
case
|
|
3028
|
+
case 26:
|
|
2302
3029
|
if (resultString !== null) {
|
|
2303
|
-
return [3 /*break*/,
|
|
3030
|
+
return [3 /*break*/, 30];
|
|
2304
3031
|
}
|
|
2305
3032
|
if (scriptPipelineExecutionErrors.length === 1) {
|
|
2306
3033
|
throw scriptPipelineExecutionErrors[0];
|
|
@@ -2310,101 +3037,104 @@ function createPipelineExecutor(options) {
|
|
|
2310
3037
|
.map(function (error) { return '- ' + error.message; })
|
|
2311
3038
|
.join('\n\n')), "\n "); }));
|
|
2312
3039
|
}
|
|
2313
|
-
case
|
|
3040
|
+
case 27:
|
|
2314
3041
|
if (tools.userInterface === undefined) {
|
|
2315
3042
|
throw new PipelineExecutionError('User interface tools are not available');
|
|
2316
3043
|
}
|
|
2317
|
-
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
3044
|
+
return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
|
|
2318
3045
|
promptTitle: currentTemplate.title,
|
|
2319
|
-
promptMessage: replaceParameters(currentTemplate.description || '',
|
|
2320
|
-
defaultValue: replaceParameters(
|
|
3046
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
3047
|
+
defaultValue: replaceParameters(preparedContent, parameters),
|
|
2321
3048
|
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
2322
3049
|
placeholder: undefined,
|
|
2323
3050
|
priority: priority,
|
|
2324
|
-
})];
|
|
2325
|
-
case
|
|
3051
|
+
}))];
|
|
3052
|
+
case 28:
|
|
2326
3053
|
// 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;
|
|
3054
|
+
resultString = _u.sent();
|
|
3055
|
+
return [3 /*break*/, 30];
|
|
3056
|
+
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
2333
3057
|
case 30:
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
_o.label = 31;
|
|
3058
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
3059
|
+
_u.label = 31;
|
|
2337
3060
|
case 31:
|
|
2338
|
-
|
|
2339
|
-
|
|
3061
|
+
_u.trys.push([31, 45, 46, 47]);
|
|
3062
|
+
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
3063
|
+
_u.label = 32;
|
|
3064
|
+
case 32:
|
|
3065
|
+
if (!!_l.done) return [3 /*break*/, 44];
|
|
3066
|
+
functionName = _l.value;
|
|
2340
3067
|
// TODO: DRY [1]
|
|
2341
3068
|
scriptPipelineExecutionErrors = [];
|
|
2342
3069
|
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;
|
|
3070
|
+
_u.label = 33;
|
|
2348
3071
|
case 33:
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
3072
|
+
_u.trys.push([33, 40, 41, 42]);
|
|
3073
|
+
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
3074
|
+
_u.label = 34;
|
|
2352
3075
|
case 34:
|
|
2353
|
-
_o.
|
|
3076
|
+
if (!!_o.done) return [3 /*break*/, 39];
|
|
3077
|
+
scriptTools = _o.value;
|
|
3078
|
+
_u.label = 35;
|
|
3079
|
+
case 35:
|
|
3080
|
+
_u.trys.push([35, 37, , 38]);
|
|
2354
3081
|
return [4 /*yield*/, scriptTools.execute({
|
|
2355
3082
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2356
3083
|
script: "".concat(functionName, "(resultString)"),
|
|
2357
3084
|
parameters: {
|
|
2358
3085
|
resultString: resultString || '',
|
|
2359
|
-
// Note: No ...
|
|
3086
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2360
3087
|
},
|
|
2361
3088
|
})];
|
|
2362
|
-
case 35:
|
|
2363
|
-
resultString = _o.sent();
|
|
2364
|
-
postprocessingError = null;
|
|
2365
|
-
return [3 /*break*/, 38];
|
|
2366
3089
|
case 36:
|
|
2367
|
-
|
|
3090
|
+
resultString = _u.sent();
|
|
3091
|
+
postprocessingError = null;
|
|
3092
|
+
return [3 /*break*/, 39];
|
|
3093
|
+
case 37:
|
|
3094
|
+
error_3 = _u.sent();
|
|
2368
3095
|
if (!(error_3 instanceof Error)) {
|
|
2369
3096
|
throw error_3;
|
|
2370
3097
|
}
|
|
3098
|
+
if (error_3 instanceof UnexpectedError) {
|
|
3099
|
+
throw error_3;
|
|
3100
|
+
}
|
|
2371
3101
|
postprocessingError = error_3;
|
|
2372
3102
|
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];
|
|
3103
|
+
return [3 /*break*/, 38];
|
|
3104
|
+
case 38:
|
|
3105
|
+
_o = _m.next();
|
|
3106
|
+
return [3 /*break*/, 34];
|
|
3107
|
+
case 39: return [3 /*break*/, 42];
|
|
2382
3108
|
case 40:
|
|
3109
|
+
e_5_1 = _u.sent();
|
|
3110
|
+
e_5 = { error: e_5_1 };
|
|
3111
|
+
return [3 /*break*/, 42];
|
|
3112
|
+
case 41:
|
|
2383
3113
|
try {
|
|
2384
|
-
if (
|
|
3114
|
+
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
2385
3115
|
}
|
|
2386
|
-
finally { if (
|
|
3116
|
+
finally { if (e_5) throw e_5.error; }
|
|
2387
3117
|
return [7 /*endfinally*/];
|
|
2388
|
-
case
|
|
3118
|
+
case 42:
|
|
2389
3119
|
if (postprocessingError) {
|
|
2390
3120
|
throw postprocessingError;
|
|
2391
3121
|
}
|
|
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];
|
|
3122
|
+
_u.label = 43;
|
|
3123
|
+
case 43:
|
|
3124
|
+
_l = _k.next();
|
|
3125
|
+
return [3 /*break*/, 32];
|
|
3126
|
+
case 44: return [3 /*break*/, 47];
|
|
2401
3127
|
case 45:
|
|
3128
|
+
e_6_1 = _u.sent();
|
|
3129
|
+
e_6 = { error: e_6_1 };
|
|
3130
|
+
return [3 /*break*/, 47];
|
|
3131
|
+
case 46:
|
|
2402
3132
|
try {
|
|
2403
|
-
if (
|
|
3133
|
+
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
2404
3134
|
}
|
|
2405
|
-
finally { if (
|
|
3135
|
+
finally { if (e_6) throw e_6.error; }
|
|
2406
3136
|
return [7 /*endfinally*/];
|
|
2407
|
-
case
|
|
3137
|
+
case 47:
|
|
2408
3138
|
// TODO: [💝] Unite object for expecting amount and format
|
|
2409
3139
|
if (currentTemplate.expectFormat) {
|
|
2410
3140
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
@@ -2417,15 +3147,18 @@ function createPipelineExecutor(options) {
|
|
|
2417
3147
|
if (currentTemplate.expectations) {
|
|
2418
3148
|
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
2419
3149
|
}
|
|
2420
|
-
return [3 /*break*/,
|
|
2421
|
-
case
|
|
2422
|
-
error_4 =
|
|
3150
|
+
return [3 /*break*/, 52];
|
|
3151
|
+
case 48:
|
|
3152
|
+
error_4 = _u.sent();
|
|
2423
3153
|
if (!(error_4 instanceof ExpectError)) {
|
|
2424
3154
|
throw error_4;
|
|
2425
3155
|
}
|
|
3156
|
+
if (error_4 instanceof UnexpectedError) {
|
|
3157
|
+
throw error_4;
|
|
3158
|
+
}
|
|
2426
3159
|
expectError = error_4;
|
|
2427
|
-
return [3 /*break*/,
|
|
2428
|
-
case
|
|
3160
|
+
return [3 /*break*/, 50];
|
|
3161
|
+
case 49:
|
|
2429
3162
|
if (!isJokerAttempt &&
|
|
2430
3163
|
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
2431
3164
|
prompt
|
|
@@ -2434,28 +3167,21 @@ function createPipelineExecutor(options) {
|
|
|
2434
3167
|
) {
|
|
2435
3168
|
// TODO: [🧠] Maybe put other blockTypes into report
|
|
2436
3169
|
executionReport.promptExecutions.push({
|
|
2437
|
-
prompt: {
|
|
2438
|
-
title: currentTemplate.title /* <- Note: If title in pipeline contains emojis, pass it innto report */,
|
|
2439
|
-
content: prompt.content,
|
|
2440
|
-
modelRequirements: prompt.modelRequirements,
|
|
2441
|
-
expectations: prompt.expectations,
|
|
2442
|
-
expectFormat: prompt.expectFormat,
|
|
2443
|
-
// <- Note: Do want to pass ONLY wanted information to the report
|
|
2444
|
-
},
|
|
3170
|
+
prompt: __assign({}, prompt),
|
|
2445
3171
|
result: result || undefined,
|
|
2446
3172
|
error: expectError || undefined,
|
|
2447
3173
|
});
|
|
2448
3174
|
}
|
|
2449
3175
|
return [7 /*endfinally*/];
|
|
2450
|
-
case
|
|
3176
|
+
case 50:
|
|
2451
3177
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
2452
3178
|
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
3179
|
}
|
|
2454
|
-
|
|
2455
|
-
case 50:
|
|
2456
|
-
attempt++;
|
|
2457
|
-
return [3 /*break*/, 3];
|
|
3180
|
+
_u.label = 51;
|
|
2458
3181
|
case 51:
|
|
3182
|
+
attempt++;
|
|
3183
|
+
return [3 /*break*/, 4];
|
|
3184
|
+
case 52:
|
|
2459
3185
|
if (resultString === null) {
|
|
2460
3186
|
throw new UnexpectedError('Something went wrong and prompt result is null');
|
|
2461
3187
|
}
|
|
@@ -2471,30 +3197,136 @@ function createPipelineExecutor(options) {
|
|
|
2471
3197
|
// <- [3]
|
|
2472
3198
|
});
|
|
2473
3199
|
}
|
|
2474
|
-
parametersToPass = __assign(__assign({}, parametersToPass), (
|
|
3200
|
+
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
3201
|
return [2 /*return*/];
|
|
2476
3202
|
}
|
|
2477
3203
|
});
|
|
2478
3204
|
});
|
|
2479
3205
|
}
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
3206
|
+
function filterJustOutputParameters() {
|
|
3207
|
+
var e_9, _a;
|
|
3208
|
+
var outputParameters = {};
|
|
3209
|
+
try {
|
|
3210
|
+
// Note: Filter ONLY output parameters
|
|
3211
|
+
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
3212
|
+
var isOutput = _a.isOutput;
|
|
3213
|
+
return isOutput;
|
|
3214
|
+
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3215
|
+
var parameter = _c.value;
|
|
3216
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3217
|
+
// [4]
|
|
3218
|
+
warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
|
|
3219
|
+
continue;
|
|
3220
|
+
}
|
|
3221
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
3225
|
+
finally {
|
|
3226
|
+
try {
|
|
3227
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3228
|
+
}
|
|
3229
|
+
finally { if (e_9) throw e_9.error; }
|
|
3230
|
+
}
|
|
3231
|
+
return outputParameters;
|
|
3232
|
+
}
|
|
3233
|
+
var errors, warnings, executionReport, _a, _b, parameter, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
3234
|
+
var e_1, _e, e_2, _f;
|
|
3235
|
+
return __generator(this, function (_g) {
|
|
3236
|
+
switch (_g.label) {
|
|
2484
3237
|
case 0:
|
|
2485
|
-
|
|
3238
|
+
if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
|
|
3239
|
+
return [4 /*yield*/, preparePipeline(pipeline, {
|
|
3240
|
+
llmTools: llmTools,
|
|
3241
|
+
isVerbose: isVerbose,
|
|
3242
|
+
maxParallelCount: maxParallelCount,
|
|
3243
|
+
})];
|
|
3244
|
+
case 1:
|
|
3245
|
+
preparedPipeline = _g.sent();
|
|
3246
|
+
_g.label = 2;
|
|
3247
|
+
case 2:
|
|
3248
|
+
errors = [];
|
|
3249
|
+
warnings = [];
|
|
2486
3250
|
executionReport = {
|
|
2487
|
-
pipelineUrl:
|
|
2488
|
-
title:
|
|
3251
|
+
pipelineUrl: preparedPipeline.pipelineUrl,
|
|
3252
|
+
title: preparedPipeline.title,
|
|
2489
3253
|
promptbookUsedVersion: PROMPTBOOK_VERSION,
|
|
2490
|
-
promptbookRequestedVersion:
|
|
2491
|
-
description:
|
|
3254
|
+
promptbookRequestedVersion: preparedPipeline.promptbookVersion,
|
|
3255
|
+
description: preparedPipeline.description,
|
|
2492
3256
|
promptExecutions: [],
|
|
2493
3257
|
};
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
3258
|
+
try {
|
|
3259
|
+
// Note: Check that all input input parameters are defined
|
|
3260
|
+
for (_a = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
3261
|
+
var isInput = _a.isInput;
|
|
3262
|
+
return isInput;
|
|
3263
|
+
})), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3264
|
+
parameter = _b.value;
|
|
3265
|
+
if (inputParameters[parameter.name] === undefined) {
|
|
3266
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
3267
|
+
isSuccessful: false,
|
|
3268
|
+
errors: __spreadArray([
|
|
3269
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
|
|
3270
|
+
], __read(errors), false),
|
|
3271
|
+
warnings: [],
|
|
3272
|
+
executionReport: executionReport,
|
|
3273
|
+
outputParameters: {},
|
|
3274
|
+
usage: ZERO_USAGE,
|
|
3275
|
+
preparedPipeline: preparedPipeline,
|
|
3276
|
+
})];
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3281
|
+
finally {
|
|
3282
|
+
try {
|
|
3283
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
3284
|
+
}
|
|
3285
|
+
finally { if (e_1) throw e_1.error; }
|
|
3286
|
+
}
|
|
3287
|
+
_loop_1 = function (parameterName) {
|
|
3288
|
+
var parameter = preparedPipeline.parameters.find(function (_a) {
|
|
3289
|
+
var name = _a.name;
|
|
3290
|
+
return name === parameterName;
|
|
3291
|
+
});
|
|
3292
|
+
if (parameter === undefined) {
|
|
3293
|
+
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3294
|
+
}
|
|
3295
|
+
else if (parameter.isInput === false) {
|
|
3296
|
+
return { value: deepFreezeWithSameType({
|
|
3297
|
+
isSuccessful: false,
|
|
3298
|
+
errors: __spreadArray([
|
|
3299
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3300
|
+
], __read(errors), false),
|
|
3301
|
+
warnings: warnings,
|
|
3302
|
+
executionReport: executionReport,
|
|
3303
|
+
outputParameters: {},
|
|
3304
|
+
usage: ZERO_USAGE,
|
|
3305
|
+
preparedPipeline: preparedPipeline,
|
|
3306
|
+
}) };
|
|
3307
|
+
}
|
|
3308
|
+
};
|
|
3309
|
+
try {
|
|
3310
|
+
// Note: Check that no extra input parameters are passed
|
|
3311
|
+
for (_c = __values(Object.keys(inputParameters)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3312
|
+
parameterName = _d.value;
|
|
3313
|
+
state_1 = _loop_1(parameterName);
|
|
3314
|
+
if (typeof state_1 === "object")
|
|
3315
|
+
return [2 /*return*/, state_1.value];
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3319
|
+
finally {
|
|
3320
|
+
try {
|
|
3321
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
3322
|
+
}
|
|
3323
|
+
finally { if (e_2) throw e_2.error; }
|
|
3324
|
+
}
|
|
3325
|
+
parametersToPass = inputParameters;
|
|
3326
|
+
_g.label = 3;
|
|
3327
|
+
case 3:
|
|
3328
|
+
_g.trys.push([3, 8, , 9]);
|
|
3329
|
+
resovedParameterNames_1 = preparedPipeline.parameters
|
|
2498
3330
|
.filter(function (_a) {
|
|
2499
3331
|
var isInput = _a.isInput;
|
|
2500
3332
|
return isInput;
|
|
@@ -2503,187 +3335,191 @@ function createPipelineExecutor(options) {
|
|
|
2503
3335
|
var name = _a.name;
|
|
2504
3336
|
return name;
|
|
2505
3337
|
});
|
|
2506
|
-
|
|
3338
|
+
unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.promptTemplates), false);
|
|
2507
3339
|
resolving_1 = [];
|
|
2508
3340
|
loopLimit = LOOP_LIMIT;
|
|
2509
|
-
|
|
3341
|
+
_loop_2 = function () {
|
|
2510
3342
|
var currentTemplate, work_1;
|
|
2511
|
-
return __generator(this, function (
|
|
2512
|
-
switch (
|
|
3343
|
+
return __generator(this, function (_h) {
|
|
3344
|
+
switch (_h.label) {
|
|
2513
3345
|
case 0:
|
|
2514
3346
|
if (loopLimit-- < 0) {
|
|
3347
|
+
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
2515
3348
|
throw new UnexpectedError('Loop limit reached during resolving parameters pipeline execution');
|
|
2516
3349
|
}
|
|
2517
|
-
currentTemplate =
|
|
2518
|
-
return template.dependentParameterNames.every(function (name) {
|
|
3350
|
+
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3351
|
+
return template.dependentParameterNames.every(function (name) {
|
|
3352
|
+
return __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), __read(RESERVED_PARAMETER_NAMES), false).includes(name);
|
|
3353
|
+
});
|
|
2519
3354
|
});
|
|
2520
3355
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
2521
|
-
throw new UnexpectedError(
|
|
3356
|
+
throw new UnexpectedError(
|
|
3357
|
+
// TODO: [🐎] DRY
|
|
3358
|
+
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3359
|
+
.map(function (_a) {
|
|
3360
|
+
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3361
|
+
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
3362
|
+
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
3363
|
+
.join(' and '));
|
|
3364
|
+
})
|
|
3365
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameterNames_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
|
|
2522
3366
|
case 1:
|
|
2523
3367
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
2524
3368
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
2525
3369
|
case 2:
|
|
2526
|
-
/* [5] */
|
|
3370
|
+
/* [5] */ _h.sent();
|
|
2527
3371
|
return [3 /*break*/, 4];
|
|
2528
3372
|
case 3:
|
|
2529
|
-
|
|
3373
|
+
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
2530
3374
|
work_1 = executeSingleTemplate(currentTemplate)
|
|
2531
3375
|
.then(function () {
|
|
2532
|
-
|
|
3376
|
+
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
|
|
2533
3377
|
})
|
|
2534
3378
|
.then(function () {
|
|
2535
3379
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
2536
3380
|
});
|
|
2537
3381
|
resolving_1.push(work_1);
|
|
2538
|
-
|
|
3382
|
+
_h.label = 4;
|
|
2539
3383
|
case 4: return [2 /*return*/];
|
|
2540
3384
|
}
|
|
2541
3385
|
});
|
|
2542
3386
|
};
|
|
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)];
|
|
3387
|
+
_g.label = 4;
|
|
3388
|
+
case 4:
|
|
3389
|
+
if (!(unresovedTemplates_1.length > 0)) return [3 /*break*/, 6];
|
|
3390
|
+
return [5 /*yield**/, _loop_2()];
|
|
2551
3391
|
case 5:
|
|
2552
|
-
|
|
2553
|
-
return [3 /*break*/,
|
|
2554
|
-
case 6:
|
|
2555
|
-
|
|
3392
|
+
_g.sent();
|
|
3393
|
+
return [3 /*break*/, 4];
|
|
3394
|
+
case 6: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
3395
|
+
case 7:
|
|
3396
|
+
_g.sent();
|
|
3397
|
+
return [3 /*break*/, 9];
|
|
3398
|
+
case 8:
|
|
3399
|
+
error_1 = _g.sent();
|
|
2556
3400
|
if (!(error_1 instanceof Error)) {
|
|
2557
3401
|
throw error_1;
|
|
2558
3402
|
}
|
|
2559
3403
|
usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
2560
3404
|
var result = _a.result;
|
|
2561
|
-
return (result === null || result === void 0 ? void 0 : result.usage) ||
|
|
3405
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2562
3406
|
})), false));
|
|
2563
|
-
|
|
3407
|
+
outputParameters_1 = filterJustOutputParameters();
|
|
3408
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2564
3409
|
isSuccessful: false,
|
|
2565
|
-
errors: [error_1],
|
|
3410
|
+
errors: __spreadArray([error_1], __read(errors), false),
|
|
3411
|
+
warnings: warnings,
|
|
2566
3412
|
usage: usage_1,
|
|
2567
3413
|
executionReport: executionReport,
|
|
2568
|
-
outputParameters:
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
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
|
-
}
|
|
3414
|
+
outputParameters: outputParameters_1,
|
|
3415
|
+
preparedPipeline: preparedPipeline,
|
|
3416
|
+
})];
|
|
3417
|
+
case 9:
|
|
2588
3418
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
2589
3419
|
var result = _a.result;
|
|
2590
|
-
return (result === null || result === void 0 ? void 0 : result.usage) ||
|
|
3420
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2591
3421
|
})), false));
|
|
2592
|
-
|
|
3422
|
+
outputParameters = filterJustOutputParameters();
|
|
3423
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2593
3424
|
isSuccessful: true,
|
|
2594
|
-
errors:
|
|
3425
|
+
errors: errors,
|
|
3426
|
+
warnings: warnings,
|
|
2595
3427
|
usage: usage,
|
|
2596
3428
|
executionReport: executionReport,
|
|
2597
|
-
outputParameters:
|
|
2598
|
-
|
|
3429
|
+
outputParameters: outputParameters,
|
|
3430
|
+
preparedPipeline: preparedPipeline,
|
|
3431
|
+
})];
|
|
2599
3432
|
}
|
|
2600
3433
|
});
|
|
2601
3434
|
}); };
|
|
2602
3435
|
return pipelineExecutor;
|
|
2603
3436
|
}
|
|
2604
3437
|
/**
|
|
3438
|
+
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3439
|
+
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
3440
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
2605
3441
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2606
3442
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2607
3443
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2608
3444
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
3445
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3446
|
+
* TODO: [🧠][💷] `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result BUT maybe NOT to preserve pure JSON object
|
|
2609
3447
|
*/
|
|
2610
3448
|
|
|
2611
|
-
|
|
3449
|
+
/**
|
|
3450
|
+
* @@@
|
|
3451
|
+
*/
|
|
3452
|
+
function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
2612
3453
|
return __awaiter(this, void 0, void 0, function () {
|
|
2613
|
-
var
|
|
2614
|
-
var
|
|
3454
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
|
|
3455
|
+
var _f, _g, _h;
|
|
2615
3456
|
var _this = this;
|
|
2616
|
-
return __generator(this, function (
|
|
2617
|
-
switch (
|
|
3457
|
+
return __generator(this, function (_j) {
|
|
3458
|
+
switch (_j.label) {
|
|
2618
3459
|
case 0:
|
|
2619
|
-
|
|
3460
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
3461
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2620
3462
|
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
3463
|
_c = createPipelineExecutor;
|
|
2631
3464
|
_f = {};
|
|
2632
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2633
|
-
case
|
|
2634
|
-
|
|
3465
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
3466
|
+
case 1:
|
|
3467
|
+
prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
|
|
2635
3468
|
_f.tools = {
|
|
2636
3469
|
llm: llmTools,
|
|
2637
3470
|
},
|
|
2638
3471
|
_f)]);
|
|
2639
3472
|
_d = createPipelineExecutor;
|
|
2640
3473
|
_g = {};
|
|
2641
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2642
|
-
case
|
|
2643
|
-
|
|
3474
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
|
|
3475
|
+
case 2:
|
|
3476
|
+
prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
|
|
2644
3477
|
_g.tools = {
|
|
2645
3478
|
llm: llmTools,
|
|
2646
3479
|
},
|
|
2647
3480
|
_g)]);
|
|
2648
|
-
|
|
3481
|
+
_e = createPipelineExecutor;
|
|
3482
|
+
_h = {};
|
|
3483
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
|
|
3484
|
+
case 3:
|
|
3485
|
+
prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
|
|
3486
|
+
_h.tools = {
|
|
3487
|
+
llm: llmTools,
|
|
3488
|
+
},
|
|
3489
|
+
_h)]);
|
|
3490
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
|
|
2649
3491
|
case 4:
|
|
2650
|
-
result =
|
|
2651
|
-
// TODO: [0] !!! Aggeregate usage
|
|
3492
|
+
result = _j.sent();
|
|
2652
3493
|
assertsExecutionSuccessful(result);
|
|
2653
3494
|
outputParameters = result.outputParameters;
|
|
2654
|
-
|
|
2655
|
-
knowledgeTextPieces = (
|
|
3495
|
+
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
3496
|
+
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
3497
|
+
// <- TODO: !!!!! Smarter split and filter out empty pieces
|
|
2656
3498
|
if (isVerbose) {
|
|
2657
3499
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
2658
3500
|
}
|
|
2659
3501
|
return [4 /*yield*/, Promise.all(
|
|
2660
|
-
// TODO:
|
|
3502
|
+
// TODO: [🪂] !! Do not send all at once but in chunks
|
|
2661
3503
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2662
|
-
var name, title,
|
|
3504
|
+
var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
2663
3505
|
return __generator(this, function (_c) {
|
|
2664
3506
|
switch (_c.label) {
|
|
2665
3507
|
case 0:
|
|
2666
3508
|
name = "piece-".concat(i);
|
|
2667
3509
|
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
2668
|
-
|
|
3510
|
+
knowledgePieceContent = spaceTrim(knowledgeTextPiece);
|
|
2669
3511
|
keywords = [];
|
|
2670
3512
|
index = [];
|
|
2671
|
-
sources = [
|
|
2672
|
-
{
|
|
2673
|
-
title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
|
|
2674
|
-
href: '#' /* <- TODO: !!! Unhardcode */,
|
|
2675
|
-
},
|
|
2676
|
-
];
|
|
2677
3513
|
_c.label = 1;
|
|
2678
3514
|
case 1:
|
|
2679
3515
|
_c.trys.push([1, 7, , 8]);
|
|
2680
|
-
return [4 /*yield*/, prepareTitleExecutor({
|
|
3516
|
+
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
2681
3517
|
case 2:
|
|
2682
3518
|
titleResult = _c.sent();
|
|
2683
3519
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
2684
3520
|
title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
2685
3521
|
name = titleToName(title);
|
|
2686
|
-
return [4 /*yield*/, prepareKeywordsExecutor({
|
|
3522
|
+
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
2687
3523
|
case 3:
|
|
2688
3524
|
keywordsResult = _c.sent();
|
|
2689
3525
|
_b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
|
|
@@ -2701,14 +3537,13 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2701
3537
|
case 4: return [4 /*yield*/, llmTools.callEmbeddingModel({
|
|
2702
3538
|
title: "Embedding for ".concat(title) /* <- Note: No impact on embedding result itself, just for logging */,
|
|
2703
3539
|
parameters: {},
|
|
2704
|
-
content:
|
|
3540
|
+
content: knowledgePieceContent,
|
|
2705
3541
|
modelRequirements: {
|
|
2706
3542
|
modelVariant: 'EMBEDDING',
|
|
2707
3543
|
},
|
|
2708
3544
|
})];
|
|
2709
3545
|
case 5:
|
|
2710
3546
|
embeddingResult = _c.sent();
|
|
2711
|
-
// TODO: [0] !!! Aggeregate usage embeddingResult.usage
|
|
2712
3547
|
index.push({
|
|
2713
3548
|
modelName: embeddingResult.modelName,
|
|
2714
3549
|
position: embeddingResult.content,
|
|
@@ -2723,24 +3558,461 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2723
3558
|
case 8: return [2 /*return*/, {
|
|
2724
3559
|
name: name,
|
|
2725
3560
|
title: title,
|
|
2726
|
-
content:
|
|
3561
|
+
content: knowledgePieceContent,
|
|
2727
3562
|
keywords: keywords,
|
|
2728
3563
|
index: index,
|
|
2729
|
-
|
|
3564
|
+
// <- TODO: [☀] sources,
|
|
2730
3565
|
}];
|
|
2731
3566
|
}
|
|
2732
3567
|
});
|
|
2733
3568
|
}); }))];
|
|
2734
3569
|
case 5:
|
|
2735
|
-
knowledge =
|
|
3570
|
+
knowledge = _j.sent();
|
|
2736
3571
|
return [2 /*return*/, knowledge];
|
|
2737
3572
|
}
|
|
2738
3573
|
});
|
|
2739
|
-
});
|
|
2740
|
-
}
|
|
3574
|
+
});
|
|
3575
|
+
}
|
|
3576
|
+
/**
|
|
3577
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/markdown`
|
|
3578
|
+
* TODO: [🪂] Do it in parallel 11:11
|
|
3579
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
3580
|
+
*/
|
|
3581
|
+
|
|
3582
|
+
/**
|
|
3583
|
+
* Prepares the knowle
|
|
3584
|
+
*
|
|
3585
|
+
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
3586
|
+
*/
|
|
3587
|
+
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
3588
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3589
|
+
var _a, maxParallelCount, knowledgePrepared;
|
|
3590
|
+
var _this = this;
|
|
3591
|
+
return __generator(this, function (_b) {
|
|
3592
|
+
switch (_b.label) {
|
|
3593
|
+
case 0:
|
|
3594
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3595
|
+
knowledgePrepared = [];
|
|
3596
|
+
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
|
|
3597
|
+
var partialPieces, pieces;
|
|
3598
|
+
return __generator(this, function (_a) {
|
|
3599
|
+
switch (_a.label) {
|
|
3600
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is
|
|
3601
|
+
options)];
|
|
3602
|
+
case 1:
|
|
3603
|
+
partialPieces = _a.sent();
|
|
3604
|
+
pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
|
|
3605
|
+
{
|
|
3606
|
+
name: knowledgeSource.name,
|
|
3607
|
+
// line, column <- TODO: [☀]
|
|
3608
|
+
// <- TODO: [❎]
|
|
3609
|
+
},
|
|
3610
|
+
] })); });
|
|
3611
|
+
knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
|
|
3612
|
+
return [2 /*return*/];
|
|
3613
|
+
}
|
|
3614
|
+
});
|
|
3615
|
+
}); })];
|
|
3616
|
+
case 1:
|
|
3617
|
+
_b.sent();
|
|
3618
|
+
return [2 /*return*/, knowledgePrepared];
|
|
3619
|
+
}
|
|
3620
|
+
});
|
|
3621
|
+
});
|
|
3622
|
+
}
|
|
3623
|
+
/*
|
|
3624
|
+
TODO: [🧊] This is how it can look in future
|
|
3625
|
+
> type PrepareKnowledgeKnowledge = {
|
|
3626
|
+
> /**
|
|
3627
|
+
> * Unprepared knowledge
|
|
3628
|
+
> * /
|
|
3629
|
+
> readonly knowledgeSources: Array<KnowledgeSourceJson>;
|
|
3630
|
+
> };
|
|
3631
|
+
>
|
|
3632
|
+
> export async function prepareKnowledgePieces(
|
|
3633
|
+
> knowledge: PrepareKnowledgeKnowledge,
|
|
3634
|
+
> options: PrepareOptions,
|
|
3635
|
+
> ):
|
|
3636
|
+
*/
|
|
3637
|
+
/**
|
|
3638
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/core`
|
|
3639
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3640
|
+
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
3641
|
+
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
3642
|
+
* TODO: [🧠][❎] Do here propper M:N mapping
|
|
3643
|
+
* [x] One source can make multiple pieces
|
|
3644
|
+
* [ ] One piece can have multiple sources
|
|
3645
|
+
*/
|
|
3646
|
+
|
|
3647
|
+
/**
|
|
3648
|
+
* Prepares the persona for the pipeline
|
|
3649
|
+
*
|
|
3650
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
3651
|
+
*/
|
|
3652
|
+
function preparePersona(personaDescription, options) {
|
|
3653
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3654
|
+
var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
3655
|
+
var _c;
|
|
3656
|
+
return __generator(this, function (_d) {
|
|
3657
|
+
switch (_d.label) {
|
|
3658
|
+
case 0:
|
|
3659
|
+
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
3660
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
3661
|
+
_b = createPipelineExecutor;
|
|
3662
|
+
_c = {};
|
|
3663
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
|
|
3664
|
+
case 1:
|
|
3665
|
+
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
3666
|
+
_c.tools = {
|
|
3667
|
+
llm: llmTools,
|
|
3668
|
+
},
|
|
3669
|
+
_c)]);
|
|
3670
|
+
return [4 /*yield*/, llmTools.listModels()];
|
|
3671
|
+
case 2:
|
|
3672
|
+
availableModels = _d.sent();
|
|
3673
|
+
availableModelNames = availableModels
|
|
3674
|
+
.filter(function (_a) {
|
|
3675
|
+
var modelVariant = _a.modelVariant;
|
|
3676
|
+
return modelVariant === 'CHAT';
|
|
3677
|
+
})
|
|
3678
|
+
.map(function (_a) {
|
|
3679
|
+
var modelName = _a.modelName;
|
|
3680
|
+
return modelName;
|
|
3681
|
+
})
|
|
3682
|
+
.join(',');
|
|
3683
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
3684
|
+
case 3:
|
|
3685
|
+
result = _d.sent();
|
|
3686
|
+
assertsExecutionSuccessful(result);
|
|
3687
|
+
outputParameters = result.outputParameters;
|
|
3688
|
+
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
3689
|
+
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
3690
|
+
if (isVerbose) {
|
|
3691
|
+
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
3692
|
+
}
|
|
3693
|
+
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
3694
|
+
return [2 /*return*/, {
|
|
3695
|
+
modelVariant: 'CHAT',
|
|
3696
|
+
modelName: modelName,
|
|
3697
|
+
systemMessage: systemMessage,
|
|
3698
|
+
temperature: temperature,
|
|
3699
|
+
}];
|
|
3700
|
+
}
|
|
3701
|
+
});
|
|
3702
|
+
});
|
|
3703
|
+
}
|
|
3704
|
+
/**
|
|
3705
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3706
|
+
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
3707
|
+
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
3708
|
+
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
3709
|
+
*/
|
|
3710
|
+
|
|
3711
|
+
/**
|
|
3712
|
+
* @@@
|
|
3713
|
+
*/
|
|
3714
|
+
function prepareTemplates(pipeline, options) {
|
|
3715
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3716
|
+
var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
|
|
3717
|
+
var _this = this;
|
|
3718
|
+
return __generator(this, function (_b) {
|
|
3719
|
+
switch (_b.label) {
|
|
3720
|
+
case 0:
|
|
3721
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3722
|
+
promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3723
|
+
// TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
3724
|
+
TODO_USE(parameters);
|
|
3725
|
+
promptTemplatesPrepared = new Array(promptTemplates.length);
|
|
3726
|
+
return [4 /*yield*/, forEachAsync(promptTemplates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3727
|
+
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
3728
|
+
return __generator(this, function (_a) {
|
|
3729
|
+
dependentParameterNames = template.dependentParameterNames;
|
|
3730
|
+
preparedContent = undefined;
|
|
3731
|
+
if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
|
|
3732
|
+
preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
3733
|
+
// <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
|
|
3734
|
+
dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
|
|
3735
|
+
'knowledge',
|
|
3736
|
+
], false);
|
|
3737
|
+
}
|
|
3738
|
+
preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
|
|
3739
|
+
promptTemplatesPrepared[index] = preparedTemplate;
|
|
3740
|
+
return [2 /*return*/];
|
|
3741
|
+
});
|
|
3742
|
+
}); })];
|
|
3743
|
+
case 1:
|
|
3744
|
+
_b.sent();
|
|
3745
|
+
return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
|
|
3746
|
+
}
|
|
3747
|
+
});
|
|
3748
|
+
});
|
|
3749
|
+
}
|
|
3750
|
+
/**
|
|
3751
|
+
* TODO: [🧠] Add context to each template (if missing)
|
|
3752
|
+
* TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
3753
|
+
* TODO: [♨] !!! Prepare index the samples and maybe templates
|
|
3754
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3755
|
+
* TODO: Write tests for `preparePipeline`
|
|
3756
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3757
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3758
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3759
|
+
* TODO: [🧠][🥜]
|
|
3760
|
+
*/
|
|
3761
|
+
|
|
3762
|
+
/**
|
|
3763
|
+
* Prepare pipeline from string (markdown) format to JSON format
|
|
3764
|
+
*
|
|
3765
|
+
* Note: This function does not validate logic of the pipeline
|
|
3766
|
+
* Note: This function acts as part of compilation process
|
|
3767
|
+
*/
|
|
3768
|
+
function preparePipeline(pipeline, options) {
|
|
3769
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3770
|
+
var _a, maxParallelCount, parameters, promptTemplates,
|
|
3771
|
+
/*
|
|
3772
|
+
<- TODO: [🧠][0] `promptbookVersion` */
|
|
3773
|
+
knowledgeSources /*
|
|
3774
|
+
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3775
|
+
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3776
|
+
var _this = this;
|
|
3777
|
+
return __generator(this, function (_b) {
|
|
3778
|
+
switch (_b.label) {
|
|
3779
|
+
case 0:
|
|
3780
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3781
|
+
parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3782
|
+
currentPreparation = {
|
|
3783
|
+
id: 1,
|
|
3784
|
+
// TODO: [🍥]> date: $currentDate(),
|
|
3785
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
3786
|
+
modelUsage: ZERO_USAGE,
|
|
3787
|
+
};
|
|
3788
|
+
preparations = [
|
|
3789
|
+
// ...preparations
|
|
3790
|
+
// <- TODO: [🧊]
|
|
3791
|
+
currentPreparation,
|
|
3792
|
+
];
|
|
3793
|
+
preparedPersonas = new Array(personas.length);
|
|
3794
|
+
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 () {
|
|
3795
|
+
var modelRequirements, preparedPersona;
|
|
3796
|
+
return __generator(this, function (_a) {
|
|
3797
|
+
switch (_a.label) {
|
|
3798
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
|
|
3799
|
+
case 1:
|
|
3800
|
+
modelRequirements = _a.sent();
|
|
3801
|
+
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
3802
|
+
preparedPersonas[index] = preparedPersona;
|
|
3803
|
+
return [2 /*return*/];
|
|
3804
|
+
}
|
|
3805
|
+
});
|
|
3806
|
+
}); })];
|
|
3807
|
+
case 1:
|
|
3808
|
+
_b.sent();
|
|
3809
|
+
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3810
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
|
|
3811
|
+
case 2:
|
|
3812
|
+
partialknowledgePiecesPrepared = _b.sent();
|
|
3813
|
+
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3814
|
+
return [4 /*yield*/, prepareTemplates({
|
|
3815
|
+
parameters: parameters,
|
|
3816
|
+
promptTemplates: promptTemplates,
|
|
3817
|
+
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
3818
|
+
}, options)];
|
|
3819
|
+
case 3:
|
|
3820
|
+
promptTemplatesPrepared = (_b.sent()).promptTemplatesPrepared;
|
|
3821
|
+
// ----- /Templates preparation -----
|
|
3822
|
+
return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3823
|
+
}
|
|
3824
|
+
});
|
|
3825
|
+
});
|
|
3826
|
+
}
|
|
3827
|
+
/**
|
|
3828
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3829
|
+
* TODO: Write tests for `preparePipeline`
|
|
3830
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3831
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3832
|
+
* TODO: [🎐] !!!!! Use here countTotalUsage
|
|
3833
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3834
|
+
*/
|
|
3835
|
+
|
|
3836
|
+
/**
|
|
3837
|
+
* Tests if given string is valid URL.
|
|
3838
|
+
*
|
|
3839
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
3840
|
+
*/
|
|
3841
|
+
function isValidFilePath(filePath) {
|
|
3842
|
+
if (typeof filePath !== 'string') {
|
|
3843
|
+
return false;
|
|
3844
|
+
}
|
|
3845
|
+
var filePathSlashes = filePath.split('\\').join('/');
|
|
3846
|
+
// Absolute Unix path: /hello.txt
|
|
3847
|
+
if (/^(\/)/i.test(filePathSlashes)) {
|
|
3848
|
+
return true;
|
|
3849
|
+
}
|
|
3850
|
+
// Absolute Windows path: /hello.txt
|
|
3851
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
3852
|
+
return true;
|
|
3853
|
+
}
|
|
3854
|
+
// Relative path: ./hello.txt
|
|
3855
|
+
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
3856
|
+
return true;
|
|
3857
|
+
}
|
|
3858
|
+
return false;
|
|
3859
|
+
}
|
|
3860
|
+
|
|
3861
|
+
/**
|
|
3862
|
+
* Parses the knowledge command
|
|
3863
|
+
*
|
|
3864
|
+
* @see ./KNOWLEDGE-README.md for more details
|
|
3865
|
+
* @private within the commands folder
|
|
3866
|
+
*/
|
|
3867
|
+
var knowledgeCommandParser = {
|
|
3868
|
+
/**
|
|
3869
|
+
* Name of the command
|
|
3870
|
+
*/
|
|
3871
|
+
name: 'KNOWLEDGE',
|
|
3872
|
+
/**
|
|
3873
|
+
* BOILERPLATE command can be used in:
|
|
3874
|
+
*/
|
|
3875
|
+
usagePlaces: ['PIPELINE_HEAD'],
|
|
3876
|
+
/**
|
|
3877
|
+
* Description of the KNOWLEDGE command
|
|
3878
|
+
*/
|
|
3879
|
+
description: "Tells promptbook which external knowledge to use",
|
|
3880
|
+
/**
|
|
3881
|
+
* Link to discussion
|
|
3882
|
+
*/
|
|
3883
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3884
|
+
/**
|
|
3885
|
+
* Example usages of the KNOWLEDGE command
|
|
3886
|
+
*/
|
|
3887
|
+
examples: [
|
|
3888
|
+
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
3889
|
+
'KNOWLEDGE ./hejny-cv.txt',
|
|
3890
|
+
'KNOWLEDGE ./hejny-cv.md',
|
|
3891
|
+
'KNOWLEDGE ./hejny-cv.pdf',
|
|
3892
|
+
'KNOWLEDGE ./hejny-cv.docx',
|
|
3893
|
+
],
|
|
3894
|
+
/**
|
|
3895
|
+
* Parses the KNOWLEDGE command
|
|
3896
|
+
*/
|
|
3897
|
+
parse: function (input) {
|
|
3898
|
+
var args = input.args;
|
|
3899
|
+
var source = args[0];
|
|
3900
|
+
if (source === undefined) {
|
|
3901
|
+
throw new ParsingError("Source is not defined");
|
|
3902
|
+
}
|
|
3903
|
+
if (source.startsWith('http://')) {
|
|
3904
|
+
throw new ParsingError("Source is not secure");
|
|
3905
|
+
}
|
|
3906
|
+
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
3907
|
+
throw new ParsingError("Source not valid");
|
|
3908
|
+
}
|
|
3909
|
+
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
3910
|
+
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
3911
|
+
}
|
|
3912
|
+
return {
|
|
3913
|
+
type: 'KNOWLEDGE',
|
|
3914
|
+
source: source,
|
|
3915
|
+
};
|
|
3916
|
+
},
|
|
3917
|
+
/**
|
|
3918
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3919
|
+
*/
|
|
3920
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3921
|
+
var source = personaCommand.source;
|
|
3922
|
+
var pipelineJson = subjects.pipelineJson;
|
|
3923
|
+
var name = titleToName(source);
|
|
3924
|
+
pipelineJson.knowledgeSources.push({
|
|
3925
|
+
name: name,
|
|
3926
|
+
source: source,
|
|
3927
|
+
});
|
|
3928
|
+
},
|
|
3929
|
+
};
|
|
3930
|
+
|
|
2741
3931
|
/**
|
|
2742
|
-
*
|
|
3932
|
+
* Parses the persona command
|
|
3933
|
+
*
|
|
3934
|
+
* @see ./PERSONA-README.md for more details
|
|
3935
|
+
* @private within the commands folder
|
|
2743
3936
|
*/
|
|
3937
|
+
var personaCommandParser = {
|
|
3938
|
+
/**
|
|
3939
|
+
* Name of the command
|
|
3940
|
+
*/
|
|
3941
|
+
name: 'PERSONA',
|
|
3942
|
+
/**
|
|
3943
|
+
* Aliases for the PERSONA command
|
|
3944
|
+
*/
|
|
3945
|
+
aliasNames: ['PERSON'],
|
|
3946
|
+
/**
|
|
3947
|
+
* PERSONA command can be used in:
|
|
3948
|
+
*/
|
|
3949
|
+
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3950
|
+
/**
|
|
3951
|
+
* Description of the PERSONA command
|
|
3952
|
+
*/
|
|
3953
|
+
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
3954
|
+
/**
|
|
3955
|
+
* Link to discussion
|
|
3956
|
+
*/
|
|
3957
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3958
|
+
/**
|
|
3959
|
+
* Example usages of the PERSONA command
|
|
3960
|
+
*/
|
|
3961
|
+
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
3962
|
+
/**
|
|
3963
|
+
* Parses the PERSONA command
|
|
3964
|
+
*/
|
|
3965
|
+
parse: function (input) {
|
|
3966
|
+
var rawArgs = input.rawArgs;
|
|
3967
|
+
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
3968
|
+
var personaName = (personaNameRaw || '').trim();
|
|
3969
|
+
if (personaName === '') {
|
|
3970
|
+
throw new ParsingError("You must set name for the persona");
|
|
3971
|
+
}
|
|
3972
|
+
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
3973
|
+
if (personaDescription === '') {
|
|
3974
|
+
personaDescription = null;
|
|
3975
|
+
}
|
|
3976
|
+
return {
|
|
3977
|
+
type: 'PERSONA',
|
|
3978
|
+
personaName: personaName,
|
|
3979
|
+
personaDescription: personaDescription,
|
|
3980
|
+
};
|
|
3981
|
+
},
|
|
3982
|
+
/**
|
|
3983
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3984
|
+
*/
|
|
3985
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3986
|
+
var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
|
|
3987
|
+
var pipelineJson = subjects.pipelineJson, templateJson = subjects.templateJson;
|
|
3988
|
+
if (templateJson !== null) {
|
|
3989
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
3990
|
+
throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
|
|
3991
|
+
}
|
|
3992
|
+
templateJson.personaName = personaName;
|
|
3993
|
+
}
|
|
3994
|
+
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
3995
|
+
if (persona === undefined) {
|
|
3996
|
+
pipelineJson.personas.push({
|
|
3997
|
+
name: personaName,
|
|
3998
|
+
description: personaDescription || '',
|
|
3999
|
+
});
|
|
4000
|
+
return;
|
|
4001
|
+
}
|
|
4002
|
+
if (persona.description === personaDescription) {
|
|
4003
|
+
return;
|
|
4004
|
+
}
|
|
4005
|
+
if (personaDescription === null) {
|
|
4006
|
+
return;
|
|
4007
|
+
}
|
|
4008
|
+
if (persona.description === '') {
|
|
4009
|
+
persona.description = personaDescription;
|
|
4010
|
+
return;
|
|
4011
|
+
}
|
|
4012
|
+
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 ")));
|
|
4013
|
+
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
4014
|
+
},
|
|
4015
|
+
};
|
|
2744
4016
|
|
|
2745
4017
|
/**
|
|
2746
4018
|
* Removes Markdown formatting tags from a string.
|
|
@@ -2860,7 +4132,7 @@ var blockCommandParser = {
|
|
|
2860
4132
|
/**
|
|
2861
4133
|
* Link to discussion
|
|
2862
4134
|
*/
|
|
2863
|
-
|
|
4135
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
|
|
2864
4136
|
/**
|
|
2865
4137
|
* Example usages of the BLOCK command
|
|
2866
4138
|
*/
|
|
@@ -2880,7 +4152,7 @@ var blockCommandParser = {
|
|
|
2880
4152
|
'Knowledge BLOCK',
|
|
2881
4153
|
// 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
|
|
2882
4154
|
//---
|
|
2883
|
-
/*
|
|
4155
|
+
/* Note: Not implemented block types will be in examples in future -> */
|
|
2884
4156
|
'Instrument BLOCK',
|
|
2885
4157
|
// 'Instrument', // <- Note: [⛱]
|
|
2886
4158
|
'Action BLOCK',
|
|
@@ -2888,6 +4160,7 @@ var blockCommandParser = {
|
|
|
2888
4160
|
//---
|
|
2889
4161
|
/* <- TODO: [🧠] Maybe dynamic */
|
|
2890
4162
|
],
|
|
4163
|
+
// TODO: [♓️] order: -10 /* <- Note: Putting before other commands */
|
|
2891
4164
|
/**
|
|
2892
4165
|
* Parses the BLOCK command
|
|
2893
4166
|
*/
|
|
@@ -2896,19 +4169,19 @@ var blockCommandParser = {
|
|
|
2896
4169
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
2897
4170
|
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
2898
4171
|
if (blockTypes.length !== 1) {
|
|
2899
|
-
// console.log('!!!', { blockType });
|
|
2900
4172
|
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
4173
|
}
|
|
2902
|
-
|
|
4174
|
+
var blockType = blockTypes[0];
|
|
2903
4175
|
return {
|
|
2904
4176
|
type: 'BLOCK',
|
|
2905
|
-
blockType:
|
|
4177
|
+
blockType: blockType,
|
|
2906
4178
|
};
|
|
2907
4179
|
},
|
|
2908
4180
|
};
|
|
2909
4181
|
|
|
2910
4182
|
/**
|
|
2911
4183
|
* Units of text measurement
|
|
4184
|
+
* @see https://github.com/webgptorg/promptbook/discussions/30
|
|
2912
4185
|
*/
|
|
2913
4186
|
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2914
4187
|
/**
|
|
@@ -3004,7 +4277,7 @@ var expectCommandParser = {
|
|
|
3004
4277
|
/**
|
|
3005
4278
|
* Link to discussion
|
|
3006
4279
|
*/
|
|
3007
|
-
|
|
4280
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
|
|
3008
4281
|
/**
|
|
3009
4282
|
* Example usages of the EXPECT command
|
|
3010
4283
|
*/
|
|
@@ -3122,7 +4395,7 @@ var jokerCommandParser = {
|
|
|
3122
4395
|
/**
|
|
3123
4396
|
* Link to discussion
|
|
3124
4397
|
*/
|
|
3125
|
-
|
|
4398
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
|
|
3126
4399
|
/**
|
|
3127
4400
|
* Example usages of the JOKER command
|
|
3128
4401
|
*/
|
|
@@ -3145,94 +4418,11 @@ var jokerCommandParser = {
|
|
|
3145
4418
|
};
|
|
3146
4419
|
|
|
3147
4420
|
/**
|
|
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
|
|
4421
|
+
* @@@
|
|
3174
4422
|
*
|
|
3175
|
-
* @
|
|
3176
|
-
* @private within the commands folder
|
|
4423
|
+
* @private for `ModelVariant` and `modelCommandParser`
|
|
3177
4424
|
*/
|
|
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
4425
|
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
4426
|
|
|
3237
4427
|
/**
|
|
3238
4428
|
* Parses the model command
|
|
@@ -3248,7 +4438,11 @@ var modelCommandParser = {
|
|
|
3248
4438
|
/**
|
|
3249
4439
|
* BOILERPLATE command can be used in:
|
|
3250
4440
|
*/
|
|
3251
|
-
usagePlaces: [
|
|
4441
|
+
usagePlaces: [
|
|
4442
|
+
'PIPELINE_HEAD',
|
|
4443
|
+
// <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
|
|
4444
|
+
'PIPELINE_TEMPLATE',
|
|
4445
|
+
],
|
|
3252
4446
|
/**
|
|
3253
4447
|
* Description of the MODEL command
|
|
3254
4448
|
*/
|
|
@@ -3256,7 +4450,7 @@ var modelCommandParser = {
|
|
|
3256
4450
|
/**
|
|
3257
4451
|
* Link to discussion
|
|
3258
4452
|
*/
|
|
3259
|
-
|
|
4453
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
|
|
3260
4454
|
/**
|
|
3261
4455
|
* Example usages of the MODEL command
|
|
3262
4456
|
*/
|
|
@@ -3336,11 +4530,11 @@ var parameterCommandParser = {
|
|
|
3336
4530
|
/**
|
|
3337
4531
|
* Link to discussion
|
|
3338
4532
|
*/
|
|
3339
|
-
|
|
4533
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/68',
|
|
3340
4534
|
/**
|
|
3341
4535
|
* Example usages of the PARAMETER command
|
|
3342
4536
|
*/
|
|
3343
|
-
examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {
|
|
4537
|
+
examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {websiteContent} Content of the book'],
|
|
3344
4538
|
/**
|
|
3345
4539
|
* Parses the PARAMETER command
|
|
3346
4540
|
*/
|
|
@@ -3370,59 +4564,6 @@ var parameterCommandParser = {
|
|
|
3370
4564
|
},
|
|
3371
4565
|
};
|
|
3372
4566
|
|
|
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
4567
|
function isValidJavascriptName(javascriptName) {
|
|
3427
4568
|
if (typeof javascriptName !== 'string') {
|
|
3428
4569
|
return false;
|
|
@@ -3453,7 +4594,7 @@ var postprocessCommandParser = {
|
|
|
3453
4594
|
/**
|
|
3454
4595
|
* Link to discussion
|
|
3455
4596
|
*/
|
|
3456
|
-
|
|
4597
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/31',
|
|
3457
4598
|
/**
|
|
3458
4599
|
* Example usages of the POSTPROCESS command
|
|
3459
4600
|
*/
|
|
@@ -3492,11 +4633,8 @@ var promptbookVersionCommandParser = {
|
|
|
3492
4633
|
/**
|
|
3493
4634
|
* Name of the command
|
|
3494
4635
|
*/
|
|
3495
|
-
name: '
|
|
3496
|
-
|
|
3497
|
-
Note: [📇] No need to put here "PROMPTBOOK" alias here
|
|
3498
|
-
aliasNames: ['PROMPTBOOK_VERSION'],
|
|
3499
|
-
*/
|
|
4636
|
+
name: 'PROMPTBOOK_VERSION',
|
|
4637
|
+
aliasNames: ['PTBK_VERSION', 'PTBK_V', 'PTBKV'],
|
|
3500
4638
|
/**
|
|
3501
4639
|
* BOILERPLATE command can be used in:
|
|
3502
4640
|
*/
|
|
@@ -3508,11 +4646,11 @@ var promptbookVersionCommandParser = {
|
|
|
3508
4646
|
/**
|
|
3509
4647
|
* Link to discussion
|
|
3510
4648
|
*/
|
|
3511
|
-
|
|
4649
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/69',
|
|
3512
4650
|
/**
|
|
3513
4651
|
* Example usages of the PROMPTBOOK_VERSION command
|
|
3514
4652
|
*/
|
|
3515
|
-
examples: ["PROMPTBOOK VERSION ".concat(PROMPTBOOK_VERSION), "
|
|
4653
|
+
examples: ["PROMPTBOOK VERSION ".concat(PROMPTBOOK_VERSION), "PTBKV ".concat(PROMPTBOOK_VERSION)],
|
|
3516
4654
|
/**
|
|
3517
4655
|
* Parses the PROMPTBOOK_VERSION command
|
|
3518
4656
|
*/
|
|
@@ -3546,8 +4684,9 @@ var urlCommandParser = {
|
|
|
3546
4684
|
* Name of the command
|
|
3547
4685
|
*/
|
|
3548
4686
|
name: 'URL',
|
|
4687
|
+
aliasNames: ['PIPELINE_URL'],
|
|
3549
4688
|
/*
|
|
3550
|
-
Note: [🛵] No need for alias name because it is already preprocessed
|
|
4689
|
+
Note: [🛵] No need for this alias name because it is already preprocessed
|
|
3551
4690
|
aliasNames: ['HTTPS'],
|
|
3552
4691
|
*/
|
|
3553
4692
|
/**
|
|
@@ -3561,11 +4700,12 @@ var urlCommandParser = {
|
|
|
3561
4700
|
/**
|
|
3562
4701
|
* Link to discussion
|
|
3563
4702
|
*/
|
|
3564
|
-
|
|
4703
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/70',
|
|
3565
4704
|
/**
|
|
3566
4705
|
* Example usages of the URL command
|
|
3567
4706
|
*/
|
|
3568
4707
|
examples: [
|
|
4708
|
+
'PIPELINE URL https://promptbook.studio/library/write-cv.ptbk.md',
|
|
3569
4709
|
'URL https://promptbook.studio/library/write-cv.ptbk.md',
|
|
3570
4710
|
'https://promptbook.studio/library/write-cv.ptbk.md',
|
|
3571
4711
|
],
|
|
@@ -3609,22 +4749,6 @@ var urlCommandParser = {
|
|
|
3609
4749
|
},
|
|
3610
4750
|
};
|
|
3611
4751
|
|
|
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
4752
|
/**
|
|
3629
4753
|
* Parses the action command
|
|
3630
4754
|
*
|
|
@@ -3647,7 +4771,7 @@ var actionCommandParser = {
|
|
|
3647
4771
|
/**
|
|
3648
4772
|
* Link to discussion
|
|
3649
4773
|
*/
|
|
3650
|
-
|
|
4774
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/72',
|
|
3651
4775
|
/**
|
|
3652
4776
|
* Example usages of the ACTION command
|
|
3653
4777
|
*/
|
|
@@ -3656,7 +4780,8 @@ var actionCommandParser = {
|
|
|
3656
4780
|
* Parses the ACTION command
|
|
3657
4781
|
*/
|
|
3658
4782
|
parse: function (input) {
|
|
3659
|
-
input.args;
|
|
4783
|
+
var args = input.args;
|
|
4784
|
+
TODO_USE(args);
|
|
3660
4785
|
return {
|
|
3661
4786
|
type: 'ACTION',
|
|
3662
4787
|
};
|
|
@@ -3685,7 +4810,7 @@ var instrumentCommandParser = {
|
|
|
3685
4810
|
/**
|
|
3686
4811
|
* Link to discussion
|
|
3687
4812
|
*/
|
|
3688
|
-
|
|
4813
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/71',
|
|
3689
4814
|
/**
|
|
3690
4815
|
* Example usages of the INSTRUMENT command
|
|
3691
4816
|
*/
|
|
@@ -3694,7 +4819,8 @@ var instrumentCommandParser = {
|
|
|
3694
4819
|
* Parses the INSTRUMENT command
|
|
3695
4820
|
*/
|
|
3696
4821
|
parse: function (input) {
|
|
3697
|
-
input.args;
|
|
4822
|
+
var args = input.args;
|
|
4823
|
+
TODO_USE(args);
|
|
3698
4824
|
return {
|
|
3699
4825
|
type: 'INSTRUMENT',
|
|
3700
4826
|
};
|
|
@@ -3727,7 +4853,7 @@ var boilerplateCommandParser = {
|
|
|
3727
4853
|
/**
|
|
3728
4854
|
* Link to discussion
|
|
3729
4855
|
*/
|
|
3730
|
-
|
|
4856
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
3731
4857
|
/**
|
|
3732
4858
|
* Example usages of the BOILERPLATE command
|
|
3733
4859
|
*/
|
|
@@ -3752,6 +4878,7 @@ var boilerplateCommandParser = {
|
|
|
3752
4878
|
};
|
|
3753
4879
|
/**
|
|
3754
4880
|
* TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
|
|
4881
|
+
* Note: [⚪] This should never be in any released package
|
|
3755
4882
|
*/
|
|
3756
4883
|
|
|
3757
4884
|
/**
|
|
@@ -3770,7 +4897,7 @@ var COMMANDS = [
|
|
|
3770
4897
|
actionCommandParser,
|
|
3771
4898
|
instrumentCommandParser,
|
|
3772
4899
|
personaCommandParser,
|
|
3773
|
-
boilerplateCommandParser, // <- TODO:
|
|
4900
|
+
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
3774
4901
|
];
|
|
3775
4902
|
|
|
3776
4903
|
/**
|
|
@@ -3817,10 +4944,6 @@ function parseCommand(raw, usagePlace) {
|
|
|
3817
4944
|
.split(' ')
|
|
3818
4945
|
.map(function (part) { return part.trim(); })
|
|
3819
4946
|
.filter(function (item) { return item !== ''; })
|
|
3820
|
-
// Note: [📇]:
|
|
3821
|
-
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
3822
|
-
.filter(function (item) { return !/^PIPELINE$/i.test(item); })
|
|
3823
|
-
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
3824
4947
|
.map(removeMarkdownFormatting)
|
|
3825
4948
|
.map(function (item) { return item.trim(); });
|
|
3826
4949
|
if (items.length === 0 || items[0] === '') {
|
|
@@ -3856,18 +4979,18 @@ function parseCommand(raw, usagePlace) {
|
|
|
3856
4979
|
}));
|
|
3857
4980
|
}
|
|
3858
4981
|
/**
|
|
3859
|
-
*
|
|
4982
|
+
* @@@
|
|
3860
4983
|
*/
|
|
3861
4984
|
function getSupportedCommandsMessage() {
|
|
3862
4985
|
return COMMANDS.flatMap(function (_a) {
|
|
3863
|
-
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description,
|
|
4986
|
+
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
|
|
3864
4987
|
return __spreadArray([
|
|
3865
|
-
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(
|
|
4988
|
+
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
|
|
3866
4989
|
], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
|
|
3867
4990
|
}).join('\n');
|
|
3868
4991
|
}
|
|
3869
4992
|
/**
|
|
3870
|
-
*
|
|
4993
|
+
* @@@
|
|
3871
4994
|
*/
|
|
3872
4995
|
function parseCommandVariant(input) {
|
|
3873
4996
|
var e_1, _a;
|
|
@@ -3876,7 +4999,6 @@ function parseCommandVariant(input) {
|
|
|
3876
4999
|
var _loop_1 = function (commandParser) {
|
|
3877
5000
|
var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
|
|
3878
5001
|
var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
|
|
3879
|
-
// console.log('!!!', { commandName, names });
|
|
3880
5002
|
if (names.includes(commandName)) {
|
|
3881
5003
|
try {
|
|
3882
5004
|
return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
|
|
@@ -3986,25 +5108,42 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
3986
5108
|
var e_1, _a;
|
|
3987
5109
|
var codeBlocks = [];
|
|
3988
5110
|
var lines = markdown.split('\n');
|
|
5111
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
5112
|
+
lines.push('');
|
|
3989
5113
|
var currentCodeBlock = null;
|
|
3990
5114
|
try {
|
|
3991
5115
|
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
3992
5116
|
var line = lines_1_1.value;
|
|
5117
|
+
if (line.startsWith('> ') || line === '>') {
|
|
5118
|
+
if (currentCodeBlock === null) {
|
|
5119
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
5120
|
+
} /* not else */
|
|
5121
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
5122
|
+
if (currentCodeBlock.content !== '') {
|
|
5123
|
+
currentCodeBlock.content += '\n';
|
|
5124
|
+
}
|
|
5125
|
+
currentCodeBlock.content += line.slice(2);
|
|
5126
|
+
}
|
|
5127
|
+
}
|
|
5128
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
5129
|
+
codeBlocks.push(currentCodeBlock);
|
|
5130
|
+
currentCodeBlock = null;
|
|
5131
|
+
}
|
|
5132
|
+
/* not else */
|
|
3993
5133
|
if (line.startsWith('```')) {
|
|
3994
5134
|
var language = line.slice(3).trim() || null;
|
|
3995
5135
|
if (currentCodeBlock === null) {
|
|
3996
|
-
currentCodeBlock = { language: language, content: '' };
|
|
5136
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
3997
5137
|
}
|
|
3998
5138
|
else {
|
|
3999
5139
|
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"));
|
|
5140
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4002
5141
|
}
|
|
4003
5142
|
codeBlocks.push(currentCodeBlock);
|
|
4004
5143
|
currentCodeBlock = null;
|
|
4005
5144
|
}
|
|
4006
5145
|
}
|
|
4007
|
-
else if (currentCodeBlock !== null) {
|
|
5146
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
4008
5147
|
if (currentCodeBlock.content !== '') {
|
|
4009
5148
|
currentCodeBlock.content += '\n';
|
|
4010
5149
|
}
|
|
@@ -4020,11 +5159,13 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4020
5159
|
finally { if (e_1) throw e_1.error; }
|
|
4021
5160
|
}
|
|
4022
5161
|
if (currentCodeBlock !== null) {
|
|
4023
|
-
|
|
4024
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
5162
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4025
5163
|
}
|
|
4026
5164
|
return codeBlocks;
|
|
4027
5165
|
}
|
|
5166
|
+
/**
|
|
5167
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
5168
|
+
*/
|
|
4028
5169
|
|
|
4029
5170
|
/**
|
|
4030
5171
|
* Extracts exactly ONE code block from markdown.
|
|
@@ -4042,13 +5183,12 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4042
5183
|
function extractOneBlockFromMarkdown(markdown) {
|
|
4043
5184
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
4044
5185
|
if (codeBlocks.length !== 1) {
|
|
4045
|
-
|
|
4046
|
-
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
5186
|
+
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
5187
|
}
|
|
4048
5188
|
return codeBlocks[0];
|
|
4049
5189
|
}
|
|
4050
5190
|
/***
|
|
4051
|
-
* TODO: [🍓][🌻]
|
|
5191
|
+
* TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
|
|
4052
5192
|
*/
|
|
4053
5193
|
|
|
4054
5194
|
/**
|
|
@@ -4058,13 +5198,13 @@ function parseMarkdownSection(value) {
|
|
|
4058
5198
|
var _a, _b;
|
|
4059
5199
|
var lines = value.split('\n');
|
|
4060
5200
|
if (!lines[0].startsWith('#')) {
|
|
4061
|
-
throw new
|
|
5201
|
+
throw new ParsingError('Markdown section must start with heading');
|
|
4062
5202
|
}
|
|
4063
5203
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
4064
5204
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
4065
5205
|
var content = spaceTrim(lines.slice(1).join('\n'));
|
|
4066
5206
|
if (level < 1 || level > 6) {
|
|
4067
|
-
throw new
|
|
5207
|
+
throw new ParsingError('Markdown section must have heading level between 1 and 6');
|
|
4068
5208
|
}
|
|
4069
5209
|
return { title: title, level: level, content: content };
|
|
4070
5210
|
}
|
|
@@ -4201,203 +5341,14 @@ function removeContentComments(content) {
|
|
|
4201
5341
|
}
|
|
4202
5342
|
|
|
4203
5343
|
/**
|
|
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
|
|
5344
|
+
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4394
5345
|
*
|
|
4395
|
-
* Note: There are
|
|
5346
|
+
* Note: There are 3 similar functions:
|
|
4396
5347
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4397
5348
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5349
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4398
5350
|
*
|
|
4399
5351
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4400
|
-
* @param options - Options and tools for the compilation
|
|
4401
5352
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
4402
5353
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
4403
5354
|
*
|
|
@@ -4413,7 +5364,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4413
5364
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
4414
5365
|
parameters: [],
|
|
4415
5366
|
promptTemplates: [],
|
|
4416
|
-
|
|
5367
|
+
knowledgeSources: [],
|
|
5368
|
+
knowledgePieces: [],
|
|
5369
|
+
personas: [],
|
|
5370
|
+
preparations: [],
|
|
4417
5371
|
};
|
|
4418
5372
|
// =============================================================
|
|
4419
5373
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
@@ -4443,7 +5397,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4443
5397
|
existingParameter.description &&
|
|
4444
5398
|
existingParameter.description !== parameterDescription &&
|
|
4445
5399
|
parameterDescription) {
|
|
4446
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description
|
|
5400
|
+
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
5401
|
}
|
|
4448
5402
|
if (existingParameter) {
|
|
4449
5403
|
if (parameterDescription) {
|
|
@@ -4462,11 +5416,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4462
5416
|
// =============================================================
|
|
4463
5417
|
// Note: 3️⃣ Process pipeline head
|
|
4464
5418
|
pipelineJson.title = pipelineHead.title;
|
|
4465
|
-
// TODO: [1] DRY description
|
|
5419
|
+
// TODO: [🎾][1] DRY description
|
|
4466
5420
|
var description = pipelineHead.content;
|
|
4467
|
-
// Note: Remove codeblocks - TODO:
|
|
5421
|
+
// Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
|
|
4468
5422
|
description = description.split(/^```.*^```/gms).join('');
|
|
4469
|
-
|
|
5423
|
+
description = description.split(/^>.*$/gm).join('');
|
|
5424
|
+
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
4470
5425
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4471
5426
|
description = spaceTrim$1(description);
|
|
4472
5427
|
if (description === '') {
|
|
@@ -4494,7 +5449,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4494
5449
|
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
4495
5450
|
break;
|
|
4496
5451
|
case 'KNOWLEDGE':
|
|
4497
|
-
|
|
5452
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
4498
5453
|
break;
|
|
4499
5454
|
case 'ACTION':
|
|
4500
5455
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
@@ -4503,7 +5458,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4503
5458
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4504
5459
|
break;
|
|
4505
5460
|
case 'PERSONA':
|
|
4506
|
-
|
|
5461
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5462
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4507
5463
|
break;
|
|
4508
5464
|
case 'BOILERPLATE':
|
|
4509
5465
|
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
@@ -4526,29 +5482,83 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4526
5482
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
4527
5483
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
4528
5484
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
4529
|
-
var
|
|
4530
|
-
var
|
|
4531
|
-
var
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
5485
|
+
var lastLine = section.content.split('\n').pop();
|
|
5486
|
+
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
5487
|
+
var resultingParameterName = null;
|
|
5488
|
+
if (resultingParameterNameMatch &&
|
|
5489
|
+
resultingParameterNameMatch.groups !== undefined &&
|
|
5490
|
+
resultingParameterNameMatch.groups.resultingParamName !== undefined) {
|
|
5491
|
+
resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
|
|
5492
|
+
}
|
|
5493
|
+
var expectResultingParameterName = function () {
|
|
5494
|
+
if (resultingParameterName !== null) {
|
|
5495
|
+
return resultingParameterName;
|
|
5496
|
+
}
|
|
5497
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
5498
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
5499
|
+
section.content
|
|
5500
|
+
.split('\n')
|
|
5501
|
+
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
5502
|
+
.join('\n')), "\n "); }));
|
|
5503
|
+
};
|
|
5504
|
+
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
5505
|
+
// TODO: [🎾][1] DRY description
|
|
5506
|
+
var description_1 = section.content;
|
|
5507
|
+
// Note: Remove codeblocks - TODO: [🎾]
|
|
5508
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
5509
|
+
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5510
|
+
//Note: Remove lists and return statement - TODO: [🎾]
|
|
5511
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5512
|
+
description_1 = spaceTrim$1(description_1);
|
|
5513
|
+
if (description_1 === '') {
|
|
5514
|
+
description_1 = undefined;
|
|
5515
|
+
}
|
|
5516
|
+
var templateJson = {
|
|
5517
|
+
blockType: 'PROMPT_TEMPLATE',
|
|
5518
|
+
name: titleToName(section.title),
|
|
5519
|
+
title: section.title,
|
|
5520
|
+
description: description_1,
|
|
5521
|
+
modelRequirements: templateModelRequirements,
|
|
5522
|
+
content: content,
|
|
5523
|
+
};
|
|
5524
|
+
/**
|
|
5525
|
+
* This is nessesary because block type can be
|
|
5526
|
+
* - Set zero times, so anticipate 'PROMPT_TEMPLATE'
|
|
5527
|
+
* - Set one time
|
|
5528
|
+
* - Set more times - throw error
|
|
5529
|
+
*
|
|
5530
|
+
* Note: [2]
|
|
5531
|
+
*/
|
|
5532
|
+
var isBlockTypeSet = false;
|
|
4536
5533
|
try {
|
|
4537
5534
|
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
5535
|
var listItem = listItems_2_1.value;
|
|
4539
5536
|
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
5537
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
4540
5538
|
switch (command.type) {
|
|
4541
5539
|
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
4542
5540
|
case 'BLOCK':
|
|
4543
|
-
if (
|
|
5541
|
+
if (isBlockTypeSet) {
|
|
4544
5542
|
throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
|
|
4545
5543
|
}
|
|
4546
5544
|
if (command.blockType === 'SAMPLE') {
|
|
4547
|
-
|
|
5545
|
+
expectResultingParameterName();
|
|
5546
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
5547
|
+
if (parameter === undefined) {
|
|
5548
|
+
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
5549
|
+
}
|
|
5550
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
5551
|
+
parameter.sampleValues.push(content);
|
|
4548
5552
|
return "continue-templates";
|
|
4549
5553
|
}
|
|
4550
5554
|
if (command.blockType === 'KNOWLEDGE') {
|
|
4551
|
-
|
|
5555
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
5556
|
+
type: 'KNOWLEDGE',
|
|
5557
|
+
source: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5558
|
+
}, {
|
|
5559
|
+
pipelineJson: pipelineJson,
|
|
5560
|
+
templateJson: templateJson,
|
|
5561
|
+
});
|
|
4552
5562
|
return "continue-templates";
|
|
4553
5563
|
}
|
|
4554
5564
|
if (command.blockType === 'ACTION') {
|
|
@@ -4559,35 +5569,37 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4559
5569
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4560
5570
|
return "continue-templates";
|
|
4561
5571
|
}
|
|
4562
|
-
|
|
4563
|
-
|
|
5572
|
+
expectResultingParameterName();
|
|
5573
|
+
templateJson.blockType = command.blockType;
|
|
5574
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
4564
5575
|
break;
|
|
4565
5576
|
case 'EXPECT_AMOUNT':
|
|
4566
5577
|
// eslint-disable-next-line no-case-declarations
|
|
4567
5578
|
var unit = command.unit.toLowerCase();
|
|
4568
|
-
|
|
5579
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
5580
|
+
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
4569
5581
|
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
4570
|
-
if (
|
|
4571
|
-
throw new ParsingError("Already defined minumum ".concat(
|
|
5582
|
+
if (templateJson.expectations[unit].min !== undefined) {
|
|
5583
|
+
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
5584
|
}
|
|
4573
|
-
|
|
5585
|
+
templateJson.expectations[unit].min = command.amount;
|
|
4574
5586
|
} /* not else */
|
|
4575
5587
|
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
4576
|
-
if (
|
|
4577
|
-
throw new ParsingError("Already defined maximum ".concat(
|
|
5588
|
+
if (templateJson.expectations[unit].max !== undefined) {
|
|
5589
|
+
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
5590
|
}
|
|
4579
|
-
|
|
5591
|
+
templateJson.expectations[unit].max = command.amount;
|
|
4580
5592
|
}
|
|
4581
5593
|
break;
|
|
4582
5594
|
case 'EXPECT_FORMAT':
|
|
4583
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
4584
|
-
throw new ParsingError("Expect format is already defined to \"".concat(expectFormat, "\"
|
|
5595
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5596
|
+
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
5597
|
}
|
|
4586
|
-
expectFormat = command.format;
|
|
5598
|
+
templateJson.expectFormat = command.format;
|
|
4587
5599
|
break;
|
|
4588
5600
|
case 'JOKER':
|
|
4589
|
-
|
|
4590
|
-
|
|
5601
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
5602
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
4591
5603
|
break;
|
|
4592
5604
|
case 'MODEL':
|
|
4593
5605
|
templateModelRequirements[command.key] = command.value;
|
|
@@ -4597,19 +5609,24 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4597
5609
|
defineParam(command);
|
|
4598
5610
|
break;
|
|
4599
5611
|
case 'POSTPROCESS':
|
|
4600
|
-
|
|
5612
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
5613
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
4601
5614
|
break;
|
|
4602
5615
|
case 'KNOWLEDGE':
|
|
4603
|
-
|
|
5616
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
5617
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
4604
5618
|
break;
|
|
4605
5619
|
case 'ACTION':
|
|
5620
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
4606
5621
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
4607
5622
|
break;
|
|
4608
5623
|
case 'INSTRUMENT':
|
|
5624
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
4609
5625
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4610
5626
|
break;
|
|
4611
5627
|
case 'PERSONA':
|
|
4612
|
-
|
|
5628
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
5629
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4613
5630
|
break;
|
|
4614
5631
|
case 'BOILERPLATE':
|
|
4615
5632
|
console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
|
|
@@ -4627,70 +5644,29 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4627
5644
|
}
|
|
4628
5645
|
finally { if (e_3) throw e_3.error; }
|
|
4629
5646
|
}
|
|
4630
|
-
|
|
4631
|
-
if (blockType === 'SCRIPT') {
|
|
5647
|
+
// TODO: [🍧] Should be done in BLOCK command
|
|
5648
|
+
if (templateJson.blockType === 'SCRIPT') {
|
|
4632
5649
|
if (!language) {
|
|
4633
5650
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
4634
5651
|
}
|
|
4635
|
-
|
|
5652
|
+
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
4636
5653
|
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
5654
|
}
|
|
5655
|
+
templateJson.contentLanguage = language;
|
|
4638
5656
|
}
|
|
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 })));
|
|
5657
|
+
// TODO: [🍧][❔] Should be done in BLOCK command
|
|
4670
5658
|
if (templateModelRequirements.modelVariant === undefined) {
|
|
4671
5659
|
templateModelRequirements.modelVariant = 'CHAT';
|
|
4672
5660
|
}
|
|
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;
|
|
5661
|
+
templateJson.dependentParameterNames = Array.from(extractParameterNamesFromPromptTemplate(templateJson));
|
|
5662
|
+
// TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
|
|
5663
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
5664
|
+
delete templateJson.modelRequirements;
|
|
4691
5665
|
}
|
|
5666
|
+
// TODO: [🍧] Make this better - for example each command parser can call and apply this
|
|
5667
|
+
templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
|
|
4692
5668
|
// TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
|
|
4693
|
-
pipelineJson.promptTemplates.push(
|
|
5669
|
+
pipelineJson.promptTemplates.push(templateJson);
|
|
4694
5670
|
};
|
|
4695
5671
|
try {
|
|
4696
5672
|
// =============================================================
|
|
@@ -4757,14 +5733,18 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4757
5733
|
* TODO: Use spaceTrim more effectively
|
|
4758
5734
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
4759
5735
|
* TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
5736
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
5737
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
5738
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
4760
5739
|
*/
|
|
4761
5740
|
|
|
4762
5741
|
/**
|
|
4763
|
-
* Compile
|
|
5742
|
+
* Compile pipeline from string (markdown) format to JSON format
|
|
4764
5743
|
*
|
|
4765
|
-
* Note: There are
|
|
5744
|
+
* Note: There are 3 similar functions:
|
|
4766
5745
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4767
5746
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5747
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4768
5748
|
*
|
|
4769
5749
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4770
5750
|
* @param options - Options and tools for the compilation
|
|
@@ -4775,22 +5755,18 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4775
5755
|
* Note: This function acts as compilation process
|
|
4776
5756
|
*/
|
|
4777
5757
|
function pipelineStringToJson(pipelineString, options) {
|
|
4778
|
-
if (options === void 0) { options = {}; }
|
|
5758
|
+
if (options === void 0) { options = { llmTools: null }; }
|
|
4779
5759
|
return __awaiter(this, void 0, void 0, function () {
|
|
4780
|
-
var llmTools, pipelineJson
|
|
5760
|
+
var llmTools, pipelineJson;
|
|
4781
5761
|
return __generator(this, function (_a) {
|
|
4782
5762
|
switch (_a.label) {
|
|
4783
5763
|
case 0:
|
|
4784
5764
|
llmTools = options.llmTools;
|
|
4785
5765
|
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
|
-
})];
|
|
5766
|
+
if (!(llmTools !== null)) return [3 /*break*/, 2];
|
|
5767
|
+
return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
|
|
4791
5768
|
case 1:
|
|
4792
|
-
|
|
4793
|
-
pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
|
|
5769
|
+
pipelineJson = _a.sent();
|
|
4794
5770
|
_a.label = 2;
|
|
4795
5771
|
case 2: return [2 /*return*/, pipelineJson];
|
|
4796
5772
|
}
|
|
@@ -4799,12 +5775,13 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
4799
5775
|
}
|
|
4800
5776
|
/**
|
|
4801
5777
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
5778
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4802
5779
|
*/
|
|
4803
5780
|
|
|
4804
5781
|
/**
|
|
4805
5782
|
* Add or modify an auto-generated section in a markdown file
|
|
4806
5783
|
*
|
|
4807
|
-
* @private within the
|
|
5784
|
+
* @private within the repository
|
|
4808
5785
|
*/
|
|
4809
5786
|
function addAutoGeneratedSection(content, options) {
|
|
4810
5787
|
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
@@ -4816,7 +5793,10 @@ function addAutoGeneratedSection(content, options) {
|
|
|
4816
5793
|
}
|
|
4817
5794
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
4818
5795
|
if (!placeForSection) {
|
|
4819
|
-
throw new
|
|
5796
|
+
throw new ParsingError(
|
|
5797
|
+
// <- [🧠] Maybe something better than `ParsingError`
|
|
5798
|
+
"No place where to put the section <!--".concat(sectionName, "-->"));
|
|
5799
|
+
// <- [🚞]
|
|
4820
5800
|
}
|
|
4821
5801
|
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
4822
5802
|
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
@@ -4973,6 +5953,28 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
4973
5953
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
4974
5954
|
*/
|
|
4975
5955
|
|
|
5956
|
+
/**
|
|
5957
|
+
* Stringify the PipelineJson with proper formatting
|
|
5958
|
+
*
|
|
5959
|
+
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
5960
|
+
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
5961
|
+
*/
|
|
5962
|
+
function stringifyPipelineJson(pipeline) {
|
|
5963
|
+
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
5964
|
+
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
5965
|
+
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
5966
|
+
}
|
|
5967
|
+
pipelineJsonStringified = pipelineJsonStringified.split(REPLACING_NONCE).join(', ');
|
|
5968
|
+
pipelineJsonStringified += '\n';
|
|
5969
|
+
return pipelineJsonStringified;
|
|
5970
|
+
}
|
|
5971
|
+
/**
|
|
5972
|
+
* TODO: [🐝] Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
5973
|
+
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
5974
|
+
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
5975
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
5976
|
+
*/
|
|
5977
|
+
|
|
4976
5978
|
/**
|
|
4977
5979
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
4978
5980
|
*/
|
|
@@ -4987,6 +5989,20 @@ var CollectionError = /** @class */ (function (_super) {
|
|
|
4987
5989
|
return CollectionError;
|
|
4988
5990
|
}(Error));
|
|
4989
5991
|
|
|
5992
|
+
/**
|
|
5993
|
+
* This error type indicates that the version of the pipeline is not matching the expected version
|
|
5994
|
+
*/
|
|
5995
|
+
var VersionMismatchError = /** @class */ (function (_super) {
|
|
5996
|
+
__extends(VersionMismatchError, _super);
|
|
5997
|
+
function VersionMismatchError(message, expectedVersion) {
|
|
5998
|
+
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;
|
|
5999
|
+
_this.name = 'UnexpectedError';
|
|
6000
|
+
Object.setPrototypeOf(_this, VersionMismatchError.prototype);
|
|
6001
|
+
return _this;
|
|
6002
|
+
}
|
|
6003
|
+
return VersionMismatchError;
|
|
6004
|
+
}(Error));
|
|
6005
|
+
|
|
4990
6006
|
/**
|
|
4991
6007
|
* Pretty print an embedding vector for logging
|
|
4992
6008
|
*/
|
|
@@ -5074,6 +6090,9 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
|
5074
6090
|
};
|
|
5075
6091
|
return SimplePromptInterfaceTools;
|
|
5076
6092
|
}());
|
|
6093
|
+
/**
|
|
6094
|
+
* Note: [🔵] This code should never be published outside of `@promptbook/browser`
|
|
6095
|
+
*/
|
|
5077
6096
|
|
|
5078
6097
|
/**
|
|
5079
6098
|
* Default options for generating an execution report string
|
|
@@ -5086,7 +6105,7 @@ var ExecutionReportStringOptionsDefaults = {
|
|
|
5086
6105
|
/**
|
|
5087
6106
|
* Format either small or big number
|
|
5088
6107
|
*
|
|
5089
|
-
* @private within the
|
|
6108
|
+
* @private within the repository
|
|
5090
6109
|
*/
|
|
5091
6110
|
function formatNumber(value) {
|
|
5092
6111
|
if (value === 0) {
|
|
@@ -5106,7 +6125,7 @@ function formatNumber(value) {
|
|
|
5106
6125
|
/**
|
|
5107
6126
|
* Create a markdown table from a 2D array of strings
|
|
5108
6127
|
*
|
|
5109
|
-
* @private within the
|
|
6128
|
+
* @private within the repository
|
|
5110
6129
|
*/
|
|
5111
6130
|
function createMarkdownTable(table) {
|
|
5112
6131
|
var columnWidths = table.reduce(function (widths, row) {
|
|
@@ -5134,7 +6153,7 @@ function createMarkdownTable(table) {
|
|
|
5134
6153
|
/**
|
|
5135
6154
|
* Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
|
|
5136
6155
|
*
|
|
5137
|
-
* @private within the
|
|
6156
|
+
* @private within the repository
|
|
5138
6157
|
*/
|
|
5139
6158
|
function createMarkdownChart(options) {
|
|
5140
6159
|
var e_1, _a;
|
|
@@ -5187,7 +6206,7 @@ var MOMENT_ARG_THRESHOLDS = {
|
|
|
5187
6206
|
/**
|
|
5188
6207
|
* Count the duration of working time
|
|
5189
6208
|
*
|
|
5190
|
-
* @private within the
|
|
6209
|
+
* @private within the repository
|
|
5191
6210
|
*/
|
|
5192
6211
|
function countWorkingDuration(items) {
|
|
5193
6212
|
var e_1, _a;
|
|
@@ -5344,10 +6363,13 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
5344
6363
|
if (just(true)) {
|
|
5345
6364
|
executionReportString +=
|
|
5346
6365
|
'\n\n\n\n' +
|
|
5347
|
-
spaceTrim$1(function (block) {
|
|
6366
|
+
spaceTrim$1(function (block) {
|
|
6367
|
+
var _a;
|
|
6368
|
+
return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(((_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.rawPromptContent) || promptExecution.prompt.content)), "\n ```\n\n ");
|
|
6369
|
+
});
|
|
5348
6370
|
}
|
|
5349
6371
|
if (promptExecution.result && promptExecution.result.content) {
|
|
5350
|
-
executionReportString += '\n\n\n\n' + '### Result';
|
|
6372
|
+
executionReportString += '\n\n\n\n' + '### Result' + '\n\n';
|
|
5351
6373
|
if (promptExecution.result === undefined) {
|
|
5352
6374
|
executionReportString += '*No result*';
|
|
5353
6375
|
}
|
|
@@ -5385,5 +6407,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
5385
6407
|
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
5386
6408
|
*/
|
|
5387
6409
|
|
|
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 };
|
|
6410
|
+
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
6411
|
//# sourceMappingURL=index.es.js.map
|