@promptbook/cli 0.59.0-0 → 0.59.0-14
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 +2734 -1170
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-library/promptbook-library.d.ts +25 -0
- package/{umd/typings → esm/typings/src}/_packages/core.index.d.ts +2 -1
- package/{umd/typings → esm/typings/src}/conversion/promptbookStringToJson.d.ts +12 -2
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +19 -0
- package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/{umd/typings → esm/typings/src}/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -0
- package/{umd/typings → esm/typings/src}/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -0
- package/esm/typings/{types → src/types}/PromptbookJson/MaterialKnowledgePieceJson.d.ts +1 -1
- package/esm/typings/{types → src/types}/typeAliases.d.ts +7 -1
- package/package.json +2 -2
- package/umd/index.umd.js +2754 -1189
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-library/promptbook-library.d.ts +25 -0
- package/{esm/typings → umd/typings/src}/_packages/core.index.d.ts +2 -1
- package/{esm/typings → umd/typings/src}/conversion/promptbookStringToJson.d.ts +12 -2
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +19 -0
- package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/{esm/typings → umd/typings/src}/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -0
- package/{esm/typings → umd/typings/src}/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -0
- package/umd/typings/src/llm-providers/multiple/playground/playground.d.ts +2 -0
- package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +2 -0
- package/umd/typings/{types → src/types}/PromptbookJson/MaterialKnowledgePieceJson.d.ts +1 -1
- package/umd/typings/{types → src/types}/typeAliases.d.ts +7 -1
- package/umd/typings/src/utils/unwrapResult.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isValidUrl.test.d.ts +1 -0
- package/esm/typings/{_packages → src/_packages}/anthropic-claude.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/azure-openai.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/cli.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/execute-javascript.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/fake-llm.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/langtail.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/node.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/openai.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/remote-client.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/remote-server.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/types.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/utils.index.d.ts +0 -0
- package/esm/typings/{config.d.ts → src/config.d.ts} +0 -0
- package/esm/typings/{conversion → src/conversion}/prettify/PrettifyOptions.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/prettify/prettifyPromptbookString.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/prettify/prettifyPromptbookStringCli.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/prettify/renderPromptbookMermaid.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/promptbookJsonToString.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/promptbookStringToJson.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/extractVariables.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/extractVariables.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/parseCommand.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/parseCommand.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/parseNumber.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/parseNumber.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/renameParameter.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/renameParameter.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/titleToName.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/titleToName.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/_importPromptbook.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/promptbookStringToJson-syntaxErrors.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/validatePromptbookJson-logicErrors.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/validatePromptbookJson.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/validatePromptbookJson.test.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookExecutionError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookLibraryError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookLogicError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookNotFoundError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookReferenceError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookSyntaxError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/TemplateError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/UnexpectedError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/_ExpectError.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/CommonExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/ExecutionTools.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/LlmExecutionTools.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/PromptResult.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/PromptbookExecutor.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/ScriptExecutionTools.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/UserInterfaceTools.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/addPromptResultUsage.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/assertsExecutionSuccessful.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/createPromptbookExecutor.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/translateMessages.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/addUsage.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/addUsage.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/checkExpectations.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/checkExpectations.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/computeUsageCounts.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/forEachAsync.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/replaceParameters.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/replaceParameters.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/uncertainNumber.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/usageToWorktime.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/usageToWorktime.test.d.ts +0 -0
- package/esm/typings/{expectations → src/expectations}/drafts/isDomainNameFree.d.ts +0 -0
- package/esm/typings/{expectations → src/expectations}/drafts/isGithubNameFree.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/_common/FormatDefinition.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/csv/ListFormatDefinition.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/index.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/json/JsonFormatDefinition.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/json/utils/isValidJsonString.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/json/utils/isValidJsonString.test.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/list/ListFormatDefinition.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/xml/XmlFormatDefinition.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/prepare-knowledge/_common/IndexPreparer.d.ts +0 -0
- package/esm/typings/{llm-providers/anthropic-claude/playground/playground.d.ts → src/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts} +0 -0
- package/{umd/typings → esm/typings/src}/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/{knowledge → src/knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +0 -0
- package/esm/typings/{llm-providers/mocked/fakeTextToExpectations.test.d.ts → src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +0 -0
- package/esm/typings/{llm-providers/azure-openai → src/llm-providers/anthropic-claude}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers/langtail → src/llm-providers/azure-openai}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers/multiple → src/llm-providers/langtail}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/fakeTextToExpectations.d.ts +0 -0
- package/{umd/typings → esm/typings/src}/llm-providers/mocked/fakeTextToExpectations.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/faked-completion.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/joker.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers/openai → src/llm-providers/multiple}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/computeOpenaiUsage.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/computeUsage.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/computeUsage.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/openai-models.d.ts +0 -0
- package/{umd/typings/llm-providers/anthropic-claude → esm/typings/src/llm-providers/openai}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/RemoteServerOptions.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/startRemoteServer.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/PromptbookLibrary.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/custom-function-async.test.ts.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/custom-function-missing.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/custom-function-with-dependencies.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/custom-function.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/postprocessing.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/script-execution-errors.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/script-execution-tools.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/utils/preserve.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/utils/unknownToString.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/python/PythonExecutionTools.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/typescript/TypescriptExecutionTools.d.ts +0 -0
- package/esm/typings/{types → src/types}/Command.d.ts +0 -0
- package/esm/typings/{types → src/types}/ExecutionTypes.d.ts +0 -0
- package/esm/typings/{types → src/types}/ModelRequirements.d.ts +0 -0
- package/esm/typings/{types → src/types}/Parameters.d.ts +0 -0
- package/esm/typings/{types → src/types}/Prompt.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookJson/KnowledgeJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookJson/PromptTemplateJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookJson/PromptTemplateParameterJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookJson/PromptbookJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookString.d.ts +0 -0
- package/esm/typings/{types → src/types}/ScriptLanguage.d.ts +0 -0
- package/esm/typings/{types → src/types}/TaskProgress.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/ExecutionReportJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/ExecutionReportString.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/ExecutionReportStringOptions.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/config.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/countWorkingDuration.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/countWorkingDuration.test.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/executionReportJsonToString.d.ts +0 -0
- package/esm/typings/{types → src/types}/typeAliasEmoji.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/FromtoItems.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/emojis.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countCharacters.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countCharacters.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countLines.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countLines.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countPages.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countPages.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countParagraphs.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countParagraphs.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countSentences.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countSentences.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countWords.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countWords.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/index.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/extractParameters.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/extractParameters.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/formatNumber.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/formatNumber.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/getCurrentIsoDate.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/isRunningInWhatever.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/just.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/createMarkdownChart.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/createMarkdownChart.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/createMarkdownTable.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/createMarkdownTable.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/prettifyMarkdown.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/prettifyMarkdown.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/removeContentComments.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/removeContentComments.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/MarkdownStructure.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/IKeywords.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/capitalize.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/capitalize.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/decapitalize.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/decapitalize.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/isValidKeyword.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/isValidKeyword.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/nameToUriPart.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/nameToUriPart.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/nameToUriParts.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/nameToUriParts.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeWhitespaces.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeWhitespaces.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/parseKeywords.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/parseKeywords.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/parseKeywordsFromString.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/parseKeywordsFromString.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/removeDiacritics.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/removeDiacritics.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/searchKeywords.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/searchKeywords.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/postprocessing/extractBlock.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/removeEmojis.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/removeEmojis.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/removeQuotes.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/removeQuotes.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/difference.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/difference.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/intersection.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/intersection.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/union.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/union.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/trimCodeBlock.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/trimCodeBlock.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/trimEndOfCodeBlock.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/trimEndOfCodeBlock.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/unwrapResult.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/unwrapResult.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/validators/url/isValidUrl.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/validators/url/isValidUrl.test.d.ts +0 -0
- package/esm/typings/{version.d.ts → src/version.d.ts} +0 -0
- package/umd/typings/{_packages → src/_packages}/anthropic-claude.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/azure-openai.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/cli.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/execute-javascript.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/fake-llm.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/langtail.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/node.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/openai.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/remote-client.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/remote-server.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/types.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/utils.index.d.ts +0 -0
- package/umd/typings/{config.d.ts → src/config.d.ts} +0 -0
- package/umd/typings/{conversion → src/conversion}/prettify/PrettifyOptions.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/prettify/prettifyPromptbookString.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/prettify/prettifyPromptbookStringCli.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/prettify/renderPromptbookMermaid.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/promptbookJsonToString.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/promptbookStringToJson.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/extractVariables.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/extractVariables.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/parseCommand.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/parseCommand.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/parseNumber.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/parseNumber.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/renameParameter.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/renameParameter.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/titleToName.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/titleToName.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/_importPromptbook.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/promptbookStringToJson-syntaxErrors.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/validatePromptbookJson-logicErrors.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/validatePromptbookJson.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/validatePromptbookJson.test.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookExecutionError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookLibraryError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookLogicError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookNotFoundError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookReferenceError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookSyntaxError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/TemplateError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/UnexpectedError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/_ExpectError.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/CommonExecutionToolsOptions.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/ExecutionTools.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/LlmExecutionTools.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/PromptResult.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/PromptbookExecutor.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/ScriptExecutionTools.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/UserInterfaceTools.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/addPromptResultUsage.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/assertsExecutionSuccessful.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/createPromptbookExecutor.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/translateMessages.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/addUsage.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/addUsage.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/checkExpectations.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/checkExpectations.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/computeUsageCounts.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/forEachAsync.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/replaceParameters.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/replaceParameters.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/uncertainNumber.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/usageToWorktime.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/usageToWorktime.test.d.ts +0 -0
- package/umd/typings/{expectations → src/expectations}/drafts/isDomainNameFree.d.ts +0 -0
- package/umd/typings/{expectations → src/expectations}/drafts/isGithubNameFree.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/_common/FormatDefinition.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/csv/ListFormatDefinition.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/index.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/json/JsonFormatDefinition.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/json/utils/isValidJsonString.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/json/utils/isValidJsonString.test.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/list/ListFormatDefinition.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/xml/XmlFormatDefinition.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/prepare-knowledge/_common/IndexPreparer.d.ts +0 -0
- package/umd/typings/{llm-providers/azure-openai/playground/playground.d.ts → src/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts} +0 -0
- package/{esm/typings → umd/typings/src}/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- /package/umd/typings/{knowledge → src/knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +0 -0
- /package/umd/typings/{llm-providers/mocked/faked-completion.test.d.ts → src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +0 -0
- /package/umd/typings/{llm-providers/langtail → src/llm-providers/anthropic-claude}/playground/playground.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers/multiple → src/llm-providers/azure-openai}/playground/playground.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers/openai → src/llm-providers/langtail}/playground/playground.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/mocked/fakeTextToExpectations.d.ts +0 -0
- /package/umd/typings/{llm-providers/openai/computeUsage.test.d.ts → src/llm-providers/mocked/fakeTextToExpectations.test.d.ts} +0 -0
- /package/umd/typings/{promptbook-library/constructors/createPromptbookLibraryFromDirectory.test.d.ts → src/llm-providers/mocked/faked-completion.test.d.ts} +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/mocked/joker.test.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/computeOpenaiUsage.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/computeUsage.d.ts +0 -0
- /package/umd/typings/{promptbook-library/constructors/createPromptbookLibraryFromPromise.test.d.ts → src/llm-providers/openai/computeUsage.test.d.ts} +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/openai-models.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/RemoteServerOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/startRemoteServer.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -0
- /package/umd/typings/{promptbook-library/constructors/createPromptbookLibraryFromSources.test.d.ts → src/promptbook-library/constructors/createPromptbookLibraryFromDirectory.test.d.ts} +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +0 -0
- /package/umd/typings/{scripting/_test/custom-function-async.test.ts.test.d.ts → src/promptbook-library/constructors/createPromptbookLibraryFromPromise.test.d.ts} +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +0 -0
- /package/umd/typings/{scripting/_test/custom-function-missing.test.d.ts → src/promptbook-library/constructors/createPromptbookLibraryFromSources.test.d.ts} +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- /package/umd/typings/{scripting/_test/custom-function-with-dependencies.test.d.ts → src/scripting/_test/custom-function-async.test.ts.test.d.ts} +0 -0
- /package/umd/typings/{scripting/_test/custom-function.test.d.ts → src/scripting/_test/custom-function-missing.test.d.ts} +0 -0
- /package/umd/typings/{scripting/_test/postprocessing.test.d.ts → src/scripting/_test/custom-function-with-dependencies.test.d.ts} +0 -0
- /package/umd/typings/{scripting/_test/script-execution-errors.test.d.ts → src/scripting/_test/custom-function.test.d.ts} +0 -0
- /package/umd/typings/{scripting/_test/script-execution-tools.test.d.ts → src/scripting/_test/postprocessing.test.d.ts} +0 -0
- /package/umd/typings/{types/execution-report/countWorkingDuration.test.d.ts → src/scripting/_test/script-execution-errors.test.d.ts} +0 -0
- /package/umd/typings/{utils/expectation-counters/countCharacters.test.d.ts → src/scripting/_test/script-execution-tools.test.d.ts} +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/utils/preserve.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/utils/unknownToString.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/python/PythonExecutionTools.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/typescript/TypescriptExecutionTools.d.ts +0 -0
- /package/umd/typings/{types → src/types}/Command.d.ts +0 -0
- /package/umd/typings/{types → src/types}/ExecutionTypes.d.ts +0 -0
- /package/umd/typings/{types → src/types}/ModelRequirements.d.ts +0 -0
- /package/umd/typings/{types → src/types}/Parameters.d.ts +0 -0
- /package/umd/typings/{types → src/types}/Prompt.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookJson/KnowledgeJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookJson/PromptTemplateJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookJson/PromptTemplateParameterJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookJson/PromptbookJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookString.d.ts +0 -0
- /package/umd/typings/{types → src/types}/ScriptLanguage.d.ts +0 -0
- /package/umd/typings/{types → src/types}/TaskProgress.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/ExecutionReportJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/ExecutionReportString.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/ExecutionReportStringOptions.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/config.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/countWorkingDuration.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countLines.test.d.ts → src/types/execution-report/countWorkingDuration.test.d.ts} +0 -0
- /package/umd/typings/{types → src/types}/execution-report/executionReportJsonToString.d.ts +0 -0
- /package/umd/typings/{types → src/types}/typeAliasEmoji.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/FromtoItems.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/emojis.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countCharacters.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countPages.test.d.ts → src/utils/expectation-counters/countCharacters.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countLines.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countParagraphs.test.d.ts → src/utils/expectation-counters/countLines.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countPages.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countSentences.test.d.ts → src/utils/expectation-counters/countPages.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countParagraphs.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countWords.test.d.ts → src/utils/expectation-counters/countParagraphs.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countSentences.d.ts +0 -0
- /package/umd/typings/{utils/extractParameters.test.d.ts → src/utils/expectation-counters/countSentences.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countWords.d.ts +0 -0
- /package/umd/typings/{utils/formatNumber.test.d.ts → src/utils/expectation-counters/countWords.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/index.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/extractParameters.d.ts +0 -0
- /package/umd/typings/{utils/markdown-json/countMarkdownStructureDeepness.test.d.ts → src/utils/extractParameters.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/formatNumber.d.ts +0 -0
- /package/umd/typings/{utils/markdown-json/markdownToMarkdownStructure.test.d.ts → src/utils/formatNumber.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/getCurrentIsoDate.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/isRunningInWhatever.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/just.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.d.ts +0 -0
- /package/umd/typings/{utils/markdown/createMarkdownTable.test.d.ts → src/utils/markdown/addAutoGeneratedSection.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/createMarkdownChart.d.ts +0 -0
- /package/umd/typings/{utils/markdown/escapeMarkdownBlock.test.d.ts → src/utils/markdown/createMarkdownChart.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/createMarkdownTable.d.ts +0 -0
- /package/umd/typings/{utils/markdown/extractAllBlocksFromMarkdown.test.d.ts → src/utils/markdown/createMarkdownTable.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.d.ts +0 -0
- /package/umd/typings/{utils/markdown/extractAllListItemsFromMarkdown.test.d.ts → src/utils/markdown/escapeMarkdownBlock.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.d.ts +0 -0
- /package/umd/typings/{utils/markdown/extractOneBlockFromMarkdown.test.d.ts → src/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.d.ts +0 -0
- /package/umd/typings/{utils/markdown/prettifyMarkdown.test.d.ts → src/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.d.ts +0 -0
- /package/umd/typings/{utils/markdown/removeContentComments.test.d.ts → src/utils/markdown/extractOneBlockFromMarkdown.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/prettifyMarkdown.d.ts +0 -0
- /package/umd/typings/{utils/markdown/removeMarkdownFormatting.test.d.ts → src/utils/markdown/prettifyMarkdown.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/removeContentComments.d.ts +0 -0
- /package/umd/typings/{utils/normalization/capitalize.test.d.ts → src/utils/markdown/removeContentComments.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.d.ts +0 -0
- /package/umd/typings/{utils/normalization/decapitalize.test.d.ts → src/utils/markdown/removeMarkdownFormatting.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown-json/MarkdownStructure.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.d.ts +0 -0
- /package/umd/typings/{utils/markdown/addAutoGeneratedSection.test.d.ts → src/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.d.ts +0 -0
- /package/umd/typings/{utils/markdown/createMarkdownChart.test.d.ts → src/utils/markdown-json/markdownToMarkdownStructure.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/IKeywords.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/capitalize.d.ts +0 -0
- /package/umd/typings/{utils/normalization/isValidKeyword.test.d.ts → src/utils/normalization/capitalize.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/decapitalize.d.ts +0 -0
- /package/umd/typings/{utils/normalization/nameToUriPart.test.d.ts → src/utils/normalization/decapitalize.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/isValidKeyword.d.ts +0 -0
- /package/umd/typings/{utils/normalization/nameToUriParts.test.d.ts → src/utils/normalization/isValidKeyword.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/nameToUriPart.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalize-to-kebab-case.test.d.ts → src/utils/normalization/nameToUriPart.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/nameToUriParts.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeTo_PascalCase.test.d.ts → src/utils/normalization/nameToUriParts.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeTo_SCREAMING_CASE.test.d.ts → src/utils/normalization/normalize-to-kebab-case.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeTo_camelCase.test.d.ts → src/utils/normalization/normalizeTo_PascalCase.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeTo_snake_case.test.d.ts → src/utils/normalization/normalizeTo_SCREAMING_CASE.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeWhitespaces.test.d.ts → src/utils/normalization/normalizeTo_camelCase.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.d.ts +0 -0
- /package/umd/typings/{utils/normalization/parseKeywords.test.d.ts → src/utils/normalization/normalizeTo_snake_case.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeWhitespaces.d.ts +0 -0
- /package/umd/typings/{utils/normalization/parseKeywordsFromString.test.d.ts → src/utils/normalization/normalizeWhitespaces.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/parseKeywords.d.ts +0 -0
- /package/umd/typings/{utils/normalization/removeDiacritics.test.d.ts → src/utils/normalization/parseKeywords.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/parseKeywordsFromString.d.ts +0 -0
- /package/umd/typings/{utils/normalization/searchKeywords.test.d.ts → src/utils/normalization/parseKeywordsFromString.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/removeDiacritics.d.ts +0 -0
- /package/umd/typings/{utils/removeEmojis.test.d.ts → src/utils/normalization/removeDiacritics.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/searchKeywords.d.ts +0 -0
- /package/umd/typings/{utils/removeQuotes.test.d.ts → src/utils/normalization/searchKeywords.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/postprocessing/extractBlock.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/removeEmojis.d.ts +0 -0
- /package/umd/typings/{utils/sets/difference.test.d.ts → src/utils/removeEmojis.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/removeQuotes.d.ts +0 -0
- /package/umd/typings/{utils/sets/intersection.test.d.ts → src/utils/removeQuotes.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/sets/difference.d.ts +0 -0
- /package/umd/typings/{utils/sets/union.test.d.ts → src/utils/sets/difference.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/sets/intersection.d.ts +0 -0
- /package/umd/typings/{utils/trimCodeBlock.test.d.ts → src/utils/sets/intersection.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/sets/union.d.ts +0 -0
- /package/umd/typings/{utils/trimEndOfCodeBlock.test.d.ts → src/utils/sets/union.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/trimCodeBlock.d.ts +0 -0
- /package/umd/typings/{utils/unwrapResult.test.d.ts → src/utils/trimCodeBlock.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/trimEndOfCodeBlock.d.ts +0 -0
- /package/umd/typings/{utils/validators/url/isValidUrl.test.d.ts → src/utils/trimEndOfCodeBlock.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/unwrapResult.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/validators/url/isValidUrl.d.ts +0 -0
- /package/umd/typings/{version.d.ts → src/version.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('fs/promises'), require('glob-promise'), require('spacetrim'), require('waitasecond'), require('prettier'), require('prettier/parser-html')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'fs/promises', 'glob-promise', 'spacetrim', 'waitasecond', 'prettier', 'prettier/parser-html'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.promises, global.glob, global.
|
|
5
|
-
})(this, (function (exports, colors, commander, promises, glob,
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.promises, global.glob, global.spaceTrim, global.waitasecond, global.prettier, global.parserHtml));
|
|
5
|
+
})(this, (function (exports, colors, commander, promises, glob, spaceTrim, waitasecond, prettier, parserHtml) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
10
10
|
var commander__default = /*#__PURE__*/_interopDefaultLegacy(commander);
|
|
11
11
|
var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
|
|
12
|
+
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
12
13
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
13
14
|
|
|
14
15
|
/*! *****************************************************************************
|
|
@@ -146,7 +147,7 @@
|
|
|
146
147
|
/**
|
|
147
148
|
* The version of the Promptbook library
|
|
148
149
|
*/
|
|
149
|
-
var PROMPTBOOK_VERSION = '0.
|
|
150
|
+
var PROMPTBOOK_VERSION = '0.59.0-13';
|
|
150
151
|
|
|
151
152
|
/**
|
|
152
153
|
* Removes HTML or Markdown comments from a string.
|
|
@@ -155,7 +156,7 @@
|
|
|
155
156
|
* @returns {string} The input string with all comments removed.
|
|
156
157
|
*/
|
|
157
158
|
function removeContentComments(content) {
|
|
158
|
-
return
|
|
159
|
+
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
/**
|
|
@@ -169,7 +170,7 @@
|
|
|
169
170
|
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
170
171
|
var sectionMatch = content.match(sectionRegex);
|
|
171
172
|
if (sectionMatch) {
|
|
172
|
-
return content.replace(sectionRegex,
|
|
173
|
+
return content.replace(sectionRegex, spaceTrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
173
174
|
}
|
|
174
175
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
175
176
|
if (!placeForSection) {
|
|
@@ -225,47 +226,73 @@
|
|
|
225
226
|
return PromptbookSyntaxError;
|
|
226
227
|
}(Error));
|
|
227
228
|
|
|
229
|
+
var promptbookLibrary = [{ "title": "Prepare Knowledge from Markdown", "promptbookUrl": "https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md", "promptbookVersion": "0.59.0-13", "parameters": [{ "name": "content", "description": "Markdown document content", "isInput": true, "isOutput": false }, { "name": "knowledge", "description": "The knowledge JSON object", "isInput": false, "isOutput": true }], "promptTemplates": [{ "name": "knowledge", "title": "Knowledge", "dependentParameterNames": ["content"], "executionType": "PROMPT_TEMPLATE", "modelRequirements": { "modelVariant": "CHAT", "modelName": "claude-3-opus-20240229" }, "content": "You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}", "resultingParameterName": "knowledge" }], "knowledge": [] }];
|
|
230
|
+
|
|
228
231
|
/**
|
|
229
|
-
*
|
|
232
|
+
* This error indicates errors during the execution of the promptbook
|
|
230
233
|
*/
|
|
231
|
-
var
|
|
234
|
+
var PromptbookExecutionError = /** @class */ (function (_super) {
|
|
235
|
+
__extends(PromptbookExecutionError, _super);
|
|
236
|
+
function PromptbookExecutionError(message) {
|
|
237
|
+
var _this = _super.call(this, message) || this;
|
|
238
|
+
_this.name = 'PromptbookExecutionError';
|
|
239
|
+
Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
|
|
240
|
+
return _this;
|
|
241
|
+
}
|
|
242
|
+
return PromptbookExecutionError;
|
|
243
|
+
}(Error));
|
|
232
244
|
|
|
233
245
|
/**
|
|
234
|
-
*
|
|
246
|
+
* Asserts that the execution of a promptnook is successful
|
|
235
247
|
*
|
|
236
|
-
* @
|
|
248
|
+
* @param executionResult - The partial result of the promptnook execution
|
|
249
|
+
* @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
|
|
237
250
|
*/
|
|
238
|
-
function
|
|
239
|
-
var
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
243
|
-
var section = _c.value;
|
|
244
|
-
maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
|
|
245
|
-
}
|
|
251
|
+
function assertsExecutionSuccessful(executionResult) {
|
|
252
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
253
|
+
if (isSuccessful === true) {
|
|
254
|
+
return;
|
|
246
255
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
256
|
+
if (errors.length === 0) {
|
|
257
|
+
throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
|
|
258
|
+
}
|
|
259
|
+
else if (errors.length === 1) {
|
|
260
|
+
throw errors[0];
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
|
|
253
264
|
}
|
|
254
|
-
return maxDeepness + 1;
|
|
255
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* TODO: [🧠] Can this return type be better typed than void
|
|
268
|
+
*/
|
|
256
269
|
|
|
257
270
|
/**
|
|
258
271
|
* The maximum number of iterations for a loops
|
|
259
272
|
*/
|
|
260
273
|
var LOOP_LIMIT = 1000;
|
|
261
274
|
|
|
275
|
+
/**
|
|
276
|
+
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
277
|
+
*/
|
|
278
|
+
var PromptbookLogicError = /** @class */ (function (_super) {
|
|
279
|
+
__extends(PromptbookLogicError, _super);
|
|
280
|
+
function PromptbookLogicError(message) {
|
|
281
|
+
var _this = _super.call(this, message) || this;
|
|
282
|
+
_this.name = 'PromptbookLogicError';
|
|
283
|
+
Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
|
|
284
|
+
return _this;
|
|
285
|
+
}
|
|
286
|
+
return PromptbookLogicError;
|
|
287
|
+
}(Error));
|
|
288
|
+
|
|
262
289
|
/**
|
|
263
290
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
264
291
|
*/
|
|
265
292
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
266
293
|
__extends(UnexpectedError, _super);
|
|
267
294
|
function UnexpectedError(message) {
|
|
268
|
-
var _this = _super.call(this,
|
|
295
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
269
296
|
_this.name = 'UnexpectedError';
|
|
270
297
|
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
271
298
|
return _this;
|
|
@@ -274,1047 +301,2215 @@
|
|
|
274
301
|
}(Error));
|
|
275
302
|
|
|
276
303
|
/**
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* Note: This function does work with code blocks
|
|
280
|
-
* Note: This function does not work with markdown comments
|
|
304
|
+
* Tests if given string is valid URL.
|
|
281
305
|
*
|
|
282
|
-
*
|
|
283
|
-
* @returns The MarkdownStructure object.
|
|
284
|
-
*
|
|
285
|
-
* @private within the library
|
|
306
|
+
* Note: Dataurl are considered perfectly valid.
|
|
286
307
|
*/
|
|
287
|
-
function
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
var current = root;
|
|
292
|
-
var isInsideCodeBlock = false;
|
|
308
|
+
function isValidUrl(url) {
|
|
309
|
+
if (typeof url !== 'string') {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
293
312
|
try {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
|
|
297
|
-
if (isInsideCodeBlock || !headingMatch) {
|
|
298
|
-
if (line.startsWith('```')) {
|
|
299
|
-
isInsideCodeBlock = !isInsideCodeBlock;
|
|
300
|
-
}
|
|
301
|
-
current.contentLines.push(line);
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
var level = headingMatch.groups.mark.length;
|
|
305
|
-
var title = headingMatch.groups.title.trim();
|
|
306
|
-
var parent_1 = void 0;
|
|
307
|
-
if (level > current.level) {
|
|
308
|
-
// Note: Going deeper (next section is child of current)
|
|
309
|
-
parent_1 = current;
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
// Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
|
|
313
|
-
parent_1 = current;
|
|
314
|
-
var loopLimit = LOOP_LIMIT;
|
|
315
|
-
while (parent_1.level !== level - 1) {
|
|
316
|
-
if (loopLimit-- < 0) {
|
|
317
|
-
throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
|
|
318
|
-
}
|
|
319
|
-
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
320
|
-
// [🌻]
|
|
321
|
-
throw new Error(spacetrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
322
|
-
}
|
|
323
|
-
parent_1 = parent_1.parent;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
|
|
327
|
-
parent_1.sections.push(section);
|
|
328
|
-
current = section;
|
|
329
|
-
}
|
|
313
|
+
if (url.startsWith('blob:')) {
|
|
314
|
+
url = url.replace(/^blob:/, '');
|
|
330
315
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
316
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
317
|
+
var urlObject = new URL(url);
|
|
318
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
319
|
+
return false;
|
|
336
320
|
}
|
|
337
|
-
|
|
321
|
+
return true;
|
|
338
322
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
return markdownStructure;
|
|
323
|
+
catch (error) {
|
|
324
|
+
return false;
|
|
342
325
|
}
|
|
343
|
-
// [🌻]
|
|
344
|
-
throw new Error('The markdown file must have exactly one top-level section.');
|
|
345
|
-
// return root;
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* @private
|
|
349
|
-
*/
|
|
350
|
-
function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
351
|
-
var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
|
|
352
|
-
return {
|
|
353
|
-
level: level,
|
|
354
|
-
title: title,
|
|
355
|
-
content: spacetrim.spaceTrim(contentLines.join('\n')),
|
|
356
|
-
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
357
|
-
};
|
|
358
326
|
}
|
|
359
327
|
|
|
360
328
|
/**
|
|
361
|
-
*
|
|
329
|
+
* Validates PromptbookJson if it is logically valid
|
|
362
330
|
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
* Note: It flattens nested lists
|
|
366
|
-
* Note: It can not work with html syntax and comments
|
|
331
|
+
* It checks:
|
|
332
|
+
* - if it has correct parameters dependency
|
|
367
333
|
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
334
|
+
* It does NOT check:
|
|
335
|
+
* - if it is valid json
|
|
336
|
+
* - if it is meaningful
|
|
337
|
+
*
|
|
338
|
+
* @param promptbook valid or invalid PromptbookJson
|
|
339
|
+
* @returns the same promptbook if it is logically valid
|
|
340
|
+
* @throws {PromptbookLogicError} on logical error in the promptbook
|
|
370
341
|
*/
|
|
371
|
-
function
|
|
372
|
-
|
|
373
|
-
var
|
|
374
|
-
|
|
375
|
-
|
|
342
|
+
function validatePromptbookJson(promptbook) {
|
|
343
|
+
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
344
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
345
|
+
if (promptbook.promptbookUrl !== undefined) {
|
|
346
|
+
if (!isValidUrl(promptbook.promptbookUrl)) {
|
|
347
|
+
// TODO: This should be maybe the syntax error detected during parsing
|
|
348
|
+
throw new PromptbookLogicError("Invalid promptbook URL \"".concat(promptbook.promptbookUrl, "\""));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
352
|
+
if (!Array.isArray(promptbook.parameters)) {
|
|
353
|
+
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
354
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof promptbook.parameters, "\n ")));
|
|
355
|
+
}
|
|
356
|
+
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
357
|
+
if (!Array.isArray(promptbook.promptTemplates)) {
|
|
358
|
+
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
359
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof promptbook.promptTemplates, "\n ")));
|
|
360
|
+
}
|
|
361
|
+
var _loop_1 = function (parameter) {
|
|
362
|
+
if (parameter.isInput && parameter.isOutput) {
|
|
363
|
+
throw new PromptbookLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
|
|
364
|
+
}
|
|
365
|
+
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
366
|
+
if (!parameter.isInput &&
|
|
367
|
+
!parameter.isOutput &&
|
|
368
|
+
!promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
369
|
+
throw new PromptbookLogicError(spaceTrim.spaceTrim("\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 ")));
|
|
370
|
+
}
|
|
371
|
+
// Note: Testing that parameter is either input or result of some template
|
|
372
|
+
if (!parameter.isInput &&
|
|
373
|
+
!promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
374
|
+
throw new PromptbookLogicError(spaceTrim.spaceTrim("\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 ")));
|
|
375
|
+
}
|
|
376
|
+
};
|
|
376
377
|
try {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
var
|
|
380
|
-
|
|
381
|
-
isInCodeBlock = !isInCodeBlock;
|
|
382
|
-
}
|
|
383
|
-
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
384
|
-
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
385
|
-
listItems.push(listItem);
|
|
386
|
-
}
|
|
378
|
+
// Note: Check each parameter individually
|
|
379
|
+
for (var _e = __values(promptbook.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
380
|
+
var parameter = _f.value;
|
|
381
|
+
_loop_1(parameter);
|
|
387
382
|
}
|
|
388
383
|
}
|
|
389
384
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
390
385
|
finally {
|
|
391
386
|
try {
|
|
392
|
-
if (
|
|
387
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
393
388
|
}
|
|
394
389
|
finally { if (e_1) throw e_1.error; }
|
|
395
390
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Extracts all code blocks from markdown.
|
|
409
|
-
*
|
|
410
|
-
* Note: There are 3 simmilar function:
|
|
411
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
412
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
413
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
414
|
-
*
|
|
415
|
-
* @param markdown any valid markdown
|
|
416
|
-
* @returns code blocks with language and content
|
|
417
|
-
*
|
|
418
|
-
*/
|
|
419
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
420
|
-
var e_1, _a;
|
|
421
|
-
var codeBlocks = [];
|
|
422
|
-
var lines = markdown.split('\n');
|
|
423
|
-
var currentCodeBlock = null;
|
|
391
|
+
// Note: Check each template individually
|
|
392
|
+
var definedParameters = new Set(promptbook.parameters.filter(function (_a) {
|
|
393
|
+
var isInput = _a.isInput;
|
|
394
|
+
return isInput;
|
|
395
|
+
}).map(function (_a) {
|
|
396
|
+
var name = _a.name;
|
|
397
|
+
return name;
|
|
398
|
+
}));
|
|
424
399
|
try {
|
|
425
|
-
for (var
|
|
426
|
-
var
|
|
427
|
-
if (
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
400
|
+
for (var _g = __values(promptbook.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
401
|
+
var template = _h.value;
|
|
402
|
+
if (definedParameters.has(template.resultingParameterName)) {
|
|
403
|
+
throw new PromptbookLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
404
|
+
}
|
|
405
|
+
definedParameters.add(template.resultingParameterName);
|
|
406
|
+
if (template.executionType === 'PROMPT_TEMPLATE' &&
|
|
407
|
+
(template.modelRequirements.modelVariant === undefined)) {
|
|
408
|
+
throw new PromptbookLogicError(spaceTrim.spaceTrim("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
|
|
409
|
+
}
|
|
410
|
+
if (template.jokers && template.jokers.length > 0) {
|
|
411
|
+
if (!template.expectFormat &&
|
|
412
|
+
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
413
|
+
throw new PromptbookLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
|
|
431
414
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
415
|
+
try {
|
|
416
|
+
for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
417
|
+
var joker = _k.value;
|
|
418
|
+
if (!template.dependentParameterNames.includes(joker)) {
|
|
419
|
+
throw new PromptbookLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
420
|
+
}
|
|
436
421
|
}
|
|
437
|
-
|
|
438
|
-
|
|
422
|
+
}
|
|
423
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
424
|
+
finally {
|
|
425
|
+
try {
|
|
426
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
427
|
+
}
|
|
428
|
+
finally { if (e_3) throw e_3.error; }
|
|
439
429
|
}
|
|
440
430
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
431
|
+
if (template.expectations) {
|
|
432
|
+
try {
|
|
433
|
+
for (var _l = (e_4 = void 0, __values(Object.entries(template.expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
434
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
435
|
+
if (min !== undefined && max !== undefined && min > max) {
|
|
436
|
+
throw new PromptbookLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
437
|
+
}
|
|
438
|
+
if (min !== undefined && min < 0) {
|
|
439
|
+
throw new PromptbookLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
|
|
440
|
+
}
|
|
441
|
+
if (max !== undefined && max <= 0) {
|
|
442
|
+
throw new PromptbookLogicError("Max expectation of ".concat(unit, " must be positive"));
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
447
|
+
finally {
|
|
448
|
+
try {
|
|
449
|
+
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
450
|
+
}
|
|
451
|
+
finally { if (e_4) throw e_4.error; }
|
|
444
452
|
}
|
|
445
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
446
453
|
}
|
|
447
454
|
}
|
|
448
455
|
}
|
|
449
|
-
catch (
|
|
456
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
450
457
|
finally {
|
|
451
458
|
try {
|
|
452
|
-
if (
|
|
459
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
453
460
|
}
|
|
454
|
-
finally { if (
|
|
461
|
+
finally { if (e_2) throw e_2.error; }
|
|
455
462
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
463
|
+
// Note: Detect circular dependencies
|
|
464
|
+
var resovedParameters = promptbook.parameters
|
|
465
|
+
.filter(function (_a) {
|
|
466
|
+
var isInput = _a.isInput;
|
|
467
|
+
return isInput;
|
|
468
|
+
})
|
|
469
|
+
.map(function (_a) {
|
|
470
|
+
var name = _a.name;
|
|
471
|
+
return name;
|
|
472
|
+
});
|
|
473
|
+
var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
474
|
+
var loopLimit = LOOP_LIMIT;
|
|
475
|
+
var _loop_2 = function () {
|
|
476
|
+
if (loopLimit-- < 0) {
|
|
477
|
+
throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePromptbookJson`');
|
|
478
|
+
}
|
|
479
|
+
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
480
|
+
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
481
|
+
});
|
|
482
|
+
if (currentlyResovedTemplates.length === 0) {
|
|
483
|
+
throw new PromptbookLogicError(spaceTrim.spaceTrim(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
484
|
+
.map(function (_a) {
|
|
485
|
+
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
486
|
+
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
487
|
+
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
488
|
+
.join(', '));
|
|
489
|
+
})
|
|
490
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
491
|
+
}
|
|
492
|
+
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
|
|
493
|
+
var resultingParameterName = _a.resultingParameterName;
|
|
494
|
+
return resultingParameterName;
|
|
495
|
+
})), false);
|
|
496
|
+
unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
|
|
497
|
+
};
|
|
498
|
+
while (unresovedTemplates.length > 0) {
|
|
499
|
+
_loop_2();
|
|
459
500
|
}
|
|
460
|
-
return
|
|
501
|
+
return promptbook;
|
|
461
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* TODO: [🧠] Work with promptbookVersion
|
|
505
|
+
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
506
|
+
* > /**
|
|
507
|
+
* > * Validates PromptbookJson if it is logically valid.
|
|
508
|
+
* > *
|
|
509
|
+
* > * It checks:
|
|
510
|
+
* > * - it has a valid structure
|
|
511
|
+
* > * - ...
|
|
512
|
+
* > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
|
|
513
|
+
*/
|
|
462
514
|
|
|
463
515
|
/**
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
* Note: If there are multiple or no code blocks the function throws an error
|
|
467
|
-
*
|
|
468
|
-
* Note: There are 3 simmilar function:
|
|
469
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
470
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
471
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
516
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
472
517
|
*
|
|
473
|
-
* @
|
|
474
|
-
*
|
|
518
|
+
* @private Always catched and rethrown as `PromptbookExecutionError`
|
|
519
|
+
* Note: This is a kindof subtype of PromptbookExecutionError
|
|
475
520
|
*/
|
|
476
|
-
function
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
521
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
522
|
+
__extends(ExpectError, _super);
|
|
523
|
+
function ExpectError(message) {
|
|
524
|
+
var _this = _super.call(this, message) || this;
|
|
525
|
+
_this.name = 'ExpectError';
|
|
526
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
527
|
+
return _this;
|
|
481
528
|
}
|
|
482
|
-
return
|
|
483
|
-
}
|
|
484
|
-
/***
|
|
485
|
-
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
486
|
-
*/
|
|
529
|
+
return ExpectError;
|
|
530
|
+
}(Error));
|
|
487
531
|
|
|
488
532
|
/**
|
|
489
|
-
*
|
|
533
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
490
534
|
*/
|
|
491
|
-
function
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
sets[_i] = arguments[_i];
|
|
535
|
+
function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
536
|
+
try {
|
|
537
|
+
JSON.parse(value);
|
|
538
|
+
return true;
|
|
496
539
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
var set = sets_1_1.value;
|
|
501
|
-
try {
|
|
502
|
-
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
503
|
-
var item = _d.value;
|
|
504
|
-
union.add(item);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
508
|
-
finally {
|
|
509
|
-
try {
|
|
510
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
511
|
-
}
|
|
512
|
-
finally { if (e_2) throw e_2.error; }
|
|
513
|
-
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
if (!(error instanceof Error)) {
|
|
542
|
+
throw error;
|
|
514
543
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
finally {
|
|
518
|
-
try {
|
|
519
|
-
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
544
|
+
if (error.message.includes('Unexpected token')) {
|
|
545
|
+
return false;
|
|
520
546
|
}
|
|
521
|
-
|
|
547
|
+
return false;
|
|
522
548
|
}
|
|
523
|
-
return union;
|
|
524
549
|
}
|
|
525
550
|
|
|
526
551
|
/**
|
|
527
|
-
*
|
|
552
|
+
* Function `addUsage` will add multiple usages into one
|
|
528
553
|
*
|
|
529
|
-
*
|
|
530
|
-
* @returns the list of parameter names
|
|
554
|
+
* Note: If you provide 0 values, it returns void usage
|
|
531
555
|
*/
|
|
532
|
-
function
|
|
533
|
-
var
|
|
534
|
-
var
|
|
535
|
-
|
|
536
|
-
try {
|
|
537
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
538
|
-
var match = matches_1_1.value;
|
|
539
|
-
var parameterName = match[0].slice(1, -1);
|
|
540
|
-
parameterNames.add(parameterName);
|
|
541
|
-
}
|
|
556
|
+
function addUsage() {
|
|
557
|
+
var usageItems = [];
|
|
558
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
559
|
+
usageItems[_i] = arguments[_i];
|
|
542
560
|
}
|
|
543
|
-
|
|
544
|
-
|
|
561
|
+
var initialStructure = {
|
|
562
|
+
price: { value: 0 },
|
|
563
|
+
input: {
|
|
564
|
+
tokensCount: { value: 0 },
|
|
565
|
+
charactersCount: { value: 0 },
|
|
566
|
+
wordsCount: { value: 0 },
|
|
567
|
+
sentencesCount: { value: 0 },
|
|
568
|
+
linesCount: { value: 0 },
|
|
569
|
+
paragraphsCount: { value: 0 },
|
|
570
|
+
pagesCount: { value: 0 },
|
|
571
|
+
},
|
|
572
|
+
output: {
|
|
573
|
+
tokensCount: { value: 0 },
|
|
574
|
+
charactersCount: { value: 0 },
|
|
575
|
+
wordsCount: { value: 0 },
|
|
576
|
+
sentencesCount: { value: 0 },
|
|
577
|
+
linesCount: { value: 0 },
|
|
578
|
+
paragraphsCount: { value: 0 },
|
|
579
|
+
pagesCount: { value: 0 },
|
|
580
|
+
},
|
|
581
|
+
};
|
|
582
|
+
return usageItems.reduce(function (acc, item) {
|
|
583
|
+
var e_1, _a, e_2, _b;
|
|
584
|
+
var _c;
|
|
585
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
545
586
|
try {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
var variables = new Set();
|
|
562
|
-
script = "(()=>{".concat(script, "})()");
|
|
563
|
-
try {
|
|
564
|
-
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
565
|
-
try {
|
|
566
|
-
eval(script);
|
|
567
|
-
}
|
|
568
|
-
catch (error) {
|
|
569
|
-
if (!(error instanceof ReferenceError)) {
|
|
570
|
-
throw error;
|
|
571
|
-
}
|
|
572
|
-
var undefinedName = error.message.split(' ')[0];
|
|
573
|
-
/*
|
|
574
|
-
Note: Remapping error
|
|
575
|
-
From: [ReferenceError: thing is not defined],
|
|
576
|
-
To: [Error: Parameter {thing} is not defined],
|
|
577
|
-
*/
|
|
578
|
-
if (!undefinedName) {
|
|
579
|
-
throw error;
|
|
580
|
-
}
|
|
581
|
-
if (script.includes(undefinedName + '(')) {
|
|
582
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
583
|
-
}
|
|
584
|
-
else {
|
|
585
|
-
variables.add(undefinedName);
|
|
586
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
587
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
588
|
+
var key = _e.value;
|
|
589
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
590
|
+
//@ts-ignore
|
|
591
|
+
if (item.input[key]) {
|
|
592
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
593
|
+
//@ts-ignore
|
|
594
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
595
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
596
|
+
//@ts-ignore
|
|
597
|
+
if (item.input[key].isUncertain) {
|
|
598
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
599
|
+
//@ts-ignore
|
|
600
|
+
acc.input[key].isUncertain = true;
|
|
601
|
+
}
|
|
587
602
|
}
|
|
588
603
|
}
|
|
589
|
-
}
|
|
590
|
-
catch (error) {
|
|
591
|
-
if (!(error instanceof Error)) {
|
|
592
|
-
throw error;
|
|
593
|
-
}
|
|
594
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
595
|
-
}
|
|
596
|
-
return variables;
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
600
|
-
*/
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* Parses the prompt template and returns the set of all used parameters
|
|
604
|
-
*
|
|
605
|
-
* @param promptTemplate the template with used parameters
|
|
606
|
-
* @returns the set of parameter names
|
|
607
|
-
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
608
|
-
*/
|
|
609
|
-
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
610
|
-
var e_1, _a, e_2, _b;
|
|
611
|
-
var parameterNames = new Set();
|
|
612
|
-
try {
|
|
613
|
-
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()) {
|
|
614
|
-
var parameterName = _d.value;
|
|
615
|
-
parameterNames.add(parameterName);
|
|
616
604
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
605
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
606
|
+
finally {
|
|
607
|
+
try {
|
|
608
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
609
|
+
}
|
|
610
|
+
finally { if (e_1) throw e_1.error; }
|
|
622
611
|
}
|
|
623
|
-
finally { if (e_1) throw e_1.error; }
|
|
624
|
-
}
|
|
625
|
-
if (promptTemplate.executionType === 'SCRIPT') {
|
|
626
612
|
try {
|
|
627
|
-
for (var
|
|
628
|
-
var
|
|
629
|
-
|
|
613
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
614
|
+
var key = _g.value;
|
|
615
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
616
|
+
//@ts-ignore
|
|
617
|
+
if (item.output[key]) {
|
|
618
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
619
|
+
//@ts-ignore
|
|
620
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
621
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
622
|
+
//@ts-ignore
|
|
623
|
+
if (item.output[key].isUncertain) {
|
|
624
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
625
|
+
//@ts-ignore
|
|
626
|
+
acc.output[key].isUncertain = true;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
630
629
|
}
|
|
631
630
|
}
|
|
632
631
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
633
632
|
finally {
|
|
634
633
|
try {
|
|
635
|
-
if (
|
|
634
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
636
635
|
}
|
|
637
636
|
finally { if (e_2) throw e_2.error; }
|
|
638
637
|
}
|
|
639
|
-
|
|
640
|
-
|
|
638
|
+
return acc;
|
|
639
|
+
}, initialStructure);
|
|
641
640
|
}
|
|
642
|
-
/**
|
|
643
|
-
* TODO: [🔣] If script require contentLanguage
|
|
644
|
-
*/
|
|
645
641
|
|
|
646
|
-
/* tslint:disable */
|
|
647
|
-
/*
|
|
648
|
-
TODO: Tests
|
|
649
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
650
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
651
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
652
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
653
|
-
*/
|
|
654
|
-
function normalizeTo_SCREAMING_CASE(sentence) {
|
|
655
|
-
var e_1, _a;
|
|
656
|
-
var charType;
|
|
657
|
-
var lastCharType = 'OTHER';
|
|
658
|
-
var normalizedName = '';
|
|
659
|
-
try {
|
|
660
|
-
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
661
|
-
var char = sentence_1_1.value;
|
|
662
|
-
var normalizedChar = void 0;
|
|
663
|
-
if (/^[a-z]$/.test(char)) {
|
|
664
|
-
charType = 'LOWERCASE';
|
|
665
|
-
normalizedChar = char.toUpperCase();
|
|
666
|
-
}
|
|
667
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
668
|
-
charType = 'UPPERCASE';
|
|
669
|
-
normalizedChar = char;
|
|
670
|
-
}
|
|
671
|
-
else if (/^[0-9]$/.test(char)) {
|
|
672
|
-
charType = 'NUMBER';
|
|
673
|
-
normalizedChar = char;
|
|
674
|
-
}
|
|
675
|
-
else if (/^\/$/.test(char)) {
|
|
676
|
-
charType = 'SLASH';
|
|
677
|
-
normalizedChar = char;
|
|
678
|
-
}
|
|
679
|
-
else {
|
|
680
|
-
charType = 'OTHER';
|
|
681
|
-
normalizedChar = '_';
|
|
682
|
-
}
|
|
683
|
-
if (charType !== lastCharType &&
|
|
684
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
685
|
-
!(lastCharType === 'NUMBER') &&
|
|
686
|
-
!(charType === 'NUMBER')) {
|
|
687
|
-
normalizedName += '_';
|
|
688
|
-
}
|
|
689
|
-
normalizedName += normalizedChar;
|
|
690
|
-
lastCharType = charType;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
694
|
-
finally {
|
|
695
|
-
try {
|
|
696
|
-
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
697
|
-
}
|
|
698
|
-
finally { if (e_1) throw e_1.error; }
|
|
699
|
-
}
|
|
700
|
-
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
701
|
-
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
702
|
-
normalizedName = normalizedName.replace(/^_/, '');
|
|
703
|
-
normalizedName = normalizedName.replace(/_$/, '');
|
|
704
|
-
return normalizedName;
|
|
705
|
-
}
|
|
706
642
|
/**
|
|
707
|
-
*
|
|
643
|
+
* Counts number of characters in the text
|
|
708
644
|
*/
|
|
645
|
+
function countCharacters(text) {
|
|
646
|
+
// Remove null characters
|
|
647
|
+
text = text.replace(/\0/g, '');
|
|
648
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
649
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
650
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
651
|
+
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
652
|
+
return text.length;
|
|
653
|
+
}
|
|
709
654
|
|
|
710
655
|
/**
|
|
711
|
-
*
|
|
712
|
-
*
|
|
713
|
-
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
656
|
+
* Counts number of lines in the text
|
|
714
657
|
*/
|
|
715
|
-
|
|
716
|
-
'
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
'
|
|
720
|
-
|
|
721
|
-
];
|
|
658
|
+
function countLines(text) {
|
|
659
|
+
if (text === '') {
|
|
660
|
+
return 0;
|
|
661
|
+
}
|
|
662
|
+
return text.split('\n').length;
|
|
663
|
+
}
|
|
722
664
|
|
|
723
665
|
/**
|
|
724
|
-
*
|
|
666
|
+
* Counts number of pages in the text
|
|
725
667
|
*/
|
|
726
|
-
|
|
668
|
+
function countPages(text) {
|
|
669
|
+
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
670
|
+
var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
671
|
+
var pageCount = Math.ceil(sentences.length / sentencesPerPage);
|
|
672
|
+
return pageCount;
|
|
673
|
+
}
|
|
674
|
+
|
|
727
675
|
/**
|
|
728
|
-
*
|
|
729
|
-
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
730
|
-
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
676
|
+
* Counts number of paragraphs in the text
|
|
731
677
|
*/
|
|
678
|
+
function countParagraphs(text) {
|
|
679
|
+
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
680
|
+
}
|
|
732
681
|
|
|
733
682
|
/**
|
|
734
|
-
*
|
|
735
|
-
*
|
|
736
|
-
* @param {string} str - The string to remove Markdown tags from.
|
|
737
|
-
* @returns {string} The input string with all Markdown tags removed.
|
|
683
|
+
* Split text into sentences
|
|
738
684
|
*/
|
|
739
|
-
function
|
|
740
|
-
|
|
741
|
-
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
742
|
-
// Remove italic formatting
|
|
743
|
-
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
744
|
-
// Remove code formatting
|
|
745
|
-
str = str.replace(/`(.*?)`/g, '$1');
|
|
746
|
-
return str;
|
|
685
|
+
function splitIntoSentences(text) {
|
|
686
|
+
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
747
687
|
}
|
|
748
|
-
|
|
749
688
|
/**
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
753
|
-
* Note: it also works only with decimal numbers
|
|
754
|
-
*
|
|
755
|
-
* @returns parsed number
|
|
756
|
-
* @throws {PromptbookSyntaxError} if the value is not a number
|
|
757
|
-
*
|
|
758
|
-
* @private within the parseCommand
|
|
689
|
+
* Counts number of sentences in the text
|
|
759
690
|
*/
|
|
760
|
-
function
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
691
|
+
function countSentences(text) {
|
|
692
|
+
return splitIntoSentences(text).length;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
var defaultDiacriticsRemovalMap = [
|
|
696
|
+
{
|
|
697
|
+
base: 'A',
|
|
698
|
+
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
699
|
+
},
|
|
700
|
+
{ base: 'AA', letters: '\uA732' },
|
|
701
|
+
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
702
|
+
{ base: 'AO', letters: '\uA734' },
|
|
703
|
+
{ base: 'AU', letters: '\uA736' },
|
|
704
|
+
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
705
|
+
{ base: 'AY', letters: '\uA73C' },
|
|
706
|
+
{
|
|
707
|
+
base: 'B',
|
|
708
|
+
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
base: 'C',
|
|
712
|
+
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
713
|
+
},
|
|
714
|
+
{
|
|
715
|
+
base: 'D',
|
|
716
|
+
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
717
|
+
},
|
|
718
|
+
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
719
|
+
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
720
|
+
{
|
|
721
|
+
base: 'E',
|
|
722
|
+
letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
|
|
723
|
+
},
|
|
724
|
+
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
725
|
+
{
|
|
726
|
+
base: 'G',
|
|
727
|
+
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
base: 'H',
|
|
731
|
+
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
base: 'I',
|
|
735
|
+
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
736
|
+
},
|
|
737
|
+
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
738
|
+
{
|
|
739
|
+
base: 'K',
|
|
740
|
+
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
base: 'L',
|
|
744
|
+
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
745
|
+
},
|
|
746
|
+
{ base: 'LJ', letters: '\u01C7' },
|
|
747
|
+
{ base: 'Lj', letters: '\u01C8' },
|
|
748
|
+
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
749
|
+
{
|
|
750
|
+
base: 'N',
|
|
751
|
+
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
752
|
+
},
|
|
753
|
+
{ base: 'NJ', letters: '\u01CA' },
|
|
754
|
+
{ base: 'Nj', letters: '\u01CB' },
|
|
755
|
+
{
|
|
756
|
+
base: 'O',
|
|
757
|
+
letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
|
|
758
|
+
},
|
|
759
|
+
{ base: 'OI', letters: '\u01A2' },
|
|
760
|
+
{ base: 'OO', letters: '\uA74E' },
|
|
761
|
+
{ base: 'OU', letters: '\u0222' },
|
|
762
|
+
{ base: 'OE', letters: '\u008C\u0152' },
|
|
763
|
+
{ base: 'oe', letters: '\u009C\u0153' },
|
|
764
|
+
{
|
|
765
|
+
base: 'P',
|
|
766
|
+
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
767
|
+
},
|
|
768
|
+
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
769
|
+
{
|
|
770
|
+
base: 'R',
|
|
771
|
+
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
772
|
+
},
|
|
773
|
+
{
|
|
774
|
+
base: 'S',
|
|
775
|
+
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
base: 'T',
|
|
779
|
+
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
780
|
+
},
|
|
781
|
+
{ base: 'TZ', letters: '\uA728' },
|
|
782
|
+
{
|
|
783
|
+
base: 'U',
|
|
784
|
+
letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
|
|
785
|
+
},
|
|
786
|
+
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
787
|
+
{ base: 'VY', letters: '\uA760' },
|
|
788
|
+
{
|
|
789
|
+
base: 'W',
|
|
790
|
+
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
791
|
+
},
|
|
792
|
+
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
793
|
+
{
|
|
794
|
+
base: 'Y',
|
|
795
|
+
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
base: 'Z',
|
|
799
|
+
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
base: 'a',
|
|
803
|
+
letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
|
|
804
|
+
},
|
|
805
|
+
{ base: 'aa', letters: '\uA733' },
|
|
806
|
+
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
807
|
+
{ base: 'ao', letters: '\uA735' },
|
|
808
|
+
{ base: 'au', letters: '\uA737' },
|
|
809
|
+
{ base: 'av', letters: '\uA739\uA73B' },
|
|
810
|
+
{ base: 'ay', letters: '\uA73D' },
|
|
811
|
+
{
|
|
812
|
+
base: 'b',
|
|
813
|
+
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
base: 'c',
|
|
817
|
+
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
base: 'd',
|
|
821
|
+
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
822
|
+
},
|
|
823
|
+
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
824
|
+
{
|
|
825
|
+
base: 'e',
|
|
826
|
+
letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
|
|
827
|
+
},
|
|
828
|
+
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
829
|
+
{
|
|
830
|
+
base: 'g',
|
|
831
|
+
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
base: 'h',
|
|
835
|
+
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
836
|
+
},
|
|
837
|
+
{ base: 'hv', letters: '\u0195' },
|
|
838
|
+
{
|
|
839
|
+
base: 'i',
|
|
840
|
+
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
841
|
+
},
|
|
842
|
+
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
843
|
+
{
|
|
844
|
+
base: 'k',
|
|
845
|
+
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
base: 'l',
|
|
849
|
+
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
850
|
+
},
|
|
851
|
+
{ base: 'lj', letters: '\u01C9' },
|
|
852
|
+
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
853
|
+
{
|
|
854
|
+
base: 'n',
|
|
855
|
+
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
856
|
+
},
|
|
857
|
+
{ base: 'nj', letters: '\u01CC' },
|
|
858
|
+
{
|
|
859
|
+
base: 'o',
|
|
860
|
+
letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
|
|
861
|
+
},
|
|
862
|
+
{ base: 'oi', letters: '\u01A3' },
|
|
863
|
+
{ base: 'ou', letters: '\u0223' },
|
|
864
|
+
{ base: 'oo', letters: '\uA74F' },
|
|
865
|
+
{
|
|
866
|
+
base: 'p',
|
|
867
|
+
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
868
|
+
},
|
|
869
|
+
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
870
|
+
{
|
|
871
|
+
base: 'r',
|
|
872
|
+
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
873
|
+
},
|
|
874
|
+
{
|
|
875
|
+
base: 's',
|
|
876
|
+
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
base: 't',
|
|
880
|
+
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
881
|
+
},
|
|
882
|
+
{ base: 'tz', letters: '\uA729' },
|
|
883
|
+
{
|
|
884
|
+
base: 'u',
|
|
885
|
+
letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
|
|
886
|
+
},
|
|
887
|
+
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
888
|
+
{ base: 'vy', letters: '\uA761' },
|
|
889
|
+
{
|
|
890
|
+
base: 'w',
|
|
891
|
+
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
892
|
+
},
|
|
893
|
+
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
894
|
+
{
|
|
895
|
+
base: 'y',
|
|
896
|
+
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
897
|
+
},
|
|
898
|
+
{
|
|
899
|
+
base: 'z',
|
|
900
|
+
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
901
|
+
},
|
|
902
|
+
];
|
|
903
|
+
/**
|
|
904
|
+
* Map of letters from diacritic variant to diacritless variant
|
|
905
|
+
* Contains lowercase and uppercase separatelly
|
|
906
|
+
*
|
|
907
|
+
* > "á" => "a"
|
|
908
|
+
* > "ě" => "e"
|
|
909
|
+
* > "Ă" => "A"
|
|
910
|
+
* > ...
|
|
911
|
+
*/
|
|
912
|
+
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
913
|
+
// tslint:disable-next-line: prefer-for-of
|
|
914
|
+
for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
915
|
+
var letters = defaultDiacriticsRemovalMap[i].letters;
|
|
916
|
+
// tslint:disable-next-line: prefer-for-of
|
|
917
|
+
for (var j = 0; j < letters.length; j++) {
|
|
918
|
+
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
922
|
+
/*
|
|
923
|
+
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
924
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
925
|
+
you may not use this file except in compliance with the License.
|
|
926
|
+
You may obtain a copy of the License at
|
|
927
|
+
|
|
928
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
929
|
+
|
|
930
|
+
Unless required by applicable law or agreed to in writing, software
|
|
931
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
932
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
933
|
+
See the License for the specific language governing permissions and
|
|
934
|
+
limitations under the License.
|
|
935
|
+
*/
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
*
|
|
939
|
+
*/
|
|
940
|
+
function removeDiacritics(input) {
|
|
941
|
+
/*eslint no-control-regex: "off"*/
|
|
942
|
+
return input.replace(/[^\u0000-\u007E]/g, function (a) {
|
|
943
|
+
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* Counts number of words in the text
|
|
949
|
+
*/
|
|
950
|
+
function countWords(text) {
|
|
951
|
+
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
952
|
+
text = removeDiacritics(text);
|
|
953
|
+
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Index of all counter functions
|
|
958
|
+
*/
|
|
959
|
+
var CountUtils = {
|
|
960
|
+
CHARACTERS: countCharacters,
|
|
961
|
+
WORDS: countWords,
|
|
962
|
+
SENTENCES: countSentences,
|
|
963
|
+
PARAGRAPHS: countParagraphs,
|
|
964
|
+
LINES: countLines,
|
|
965
|
+
PAGES: countPages,
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Function checkExpectations will check if the expectations on given value are met
|
|
970
|
+
*
|
|
971
|
+
* Note: There are two simmilar functions:
|
|
972
|
+
* - `checkExpectations` which throws an error if the expectations are not met
|
|
973
|
+
* - `isPassingExpectations` which returns a boolean
|
|
974
|
+
*
|
|
975
|
+
* @throws {ExpectError} if the expectations are not met
|
|
976
|
+
* @returns {void} Nothing
|
|
977
|
+
*/
|
|
978
|
+
function checkExpectations(expectations, value) {
|
|
979
|
+
var e_1, _a;
|
|
980
|
+
try {
|
|
981
|
+
for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
982
|
+
var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
|
|
983
|
+
var amount = CountUtils[unit.toUpperCase()](value);
|
|
984
|
+
if (min && amount < min) {
|
|
985
|
+
throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
|
|
986
|
+
} /* not else */
|
|
987
|
+
if (max && amount > max) {
|
|
988
|
+
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
993
|
+
finally {
|
|
994
|
+
try {
|
|
995
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
996
|
+
}
|
|
997
|
+
finally { if (e_1) throw e_1.error; }
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* TODO: [💝] Unite object for expecting amount and format
|
|
1002
|
+
*/
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* This error occurs during the parameter replacement in the template
|
|
1006
|
+
*
|
|
1007
|
+
* Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
|
|
1008
|
+
*/
|
|
1009
|
+
var TemplateError = /** @class */ (function (_super) {
|
|
1010
|
+
__extends(TemplateError, _super);
|
|
1011
|
+
function TemplateError(message) {
|
|
1012
|
+
var _this = _super.call(this, message) || this;
|
|
1013
|
+
_this.name = 'TemplateError';
|
|
1014
|
+
Object.setPrototypeOf(_this, TemplateError.prototype);
|
|
1015
|
+
return _this;
|
|
1016
|
+
}
|
|
1017
|
+
return TemplateError;
|
|
1018
|
+
}(Error));
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Replaces parameters in template with values from parameters object
|
|
1022
|
+
*
|
|
1023
|
+
* @param template the template with parameters in {curly} braces
|
|
1024
|
+
* @param parameters the object with parameters
|
|
1025
|
+
* @returns the template with replaced parameters
|
|
1026
|
+
* @throws {TemplateError} if parameter is not defined, not closed, or not opened
|
|
1027
|
+
*
|
|
1028
|
+
* @private within the createPromptbookExecutor
|
|
1029
|
+
*/
|
|
1030
|
+
function replaceParameters(template, parameters) {
|
|
1031
|
+
var replacedTemplate = template;
|
|
1032
|
+
var match;
|
|
1033
|
+
var loopLimit = LOOP_LIMIT;
|
|
1034
|
+
var _loop_1 = function () {
|
|
1035
|
+
if (loopLimit-- < 0) {
|
|
1036
|
+
throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
1037
|
+
}
|
|
1038
|
+
var precol = match.groups.precol;
|
|
1039
|
+
var parameterName = match.groups.parameterName;
|
|
1040
|
+
if (parameterName === '') {
|
|
1041
|
+
return "continue";
|
|
1042
|
+
}
|
|
1043
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
1044
|
+
throw new TemplateError('Parameter is already opened or not closed');
|
|
1045
|
+
}
|
|
1046
|
+
if (parameters[parameterName] === undefined) {
|
|
1047
|
+
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
1048
|
+
}
|
|
1049
|
+
var parameterValue = parameters[parameterName];
|
|
1050
|
+
if (parameterValue === undefined) {
|
|
1051
|
+
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
1052
|
+
}
|
|
1053
|
+
parameterValue = parameterValue.toString();
|
|
1054
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
1055
|
+
parameterValue = parameterValue
|
|
1056
|
+
.split('\n')
|
|
1057
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
1058
|
+
.join('\n');
|
|
1059
|
+
}
|
|
1060
|
+
replacedTemplate =
|
|
1061
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
1062
|
+
parameterValue +
|
|
1063
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
1064
|
+
};
|
|
1065
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
1066
|
+
.exec(replacedTemplate))) {
|
|
1067
|
+
_loop_1();
|
|
1068
|
+
}
|
|
1069
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
1070
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
1071
|
+
throw new TemplateError('Parameter is not closed');
|
|
1072
|
+
}
|
|
1073
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
1074
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
1075
|
+
throw new TemplateError('Parameter is not opened');
|
|
1076
|
+
}
|
|
1077
|
+
return replacedTemplate;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* Creates executor function from promptbook and execution tools.
|
|
1082
|
+
*
|
|
1083
|
+
* @returns The executor function
|
|
1084
|
+
* @throws {PromptbookLogicError} on logical error in the promptbook
|
|
1085
|
+
*/
|
|
1086
|
+
function createPromptbookExecutor(options) {
|
|
1087
|
+
var _this = this;
|
|
1088
|
+
var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1089
|
+
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1090
|
+
validatePromptbookJson(promptbook);
|
|
1091
|
+
var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1092
|
+
function executeSingleTemplate(currentTemplate) {
|
|
1093
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1094
|
+
var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, error_4;
|
|
1095
|
+
var e_2, _j, e_4, _k, e_3, _l, _m;
|
|
1096
|
+
var _this = this;
|
|
1097
|
+
return __generator(this, function (_o) {
|
|
1098
|
+
switch (_o.label) {
|
|
1099
|
+
case 0:
|
|
1100
|
+
name = "promptbook-executor-frame-".concat(currentTemplate.name);
|
|
1101
|
+
title = currentTemplate.title;
|
|
1102
|
+
priority = promptbook.promptTemplates.length - promptbook.promptTemplates.indexOf(currentTemplate);
|
|
1103
|
+
if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
1104
|
+
return [4 /*yield*/, onProgress({
|
|
1105
|
+
name: name,
|
|
1106
|
+
title: title,
|
|
1107
|
+
isStarted: false,
|
|
1108
|
+
isDone: false,
|
|
1109
|
+
executionType: currentTemplate.executionType,
|
|
1110
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
1111
|
+
parameterValue: null,
|
|
1112
|
+
// <- [3]
|
|
1113
|
+
})];
|
|
1114
|
+
case 1:
|
|
1115
|
+
_o.sent();
|
|
1116
|
+
_o.label = 2;
|
|
1117
|
+
case 2:
|
|
1118
|
+
result = null;
|
|
1119
|
+
resultString = null;
|
|
1120
|
+
expectError = null;
|
|
1121
|
+
maxAttempts = currentTemplate.executionType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
1122
|
+
jokers = currentTemplate.jokers || [];
|
|
1123
|
+
attempt = -jokers.length;
|
|
1124
|
+
_o.label = 3;
|
|
1125
|
+
case 3:
|
|
1126
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 49];
|
|
1127
|
+
isJokerAttempt = attempt < 0;
|
|
1128
|
+
joker = jokers[jokers.length + attempt];
|
|
1129
|
+
if (isJokerAttempt && !joker) {
|
|
1130
|
+
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
1131
|
+
}
|
|
1132
|
+
result = null;
|
|
1133
|
+
resultString = null;
|
|
1134
|
+
expectError = null;
|
|
1135
|
+
if (isJokerAttempt) {
|
|
1136
|
+
if (typeof parametersToPass[joker] === 'undefined') {
|
|
1137
|
+
throw new PromptbookExecutionError("Joker parameter {".concat(joker, "} not defined"));
|
|
1138
|
+
}
|
|
1139
|
+
resultString = parametersToPass[joker];
|
|
1140
|
+
}
|
|
1141
|
+
_o.label = 4;
|
|
1142
|
+
case 4:
|
|
1143
|
+
_o.trys.push([4, 45, 46, 47]);
|
|
1144
|
+
if (!!isJokerAttempt) return [3 /*break*/, 27];
|
|
1145
|
+
_a = currentTemplate.executionType;
|
|
1146
|
+
switch (_a) {
|
|
1147
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 5];
|
|
1148
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 6];
|
|
1149
|
+
case 'SCRIPT': return [3 /*break*/, 13];
|
|
1150
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 24];
|
|
1151
|
+
}
|
|
1152
|
+
return [3 /*break*/, 26];
|
|
1153
|
+
case 5:
|
|
1154
|
+
resultString = replaceParameters(currentTemplate.content, parametersToPass);
|
|
1155
|
+
return [3 /*break*/, 27];
|
|
1156
|
+
case 6:
|
|
1157
|
+
prompt = {
|
|
1158
|
+
title: currentTemplate.title,
|
|
1159
|
+
promptbookUrl: "".concat(promptbook.promptbookUrl
|
|
1160
|
+
? promptbook.promptbookUrl
|
|
1161
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
1162
|
+
parameters: parametersToPass,
|
|
1163
|
+
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
1164
|
+
modelRequirements: currentTemplate.modelRequirements,
|
|
1165
|
+
expectations: currentTemplate.expectations,
|
|
1166
|
+
expectFormat: currentTemplate.expectFormat,
|
|
1167
|
+
postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
1168
|
+
var errors, _a, _b, scriptTools, error_5, e_5_1;
|
|
1169
|
+
var e_5, _c;
|
|
1170
|
+
return __generator(this, function (_d) {
|
|
1171
|
+
switch (_d.label) {
|
|
1172
|
+
case 0:
|
|
1173
|
+
errors = [];
|
|
1174
|
+
_d.label = 1;
|
|
1175
|
+
case 1:
|
|
1176
|
+
_d.trys.push([1, 8, 9, 10]);
|
|
1177
|
+
_a = __values(tools.script), _b = _a.next();
|
|
1178
|
+
_d.label = 2;
|
|
1179
|
+
case 2:
|
|
1180
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
1181
|
+
scriptTools = _b.value;
|
|
1182
|
+
_d.label = 3;
|
|
1183
|
+
case 3:
|
|
1184
|
+
_d.trys.push([3, 5, , 6]);
|
|
1185
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
1186
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
1187
|
+
script: "".concat(functionName, "(result)"),
|
|
1188
|
+
parameters: {
|
|
1189
|
+
result: result || '',
|
|
1190
|
+
// Note: No ...parametersToPass, because working with result only
|
|
1191
|
+
},
|
|
1192
|
+
})];
|
|
1193
|
+
case 4: return [2 /*return*/, _d.sent()];
|
|
1194
|
+
case 5:
|
|
1195
|
+
error_5 = _d.sent();
|
|
1196
|
+
if (!(error_5 instanceof Error)) {
|
|
1197
|
+
throw error_5;
|
|
1198
|
+
}
|
|
1199
|
+
errors.push(error_5);
|
|
1200
|
+
return [3 /*break*/, 6];
|
|
1201
|
+
case 6:
|
|
1202
|
+
_b = _a.next();
|
|
1203
|
+
return [3 /*break*/, 2];
|
|
1204
|
+
case 7: return [3 /*break*/, 10];
|
|
1205
|
+
case 8:
|
|
1206
|
+
e_5_1 = _d.sent();
|
|
1207
|
+
e_5 = { error: e_5_1 };
|
|
1208
|
+
return [3 /*break*/, 10];
|
|
1209
|
+
case 9:
|
|
1210
|
+
try {
|
|
1211
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1212
|
+
}
|
|
1213
|
+
finally { if (e_5) throw e_5.error; }
|
|
1214
|
+
return [7 /*endfinally*/];
|
|
1215
|
+
case 10:
|
|
1216
|
+
if (errors.length === 0) {
|
|
1217
|
+
throw new PromptbookExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
|
|
1218
|
+
}
|
|
1219
|
+
else if (errors.length === 1) {
|
|
1220
|
+
throw errors[0];
|
|
1221
|
+
}
|
|
1222
|
+
else {
|
|
1223
|
+
throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
}); }; }),
|
|
1228
|
+
};
|
|
1229
|
+
_b = currentTemplate.modelRequirements.modelVariant;
|
|
1230
|
+
switch (_b) {
|
|
1231
|
+
case 'CHAT': return [3 /*break*/, 7];
|
|
1232
|
+
case 'COMPLETION': return [3 /*break*/, 9];
|
|
1233
|
+
}
|
|
1234
|
+
return [3 /*break*/, 11];
|
|
1235
|
+
case 7: return [4 /*yield*/, tools.llm.gptChat(prompt)];
|
|
1236
|
+
case 8:
|
|
1237
|
+
chatThread = _o.sent();
|
|
1238
|
+
// TODO: [🍬] Destroy chatThread
|
|
1239
|
+
result = chatThread;
|
|
1240
|
+
resultString = chatThread.content;
|
|
1241
|
+
return [3 /*break*/, 12];
|
|
1242
|
+
case 9: return [4 /*yield*/, tools.llm.gptComplete(prompt)];
|
|
1243
|
+
case 10:
|
|
1244
|
+
completionResult = _o.sent();
|
|
1245
|
+
result = completionResult;
|
|
1246
|
+
resultString = completionResult.content;
|
|
1247
|
+
return [3 /*break*/, 12];
|
|
1248
|
+
case 11: throw new PromptbookExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
1249
|
+
case 12: return [3 /*break*/, 27];
|
|
1250
|
+
case 13:
|
|
1251
|
+
if (tools.script.length === 0) {
|
|
1252
|
+
throw new PromptbookExecutionError('No script execution tools are available');
|
|
1253
|
+
}
|
|
1254
|
+
if (!currentTemplate.contentLanguage) {
|
|
1255
|
+
throw new PromptbookExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
1256
|
+
}
|
|
1257
|
+
// TODO: DRY [1]
|
|
1258
|
+
scriptExecutionErrors = [];
|
|
1259
|
+
_o.label = 14;
|
|
1260
|
+
case 14:
|
|
1261
|
+
_o.trys.push([14, 21, 22, 23]);
|
|
1262
|
+
_c = (e_2 = void 0, __values(tools.script)), _d = _c.next();
|
|
1263
|
+
_o.label = 15;
|
|
1264
|
+
case 15:
|
|
1265
|
+
if (!!_d.done) return [3 /*break*/, 20];
|
|
1266
|
+
scriptTools = _d.value;
|
|
1267
|
+
_o.label = 16;
|
|
1268
|
+
case 16:
|
|
1269
|
+
_o.trys.push([16, 18, , 19]);
|
|
1270
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
1271
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
1272
|
+
script: currentTemplate.content,
|
|
1273
|
+
parameters: parametersToPass,
|
|
1274
|
+
})];
|
|
1275
|
+
case 17:
|
|
1276
|
+
resultString = _o.sent();
|
|
1277
|
+
return [3 /*break*/, 20];
|
|
1278
|
+
case 18:
|
|
1279
|
+
error_2 = _o.sent();
|
|
1280
|
+
if (!(error_2 instanceof Error)) {
|
|
1281
|
+
throw error_2;
|
|
1282
|
+
}
|
|
1283
|
+
scriptExecutionErrors.push(error_2);
|
|
1284
|
+
return [3 /*break*/, 19];
|
|
1285
|
+
case 19:
|
|
1286
|
+
_d = _c.next();
|
|
1287
|
+
return [3 /*break*/, 15];
|
|
1288
|
+
case 20: return [3 /*break*/, 23];
|
|
1289
|
+
case 21:
|
|
1290
|
+
e_2_1 = _o.sent();
|
|
1291
|
+
e_2 = { error: e_2_1 };
|
|
1292
|
+
return [3 /*break*/, 23];
|
|
1293
|
+
case 22:
|
|
1294
|
+
try {
|
|
1295
|
+
if (_d && !_d.done && (_j = _c.return)) _j.call(_c);
|
|
1296
|
+
}
|
|
1297
|
+
finally { if (e_2) throw e_2.error; }
|
|
1298
|
+
return [7 /*endfinally*/];
|
|
1299
|
+
case 23:
|
|
1300
|
+
if (resultString !== null) {
|
|
1301
|
+
return [3 /*break*/, 27];
|
|
1302
|
+
}
|
|
1303
|
+
if (scriptExecutionErrors.length === 1) {
|
|
1304
|
+
throw scriptExecutionErrors[0];
|
|
1305
|
+
}
|
|
1306
|
+
else {
|
|
1307
|
+
throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
|
|
1308
|
+
.map(function (error) { return '- ' + error.message; })
|
|
1309
|
+
.join('\n\n')), "\n "); }));
|
|
1310
|
+
}
|
|
1311
|
+
case 24:
|
|
1312
|
+
if (tools.userInterface === undefined) {
|
|
1313
|
+
throw new PromptbookExecutionError('User interface tools are not available');
|
|
1314
|
+
}
|
|
1315
|
+
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
1316
|
+
promptTitle: currentTemplate.title,
|
|
1317
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parametersToPass),
|
|
1318
|
+
defaultValue: replaceParameters(currentTemplate.content, parametersToPass),
|
|
1319
|
+
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
1320
|
+
placeholder: undefined,
|
|
1321
|
+
priority: priority,
|
|
1322
|
+
})];
|
|
1323
|
+
case 25:
|
|
1324
|
+
// TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
1325
|
+
resultString = _o.sent();
|
|
1326
|
+
return [3 /*break*/, 27];
|
|
1327
|
+
case 26: throw new PromptbookExecutionError(
|
|
1328
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1329
|
+
"Unknown execution type \"".concat(currentTemplate.executionType, "\""));
|
|
1330
|
+
case 27:
|
|
1331
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 44];
|
|
1332
|
+
_o.label = 28;
|
|
1333
|
+
case 28:
|
|
1334
|
+
_o.trys.push([28, 42, 43, 44]);
|
|
1335
|
+
_e = (e_4 = void 0, __values(currentTemplate.postprocessing)), _f = _e.next();
|
|
1336
|
+
_o.label = 29;
|
|
1337
|
+
case 29:
|
|
1338
|
+
if (!!_f.done) return [3 /*break*/, 41];
|
|
1339
|
+
functionName = _f.value;
|
|
1340
|
+
// TODO: DRY [1]
|
|
1341
|
+
scriptExecutionErrors = [];
|
|
1342
|
+
postprocessingError = null;
|
|
1343
|
+
_o.label = 30;
|
|
1344
|
+
case 30:
|
|
1345
|
+
_o.trys.push([30, 37, 38, 39]);
|
|
1346
|
+
_g = (e_3 = void 0, __values(tools.script)), _h = _g.next();
|
|
1347
|
+
_o.label = 31;
|
|
1348
|
+
case 31:
|
|
1349
|
+
if (!!_h.done) return [3 /*break*/, 36];
|
|
1350
|
+
scriptTools = _h.value;
|
|
1351
|
+
_o.label = 32;
|
|
1352
|
+
case 32:
|
|
1353
|
+
_o.trys.push([32, 34, , 35]);
|
|
1354
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
1355
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
1356
|
+
script: "".concat(functionName, "(resultString)"),
|
|
1357
|
+
parameters: {
|
|
1358
|
+
resultString: resultString || '',
|
|
1359
|
+
// Note: No ...parametersToPass, because working with result only
|
|
1360
|
+
},
|
|
1361
|
+
})];
|
|
1362
|
+
case 33:
|
|
1363
|
+
resultString = _o.sent();
|
|
1364
|
+
postprocessingError = null;
|
|
1365
|
+
return [3 /*break*/, 36];
|
|
1366
|
+
case 34:
|
|
1367
|
+
error_3 = _o.sent();
|
|
1368
|
+
if (!(error_3 instanceof Error)) {
|
|
1369
|
+
throw error_3;
|
|
1370
|
+
}
|
|
1371
|
+
postprocessingError = error_3;
|
|
1372
|
+
scriptExecutionErrors.push(error_3);
|
|
1373
|
+
return [3 /*break*/, 35];
|
|
1374
|
+
case 35:
|
|
1375
|
+
_h = _g.next();
|
|
1376
|
+
return [3 /*break*/, 31];
|
|
1377
|
+
case 36: return [3 /*break*/, 39];
|
|
1378
|
+
case 37:
|
|
1379
|
+
e_3_1 = _o.sent();
|
|
1380
|
+
e_3 = { error: e_3_1 };
|
|
1381
|
+
return [3 /*break*/, 39];
|
|
1382
|
+
case 38:
|
|
1383
|
+
try {
|
|
1384
|
+
if (_h && !_h.done && (_l = _g.return)) _l.call(_g);
|
|
1385
|
+
}
|
|
1386
|
+
finally { if (e_3) throw e_3.error; }
|
|
1387
|
+
return [7 /*endfinally*/];
|
|
1388
|
+
case 39:
|
|
1389
|
+
if (postprocessingError) {
|
|
1390
|
+
throw postprocessingError;
|
|
1391
|
+
}
|
|
1392
|
+
_o.label = 40;
|
|
1393
|
+
case 40:
|
|
1394
|
+
_f = _e.next();
|
|
1395
|
+
return [3 /*break*/, 29];
|
|
1396
|
+
case 41: return [3 /*break*/, 44];
|
|
1397
|
+
case 42:
|
|
1398
|
+
e_4_1 = _o.sent();
|
|
1399
|
+
e_4 = { error: e_4_1 };
|
|
1400
|
+
return [3 /*break*/, 44];
|
|
1401
|
+
case 43:
|
|
1402
|
+
try {
|
|
1403
|
+
if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
|
|
1404
|
+
}
|
|
1405
|
+
finally { if (e_4) throw e_4.error; }
|
|
1406
|
+
return [7 /*endfinally*/];
|
|
1407
|
+
case 44:
|
|
1408
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
1409
|
+
if (currentTemplate.expectFormat) {
|
|
1410
|
+
if (currentTemplate.expectFormat === 'JSON') {
|
|
1411
|
+
if (!isValidJsonString(resultString || '')) {
|
|
1412
|
+
throw new ExpectError('Expected valid JSON string');
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
1417
|
+
if (currentTemplate.expectations) {
|
|
1418
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
1419
|
+
}
|
|
1420
|
+
return [3 /*break*/, 49];
|
|
1421
|
+
case 45:
|
|
1422
|
+
error_4 = _o.sent();
|
|
1423
|
+
if (!(error_4 instanceof ExpectError)) {
|
|
1424
|
+
throw error_4;
|
|
1425
|
+
}
|
|
1426
|
+
expectError = error_4;
|
|
1427
|
+
return [3 /*break*/, 47];
|
|
1428
|
+
case 46:
|
|
1429
|
+
if (!isJokerAttempt &&
|
|
1430
|
+
currentTemplate.executionType === 'PROMPT_TEMPLATE' &&
|
|
1431
|
+
prompt
|
|
1432
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
1433
|
+
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
1434
|
+
) {
|
|
1435
|
+
// TODO: [🧠] Maybe put other executionTypes into report
|
|
1436
|
+
executionReport.promptExecutions.push({
|
|
1437
|
+
prompt: {
|
|
1438
|
+
title: currentTemplate.title /* <- Note: If title in promptbook contains emojis, pass it innto report */,
|
|
1439
|
+
content: prompt.content,
|
|
1440
|
+
modelRequirements: prompt.modelRequirements,
|
|
1441
|
+
expectations: prompt.expectations,
|
|
1442
|
+
expectFormat: prompt.expectFormat,
|
|
1443
|
+
// <- Note: Do want to pass ONLY wanted information to the report
|
|
1444
|
+
},
|
|
1445
|
+
result: result || undefined,
|
|
1446
|
+
error: expectError || undefined,
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
return [7 /*endfinally*/];
|
|
1450
|
+
case 47:
|
|
1451
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
1452
|
+
throw new PromptbookExecutionError(spaceTrim.spaceTrim(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 "); }));
|
|
1453
|
+
}
|
|
1454
|
+
_o.label = 48;
|
|
1455
|
+
case 48:
|
|
1456
|
+
attempt++;
|
|
1457
|
+
return [3 /*break*/, 3];
|
|
1458
|
+
case 49:
|
|
1459
|
+
if (resultString === null) {
|
|
1460
|
+
throw new UnexpectedError('Something went wrong and prompt result is null');
|
|
1461
|
+
}
|
|
1462
|
+
if (onProgress /* <- [3] */) {
|
|
1463
|
+
onProgress({
|
|
1464
|
+
name: name,
|
|
1465
|
+
title: title,
|
|
1466
|
+
isStarted: true,
|
|
1467
|
+
isDone: true,
|
|
1468
|
+
executionType: currentTemplate.executionType,
|
|
1469
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
1470
|
+
parameterValue: resultString,
|
|
1471
|
+
// <- [3]
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _m));
|
|
1475
|
+
return [2 /*return*/];
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
var parametersToPass, executionReport, resovedParameters_1, unresovedTemplates, resolving_1, loopLimit, _loop_1, error_1, usage_1, _a, _b, parameter, usage;
|
|
1481
|
+
var e_1, _c;
|
|
1482
|
+
return __generator(this, function (_d) {
|
|
1483
|
+
switch (_d.label) {
|
|
1484
|
+
case 0:
|
|
1485
|
+
parametersToPass = inputParameters;
|
|
1486
|
+
executionReport = {
|
|
1487
|
+
promptbookUrl: promptbook.promptbookUrl,
|
|
1488
|
+
title: promptbook.title,
|
|
1489
|
+
promptbookUsedVersion: PROMPTBOOK_VERSION,
|
|
1490
|
+
promptbookRequestedVersion: promptbook.promptbookVersion,
|
|
1491
|
+
description: promptbook.description,
|
|
1492
|
+
promptExecutions: [],
|
|
1493
|
+
};
|
|
1494
|
+
_d.label = 1;
|
|
1495
|
+
case 1:
|
|
1496
|
+
_d.trys.push([1, 6, , 7]);
|
|
1497
|
+
resovedParameters_1 = promptbook.parameters
|
|
1498
|
+
.filter(function (_a) {
|
|
1499
|
+
var isInput = _a.isInput;
|
|
1500
|
+
return isInput;
|
|
1501
|
+
})
|
|
1502
|
+
.map(function (_a) {
|
|
1503
|
+
var name = _a.name;
|
|
1504
|
+
return name;
|
|
1505
|
+
});
|
|
1506
|
+
unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
1507
|
+
resolving_1 = [];
|
|
1508
|
+
loopLimit = LOOP_LIMIT;
|
|
1509
|
+
_loop_1 = function () {
|
|
1510
|
+
var currentTemplate, work_1;
|
|
1511
|
+
return __generator(this, function (_e) {
|
|
1512
|
+
switch (_e.label) {
|
|
1513
|
+
case 0:
|
|
1514
|
+
if (loopLimit-- < 0) {
|
|
1515
|
+
throw new UnexpectedError('Loop limit reached during resolving parameters promptbook execution');
|
|
1516
|
+
}
|
|
1517
|
+
currentTemplate = unresovedTemplates.find(function (template) {
|
|
1518
|
+
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
1519
|
+
});
|
|
1520
|
+
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
1521
|
+
throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
|
|
1522
|
+
case 1:
|
|
1523
|
+
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
1524
|
+
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
1525
|
+
case 2:
|
|
1526
|
+
/* [5] */ _e.sent();
|
|
1527
|
+
return [3 /*break*/, 4];
|
|
1528
|
+
case 3:
|
|
1529
|
+
unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
|
|
1530
|
+
work_1 = executeSingleTemplate(currentTemplate)
|
|
1531
|
+
.then(function () {
|
|
1532
|
+
resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
|
|
1533
|
+
})
|
|
1534
|
+
.then(function () {
|
|
1535
|
+
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
1536
|
+
});
|
|
1537
|
+
resolving_1.push(work_1);
|
|
1538
|
+
_e.label = 4;
|
|
1539
|
+
case 4: return [2 /*return*/];
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1542
|
+
};
|
|
1543
|
+
_d.label = 2;
|
|
1544
|
+
case 2:
|
|
1545
|
+
if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
|
|
1546
|
+
return [5 /*yield**/, _loop_1()];
|
|
1547
|
+
case 3:
|
|
1548
|
+
_d.sent();
|
|
1549
|
+
return [3 /*break*/, 2];
|
|
1550
|
+
case 4: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
1551
|
+
case 5:
|
|
1552
|
+
_d.sent();
|
|
1553
|
+
return [3 /*break*/, 7];
|
|
1554
|
+
case 6:
|
|
1555
|
+
error_1 = _d.sent();
|
|
1556
|
+
if (!(error_1 instanceof Error)) {
|
|
1557
|
+
throw error_1;
|
|
1558
|
+
}
|
|
1559
|
+
usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1560
|
+
var result = _a.result;
|
|
1561
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1562
|
+
})), false));
|
|
1563
|
+
return [2 /*return*/, {
|
|
1564
|
+
isSuccessful: false,
|
|
1565
|
+
errors: [error_1],
|
|
1566
|
+
usage: usage_1,
|
|
1567
|
+
executionReport: executionReport,
|
|
1568
|
+
outputParameters: parametersToPass,
|
|
1569
|
+
}];
|
|
1570
|
+
case 7:
|
|
1571
|
+
try {
|
|
1572
|
+
// Note: Filter ONLY output parameters
|
|
1573
|
+
for (_a = __values(promptbook.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1574
|
+
parameter = _b.value;
|
|
1575
|
+
if (parameter.isOutput) {
|
|
1576
|
+
continue;
|
|
1577
|
+
}
|
|
1578
|
+
delete parametersToPass[parameter.name];
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1582
|
+
finally {
|
|
1583
|
+
try {
|
|
1584
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1585
|
+
}
|
|
1586
|
+
finally { if (e_1) throw e_1.error; }
|
|
1587
|
+
}
|
|
1588
|
+
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1589
|
+
var result = _a.result;
|
|
1590
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1591
|
+
})), false));
|
|
1592
|
+
return [2 /*return*/, {
|
|
1593
|
+
isSuccessful: true,
|
|
1594
|
+
errors: [],
|
|
1595
|
+
usage: usage,
|
|
1596
|
+
executionReport: executionReport,
|
|
1597
|
+
outputParameters: parametersToPass,
|
|
1598
|
+
}];
|
|
1599
|
+
}
|
|
1600
|
+
});
|
|
1601
|
+
}); };
|
|
1602
|
+
return promptbookExecutor;
|
|
1603
|
+
}
|
|
1604
|
+
/**
|
|
1605
|
+
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
1606
|
+
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
1607
|
+
* Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
|
|
1608
|
+
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
1609
|
+
*/
|
|
1610
|
+
|
|
1611
|
+
/**
|
|
1612
|
+
* Makes first letter of a string uppercase
|
|
1613
|
+
*
|
|
1614
|
+
*/
|
|
1615
|
+
function capitalize(word) {
|
|
1616
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
/**
|
|
1620
|
+
* Converts promptbook in JSON format to string format
|
|
1621
|
+
*
|
|
1622
|
+
* @param promptbookJson Promptbook in JSON format (.ptbk.json)
|
|
1623
|
+
* @returns Promptbook in string format (.ptbk.md)
|
|
1624
|
+
*/
|
|
1625
|
+
function promptbookJsonToString(promptbookJson) {
|
|
1626
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
1627
|
+
var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
|
|
1628
|
+
var promptbookString = "# ".concat(title);
|
|
1629
|
+
if (description) {
|
|
1630
|
+
promptbookString += '\n\n';
|
|
1631
|
+
promptbookString += description;
|
|
1632
|
+
}
|
|
1633
|
+
// TODO:> const commands: Array<Command>
|
|
1634
|
+
var commands = [];
|
|
1635
|
+
if (promptbookUrl) {
|
|
1636
|
+
commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
|
|
1637
|
+
}
|
|
1638
|
+
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
1639
|
+
promptbookString = prettifyMarkdown(promptbookString);
|
|
1640
|
+
try {
|
|
1641
|
+
for (var _g = __values(parameters.filter(function (_a) {
|
|
1642
|
+
var isInput = _a.isInput;
|
|
1643
|
+
return isInput;
|
|
1644
|
+
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1645
|
+
var parameter = _h.value;
|
|
1646
|
+
commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1650
|
+
finally {
|
|
1651
|
+
try {
|
|
1652
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
1653
|
+
}
|
|
1654
|
+
finally { if (e_1) throw e_1.error; }
|
|
1655
|
+
}
|
|
1656
|
+
try {
|
|
1657
|
+
for (var _j = __values(parameters.filter(function (_a) {
|
|
1658
|
+
var isOutput = _a.isOutput;
|
|
1659
|
+
return isOutput;
|
|
1660
|
+
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1661
|
+
var parameter = _k.value;
|
|
1662
|
+
commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1666
|
+
finally {
|
|
1667
|
+
try {
|
|
1668
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
1669
|
+
}
|
|
1670
|
+
finally { if (e_2) throw e_2.error; }
|
|
1671
|
+
}
|
|
1672
|
+
promptbookString += '\n\n';
|
|
1673
|
+
promptbookString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1674
|
+
try {
|
|
1675
|
+
for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
|
|
1676
|
+
var promptTemplate = promptTemplates_1_1.value;
|
|
1677
|
+
var
|
|
1678
|
+
/* Note: Not using:> name, */
|
|
1679
|
+
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
1680
|
+
/* Note: dependentParameterNames, */
|
|
1681
|
+
jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
1682
|
+
promptbookString += '\n\n';
|
|
1683
|
+
promptbookString += "## ".concat(title_1);
|
|
1684
|
+
if (description_1) {
|
|
1685
|
+
promptbookString += '\n\n';
|
|
1686
|
+
promptbookString += description_1;
|
|
1687
|
+
}
|
|
1688
|
+
// TODO:> const commands: Array<Command>
|
|
1689
|
+
var commands_1 = [];
|
|
1690
|
+
var contentLanguage = 'text';
|
|
1691
|
+
if (executionType === 'PROMPT_TEMPLATE') {
|
|
1692
|
+
var modelRequirements = promptTemplate.modelRequirements;
|
|
1693
|
+
var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
|
|
1694
|
+
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
1695
|
+
if (modelVariant) {
|
|
1696
|
+
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
1697
|
+
}
|
|
1698
|
+
if (modelName) {
|
|
1699
|
+
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
else if (executionType === 'SIMPLE_TEMPLATE') {
|
|
1703
|
+
commands_1.push("SIMPLE TEMPLATE");
|
|
1704
|
+
// Note: Nothing special here
|
|
1705
|
+
}
|
|
1706
|
+
else if (executionType === 'SCRIPT') {
|
|
1707
|
+
commands_1.push("EXECUTE SCRIPT");
|
|
1708
|
+
if (promptTemplate.contentLanguage) {
|
|
1709
|
+
contentLanguage = promptTemplate.contentLanguage;
|
|
1710
|
+
}
|
|
1711
|
+
else {
|
|
1712
|
+
contentLanguage = '';
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
else if (executionType === 'PROMPT_DIALOG') {
|
|
1716
|
+
commands_1.push("PROMPT DIALOG");
|
|
1717
|
+
// Note: Nothing special here
|
|
1718
|
+
}
|
|
1719
|
+
if (jokers) {
|
|
1720
|
+
try {
|
|
1721
|
+
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
1722
|
+
var joker = jokers_1_1.value;
|
|
1723
|
+
commands_1.push("JOKER {".concat(joker, "}"));
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1727
|
+
finally {
|
|
1728
|
+
try {
|
|
1729
|
+
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
1730
|
+
}
|
|
1731
|
+
finally { if (e_4) throw e_4.error; }
|
|
1732
|
+
}
|
|
1733
|
+
} /* not else */
|
|
1734
|
+
if (postprocessing) {
|
|
1735
|
+
try {
|
|
1736
|
+
for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
|
|
1737
|
+
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
1738
|
+
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1742
|
+
finally {
|
|
1743
|
+
try {
|
|
1744
|
+
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
1745
|
+
}
|
|
1746
|
+
finally { if (e_5) throw e_5.error; }
|
|
1747
|
+
}
|
|
1748
|
+
} /* not else */
|
|
1749
|
+
if (expectations) {
|
|
1750
|
+
try {
|
|
1751
|
+
for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1752
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
1753
|
+
if (min === max) {
|
|
1754
|
+
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1755
|
+
}
|
|
1756
|
+
else {
|
|
1757
|
+
if (min !== undefined) {
|
|
1758
|
+
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1759
|
+
} /* not else */
|
|
1760
|
+
if (max !== undefined) {
|
|
1761
|
+
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1767
|
+
finally {
|
|
1768
|
+
try {
|
|
1769
|
+
if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
|
|
1770
|
+
}
|
|
1771
|
+
finally { if (e_6) throw e_6.error; }
|
|
1772
|
+
}
|
|
1773
|
+
} /* not else */
|
|
1774
|
+
if (expectFormat) {
|
|
1775
|
+
if (expectFormat === 'JSON') {
|
|
1776
|
+
// TODO: @deprecated remove
|
|
1777
|
+
commands_1.push("EXPECT JSON");
|
|
1778
|
+
}
|
|
1779
|
+
} /* not else */
|
|
1780
|
+
promptbookString += '\n\n';
|
|
1781
|
+
promptbookString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1782
|
+
promptbookString += '\n\n';
|
|
1783
|
+
promptbookString += '```' + contentLanguage;
|
|
1784
|
+
promptbookString += '\n';
|
|
1785
|
+
promptbookString += spaceTrim__default["default"](content);
|
|
1786
|
+
// <- TODO: !!! Escape
|
|
1787
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1788
|
+
promptbookString += '\n';
|
|
1789
|
+
promptbookString += '```';
|
|
1790
|
+
promptbookString += '\n\n';
|
|
1791
|
+
promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1795
|
+
finally {
|
|
1796
|
+
try {
|
|
1797
|
+
if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
|
|
1798
|
+
}
|
|
1799
|
+
finally { if (e_3) throw e_3.error; }
|
|
1800
|
+
}
|
|
1801
|
+
return promptbookString;
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* @private internal util of promptbookJsonToString
|
|
1805
|
+
*/
|
|
1806
|
+
function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
1807
|
+
var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
|
|
1808
|
+
var parameterString = "{".concat(name, "}");
|
|
1809
|
+
if (description) {
|
|
1810
|
+
parameterString = "".concat(parameterString, " ").concat(description);
|
|
1811
|
+
}
|
|
1812
|
+
return parameterString;
|
|
1813
|
+
}
|
|
1814
|
+
/**
|
|
1815
|
+
* TODO: Escape all
|
|
1816
|
+
*/
|
|
1817
|
+
|
|
1818
|
+
/**
|
|
1819
|
+
* This error indicates that promptbook not found in the library
|
|
1820
|
+
*/
|
|
1821
|
+
var PromptbookNotFoundError = /** @class */ (function (_super) {
|
|
1822
|
+
__extends(PromptbookNotFoundError, _super);
|
|
1823
|
+
function PromptbookNotFoundError(message) {
|
|
1824
|
+
var _this = _super.call(this, message) || this;
|
|
1825
|
+
_this.name = 'PromptbookNotFoundError';
|
|
1826
|
+
Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
|
|
1827
|
+
return _this;
|
|
1828
|
+
}
|
|
1829
|
+
return PromptbookNotFoundError;
|
|
1830
|
+
}(Error));
|
|
1831
|
+
|
|
1832
|
+
/**
|
|
1833
|
+
* This error indicates errors in referencing promptbooks between each other
|
|
1834
|
+
*/
|
|
1835
|
+
var PromptbookReferenceError = /** @class */ (function (_super) {
|
|
1836
|
+
__extends(PromptbookReferenceError, _super);
|
|
1837
|
+
function PromptbookReferenceError(message) {
|
|
1838
|
+
var _this = _super.call(this, message) || this;
|
|
1839
|
+
_this.name = 'PromptbookReferenceError';
|
|
1840
|
+
Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
|
|
1841
|
+
return _this;
|
|
1842
|
+
}
|
|
1843
|
+
return PromptbookReferenceError;
|
|
1844
|
+
}(Error));
|
|
1845
|
+
|
|
1846
|
+
/**
|
|
1847
|
+
* Library of promptbooks that groups together promptbooks for an application.
|
|
1848
|
+
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
1849
|
+
*
|
|
1850
|
+
* @see https://github.com/webgptorg/promptbook#promptbook-library
|
|
1851
|
+
*/
|
|
1852
|
+
var SimplePromptbookLibrary = /** @class */ (function () {
|
|
1853
|
+
/**
|
|
1854
|
+
* Constructs a promptbook library from promptbooks
|
|
1855
|
+
*
|
|
1856
|
+
* @param promptbooks !!!
|
|
1857
|
+
*
|
|
1858
|
+
* Note: During the construction logic of all promptbooks are validated
|
|
1859
|
+
* Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
|
|
1860
|
+
*/
|
|
1861
|
+
function SimplePromptbookLibrary() {
|
|
1862
|
+
var e_1, _a;
|
|
1863
|
+
var promptbooks = [];
|
|
1864
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1865
|
+
promptbooks[_i] = arguments[_i];
|
|
1866
|
+
}
|
|
1867
|
+
this.library = new Map();
|
|
1868
|
+
try {
|
|
1869
|
+
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
1870
|
+
var promptbook = promptbooks_1_1.value;
|
|
1871
|
+
if (promptbook.promptbookUrl === undefined) {
|
|
1872
|
+
throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
|
|
1873
|
+
}
|
|
1874
|
+
validatePromptbookJson(promptbook);
|
|
1875
|
+
// Note: [🦄]
|
|
1876
|
+
if (this.library.has(promptbook.promptbookUrl) &&
|
|
1877
|
+
promptbookJsonToString(promptbook) !==
|
|
1878
|
+
promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
|
|
1879
|
+
throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
|
|
1880
|
+
}
|
|
1881
|
+
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1885
|
+
finally {
|
|
1886
|
+
try {
|
|
1887
|
+
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
1888
|
+
}
|
|
1889
|
+
finally { if (e_1) throw e_1.error; }
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Gets all promptbooks in the library
|
|
1894
|
+
*/
|
|
1895
|
+
SimplePromptbookLibrary.prototype.listPromptbooks = function () {
|
|
1896
|
+
return Array.from(this.library.keys());
|
|
1897
|
+
};
|
|
1898
|
+
/**
|
|
1899
|
+
* Gets promptbook by its URL
|
|
1900
|
+
*
|
|
1901
|
+
* Note: This is not a direct fetching from the URL, but a lookup in the library
|
|
1902
|
+
*/
|
|
1903
|
+
SimplePromptbookLibrary.prototype.getPromptbookByUrl = function (url) {
|
|
1904
|
+
var _this = this;
|
|
1905
|
+
var promptbook = this.library.get(url);
|
|
1906
|
+
if (!promptbook) {
|
|
1907
|
+
if (this.listPromptbooks().length === 0) {
|
|
1908
|
+
throw new PromptbookNotFoundError(spaceTrim.spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
1909
|
+
}
|
|
1910
|
+
throw new PromptbookNotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
|
|
1911
|
+
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
1912
|
+
.join('\n')), "\n\n "); }));
|
|
1913
|
+
}
|
|
1914
|
+
return promptbook;
|
|
1915
|
+
};
|
|
1916
|
+
/**
|
|
1917
|
+
* Checks whether given prompt was defined in any promptbook in the library
|
|
1918
|
+
*/
|
|
1919
|
+
SimplePromptbookLibrary.prototype.isResponsibleForPrompt = function (prompt) {
|
|
1920
|
+
return true;
|
|
1921
|
+
};
|
|
1922
|
+
return SimplePromptbookLibrary;
|
|
1923
|
+
}());
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
|
|
1927
|
+
*
|
|
1928
|
+
* Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
|
|
1929
|
+
* Note: During the construction syntax and logic of all sources are validated
|
|
1930
|
+
*
|
|
1931
|
+
* @param promptbookSources
|
|
1932
|
+
* @returns PromptbookLibrary
|
|
1933
|
+
*/
|
|
1934
|
+
function createPromptbookLibraryFromSources() {
|
|
1935
|
+
var promptbookSources = [];
|
|
1936
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1937
|
+
promptbookSources[_i] = arguments[_i];
|
|
1938
|
+
}
|
|
1939
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1940
|
+
var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
|
|
1941
|
+
var e_1, _a;
|
|
1942
|
+
return __generator(this, function (_b) {
|
|
1943
|
+
switch (_b.label) {
|
|
1944
|
+
case 0:
|
|
1945
|
+
promptbooks = new Array();
|
|
1946
|
+
_b.label = 1;
|
|
1947
|
+
case 1:
|
|
1948
|
+
_b.trys.push([1, 8, 9, 10]);
|
|
1949
|
+
promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
|
|
1950
|
+
_b.label = 2;
|
|
1951
|
+
case 2:
|
|
1952
|
+
if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
|
|
1953
|
+
source = promptbookSources_1_1.value;
|
|
1954
|
+
promptbook = void 0;
|
|
1955
|
+
if (!(typeof source === 'string')) return [3 /*break*/, 4];
|
|
1956
|
+
return [4 /*yield*/, promptbookStringToJson(source)];
|
|
1957
|
+
case 3:
|
|
1958
|
+
// Note: When directly creating from string, no need to validate the source
|
|
1959
|
+
// The validation is performed always before execution
|
|
1960
|
+
promptbook = _b.sent();
|
|
1961
|
+
return [3 /*break*/, 5];
|
|
1962
|
+
case 4:
|
|
1963
|
+
promptbook = source;
|
|
1964
|
+
_b.label = 5;
|
|
1965
|
+
case 5:
|
|
1966
|
+
promptbooks.push(promptbook);
|
|
1967
|
+
_b.label = 6;
|
|
1968
|
+
case 6:
|
|
1969
|
+
promptbookSources_1_1 = promptbookSources_1.next();
|
|
1970
|
+
return [3 /*break*/, 2];
|
|
1971
|
+
case 7: return [3 /*break*/, 10];
|
|
1972
|
+
case 8:
|
|
1973
|
+
e_1_1 = _b.sent();
|
|
1974
|
+
e_1 = { error: e_1_1 };
|
|
1975
|
+
return [3 /*break*/, 10];
|
|
1976
|
+
case 9:
|
|
1977
|
+
try {
|
|
1978
|
+
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
1979
|
+
}
|
|
1980
|
+
finally { if (e_1) throw e_1.error; }
|
|
1981
|
+
return [7 /*endfinally*/];
|
|
1982
|
+
case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
|
|
1983
|
+
}
|
|
1984
|
+
});
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
/**
|
|
1988
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
1989
|
+
*/
|
|
1990
|
+
|
|
1991
|
+
/* tslint:disable */
|
|
1992
|
+
function normalizeToKebabCase(sentence) {
|
|
1993
|
+
var e_1, _a;
|
|
1994
|
+
sentence = removeDiacritics(sentence);
|
|
1995
|
+
var charType;
|
|
1996
|
+
var lastCharType = 'OTHER';
|
|
1997
|
+
var normalizedName = '';
|
|
1998
|
+
try {
|
|
1999
|
+
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
2000
|
+
var char = sentence_1_1.value;
|
|
2001
|
+
var normalizedChar = void 0;
|
|
2002
|
+
if (/^[a-z]$/.test(char)) {
|
|
2003
|
+
charType = 'LOWERCASE';
|
|
2004
|
+
normalizedChar = char;
|
|
2005
|
+
}
|
|
2006
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
2007
|
+
charType = 'UPPERCASE';
|
|
2008
|
+
normalizedChar = char.toLowerCase();
|
|
2009
|
+
}
|
|
2010
|
+
else if (/^[0-9]$/.test(char)) {
|
|
2011
|
+
charType = 'NUMBER';
|
|
2012
|
+
normalizedChar = char;
|
|
2013
|
+
}
|
|
2014
|
+
else if (/^\/$/.test(char)) {
|
|
2015
|
+
charType = 'SLASH';
|
|
2016
|
+
normalizedChar = char;
|
|
2017
|
+
}
|
|
2018
|
+
else {
|
|
2019
|
+
charType = 'OTHER';
|
|
2020
|
+
normalizedChar = '-';
|
|
2021
|
+
}
|
|
2022
|
+
if (charType !== lastCharType &&
|
|
2023
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
2024
|
+
!(lastCharType === 'NUMBER') &&
|
|
2025
|
+
!(charType === 'NUMBER')) {
|
|
2026
|
+
normalizedName += '-';
|
|
2027
|
+
}
|
|
2028
|
+
normalizedName += normalizedChar;
|
|
2029
|
+
lastCharType = charType;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2033
|
+
finally {
|
|
2034
|
+
try {
|
|
2035
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
2036
|
+
}
|
|
2037
|
+
finally { if (e_1) throw e_1.error; }
|
|
2038
|
+
}
|
|
2039
|
+
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
2040
|
+
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
2041
|
+
normalizedName = normalizedName.replace(/^-/, '');
|
|
2042
|
+
normalizedName = normalizedName.replace(/-$/, '');
|
|
2043
|
+
return normalizedName;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
function prepareKnowledgeFromMarkdown(options) {
|
|
2047
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2048
|
+
var content, llmTools, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
2049
|
+
var _this = this;
|
|
2050
|
+
return __generator(this, function (_a) {
|
|
2051
|
+
switch (_a.label) {
|
|
2052
|
+
case 0:
|
|
2053
|
+
content = options.content, llmTools = options.llmTools;
|
|
2054
|
+
return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
|
|
2055
|
+
case 1:
|
|
2056
|
+
library = _a.sent();
|
|
2057
|
+
promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
|
|
2058
|
+
executor = createPromptbookExecutor({
|
|
2059
|
+
promptbook: promptbook,
|
|
2060
|
+
tools: {
|
|
2061
|
+
llm: llmTools,
|
|
2062
|
+
script: [
|
|
2063
|
+
/* <- TODO: Allow to just not define script tools */
|
|
2064
|
+
],
|
|
2065
|
+
},
|
|
2066
|
+
});
|
|
2067
|
+
return [4 /*yield*/, executor({ content: content })];
|
|
2068
|
+
case 2:
|
|
2069
|
+
result = _a.sent();
|
|
2070
|
+
assertsExecutionSuccessful(result);
|
|
2071
|
+
outputParameters = result.outputParameters;
|
|
2072
|
+
knowledgeRaw = outputParameters.knowledge;
|
|
2073
|
+
knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
|
|
2074
|
+
return [4 /*yield*/, Promise.all(knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2075
|
+
var name, title, content, keywords, index, sources;
|
|
2076
|
+
return __generator(this, function (_a) {
|
|
2077
|
+
name = "piece-".concat(i);
|
|
2078
|
+
title = spaceTrim__default["default"](knowledgeTextPiece.substring(0, 100));
|
|
2079
|
+
content = spaceTrim__default["default"](knowledgeTextPiece);
|
|
2080
|
+
keywords = [];
|
|
2081
|
+
index = [];
|
|
2082
|
+
sources = [];
|
|
2083
|
+
try {
|
|
2084
|
+
// TODO: !!!! Summarize name and title from the content
|
|
2085
|
+
title = spaceTrim__default["default"](knowledgeTextPiece.substring(0, 30));
|
|
2086
|
+
name = normalizeToKebabCase(title);
|
|
2087
|
+
// TODO: !!!! Extract keywords via prompt
|
|
2088
|
+
// TODO: !!!! Index through LLM model
|
|
2089
|
+
// TODO: [🖖] !!!! Make system for sources and identification of sources
|
|
2090
|
+
}
|
|
2091
|
+
catch (error) {
|
|
2092
|
+
console.error(error);
|
|
2093
|
+
}
|
|
2094
|
+
return [2 /*return*/, {
|
|
2095
|
+
name: name,
|
|
2096
|
+
title: title,
|
|
2097
|
+
content: content,
|
|
2098
|
+
keywords: keywords,
|
|
2099
|
+
index: index,
|
|
2100
|
+
sources: sources,
|
|
2101
|
+
}];
|
|
2102
|
+
});
|
|
2103
|
+
}); }))];
|
|
2104
|
+
case 3:
|
|
2105
|
+
knowledge = _a.sent();
|
|
2106
|
+
return [2 /*return*/, knowledge];
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
/**
|
|
2113
|
+
* Supported script languages
|
|
2114
|
+
*/
|
|
2115
|
+
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
2116
|
+
|
|
2117
|
+
/**
|
|
2118
|
+
* Computes the deepness of the markdown structure.
|
|
2119
|
+
*
|
|
2120
|
+
* @private within the library
|
|
2121
|
+
*/
|
|
2122
|
+
function countMarkdownStructureDeepness(markdownStructure) {
|
|
2123
|
+
var e_1, _a;
|
|
2124
|
+
var maxDeepness = 0;
|
|
2125
|
+
try {
|
|
2126
|
+
for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2127
|
+
var section = _c.value;
|
|
2128
|
+
maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
|
|
776
2129
|
}
|
|
777
|
-
return -number;
|
|
778
|
-
}
|
|
779
|
-
value = value.replace(/,/g, '.');
|
|
780
|
-
value = value.toUpperCase();
|
|
781
|
-
if (value === '') {
|
|
782
|
-
return 0;
|
|
783
2130
|
}
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
789
|
-
var numerator = parseNumber(numerator_);
|
|
790
|
-
var denominator = parseNumber(denominator_);
|
|
791
|
-
if (denominator === 0) {
|
|
792
|
-
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
2131
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2132
|
+
finally {
|
|
2133
|
+
try {
|
|
2134
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
793
2135
|
}
|
|
794
|
-
|
|
795
|
-
}
|
|
796
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
797
|
-
return 0;
|
|
2136
|
+
finally { if (e_1) throw e_1.error; }
|
|
798
2137
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
2138
|
+
return maxDeepness + 1;
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
/**
|
|
2142
|
+
* Parse a markdown string into a MarkdownStructure object.
|
|
2143
|
+
*
|
|
2144
|
+
* Note: This function does work with code blocks
|
|
2145
|
+
* Note: This function does not work with markdown comments
|
|
2146
|
+
*
|
|
2147
|
+
* @param markdown The markdown string to parse.
|
|
2148
|
+
* @returns The MarkdownStructure object.
|
|
2149
|
+
*
|
|
2150
|
+
* @private within the library
|
|
2151
|
+
*/
|
|
2152
|
+
function markdownToMarkdownStructure(markdown) {
|
|
2153
|
+
var e_1, _a;
|
|
2154
|
+
var lines = markdown.split('\n');
|
|
2155
|
+
var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
|
|
2156
|
+
var current = root;
|
|
2157
|
+
var isInsideCodeBlock = false;
|
|
2158
|
+
try {
|
|
2159
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2160
|
+
var line = lines_1_1.value;
|
|
2161
|
+
var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
|
|
2162
|
+
if (isInsideCodeBlock || !headingMatch) {
|
|
2163
|
+
if (line.startsWith('```')) {
|
|
2164
|
+
isInsideCodeBlock = !isInsideCodeBlock;
|
|
2165
|
+
}
|
|
2166
|
+
current.contentLines.push(line);
|
|
2167
|
+
}
|
|
2168
|
+
else {
|
|
2169
|
+
var level = headingMatch.groups.mark.length;
|
|
2170
|
+
var title = headingMatch.groups.title.trim();
|
|
2171
|
+
var parent_1 = void 0;
|
|
2172
|
+
if (level > current.level) {
|
|
2173
|
+
// Note: Going deeper (next section is child of current)
|
|
2174
|
+
parent_1 = current;
|
|
2175
|
+
}
|
|
2176
|
+
else {
|
|
2177
|
+
// Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
|
|
2178
|
+
parent_1 = current;
|
|
2179
|
+
var loopLimit = LOOP_LIMIT;
|
|
2180
|
+
while (parent_1.level !== level - 1) {
|
|
2181
|
+
if (loopLimit-- < 0) {
|
|
2182
|
+
throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
|
|
2183
|
+
}
|
|
2184
|
+
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
2185
|
+
// [🌻]
|
|
2186
|
+
throw new Error(spaceTrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
2187
|
+
}
|
|
2188
|
+
parent_1 = parent_1.parent;
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
|
|
2192
|
+
parent_1.sections.push(section);
|
|
2193
|
+
current = section;
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
802
2196
|
}
|
|
803
|
-
|
|
804
|
-
|
|
2197
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2198
|
+
finally {
|
|
2199
|
+
try {
|
|
2200
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2201
|
+
}
|
|
2202
|
+
finally { if (e_1) throw e_1.error; }
|
|
805
2203
|
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
2204
|
+
if (root.sections.length === 1) {
|
|
2205
|
+
var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
|
|
2206
|
+
return markdownStructure;
|
|
809
2207
|
}
|
|
810
|
-
|
|
2208
|
+
// [🌻]
|
|
2209
|
+
throw new Error('The markdown file must have exactly one top-level section.');
|
|
2210
|
+
// return root;
|
|
811
2211
|
}
|
|
812
2212
|
/**
|
|
813
|
-
*
|
|
2213
|
+
* @private
|
|
814
2214
|
*/
|
|
2215
|
+
function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
2216
|
+
var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
|
|
2217
|
+
return {
|
|
2218
|
+
level: level,
|
|
2219
|
+
title: title,
|
|
2220
|
+
content: spaceTrim.spaceTrim(contentLines.join('\n')),
|
|
2221
|
+
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
2222
|
+
};
|
|
2223
|
+
}
|
|
815
2224
|
|
|
816
2225
|
/**
|
|
817
|
-
*
|
|
2226
|
+
* Utility function to extract all list items from markdown
|
|
818
2227
|
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
2228
|
+
* Note: It works with both ul and ol
|
|
2229
|
+
* Note: It omits list items in code blocks
|
|
2230
|
+
* Note: It flattens nested lists
|
|
2231
|
+
* Note: It can not work with html syntax and comments
|
|
821
2232
|
*
|
|
822
|
-
* @
|
|
2233
|
+
* @param markdown any valid markdown
|
|
2234
|
+
* @returns
|
|
823
2235
|
*/
|
|
824
|
-
function
|
|
2236
|
+
function extractAllListItemsFromMarkdown(markdown) {
|
|
825
2237
|
var e_1, _a;
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
var listItemParts = listItem
|
|
841
|
-
.split(' ')
|
|
842
|
-
.map(function (part) { return part.trim(); })
|
|
843
|
-
.filter(function (item) { return item !== ''; })
|
|
844
|
-
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
845
|
-
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
846
|
-
.map(removeMarkdownFormatting);
|
|
847
|
-
if (type.startsWith('URL') ||
|
|
848
|
-
type.startsWith('PTBK_URL') ||
|
|
849
|
-
type.startsWith('PTBKURL') ||
|
|
850
|
-
type.startsWith('PROMPTBOOK_URL') ||
|
|
851
|
-
type.startsWith('PROMPTBOOKURL') ||
|
|
852
|
-
type.startsWith('HTTPS')) {
|
|
853
|
-
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
854
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
855
|
-
}
|
|
856
|
-
var promptbookUrlString = listItemParts.pop();
|
|
857
|
-
var promptbookUrl = new URL(promptbookUrlString);
|
|
858
|
-
if (promptbookUrl.protocol !== 'https:') {
|
|
859
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
860
|
-
}
|
|
861
|
-
if (promptbookUrl.hash !== '') {
|
|
862
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
|
|
863
|
-
}
|
|
864
|
-
return {
|
|
865
|
-
type: 'PROMPTBOOK_URL',
|
|
866
|
-
promptbookUrl: promptbookUrl,
|
|
867
|
-
};
|
|
868
|
-
}
|
|
869
|
-
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
870
|
-
if (listItemParts.length !== 2) {
|
|
871
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
2238
|
+
var lines = markdown.split('\n');
|
|
2239
|
+
var listItems = [];
|
|
2240
|
+
var isInCodeBlock = false;
|
|
2241
|
+
try {
|
|
2242
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2243
|
+
var line = lines_1_1.value;
|
|
2244
|
+
var trimmedLine = line.trim();
|
|
2245
|
+
if (trimmedLine.startsWith('```')) {
|
|
2246
|
+
isInCodeBlock = !isInCodeBlock;
|
|
2247
|
+
}
|
|
2248
|
+
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
2249
|
+
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
2250
|
+
listItems.push(listItem);
|
|
2251
|
+
}
|
|
872
2252
|
}
|
|
873
|
-
var promptbookVersion = listItemParts.pop();
|
|
874
|
-
// TODO: Validate version
|
|
875
|
-
return {
|
|
876
|
-
type: 'PROMPTBOOK_VERSION',
|
|
877
|
-
promptbookVersion: promptbookVersion,
|
|
878
|
-
};
|
|
879
2253
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
885
|
-
if (executionTypes.length !== 1) {
|
|
886
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
|
|
2254
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2255
|
+
finally {
|
|
2256
|
+
try {
|
|
2257
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
887
2258
|
}
|
|
888
|
-
|
|
889
|
-
type: 'EXECUTE',
|
|
890
|
-
executionType: executionTypes[0],
|
|
891
|
-
};
|
|
2259
|
+
finally { if (e_1) throw e_1.error; }
|
|
892
2260
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
2261
|
+
return listItems;
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
/**
|
|
2265
|
+
* Extracts all code blocks from markdown.
|
|
2266
|
+
*
|
|
2267
|
+
* Note: There are 3 simmilar function:
|
|
2268
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2269
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2270
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2271
|
+
*
|
|
2272
|
+
* @param markdown any valid markdown
|
|
2273
|
+
* @returns code blocks with language and content
|
|
2274
|
+
*
|
|
2275
|
+
*/
|
|
2276
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
2277
|
+
var e_1, _a;
|
|
2278
|
+
var codeBlocks = [];
|
|
2279
|
+
var lines = markdown.split('\n');
|
|
2280
|
+
var currentCodeBlock = null;
|
|
2281
|
+
try {
|
|
2282
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2283
|
+
var line = lines_1_1.value;
|
|
2284
|
+
if (line.startsWith('```')) {
|
|
2285
|
+
var language = line.slice(3).trim() || null;
|
|
2286
|
+
if (currentCodeBlock === null) {
|
|
2287
|
+
currentCodeBlock = { language: language, content: '' };
|
|
2288
|
+
}
|
|
2289
|
+
else {
|
|
2290
|
+
if (language !== null) {
|
|
2291
|
+
// [🌻]
|
|
2292
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2293
|
+
}
|
|
2294
|
+
codeBlocks.push(currentCodeBlock);
|
|
2295
|
+
currentCodeBlock = null;
|
|
2296
|
+
}
|
|
909
2297
|
}
|
|
910
|
-
else {
|
|
911
|
-
|
|
2298
|
+
else if (currentCodeBlock !== null) {
|
|
2299
|
+
if (currentCodeBlock.content !== '') {
|
|
2300
|
+
currentCodeBlock.content += '\n';
|
|
2301
|
+
}
|
|
2302
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
912
2303
|
}
|
|
913
2304
|
}
|
|
914
|
-
if (type.startsWith('MODEL_NAME')) {
|
|
915
|
-
return {
|
|
916
|
-
type: 'MODEL',
|
|
917
|
-
key: 'modelName',
|
|
918
|
-
value: listItemParts.pop(),
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
else {
|
|
922
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
923
|
-
}
|
|
924
2305
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
930
|
-
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
931
|
-
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
932
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
933
|
-
}
|
|
934
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
935
|
-
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
936
|
-
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
937
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
938
|
-
}
|
|
939
|
-
var isInput = type.startsWith('INPUT');
|
|
940
|
-
var isOutput = type.startsWith('OUTPUT');
|
|
941
|
-
if (listItem.startsWith('> {')) {
|
|
942
|
-
isInput = false;
|
|
943
|
-
isOutput = false;
|
|
2306
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2307
|
+
finally {
|
|
2308
|
+
try {
|
|
2309
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
944
2310
|
}
|
|
945
|
-
|
|
946
|
-
type: 'PARAMETER',
|
|
947
|
-
parameterName: parameterName,
|
|
948
|
-
parameterDescription: parameterDescription.trim() || null,
|
|
949
|
-
isInput: isInput,
|
|
950
|
-
isOutput: isOutput,
|
|
951
|
-
};
|
|
2311
|
+
finally { if (e_1) throw e_1.error; }
|
|
952
2312
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
}
|
|
957
|
-
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
958
|
-
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
959
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
960
|
-
}
|
|
961
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
962
|
-
var parameterName = parametersMatch.groups.parameterName;
|
|
963
|
-
return {
|
|
964
|
-
type: 'JOKER',
|
|
965
|
-
parameterName: parameterName,
|
|
966
|
-
};
|
|
2313
|
+
if (currentCodeBlock !== null) {
|
|
2314
|
+
// [🌻]
|
|
2315
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
967
2316
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
2317
|
+
return codeBlocks;
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
/**
|
|
2321
|
+
* Extracts exactly ONE code block from markdown.
|
|
2322
|
+
*
|
|
2323
|
+
* Note: If there are multiple or no code blocks the function throws an error
|
|
2324
|
+
*
|
|
2325
|
+
* Note: There are 3 simmilar function:
|
|
2326
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2327
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2328
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2329
|
+
*
|
|
2330
|
+
* @param markdown any valid markdown
|
|
2331
|
+
* @returns code block with language and content
|
|
2332
|
+
*/
|
|
2333
|
+
function extractOneBlockFromMarkdown(markdown) {
|
|
2334
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2335
|
+
if (codeBlocks.length !== 1) {
|
|
2336
|
+
// TODO: Report more specific place where the error happened
|
|
2337
|
+
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
977
2338
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
2339
|
+
return codeBlocks[0];
|
|
2340
|
+
}
|
|
2341
|
+
/***
|
|
2342
|
+
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
2343
|
+
*/
|
|
2344
|
+
|
|
2345
|
+
/**
|
|
2346
|
+
* Creates a new set with all elements that are present in either set
|
|
2347
|
+
*/
|
|
2348
|
+
function union() {
|
|
2349
|
+
var e_1, _a, e_2, _b;
|
|
2350
|
+
var sets = [];
|
|
2351
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2352
|
+
sets[_i] = arguments[_i];
|
|
984
2353
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
var
|
|
989
|
-
var signRaw = listItemParts.shift();
|
|
990
|
-
if (/^exact/i.test(signRaw)) {
|
|
991
|
-
sign = 'EXACTLY';
|
|
992
|
-
}
|
|
993
|
-
else if (/^min/i.test(signRaw)) {
|
|
994
|
-
sign = 'MINIMUM';
|
|
995
|
-
}
|
|
996
|
-
else if (/^max/i.test(signRaw)) {
|
|
997
|
-
sign = 'MAXIMUM';
|
|
998
|
-
}
|
|
999
|
-
else {
|
|
1000
|
-
throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
|
|
1001
|
-
}
|
|
1002
|
-
var amountRaw = listItemParts.shift();
|
|
1003
|
-
var amount = parseNumber(amountRaw);
|
|
1004
|
-
if (amount < 0) {
|
|
1005
|
-
throw new PromptbookSyntaxError('Amount must be positive number or zero');
|
|
1006
|
-
}
|
|
1007
|
-
if (amount !== Math.floor(amount)) {
|
|
1008
|
-
throw new PromptbookSyntaxError('Amount must be whole number');
|
|
1009
|
-
}
|
|
1010
|
-
var unitRaw = listItemParts.shift();
|
|
1011
|
-
var unit = undefined;
|
|
2354
|
+
var union = new Set();
|
|
2355
|
+
try {
|
|
2356
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2357
|
+
var set = sets_1_1.value;
|
|
1012
2358
|
try {
|
|
1013
|
-
for (var
|
|
1014
|
-
var
|
|
1015
|
-
|
|
1016
|
-
existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
|
|
1017
|
-
if (existingUnitText === 'CHARACTER') {
|
|
1018
|
-
existingUnitText = 'CHAR';
|
|
1019
|
-
}
|
|
1020
|
-
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
1021
|
-
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
1022
|
-
if (unit !== undefined) {
|
|
1023
|
-
throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
1024
|
-
}
|
|
1025
|
-
unit = existingUnit;
|
|
1026
|
-
}
|
|
2359
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2360
|
+
var item = _d.value;
|
|
2361
|
+
union.add(item);
|
|
1027
2362
|
}
|
|
1028
2363
|
}
|
|
1029
|
-
catch (
|
|
2364
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1030
2365
|
finally {
|
|
1031
2366
|
try {
|
|
1032
|
-
if (
|
|
2367
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1033
2368
|
}
|
|
1034
|
-
finally { if (
|
|
1035
|
-
}
|
|
1036
|
-
if (unit === undefined) {
|
|
1037
|
-
throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
|
|
2369
|
+
finally { if (e_2) throw e_2.error; }
|
|
1038
2370
|
}
|
|
1039
|
-
return {
|
|
1040
|
-
type: 'EXPECT_AMOUNT',
|
|
1041
|
-
sign: sign,
|
|
1042
|
-
unit: unit,
|
|
1043
|
-
amount: amount,
|
|
1044
|
-
};
|
|
1045
2371
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
2372
|
+
}
|
|
2373
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2374
|
+
finally {
|
|
2375
|
+
try {
|
|
2376
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
1051
2377
|
}
|
|
1052
|
-
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
|
|
2378
|
+
finally { if (e_1) throw e_1.error; }
|
|
2379
|
+
}
|
|
2380
|
+
return union;
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
/**
|
|
2384
|
+
* Parses the template and returns the list of all parameter names
|
|
2385
|
+
*
|
|
2386
|
+
* @param template the template with parameters in {curly} braces
|
|
2387
|
+
* @returns the list of parameter names
|
|
2388
|
+
*/
|
|
2389
|
+
function extractParameters(template) {
|
|
2390
|
+
var e_1, _a;
|
|
2391
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
2392
|
+
var parameterNames = new Set();
|
|
2393
|
+
try {
|
|
2394
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
2395
|
+
var match = matches_1_1.value;
|
|
2396
|
+
var parameterName = match[0].slice(1, -1);
|
|
2397
|
+
parameterNames.add(parameterName);
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2401
|
+
finally {
|
|
2402
|
+
try {
|
|
2403
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
2404
|
+
}
|
|
2405
|
+
finally { if (e_1) throw e_1.error; }
|
|
2406
|
+
}
|
|
2407
|
+
return parameterNames;
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
/**
|
|
2411
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
2412
|
+
*
|
|
2413
|
+
* @param script from which to extract the variables
|
|
2414
|
+
* @returns the list of variable names
|
|
2415
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
2416
|
+
*/
|
|
2417
|
+
function extractVariables(script) {
|
|
2418
|
+
var variables = new Set();
|
|
2419
|
+
script = "(()=>{".concat(script, "})()");
|
|
2420
|
+
try {
|
|
2421
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2422
|
+
try {
|
|
2423
|
+
eval(script);
|
|
2424
|
+
}
|
|
2425
|
+
catch (error) {
|
|
2426
|
+
if (!(error instanceof ReferenceError)) {
|
|
2427
|
+
throw error;
|
|
2428
|
+
}
|
|
2429
|
+
var undefinedName = error.message.split(' ')[0];
|
|
2430
|
+
/*
|
|
2431
|
+
Note: Remapping error
|
|
2432
|
+
From: [ReferenceError: thing is not defined],
|
|
2433
|
+
To: [Error: Parameter {thing} is not defined],
|
|
2434
|
+
*/
|
|
2435
|
+
if (!undefinedName) {
|
|
2436
|
+
throw error;
|
|
2437
|
+
}
|
|
2438
|
+
if (script.includes(undefinedName + '(')) {
|
|
2439
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2440
|
+
}
|
|
2441
|
+
else {
|
|
2442
|
+
variables.add(undefinedName);
|
|
2443
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
1056
2446
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
2447
|
+
catch (error) {
|
|
2448
|
+
if (!(error instanceof Error)) {
|
|
2449
|
+
throw error;
|
|
2450
|
+
}
|
|
2451
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
1059
2452
|
}
|
|
2453
|
+
return variables;
|
|
1060
2454
|
}
|
|
2455
|
+
/**
|
|
2456
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
2457
|
+
*/
|
|
1061
2458
|
|
|
1062
|
-
var defaultDiacriticsRemovalMap = [
|
|
1063
|
-
{
|
|
1064
|
-
base: 'A',
|
|
1065
|
-
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
1066
|
-
},
|
|
1067
|
-
{ base: 'AA', letters: '\uA732' },
|
|
1068
|
-
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
1069
|
-
{ base: 'AO', letters: '\uA734' },
|
|
1070
|
-
{ base: 'AU', letters: '\uA736' },
|
|
1071
|
-
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
1072
|
-
{ base: 'AY', letters: '\uA73C' },
|
|
1073
|
-
{
|
|
1074
|
-
base: 'B',
|
|
1075
|
-
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
1076
|
-
},
|
|
1077
|
-
{
|
|
1078
|
-
base: 'C',
|
|
1079
|
-
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
1080
|
-
},
|
|
1081
|
-
{
|
|
1082
|
-
base: 'D',
|
|
1083
|
-
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
1084
|
-
},
|
|
1085
|
-
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
1086
|
-
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
1087
|
-
{
|
|
1088
|
-
base: 'E',
|
|
1089
|
-
letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
|
|
1090
|
-
},
|
|
1091
|
-
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
1092
|
-
{
|
|
1093
|
-
base: 'G',
|
|
1094
|
-
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
1095
|
-
},
|
|
1096
|
-
{
|
|
1097
|
-
base: 'H',
|
|
1098
|
-
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
1099
|
-
},
|
|
1100
|
-
{
|
|
1101
|
-
base: 'I',
|
|
1102
|
-
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
1103
|
-
},
|
|
1104
|
-
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
1105
|
-
{
|
|
1106
|
-
base: 'K',
|
|
1107
|
-
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
1108
|
-
},
|
|
1109
|
-
{
|
|
1110
|
-
base: 'L',
|
|
1111
|
-
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
1112
|
-
},
|
|
1113
|
-
{ base: 'LJ', letters: '\u01C7' },
|
|
1114
|
-
{ base: 'Lj', letters: '\u01C8' },
|
|
1115
|
-
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
1116
|
-
{
|
|
1117
|
-
base: 'N',
|
|
1118
|
-
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
1119
|
-
},
|
|
1120
|
-
{ base: 'NJ', letters: '\u01CA' },
|
|
1121
|
-
{ base: 'Nj', letters: '\u01CB' },
|
|
1122
|
-
{
|
|
1123
|
-
base: 'O',
|
|
1124
|
-
letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
|
|
1125
|
-
},
|
|
1126
|
-
{ base: 'OI', letters: '\u01A2' },
|
|
1127
|
-
{ base: 'OO', letters: '\uA74E' },
|
|
1128
|
-
{ base: 'OU', letters: '\u0222' },
|
|
1129
|
-
{ base: 'OE', letters: '\u008C\u0152' },
|
|
1130
|
-
{ base: 'oe', letters: '\u009C\u0153' },
|
|
1131
|
-
{
|
|
1132
|
-
base: 'P',
|
|
1133
|
-
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
1134
|
-
},
|
|
1135
|
-
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
1136
|
-
{
|
|
1137
|
-
base: 'R',
|
|
1138
|
-
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
1139
|
-
},
|
|
1140
|
-
{
|
|
1141
|
-
base: 'S',
|
|
1142
|
-
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
1143
|
-
},
|
|
1144
|
-
{
|
|
1145
|
-
base: 'T',
|
|
1146
|
-
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
1147
|
-
},
|
|
1148
|
-
{ base: 'TZ', letters: '\uA728' },
|
|
1149
|
-
{
|
|
1150
|
-
base: 'U',
|
|
1151
|
-
letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
|
|
1152
|
-
},
|
|
1153
|
-
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
1154
|
-
{ base: 'VY', letters: '\uA760' },
|
|
1155
|
-
{
|
|
1156
|
-
base: 'W',
|
|
1157
|
-
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
1158
|
-
},
|
|
1159
|
-
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
1160
|
-
{
|
|
1161
|
-
base: 'Y',
|
|
1162
|
-
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
1163
|
-
},
|
|
1164
|
-
{
|
|
1165
|
-
base: 'Z',
|
|
1166
|
-
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
1167
|
-
},
|
|
1168
|
-
{
|
|
1169
|
-
base: 'a',
|
|
1170
|
-
letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
|
|
1171
|
-
},
|
|
1172
|
-
{ base: 'aa', letters: '\uA733' },
|
|
1173
|
-
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
1174
|
-
{ base: 'ao', letters: '\uA735' },
|
|
1175
|
-
{ base: 'au', letters: '\uA737' },
|
|
1176
|
-
{ base: 'av', letters: '\uA739\uA73B' },
|
|
1177
|
-
{ base: 'ay', letters: '\uA73D' },
|
|
1178
|
-
{
|
|
1179
|
-
base: 'b',
|
|
1180
|
-
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
1181
|
-
},
|
|
1182
|
-
{
|
|
1183
|
-
base: 'c',
|
|
1184
|
-
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
1185
|
-
},
|
|
1186
|
-
{
|
|
1187
|
-
base: 'd',
|
|
1188
|
-
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
1189
|
-
},
|
|
1190
|
-
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
1191
|
-
{
|
|
1192
|
-
base: 'e',
|
|
1193
|
-
letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
|
|
1194
|
-
},
|
|
1195
|
-
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
1196
|
-
{
|
|
1197
|
-
base: 'g',
|
|
1198
|
-
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
1199
|
-
},
|
|
1200
|
-
{
|
|
1201
|
-
base: 'h',
|
|
1202
|
-
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
1203
|
-
},
|
|
1204
|
-
{ base: 'hv', letters: '\u0195' },
|
|
1205
|
-
{
|
|
1206
|
-
base: 'i',
|
|
1207
|
-
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
1208
|
-
},
|
|
1209
|
-
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
1210
|
-
{
|
|
1211
|
-
base: 'k',
|
|
1212
|
-
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
1213
|
-
},
|
|
1214
|
-
{
|
|
1215
|
-
base: 'l',
|
|
1216
|
-
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
1217
|
-
},
|
|
1218
|
-
{ base: 'lj', letters: '\u01C9' },
|
|
1219
|
-
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
1220
|
-
{
|
|
1221
|
-
base: 'n',
|
|
1222
|
-
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
1223
|
-
},
|
|
1224
|
-
{ base: 'nj', letters: '\u01CC' },
|
|
1225
|
-
{
|
|
1226
|
-
base: 'o',
|
|
1227
|
-
letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
|
|
1228
|
-
},
|
|
1229
|
-
{ base: 'oi', letters: '\u01A3' },
|
|
1230
|
-
{ base: 'ou', letters: '\u0223' },
|
|
1231
|
-
{ base: 'oo', letters: '\uA74F' },
|
|
1232
|
-
{
|
|
1233
|
-
base: 'p',
|
|
1234
|
-
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
1235
|
-
},
|
|
1236
|
-
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
1237
|
-
{
|
|
1238
|
-
base: 'r',
|
|
1239
|
-
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
1240
|
-
},
|
|
1241
|
-
{
|
|
1242
|
-
base: 's',
|
|
1243
|
-
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
1244
|
-
},
|
|
1245
|
-
{
|
|
1246
|
-
base: 't',
|
|
1247
|
-
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
1248
|
-
},
|
|
1249
|
-
{ base: 'tz', letters: '\uA729' },
|
|
1250
|
-
{
|
|
1251
|
-
base: 'u',
|
|
1252
|
-
letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
|
|
1253
|
-
},
|
|
1254
|
-
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
1255
|
-
{ base: 'vy', letters: '\uA761' },
|
|
1256
|
-
{
|
|
1257
|
-
base: 'w',
|
|
1258
|
-
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
1259
|
-
},
|
|
1260
|
-
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
1261
|
-
{
|
|
1262
|
-
base: 'y',
|
|
1263
|
-
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
1264
|
-
},
|
|
1265
|
-
{
|
|
1266
|
-
base: 'z',
|
|
1267
|
-
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
1268
|
-
},
|
|
1269
|
-
];
|
|
1270
2459
|
/**
|
|
1271
|
-
*
|
|
1272
|
-
* Contains lowercase and uppercase separatelly
|
|
2460
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
1273
2461
|
*
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
* > ...
|
|
2462
|
+
* @param promptTemplate the template with used parameters
|
|
2463
|
+
* @returns the set of parameter names
|
|
2464
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
1278
2465
|
*/
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
2466
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
2467
|
+
var e_1, _a, e_2, _b;
|
|
2468
|
+
var parameterNames = new Set();
|
|
2469
|
+
try {
|
|
2470
|
+
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()) {
|
|
2471
|
+
var parameterName = _d.value;
|
|
2472
|
+
parameterNames.add(parameterName);
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2476
|
+
finally {
|
|
2477
|
+
try {
|
|
2478
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
2479
|
+
}
|
|
2480
|
+
finally { if (e_1) throw e_1.error; }
|
|
2481
|
+
}
|
|
2482
|
+
if (promptTemplate.executionType === 'SCRIPT') {
|
|
2483
|
+
try {
|
|
2484
|
+
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
2485
|
+
var parameterName = _f.value;
|
|
2486
|
+
parameterNames.add(parameterName);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2490
|
+
finally {
|
|
2491
|
+
try {
|
|
2492
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
2493
|
+
}
|
|
2494
|
+
finally { if (e_2) throw e_2.error; }
|
|
2495
|
+
}
|
|
1286
2496
|
}
|
|
2497
|
+
return parameterNames;
|
|
1287
2498
|
}
|
|
1288
|
-
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
1289
|
-
/*
|
|
1290
|
-
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
1291
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
1292
|
-
you may not use this file except in compliance with the License.
|
|
1293
|
-
You may obtain a copy of the License at
|
|
1294
|
-
|
|
1295
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
1296
|
-
|
|
1297
|
-
Unless required by applicable law or agreed to in writing, software
|
|
1298
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
1299
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1300
|
-
See the License for the specific language governing permissions and
|
|
1301
|
-
limitations under the License.
|
|
1302
|
-
*/
|
|
1303
|
-
|
|
1304
2499
|
/**
|
|
1305
|
-
*
|
|
2500
|
+
* TODO: [🔣] If script require contentLanguage
|
|
1306
2501
|
*/
|
|
1307
|
-
function removeDiacritics(input) {
|
|
1308
|
-
/*eslint no-control-regex: "off"*/
|
|
1309
|
-
return input.replace(/[^\u0000-\u007E]/g, function (a) {
|
|
1310
|
-
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
2502
|
|
|
1314
2503
|
/* tslint:disable */
|
|
1315
|
-
|
|
2504
|
+
/*
|
|
2505
|
+
TODO: Tests
|
|
2506
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
2507
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
2508
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
2509
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
2510
|
+
*/
|
|
2511
|
+
function normalizeTo_SCREAMING_CASE(sentence) {
|
|
1316
2512
|
var e_1, _a;
|
|
1317
|
-
sentence = removeDiacritics(sentence);
|
|
1318
2513
|
var charType;
|
|
1319
2514
|
var lastCharType = 'OTHER';
|
|
1320
2515
|
var normalizedName = '';
|
|
@@ -1324,46 +2519,401 @@
|
|
|
1324
2519
|
var normalizedChar = void 0;
|
|
1325
2520
|
if (/^[a-z]$/.test(char)) {
|
|
1326
2521
|
charType = 'LOWERCASE';
|
|
2522
|
+
normalizedChar = char.toUpperCase();
|
|
2523
|
+
}
|
|
2524
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
2525
|
+
charType = 'UPPERCASE';
|
|
2526
|
+
normalizedChar = char;
|
|
2527
|
+
}
|
|
2528
|
+
else if (/^[0-9]$/.test(char)) {
|
|
2529
|
+
charType = 'NUMBER';
|
|
2530
|
+
normalizedChar = char;
|
|
2531
|
+
}
|
|
2532
|
+
else if (/^\/$/.test(char)) {
|
|
2533
|
+
charType = 'SLASH';
|
|
1327
2534
|
normalizedChar = char;
|
|
1328
2535
|
}
|
|
1329
|
-
else
|
|
1330
|
-
charType = '
|
|
1331
|
-
normalizedChar =
|
|
2536
|
+
else {
|
|
2537
|
+
charType = 'OTHER';
|
|
2538
|
+
normalizedChar = '_';
|
|
2539
|
+
}
|
|
2540
|
+
if (charType !== lastCharType &&
|
|
2541
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
2542
|
+
!(lastCharType === 'NUMBER') &&
|
|
2543
|
+
!(charType === 'NUMBER')) {
|
|
2544
|
+
normalizedName += '_';
|
|
2545
|
+
}
|
|
2546
|
+
normalizedName += normalizedChar;
|
|
2547
|
+
lastCharType = charType;
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2551
|
+
finally {
|
|
2552
|
+
try {
|
|
2553
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
2554
|
+
}
|
|
2555
|
+
finally { if (e_1) throw e_1.error; }
|
|
2556
|
+
}
|
|
2557
|
+
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
2558
|
+
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
2559
|
+
normalizedName = normalizedName.replace(/^_/, '');
|
|
2560
|
+
normalizedName = normalizedName.replace(/_$/, '');
|
|
2561
|
+
return normalizedName;
|
|
2562
|
+
}
|
|
2563
|
+
/**
|
|
2564
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
2565
|
+
*/
|
|
2566
|
+
|
|
2567
|
+
/**
|
|
2568
|
+
* Execution type describes the way how the block is executed
|
|
2569
|
+
*
|
|
2570
|
+
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
2571
|
+
*/
|
|
2572
|
+
var ExecutionTypes = [
|
|
2573
|
+
'PROMPT_TEMPLATE',
|
|
2574
|
+
'SIMPLE_TEMPLATE',
|
|
2575
|
+
'SCRIPT',
|
|
2576
|
+
'PROMPT_DIALOG',
|
|
2577
|
+
// <- [🥻] Insert here when making new command
|
|
2578
|
+
];
|
|
2579
|
+
|
|
2580
|
+
/**
|
|
2581
|
+
* Units of text measurement
|
|
2582
|
+
*/
|
|
2583
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2584
|
+
/**
|
|
2585
|
+
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
2586
|
+
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
2587
|
+
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
2588
|
+
*/
|
|
2589
|
+
|
|
2590
|
+
/**
|
|
2591
|
+
* Removes Markdown formatting tags from a string.
|
|
2592
|
+
*
|
|
2593
|
+
* @param {string} str - The string to remove Markdown tags from.
|
|
2594
|
+
* @returns {string} The input string with all Markdown tags removed.
|
|
2595
|
+
*/
|
|
2596
|
+
function removeMarkdownFormatting(str) {
|
|
2597
|
+
// Remove bold formatting
|
|
2598
|
+
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
2599
|
+
// Remove italic formatting
|
|
2600
|
+
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
2601
|
+
// Remove code formatting
|
|
2602
|
+
str = str.replace(/`(.*?)`/g, '$1');
|
|
2603
|
+
return str;
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
/**
|
|
2607
|
+
* Function parseNumber will parse number from string
|
|
2608
|
+
*
|
|
2609
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
2610
|
+
* Note: it also works only with decimal numbers
|
|
2611
|
+
*
|
|
2612
|
+
* @returns parsed number
|
|
2613
|
+
* @throws {PromptbookSyntaxError} if the value is not a number
|
|
2614
|
+
*
|
|
2615
|
+
* @private within the parseCommand
|
|
2616
|
+
*/
|
|
2617
|
+
function parseNumber(value) {
|
|
2618
|
+
var originalValue = value;
|
|
2619
|
+
if (typeof value === 'number') {
|
|
2620
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
2621
|
+
}
|
|
2622
|
+
if (typeof value !== 'string') {
|
|
2623
|
+
return 0;
|
|
2624
|
+
}
|
|
2625
|
+
value = value.trim();
|
|
2626
|
+
if (value.startsWith('+')) {
|
|
2627
|
+
return parseNumber(value.substring(1));
|
|
2628
|
+
}
|
|
2629
|
+
if (value.startsWith('-')) {
|
|
2630
|
+
var number = parseNumber(value.substring(1));
|
|
2631
|
+
if (number === 0) {
|
|
2632
|
+
return 0; // <- Note: To prevent -0
|
|
2633
|
+
}
|
|
2634
|
+
return -number;
|
|
2635
|
+
}
|
|
2636
|
+
value = value.replace(/,/g, '.');
|
|
2637
|
+
value = value.toUpperCase();
|
|
2638
|
+
if (value === '') {
|
|
2639
|
+
return 0;
|
|
2640
|
+
}
|
|
2641
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
2642
|
+
return Infinity;
|
|
2643
|
+
}
|
|
2644
|
+
if (value.includes('/')) {
|
|
2645
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
2646
|
+
var numerator = parseNumber(numerator_);
|
|
2647
|
+
var denominator = parseNumber(denominator_);
|
|
2648
|
+
if (denominator === 0) {
|
|
2649
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
2650
|
+
}
|
|
2651
|
+
return numerator / denominator;
|
|
2652
|
+
}
|
|
2653
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
2654
|
+
return 0;
|
|
2655
|
+
}
|
|
2656
|
+
if (value.includes('E')) {
|
|
2657
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
2658
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
2659
|
+
}
|
|
2660
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
2661
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
2662
|
+
}
|
|
2663
|
+
var num = parseFloat(value);
|
|
2664
|
+
if (isNaN(num)) {
|
|
2665
|
+
throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
2666
|
+
}
|
|
2667
|
+
return num;
|
|
2668
|
+
}
|
|
2669
|
+
/**
|
|
2670
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
2671
|
+
*/
|
|
2672
|
+
|
|
2673
|
+
/**
|
|
2674
|
+
* Parses one line of ul/ol to command
|
|
2675
|
+
*
|
|
2676
|
+
* @returns parsed command object
|
|
2677
|
+
* @throws {PromptbookSyntaxError} if the command is invalid
|
|
2678
|
+
*
|
|
2679
|
+
* @private within the promptbookStringToJson
|
|
2680
|
+
*/
|
|
2681
|
+
function parseCommand(listItem) {
|
|
2682
|
+
var e_1, _a;
|
|
2683
|
+
if (listItem.includes('\n') || listItem.includes('\r')) {
|
|
2684
|
+
throw new PromptbookSyntaxError('Command can not contain new line characters:');
|
|
2685
|
+
}
|
|
2686
|
+
var type = listItem.trim();
|
|
2687
|
+
type = type.split('`').join('');
|
|
2688
|
+
type = type.split('"').join('');
|
|
2689
|
+
type = type.split("'").join('');
|
|
2690
|
+
type = type.split('~').join('');
|
|
2691
|
+
type = type.split('[').join('');
|
|
2692
|
+
type = type.split(']').join('');
|
|
2693
|
+
type = type.split('(').join('');
|
|
2694
|
+
type = type.split(')').join('');
|
|
2695
|
+
type = normalizeTo_SCREAMING_CASE(type);
|
|
2696
|
+
type = type.split('DIALOGUE').join('DIALOG');
|
|
2697
|
+
var listItemParts = listItem
|
|
2698
|
+
.split(' ')
|
|
2699
|
+
.map(function (part) { return part.trim(); })
|
|
2700
|
+
.filter(function (item) { return item !== ''; })
|
|
2701
|
+
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
2702
|
+
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
2703
|
+
.map(removeMarkdownFormatting);
|
|
2704
|
+
if (type.startsWith('URL') ||
|
|
2705
|
+
type.startsWith('PTBK_URL') ||
|
|
2706
|
+
type.startsWith('PTBKURL') ||
|
|
2707
|
+
type.startsWith('PROMPTBOOK_URL') ||
|
|
2708
|
+
type.startsWith('PROMPTBOOKURL') ||
|
|
2709
|
+
type.startsWith('HTTPS')) {
|
|
2710
|
+
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
2711
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
2712
|
+
}
|
|
2713
|
+
var promptbookUrlString = listItemParts.pop();
|
|
2714
|
+
var promptbookUrl = new URL(promptbookUrlString);
|
|
2715
|
+
if (promptbookUrl.protocol !== 'https:') {
|
|
2716
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
2717
|
+
}
|
|
2718
|
+
if (promptbookUrl.hash !== '') {
|
|
2719
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
|
|
2720
|
+
}
|
|
2721
|
+
return {
|
|
2722
|
+
type: 'PROMPTBOOK_URL',
|
|
2723
|
+
promptbookUrl: promptbookUrl,
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
2727
|
+
if (listItemParts.length !== 2) {
|
|
2728
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
2729
|
+
}
|
|
2730
|
+
var promptbookVersion = listItemParts.pop();
|
|
2731
|
+
// TODO: Validate version
|
|
2732
|
+
return {
|
|
2733
|
+
type: 'PROMPTBOOK_VERSION',
|
|
2734
|
+
promptbookVersion: promptbookVersion,
|
|
2735
|
+
};
|
|
2736
|
+
}
|
|
2737
|
+
else if (type.startsWith('EXECUTE') ||
|
|
2738
|
+
type.startsWith('EXEC') ||
|
|
2739
|
+
type.startsWith('PROMPT_DIALOG') ||
|
|
2740
|
+
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
2741
|
+
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
2742
|
+
if (executionTypes.length !== 1) {
|
|
2743
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
|
|
2744
|
+
}
|
|
2745
|
+
return {
|
|
2746
|
+
type: 'EXECUTE',
|
|
2747
|
+
executionType: executionTypes[0],
|
|
2748
|
+
};
|
|
2749
|
+
}
|
|
2750
|
+
else if (type.startsWith('MODEL')) {
|
|
2751
|
+
// TODO: Make this more elegant and dynamically
|
|
2752
|
+
if (type.startsWith('MODEL_VARIANT')) {
|
|
2753
|
+
if (type === 'MODEL_VARIANT_CHAT') {
|
|
2754
|
+
return {
|
|
2755
|
+
type: 'MODEL',
|
|
2756
|
+
key: 'modelVariant',
|
|
2757
|
+
value: 'CHAT',
|
|
2758
|
+
};
|
|
2759
|
+
}
|
|
2760
|
+
else if (type === 'MODEL_VARIANT_COMPLETION') {
|
|
2761
|
+
return {
|
|
2762
|
+
type: 'MODEL',
|
|
2763
|
+
key: 'modelVariant',
|
|
2764
|
+
value: 'COMPLETION',
|
|
2765
|
+
};
|
|
1332
2766
|
}
|
|
1333
|
-
else
|
|
1334
|
-
|
|
1335
|
-
normalizedChar = char;
|
|
2767
|
+
else {
|
|
2768
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
|
|
1336
2769
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
2770
|
+
}
|
|
2771
|
+
if (type.startsWith('MODEL_NAME')) {
|
|
2772
|
+
return {
|
|
2773
|
+
type: 'MODEL',
|
|
2774
|
+
key: 'modelName',
|
|
2775
|
+
value: listItemParts.pop(),
|
|
2776
|
+
};
|
|
2777
|
+
}
|
|
2778
|
+
else {
|
|
2779
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
else if (type.startsWith('PARAM') ||
|
|
2783
|
+
type.startsWith('INPUT_PARAM') ||
|
|
2784
|
+
type.startsWith('OUTPUT_PARAM') ||
|
|
2785
|
+
listItem.startsWith('{') ||
|
|
2786
|
+
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
2787
|
+
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
2788
|
+
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2789
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2790
|
+
}
|
|
2791
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2792
|
+
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
2793
|
+
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
2794
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
2795
|
+
}
|
|
2796
|
+
var isInput = type.startsWith('INPUT');
|
|
2797
|
+
var isOutput = type.startsWith('OUTPUT');
|
|
2798
|
+
if (listItem.startsWith('> {')) {
|
|
2799
|
+
isInput = false;
|
|
2800
|
+
isOutput = false;
|
|
2801
|
+
}
|
|
2802
|
+
return {
|
|
2803
|
+
type: 'PARAMETER',
|
|
2804
|
+
parameterName: parameterName,
|
|
2805
|
+
parameterDescription: parameterDescription.trim() || null,
|
|
2806
|
+
isInput: isInput,
|
|
2807
|
+
isOutput: isOutput,
|
|
2808
|
+
};
|
|
2809
|
+
}
|
|
2810
|
+
else if (type.startsWith('JOKER')) {
|
|
2811
|
+
if (listItemParts.length !== 2) {
|
|
2812
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
2813
|
+
}
|
|
2814
|
+
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
2815
|
+
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2816
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2817
|
+
}
|
|
2818
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2819
|
+
var parameterName = parametersMatch.groups.parameterName;
|
|
2820
|
+
return {
|
|
2821
|
+
type: 'JOKER',
|
|
2822
|
+
parameterName: parameterName,
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
2826
|
+
if (listItemParts.length !== 2) {
|
|
2827
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
2828
|
+
}
|
|
2829
|
+
var functionName = listItemParts.pop();
|
|
2830
|
+
return {
|
|
2831
|
+
type: 'POSTPROCESS',
|
|
2832
|
+
functionName: functionName,
|
|
2833
|
+
};
|
|
2834
|
+
}
|
|
2835
|
+
else if (type.startsWith('EXPECT_JSON')) {
|
|
2836
|
+
return {
|
|
2837
|
+
type: 'EXPECT_FORMAT',
|
|
2838
|
+
format: 'JSON',
|
|
2839
|
+
};
|
|
2840
|
+
// [🥤]
|
|
2841
|
+
}
|
|
2842
|
+
else if (type.startsWith('EXPECT')) {
|
|
2843
|
+
try {
|
|
2844
|
+
listItemParts.shift();
|
|
2845
|
+
var sign = void 0;
|
|
2846
|
+
var signRaw = listItemParts.shift();
|
|
2847
|
+
if (/^exact/i.test(signRaw)) {
|
|
2848
|
+
sign = 'EXACTLY';
|
|
2849
|
+
}
|
|
2850
|
+
else if (/^min/i.test(signRaw)) {
|
|
2851
|
+
sign = 'MINIMUM';
|
|
2852
|
+
}
|
|
2853
|
+
else if (/^max/i.test(signRaw)) {
|
|
2854
|
+
sign = 'MAXIMUM';
|
|
1340
2855
|
}
|
|
1341
2856
|
else {
|
|
1342
|
-
|
|
1343
|
-
normalizedChar = '-';
|
|
2857
|
+
throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
|
|
1344
2858
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
normalizedName += '-';
|
|
2859
|
+
var amountRaw = listItemParts.shift();
|
|
2860
|
+
var amount = parseNumber(amountRaw);
|
|
2861
|
+
if (amount < 0) {
|
|
2862
|
+
throw new PromptbookSyntaxError('Amount must be positive number or zero');
|
|
1350
2863
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
2864
|
+
if (amount !== Math.floor(amount)) {
|
|
2865
|
+
throw new PromptbookSyntaxError('Amount must be whole number');
|
|
2866
|
+
}
|
|
2867
|
+
var unitRaw = listItemParts.shift();
|
|
2868
|
+
var unit = undefined;
|
|
2869
|
+
try {
|
|
2870
|
+
for (var EXPECTATION_UNITS_1 = __values(EXPECTATION_UNITS), EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next(); !EXPECTATION_UNITS_1_1.done; EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next()) {
|
|
2871
|
+
var existingUnit = EXPECTATION_UNITS_1_1.value;
|
|
2872
|
+
var existingUnitText = existingUnit;
|
|
2873
|
+
existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
|
|
2874
|
+
if (existingUnitText === 'CHARACTER') {
|
|
2875
|
+
existingUnitText = 'CHAR';
|
|
2876
|
+
}
|
|
2877
|
+
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
2878
|
+
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
2879
|
+
if (unit !== undefined) {
|
|
2880
|
+
throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
2881
|
+
}
|
|
2882
|
+
unit = existingUnit;
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2887
|
+
finally {
|
|
2888
|
+
try {
|
|
2889
|
+
if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
|
|
2890
|
+
}
|
|
2891
|
+
finally { if (e_1) throw e_1.error; }
|
|
2892
|
+
}
|
|
2893
|
+
if (unit === undefined) {
|
|
2894
|
+
throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
|
|
2895
|
+
}
|
|
2896
|
+
return {
|
|
2897
|
+
type: 'EXPECT_AMOUNT',
|
|
2898
|
+
sign: sign,
|
|
2899
|
+
unit: unit,
|
|
2900
|
+
amount: amount,
|
|
2901
|
+
};
|
|
1353
2902
|
}
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
2903
|
+
catch (error) {
|
|
2904
|
+
if (!(error instanceof Error)) {
|
|
2905
|
+
throw error;
|
|
2906
|
+
}
|
|
2907
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
1359
2908
|
}
|
|
1360
|
-
|
|
2909
|
+
/*
|
|
2910
|
+
} else if (type.startsWith('__________________')) {
|
|
2911
|
+
// <- [🥻] Insert here when making new command
|
|
2912
|
+
*/
|
|
2913
|
+
}
|
|
2914
|
+
else {
|
|
2915
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
|
|
1361
2916
|
}
|
|
1362
|
-
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
1363
|
-
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
1364
|
-
normalizedName = normalizedName.replace(/^-/, '');
|
|
1365
|
-
normalizedName = normalizedName.replace(/-$/, '');
|
|
1366
|
-
return normalizedName;
|
|
1367
2917
|
}
|
|
1368
2918
|
|
|
1369
2919
|
/**
|
|
@@ -1395,250 +2945,265 @@
|
|
|
1395
2945
|
* Compile promptbook from string (markdown) format to JSON format
|
|
1396
2946
|
*
|
|
1397
2947
|
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1398
|
-
* @param
|
|
2948
|
+
* @param options - Options and tools for the compilation
|
|
1399
2949
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1400
2950
|
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1401
2951
|
*
|
|
1402
2952
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1403
2953
|
* Note: This function acts as compilation process
|
|
1404
2954
|
*/
|
|
1405
|
-
function promptbookStringToJson(promptbookString,
|
|
2955
|
+
function promptbookStringToJson(promptbookString, options) {
|
|
2956
|
+
if (options === void 0) { options = {}; }
|
|
1406
2957
|
return __awaiter(this, void 0, void 0, function () {
|
|
1407
|
-
var promptbookJson, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
2958
|
+
var llmTools, promptbookJson, knowledge, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1408
2959
|
var e_1, _c, e_2, _d;
|
|
1409
2960
|
return __generator(this, function (_e) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
2961
|
+
switch (_e.label) {
|
|
2962
|
+
case 0:
|
|
2963
|
+
llmTools = options.llmTools;
|
|
2964
|
+
promptbookJson = {
|
|
2965
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2966
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
2967
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
2968
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2969
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
2970
|
+
parameters: [],
|
|
2971
|
+
promptTemplates: [],
|
|
2972
|
+
knowledge: [],
|
|
2973
|
+
};
|
|
2974
|
+
if (!llmTools) return [3 /*break*/, 2];
|
|
2975
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdown({
|
|
2976
|
+
content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
|
|
2977
|
+
llmTools: llmTools,
|
|
2978
|
+
})];
|
|
2979
|
+
case 1:
|
|
2980
|
+
knowledge = _e.sent();
|
|
2981
|
+
console.info('!!!! knowledge', knowledge);
|
|
2982
|
+
_e.label = 2;
|
|
2983
|
+
case 2:
|
|
2984
|
+
// =============================================================
|
|
2985
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
2986
|
+
promptbookString = removeContentComments(promptbookString);
|
|
2987
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
2988
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
2989
|
+
addParam = function (parameterCommand) {
|
|
2990
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
2991
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
2992
|
+
if (existingParameter &&
|
|
2993
|
+
existingParameter.description &&
|
|
2994
|
+
existingParameter.description !== parameterDescription &&
|
|
2995
|
+
parameterDescription) {
|
|
2996
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(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 "); }));
|
|
2997
|
+
}
|
|
2998
|
+
if (existingParameter) {
|
|
2999
|
+
if (parameterDescription) {
|
|
3000
|
+
existingParameter.description = parameterDescription;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
else {
|
|
3004
|
+
promptbookJson.parameters.push({
|
|
3005
|
+
name: parameterName,
|
|
3006
|
+
description: parameterDescription || undefined,
|
|
3007
|
+
isInput: isInput,
|
|
3008
|
+
isOutput: isOutput,
|
|
3009
|
+
});
|
|
3010
|
+
}
|
|
3011
|
+
};
|
|
3012
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
3013
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
3014
|
+
if (markdownStructureDeepness !== 2) {
|
|
3015
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
1437
3016
|
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
};
|
|
1448
|
-
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1449
|
-
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1450
|
-
if (markdownStructureDeepness !== 2) {
|
|
1451
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
1452
|
-
}
|
|
1453
|
-
promptbookJson.title = markdownStructure.title;
|
|
1454
|
-
description = markdownStructure.content;
|
|
1455
|
-
// Note: Remove codeblocks
|
|
1456
|
-
description = description.split(/^```.*^```/gms).join('');
|
|
1457
|
-
//Note: Remove lists and return statement
|
|
1458
|
-
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1459
|
-
description = spacetrim.spaceTrim(description);
|
|
1460
|
-
if (description === '') {
|
|
1461
|
-
description = undefined;
|
|
1462
|
-
}
|
|
1463
|
-
promptbookJson.description = description;
|
|
1464
|
-
defaultModelRequirements = {};
|
|
1465
|
-
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1466
|
-
try {
|
|
1467
|
-
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1468
|
-
listItem = listItems_1_1.value;
|
|
1469
|
-
command = parseCommand(listItem);
|
|
1470
|
-
switch (command.type) {
|
|
1471
|
-
case 'PROMPTBOOK_URL':
|
|
1472
|
-
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1473
|
-
break;
|
|
1474
|
-
case 'PROMPTBOOK_VERSION':
|
|
1475
|
-
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1476
|
-
break;
|
|
1477
|
-
case 'MODEL':
|
|
1478
|
-
defaultModelRequirements[command.key] = command.value;
|
|
1479
|
-
break;
|
|
1480
|
-
case 'PARAMETER':
|
|
1481
|
-
addParam(command);
|
|
1482
|
-
break;
|
|
1483
|
-
default:
|
|
1484
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
3017
|
+
promptbookJson.title = markdownStructure.title;
|
|
3018
|
+
description = markdownStructure.content;
|
|
3019
|
+
// Note: Remove codeblocks
|
|
3020
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
3021
|
+
//Note: Remove lists and return statement
|
|
3022
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
3023
|
+
description = spaceTrim.spaceTrim(description);
|
|
3024
|
+
if (description === '') {
|
|
3025
|
+
description = undefined;
|
|
1485
3026
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
var listItem = listItems_2_1.value;
|
|
1510
|
-
var command = parseCommand(listItem);
|
|
1511
|
-
switch (command.type) {
|
|
1512
|
-
case 'JOKER':
|
|
1513
|
-
jokers.push(command.parameterName);
|
|
1514
|
-
dependentParameterNames.add(command.parameterName);
|
|
1515
|
-
break;
|
|
1516
|
-
case 'EXECUTE':
|
|
1517
|
-
if (isExecutionTypeChanged) {
|
|
1518
|
-
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1519
|
-
}
|
|
1520
|
-
executionType = command.executionType;
|
|
1521
|
-
isExecutionTypeChanged = true;
|
|
1522
|
-
break;
|
|
1523
|
-
case 'MODEL':
|
|
1524
|
-
templateModelRequirements[command.key] = command.value;
|
|
1525
|
-
break;
|
|
1526
|
-
case 'PARAMETER':
|
|
1527
|
-
// Note: This is just for detecting resulitng parameter name
|
|
1528
|
-
addParam(command);
|
|
1529
|
-
break;
|
|
1530
|
-
case 'POSTPROCESS':
|
|
1531
|
-
postprocessing.push(command.functionName);
|
|
1532
|
-
break;
|
|
1533
|
-
case 'EXPECT_AMOUNT':
|
|
1534
|
-
// eslint-disable-next-line no-case-declarations
|
|
1535
|
-
var unit = command.unit.toLowerCase();
|
|
1536
|
-
expectAmount[unit] = expectAmount[unit] || {};
|
|
1537
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1538
|
-
if (expectAmount[unit].min !== undefined) {
|
|
1539
|
-
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1540
|
-
}
|
|
1541
|
-
expectAmount[unit].min = command.amount;
|
|
1542
|
-
} /* not else */
|
|
1543
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1544
|
-
if (expectAmount[unit].max !== undefined) {
|
|
1545
|
-
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1546
|
-
}
|
|
1547
|
-
expectAmount[unit].max = command.amount;
|
|
1548
|
-
}
|
|
1549
|
-
break;
|
|
1550
|
-
case 'EXPECT_FORMAT':
|
|
1551
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1552
|
-
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1553
|
-
}
|
|
1554
|
-
expectFormat = command.format;
|
|
1555
|
-
break;
|
|
1556
|
-
default:
|
|
1557
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
3027
|
+
promptbookJson.description = description;
|
|
3028
|
+
defaultModelRequirements = {};
|
|
3029
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
3030
|
+
try {
|
|
3031
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
3032
|
+
listItem = listItems_1_1.value;
|
|
3033
|
+
command = parseCommand(listItem);
|
|
3034
|
+
switch (command.type) {
|
|
3035
|
+
case 'PROMPTBOOK_URL':
|
|
3036
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
3037
|
+
break;
|
|
3038
|
+
case 'PROMPTBOOK_VERSION':
|
|
3039
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
3040
|
+
break;
|
|
3041
|
+
case 'MODEL':
|
|
3042
|
+
defaultModelRequirements[command.key] = command.value;
|
|
3043
|
+
break;
|
|
3044
|
+
case 'PARAMETER':
|
|
3045
|
+
addParam(command);
|
|
3046
|
+
break;
|
|
3047
|
+
default:
|
|
3048
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
3049
|
+
}
|
|
1558
3050
|
}
|
|
1559
3051
|
}
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
3052
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3053
|
+
finally {
|
|
3054
|
+
try {
|
|
3055
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
3056
|
+
}
|
|
3057
|
+
finally { if (e_1) throw e_1.error; }
|
|
1565
3058
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
3059
|
+
_loop_1 = function (section) {
|
|
3060
|
+
var e_3, _f;
|
|
3061
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
3062
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
3063
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
3064
|
+
var dependentParameterNames = new Set();
|
|
3065
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
3066
|
+
var jokers = [];
|
|
3067
|
+
var postprocessing = [];
|
|
3068
|
+
var expectAmount = {};
|
|
3069
|
+
var expectFormat = undefined;
|
|
3070
|
+
var isExecutionTypeChanged = false;
|
|
3071
|
+
try {
|
|
3072
|
+
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()) {
|
|
3073
|
+
var listItem = listItems_2_1.value;
|
|
3074
|
+
var command = parseCommand(listItem);
|
|
3075
|
+
switch (command.type) {
|
|
3076
|
+
case 'JOKER':
|
|
3077
|
+
jokers.push(command.parameterName);
|
|
3078
|
+
dependentParameterNames.add(command.parameterName);
|
|
3079
|
+
break;
|
|
3080
|
+
case 'EXECUTE':
|
|
3081
|
+
if (isExecutionTypeChanged) {
|
|
3082
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
3083
|
+
}
|
|
3084
|
+
executionType = command.executionType;
|
|
3085
|
+
isExecutionTypeChanged = true;
|
|
3086
|
+
break;
|
|
3087
|
+
case 'MODEL':
|
|
3088
|
+
templateModelRequirements[command.key] = command.value;
|
|
3089
|
+
break;
|
|
3090
|
+
case 'PARAMETER':
|
|
3091
|
+
// Note: This is just for detecting resulitng parameter name
|
|
3092
|
+
addParam(command);
|
|
3093
|
+
break;
|
|
3094
|
+
case 'POSTPROCESS':
|
|
3095
|
+
postprocessing.push(command.functionName);
|
|
3096
|
+
break;
|
|
3097
|
+
case 'EXPECT_AMOUNT':
|
|
3098
|
+
// eslint-disable-next-line no-case-declarations
|
|
3099
|
+
var unit = command.unit.toLowerCase();
|
|
3100
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
3101
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
3102
|
+
if (expectAmount[unit].min !== undefined) {
|
|
3103
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3104
|
+
}
|
|
3105
|
+
expectAmount[unit].min = command.amount;
|
|
3106
|
+
} /* not else */
|
|
3107
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
3108
|
+
if (expectAmount[unit].max !== undefined) {
|
|
3109
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3110
|
+
}
|
|
3111
|
+
expectAmount[unit].max = command.amount;
|
|
3112
|
+
}
|
|
3113
|
+
break;
|
|
3114
|
+
case 'EXPECT_FORMAT':
|
|
3115
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
3116
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
3117
|
+
}
|
|
3118
|
+
expectFormat = command.format;
|
|
3119
|
+
break;
|
|
3120
|
+
default:
|
|
3121
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
3126
|
+
finally {
|
|
3127
|
+
try {
|
|
3128
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
3129
|
+
}
|
|
3130
|
+
finally { if (e_3) throw e_3.error; }
|
|
3131
|
+
}
|
|
3132
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
3133
|
+
if (executionType === 'SCRIPT') {
|
|
3134
|
+
if (!language) {
|
|
3135
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
3136
|
+
}
|
|
3137
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
3138
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(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 "); }));
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
var lastLine = section.content.split('\n').pop();
|
|
3142
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
3143
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
3144
|
+
throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
3145
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
3146
|
+
section.content
|
|
3147
|
+
.split('\n')
|
|
3148
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3149
|
+
.join('\n')), "\n "); }));
|
|
3150
|
+
}
|
|
3151
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
3152
|
+
// TODO: [1] DRY description
|
|
3153
|
+
var description_1 = section.content;
|
|
3154
|
+
// Note: Remove codeblocks
|
|
3155
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
3156
|
+
//Note: Remove lists and return statement
|
|
3157
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
3158
|
+
description_1 = spaceTrim.spaceTrim(description_1);
|
|
3159
|
+
if (description_1 === '') {
|
|
3160
|
+
description_1 = undefined;
|
|
3161
|
+
}
|
|
3162
|
+
if (Object.keys(jokers).length === 0) {
|
|
3163
|
+
jokers = undefined;
|
|
3164
|
+
}
|
|
3165
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
3166
|
+
expectAmount = undefined;
|
|
3167
|
+
}
|
|
3168
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
3169
|
+
postprocessing = undefined;
|
|
3170
|
+
}
|
|
3171
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
3172
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
3173
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
3174
|
+
}
|
|
3175
|
+
promptbookJson.promptTemplates.push({
|
|
3176
|
+
name: titleToName(section.title),
|
|
3177
|
+
title: section.title,
|
|
3178
|
+
description: description_1,
|
|
3179
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
3180
|
+
executionType: executionType,
|
|
3181
|
+
jokers: jokers,
|
|
3182
|
+
postprocessing: postprocessing,
|
|
3183
|
+
expectations: expectAmount,
|
|
3184
|
+
expectFormat: expectFormat,
|
|
3185
|
+
modelRequirements: templateModelRequirements,
|
|
3186
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
3187
|
+
content: content,
|
|
3188
|
+
resultingParameterName: resultingParameterName,
|
|
3189
|
+
});
|
|
3190
|
+
};
|
|
3191
|
+
try {
|
|
3192
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3193
|
+
section = _b.value;
|
|
3194
|
+
_loop_1(section);
|
|
3195
|
+
}
|
|
1572
3196
|
}
|
|
1573
|
-
|
|
1574
|
-
|
|
3197
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3198
|
+
finally {
|
|
3199
|
+
try {
|
|
3200
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
3201
|
+
}
|
|
3202
|
+
finally { if (e_2) throw e_2.error; }
|
|
1575
3203
|
}
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1579
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1580
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1581
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
1582
|
-
section.content
|
|
1583
|
-
.split('\n')
|
|
1584
|
-
.map(function (line) { return "> ".concat(line); })
|
|
1585
|
-
.join('\n')), "\n "); }));
|
|
1586
|
-
}
|
|
1587
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
1588
|
-
// TODO: [1] DRY description
|
|
1589
|
-
var description_1 = section.content;
|
|
1590
|
-
// Note: Remove codeblocks
|
|
1591
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1592
|
-
//Note: Remove lists and return statement
|
|
1593
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1594
|
-
description_1 = spacetrim.spaceTrim(description_1);
|
|
1595
|
-
if (description_1 === '') {
|
|
1596
|
-
description_1 = undefined;
|
|
1597
|
-
}
|
|
1598
|
-
if (Object.keys(jokers).length === 0) {
|
|
1599
|
-
jokers = undefined;
|
|
1600
|
-
}
|
|
1601
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
1602
|
-
expectAmount = undefined;
|
|
1603
|
-
}
|
|
1604
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
1605
|
-
postprocessing = undefined;
|
|
1606
|
-
}
|
|
1607
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1608
|
-
if (templateModelRequirements.modelVariant === undefined) {
|
|
1609
|
-
templateModelRequirements.modelVariant = 'CHAT';
|
|
1610
|
-
}
|
|
1611
|
-
promptbookJson.promptTemplates.push({
|
|
1612
|
-
name: titleToName(section.title),
|
|
1613
|
-
title: section.title,
|
|
1614
|
-
description: description_1,
|
|
1615
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1616
|
-
executionType: executionType,
|
|
1617
|
-
jokers: jokers,
|
|
1618
|
-
postprocessing: postprocessing,
|
|
1619
|
-
expectations: expectAmount,
|
|
1620
|
-
expectFormat: expectFormat,
|
|
1621
|
-
modelRequirements: templateModelRequirements,
|
|
1622
|
-
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1623
|
-
content: content,
|
|
1624
|
-
resultingParameterName: resultingParameterName,
|
|
1625
|
-
});
|
|
1626
|
-
};
|
|
1627
|
-
try {
|
|
1628
|
-
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1629
|
-
section = _b.value;
|
|
1630
|
-
_loop_1(section);
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1634
|
-
finally {
|
|
1635
|
-
try {
|
|
1636
|
-
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1637
|
-
}
|
|
1638
|
-
finally { if (e_2) throw e_2.error; }
|
|
3204
|
+
// =============================================================
|
|
3205
|
+
return [2 /*return*/, promptbookJson];
|
|
1639
3206
|
}
|
|
1640
|
-
// =============================================================
|
|
1641
|
-
return [2 /*return*/, promptbookJson];
|
|
1642
3207
|
});
|
|
1643
3208
|
});
|
|
1644
3209
|
}
|
|
@@ -1724,7 +3289,7 @@
|
|
|
1724
3289
|
}
|
|
1725
3290
|
return normalizeTo_camelCase('template-' + titleToName(template.title));
|
|
1726
3291
|
};
|
|
1727
|
-
var promptbookMermaid =
|
|
3292
|
+
var promptbookMermaid = spaceTrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
|
|
1728
3293
|
.flatMap(function (_a) {
|
|
1729
3294
|
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
1730
3295
|
return __spreadArray([
|
|
@@ -1780,7 +3345,7 @@
|
|
|
1780
3345
|
return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
|
|
1781
3346
|
},
|
|
1782
3347
|
});
|
|
1783
|
-
promptbookMermaidBlock =
|
|
3348
|
+
promptbookMermaidBlock = spaceTrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
1784
3349
|
promptbookString = addAutoGeneratedSection(promptbookString, {
|
|
1785
3350
|
sectionName: 'Graph',
|
|
1786
3351
|
sectionContent: promptbookMermaidBlock,
|
|
@@ -1809,14 +3374,14 @@
|
|
|
1809
3374
|
var _this = this;
|
|
1810
3375
|
return __generator(this, function (_a) {
|
|
1811
3376
|
if (!isRunningInNode()) {
|
|
1812
|
-
throw new Error(
|
|
3377
|
+
throw new Error(spaceTrim.spaceTrim("\n Function prettifyPromptbookStringCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use prettifyPromptbookString.\n\n "));
|
|
1813
3378
|
}
|
|
1814
3379
|
program = new commander__default["default"].Command();
|
|
1815
3380
|
program.name('promptbook');
|
|
1816
3381
|
program.version(PROMPTBOOK_VERSION);
|
|
1817
|
-
program.description(
|
|
3382
|
+
program.description(spaceTrim.spaceTrim("\n Promptbook utilities\n "));
|
|
1818
3383
|
prettifyCommand = program.command('prettify');
|
|
1819
|
-
prettifyCommand.description(
|
|
3384
|
+
prettifyCommand.description(spaceTrim.spaceTrim("\n Iterates over promptbooks and does multiple enhancing operations on them:\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
|
|
1820
3385
|
prettifyCommand.argument('<filesGlob>', 'Promptbooks to prettify as glob pattern');
|
|
1821
3386
|
prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
|
|
1822
3387
|
prettifyCommand.action(function (filesGlob, _a) {
|
|
@@ -1891,7 +3456,7 @@
|
|
|
1891
3456
|
});
|
|
1892
3457
|
});
|
|
1893
3458
|
helloCommand = program.command('hello');
|
|
1894
|
-
helloCommand.description(
|
|
3459
|
+
helloCommand.description(spaceTrim.spaceTrim("\n Just command for testing\n "));
|
|
1895
3460
|
helloCommand.argument('<name>', 'Your name');
|
|
1896
3461
|
helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
|
|
1897
3462
|
helloCommand.action(function (name, _a) {
|