@promptbook/core 0.62.1 → 0.63.0-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 +1 -1
- package/esm/index.es.js +534 -38
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/anthropic-claude.index.d.ts +3 -2
- package/esm/typings/src/_packages/azure-openai.index.d.ts +4 -2
- package/esm/typings/src/_packages/browser.index.d.ts +6 -0
- package/esm/typings/src/_packages/cli.index.d.ts +1 -7
- package/esm/typings/src/_packages/core.index.d.ts +87 -13
- package/esm/typings/src/_packages/execute-javascript.index.d.ts +5 -45
- package/esm/typings/src/_packages/fake-llm.index.d.ts +4 -5
- package/esm/typings/src/_packages/langtail.index.d.ts +4 -2
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +23 -4
- package/esm/typings/src/_packages/node.index.d.ts +5 -2
- package/esm/typings/src/_packages/openai.index.d.ts +5 -2
- package/esm/typings/src/_packages/remote-client.index.d.ts +5 -2
- package/esm/typings/src/_packages/remote-server.index.d.ts +4 -2
- package/esm/typings/src/_packages/types.index.d.ts +441 -21
- package/esm/typings/src/_packages/utils.index.d.ts +84 -31
- package/esm/typings/src/cli/main.d.ts +12 -0
- package/esm/typings/src/collection/collectionToJson.d.ts +2 -0
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createSubcollection.d.ts +1 -0
- package/esm/typings/src/commands/BLOCK/BlockTypes.d.ts +2 -0
- package/esm/typings/src/config.d.ts +27 -1
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +6 -3
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +4 -3
- package/esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts +2 -0
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +2 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts +1 -0
- package/esm/typings/src/conversion/utils/extractVariables.d.ts +1 -0
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +1 -0
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +2 -0
- package/esm/typings/src/conversion/utils/titleToName.d.ts +6 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +1 -0
- package/esm/typings/src/errors/CollectionError.d.ts +2 -0
- package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +2 -0
- package/esm/typings/src/errors/LimitReachedError.d.ts +2 -0
- package/esm/typings/src/errors/NotFoundError.d.ts +2 -0
- package/esm/typings/src/errors/NotYetImplementedError.d.ts +2 -0
- package/esm/typings/src/errors/ParsingError.d.ts +2 -0
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +2 -0
- package/esm/typings/src/errors/PipelineLogicError.d.ts +2 -0
- package/esm/typings/src/errors/ReferenceError.d.ts +2 -0
- package/esm/typings/src/errors/UnexpectedError.d.ts +2 -0
- package/esm/typings/src/errors/VersionMismatchError.d.ts +2 -0
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -0
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/esm/typings/src/execution/embeddingVectorToString.d.ts +2 -0
- package/esm/typings/src/execution/utils/addUsage.d.ts +3 -1
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +2 -0
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -0
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +2 -0
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +2 -0
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +2 -1
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +2 -0
- package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceTools.d.ts +2 -0
- package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +2 -0
- package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -1
- package/esm/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +10 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +2 -0
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +4 -1
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +1 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +2 -0
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -0
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +7 -1
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +5 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +2 -1
- package/esm/typings/src/prepare/preparePipeline.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTemplates.d.ts +2 -1
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +2 -1
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +2 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +51 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +0 -1
- package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +2 -1
- package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +0 -3
- package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +2 -1
- package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +2 -1
- package/esm/typings/src/storage/memory/MemoryStorage.d.ts +2 -3
- package/esm/typings/src/storage/utils/PrefixStorage.d.ts +2 -3
- package/esm/typings/src/types/ModelRequirements.d.ts +0 -1
- package/esm/typings/src/types/Prompt.d.ts +0 -1
- package/esm/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +4 -0
- package/esm/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -0
- package/esm/typings/src/types/typeAliases.d.ts +9 -2
- package/esm/typings/src/utils/currentDate.d.ts +1 -0
- package/esm/typings/src/utils/deepClone.d.ts +2 -1
- package/esm/typings/src/utils/deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +4 -0
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/index.d.ts +2 -0
- package/esm/typings/src/utils/extractParameterNames.d.ts +1 -0
- package/esm/typings/src/utils/isRunningInWhatever.d.ts +6 -3
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +4 -1
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +4 -1
- package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +5 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -0
- package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +3 -0
- package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +4 -0
- package/esm/typings/src/utils/markdown/removeContentComments.d.ts +1 -0
- package/esm/typings/src/utils/markdown/removeMarkdownFormatting.d.ts +1 -0
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +3 -0
- package/esm/typings/src/utils/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +2 -0
- package/esm/typings/src/utils/normalization/IKeywords.d.ts +3 -0
- package/esm/typings/src/utils/normalization/capitalize.d.ts +1 -0
- package/esm/typings/src/utils/normalization/decapitalize.d.ts +1 -0
- package/esm/typings/src/utils/normalization/isValidKeyword.d.ts +2 -0
- package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +8 -0
- package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +8 -0
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +10 -0
- package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +9 -0
- package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +10 -0
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +11 -0
- package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +9 -0
- package/esm/typings/src/utils/normalization/parseKeywords.d.ts +1 -0
- package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +1 -0
- package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +7 -0
- package/esm/typings/src/utils/normalization/searchKeywords.d.ts +5 -0
- package/esm/typings/src/utils/parseNumber.d.ts +2 -1
- package/esm/typings/src/utils/random/randomSeed.d.ts +1 -0
- package/esm/typings/src/utils/removeEmojis.d.ts +1 -0
- package/esm/typings/src/utils/removeQuotes.d.ts +1 -0
- package/esm/typings/src/utils/replaceParameters.d.ts +1 -0
- package/esm/typings/src/utils/sets/difference.d.ts +1 -0
- package/esm/typings/src/utils/sets/intersection.d.ts +1 -0
- package/esm/typings/src/utils/sets/union.d.ts +1 -0
- package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -0
- package/esm/typings/src/utils/trimEndOfCodeBlock.d.ts +2 -0
- package/esm/typings/src/utils/unwrapResult.d.ts +1 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +1 -0
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +7 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -0
- package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +2 -0
- package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -0
- package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +2 -0
- package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -0
- package/esm/typings/src/version.d.ts +2 -0
- package/package.json +1 -1
- package/umd/index.umd.js +557 -42
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/_packages/anthropic-claude.index.d.ts +3 -2
- package/umd/typings/src/_packages/azure-openai.index.d.ts +4 -2
- package/umd/typings/src/_packages/browser.index.d.ts +6 -0
- package/umd/typings/src/_packages/cli.index.d.ts +1 -7
- package/umd/typings/src/_packages/core.index.d.ts +87 -13
- package/umd/typings/src/_packages/execute-javascript.index.d.ts +5 -45
- package/umd/typings/src/_packages/fake-llm.index.d.ts +4 -5
- package/umd/typings/src/_packages/langtail.index.d.ts +4 -2
- package/umd/typings/src/_packages/markdown-utils.index.d.ts +23 -4
- package/umd/typings/src/_packages/node.index.d.ts +5 -2
- package/umd/typings/src/_packages/openai.index.d.ts +5 -2
- package/umd/typings/src/_packages/remote-client.index.d.ts +5 -2
- package/umd/typings/src/_packages/remote-server.index.d.ts +4 -2
- package/umd/typings/src/_packages/types.index.d.ts +441 -21
- package/umd/typings/src/_packages/utils.index.d.ts +84 -31
- package/umd/typings/src/cli/main.d.ts +12 -0
- package/umd/typings/src/collection/collectionToJson.d.ts +2 -0
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
- package/umd/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -0
- package/umd/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -0
- package/umd/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/umd/typings/src/collection/constructors/createSubcollection.d.ts +1 -0
- package/umd/typings/src/commands/BLOCK/BlockTypes.d.ts +2 -0
- package/umd/typings/src/config.d.ts +27 -1
- package/umd/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +6 -3
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +4 -3
- package/umd/typings/src/conversion/prettify/prettifyPipelineString.d.ts +2 -0
- package/umd/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +2 -0
- package/umd/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts +1 -0
- package/umd/typings/src/conversion/utils/extractVariables.d.ts +1 -0
- package/umd/typings/src/conversion/utils/renameParameter.d.ts +1 -0
- package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +2 -0
- package/umd/typings/src/conversion/utils/titleToName.d.ts +6 -1
- package/umd/typings/src/conversion/validation/validatePipeline.d.ts +1 -0
- package/umd/typings/src/errors/CollectionError.d.ts +2 -0
- package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +2 -0
- package/umd/typings/src/errors/LimitReachedError.d.ts +2 -0
- package/umd/typings/src/errors/NotFoundError.d.ts +2 -0
- package/umd/typings/src/errors/NotYetImplementedError.d.ts +2 -0
- package/umd/typings/src/errors/ParsingError.d.ts +2 -0
- package/umd/typings/src/errors/PipelineExecutionError.d.ts +2 -0
- package/umd/typings/src/errors/PipelineLogicError.d.ts +2 -0
- package/umd/typings/src/errors/ReferenceError.d.ts +2 -0
- package/umd/typings/src/errors/UnexpectedError.d.ts +2 -0
- package/umd/typings/src/errors/VersionMismatchError.d.ts +2 -0
- package/umd/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -0
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/umd/typings/src/execution/embeddingVectorToString.d.ts +2 -0
- package/umd/typings/src/execution/utils/addUsage.d.ts +3 -1
- package/umd/typings/src/execution/utils/checkExpectations.d.ts +2 -0
- package/umd/typings/src/execution/utils/forEachAsync.d.ts +1 -0
- package/umd/typings/src/execution/utils/usageToHuman.d.ts +2 -0
- package/umd/typings/src/execution/utils/usageToWorktime.d.ts +2 -0
- package/umd/typings/src/formats/_common/FormatDefinition.d.ts +2 -1
- package/umd/typings/src/formats/json/utils/isValidJsonString.d.ts +2 -0
- package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceTools.d.ts +2 -0
- package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +2 -0
- package/umd/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -1
- package/umd/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +10 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +2 -0
- package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +4 -1
- package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts +1 -1
- package/umd/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -1
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -1
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +1 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +2 -0
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -0
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -0
- package/umd/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +7 -1
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/umd/typings/src/personas/preparePersona.d.ts +1 -1
- package/umd/typings/src/postprocessing/utils/extractBlock.d.ts +5 -0
- package/umd/typings/src/prepare/isPipelinePrepared.d.ts +2 -1
- package/umd/typings/src/prepare/preparePipeline.d.ts +1 -1
- package/umd/typings/src/prepare/prepareTemplates.d.ts +2 -1
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +2 -1
- package/umd/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +2 -0
- package/umd/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -0
- package/umd/typings/src/scripting/javascript/postprocessing-functions.d.ts +51 -0
- package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +0 -1
- package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +2 -1
- package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +0 -3
- package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +2 -1
- package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +2 -1
- package/umd/typings/src/storage/memory/MemoryStorage.d.ts +2 -3
- package/umd/typings/src/storage/utils/PrefixStorage.d.ts +2 -3
- package/umd/typings/src/types/ModelRequirements.d.ts +0 -1
- package/umd/typings/src/types/Prompt.d.ts +0 -1
- package/umd/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +4 -0
- package/umd/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -0
- package/umd/typings/src/types/typeAliases.d.ts +9 -2
- package/umd/typings/src/utils/currentDate.d.ts +1 -0
- package/umd/typings/src/utils/deepClone.d.ts +2 -1
- package/umd/typings/src/utils/deepFreeze.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countCharacters.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/countLines.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/countPages.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/countParagraphs.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/countSentences.d.ts +4 -0
- package/umd/typings/src/utils/expectation-counters/countWords.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/index.d.ts +2 -0
- package/umd/typings/src/utils/extractParameterNames.d.ts +1 -0
- package/umd/typings/src/utils/isRunningInWhatever.d.ts +6 -3
- package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +4 -1
- package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +4 -1
- package/umd/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +5 -0
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
- package/umd/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
- package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -0
- package/umd/typings/src/utils/markdown/flattenMarkdown.d.ts +3 -0
- package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +4 -0
- package/umd/typings/src/utils/markdown/removeContentComments.d.ts +1 -0
- package/umd/typings/src/utils/markdown/removeMarkdownFormatting.d.ts +1 -0
- package/umd/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +3 -0
- package/umd/typings/src/utils/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +2 -0
- package/umd/typings/src/utils/normalization/IKeywords.d.ts +3 -0
- package/umd/typings/src/utils/normalization/capitalize.d.ts +1 -0
- package/umd/typings/src/utils/normalization/decapitalize.d.ts +1 -0
- package/umd/typings/src/utils/normalization/isValidKeyword.d.ts +2 -0
- package/umd/typings/src/utils/normalization/nameToUriPart.d.ts +8 -0
- package/umd/typings/src/utils/normalization/nameToUriParts.d.ts +8 -0
- package/umd/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +10 -0
- package/umd/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +9 -0
- package/umd/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +10 -0
- package/umd/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +11 -0
- package/umd/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +9 -0
- package/umd/typings/src/utils/normalization/parseKeywords.d.ts +1 -0
- package/umd/typings/src/utils/normalization/parseKeywordsFromString.d.ts +1 -0
- package/umd/typings/src/utils/normalization/removeDiacritics.d.ts +7 -0
- package/umd/typings/src/utils/normalization/searchKeywords.d.ts +5 -0
- package/umd/typings/src/utils/parseNumber.d.ts +2 -1
- package/umd/typings/src/utils/random/randomSeed.d.ts +1 -0
- package/umd/typings/src/utils/removeEmojis.d.ts +1 -0
- package/umd/typings/src/utils/removeQuotes.d.ts +1 -0
- package/umd/typings/src/utils/replaceParameters.d.ts +1 -0
- package/umd/typings/src/utils/sets/difference.d.ts +1 -0
- package/umd/typings/src/utils/sets/intersection.d.ts +1 -0
- package/umd/typings/src/utils/sets/union.d.ts +1 -0
- package/umd/typings/src/utils/trimCodeBlock.d.ts +1 -0
- package/umd/typings/src/utils/trimEndOfCodeBlock.d.ts +2 -0
- package/umd/typings/src/utils/unwrapResult.d.ts +1 -0
- package/umd/typings/src/utils/validators/filePath/isValidFilePath.d.ts +1 -0
- package/umd/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +7 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -0
- package/umd/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +2 -0
- package/umd/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -0
- package/umd/typings/src/utils/validators/url/isValidUrl.d.ts +2 -0
- package/umd/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -0
- package/umd/typings/src/version.d.ts +2 -0
package/esm/index.es.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
2
2
|
import { format } from 'prettier';
|
|
3
3
|
import parserHtml from 'prettier/parser-html';
|
|
4
|
+
import hexEncoder from 'crypto-js/enc-hex';
|
|
5
|
+
import sha256 from 'crypto-js/sha256';
|
|
4
6
|
import moment from 'moment';
|
|
5
7
|
|
|
8
|
+
/**
|
|
9
|
+
* The version of the Promptbook library
|
|
10
|
+
*
|
|
11
|
+
* @public exported from all packages
|
|
12
|
+
*/
|
|
13
|
+
var PROMPTBOOK_VERSION = '0.62.0';
|
|
14
|
+
// TODO: !!!! List here all the versions and annotate + put into script
|
|
15
|
+
|
|
6
16
|
/*! *****************************************************************************
|
|
7
17
|
Copyright (c) Microsoft Corporation.
|
|
8
18
|
|
|
@@ -126,6 +136,8 @@ function __spreadArray(to, from, pack) {
|
|
|
126
136
|
* Converts PipelineCollection to serialized JSON
|
|
127
137
|
*
|
|
128
138
|
* Note: Functions `collectionToJson` and `createCollectionFromJson` are complementary
|
|
139
|
+
*
|
|
140
|
+
* @public exported from `@promptbook/core`
|
|
129
141
|
*/
|
|
130
142
|
function collectionToJson(collection) {
|
|
131
143
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -184,6 +196,7 @@ function prettifyMarkdown(content) {
|
|
|
184
196
|
/**
|
|
185
197
|
* Makes first letter of a string uppercase
|
|
186
198
|
*
|
|
199
|
+
* @public exported from `@promptbook/utils`
|
|
187
200
|
*/
|
|
188
201
|
function capitalize(word) {
|
|
189
202
|
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
@@ -194,6 +207,7 @@ function capitalize(word) {
|
|
|
194
207
|
*
|
|
195
208
|
* @param pipelineJson Promptbook in JSON format (.ptbk.json)
|
|
196
209
|
* @returns Promptbook in string format (.ptbk.md)
|
|
210
|
+
* @public exported from `@promptbook/core`
|
|
197
211
|
*/
|
|
198
212
|
function pipelineJsonToString(pipelineJson) {
|
|
199
213
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
@@ -424,6 +438,7 @@ function deepFreeze(objectValue) {
|
|
|
424
438
|
* @@@
|
|
425
439
|
*
|
|
426
440
|
* @returns The same object as the input, but deeply frozen
|
|
441
|
+
* @public exported from `@promptbook/utils`
|
|
427
442
|
*
|
|
428
443
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
429
444
|
*/
|
|
@@ -431,7 +446,6 @@ function deepFreezeWithSameType(objectValue) {
|
|
|
431
446
|
return deepFreeze(objectValue);
|
|
432
447
|
}
|
|
433
448
|
/**
|
|
434
|
-
* TODO: [🔼] Export from `@promptbook/utils`
|
|
435
449
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
436
450
|
*/
|
|
437
451
|
|
|
@@ -457,22 +471,62 @@ function just(value) {
|
|
|
457
471
|
|
|
458
472
|
/**
|
|
459
473
|
* The maximum number of iterations for a loops
|
|
474
|
+
*
|
|
475
|
+
* @private within the repository - too low-level in comparison to other `MAX_...`
|
|
460
476
|
*/
|
|
461
477
|
var LOOP_LIMIT = 1000;
|
|
462
478
|
/**
|
|
463
479
|
* The maximum number of (LLM) tasks running in parallel
|
|
480
|
+
*
|
|
481
|
+
* @public exported from `@promptbook/core`
|
|
464
482
|
*/
|
|
465
483
|
var MAX_PARALLEL_COUNT = 5;
|
|
466
484
|
/**
|
|
467
485
|
* The maximum number of attempts to execute LLM task before giving up
|
|
486
|
+
*
|
|
487
|
+
* @public exported from `@promptbook/core`
|
|
468
488
|
*/
|
|
469
489
|
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
490
|
+
/**
|
|
491
|
+
* The maximum length of the (generated) filename
|
|
492
|
+
*
|
|
493
|
+
* @public exported from `@promptbook/core`
|
|
494
|
+
*/
|
|
495
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
496
|
+
/**
|
|
497
|
+
* @@@
|
|
498
|
+
* TODO: [🐝] !!! Use
|
|
499
|
+
*
|
|
500
|
+
* @public exported from `@promptbook/core`
|
|
501
|
+
*/
|
|
502
|
+
var MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH = 3;
|
|
503
|
+
/**
|
|
504
|
+
* @@@
|
|
505
|
+
* TODO: [🐝] !!! Use
|
|
506
|
+
*
|
|
507
|
+
* @public exported from `@promptbook/core`
|
|
508
|
+
*/
|
|
509
|
+
var MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
|
|
510
|
+
/**
|
|
511
|
+
* Where to store the cache of executions for promptbook CLI
|
|
512
|
+
*
|
|
513
|
+
* @public exported from `@promptbook/core`
|
|
514
|
+
*/
|
|
515
|
+
var EXECUTIONS_CACHE_DIRNAME = '/.promptbook/executions-cache';
|
|
516
|
+
/**
|
|
517
|
+
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
518
|
+
*
|
|
519
|
+
* @public exported from `@promptbook/core`
|
|
520
|
+
*/
|
|
521
|
+
var PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
470
522
|
/**
|
|
471
523
|
* Nonce which is used for replacing things in strings
|
|
472
524
|
*/
|
|
473
525
|
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
474
526
|
/**
|
|
475
527
|
* The names of the parameters that are reserved for special purposes
|
|
528
|
+
*
|
|
529
|
+
* @public exported from `@promptbook/core`
|
|
476
530
|
*/
|
|
477
531
|
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
478
532
|
'content',
|
|
@@ -486,10 +540,14 @@ var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
|
486
540
|
]);
|
|
487
541
|
/**
|
|
488
542
|
* @@@
|
|
543
|
+
*
|
|
544
|
+
* @private within the repository
|
|
489
545
|
*/
|
|
490
546
|
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
491
547
|
/**
|
|
492
548
|
* @@@
|
|
549
|
+
*
|
|
550
|
+
* @private within the repository
|
|
493
551
|
*/
|
|
494
552
|
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
495
553
|
/*
|
|
@@ -497,11 +555,13 @@ TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
|
497
555
|
*/
|
|
498
556
|
// [🟡][🟢][🔵][⚪]
|
|
499
557
|
/**
|
|
500
|
-
* TODO:
|
|
558
|
+
* TODO: !!!!!! Check that all @private contains some normalized explanation
|
|
501
559
|
*/
|
|
502
560
|
|
|
503
561
|
/**
|
|
504
562
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
563
|
+
*
|
|
564
|
+
* @public exported from `@promptbook/core`
|
|
505
565
|
*/
|
|
506
566
|
var ParsingError = /** @class */ (function (_super) {
|
|
507
567
|
__extends(ParsingError, _super);
|
|
@@ -516,6 +576,8 @@ var ParsingError = /** @class */ (function (_super) {
|
|
|
516
576
|
|
|
517
577
|
/**
|
|
518
578
|
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
579
|
+
*
|
|
580
|
+
* @public exported from `@promptbook/core`
|
|
519
581
|
*/
|
|
520
582
|
var PipelineLogicError = /** @class */ (function (_super) {
|
|
521
583
|
__extends(PipelineLogicError, _super);
|
|
@@ -530,6 +592,8 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
530
592
|
|
|
531
593
|
/**
|
|
532
594
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
595
|
+
*
|
|
596
|
+
* @public exported from `@promptbook/core`
|
|
533
597
|
*/
|
|
534
598
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
535
599
|
__extends(UnexpectedError, _super);
|
|
@@ -548,6 +612,8 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
548
612
|
* Note: There are two simmilar functions:
|
|
549
613
|
* - `isValidSemanticVersion` which tests any semantic version
|
|
550
614
|
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
615
|
+
*
|
|
616
|
+
* @public exported from `@promptbook/utils`
|
|
551
617
|
*/
|
|
552
618
|
function isValidSemanticVersion(version) {
|
|
553
619
|
if (typeof version !== 'string') {
|
|
@@ -568,6 +634,8 @@ function isValidSemanticVersion(version) {
|
|
|
568
634
|
* Note: There are two simmilar functions:
|
|
569
635
|
* - `isValidSemanticVersion` which tests any semantic version
|
|
570
636
|
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
637
|
+
*
|
|
638
|
+
* @public exported from `@promptbook/utils`
|
|
571
639
|
*/
|
|
572
640
|
function isValidPromptbookVersion(version) {
|
|
573
641
|
if (!isValidSemanticVersion(version)) {
|
|
@@ -586,6 +654,8 @@ function isValidPromptbookVersion(version) {
|
|
|
586
654
|
* Note: There are two simmilar functions:
|
|
587
655
|
* - `isUrlOnPrivateNetwork` which tests full URL
|
|
588
656
|
* - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
|
|
657
|
+
*
|
|
658
|
+
* @public exported from `@promptbook/utils`
|
|
589
659
|
*/
|
|
590
660
|
function isHostnameOnPrivateNetwork(hostname) {
|
|
591
661
|
if (hostname === 'example.com' ||
|
|
@@ -620,6 +690,7 @@ function isHostnameOnPrivateNetwork(hostname) {
|
|
|
620
690
|
*
|
|
621
691
|
* @param {string} ipAddress - The IP address to check.
|
|
622
692
|
* @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
|
|
693
|
+
* @public exported from `@promptbook/utils`
|
|
623
694
|
*/
|
|
624
695
|
function isUrlOnPrivateNetwork(url) {
|
|
625
696
|
if (typeof url === 'string') {
|
|
@@ -635,6 +706,8 @@ function isUrlOnPrivateNetwork(url) {
|
|
|
635
706
|
* Note: There are two simmilar functions:
|
|
636
707
|
* - `isValidUrl` which tests any URL
|
|
637
708
|
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
709
|
+
*
|
|
710
|
+
* @public exported from `@promptbook/utils`
|
|
638
711
|
*/
|
|
639
712
|
function isValidUrl(url) {
|
|
640
713
|
if (typeof url !== 'string') {
|
|
@@ -661,6 +734,8 @@ function isValidUrl(url) {
|
|
|
661
734
|
* Note: There are two simmilar functions:
|
|
662
735
|
* - `isValidUrl` which tests any URL
|
|
663
736
|
* - `isValidPipelineUrl` *(this one)* which tests just pipeline URL
|
|
737
|
+
*
|
|
738
|
+
* @public exported from `@promptbook/utils`
|
|
664
739
|
*/
|
|
665
740
|
function isValidPipelineUrl(url) {
|
|
666
741
|
if (!isValidUrl(url)) {
|
|
@@ -698,6 +773,7 @@ function isValidPipelineUrl(url) {
|
|
|
698
773
|
* @param pipeline valid or invalid PipelineJson
|
|
699
774
|
* @returns the same pipeline if it is logically valid
|
|
700
775
|
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
776
|
+
* @public exported from `@promptbook/core`
|
|
701
777
|
*/
|
|
702
778
|
function validatePipeline(pipeline) {
|
|
703
779
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
@@ -927,6 +1003,8 @@ function validatePipeline(pipeline) {
|
|
|
927
1003
|
|
|
928
1004
|
/**
|
|
929
1005
|
* This error indicates that promptbook not found in the collection
|
|
1006
|
+
*
|
|
1007
|
+
* @public exported from `@promptbook/core`
|
|
930
1008
|
*/
|
|
931
1009
|
var NotFoundError = /** @class */ (function (_super) {
|
|
932
1010
|
__extends(NotFoundError, _super);
|
|
@@ -941,6 +1019,8 @@ var NotFoundError = /** @class */ (function (_super) {
|
|
|
941
1019
|
|
|
942
1020
|
/**
|
|
943
1021
|
* This error indicates errors in referencing promptbooks between each other
|
|
1022
|
+
*
|
|
1023
|
+
* @public exported from `@promptbook/core`
|
|
944
1024
|
*/
|
|
945
1025
|
var ReferenceError$1 = /** @class */ (function (_super) {
|
|
946
1026
|
__extends(ReferenceError, _super);
|
|
@@ -958,6 +1038,7 @@ var ReferenceError$1 = /** @class */ (function (_super) {
|
|
|
958
1038
|
*
|
|
959
1039
|
* @param template the template with parameters in {curly} braces
|
|
960
1040
|
* @returns the list of parameter names
|
|
1041
|
+
* @public exported from `@promptbook/utils`
|
|
961
1042
|
*/
|
|
962
1043
|
function extractParameterNames(template) {
|
|
963
1044
|
var e_1, _a;
|
|
@@ -982,6 +1063,8 @@ function extractParameterNames(template) {
|
|
|
982
1063
|
|
|
983
1064
|
/**
|
|
984
1065
|
* Unprepare just strips the preparation data of the pipeline
|
|
1066
|
+
*
|
|
1067
|
+
* @public exported from `@promptbook/core`
|
|
985
1068
|
*/
|
|
986
1069
|
function unpreparePipeline(pipeline) {
|
|
987
1070
|
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
|
|
@@ -998,7 +1081,6 @@ function unpreparePipeline(pipeline) {
|
|
|
998
1081
|
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
999
1082
|
}
|
|
1000
1083
|
/**
|
|
1001
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
1002
1084
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
1003
1085
|
* TODO: Write tests for `preparePipeline`
|
|
1004
1086
|
* TODO: [🍙] Make some standart order of json properties
|
|
@@ -1100,6 +1182,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1100
1182
|
*
|
|
1101
1183
|
* @param promptbookSources
|
|
1102
1184
|
* @returns PipelineCollection
|
|
1185
|
+
* @public exported from `@promptbook/core`
|
|
1103
1186
|
*/
|
|
1104
1187
|
function createCollectionFromJson() {
|
|
1105
1188
|
var promptbooks = [];
|
|
@@ -1127,6 +1210,7 @@ function createCollectionFromJson() {
|
|
|
1127
1210
|
* @param promptbookSourcesPromiseOrFactory
|
|
1128
1211
|
* @returns PipelineCollection
|
|
1129
1212
|
* @deprecated Do not use, it will became internal tool for other constructor functions
|
|
1213
|
+
* @public exported from `@promptbook/core`
|
|
1130
1214
|
*/
|
|
1131
1215
|
function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
1132
1216
|
var collection = null;
|
|
@@ -1197,8 +1281,8 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
1197
1281
|
|
|
1198
1282
|
/**
|
|
1199
1283
|
* Constructs Promptbook from remote Promptbase URL
|
|
1200
|
-
|
|
1201
1284
|
* @returns PipelineCollection
|
|
1285
|
+
* @public exported from `@promptbook/core`
|
|
1202
1286
|
*/
|
|
1203
1287
|
function createCollectionFromUrl(url, options) {
|
|
1204
1288
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1238,6 +1322,7 @@ function createCollectionFromUrl(url, options) {
|
|
|
1238
1322
|
*
|
|
1239
1323
|
* @param promptbookSources
|
|
1240
1324
|
* @returns PipelineCollection
|
|
1325
|
+
* @public exported from `@promptbook/core`
|
|
1241
1326
|
*/
|
|
1242
1327
|
function createSubcollection(collection, predicate) {
|
|
1243
1328
|
function listPipelines() {
|
|
@@ -1313,6 +1398,7 @@ function createSubcollection(collection, predicate) {
|
|
|
1313
1398
|
* Block type describes the way how the block is blockd
|
|
1314
1399
|
*
|
|
1315
1400
|
* @see https://github.com/webgptorg/promptbook#block-type
|
|
1401
|
+
* @public exported from `@promptbook/core`
|
|
1316
1402
|
*/
|
|
1317
1403
|
var BlockTypes = [
|
|
1318
1404
|
'PROMPT_TEMPLATE',
|
|
@@ -1328,6 +1414,8 @@ var BlockTypes = [
|
|
|
1328
1414
|
|
|
1329
1415
|
/**
|
|
1330
1416
|
* @@@
|
|
1417
|
+
*
|
|
1418
|
+
* @public exported from `@promptbook/utils`
|
|
1331
1419
|
*/
|
|
1332
1420
|
function deepClone(objectValue) {
|
|
1333
1421
|
return JSON.parse(JSON.stringify(objectValue));
|
|
@@ -1344,14 +1432,13 @@ function deepClone(objectValue) {
|
|
|
1344
1432
|
*/
|
|
1345
1433
|
}
|
|
1346
1434
|
/**
|
|
1347
|
-
* TODO: [🔼] Export from `@promptbook/utils`
|
|
1348
1435
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1349
1436
|
*/
|
|
1350
1437
|
|
|
1351
1438
|
/**
|
|
1352
1439
|
* @@@
|
|
1353
1440
|
*
|
|
1354
|
-
*
|
|
1441
|
+
* @public exported from `@promptbook/core`
|
|
1355
1442
|
*/
|
|
1356
1443
|
var ZERO_USAGE = deepFreeze({
|
|
1357
1444
|
price: { value: 0 },
|
|
@@ -1378,6 +1465,8 @@ var ZERO_USAGE = deepFreeze({
|
|
|
1378
1465
|
* Function `addUsage` will add multiple usages into one
|
|
1379
1466
|
*
|
|
1380
1467
|
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
1468
|
+
*
|
|
1469
|
+
* @public exported from `@promptbook/core`
|
|
1381
1470
|
*/
|
|
1382
1471
|
function addUsage() {
|
|
1383
1472
|
var usageItems = [];
|
|
@@ -1450,6 +1539,7 @@ function addUsage() {
|
|
|
1450
1539
|
* @param array - Array to iterate over
|
|
1451
1540
|
* @param options - Options for the function
|
|
1452
1541
|
* @param callbackfunction - Function to call for each item
|
|
1542
|
+
* @public exported from `@promptbook/utils`
|
|
1453
1543
|
*/
|
|
1454
1544
|
function forEachAsync(array, options, callbackfunction) {
|
|
1455
1545
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1736,6 +1826,8 @@ var defaultDiacriticsRemovalMap = [
|
|
|
1736
1826
|
* > "ě" => "e"
|
|
1737
1827
|
* > "Ă" => "A"
|
|
1738
1828
|
* > ...
|
|
1829
|
+
*
|
|
1830
|
+
* @public exported from `@promptbook/utils`
|
|
1739
1831
|
*/
|
|
1740
1832
|
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
1741
1833
|
// tslint:disable-next-line: prefer-for-of
|
|
@@ -1763,7 +1855,11 @@ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
|
1763
1855
|
*/
|
|
1764
1856
|
|
|
1765
1857
|
/**
|
|
1858
|
+
* @@@
|
|
1766
1859
|
*
|
|
1860
|
+
* @param input @@@
|
|
1861
|
+
* @returns @@@
|
|
1862
|
+
* @public exported from `@promptbook/utils`
|
|
1767
1863
|
*/
|
|
1768
1864
|
function removeDiacritics(input) {
|
|
1769
1865
|
/*eslint no-control-regex: "off"*/
|
|
@@ -1771,7 +1867,19 @@ function removeDiacritics(input) {
|
|
|
1771
1867
|
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
1772
1868
|
});
|
|
1773
1869
|
}
|
|
1870
|
+
/**
|
|
1871
|
+
* TODO: [Ж] Variant for cyrillic (and in general non-latin) letters
|
|
1872
|
+
*/
|
|
1774
1873
|
|
|
1874
|
+
/**
|
|
1875
|
+
* @@@
|
|
1876
|
+
*
|
|
1877
|
+
* @param text @@@
|
|
1878
|
+
* @returns @@@
|
|
1879
|
+
* @example 'hello-world'
|
|
1880
|
+
* @example 'i-love-promptbook'
|
|
1881
|
+
* @public exported from `@promptbook/utils`
|
|
1882
|
+
*/
|
|
1775
1883
|
function normalizeToKebabCase(text) {
|
|
1776
1884
|
var e_1, _a;
|
|
1777
1885
|
text = removeDiacritics(text);
|
|
@@ -1831,6 +1939,7 @@ function normalizeToKebabCase(text) {
|
|
|
1831
1939
|
*
|
|
1832
1940
|
* @param text with emojis
|
|
1833
1941
|
* @returns text without emojis
|
|
1942
|
+
* @public exported from `@promptbook/utils`
|
|
1834
1943
|
*/
|
|
1835
1944
|
function removeEmojis(text) {
|
|
1836
1945
|
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
@@ -1842,7 +1951,12 @@ function removeEmojis(text) {
|
|
|
1842
1951
|
}
|
|
1843
1952
|
|
|
1844
1953
|
/**
|
|
1845
|
-
*
|
|
1954
|
+
* @@@
|
|
1955
|
+
*
|
|
1956
|
+
* @param value @@@
|
|
1957
|
+
* @returns @@@
|
|
1958
|
+
* @example @@@
|
|
1959
|
+
* @public exported from `@promptbook/utils`
|
|
1846
1960
|
*/
|
|
1847
1961
|
function titleToName(value) {
|
|
1848
1962
|
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
@@ -1861,6 +1975,8 @@ function titleToName(value) {
|
|
|
1861
1975
|
|
|
1862
1976
|
/**
|
|
1863
1977
|
* This error indicates errors during the execution of the pipeline
|
|
1978
|
+
*
|
|
1979
|
+
* @public exported from `@promptbook/core`
|
|
1864
1980
|
*/
|
|
1865
1981
|
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
1866
1982
|
__extends(PipelineExecutionError, _super);
|
|
@@ -1878,6 +1994,7 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
1878
1994
|
*
|
|
1879
1995
|
* @param executionResult - The partial result of the promptnook execution
|
|
1880
1996
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1997
|
+
* @public exported from `@promptbook/core`
|
|
1881
1998
|
*/
|
|
1882
1999
|
function assertsExecutionSuccessful(executionResult) {
|
|
1883
2000
|
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
@@ -1908,6 +2025,7 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1908
2025
|
* @param script from which to extract the variables
|
|
1909
2026
|
* @returns the list of variable names
|
|
1910
2027
|
* @throws {ParsingError} if the script is invalid
|
|
2028
|
+
* @public exported from `@promptbook/utils`
|
|
1911
2029
|
*/
|
|
1912
2030
|
function extractVariables(script) {
|
|
1913
2031
|
var variables = new Set();
|
|
@@ -1956,6 +2074,7 @@ function extractVariables(script) {
|
|
|
1956
2074
|
* @param promptTemplate the template with used parameters
|
|
1957
2075
|
* @returns the set of parameter names
|
|
1958
2076
|
* @throws {ParsingError} if the script is invalid
|
|
2077
|
+
* @public exported from `@promptbook/utils`
|
|
1959
2078
|
*/
|
|
1960
2079
|
function extractParameterNamesFromPromptTemplate(promptTemplate) {
|
|
1961
2080
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
@@ -2029,6 +2148,8 @@ var ExpectError = /** @class */ (function (_super) {
|
|
|
2029
2148
|
|
|
2030
2149
|
/**
|
|
2031
2150
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2151
|
+
*
|
|
2152
|
+
* @public exported from `@promptbook/utils`
|
|
2032
2153
|
*/
|
|
2033
2154
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
2034
2155
|
try {
|
|
@@ -2255,6 +2376,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2255
2376
|
*
|
|
2256
2377
|
*
|
|
2257
2378
|
* Tip: You don't have to use this function directly, just pass an array of LlmExecutionTools to the `ExecutionTools`
|
|
2379
|
+
*
|
|
2380
|
+
* @public exported from `@promptbook/core`
|
|
2258
2381
|
*/
|
|
2259
2382
|
function joinLlmExecutionTools() {
|
|
2260
2383
|
var llmExecutionTools = [];
|
|
@@ -2294,6 +2417,8 @@ function joinLlmExecutionTools() {
|
|
|
2294
2417
|
|
|
2295
2418
|
/**
|
|
2296
2419
|
* Determine if the pipeline is fully prepared
|
|
2420
|
+
*
|
|
2421
|
+
* @public exported from `@promptbook/core`
|
|
2297
2422
|
*/
|
|
2298
2423
|
function isPipelinePrepared(pipeline) {
|
|
2299
2424
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
@@ -2314,7 +2439,6 @@ function isPipelinePrepared(pipeline) {
|
|
|
2314
2439
|
}
|
|
2315
2440
|
/**
|
|
2316
2441
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2317
|
-
* TODO: [🔼] Export via core or utils
|
|
2318
2442
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2319
2443
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2320
2444
|
* - [🏍] ? Is context in each template
|
|
@@ -2360,6 +2484,8 @@ function TODO_USE() {
|
|
|
2360
2484
|
|
|
2361
2485
|
/**
|
|
2362
2486
|
* This error type indicates that some limit was reached
|
|
2487
|
+
*
|
|
2488
|
+
* @public exported from `@promptbook/core`
|
|
2363
2489
|
*/
|
|
2364
2490
|
var LimitReachedError = /** @class */ (function (_super) {
|
|
2365
2491
|
__extends(LimitReachedError, _super);
|
|
@@ -2379,6 +2505,7 @@ var LimitReachedError = /** @class */ (function (_super) {
|
|
|
2379
2505
|
* @param parameters the object with parameters
|
|
2380
2506
|
* @returns the template with replaced parameters
|
|
2381
2507
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2508
|
+
* @public exported from `@promptbook/utils`
|
|
2382
2509
|
*/
|
|
2383
2510
|
function replaceParameters(template, parameters) {
|
|
2384
2511
|
var e_1, _a;
|
|
@@ -2454,6 +2581,7 @@ function replaceParameters(template, parameters) {
|
|
|
2454
2581
|
* Create difference set of two sets.
|
|
2455
2582
|
*
|
|
2456
2583
|
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2584
|
+
* @public exported from `@promptbook/utils`
|
|
2457
2585
|
*/
|
|
2458
2586
|
function difference(a, b, isEqual) {
|
|
2459
2587
|
var e_1, _a;
|
|
@@ -2487,6 +2615,7 @@ function difference(a, b, isEqual) {
|
|
|
2487
2615
|
* Creates a new set with all elements that are present in either set
|
|
2488
2616
|
*
|
|
2489
2617
|
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2618
|
+
* @public exported from `@promptbook/utils`
|
|
2490
2619
|
*/
|
|
2491
2620
|
function union() {
|
|
2492
2621
|
var e_1, _a, e_2, _b;
|
|
@@ -2523,14 +2652,10 @@ function union() {
|
|
|
2523
2652
|
return union;
|
|
2524
2653
|
}
|
|
2525
2654
|
|
|
2526
|
-
/**
|
|
2527
|
-
* The version of the Promptbook library
|
|
2528
|
-
*/
|
|
2529
|
-
var PROMPTBOOK_VERSION = '0.62.0';
|
|
2530
|
-
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2531
|
-
|
|
2532
2655
|
/**
|
|
2533
2656
|
* Counts number of characters in the text
|
|
2657
|
+
*
|
|
2658
|
+
* @public exported from `@promptbook/utils`
|
|
2534
2659
|
*/
|
|
2535
2660
|
function countCharacters(text) {
|
|
2536
2661
|
// Remove null characters
|
|
@@ -2544,6 +2669,8 @@ function countCharacters(text) {
|
|
|
2544
2669
|
|
|
2545
2670
|
/**
|
|
2546
2671
|
* Counts number of lines in the text
|
|
2672
|
+
*
|
|
2673
|
+
* @public exported from `@promptbook/utils`
|
|
2547
2674
|
*/
|
|
2548
2675
|
function countLines(text) {
|
|
2549
2676
|
if (text === '') {
|
|
@@ -2554,6 +2681,8 @@ function countLines(text) {
|
|
|
2554
2681
|
|
|
2555
2682
|
/**
|
|
2556
2683
|
* Counts number of pages in the text
|
|
2684
|
+
*
|
|
2685
|
+
* @public exported from `@promptbook/utils`
|
|
2557
2686
|
*/
|
|
2558
2687
|
function countPages(text) {
|
|
2559
2688
|
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
@@ -2564,6 +2693,8 @@ function countPages(text) {
|
|
|
2564
2693
|
|
|
2565
2694
|
/**
|
|
2566
2695
|
* Counts number of paragraphs in the text
|
|
2696
|
+
*
|
|
2697
|
+
* @public exported from `@promptbook/utils`
|
|
2567
2698
|
*/
|
|
2568
2699
|
function countParagraphs(text) {
|
|
2569
2700
|
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
@@ -2571,12 +2702,16 @@ function countParagraphs(text) {
|
|
|
2571
2702
|
|
|
2572
2703
|
/**
|
|
2573
2704
|
* Split text into sentences
|
|
2705
|
+
*
|
|
2706
|
+
* @public exported from `@promptbook/utils`
|
|
2574
2707
|
*/
|
|
2575
2708
|
function splitIntoSentences(text) {
|
|
2576
2709
|
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
2577
2710
|
}
|
|
2578
2711
|
/**
|
|
2579
2712
|
* Counts number of sentences in the text
|
|
2713
|
+
*
|
|
2714
|
+
* @public exported from `@promptbook/utils`
|
|
2580
2715
|
*/
|
|
2581
2716
|
function countSentences(text) {
|
|
2582
2717
|
return splitIntoSentences(text).length;
|
|
@@ -2584,6 +2719,8 @@ function countSentences(text) {
|
|
|
2584
2719
|
|
|
2585
2720
|
/**
|
|
2586
2721
|
* Counts number of words in the text
|
|
2722
|
+
*
|
|
2723
|
+
* @public exported from `@promptbook/utils`
|
|
2587
2724
|
*/
|
|
2588
2725
|
function countWords(text) {
|
|
2589
2726
|
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
@@ -2593,6 +2730,8 @@ function countWords(text) {
|
|
|
2593
2730
|
|
|
2594
2731
|
/**
|
|
2595
2732
|
* Index of all counter functions
|
|
2733
|
+
*
|
|
2734
|
+
* @public exported from `@promptbook/utils`
|
|
2596
2735
|
*/
|
|
2597
2736
|
var CountUtils = {
|
|
2598
2737
|
CHARACTERS: countCharacters,
|
|
@@ -2612,6 +2751,7 @@ var CountUtils = {
|
|
|
2612
2751
|
*
|
|
2613
2752
|
* @throws {ExpectError} if the expectations are not met
|
|
2614
2753
|
* @returns {void} Nothing
|
|
2754
|
+
* @public exported from `@promptbook/core`
|
|
2615
2755
|
*/
|
|
2616
2756
|
function checkExpectations(expectations, value) {
|
|
2617
2757
|
var e_1, _a;
|
|
@@ -2643,6 +2783,7 @@ function checkExpectations(expectations, value) {
|
|
|
2643
2783
|
* - `isPassingExpectations` which returns a boolean
|
|
2644
2784
|
*
|
|
2645
2785
|
* @returns {boolean} True if the expectations are met
|
|
2786
|
+
* @public exported from `@promptbook/core`
|
|
2646
2787
|
*/
|
|
2647
2788
|
function isPassingExpectations(expectations, value) {
|
|
2648
2789
|
try {
|
|
@@ -2665,6 +2806,7 @@ function isPassingExpectations(expectations, value) {
|
|
|
2665
2806
|
*
|
|
2666
2807
|
* @returns The executor function
|
|
2667
2808
|
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
2809
|
+
* @public exported from `@promptbook/core`
|
|
2668
2810
|
*/
|
|
2669
2811
|
function createPipelineExecutor(options) {
|
|
2670
2812
|
var _this = this;
|
|
@@ -3453,6 +3595,8 @@ function createPipelineExecutor(options) {
|
|
|
3453
3595
|
|
|
3454
3596
|
/**
|
|
3455
3597
|
* @@@
|
|
3598
|
+
*
|
|
3599
|
+
* @public exported from `@promptbook/core`
|
|
3456
3600
|
*/
|
|
3457
3601
|
function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
3458
3602
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3588,6 +3732,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3588
3732
|
* Prepares the knowle
|
|
3589
3733
|
*
|
|
3590
3734
|
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
3735
|
+
* @public exported from `@promptbook/core`
|
|
3591
3736
|
*/
|
|
3592
3737
|
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
3593
3738
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3602,7 +3747,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
|
|
|
3602
3747
|
var partialPieces, pieces;
|
|
3603
3748
|
return __generator(this, function (_a) {
|
|
3604
3749
|
switch (_a.label) {
|
|
3605
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is
|
|
3750
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is - BE AWARE of big package size
|
|
3606
3751
|
options)];
|
|
3607
3752
|
case 1:
|
|
3608
3753
|
partialPieces = _a.sent();
|
|
@@ -3640,7 +3785,6 @@ TODO: [🧊] This is how it can look in future
|
|
|
3640
3785
|
> ):
|
|
3641
3786
|
*/
|
|
3642
3787
|
/**
|
|
3643
|
-
* TODO: [🐝][🔼] !!! Export via `@promptbook/core`
|
|
3644
3788
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3645
3789
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
3646
3790
|
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
@@ -3654,6 +3798,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
3654
3798
|
*
|
|
3655
3799
|
* @param llmTools LLM tools to be intercepted with usage counting
|
|
3656
3800
|
* @returns LLM tools with same functionality with added total cost counting
|
|
3801
|
+
* @public exported from `@promptbook/core`
|
|
3657
3802
|
*/
|
|
3658
3803
|
function countTotalUsage(llmTools) {
|
|
3659
3804
|
var _this = this;
|
|
@@ -3721,7 +3866,6 @@ function countTotalUsage(llmTools) {
|
|
|
3721
3866
|
return proxyTools;
|
|
3722
3867
|
}
|
|
3723
3868
|
/**
|
|
3724
|
-
* TODO: [🔼] !!! Export via `@promptbookcore/`
|
|
3725
3869
|
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
3726
3870
|
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
3727
3871
|
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
@@ -3733,6 +3877,7 @@ function countTotalUsage(llmTools) {
|
|
|
3733
3877
|
* Prepares the persona for the pipeline
|
|
3734
3878
|
*
|
|
3735
3879
|
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
3880
|
+
* @public exported from `@promptbook/core`
|
|
3736
3881
|
*/
|
|
3737
3882
|
function preparePersona(personaDescription, options) {
|
|
3738
3883
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3787,7 +3932,6 @@ function preparePersona(personaDescription, options) {
|
|
|
3787
3932
|
});
|
|
3788
3933
|
}
|
|
3789
3934
|
/**
|
|
3790
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3791
3935
|
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
3792
3936
|
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
3793
3937
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
@@ -3795,6 +3939,8 @@ function preparePersona(personaDescription, options) {
|
|
|
3795
3939
|
|
|
3796
3940
|
/**
|
|
3797
3941
|
* @@@
|
|
3942
|
+
*
|
|
3943
|
+
* @public exported from `@promptbook/core`
|
|
3798
3944
|
*/
|
|
3799
3945
|
function prepareTemplates(pipeline, options) {
|
|
3800
3946
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3836,7 +3982,6 @@ function prepareTemplates(pipeline, options) {
|
|
|
3836
3982
|
* TODO: [🧠] Add context to each template (if missing)
|
|
3837
3983
|
* TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
3838
3984
|
* TODO: [♨] !!! Prepare index the samples and maybe templates
|
|
3839
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3840
3985
|
* TODO: Write tests for `preparePipeline`
|
|
3841
3986
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3842
3987
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3849,6 +3994,7 @@ function prepareTemplates(pipeline, options) {
|
|
|
3849
3994
|
*
|
|
3850
3995
|
* Note: This function does not validate logic of the pipeline
|
|
3851
3996
|
* Note: This function acts as part of compilation process
|
|
3997
|
+
* @public exported from `@promptbook/core`
|
|
3852
3998
|
*/
|
|
3853
3999
|
function preparePipeline(pipeline, options) {
|
|
3854
4000
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3925,7 +4071,6 @@ function preparePipeline(pipeline, options) {
|
|
|
3925
4071
|
});
|
|
3926
4072
|
}
|
|
3927
4073
|
/**
|
|
3928
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3929
4074
|
* TODO: Write tests for `preparePipeline`
|
|
3930
4075
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3931
4076
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3936,6 +4081,7 @@ function preparePipeline(pipeline, options) {
|
|
|
3936
4081
|
* Tests if given string is valid URL.
|
|
3937
4082
|
*
|
|
3938
4083
|
* Note: This does not check if the file exists only if the path is valid
|
|
4084
|
+
* @public exported from `@promptbook/utils`
|
|
3939
4085
|
*/
|
|
3940
4086
|
function isValidFilePath(filePath) {
|
|
3941
4087
|
if (typeof filePath !== 'string') {
|
|
@@ -4118,6 +4264,7 @@ var personaCommandParser = {
|
|
|
4118
4264
|
*
|
|
4119
4265
|
* @param {string} str - The string to remove Markdown tags from.
|
|
4120
4266
|
* @returns {string} The input string with all Markdown tags removed.
|
|
4267
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
4121
4268
|
*/
|
|
4122
4269
|
function removeMarkdownFormatting(str) {
|
|
4123
4270
|
// Remove bold formatting
|
|
@@ -4129,6 +4276,15 @@ function removeMarkdownFormatting(str) {
|
|
|
4129
4276
|
return str;
|
|
4130
4277
|
}
|
|
4131
4278
|
|
|
4279
|
+
/**
|
|
4280
|
+
* @@@
|
|
4281
|
+
*
|
|
4282
|
+
* @param text @@@
|
|
4283
|
+
* @returns @@@
|
|
4284
|
+
* @example 'HELLO_WORLD'
|
|
4285
|
+
* @example 'I_LOVE_PROMPTBOOK'
|
|
4286
|
+
* @public exported from `@promptbook/utils`
|
|
4287
|
+
*/
|
|
4132
4288
|
function normalizeTo_SCREAMING_CASE(text) {
|
|
4133
4289
|
var e_1, _a;
|
|
4134
4290
|
var charType;
|
|
@@ -4296,7 +4452,7 @@ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPH
|
|
|
4296
4452
|
* @returns parsed number
|
|
4297
4453
|
* @throws {ParsingError} if the value is not a number
|
|
4298
4454
|
*
|
|
4299
|
-
* @
|
|
4455
|
+
* @public exported from `@promptbook/utils`
|
|
4300
4456
|
*/
|
|
4301
4457
|
function parseNumber(value) {
|
|
4302
4458
|
var originalValue = value;
|
|
@@ -4352,6 +4508,7 @@ function parseNumber(value) {
|
|
|
4352
4508
|
}
|
|
4353
4509
|
/**
|
|
4354
4510
|
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
4511
|
+
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
4355
4512
|
*/
|
|
4356
4513
|
|
|
4357
4514
|
/**
|
|
@@ -4663,6 +4820,13 @@ var parameterCommandParser = {
|
|
|
4663
4820
|
},
|
|
4664
4821
|
};
|
|
4665
4822
|
|
|
4823
|
+
/**
|
|
4824
|
+
* @@@
|
|
4825
|
+
*
|
|
4826
|
+
* @param javascriptName @@@
|
|
4827
|
+
* @returns @@@
|
|
4828
|
+
* @public exported from `@promptbook/utils`
|
|
4829
|
+
*/
|
|
4666
4830
|
function isValidJavascriptName(javascriptName) {
|
|
4667
4831
|
if (typeof javascriptName !== 'string') {
|
|
4668
4832
|
return false;
|
|
@@ -5135,6 +5299,8 @@ function parseCommandVariant(input) {
|
|
|
5135
5299
|
|
|
5136
5300
|
/**
|
|
5137
5301
|
* This error type indicates that some part of the code is not implemented yet
|
|
5302
|
+
*
|
|
5303
|
+
* @public exported from `@promptbook/core`
|
|
5138
5304
|
*/
|
|
5139
5305
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
5140
5306
|
__extends(NotYetImplementedError, _super);
|
|
@@ -5161,7 +5327,8 @@ var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
|
5161
5327
|
* Note: It can not work with html syntax and comments
|
|
5162
5328
|
*
|
|
5163
5329
|
* @param markdown any valid markdown
|
|
5164
|
-
* @returns
|
|
5330
|
+
* @returns @@@
|
|
5331
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5165
5332
|
*/
|
|
5166
5333
|
function extractAllListItemsFromMarkdown(markdown) {
|
|
5167
5334
|
var e_1, _a;
|
|
@@ -5201,7 +5368,7 @@ function extractAllListItemsFromMarkdown(markdown) {
|
|
|
5201
5368
|
*
|
|
5202
5369
|
* @param markdown any valid markdown
|
|
5203
5370
|
* @returns code blocks with language and content
|
|
5204
|
-
*
|
|
5371
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5205
5372
|
*/
|
|
5206
5373
|
function extractAllBlocksFromMarkdown(markdown) {
|
|
5207
5374
|
var e_1, _a;
|
|
@@ -5278,6 +5445,7 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
5278
5445
|
*
|
|
5279
5446
|
* @param markdown any valid markdown
|
|
5280
5447
|
* @returns code block with language and content
|
|
5448
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5281
5449
|
*/
|
|
5282
5450
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5283
5451
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
@@ -5292,6 +5460,8 @@ function extractOneBlockFromMarkdown(markdown) {
|
|
|
5292
5460
|
|
|
5293
5461
|
/**
|
|
5294
5462
|
* Parses markdown section to title its level and content
|
|
5463
|
+
*
|
|
5464
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5295
5465
|
*/
|
|
5296
5466
|
function parseMarkdownSection(value) {
|
|
5297
5467
|
var _a, _b;
|
|
@@ -5316,6 +5486,8 @@ function parseMarkdownSection(value) {
|
|
|
5316
5486
|
|
|
5317
5487
|
/**
|
|
5318
5488
|
* Splits the markdown into sections by headings
|
|
5489
|
+
*
|
|
5490
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5319
5491
|
*/
|
|
5320
5492
|
function splitMarkdownIntoSections(markdown) {
|
|
5321
5493
|
var e_1, _a;
|
|
@@ -5377,6 +5549,7 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
5377
5549
|
return sections;
|
|
5378
5550
|
}
|
|
5379
5551
|
/**
|
|
5552
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
5380
5553
|
* Note: [🕞] In past (commit 42086e1603cbed506482997c00a8ee979af0a247) there was much more
|
|
5381
5554
|
* sophisticated implementation of this function through parsing markdown into JSON structure
|
|
5382
5555
|
* and flattening the actual structure
|
|
@@ -5388,6 +5561,8 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
5388
5561
|
*
|
|
5389
5562
|
* - It always have h1 - if there is no h1 in the markdown, it will be added "# Untitled"
|
|
5390
5563
|
* - All other headings are normalized to h2
|
|
5564
|
+
*
|
|
5565
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5391
5566
|
*/
|
|
5392
5567
|
function flattenMarkdown(markdown) {
|
|
5393
5568
|
var e_1, _a;
|
|
@@ -5423,6 +5598,7 @@ function flattenMarkdown(markdown) {
|
|
|
5423
5598
|
return spaceTrim(flattenedMarkdown);
|
|
5424
5599
|
}
|
|
5425
5600
|
/**
|
|
5601
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
5426
5602
|
* Note: [🕞] In past (commit 42086e1603cbed506482997c00a8ee979af0a247) there was much more
|
|
5427
5603
|
* sophisticated implementation of this function through parsing markdown into JSON structure
|
|
5428
5604
|
* and flattening the actual structure
|
|
@@ -5434,6 +5610,7 @@ function flattenMarkdown(markdown) {
|
|
|
5434
5610
|
*
|
|
5435
5611
|
* @param {string} content - The string to remove comments from.
|
|
5436
5612
|
* @returns {string} The input string with all comments removed.
|
|
5613
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5437
5614
|
*/
|
|
5438
5615
|
function removeContentComments(content) {
|
|
5439
5616
|
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
@@ -5447,12 +5624,13 @@ function removeContentComments(content) {
|
|
|
5447
5624
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5448
5625
|
* - `preparePipeline` - just one step in the compilation process
|
|
5449
5626
|
*
|
|
5627
|
+
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5628
|
+
* Note: This function acts as compilation process
|
|
5629
|
+
*
|
|
5450
5630
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
5451
5631
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
5452
5632
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
5453
|
-
*
|
|
5454
|
-
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5455
|
-
* Note: This function acts as compilation process
|
|
5633
|
+
* @public exported from `@promptbook/core`
|
|
5456
5634
|
*/
|
|
5457
5635
|
function pipelineStringToJsonSync(pipelineString) {
|
|
5458
5636
|
var e_1, _a, e_2, _b;
|
|
@@ -5845,13 +6023,14 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5845
6023
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5846
6024
|
* - `preparePipeline` - just one step in the compilation process
|
|
5847
6025
|
*
|
|
6026
|
+
* Note: This function does not validate logic of the pipeline only the syntax
|
|
6027
|
+
* Note: This function acts as compilation process
|
|
6028
|
+
*
|
|
5848
6029
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
5849
6030
|
* @param options - Options and tools for the compilation
|
|
5850
6031
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
5851
6032
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
5852
|
-
*
|
|
5853
|
-
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5854
|
-
* Note: This function acts as compilation process
|
|
6033
|
+
* @public exported from `@promptbook/core`
|
|
5855
6034
|
*/
|
|
5856
6035
|
function pipelineStringToJson(pipelineString, options) {
|
|
5857
6036
|
if (options === void 0) { options = { llmTools: null }; }
|
|
@@ -5880,7 +6059,7 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
5880
6059
|
/**
|
|
5881
6060
|
* Add or modify an auto-generated section in a markdown file
|
|
5882
6061
|
*
|
|
5883
|
-
* @
|
|
6062
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5884
6063
|
*/
|
|
5885
6064
|
function addAutoGeneratedSection(content, options) {
|
|
5886
6065
|
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
@@ -5900,7 +6079,20 @@ function addAutoGeneratedSection(content, options) {
|
|
|
5900
6079
|
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
5901
6080
|
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
5902
6081
|
}
|
|
6082
|
+
/**
|
|
6083
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
6084
|
+
*/
|
|
5903
6085
|
|
|
6086
|
+
/**
|
|
6087
|
+
* @@@
|
|
6088
|
+
*
|
|
6089
|
+
* @param text @@@
|
|
6090
|
+
* @param _isFirstLetterCapital @@@
|
|
6091
|
+
* @returns @@@
|
|
6092
|
+
* @example 'helloWorld'
|
|
6093
|
+
* @example 'iLovePromptbook'
|
|
6094
|
+
* @public exported from `@promptbook/utils`
|
|
6095
|
+
*/
|
|
5904
6096
|
function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
5905
6097
|
var e_1, _a;
|
|
5906
6098
|
if (_isFirstLetterCapital === void 0) { _isFirstLetterCapital = false; }
|
|
@@ -5959,6 +6151,8 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
|
5959
6151
|
* Creates a Mermaid graph based on the promptbook
|
|
5960
6152
|
*
|
|
5961
6153
|
* Note: The result is not wrapped in a Markdown code block
|
|
6154
|
+
*
|
|
6155
|
+
* @public exported from `@promptbook/utils`
|
|
5962
6156
|
*/
|
|
5963
6157
|
function renderPromptbookMermaid(pipelineJson, options) {
|
|
5964
6158
|
var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
|
|
@@ -6015,6 +6209,8 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
6015
6209
|
|
|
6016
6210
|
/**
|
|
6017
6211
|
* Prettyfies Promptbook string and adds Mermaid graph
|
|
6212
|
+
*
|
|
6213
|
+
* @public exported from `@promptbook/core`
|
|
6018
6214
|
*/
|
|
6019
6215
|
function prettifyPipelineString(pipelineString, options) {
|
|
6020
6216
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -6057,6 +6253,8 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
6057
6253
|
*
|
|
6058
6254
|
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
6059
6255
|
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
6256
|
+
*
|
|
6257
|
+
* @public exported from `@promptbook/core`
|
|
6060
6258
|
*/
|
|
6061
6259
|
function stringifyPipelineJson(pipeline) {
|
|
6062
6260
|
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
@@ -6076,6 +6274,8 @@ function stringifyPipelineJson(pipeline) {
|
|
|
6076
6274
|
|
|
6077
6275
|
/**
|
|
6078
6276
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
6277
|
+
*
|
|
6278
|
+
* @public exported from `@promptbook/core`
|
|
6079
6279
|
*/
|
|
6080
6280
|
var CollectionError = /** @class */ (function (_super) {
|
|
6081
6281
|
__extends(CollectionError, _super);
|
|
@@ -6088,8 +6288,26 @@ var CollectionError = /** @class */ (function (_super) {
|
|
|
6088
6288
|
return CollectionError;
|
|
6089
6289
|
}(Error));
|
|
6090
6290
|
|
|
6291
|
+
/**
|
|
6292
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
6293
|
+
*
|
|
6294
|
+
* @public exported from `@promptbook/core`
|
|
6295
|
+
*/
|
|
6296
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
6297
|
+
__extends(EnvironmentMismatchError, _super);
|
|
6298
|
+
function EnvironmentMismatchError(message) {
|
|
6299
|
+
var _this = _super.call(this, message) || this;
|
|
6300
|
+
_this.name = 'EnvironmentMismatchError';
|
|
6301
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
6302
|
+
return _this;
|
|
6303
|
+
}
|
|
6304
|
+
return EnvironmentMismatchError;
|
|
6305
|
+
}(Error));
|
|
6306
|
+
|
|
6091
6307
|
/**
|
|
6092
6308
|
* This error type indicates that the version of the pipeline is not matching the expected version
|
|
6309
|
+
*
|
|
6310
|
+
* @public exported from `@promptbook/core`
|
|
6093
6311
|
*/
|
|
6094
6312
|
var VersionMismatchError = /** @class */ (function (_super) {
|
|
6095
6313
|
__extends(VersionMismatchError, _super);
|
|
@@ -6104,6 +6322,8 @@ var VersionMismatchError = /** @class */ (function (_super) {
|
|
|
6104
6322
|
|
|
6105
6323
|
/**
|
|
6106
6324
|
* Pretty print an embedding vector for logging
|
|
6325
|
+
*
|
|
6326
|
+
* @public exported from `@promptbook/core`
|
|
6107
6327
|
*/
|
|
6108
6328
|
function embeddingVectorToString(embeddingVector) {
|
|
6109
6329
|
var vectorLength = Math.pow(embeddingVector.reduce(function (acc, val) { return acc + Math.pow(val, 2); }, 0), 0.5);
|
|
@@ -6116,6 +6336,8 @@ function embeddingVectorToString(embeddingVector) {
|
|
|
6116
6336
|
* Note: This is an estimate based of theese sources:
|
|
6117
6337
|
* - https://jecas.cz/doba-cteni
|
|
6118
6338
|
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
6339
|
+
*
|
|
6340
|
+
* @public exported from `@promptbook/core`
|
|
6119
6341
|
*/
|
|
6120
6342
|
function usageToWorktime(usage) {
|
|
6121
6343
|
var value = usage.input.wordsCount.value / (200 /* words per minute */ * 60) +
|
|
@@ -6130,6 +6352,8 @@ function usageToWorktime(usage) {
|
|
|
6130
6352
|
|
|
6131
6353
|
/**
|
|
6132
6354
|
* Function `usageToHuman` will take usage and convert it to human readable report
|
|
6355
|
+
*
|
|
6356
|
+
* @public exported from `@promptbook/core`
|
|
6133
6357
|
*/
|
|
6134
6358
|
function usageToHuman(usage) {
|
|
6135
6359
|
var report = 'Usage:';
|
|
@@ -6154,6 +6378,8 @@ function usageToHuman(usage) {
|
|
|
6154
6378
|
/**
|
|
6155
6379
|
* Delagates the user interaction to a async callback function
|
|
6156
6380
|
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
6381
|
+
*
|
|
6382
|
+
* @public exported from `@promptbook/core`
|
|
6157
6383
|
*/
|
|
6158
6384
|
var CallbackInterfaceTools = /** @class */ (function () {
|
|
6159
6385
|
function CallbackInterfaceTools(options) {
|
|
@@ -6186,6 +6412,8 @@ var CallbackInterfaceTools = /** @class */ (function () {
|
|
|
6186
6412
|
*
|
|
6187
6413
|
* Warning: It is used for testing and mocking
|
|
6188
6414
|
* **NOT intended to use in the production** due to its synchronous nature.
|
|
6415
|
+
*
|
|
6416
|
+
* @public exported from `@promptbook/core`
|
|
6189
6417
|
*/
|
|
6190
6418
|
var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
6191
6419
|
function SimplePromptInterfaceTools(options) {
|
|
@@ -6217,12 +6445,260 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
|
6217
6445
|
*/
|
|
6218
6446
|
|
|
6219
6447
|
/**
|
|
6220
|
-
*
|
|
6448
|
+
* Stores
|
|
6449
|
+
*
|
|
6450
|
+
* @public exported from `@promptbook/core`
|
|
6221
6451
|
*/
|
|
6222
|
-
var
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
}
|
|
6452
|
+
var MemoryStorage = /** @class */ (function () {
|
|
6453
|
+
function MemoryStorage() {
|
|
6454
|
+
this.storage = {};
|
|
6455
|
+
}
|
|
6456
|
+
Object.defineProperty(MemoryStorage.prototype, "length", {
|
|
6457
|
+
/**
|
|
6458
|
+
* Returns the number of key/value pairs currently present in the list associated with the object.
|
|
6459
|
+
*/
|
|
6460
|
+
get: function () {
|
|
6461
|
+
return Object.keys(this.storage).length;
|
|
6462
|
+
},
|
|
6463
|
+
enumerable: false,
|
|
6464
|
+
configurable: true
|
|
6465
|
+
});
|
|
6466
|
+
/**
|
|
6467
|
+
* Empties the list associated with the object of all key/value pairs, if there are any.
|
|
6468
|
+
*/
|
|
6469
|
+
MemoryStorage.prototype.clear = function () {
|
|
6470
|
+
this.storage = {};
|
|
6471
|
+
};
|
|
6472
|
+
/**
|
|
6473
|
+
* Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
|
|
6474
|
+
*/
|
|
6475
|
+
MemoryStorage.prototype.getItem = function (key) {
|
|
6476
|
+
return this.storage[key] || null;
|
|
6477
|
+
};
|
|
6478
|
+
/**
|
|
6479
|
+
* Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
|
|
6480
|
+
*/
|
|
6481
|
+
MemoryStorage.prototype.key = function (index) {
|
|
6482
|
+
return Object.keys(this.storage)[index] || null;
|
|
6483
|
+
};
|
|
6484
|
+
/**
|
|
6485
|
+
* Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
6486
|
+
*/
|
|
6487
|
+
MemoryStorage.prototype.setItem = function (key, value) {
|
|
6488
|
+
this.storage[key] = value;
|
|
6489
|
+
};
|
|
6490
|
+
/**
|
|
6491
|
+
* Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
|
|
6492
|
+
*/
|
|
6493
|
+
MemoryStorage.prototype.removeItem = function (key) {
|
|
6494
|
+
delete this.storage[key];
|
|
6495
|
+
};
|
|
6496
|
+
return MemoryStorage;
|
|
6497
|
+
}());
|
|
6498
|
+
|
|
6499
|
+
/**
|
|
6500
|
+
* Simple wrapper `new Date().toISOString()`
|
|
6501
|
+
*
|
|
6502
|
+
* @returns string_date branded type
|
|
6503
|
+
* @public exported from `@promptbook/utils`
|
|
6504
|
+
*/
|
|
6505
|
+
function $currentDate() {
|
|
6506
|
+
return new Date().toISOString();
|
|
6507
|
+
}
|
|
6508
|
+
|
|
6509
|
+
/**
|
|
6510
|
+
* Intercepts LLM tools and counts total usage of the tools
|
|
6511
|
+
*
|
|
6512
|
+
* Note: It can take extended `LlmExecutionTools` and cache the
|
|
6513
|
+
*
|
|
6514
|
+
* @param llmTools LLM tools to be intercepted with usage counting, it can contain extra methods like `totalUsage`
|
|
6515
|
+
* @returns LLM tools with same functionality with added total cost counting
|
|
6516
|
+
* @public exported from `@promptbook/core`
|
|
6517
|
+
*/
|
|
6518
|
+
function cacheLlmTools(llmTools, options) {
|
|
6519
|
+
var _this = this;
|
|
6520
|
+
if (options === void 0) { options = {}; }
|
|
6521
|
+
var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a, _b = options.isReloaded, isReloaded = _b === void 0 ? false : _b;
|
|
6522
|
+
var proxyTools = __assign(__assign({}, llmTools), {
|
|
6523
|
+
// <- Note: [🥫]
|
|
6524
|
+
get title() {
|
|
6525
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
6526
|
+
return llmTools.title;
|
|
6527
|
+
},
|
|
6528
|
+
get description() {
|
|
6529
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
6530
|
+
return llmTools.description;
|
|
6531
|
+
}, listModels: function () {
|
|
6532
|
+
// TODO: [🧠] Should be model listing also cached?
|
|
6533
|
+
return /* not await */ llmTools.listModels();
|
|
6534
|
+
} });
|
|
6535
|
+
var callCommonModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6536
|
+
var key, cacheItem, _a, promptResult, _b;
|
|
6537
|
+
return __generator(this, function (_c) {
|
|
6538
|
+
switch (_c.label) {
|
|
6539
|
+
case 0:
|
|
6540
|
+
key = titleToName(prompt.title.substring(0, MAX_FILENAME_LENGTH - 10) +
|
|
6541
|
+
'-' +
|
|
6542
|
+
sha256(hexEncoder.parse(JSON.stringify(prompt.parameters))).toString( /* hex */));
|
|
6543
|
+
if (!!isReloaded) return [3 /*break*/, 2];
|
|
6544
|
+
return [4 /*yield*/, storage.getItem(key)];
|
|
6545
|
+
case 1:
|
|
6546
|
+
_a = _c.sent();
|
|
6547
|
+
return [3 /*break*/, 3];
|
|
6548
|
+
case 2:
|
|
6549
|
+
_a = null;
|
|
6550
|
+
_c.label = 3;
|
|
6551
|
+
case 3:
|
|
6552
|
+
cacheItem = _a;
|
|
6553
|
+
if (cacheItem) {
|
|
6554
|
+
return [2 /*return*/, cacheItem.promptResult];
|
|
6555
|
+
}
|
|
6556
|
+
_b = prompt.modelRequirements.modelVariant;
|
|
6557
|
+
switch (_b) {
|
|
6558
|
+
case 'CHAT': return [3 /*break*/, 4];
|
|
6559
|
+
case 'COMPLETION': return [3 /*break*/, 6];
|
|
6560
|
+
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
6561
|
+
}
|
|
6562
|
+
return [3 /*break*/, 10];
|
|
6563
|
+
case 4: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
6564
|
+
case 5:
|
|
6565
|
+
promptResult = _c.sent();
|
|
6566
|
+
return [3 /*break*/, 11];
|
|
6567
|
+
case 6: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
6568
|
+
case 7:
|
|
6569
|
+
promptResult = _c.sent();
|
|
6570
|
+
return [3 /*break*/, 11];
|
|
6571
|
+
case 8: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
6572
|
+
case 9:
|
|
6573
|
+
promptResult = _c.sent();
|
|
6574
|
+
return [3 /*break*/, 11];
|
|
6575
|
+
case 10: throw new PipelineExecutionError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
|
|
6576
|
+
case 11: return [4 /*yield*/, storage.setItem(key, {
|
|
6577
|
+
date: $currentDate(),
|
|
6578
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
6579
|
+
prompt: prompt,
|
|
6580
|
+
promptResult: promptResult,
|
|
6581
|
+
})];
|
|
6582
|
+
case 12:
|
|
6583
|
+
_c.sent();
|
|
6584
|
+
return [2 /*return*/, promptResult];
|
|
6585
|
+
}
|
|
6586
|
+
});
|
|
6587
|
+
}); };
|
|
6588
|
+
if (llmTools.callChatModel !== undefined) {
|
|
6589
|
+
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6590
|
+
return __generator(this, function (_a) {
|
|
6591
|
+
return [2 /*return*/, /* not await */ callCommonModel(prompt)];
|
|
6592
|
+
});
|
|
6593
|
+
}); };
|
|
6594
|
+
}
|
|
6595
|
+
if (llmTools.callCompletionModel !== undefined) {
|
|
6596
|
+
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6597
|
+
return __generator(this, function (_a) {
|
|
6598
|
+
return [2 /*return*/, /* not await */ callCommonModel(prompt)];
|
|
6599
|
+
});
|
|
6600
|
+
}); };
|
|
6601
|
+
}
|
|
6602
|
+
if (llmTools.callEmbeddingModel !== undefined) {
|
|
6603
|
+
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6604
|
+
return __generator(this, function (_a) {
|
|
6605
|
+
return [2 /*return*/, /* not await */ callCommonModel(prompt)];
|
|
6606
|
+
});
|
|
6607
|
+
}); };
|
|
6608
|
+
}
|
|
6609
|
+
// <- Note: [🤖]
|
|
6610
|
+
return proxyTools;
|
|
6611
|
+
}
|
|
6612
|
+
/**
|
|
6613
|
+
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
6614
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
6615
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
6616
|
+
* @@@ write discussion about this and storages
|
|
6617
|
+
* @@@ write how to combine multiple interceptors
|
|
6618
|
+
*/
|
|
6619
|
+
|
|
6620
|
+
/**
|
|
6621
|
+
* @@@
|
|
6622
|
+
*
|
|
6623
|
+
* @public exported from `@promptbook/core`
|
|
6624
|
+
*/
|
|
6625
|
+
function limitTotalUsage(llmTools, options) {
|
|
6626
|
+
var _this = this;
|
|
6627
|
+
if (options === void 0) { options = {}; }
|
|
6628
|
+
var _a = options.maxTotalUsage, maxTotalUsage = _a === void 0 ? ZERO_USAGE : _a, _b = options.storage, storage = _b === void 0 ? new MemoryStorage() : _b;
|
|
6629
|
+
TODO_USE(storage);
|
|
6630
|
+
var proxyTools = countTotalUsage(llmTools);
|
|
6631
|
+
if (maxTotalUsage.price.value !== 0) {
|
|
6632
|
+
throw new NotYetImplementedError('`limitTotalUsage` is not yet implemented for non-zero price');
|
|
6633
|
+
// TODO: "Cannot call `callChatModel` because the total cost limit is reached"
|
|
6634
|
+
}
|
|
6635
|
+
if (proxyTools.callChatModel !== undefined) {
|
|
6636
|
+
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6637
|
+
return __generator(this, function (_a) {
|
|
6638
|
+
TODO_USE(prompt);
|
|
6639
|
+
throw new LimitReachedError('Cannot call `callChatModel` because you are not allowed to spend any cost');
|
|
6640
|
+
});
|
|
6641
|
+
}); };
|
|
6642
|
+
}
|
|
6643
|
+
if (proxyTools.callCompletionModel !== undefined) {
|
|
6644
|
+
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6645
|
+
return __generator(this, function (_a) {
|
|
6646
|
+
TODO_USE(prompt);
|
|
6647
|
+
throw new LimitReachedError('Cannot call `callCompletionModel` because you are not allowed to spend any cost');
|
|
6648
|
+
});
|
|
6649
|
+
}); };
|
|
6650
|
+
}
|
|
6651
|
+
if (proxyTools.callEmbeddingModel !== undefined) {
|
|
6652
|
+
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
6653
|
+
return __generator(this, function (_a) {
|
|
6654
|
+
TODO_USE(prompt);
|
|
6655
|
+
throw new LimitReachedError('Cannot call `callEmbeddingModel` because you are not allowed to spend any cost');
|
|
6656
|
+
});
|
|
6657
|
+
}); };
|
|
6658
|
+
}
|
|
6659
|
+
// <- Note: [🤖]
|
|
6660
|
+
return proxyTools;
|
|
6661
|
+
}
|
|
6662
|
+
/**
|
|
6663
|
+
* TODO: Maybe internally use `countTotalUsage`
|
|
6664
|
+
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
6665
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
6666
|
+
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
6667
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
6668
|
+
*/
|
|
6669
|
+
|
|
6670
|
+
/**
|
|
6671
|
+
* This class behaves like LocalStorage but separates keys by prefix
|
|
6672
|
+
*
|
|
6673
|
+
* @public exported from `@promptbook/core`
|
|
6674
|
+
*/
|
|
6675
|
+
var PrefixStorage = /** @class */ (function () {
|
|
6676
|
+
function PrefixStorage(baseStorage, keyPrefix, separator) {
|
|
6677
|
+
if (separator === void 0) { separator = '_'; }
|
|
6678
|
+
this.baseStorage = baseStorage;
|
|
6679
|
+
this.keyPrefix = keyPrefix;
|
|
6680
|
+
this.separator = separator;
|
|
6681
|
+
}
|
|
6682
|
+
/**
|
|
6683
|
+
* Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
|
|
6684
|
+
*/
|
|
6685
|
+
PrefixStorage.prototype.getItem = function (key) {
|
|
6686
|
+
return this.baseStorage.getItem(this.keyPrefix + this.separator + key);
|
|
6687
|
+
};
|
|
6688
|
+
/**
|
|
6689
|
+
* Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
6690
|
+
*/
|
|
6691
|
+
PrefixStorage.prototype.setItem = function (key, value) {
|
|
6692
|
+
return this.baseStorage.setItem(this.keyPrefix + this.separator + key, value);
|
|
6693
|
+
};
|
|
6694
|
+
/**
|
|
6695
|
+
* Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
|
|
6696
|
+
*/
|
|
6697
|
+
PrefixStorage.prototype.removeItem = function (key) {
|
|
6698
|
+
this.baseStorage.removeItem(this.keyPrefix + this.separator + key);
|
|
6699
|
+
};
|
|
6700
|
+
return PrefixStorage;
|
|
6701
|
+
}());
|
|
6226
6702
|
|
|
6227
6703
|
/**
|
|
6228
6704
|
* Format either small or big number
|
|
@@ -6247,7 +6723,7 @@ function formatNumber(value) {
|
|
|
6247
6723
|
/**
|
|
6248
6724
|
* Create a markdown table from a 2D array of strings
|
|
6249
6725
|
*
|
|
6250
|
-
* @
|
|
6726
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
6251
6727
|
*/
|
|
6252
6728
|
function createMarkdownTable(table) {
|
|
6253
6729
|
var columnWidths = table.reduce(function (widths, row) {
|
|
@@ -6271,11 +6747,14 @@ function createMarkdownTable(table) {
|
|
|
6271
6747
|
});
|
|
6272
6748
|
return __spreadArray([header, separator], __read(rows), false).join('\n');
|
|
6273
6749
|
}
|
|
6750
|
+
/**
|
|
6751
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
6752
|
+
*/
|
|
6274
6753
|
|
|
6275
6754
|
/**
|
|
6276
6755
|
* Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
|
|
6277
6756
|
*
|
|
6278
|
-
* @
|
|
6757
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
6279
6758
|
*/
|
|
6280
6759
|
function createMarkdownChart(options) {
|
|
6281
6760
|
var e_1, _a;
|
|
@@ -6311,10 +6790,25 @@ function createMarkdownChart(options) {
|
|
|
6311
6790
|
/**
|
|
6312
6791
|
* Function escapeMarkdownBlock will escape markdown block if needed
|
|
6313
6792
|
* It is useful when you want have block in block
|
|
6793
|
+
*
|
|
6794
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
6314
6795
|
*/
|
|
6315
6796
|
function escapeMarkdownBlock(value) {
|
|
6316
6797
|
return value.replace(/```/g, '\\`\\`\\`');
|
|
6317
6798
|
}
|
|
6799
|
+
/**
|
|
6800
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
6801
|
+
*/
|
|
6802
|
+
|
|
6803
|
+
/**
|
|
6804
|
+
* Default options for generating an execution report string
|
|
6805
|
+
*
|
|
6806
|
+
* @public exported from `@promptbook/core`
|
|
6807
|
+
*/
|
|
6808
|
+
var ExecutionReportStringOptionsDefaults = {
|
|
6809
|
+
taxRate: 0,
|
|
6810
|
+
chartsWidth: 36,
|
|
6811
|
+
};
|
|
6318
6812
|
|
|
6319
6813
|
/**
|
|
6320
6814
|
* The thresholds for the relative time in the `moment` NPM package.
|
|
@@ -6360,6 +6854,8 @@ function countWorkingDuration(items) {
|
|
|
6360
6854
|
|
|
6361
6855
|
/**
|
|
6362
6856
|
* Converts execution report from JSON to string format
|
|
6857
|
+
*
|
|
6858
|
+
* @public exported from `@promptbook/core`
|
|
6363
6859
|
*/
|
|
6364
6860
|
function executionReportJsonToString(executionReportJson, options) {
|
|
6365
6861
|
var e_1, _a;
|
|
@@ -6529,5 +7025,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
6529
7025
|
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
6530
7026
|
*/
|
|
6531
7027
|
|
|
6532
|
-
export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults,
|
|
7028
|
+
export { BlockTypes, CallbackInterfaceTools, CollectionError, EXECUTIONS_CACHE_DIRNAME, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, LimitReachedError, MAX_EXECUTION_ATTEMPTS, MAX_FILENAME_LENGTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, MAX_PARALLEL_COUNT, MemoryStorage, NotFoundError, NotYetImplementedError, PIPELINE_COLLECTION_BASE_FILENAME, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, PrefixStorage, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatchError, ZERO_USAGE, addUsage, assertsExecutionSuccessful, cacheLlmTools, checkExpectations, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTemplates, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
|
|
6533
7029
|
//# sourceMappingURL=index.es.js.map
|