@promptbook/node 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 +2588 -1622
- 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 +2588 -1622
- 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/esm/index.es.js
CHANGED
|
@@ -137,40 +137,66 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
137
137
|
return PromptbookSyntaxError;
|
|
138
138
|
}(Error));
|
|
139
139
|
|
|
140
|
+
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": [] }];
|
|
141
|
+
|
|
140
142
|
/**
|
|
141
|
-
*
|
|
143
|
+
* This error indicates errors during the execution of the promptbook
|
|
142
144
|
*/
|
|
143
|
-
var
|
|
145
|
+
var PromptbookExecutionError = /** @class */ (function (_super) {
|
|
146
|
+
__extends(PromptbookExecutionError, _super);
|
|
147
|
+
function PromptbookExecutionError(message) {
|
|
148
|
+
var _this = _super.call(this, message) || this;
|
|
149
|
+
_this.name = 'PromptbookExecutionError';
|
|
150
|
+
Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
|
|
151
|
+
return _this;
|
|
152
|
+
}
|
|
153
|
+
return PromptbookExecutionError;
|
|
154
|
+
}(Error));
|
|
144
155
|
|
|
145
156
|
/**
|
|
146
|
-
*
|
|
157
|
+
* Asserts that the execution of a promptnook is successful
|
|
147
158
|
*
|
|
148
|
-
* @
|
|
159
|
+
* @param executionResult - The partial result of the promptnook execution
|
|
160
|
+
* @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
|
|
149
161
|
*/
|
|
150
|
-
function
|
|
151
|
-
var
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
155
|
-
var section = _c.value;
|
|
156
|
-
maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
|
|
157
|
-
}
|
|
162
|
+
function assertsExecutionSuccessful(executionResult) {
|
|
163
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
164
|
+
if (isSuccessful === true) {
|
|
165
|
+
return;
|
|
158
166
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
167
|
+
if (errors.length === 0) {
|
|
168
|
+
throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
|
|
169
|
+
}
|
|
170
|
+
else if (errors.length === 1) {
|
|
171
|
+
throw errors[0];
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
throw new PromptbookExecutionError(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 "); }));
|
|
165
175
|
}
|
|
166
|
-
return maxDeepness + 1;
|
|
167
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* TODO: [🧠] Can this return type be better typed than void
|
|
179
|
+
*/
|
|
168
180
|
|
|
169
181
|
/**
|
|
170
182
|
* The maximum number of iterations for a loops
|
|
171
183
|
*/
|
|
172
184
|
var LOOP_LIMIT = 1000;
|
|
173
185
|
|
|
186
|
+
/**
|
|
187
|
+
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
188
|
+
*/
|
|
189
|
+
var PromptbookLogicError = /** @class */ (function (_super) {
|
|
190
|
+
__extends(PromptbookLogicError, _super);
|
|
191
|
+
function PromptbookLogicError(message) {
|
|
192
|
+
var _this = _super.call(this, message) || this;
|
|
193
|
+
_this.name = 'PromptbookLogicError';
|
|
194
|
+
Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
|
|
195
|
+
return _this;
|
|
196
|
+
}
|
|
197
|
+
return PromptbookLogicError;
|
|
198
|
+
}(Error));
|
|
199
|
+
|
|
174
200
|
/**
|
|
175
201
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
176
202
|
*/
|
|
@@ -186,804 +212,400 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
186
212
|
}(Error));
|
|
187
213
|
|
|
188
214
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* Note: This function does work with code blocks
|
|
192
|
-
* Note: This function does not work with markdown comments
|
|
193
|
-
*
|
|
194
|
-
* @param markdown The markdown string to parse.
|
|
195
|
-
* @returns The MarkdownStructure object.
|
|
215
|
+
* Tests if given string is valid URL.
|
|
196
216
|
*
|
|
197
|
-
*
|
|
217
|
+
* Note: Dataurl are considered perfectly valid.
|
|
198
218
|
*/
|
|
199
|
-
function
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
var current = root;
|
|
204
|
-
var isInsideCodeBlock = false;
|
|
219
|
+
function isValidUrl(url) {
|
|
220
|
+
if (typeof url !== 'string') {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
205
223
|
try {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
|
|
209
|
-
if (isInsideCodeBlock || !headingMatch) {
|
|
210
|
-
if (line.startsWith('```')) {
|
|
211
|
-
isInsideCodeBlock = !isInsideCodeBlock;
|
|
212
|
-
}
|
|
213
|
-
current.contentLines.push(line);
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
var level = headingMatch.groups.mark.length;
|
|
217
|
-
var title = headingMatch.groups.title.trim();
|
|
218
|
-
var parent_1 = void 0;
|
|
219
|
-
if (level > current.level) {
|
|
220
|
-
// Note: Going deeper (next section is child of current)
|
|
221
|
-
parent_1 = current;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
// Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
|
|
225
|
-
parent_1 = current;
|
|
226
|
-
var loopLimit = LOOP_LIMIT;
|
|
227
|
-
while (parent_1.level !== level - 1) {
|
|
228
|
-
if (loopLimit-- < 0) {
|
|
229
|
-
throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
|
|
230
|
-
}
|
|
231
|
-
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
232
|
-
// [🌻]
|
|
233
|
-
throw new Error(spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
234
|
-
}
|
|
235
|
-
parent_1 = parent_1.parent;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
|
|
239
|
-
parent_1.sections.push(section);
|
|
240
|
-
current = section;
|
|
241
|
-
}
|
|
224
|
+
if (url.startsWith('blob:')) {
|
|
225
|
+
url = url.replace(/^blob:/, '');
|
|
242
226
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
228
|
+
var urlObject = new URL(url);
|
|
229
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
230
|
+
return false;
|
|
248
231
|
}
|
|
249
|
-
|
|
232
|
+
return true;
|
|
250
233
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return markdownStructure;
|
|
234
|
+
catch (error) {
|
|
235
|
+
return false;
|
|
254
236
|
}
|
|
255
|
-
// [🌻]
|
|
256
|
-
throw new Error('The markdown file must have exactly one top-level section.');
|
|
257
|
-
// return root;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* @private
|
|
261
|
-
*/
|
|
262
|
-
function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
263
|
-
var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
|
|
264
|
-
return {
|
|
265
|
-
level: level,
|
|
266
|
-
title: title,
|
|
267
|
-
content: spaceTrim(contentLines.join('\n')),
|
|
268
|
-
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
269
|
-
};
|
|
270
237
|
}
|
|
271
238
|
|
|
272
239
|
/**
|
|
273
|
-
*
|
|
240
|
+
* Validates PromptbookJson if it is logically valid
|
|
274
241
|
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* Note: It flattens nested lists
|
|
278
|
-
* Note: It can not work with html syntax and comments
|
|
242
|
+
* It checks:
|
|
243
|
+
* - if it has correct parameters dependency
|
|
279
244
|
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
245
|
+
* It does NOT check:
|
|
246
|
+
* - if it is valid json
|
|
247
|
+
* - if it is meaningful
|
|
248
|
+
*
|
|
249
|
+
* @param promptbook valid or invalid PromptbookJson
|
|
250
|
+
* @returns the same promptbook if it is logically valid
|
|
251
|
+
* @throws {PromptbookLogicError} on logical error in the promptbook
|
|
282
252
|
*/
|
|
283
|
-
function
|
|
284
|
-
|
|
285
|
-
var
|
|
286
|
-
|
|
287
|
-
|
|
253
|
+
function validatePromptbookJson(promptbook) {
|
|
254
|
+
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
255
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
256
|
+
if (promptbook.promptbookUrl !== undefined) {
|
|
257
|
+
if (!isValidUrl(promptbook.promptbookUrl)) {
|
|
258
|
+
// TODO: This should be maybe the syntax error detected during parsing
|
|
259
|
+
throw new PromptbookLogicError("Invalid promptbook URL \"".concat(promptbook.promptbookUrl, "\""));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
263
|
+
if (!Array.isArray(promptbook.parameters)) {
|
|
264
|
+
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
265
|
+
throw new PromptbookSyntaxError(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 ")));
|
|
266
|
+
}
|
|
267
|
+
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
268
|
+
if (!Array.isArray(promptbook.promptTemplates)) {
|
|
269
|
+
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
270
|
+
throw new PromptbookSyntaxError(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 ")));
|
|
271
|
+
}
|
|
272
|
+
var _loop_1 = function (parameter) {
|
|
273
|
+
if (parameter.isInput && parameter.isOutput) {
|
|
274
|
+
throw new PromptbookLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
|
|
275
|
+
}
|
|
276
|
+
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
277
|
+
if (!parameter.isInput &&
|
|
278
|
+
!parameter.isOutput &&
|
|
279
|
+
!promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
280
|
+
throw new PromptbookLogicError(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 ")));
|
|
281
|
+
}
|
|
282
|
+
// Note: Testing that parameter is either input or result of some template
|
|
283
|
+
if (!parameter.isInput &&
|
|
284
|
+
!promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
285
|
+
throw new PromptbookLogicError(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 ")));
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
288
|
try {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
var
|
|
292
|
-
|
|
293
|
-
isInCodeBlock = !isInCodeBlock;
|
|
294
|
-
}
|
|
295
|
-
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
296
|
-
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
297
|
-
listItems.push(listItem);
|
|
298
|
-
}
|
|
289
|
+
// Note: Check each parameter individually
|
|
290
|
+
for (var _e = __values(promptbook.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
291
|
+
var parameter = _f.value;
|
|
292
|
+
_loop_1(parameter);
|
|
299
293
|
}
|
|
300
294
|
}
|
|
301
295
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
302
296
|
finally {
|
|
303
297
|
try {
|
|
304
|
-
if (
|
|
298
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
305
299
|
}
|
|
306
300
|
finally { if (e_1) throw e_1.error; }
|
|
307
301
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Extracts all code blocks from markdown.
|
|
321
|
-
*
|
|
322
|
-
* Note: There are 3 simmilar function:
|
|
323
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
324
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
325
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
326
|
-
*
|
|
327
|
-
* @param markdown any valid markdown
|
|
328
|
-
* @returns code blocks with language and content
|
|
329
|
-
*
|
|
330
|
-
*/
|
|
331
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
332
|
-
var e_1, _a;
|
|
333
|
-
var codeBlocks = [];
|
|
334
|
-
var lines = markdown.split('\n');
|
|
335
|
-
var currentCodeBlock = null;
|
|
302
|
+
// Note: Check each template individually
|
|
303
|
+
var definedParameters = new Set(promptbook.parameters.filter(function (_a) {
|
|
304
|
+
var isInput = _a.isInput;
|
|
305
|
+
return isInput;
|
|
306
|
+
}).map(function (_a) {
|
|
307
|
+
var name = _a.name;
|
|
308
|
+
return name;
|
|
309
|
+
}));
|
|
336
310
|
try {
|
|
337
|
-
for (var
|
|
338
|
-
var
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
if (currentCodeBlock === null) {
|
|
342
|
-
currentCodeBlock = { language: language, content: '' };
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
if (language !== null) {
|
|
346
|
-
// [🌻]
|
|
347
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
348
|
-
}
|
|
349
|
-
codeBlocks.push(currentCodeBlock);
|
|
350
|
-
currentCodeBlock = null;
|
|
351
|
-
}
|
|
311
|
+
for (var _g = __values(promptbook.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
312
|
+
var template = _h.value;
|
|
313
|
+
if (definedParameters.has(template.resultingParameterName)) {
|
|
314
|
+
throw new PromptbookLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
352
315
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
316
|
+
definedParameters.add(template.resultingParameterName);
|
|
317
|
+
if (template.executionType === 'PROMPT_TEMPLATE' &&
|
|
318
|
+
(template.modelRequirements.modelVariant === undefined)) {
|
|
319
|
+
throw new PromptbookLogicError(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 ")));
|
|
320
|
+
}
|
|
321
|
+
if (template.jokers && template.jokers.length > 0) {
|
|
322
|
+
if (!template.expectFormat &&
|
|
323
|
+
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
324
|
+
throw new PromptbookLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
328
|
+
var joker = _k.value;
|
|
329
|
+
if (!template.dependentParameterNames.includes(joker)) {
|
|
330
|
+
throw new PromptbookLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
335
|
+
finally {
|
|
336
|
+
try {
|
|
337
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
338
|
+
}
|
|
339
|
+
finally { if (e_3) throw e_3.error; }
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (template.expectations) {
|
|
343
|
+
try {
|
|
344
|
+
for (var _l = (e_4 = void 0, __values(Object.entries(template.expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
345
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
346
|
+
if (min !== undefined && max !== undefined && min > max) {
|
|
347
|
+
throw new PromptbookLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
348
|
+
}
|
|
349
|
+
if (min !== undefined && min < 0) {
|
|
350
|
+
throw new PromptbookLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
|
|
351
|
+
}
|
|
352
|
+
if (max !== undefined && max <= 0) {
|
|
353
|
+
throw new PromptbookLogicError("Max expectation of ".concat(unit, " must be positive"));
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
358
|
+
finally {
|
|
359
|
+
try {
|
|
360
|
+
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
361
|
+
}
|
|
362
|
+
finally { if (e_4) throw e_4.error; }
|
|
356
363
|
}
|
|
357
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
358
364
|
}
|
|
359
365
|
}
|
|
360
366
|
}
|
|
361
|
-
catch (
|
|
367
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
362
368
|
finally {
|
|
363
369
|
try {
|
|
364
|
-
if (
|
|
370
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
365
371
|
}
|
|
366
|
-
finally { if (
|
|
372
|
+
finally { if (e_2) throw e_2.error; }
|
|
367
373
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
374
|
+
// Note: Detect circular dependencies
|
|
375
|
+
var resovedParameters = promptbook.parameters
|
|
376
|
+
.filter(function (_a) {
|
|
377
|
+
var isInput = _a.isInput;
|
|
378
|
+
return isInput;
|
|
379
|
+
})
|
|
380
|
+
.map(function (_a) {
|
|
381
|
+
var name = _a.name;
|
|
382
|
+
return name;
|
|
383
|
+
});
|
|
384
|
+
var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
385
|
+
var loopLimit = LOOP_LIMIT;
|
|
386
|
+
var _loop_2 = function () {
|
|
387
|
+
if (loopLimit-- < 0) {
|
|
388
|
+
throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePromptbookJson`');
|
|
389
|
+
}
|
|
390
|
+
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
391
|
+
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
392
|
+
});
|
|
393
|
+
if (currentlyResovedTemplates.length === 0) {
|
|
394
|
+
throw new PromptbookLogicError(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
|
|
395
|
+
.map(function (_a) {
|
|
396
|
+
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
397
|
+
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
398
|
+
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
399
|
+
.join(', '));
|
|
400
|
+
})
|
|
401
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
402
|
+
}
|
|
403
|
+
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
|
|
404
|
+
var resultingParameterName = _a.resultingParameterName;
|
|
405
|
+
return resultingParameterName;
|
|
406
|
+
})), false);
|
|
407
|
+
unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
|
|
408
|
+
};
|
|
409
|
+
while (unresovedTemplates.length > 0) {
|
|
410
|
+
_loop_2();
|
|
371
411
|
}
|
|
372
|
-
return
|
|
412
|
+
return promptbook;
|
|
373
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* TODO: [🧠] Work with promptbookVersion
|
|
416
|
+
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
417
|
+
* > /**
|
|
418
|
+
* > * Validates PromptbookJson if it is logically valid.
|
|
419
|
+
* > *
|
|
420
|
+
* > * It checks:
|
|
421
|
+
* > * - it has a valid structure
|
|
422
|
+
* > * - ...
|
|
423
|
+
* > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
|
|
424
|
+
*/
|
|
374
425
|
|
|
375
426
|
/**
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* Note: If there are multiple or no code blocks the function throws an error
|
|
379
|
-
*
|
|
380
|
-
* Note: There are 3 simmilar function:
|
|
381
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
382
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
383
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
427
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
384
428
|
*
|
|
385
|
-
* @
|
|
386
|
-
*
|
|
429
|
+
* @private Always catched and rethrown as `PromptbookExecutionError`
|
|
430
|
+
* Note: This is a kindof subtype of PromptbookExecutionError
|
|
387
431
|
*/
|
|
388
|
-
function
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
432
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
433
|
+
__extends(ExpectError, _super);
|
|
434
|
+
function ExpectError(message) {
|
|
435
|
+
var _this = _super.call(this, message) || this;
|
|
436
|
+
_this.name = 'ExpectError';
|
|
437
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
438
|
+
return _this;
|
|
393
439
|
}
|
|
394
|
-
return
|
|
395
|
-
}
|
|
396
|
-
/***
|
|
397
|
-
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
398
|
-
*/
|
|
440
|
+
return ExpectError;
|
|
441
|
+
}(Error));
|
|
399
442
|
|
|
400
443
|
/**
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
* @param {string} content - The string to remove comments from.
|
|
404
|
-
* @returns {string} The input string with all comments removed.
|
|
444
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
405
445
|
*/
|
|
406
|
-
function
|
|
407
|
-
|
|
446
|
+
function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
447
|
+
try {
|
|
448
|
+
JSON.parse(value);
|
|
449
|
+
return true;
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
if (!(error instanceof Error)) {
|
|
453
|
+
throw error;
|
|
454
|
+
}
|
|
455
|
+
if (error.message.includes('Unexpected token')) {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
408
460
|
}
|
|
409
461
|
|
|
410
462
|
/**
|
|
411
|
-
*
|
|
463
|
+
* The version of the Promptbook library
|
|
412
464
|
*/
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
465
|
+
var PROMPTBOOK_VERSION = '0.59.0-13';
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Function `addUsage` will add multiple usages into one
|
|
469
|
+
*
|
|
470
|
+
* Note: If you provide 0 values, it returns void usage
|
|
471
|
+
*/
|
|
472
|
+
function addUsage() {
|
|
473
|
+
var usageItems = [];
|
|
416
474
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
var
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
475
|
+
usageItems[_i] = arguments[_i];
|
|
476
|
+
}
|
|
477
|
+
var initialStructure = {
|
|
478
|
+
price: { value: 0 },
|
|
479
|
+
input: {
|
|
480
|
+
tokensCount: { value: 0 },
|
|
481
|
+
charactersCount: { value: 0 },
|
|
482
|
+
wordsCount: { value: 0 },
|
|
483
|
+
sentencesCount: { value: 0 },
|
|
484
|
+
linesCount: { value: 0 },
|
|
485
|
+
paragraphsCount: { value: 0 },
|
|
486
|
+
pagesCount: { value: 0 },
|
|
487
|
+
},
|
|
488
|
+
output: {
|
|
489
|
+
tokensCount: { value: 0 },
|
|
490
|
+
charactersCount: { value: 0 },
|
|
491
|
+
wordsCount: { value: 0 },
|
|
492
|
+
sentencesCount: { value: 0 },
|
|
493
|
+
linesCount: { value: 0 },
|
|
494
|
+
paragraphsCount: { value: 0 },
|
|
495
|
+
pagesCount: { value: 0 },
|
|
496
|
+
},
|
|
497
|
+
};
|
|
498
|
+
return usageItems.reduce(function (acc, item) {
|
|
499
|
+
var e_1, _a, e_2, _b;
|
|
500
|
+
var _c;
|
|
501
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
502
|
+
try {
|
|
503
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
504
|
+
var key = _e.value;
|
|
505
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
506
|
+
//@ts-ignore
|
|
507
|
+
if (item.input[key]) {
|
|
508
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
509
|
+
//@ts-ignore
|
|
510
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
511
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
512
|
+
//@ts-ignore
|
|
513
|
+
if (item.input[key].isUncertain) {
|
|
514
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
515
|
+
//@ts-ignore
|
|
516
|
+
acc.input[key].isUncertain = true;
|
|
517
|
+
}
|
|
427
518
|
}
|
|
428
519
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
finally { if (e_2) throw e_2.error; }
|
|
520
|
+
}
|
|
521
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
522
|
+
finally {
|
|
523
|
+
try {
|
|
524
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
435
525
|
}
|
|
526
|
+
finally { if (e_1) throw e_1.error; }
|
|
436
527
|
}
|
|
437
|
-
}
|
|
438
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
439
|
-
finally {
|
|
440
528
|
try {
|
|
441
|
-
|
|
529
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
530
|
+
var key = _g.value;
|
|
531
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
532
|
+
//@ts-ignore
|
|
533
|
+
if (item.output[key]) {
|
|
534
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
535
|
+
//@ts-ignore
|
|
536
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
537
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
538
|
+
//@ts-ignore
|
|
539
|
+
if (item.output[key].isUncertain) {
|
|
540
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
541
|
+
//@ts-ignore
|
|
542
|
+
acc.output[key].isUncertain = true;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
442
546
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
547
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
548
|
+
finally {
|
|
549
|
+
try {
|
|
550
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
551
|
+
}
|
|
552
|
+
finally { if (e_2) throw e_2.error; }
|
|
553
|
+
}
|
|
554
|
+
return acc;
|
|
555
|
+
}, initialStructure);
|
|
446
556
|
}
|
|
447
557
|
|
|
448
558
|
/**
|
|
449
|
-
*
|
|
559
|
+
* Counts number of characters in the text
|
|
450
560
|
*/
|
|
451
|
-
|
|
561
|
+
function countCharacters(text) {
|
|
562
|
+
// Remove null characters
|
|
563
|
+
text = text.replace(/\0/g, '');
|
|
564
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
565
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
566
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
567
|
+
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
568
|
+
return text.length;
|
|
569
|
+
}
|
|
452
570
|
|
|
453
571
|
/**
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
* @param template the template with parameters in {curly} braces
|
|
457
|
-
* @returns the list of parameter names
|
|
572
|
+
* Counts number of lines in the text
|
|
458
573
|
*/
|
|
459
|
-
function
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
var parameterNames = new Set();
|
|
463
|
-
try {
|
|
464
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
465
|
-
var match = matches_1_1.value;
|
|
466
|
-
var parameterName = match[0].slice(1, -1);
|
|
467
|
-
parameterNames.add(parameterName);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
471
|
-
finally {
|
|
472
|
-
try {
|
|
473
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
474
|
-
}
|
|
475
|
-
finally { if (e_1) throw e_1.error; }
|
|
574
|
+
function countLines(text) {
|
|
575
|
+
if (text === '') {
|
|
576
|
+
return 0;
|
|
476
577
|
}
|
|
477
|
-
return
|
|
578
|
+
return text.split('\n').length;
|
|
478
579
|
}
|
|
479
580
|
|
|
480
581
|
/**
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
* @param script from which to extract the variables
|
|
484
|
-
* @returns the list of variable names
|
|
485
|
-
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
582
|
+
* Counts number of pages in the text
|
|
486
583
|
*/
|
|
487
|
-
function
|
|
488
|
-
var
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
try {
|
|
493
|
-
eval(script);
|
|
494
|
-
}
|
|
495
|
-
catch (error) {
|
|
496
|
-
if (!(error instanceof ReferenceError)) {
|
|
497
|
-
throw error;
|
|
498
|
-
}
|
|
499
|
-
var undefinedName = error.message.split(' ')[0];
|
|
500
|
-
/*
|
|
501
|
-
Note: Remapping error
|
|
502
|
-
From: [ReferenceError: thing is not defined],
|
|
503
|
-
To: [Error: Parameter {thing} is not defined],
|
|
504
|
-
*/
|
|
505
|
-
if (!undefinedName) {
|
|
506
|
-
throw error;
|
|
507
|
-
}
|
|
508
|
-
if (script.includes(undefinedName + '(')) {
|
|
509
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
510
|
-
}
|
|
511
|
-
else {
|
|
512
|
-
variables.add(undefinedName);
|
|
513
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
catch (error) {
|
|
518
|
-
if (!(error instanceof Error)) {
|
|
519
|
-
throw error;
|
|
520
|
-
}
|
|
521
|
-
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
522
|
-
}
|
|
523
|
-
return variables;
|
|
584
|
+
function countPages(text) {
|
|
585
|
+
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
586
|
+
var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
587
|
+
var pageCount = Math.ceil(sentences.length / sentencesPerPage);
|
|
588
|
+
return pageCount;
|
|
524
589
|
}
|
|
525
|
-
/**
|
|
526
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
527
|
-
*/
|
|
528
590
|
|
|
529
591
|
/**
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
* @param promptTemplate the template with used parameters
|
|
533
|
-
* @returns the set of parameter names
|
|
534
|
-
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
535
|
-
*/
|
|
536
|
-
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
537
|
-
var e_1, _a, e_2, _b;
|
|
538
|
-
var parameterNames = new Set();
|
|
539
|
-
try {
|
|
540
|
-
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()) {
|
|
541
|
-
var parameterName = _d.value;
|
|
542
|
-
parameterNames.add(parameterName);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
546
|
-
finally {
|
|
547
|
-
try {
|
|
548
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
549
|
-
}
|
|
550
|
-
finally { if (e_1) throw e_1.error; }
|
|
551
|
-
}
|
|
552
|
-
if (promptTemplate.executionType === 'SCRIPT') {
|
|
553
|
-
try {
|
|
554
|
-
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
555
|
-
var parameterName = _f.value;
|
|
556
|
-
parameterNames.add(parameterName);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
560
|
-
finally {
|
|
561
|
-
try {
|
|
562
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
563
|
-
}
|
|
564
|
-
finally { if (e_2) throw e_2.error; }
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return parameterNames;
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* TODO: [🔣] If script require contentLanguage
|
|
592
|
+
* Counts number of paragraphs in the text
|
|
571
593
|
*/
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
/*
|
|
575
|
-
TODO: Tests
|
|
576
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
577
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
578
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
579
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
580
|
-
*/
|
|
581
|
-
function normalizeTo_SCREAMING_CASE(sentence) {
|
|
582
|
-
var e_1, _a;
|
|
583
|
-
var charType;
|
|
584
|
-
var lastCharType = 'OTHER';
|
|
585
|
-
var normalizedName = '';
|
|
586
|
-
try {
|
|
587
|
-
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
588
|
-
var char = sentence_1_1.value;
|
|
589
|
-
var normalizedChar = void 0;
|
|
590
|
-
if (/^[a-z]$/.test(char)) {
|
|
591
|
-
charType = 'LOWERCASE';
|
|
592
|
-
normalizedChar = char.toUpperCase();
|
|
593
|
-
}
|
|
594
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
595
|
-
charType = 'UPPERCASE';
|
|
596
|
-
normalizedChar = char;
|
|
597
|
-
}
|
|
598
|
-
else if (/^[0-9]$/.test(char)) {
|
|
599
|
-
charType = 'NUMBER';
|
|
600
|
-
normalizedChar = char;
|
|
601
|
-
}
|
|
602
|
-
else if (/^\/$/.test(char)) {
|
|
603
|
-
charType = 'SLASH';
|
|
604
|
-
normalizedChar = char;
|
|
605
|
-
}
|
|
606
|
-
else {
|
|
607
|
-
charType = 'OTHER';
|
|
608
|
-
normalizedChar = '_';
|
|
609
|
-
}
|
|
610
|
-
if (charType !== lastCharType &&
|
|
611
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
612
|
-
!(lastCharType === 'NUMBER') &&
|
|
613
|
-
!(charType === 'NUMBER')) {
|
|
614
|
-
normalizedName += '_';
|
|
615
|
-
}
|
|
616
|
-
normalizedName += normalizedChar;
|
|
617
|
-
lastCharType = charType;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
621
|
-
finally {
|
|
622
|
-
try {
|
|
623
|
-
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
624
|
-
}
|
|
625
|
-
finally { if (e_1) throw e_1.error; }
|
|
626
|
-
}
|
|
627
|
-
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
628
|
-
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
629
|
-
normalizedName = normalizedName.replace(/^_/, '');
|
|
630
|
-
normalizedName = normalizedName.replace(/_$/, '');
|
|
631
|
-
return normalizedName;
|
|
594
|
+
function countParagraphs(text) {
|
|
595
|
+
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
632
596
|
}
|
|
633
|
-
/**
|
|
634
|
-
* TODO: [🌺] Use some intermediate util splitWords
|
|
635
|
-
*/
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
* Execution type describes the way how the block is executed
|
|
639
|
-
*
|
|
640
|
-
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
641
|
-
*/
|
|
642
|
-
var ExecutionTypes = [
|
|
643
|
-
'PROMPT_TEMPLATE',
|
|
644
|
-
'SIMPLE_TEMPLATE',
|
|
645
|
-
'SCRIPT',
|
|
646
|
-
'PROMPT_DIALOG',
|
|
647
|
-
// <- [🥻] Insert here when making new command
|
|
648
|
-
];
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* Units of text measurement
|
|
652
|
-
*/
|
|
653
|
-
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
654
|
-
/**
|
|
655
|
-
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
656
|
-
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
657
|
-
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
658
|
-
*/
|
|
659
597
|
|
|
660
598
|
/**
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
* @param {string} str - The string to remove Markdown tags from.
|
|
664
|
-
* @returns {string} The input string with all Markdown tags removed.
|
|
599
|
+
* Split text into sentences
|
|
665
600
|
*/
|
|
666
|
-
function
|
|
667
|
-
|
|
668
|
-
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
669
|
-
// Remove italic formatting
|
|
670
|
-
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
671
|
-
// Remove code formatting
|
|
672
|
-
str = str.replace(/`(.*?)`/g, '$1');
|
|
673
|
-
return str;
|
|
601
|
+
function splitIntoSentences(text) {
|
|
602
|
+
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
674
603
|
}
|
|
675
|
-
|
|
676
604
|
/**
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
680
|
-
* Note: it also works only with decimal numbers
|
|
681
|
-
*
|
|
682
|
-
* @returns parsed number
|
|
683
|
-
* @throws {PromptbookSyntaxError} if the value is not a number
|
|
684
|
-
*
|
|
685
|
-
* @private within the parseCommand
|
|
605
|
+
* Counts number of sentences in the text
|
|
686
606
|
*/
|
|
687
|
-
function
|
|
688
|
-
|
|
689
|
-
if (typeof value === 'number') {
|
|
690
|
-
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
691
|
-
}
|
|
692
|
-
if (typeof value !== 'string') {
|
|
693
|
-
return 0;
|
|
694
|
-
}
|
|
695
|
-
value = value.trim();
|
|
696
|
-
if (value.startsWith('+')) {
|
|
697
|
-
return parseNumber(value.substring(1));
|
|
698
|
-
}
|
|
699
|
-
if (value.startsWith('-')) {
|
|
700
|
-
var number = parseNumber(value.substring(1));
|
|
701
|
-
if (number === 0) {
|
|
702
|
-
return 0; // <- Note: To prevent -0
|
|
703
|
-
}
|
|
704
|
-
return -number;
|
|
705
|
-
}
|
|
706
|
-
value = value.replace(/,/g, '.');
|
|
707
|
-
value = value.toUpperCase();
|
|
708
|
-
if (value === '') {
|
|
709
|
-
return 0;
|
|
710
|
-
}
|
|
711
|
-
if (value === '♾' || value.startsWith('INF')) {
|
|
712
|
-
return Infinity;
|
|
713
|
-
}
|
|
714
|
-
if (value.includes('/')) {
|
|
715
|
-
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
716
|
-
var numerator = parseNumber(numerator_);
|
|
717
|
-
var denominator = parseNumber(denominator_);
|
|
718
|
-
if (denominator === 0) {
|
|
719
|
-
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
720
|
-
}
|
|
721
|
-
return numerator / denominator;
|
|
722
|
-
}
|
|
723
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
724
|
-
return 0;
|
|
725
|
-
}
|
|
726
|
-
if (value.includes('E')) {
|
|
727
|
-
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
728
|
-
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
729
|
-
}
|
|
730
|
-
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
731
|
-
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
732
|
-
}
|
|
733
|
-
var num = parseFloat(value);
|
|
734
|
-
if (isNaN(num)) {
|
|
735
|
-
throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
736
|
-
}
|
|
737
|
-
return num;
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
741
|
-
*/
|
|
742
|
-
|
|
743
|
-
/**
|
|
744
|
-
* Parses one line of ul/ol to command
|
|
745
|
-
*
|
|
746
|
-
* @returns parsed command object
|
|
747
|
-
* @throws {PromptbookSyntaxError} if the command is invalid
|
|
748
|
-
*
|
|
749
|
-
* @private within the promptbookStringToJson
|
|
750
|
-
*/
|
|
751
|
-
function parseCommand(listItem) {
|
|
752
|
-
var e_1, _a;
|
|
753
|
-
if (listItem.includes('\n') || listItem.includes('\r')) {
|
|
754
|
-
throw new PromptbookSyntaxError('Command can not contain new line characters:');
|
|
755
|
-
}
|
|
756
|
-
var type = listItem.trim();
|
|
757
|
-
type = type.split('`').join('');
|
|
758
|
-
type = type.split('"').join('');
|
|
759
|
-
type = type.split("'").join('');
|
|
760
|
-
type = type.split('~').join('');
|
|
761
|
-
type = type.split('[').join('');
|
|
762
|
-
type = type.split(']').join('');
|
|
763
|
-
type = type.split('(').join('');
|
|
764
|
-
type = type.split(')').join('');
|
|
765
|
-
type = normalizeTo_SCREAMING_CASE(type);
|
|
766
|
-
type = type.split('DIALOGUE').join('DIALOG');
|
|
767
|
-
var listItemParts = listItem
|
|
768
|
-
.split(' ')
|
|
769
|
-
.map(function (part) { return part.trim(); })
|
|
770
|
-
.filter(function (item) { return item !== ''; })
|
|
771
|
-
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
772
|
-
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
773
|
-
.map(removeMarkdownFormatting);
|
|
774
|
-
if (type.startsWith('URL') ||
|
|
775
|
-
type.startsWith('PTBK_URL') ||
|
|
776
|
-
type.startsWith('PTBKURL') ||
|
|
777
|
-
type.startsWith('PROMPTBOOK_URL') ||
|
|
778
|
-
type.startsWith('PROMPTBOOKURL') ||
|
|
779
|
-
type.startsWith('HTTPS')) {
|
|
780
|
-
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
781
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
782
|
-
}
|
|
783
|
-
var promptbookUrlString = listItemParts.pop();
|
|
784
|
-
var promptbookUrl = new URL(promptbookUrlString);
|
|
785
|
-
if (promptbookUrl.protocol !== 'https:') {
|
|
786
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
787
|
-
}
|
|
788
|
-
if (promptbookUrl.hash !== '') {
|
|
789
|
-
throw new PromptbookSyntaxError(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 ")));
|
|
790
|
-
}
|
|
791
|
-
return {
|
|
792
|
-
type: 'PROMPTBOOK_URL',
|
|
793
|
-
promptbookUrl: promptbookUrl,
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
797
|
-
if (listItemParts.length !== 2) {
|
|
798
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
799
|
-
}
|
|
800
|
-
var promptbookVersion = listItemParts.pop();
|
|
801
|
-
// TODO: Validate version
|
|
802
|
-
return {
|
|
803
|
-
type: 'PROMPTBOOK_VERSION',
|
|
804
|
-
promptbookVersion: promptbookVersion,
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
else if (type.startsWith('EXECUTE') ||
|
|
808
|
-
type.startsWith('EXEC') ||
|
|
809
|
-
type.startsWith('PROMPT_DIALOG') ||
|
|
810
|
-
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
811
|
-
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
812
|
-
if (executionTypes.length !== 1) {
|
|
813
|
-
throw new PromptbookSyntaxError(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 "); }));
|
|
814
|
-
}
|
|
815
|
-
return {
|
|
816
|
-
type: 'EXECUTE',
|
|
817
|
-
executionType: executionTypes[0],
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
else if (type.startsWith('MODEL')) {
|
|
821
|
-
// TODO: Make this more elegant and dynamically
|
|
822
|
-
if (type.startsWith('MODEL_VARIANT')) {
|
|
823
|
-
if (type === 'MODEL_VARIANT_CHAT') {
|
|
824
|
-
return {
|
|
825
|
-
type: 'MODEL',
|
|
826
|
-
key: 'modelVariant',
|
|
827
|
-
value: 'CHAT',
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
else if (type === 'MODEL_VARIANT_COMPLETION') {
|
|
831
|
-
return {
|
|
832
|
-
type: 'MODEL',
|
|
833
|
-
key: 'modelVariant',
|
|
834
|
-
value: 'COMPLETION',
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
else {
|
|
838
|
-
throw new PromptbookSyntaxError(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 "); }));
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
if (type.startsWith('MODEL_NAME')) {
|
|
842
|
-
return {
|
|
843
|
-
type: 'MODEL',
|
|
844
|
-
key: 'modelName',
|
|
845
|
-
value: listItemParts.pop(),
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
else {
|
|
849
|
-
throw new PromptbookSyntaxError(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 "); }));
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
else if (type.startsWith('PARAM') ||
|
|
853
|
-
type.startsWith('INPUT_PARAM') ||
|
|
854
|
-
type.startsWith('OUTPUT_PARAM') ||
|
|
855
|
-
listItem.startsWith('{') ||
|
|
856
|
-
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
857
|
-
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
858
|
-
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
859
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
860
|
-
}
|
|
861
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
862
|
-
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
863
|
-
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
864
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
865
|
-
}
|
|
866
|
-
var isInput = type.startsWith('INPUT');
|
|
867
|
-
var isOutput = type.startsWith('OUTPUT');
|
|
868
|
-
if (listItem.startsWith('> {')) {
|
|
869
|
-
isInput = false;
|
|
870
|
-
isOutput = false;
|
|
871
|
-
}
|
|
872
|
-
return {
|
|
873
|
-
type: 'PARAMETER',
|
|
874
|
-
parameterName: parameterName,
|
|
875
|
-
parameterDescription: parameterDescription.trim() || null,
|
|
876
|
-
isInput: isInput,
|
|
877
|
-
isOutput: isOutput,
|
|
878
|
-
};
|
|
879
|
-
}
|
|
880
|
-
else if (type.startsWith('JOKER')) {
|
|
881
|
-
if (listItemParts.length !== 2) {
|
|
882
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
883
|
-
}
|
|
884
|
-
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
885
|
-
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
886
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
887
|
-
}
|
|
888
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
889
|
-
var parameterName = parametersMatch.groups.parameterName;
|
|
890
|
-
return {
|
|
891
|
-
type: 'JOKER',
|
|
892
|
-
parameterName: parameterName,
|
|
893
|
-
};
|
|
894
|
-
}
|
|
895
|
-
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
896
|
-
if (listItemParts.length !== 2) {
|
|
897
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
898
|
-
}
|
|
899
|
-
var functionName = listItemParts.pop();
|
|
900
|
-
return {
|
|
901
|
-
type: 'POSTPROCESS',
|
|
902
|
-
functionName: functionName,
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
else if (type.startsWith('EXPECT_JSON')) {
|
|
906
|
-
return {
|
|
907
|
-
type: 'EXPECT_FORMAT',
|
|
908
|
-
format: 'JSON',
|
|
909
|
-
};
|
|
910
|
-
// [🥤]
|
|
911
|
-
}
|
|
912
|
-
else if (type.startsWith('EXPECT')) {
|
|
913
|
-
try {
|
|
914
|
-
listItemParts.shift();
|
|
915
|
-
var sign = void 0;
|
|
916
|
-
var signRaw = listItemParts.shift();
|
|
917
|
-
if (/^exact/i.test(signRaw)) {
|
|
918
|
-
sign = 'EXACTLY';
|
|
919
|
-
}
|
|
920
|
-
else if (/^min/i.test(signRaw)) {
|
|
921
|
-
sign = 'MINIMUM';
|
|
922
|
-
}
|
|
923
|
-
else if (/^max/i.test(signRaw)) {
|
|
924
|
-
sign = 'MAXIMUM';
|
|
925
|
-
}
|
|
926
|
-
else {
|
|
927
|
-
throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
|
|
928
|
-
}
|
|
929
|
-
var amountRaw = listItemParts.shift();
|
|
930
|
-
var amount = parseNumber(amountRaw);
|
|
931
|
-
if (amount < 0) {
|
|
932
|
-
throw new PromptbookSyntaxError('Amount must be positive number or zero');
|
|
933
|
-
}
|
|
934
|
-
if (amount !== Math.floor(amount)) {
|
|
935
|
-
throw new PromptbookSyntaxError('Amount must be whole number');
|
|
936
|
-
}
|
|
937
|
-
var unitRaw = listItemParts.shift();
|
|
938
|
-
var unit = undefined;
|
|
939
|
-
try {
|
|
940
|
-
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()) {
|
|
941
|
-
var existingUnit = EXPECTATION_UNITS_1_1.value;
|
|
942
|
-
var existingUnitText = existingUnit;
|
|
943
|
-
existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
|
|
944
|
-
if (existingUnitText === 'CHARACTER') {
|
|
945
|
-
existingUnitText = 'CHAR';
|
|
946
|
-
}
|
|
947
|
-
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
948
|
-
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
949
|
-
if (unit !== undefined) {
|
|
950
|
-
throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
951
|
-
}
|
|
952
|
-
unit = existingUnit;
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
957
|
-
finally {
|
|
958
|
-
try {
|
|
959
|
-
if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
|
|
960
|
-
}
|
|
961
|
-
finally { if (e_1) throw e_1.error; }
|
|
962
|
-
}
|
|
963
|
-
if (unit === undefined) {
|
|
964
|
-
throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
|
|
965
|
-
}
|
|
966
|
-
return {
|
|
967
|
-
type: 'EXPECT_AMOUNT',
|
|
968
|
-
sign: sign,
|
|
969
|
-
unit: unit,
|
|
970
|
-
amount: amount,
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
catch (error) {
|
|
974
|
-
if (!(error instanceof Error)) {
|
|
975
|
-
throw error;
|
|
976
|
-
}
|
|
977
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
978
|
-
}
|
|
979
|
-
/*
|
|
980
|
-
} else if (type.startsWith('__________________')) {
|
|
981
|
-
// <- [🥻] Insert here when making new command
|
|
982
|
-
*/
|
|
983
|
-
}
|
|
984
|
-
else {
|
|
985
|
-
throw new PromptbookSyntaxError(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 ")));
|
|
986
|
-
}
|
|
607
|
+
function countSentences(text) {
|
|
608
|
+
return splitIntoSentences(text).length;
|
|
987
609
|
}
|
|
988
610
|
|
|
989
611
|
var defaultDiacriticsRemovalMap = [
|
|
@@ -1195,1042 +817,2386 @@ var defaultDiacriticsRemovalMap = [
|
|
|
1195
817
|
},
|
|
1196
818
|
];
|
|
1197
819
|
/**
|
|
1198
|
-
* Map of letters from diacritic variant to diacritless variant
|
|
1199
|
-
* Contains lowercase and uppercase separatelly
|
|
820
|
+
* Map of letters from diacritic variant to diacritless variant
|
|
821
|
+
* Contains lowercase and uppercase separatelly
|
|
822
|
+
*
|
|
823
|
+
* > "á" => "a"
|
|
824
|
+
* > "ě" => "e"
|
|
825
|
+
* > "Ă" => "A"
|
|
826
|
+
* > ...
|
|
827
|
+
*/
|
|
828
|
+
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
829
|
+
// tslint:disable-next-line: prefer-for-of
|
|
830
|
+
for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
831
|
+
var letters = defaultDiacriticsRemovalMap[i].letters;
|
|
832
|
+
// tslint:disable-next-line: prefer-for-of
|
|
833
|
+
for (var j = 0; j < letters.length; j++) {
|
|
834
|
+
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
838
|
+
/*
|
|
839
|
+
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
840
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
841
|
+
you may not use this file except in compliance with the License.
|
|
842
|
+
You may obtain a copy of the License at
|
|
843
|
+
|
|
844
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
845
|
+
|
|
846
|
+
Unless required by applicable law or agreed to in writing, software
|
|
847
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
848
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
849
|
+
See the License for the specific language governing permissions and
|
|
850
|
+
limitations under the License.
|
|
851
|
+
*/
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
*
|
|
855
|
+
*/
|
|
856
|
+
function removeDiacritics(input) {
|
|
857
|
+
/*eslint no-control-regex: "off"*/
|
|
858
|
+
return input.replace(/[^\u0000-\u007E]/g, function (a) {
|
|
859
|
+
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Counts number of words in the text
|
|
865
|
+
*/
|
|
866
|
+
function countWords(text) {
|
|
867
|
+
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
868
|
+
text = removeDiacritics(text);
|
|
869
|
+
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Index of all counter functions
|
|
874
|
+
*/
|
|
875
|
+
var CountUtils = {
|
|
876
|
+
CHARACTERS: countCharacters,
|
|
877
|
+
WORDS: countWords,
|
|
878
|
+
SENTENCES: countSentences,
|
|
879
|
+
PARAGRAPHS: countParagraphs,
|
|
880
|
+
LINES: countLines,
|
|
881
|
+
PAGES: countPages,
|
|
882
|
+
};
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Function checkExpectations will check if the expectations on given value are met
|
|
886
|
+
*
|
|
887
|
+
* Note: There are two simmilar functions:
|
|
888
|
+
* - `checkExpectations` which throws an error if the expectations are not met
|
|
889
|
+
* - `isPassingExpectations` which returns a boolean
|
|
890
|
+
*
|
|
891
|
+
* @throws {ExpectError} if the expectations are not met
|
|
892
|
+
* @returns {void} Nothing
|
|
893
|
+
*/
|
|
894
|
+
function checkExpectations(expectations, value) {
|
|
895
|
+
var e_1, _a;
|
|
896
|
+
try {
|
|
897
|
+
for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
898
|
+
var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
|
|
899
|
+
var amount = CountUtils[unit.toUpperCase()](value);
|
|
900
|
+
if (min && amount < min) {
|
|
901
|
+
throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
|
|
902
|
+
} /* not else */
|
|
903
|
+
if (max && amount > max) {
|
|
904
|
+
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
909
|
+
finally {
|
|
910
|
+
try {
|
|
911
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
912
|
+
}
|
|
913
|
+
finally { if (e_1) throw e_1.error; }
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* TODO: [💝] Unite object for expecting amount and format
|
|
918
|
+
*/
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* This error occurs during the parameter replacement in the template
|
|
922
|
+
*
|
|
923
|
+
* Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
|
|
924
|
+
*/
|
|
925
|
+
var TemplateError = /** @class */ (function (_super) {
|
|
926
|
+
__extends(TemplateError, _super);
|
|
927
|
+
function TemplateError(message) {
|
|
928
|
+
var _this = _super.call(this, message) || this;
|
|
929
|
+
_this.name = 'TemplateError';
|
|
930
|
+
Object.setPrototypeOf(_this, TemplateError.prototype);
|
|
931
|
+
return _this;
|
|
932
|
+
}
|
|
933
|
+
return TemplateError;
|
|
934
|
+
}(Error));
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Replaces parameters in template with values from parameters object
|
|
938
|
+
*
|
|
939
|
+
* @param template the template with parameters in {curly} braces
|
|
940
|
+
* @param parameters the object with parameters
|
|
941
|
+
* @returns the template with replaced parameters
|
|
942
|
+
* @throws {TemplateError} if parameter is not defined, not closed, or not opened
|
|
943
|
+
*
|
|
944
|
+
* @private within the createPromptbookExecutor
|
|
945
|
+
*/
|
|
946
|
+
function replaceParameters(template, parameters) {
|
|
947
|
+
var replacedTemplate = template;
|
|
948
|
+
var match;
|
|
949
|
+
var loopLimit = LOOP_LIMIT;
|
|
950
|
+
var _loop_1 = function () {
|
|
951
|
+
if (loopLimit-- < 0) {
|
|
952
|
+
throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
953
|
+
}
|
|
954
|
+
var precol = match.groups.precol;
|
|
955
|
+
var parameterName = match.groups.parameterName;
|
|
956
|
+
if (parameterName === '') {
|
|
957
|
+
return "continue";
|
|
958
|
+
}
|
|
959
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
960
|
+
throw new TemplateError('Parameter is already opened or not closed');
|
|
961
|
+
}
|
|
962
|
+
if (parameters[parameterName] === undefined) {
|
|
963
|
+
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
964
|
+
}
|
|
965
|
+
var parameterValue = parameters[parameterName];
|
|
966
|
+
if (parameterValue === undefined) {
|
|
967
|
+
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
968
|
+
}
|
|
969
|
+
parameterValue = parameterValue.toString();
|
|
970
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
971
|
+
parameterValue = parameterValue
|
|
972
|
+
.split('\n')
|
|
973
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
974
|
+
.join('\n');
|
|
975
|
+
}
|
|
976
|
+
replacedTemplate =
|
|
977
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
978
|
+
parameterValue +
|
|
979
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
980
|
+
};
|
|
981
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
982
|
+
.exec(replacedTemplate))) {
|
|
983
|
+
_loop_1();
|
|
984
|
+
}
|
|
985
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
986
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
987
|
+
throw new TemplateError('Parameter is not closed');
|
|
988
|
+
}
|
|
989
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
990
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
991
|
+
throw new TemplateError('Parameter is not opened');
|
|
992
|
+
}
|
|
993
|
+
return replacedTemplate;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Creates executor function from promptbook and execution tools.
|
|
998
|
+
*
|
|
999
|
+
* @returns The executor function
|
|
1000
|
+
* @throws {PromptbookLogicError} on logical error in the promptbook
|
|
1001
|
+
*/
|
|
1002
|
+
function createPromptbookExecutor(options) {
|
|
1003
|
+
var _this = this;
|
|
1004
|
+
var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1005
|
+
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1006
|
+
validatePromptbookJson(promptbook);
|
|
1007
|
+
var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1008
|
+
function executeSingleTemplate(currentTemplate) {
|
|
1009
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1010
|
+
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;
|
|
1011
|
+
var e_2, _j, e_4, _k, e_3, _l, _m;
|
|
1012
|
+
var _this = this;
|
|
1013
|
+
return __generator(this, function (_o) {
|
|
1014
|
+
switch (_o.label) {
|
|
1015
|
+
case 0:
|
|
1016
|
+
name = "promptbook-executor-frame-".concat(currentTemplate.name);
|
|
1017
|
+
title = currentTemplate.title;
|
|
1018
|
+
priority = promptbook.promptTemplates.length - promptbook.promptTemplates.indexOf(currentTemplate);
|
|
1019
|
+
if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
1020
|
+
return [4 /*yield*/, onProgress({
|
|
1021
|
+
name: name,
|
|
1022
|
+
title: title,
|
|
1023
|
+
isStarted: false,
|
|
1024
|
+
isDone: false,
|
|
1025
|
+
executionType: currentTemplate.executionType,
|
|
1026
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
1027
|
+
parameterValue: null,
|
|
1028
|
+
// <- [3]
|
|
1029
|
+
})];
|
|
1030
|
+
case 1:
|
|
1031
|
+
_o.sent();
|
|
1032
|
+
_o.label = 2;
|
|
1033
|
+
case 2:
|
|
1034
|
+
result = null;
|
|
1035
|
+
resultString = null;
|
|
1036
|
+
expectError = null;
|
|
1037
|
+
maxAttempts = currentTemplate.executionType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
1038
|
+
jokers = currentTemplate.jokers || [];
|
|
1039
|
+
attempt = -jokers.length;
|
|
1040
|
+
_o.label = 3;
|
|
1041
|
+
case 3:
|
|
1042
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 49];
|
|
1043
|
+
isJokerAttempt = attempt < 0;
|
|
1044
|
+
joker = jokers[jokers.length + attempt];
|
|
1045
|
+
if (isJokerAttempt && !joker) {
|
|
1046
|
+
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
1047
|
+
}
|
|
1048
|
+
result = null;
|
|
1049
|
+
resultString = null;
|
|
1050
|
+
expectError = null;
|
|
1051
|
+
if (isJokerAttempt) {
|
|
1052
|
+
if (typeof parametersToPass[joker] === 'undefined') {
|
|
1053
|
+
throw new PromptbookExecutionError("Joker parameter {".concat(joker, "} not defined"));
|
|
1054
|
+
}
|
|
1055
|
+
resultString = parametersToPass[joker];
|
|
1056
|
+
}
|
|
1057
|
+
_o.label = 4;
|
|
1058
|
+
case 4:
|
|
1059
|
+
_o.trys.push([4, 45, 46, 47]);
|
|
1060
|
+
if (!!isJokerAttempt) return [3 /*break*/, 27];
|
|
1061
|
+
_a = currentTemplate.executionType;
|
|
1062
|
+
switch (_a) {
|
|
1063
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 5];
|
|
1064
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 6];
|
|
1065
|
+
case 'SCRIPT': return [3 /*break*/, 13];
|
|
1066
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 24];
|
|
1067
|
+
}
|
|
1068
|
+
return [3 /*break*/, 26];
|
|
1069
|
+
case 5:
|
|
1070
|
+
resultString = replaceParameters(currentTemplate.content, parametersToPass);
|
|
1071
|
+
return [3 /*break*/, 27];
|
|
1072
|
+
case 6:
|
|
1073
|
+
prompt = {
|
|
1074
|
+
title: currentTemplate.title,
|
|
1075
|
+
promptbookUrl: "".concat(promptbook.promptbookUrl
|
|
1076
|
+
? promptbook.promptbookUrl
|
|
1077
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
1078
|
+
parameters: parametersToPass,
|
|
1079
|
+
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
1080
|
+
modelRequirements: currentTemplate.modelRequirements,
|
|
1081
|
+
expectations: currentTemplate.expectations,
|
|
1082
|
+
expectFormat: currentTemplate.expectFormat,
|
|
1083
|
+
postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
1084
|
+
var errors, _a, _b, scriptTools, error_5, e_5_1;
|
|
1085
|
+
var e_5, _c;
|
|
1086
|
+
return __generator(this, function (_d) {
|
|
1087
|
+
switch (_d.label) {
|
|
1088
|
+
case 0:
|
|
1089
|
+
errors = [];
|
|
1090
|
+
_d.label = 1;
|
|
1091
|
+
case 1:
|
|
1092
|
+
_d.trys.push([1, 8, 9, 10]);
|
|
1093
|
+
_a = __values(tools.script), _b = _a.next();
|
|
1094
|
+
_d.label = 2;
|
|
1095
|
+
case 2:
|
|
1096
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
1097
|
+
scriptTools = _b.value;
|
|
1098
|
+
_d.label = 3;
|
|
1099
|
+
case 3:
|
|
1100
|
+
_d.trys.push([3, 5, , 6]);
|
|
1101
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
1102
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
1103
|
+
script: "".concat(functionName, "(result)"),
|
|
1104
|
+
parameters: {
|
|
1105
|
+
result: result || '',
|
|
1106
|
+
// Note: No ...parametersToPass, because working with result only
|
|
1107
|
+
},
|
|
1108
|
+
})];
|
|
1109
|
+
case 4: return [2 /*return*/, _d.sent()];
|
|
1110
|
+
case 5:
|
|
1111
|
+
error_5 = _d.sent();
|
|
1112
|
+
if (!(error_5 instanceof Error)) {
|
|
1113
|
+
throw error_5;
|
|
1114
|
+
}
|
|
1115
|
+
errors.push(error_5);
|
|
1116
|
+
return [3 /*break*/, 6];
|
|
1117
|
+
case 6:
|
|
1118
|
+
_b = _a.next();
|
|
1119
|
+
return [3 /*break*/, 2];
|
|
1120
|
+
case 7: return [3 /*break*/, 10];
|
|
1121
|
+
case 8:
|
|
1122
|
+
e_5_1 = _d.sent();
|
|
1123
|
+
e_5 = { error: e_5_1 };
|
|
1124
|
+
return [3 /*break*/, 10];
|
|
1125
|
+
case 9:
|
|
1126
|
+
try {
|
|
1127
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1128
|
+
}
|
|
1129
|
+
finally { if (e_5) throw e_5.error; }
|
|
1130
|
+
return [7 /*endfinally*/];
|
|
1131
|
+
case 10:
|
|
1132
|
+
if (errors.length === 0) {
|
|
1133
|
+
throw new PromptbookExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
|
|
1134
|
+
}
|
|
1135
|
+
else if (errors.length === 1) {
|
|
1136
|
+
throw errors[0];
|
|
1137
|
+
}
|
|
1138
|
+
else {
|
|
1139
|
+
throw new PromptbookExecutionError(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 "); }));
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
}); }; }),
|
|
1144
|
+
};
|
|
1145
|
+
_b = currentTemplate.modelRequirements.modelVariant;
|
|
1146
|
+
switch (_b) {
|
|
1147
|
+
case 'CHAT': return [3 /*break*/, 7];
|
|
1148
|
+
case 'COMPLETION': return [3 /*break*/, 9];
|
|
1149
|
+
}
|
|
1150
|
+
return [3 /*break*/, 11];
|
|
1151
|
+
case 7: return [4 /*yield*/, tools.llm.gptChat(prompt)];
|
|
1152
|
+
case 8:
|
|
1153
|
+
chatThread = _o.sent();
|
|
1154
|
+
// TODO: [🍬] Destroy chatThread
|
|
1155
|
+
result = chatThread;
|
|
1156
|
+
resultString = chatThread.content;
|
|
1157
|
+
return [3 /*break*/, 12];
|
|
1158
|
+
case 9: return [4 /*yield*/, tools.llm.gptComplete(prompt)];
|
|
1159
|
+
case 10:
|
|
1160
|
+
completionResult = _o.sent();
|
|
1161
|
+
result = completionResult;
|
|
1162
|
+
resultString = completionResult.content;
|
|
1163
|
+
return [3 /*break*/, 12];
|
|
1164
|
+
case 11: throw new PromptbookExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
1165
|
+
case 12: return [3 /*break*/, 27];
|
|
1166
|
+
case 13:
|
|
1167
|
+
if (tools.script.length === 0) {
|
|
1168
|
+
throw new PromptbookExecutionError('No script execution tools are available');
|
|
1169
|
+
}
|
|
1170
|
+
if (!currentTemplate.contentLanguage) {
|
|
1171
|
+
throw new PromptbookExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
1172
|
+
}
|
|
1173
|
+
// TODO: DRY [1]
|
|
1174
|
+
scriptExecutionErrors = [];
|
|
1175
|
+
_o.label = 14;
|
|
1176
|
+
case 14:
|
|
1177
|
+
_o.trys.push([14, 21, 22, 23]);
|
|
1178
|
+
_c = (e_2 = void 0, __values(tools.script)), _d = _c.next();
|
|
1179
|
+
_o.label = 15;
|
|
1180
|
+
case 15:
|
|
1181
|
+
if (!!_d.done) return [3 /*break*/, 20];
|
|
1182
|
+
scriptTools = _d.value;
|
|
1183
|
+
_o.label = 16;
|
|
1184
|
+
case 16:
|
|
1185
|
+
_o.trys.push([16, 18, , 19]);
|
|
1186
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
1187
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
1188
|
+
script: currentTemplate.content,
|
|
1189
|
+
parameters: parametersToPass,
|
|
1190
|
+
})];
|
|
1191
|
+
case 17:
|
|
1192
|
+
resultString = _o.sent();
|
|
1193
|
+
return [3 /*break*/, 20];
|
|
1194
|
+
case 18:
|
|
1195
|
+
error_2 = _o.sent();
|
|
1196
|
+
if (!(error_2 instanceof Error)) {
|
|
1197
|
+
throw error_2;
|
|
1198
|
+
}
|
|
1199
|
+
scriptExecutionErrors.push(error_2);
|
|
1200
|
+
return [3 /*break*/, 19];
|
|
1201
|
+
case 19:
|
|
1202
|
+
_d = _c.next();
|
|
1203
|
+
return [3 /*break*/, 15];
|
|
1204
|
+
case 20: return [3 /*break*/, 23];
|
|
1205
|
+
case 21:
|
|
1206
|
+
e_2_1 = _o.sent();
|
|
1207
|
+
e_2 = { error: e_2_1 };
|
|
1208
|
+
return [3 /*break*/, 23];
|
|
1209
|
+
case 22:
|
|
1210
|
+
try {
|
|
1211
|
+
if (_d && !_d.done && (_j = _c.return)) _j.call(_c);
|
|
1212
|
+
}
|
|
1213
|
+
finally { if (e_2) throw e_2.error; }
|
|
1214
|
+
return [7 /*endfinally*/];
|
|
1215
|
+
case 23:
|
|
1216
|
+
if (resultString !== null) {
|
|
1217
|
+
return [3 /*break*/, 27];
|
|
1218
|
+
}
|
|
1219
|
+
if (scriptExecutionErrors.length === 1) {
|
|
1220
|
+
throw scriptExecutionErrors[0];
|
|
1221
|
+
}
|
|
1222
|
+
else {
|
|
1223
|
+
throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
|
|
1224
|
+
.map(function (error) { return '- ' + error.message; })
|
|
1225
|
+
.join('\n\n')), "\n "); }));
|
|
1226
|
+
}
|
|
1227
|
+
case 24:
|
|
1228
|
+
if (tools.userInterface === undefined) {
|
|
1229
|
+
throw new PromptbookExecutionError('User interface tools are not available');
|
|
1230
|
+
}
|
|
1231
|
+
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
1232
|
+
promptTitle: currentTemplate.title,
|
|
1233
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parametersToPass),
|
|
1234
|
+
defaultValue: replaceParameters(currentTemplate.content, parametersToPass),
|
|
1235
|
+
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
1236
|
+
placeholder: undefined,
|
|
1237
|
+
priority: priority,
|
|
1238
|
+
})];
|
|
1239
|
+
case 25:
|
|
1240
|
+
// TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
1241
|
+
resultString = _o.sent();
|
|
1242
|
+
return [3 /*break*/, 27];
|
|
1243
|
+
case 26: throw new PromptbookExecutionError(
|
|
1244
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1245
|
+
"Unknown execution type \"".concat(currentTemplate.executionType, "\""));
|
|
1246
|
+
case 27:
|
|
1247
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 44];
|
|
1248
|
+
_o.label = 28;
|
|
1249
|
+
case 28:
|
|
1250
|
+
_o.trys.push([28, 42, 43, 44]);
|
|
1251
|
+
_e = (e_4 = void 0, __values(currentTemplate.postprocessing)), _f = _e.next();
|
|
1252
|
+
_o.label = 29;
|
|
1253
|
+
case 29:
|
|
1254
|
+
if (!!_f.done) return [3 /*break*/, 41];
|
|
1255
|
+
functionName = _f.value;
|
|
1256
|
+
// TODO: DRY [1]
|
|
1257
|
+
scriptExecutionErrors = [];
|
|
1258
|
+
postprocessingError = null;
|
|
1259
|
+
_o.label = 30;
|
|
1260
|
+
case 30:
|
|
1261
|
+
_o.trys.push([30, 37, 38, 39]);
|
|
1262
|
+
_g = (e_3 = void 0, __values(tools.script)), _h = _g.next();
|
|
1263
|
+
_o.label = 31;
|
|
1264
|
+
case 31:
|
|
1265
|
+
if (!!_h.done) return [3 /*break*/, 36];
|
|
1266
|
+
scriptTools = _h.value;
|
|
1267
|
+
_o.label = 32;
|
|
1268
|
+
case 32:
|
|
1269
|
+
_o.trys.push([32, 34, , 35]);
|
|
1270
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
1271
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
1272
|
+
script: "".concat(functionName, "(resultString)"),
|
|
1273
|
+
parameters: {
|
|
1274
|
+
resultString: resultString || '',
|
|
1275
|
+
// Note: No ...parametersToPass, because working with result only
|
|
1276
|
+
},
|
|
1277
|
+
})];
|
|
1278
|
+
case 33:
|
|
1279
|
+
resultString = _o.sent();
|
|
1280
|
+
postprocessingError = null;
|
|
1281
|
+
return [3 /*break*/, 36];
|
|
1282
|
+
case 34:
|
|
1283
|
+
error_3 = _o.sent();
|
|
1284
|
+
if (!(error_3 instanceof Error)) {
|
|
1285
|
+
throw error_3;
|
|
1286
|
+
}
|
|
1287
|
+
postprocessingError = error_3;
|
|
1288
|
+
scriptExecutionErrors.push(error_3);
|
|
1289
|
+
return [3 /*break*/, 35];
|
|
1290
|
+
case 35:
|
|
1291
|
+
_h = _g.next();
|
|
1292
|
+
return [3 /*break*/, 31];
|
|
1293
|
+
case 36: return [3 /*break*/, 39];
|
|
1294
|
+
case 37:
|
|
1295
|
+
e_3_1 = _o.sent();
|
|
1296
|
+
e_3 = { error: e_3_1 };
|
|
1297
|
+
return [3 /*break*/, 39];
|
|
1298
|
+
case 38:
|
|
1299
|
+
try {
|
|
1300
|
+
if (_h && !_h.done && (_l = _g.return)) _l.call(_g);
|
|
1301
|
+
}
|
|
1302
|
+
finally { if (e_3) throw e_3.error; }
|
|
1303
|
+
return [7 /*endfinally*/];
|
|
1304
|
+
case 39:
|
|
1305
|
+
if (postprocessingError) {
|
|
1306
|
+
throw postprocessingError;
|
|
1307
|
+
}
|
|
1308
|
+
_o.label = 40;
|
|
1309
|
+
case 40:
|
|
1310
|
+
_f = _e.next();
|
|
1311
|
+
return [3 /*break*/, 29];
|
|
1312
|
+
case 41: return [3 /*break*/, 44];
|
|
1313
|
+
case 42:
|
|
1314
|
+
e_4_1 = _o.sent();
|
|
1315
|
+
e_4 = { error: e_4_1 };
|
|
1316
|
+
return [3 /*break*/, 44];
|
|
1317
|
+
case 43:
|
|
1318
|
+
try {
|
|
1319
|
+
if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
|
|
1320
|
+
}
|
|
1321
|
+
finally { if (e_4) throw e_4.error; }
|
|
1322
|
+
return [7 /*endfinally*/];
|
|
1323
|
+
case 44:
|
|
1324
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
1325
|
+
if (currentTemplate.expectFormat) {
|
|
1326
|
+
if (currentTemplate.expectFormat === 'JSON') {
|
|
1327
|
+
if (!isValidJsonString(resultString || '')) {
|
|
1328
|
+
throw new ExpectError('Expected valid JSON string');
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
1333
|
+
if (currentTemplate.expectations) {
|
|
1334
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
1335
|
+
}
|
|
1336
|
+
return [3 /*break*/, 49];
|
|
1337
|
+
case 45:
|
|
1338
|
+
error_4 = _o.sent();
|
|
1339
|
+
if (!(error_4 instanceof ExpectError)) {
|
|
1340
|
+
throw error_4;
|
|
1341
|
+
}
|
|
1342
|
+
expectError = error_4;
|
|
1343
|
+
return [3 /*break*/, 47];
|
|
1344
|
+
case 46:
|
|
1345
|
+
if (!isJokerAttempt &&
|
|
1346
|
+
currentTemplate.executionType === 'PROMPT_TEMPLATE' &&
|
|
1347
|
+
prompt
|
|
1348
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
1349
|
+
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
1350
|
+
) {
|
|
1351
|
+
// TODO: [🧠] Maybe put other executionTypes into report
|
|
1352
|
+
executionReport.promptExecutions.push({
|
|
1353
|
+
prompt: {
|
|
1354
|
+
title: currentTemplate.title /* <- Note: If title in promptbook contains emojis, pass it innto report */,
|
|
1355
|
+
content: prompt.content,
|
|
1356
|
+
modelRequirements: prompt.modelRequirements,
|
|
1357
|
+
expectations: prompt.expectations,
|
|
1358
|
+
expectFormat: prompt.expectFormat,
|
|
1359
|
+
// <- Note: Do want to pass ONLY wanted information to the report
|
|
1360
|
+
},
|
|
1361
|
+
result: result || undefined,
|
|
1362
|
+
error: expectError || undefined,
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
return [7 /*endfinally*/];
|
|
1366
|
+
case 47:
|
|
1367
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
1368
|
+
throw new PromptbookExecutionError(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 "); }));
|
|
1369
|
+
}
|
|
1370
|
+
_o.label = 48;
|
|
1371
|
+
case 48:
|
|
1372
|
+
attempt++;
|
|
1373
|
+
return [3 /*break*/, 3];
|
|
1374
|
+
case 49:
|
|
1375
|
+
if (resultString === null) {
|
|
1376
|
+
throw new UnexpectedError('Something went wrong and prompt result is null');
|
|
1377
|
+
}
|
|
1378
|
+
if (onProgress /* <- [3] */) {
|
|
1379
|
+
onProgress({
|
|
1380
|
+
name: name,
|
|
1381
|
+
title: title,
|
|
1382
|
+
isStarted: true,
|
|
1383
|
+
isDone: true,
|
|
1384
|
+
executionType: currentTemplate.executionType,
|
|
1385
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
1386
|
+
parameterValue: resultString,
|
|
1387
|
+
// <- [3]
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
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));
|
|
1391
|
+
return [2 /*return*/];
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
var parametersToPass, executionReport, resovedParameters_1, unresovedTemplates, resolving_1, loopLimit, _loop_1, error_1, usage_1, _a, _b, parameter, usage;
|
|
1397
|
+
var e_1, _c;
|
|
1398
|
+
return __generator(this, function (_d) {
|
|
1399
|
+
switch (_d.label) {
|
|
1400
|
+
case 0:
|
|
1401
|
+
parametersToPass = inputParameters;
|
|
1402
|
+
executionReport = {
|
|
1403
|
+
promptbookUrl: promptbook.promptbookUrl,
|
|
1404
|
+
title: promptbook.title,
|
|
1405
|
+
promptbookUsedVersion: PROMPTBOOK_VERSION,
|
|
1406
|
+
promptbookRequestedVersion: promptbook.promptbookVersion,
|
|
1407
|
+
description: promptbook.description,
|
|
1408
|
+
promptExecutions: [],
|
|
1409
|
+
};
|
|
1410
|
+
_d.label = 1;
|
|
1411
|
+
case 1:
|
|
1412
|
+
_d.trys.push([1, 6, , 7]);
|
|
1413
|
+
resovedParameters_1 = promptbook.parameters
|
|
1414
|
+
.filter(function (_a) {
|
|
1415
|
+
var isInput = _a.isInput;
|
|
1416
|
+
return isInput;
|
|
1417
|
+
})
|
|
1418
|
+
.map(function (_a) {
|
|
1419
|
+
var name = _a.name;
|
|
1420
|
+
return name;
|
|
1421
|
+
});
|
|
1422
|
+
unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
1423
|
+
resolving_1 = [];
|
|
1424
|
+
loopLimit = LOOP_LIMIT;
|
|
1425
|
+
_loop_1 = function () {
|
|
1426
|
+
var currentTemplate, work_1;
|
|
1427
|
+
return __generator(this, function (_e) {
|
|
1428
|
+
switch (_e.label) {
|
|
1429
|
+
case 0:
|
|
1430
|
+
if (loopLimit-- < 0) {
|
|
1431
|
+
throw new UnexpectedError('Loop limit reached during resolving parameters promptbook execution');
|
|
1432
|
+
}
|
|
1433
|
+
currentTemplate = unresovedTemplates.find(function (template) {
|
|
1434
|
+
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
1435
|
+
});
|
|
1436
|
+
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
1437
|
+
throw new UnexpectedError(spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
|
|
1438
|
+
case 1:
|
|
1439
|
+
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
1440
|
+
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
1441
|
+
case 2:
|
|
1442
|
+
/* [5] */ _e.sent();
|
|
1443
|
+
return [3 /*break*/, 4];
|
|
1444
|
+
case 3:
|
|
1445
|
+
unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
|
|
1446
|
+
work_1 = executeSingleTemplate(currentTemplate)
|
|
1447
|
+
.then(function () {
|
|
1448
|
+
resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
|
|
1449
|
+
})
|
|
1450
|
+
.then(function () {
|
|
1451
|
+
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
1452
|
+
});
|
|
1453
|
+
resolving_1.push(work_1);
|
|
1454
|
+
_e.label = 4;
|
|
1455
|
+
case 4: return [2 /*return*/];
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
};
|
|
1459
|
+
_d.label = 2;
|
|
1460
|
+
case 2:
|
|
1461
|
+
if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
|
|
1462
|
+
return [5 /*yield**/, _loop_1()];
|
|
1463
|
+
case 3:
|
|
1464
|
+
_d.sent();
|
|
1465
|
+
return [3 /*break*/, 2];
|
|
1466
|
+
case 4: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
1467
|
+
case 5:
|
|
1468
|
+
_d.sent();
|
|
1469
|
+
return [3 /*break*/, 7];
|
|
1470
|
+
case 6:
|
|
1471
|
+
error_1 = _d.sent();
|
|
1472
|
+
if (!(error_1 instanceof Error)) {
|
|
1473
|
+
throw error_1;
|
|
1474
|
+
}
|
|
1475
|
+
usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1476
|
+
var result = _a.result;
|
|
1477
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1478
|
+
})), false));
|
|
1479
|
+
return [2 /*return*/, {
|
|
1480
|
+
isSuccessful: false,
|
|
1481
|
+
errors: [error_1],
|
|
1482
|
+
usage: usage_1,
|
|
1483
|
+
executionReport: executionReport,
|
|
1484
|
+
outputParameters: parametersToPass,
|
|
1485
|
+
}];
|
|
1486
|
+
case 7:
|
|
1487
|
+
try {
|
|
1488
|
+
// Note: Filter ONLY output parameters
|
|
1489
|
+
for (_a = __values(promptbook.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1490
|
+
parameter = _b.value;
|
|
1491
|
+
if (parameter.isOutput) {
|
|
1492
|
+
continue;
|
|
1493
|
+
}
|
|
1494
|
+
delete parametersToPass[parameter.name];
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1498
|
+
finally {
|
|
1499
|
+
try {
|
|
1500
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1501
|
+
}
|
|
1502
|
+
finally { if (e_1) throw e_1.error; }
|
|
1503
|
+
}
|
|
1504
|
+
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1505
|
+
var result = _a.result;
|
|
1506
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1507
|
+
})), false));
|
|
1508
|
+
return [2 /*return*/, {
|
|
1509
|
+
isSuccessful: true,
|
|
1510
|
+
errors: [],
|
|
1511
|
+
usage: usage,
|
|
1512
|
+
executionReport: executionReport,
|
|
1513
|
+
outputParameters: parametersToPass,
|
|
1514
|
+
}];
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
}); };
|
|
1518
|
+
return promptbookExecutor;
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
1522
|
+
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
1523
|
+
* Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
|
|
1524
|
+
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
1525
|
+
*/
|
|
1526
|
+
|
|
1527
|
+
/**
|
|
1528
|
+
* Prettify the html code
|
|
1529
|
+
*
|
|
1530
|
+
* @param content raw html code
|
|
1531
|
+
* @returns formatted html code
|
|
1532
|
+
*/
|
|
1533
|
+
function prettifyMarkdown(content) {
|
|
1534
|
+
try {
|
|
1535
|
+
return format(content, {
|
|
1536
|
+
parser: 'markdown',
|
|
1537
|
+
plugins: [parserHtml],
|
|
1538
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1539
|
+
endOfLine: 'lf',
|
|
1540
|
+
tabWidth: 4,
|
|
1541
|
+
singleQuote: true,
|
|
1542
|
+
trailingComma: 'all',
|
|
1543
|
+
arrowParens: 'always',
|
|
1544
|
+
printWidth: 120,
|
|
1545
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
1546
|
+
jsxBracketSameLine: false,
|
|
1547
|
+
bracketSpacing: true,
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
catch (error) {
|
|
1551
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
1552
|
+
error: error,
|
|
1553
|
+
html: content,
|
|
1554
|
+
});
|
|
1555
|
+
return content;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
/**
|
|
1560
|
+
* Makes first letter of a string uppercase
|
|
1561
|
+
*
|
|
1562
|
+
*/
|
|
1563
|
+
function capitalize(word) {
|
|
1564
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
/**
|
|
1568
|
+
* Converts promptbook in JSON format to string format
|
|
1569
|
+
*
|
|
1570
|
+
* @param promptbookJson Promptbook in JSON format (.ptbk.json)
|
|
1571
|
+
* @returns Promptbook in string format (.ptbk.md)
|
|
1572
|
+
*/
|
|
1573
|
+
function promptbookJsonToString(promptbookJson) {
|
|
1574
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
1575
|
+
var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
|
|
1576
|
+
var promptbookString = "# ".concat(title);
|
|
1577
|
+
if (description) {
|
|
1578
|
+
promptbookString += '\n\n';
|
|
1579
|
+
promptbookString += description;
|
|
1580
|
+
}
|
|
1581
|
+
// TODO:> const commands: Array<Command>
|
|
1582
|
+
var commands = [];
|
|
1583
|
+
if (promptbookUrl) {
|
|
1584
|
+
commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
|
|
1585
|
+
}
|
|
1586
|
+
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
1587
|
+
promptbookString = prettifyMarkdown(promptbookString);
|
|
1588
|
+
try {
|
|
1589
|
+
for (var _g = __values(parameters.filter(function (_a) {
|
|
1590
|
+
var isInput = _a.isInput;
|
|
1591
|
+
return isInput;
|
|
1592
|
+
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1593
|
+
var parameter = _h.value;
|
|
1594
|
+
commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1598
|
+
finally {
|
|
1599
|
+
try {
|
|
1600
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
1601
|
+
}
|
|
1602
|
+
finally { if (e_1) throw e_1.error; }
|
|
1603
|
+
}
|
|
1604
|
+
try {
|
|
1605
|
+
for (var _j = __values(parameters.filter(function (_a) {
|
|
1606
|
+
var isOutput = _a.isOutput;
|
|
1607
|
+
return isOutput;
|
|
1608
|
+
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1609
|
+
var parameter = _k.value;
|
|
1610
|
+
commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1614
|
+
finally {
|
|
1615
|
+
try {
|
|
1616
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
1617
|
+
}
|
|
1618
|
+
finally { if (e_2) throw e_2.error; }
|
|
1619
|
+
}
|
|
1620
|
+
promptbookString += '\n\n';
|
|
1621
|
+
promptbookString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1622
|
+
try {
|
|
1623
|
+
for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
|
|
1624
|
+
var promptTemplate = promptTemplates_1_1.value;
|
|
1625
|
+
var
|
|
1626
|
+
/* Note: Not using:> name, */
|
|
1627
|
+
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
1628
|
+
/* Note: dependentParameterNames, */
|
|
1629
|
+
jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
1630
|
+
promptbookString += '\n\n';
|
|
1631
|
+
promptbookString += "## ".concat(title_1);
|
|
1632
|
+
if (description_1) {
|
|
1633
|
+
promptbookString += '\n\n';
|
|
1634
|
+
promptbookString += description_1;
|
|
1635
|
+
}
|
|
1636
|
+
// TODO:> const commands: Array<Command>
|
|
1637
|
+
var commands_1 = [];
|
|
1638
|
+
var contentLanguage = 'text';
|
|
1639
|
+
if (executionType === 'PROMPT_TEMPLATE') {
|
|
1640
|
+
var modelRequirements = promptTemplate.modelRequirements;
|
|
1641
|
+
var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
|
|
1642
|
+
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
1643
|
+
if (modelVariant) {
|
|
1644
|
+
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
1645
|
+
}
|
|
1646
|
+
if (modelName) {
|
|
1647
|
+
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
else if (executionType === 'SIMPLE_TEMPLATE') {
|
|
1651
|
+
commands_1.push("SIMPLE TEMPLATE");
|
|
1652
|
+
// Note: Nothing special here
|
|
1653
|
+
}
|
|
1654
|
+
else if (executionType === 'SCRIPT') {
|
|
1655
|
+
commands_1.push("EXECUTE SCRIPT");
|
|
1656
|
+
if (promptTemplate.contentLanguage) {
|
|
1657
|
+
contentLanguage = promptTemplate.contentLanguage;
|
|
1658
|
+
}
|
|
1659
|
+
else {
|
|
1660
|
+
contentLanguage = '';
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
else if (executionType === 'PROMPT_DIALOG') {
|
|
1664
|
+
commands_1.push("PROMPT DIALOG");
|
|
1665
|
+
// Note: Nothing special here
|
|
1666
|
+
}
|
|
1667
|
+
if (jokers) {
|
|
1668
|
+
try {
|
|
1669
|
+
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()) {
|
|
1670
|
+
var joker = jokers_1_1.value;
|
|
1671
|
+
commands_1.push("JOKER {".concat(joker, "}"));
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1675
|
+
finally {
|
|
1676
|
+
try {
|
|
1677
|
+
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
1678
|
+
}
|
|
1679
|
+
finally { if (e_4) throw e_4.error; }
|
|
1680
|
+
}
|
|
1681
|
+
} /* not else */
|
|
1682
|
+
if (postprocessing) {
|
|
1683
|
+
try {
|
|
1684
|
+
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()) {
|
|
1685
|
+
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
1686
|
+
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1690
|
+
finally {
|
|
1691
|
+
try {
|
|
1692
|
+
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
1693
|
+
}
|
|
1694
|
+
finally { if (e_5) throw e_5.error; }
|
|
1695
|
+
}
|
|
1696
|
+
} /* not else */
|
|
1697
|
+
if (expectations) {
|
|
1698
|
+
try {
|
|
1699
|
+
for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1700
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
1701
|
+
if (min === max) {
|
|
1702
|
+
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1703
|
+
}
|
|
1704
|
+
else {
|
|
1705
|
+
if (min !== undefined) {
|
|
1706
|
+
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1707
|
+
} /* not else */
|
|
1708
|
+
if (max !== undefined) {
|
|
1709
|
+
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1715
|
+
finally {
|
|
1716
|
+
try {
|
|
1717
|
+
if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
|
|
1718
|
+
}
|
|
1719
|
+
finally { if (e_6) throw e_6.error; }
|
|
1720
|
+
}
|
|
1721
|
+
} /* not else */
|
|
1722
|
+
if (expectFormat) {
|
|
1723
|
+
if (expectFormat === 'JSON') {
|
|
1724
|
+
// TODO: @deprecated remove
|
|
1725
|
+
commands_1.push("EXPECT JSON");
|
|
1726
|
+
}
|
|
1727
|
+
} /* not else */
|
|
1728
|
+
promptbookString += '\n\n';
|
|
1729
|
+
promptbookString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1730
|
+
promptbookString += '\n\n';
|
|
1731
|
+
promptbookString += '```' + contentLanguage;
|
|
1732
|
+
promptbookString += '\n';
|
|
1733
|
+
promptbookString += spaceTrim$1(content);
|
|
1734
|
+
// <- TODO: !!! Escape
|
|
1735
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1736
|
+
promptbookString += '\n';
|
|
1737
|
+
promptbookString += '```';
|
|
1738
|
+
promptbookString += '\n\n';
|
|
1739
|
+
promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1743
|
+
finally {
|
|
1744
|
+
try {
|
|
1745
|
+
if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
|
|
1746
|
+
}
|
|
1747
|
+
finally { if (e_3) throw e_3.error; }
|
|
1748
|
+
}
|
|
1749
|
+
return promptbookString;
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* @private internal util of promptbookJsonToString
|
|
1753
|
+
*/
|
|
1754
|
+
function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
1755
|
+
var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
|
|
1756
|
+
var parameterString = "{".concat(name, "}");
|
|
1757
|
+
if (description) {
|
|
1758
|
+
parameterString = "".concat(parameterString, " ").concat(description);
|
|
1759
|
+
}
|
|
1760
|
+
return parameterString;
|
|
1761
|
+
}
|
|
1762
|
+
/**
|
|
1763
|
+
* TODO: Escape all
|
|
1764
|
+
*/
|
|
1765
|
+
|
|
1766
|
+
/**
|
|
1767
|
+
* This error indicates that promptbook not found in the library
|
|
1768
|
+
*/
|
|
1769
|
+
var PromptbookNotFoundError = /** @class */ (function (_super) {
|
|
1770
|
+
__extends(PromptbookNotFoundError, _super);
|
|
1771
|
+
function PromptbookNotFoundError(message) {
|
|
1772
|
+
var _this = _super.call(this, message) || this;
|
|
1773
|
+
_this.name = 'PromptbookNotFoundError';
|
|
1774
|
+
Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
|
|
1775
|
+
return _this;
|
|
1776
|
+
}
|
|
1777
|
+
return PromptbookNotFoundError;
|
|
1778
|
+
}(Error));
|
|
1779
|
+
|
|
1780
|
+
/**
|
|
1781
|
+
* This error indicates errors in referencing promptbooks between each other
|
|
1782
|
+
*/
|
|
1783
|
+
var PromptbookReferenceError = /** @class */ (function (_super) {
|
|
1784
|
+
__extends(PromptbookReferenceError, _super);
|
|
1785
|
+
function PromptbookReferenceError(message) {
|
|
1786
|
+
var _this = _super.call(this, message) || this;
|
|
1787
|
+
_this.name = 'PromptbookReferenceError';
|
|
1788
|
+
Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
|
|
1789
|
+
return _this;
|
|
1790
|
+
}
|
|
1791
|
+
return PromptbookReferenceError;
|
|
1792
|
+
}(Error));
|
|
1793
|
+
|
|
1794
|
+
/**
|
|
1795
|
+
* Library of promptbooks that groups together promptbooks for an application.
|
|
1796
|
+
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
1797
|
+
*
|
|
1798
|
+
* @see https://github.com/webgptorg/promptbook#promptbook-library
|
|
1799
|
+
*/
|
|
1800
|
+
var SimplePromptbookLibrary = /** @class */ (function () {
|
|
1801
|
+
/**
|
|
1802
|
+
* Constructs a promptbook library from promptbooks
|
|
1803
|
+
*
|
|
1804
|
+
* @param promptbooks !!!
|
|
1805
|
+
*
|
|
1806
|
+
* Note: During the construction logic of all promptbooks are validated
|
|
1807
|
+
* Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
|
|
1808
|
+
*/
|
|
1809
|
+
function SimplePromptbookLibrary() {
|
|
1810
|
+
var e_1, _a;
|
|
1811
|
+
var promptbooks = [];
|
|
1812
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1813
|
+
promptbooks[_i] = arguments[_i];
|
|
1814
|
+
}
|
|
1815
|
+
this.library = new Map();
|
|
1816
|
+
try {
|
|
1817
|
+
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
1818
|
+
var promptbook = promptbooks_1_1.value;
|
|
1819
|
+
if (promptbook.promptbookUrl === undefined) {
|
|
1820
|
+
throw new PromptbookReferenceError(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 ")));
|
|
1821
|
+
}
|
|
1822
|
+
validatePromptbookJson(promptbook);
|
|
1823
|
+
// Note: [🦄]
|
|
1824
|
+
if (this.library.has(promptbook.promptbookUrl) &&
|
|
1825
|
+
promptbookJsonToString(promptbook) !==
|
|
1826
|
+
promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
|
|
1827
|
+
throw new PromptbookReferenceError(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 ")));
|
|
1828
|
+
}
|
|
1829
|
+
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1833
|
+
finally {
|
|
1834
|
+
try {
|
|
1835
|
+
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
1836
|
+
}
|
|
1837
|
+
finally { if (e_1) throw e_1.error; }
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Gets all promptbooks in the library
|
|
1842
|
+
*/
|
|
1843
|
+
SimplePromptbookLibrary.prototype.listPromptbooks = function () {
|
|
1844
|
+
return Array.from(this.library.keys());
|
|
1845
|
+
};
|
|
1846
|
+
/**
|
|
1847
|
+
* Gets promptbook by its URL
|
|
1848
|
+
*
|
|
1849
|
+
* Note: This is not a direct fetching from the URL, but a lookup in the library
|
|
1850
|
+
*/
|
|
1851
|
+
SimplePromptbookLibrary.prototype.getPromptbookByUrl = function (url) {
|
|
1852
|
+
var _this = this;
|
|
1853
|
+
var promptbook = this.library.get(url);
|
|
1854
|
+
if (!promptbook) {
|
|
1855
|
+
if (this.listPromptbooks().length === 0) {
|
|
1856
|
+
throw new PromptbookNotFoundError(spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
1857
|
+
}
|
|
1858
|
+
throw new PromptbookNotFoundError(spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
|
|
1859
|
+
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
1860
|
+
.join('\n')), "\n\n "); }));
|
|
1861
|
+
}
|
|
1862
|
+
return promptbook;
|
|
1863
|
+
};
|
|
1864
|
+
/**
|
|
1865
|
+
* Checks whether given prompt was defined in any promptbook in the library
|
|
1866
|
+
*/
|
|
1867
|
+
SimplePromptbookLibrary.prototype.isResponsibleForPrompt = function (prompt) {
|
|
1868
|
+
return true;
|
|
1869
|
+
};
|
|
1870
|
+
return SimplePromptbookLibrary;
|
|
1871
|
+
}());
|
|
1872
|
+
|
|
1873
|
+
/**
|
|
1874
|
+
* Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
|
|
1875
|
+
*
|
|
1876
|
+
* Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
|
|
1877
|
+
* Note: During the construction syntax and logic of all sources are validated
|
|
1878
|
+
*
|
|
1879
|
+
* @param promptbookSources
|
|
1880
|
+
* @returns PromptbookLibrary
|
|
1881
|
+
*/
|
|
1882
|
+
function createPromptbookLibraryFromSources() {
|
|
1883
|
+
var promptbookSources = [];
|
|
1884
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1885
|
+
promptbookSources[_i] = arguments[_i];
|
|
1886
|
+
}
|
|
1887
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1888
|
+
var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
|
|
1889
|
+
var e_1, _a;
|
|
1890
|
+
return __generator(this, function (_b) {
|
|
1891
|
+
switch (_b.label) {
|
|
1892
|
+
case 0:
|
|
1893
|
+
promptbooks = new Array();
|
|
1894
|
+
_b.label = 1;
|
|
1895
|
+
case 1:
|
|
1896
|
+
_b.trys.push([1, 8, 9, 10]);
|
|
1897
|
+
promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
|
|
1898
|
+
_b.label = 2;
|
|
1899
|
+
case 2:
|
|
1900
|
+
if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
|
|
1901
|
+
source = promptbookSources_1_1.value;
|
|
1902
|
+
promptbook = void 0;
|
|
1903
|
+
if (!(typeof source === 'string')) return [3 /*break*/, 4];
|
|
1904
|
+
return [4 /*yield*/, promptbookStringToJson(source)];
|
|
1905
|
+
case 3:
|
|
1906
|
+
// Note: When directly creating from string, no need to validate the source
|
|
1907
|
+
// The validation is performed always before execution
|
|
1908
|
+
promptbook = _b.sent();
|
|
1909
|
+
return [3 /*break*/, 5];
|
|
1910
|
+
case 4:
|
|
1911
|
+
promptbook = source;
|
|
1912
|
+
_b.label = 5;
|
|
1913
|
+
case 5:
|
|
1914
|
+
promptbooks.push(promptbook);
|
|
1915
|
+
_b.label = 6;
|
|
1916
|
+
case 6:
|
|
1917
|
+
promptbookSources_1_1 = promptbookSources_1.next();
|
|
1918
|
+
return [3 /*break*/, 2];
|
|
1919
|
+
case 7: return [3 /*break*/, 10];
|
|
1920
|
+
case 8:
|
|
1921
|
+
e_1_1 = _b.sent();
|
|
1922
|
+
e_1 = { error: e_1_1 };
|
|
1923
|
+
return [3 /*break*/, 10];
|
|
1924
|
+
case 9:
|
|
1925
|
+
try {
|
|
1926
|
+
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
1927
|
+
}
|
|
1928
|
+
finally { if (e_1) throw e_1.error; }
|
|
1929
|
+
return [7 /*endfinally*/];
|
|
1930
|
+
case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
|
|
1931
|
+
}
|
|
1932
|
+
});
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
/**
|
|
1936
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
1937
|
+
*/
|
|
1938
|
+
|
|
1939
|
+
/* tslint:disable */
|
|
1940
|
+
function normalizeToKebabCase(sentence) {
|
|
1941
|
+
var e_1, _a;
|
|
1942
|
+
sentence = removeDiacritics(sentence);
|
|
1943
|
+
var charType;
|
|
1944
|
+
var lastCharType = 'OTHER';
|
|
1945
|
+
var normalizedName = '';
|
|
1946
|
+
try {
|
|
1947
|
+
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
1948
|
+
var char = sentence_1_1.value;
|
|
1949
|
+
var normalizedChar = void 0;
|
|
1950
|
+
if (/^[a-z]$/.test(char)) {
|
|
1951
|
+
charType = 'LOWERCASE';
|
|
1952
|
+
normalizedChar = char;
|
|
1953
|
+
}
|
|
1954
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
1955
|
+
charType = 'UPPERCASE';
|
|
1956
|
+
normalizedChar = char.toLowerCase();
|
|
1957
|
+
}
|
|
1958
|
+
else if (/^[0-9]$/.test(char)) {
|
|
1959
|
+
charType = 'NUMBER';
|
|
1960
|
+
normalizedChar = char;
|
|
1961
|
+
}
|
|
1962
|
+
else if (/^\/$/.test(char)) {
|
|
1963
|
+
charType = 'SLASH';
|
|
1964
|
+
normalizedChar = char;
|
|
1965
|
+
}
|
|
1966
|
+
else {
|
|
1967
|
+
charType = 'OTHER';
|
|
1968
|
+
normalizedChar = '-';
|
|
1969
|
+
}
|
|
1970
|
+
if (charType !== lastCharType &&
|
|
1971
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1972
|
+
!(lastCharType === 'NUMBER') &&
|
|
1973
|
+
!(charType === 'NUMBER')) {
|
|
1974
|
+
normalizedName += '-';
|
|
1975
|
+
}
|
|
1976
|
+
normalizedName += normalizedChar;
|
|
1977
|
+
lastCharType = charType;
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1981
|
+
finally {
|
|
1982
|
+
try {
|
|
1983
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
1984
|
+
}
|
|
1985
|
+
finally { if (e_1) throw e_1.error; }
|
|
1986
|
+
}
|
|
1987
|
+
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
1988
|
+
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
1989
|
+
normalizedName = normalizedName.replace(/^-/, '');
|
|
1990
|
+
normalizedName = normalizedName.replace(/-$/, '');
|
|
1991
|
+
return normalizedName;
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
function prepareKnowledgeFromMarkdown(options) {
|
|
1995
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1996
|
+
var content, llmTools, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
1997
|
+
var _this = this;
|
|
1998
|
+
return __generator(this, function (_a) {
|
|
1999
|
+
switch (_a.label) {
|
|
2000
|
+
case 0:
|
|
2001
|
+
content = options.content, llmTools = options.llmTools;
|
|
2002
|
+
return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
|
|
2003
|
+
case 1:
|
|
2004
|
+
library = _a.sent();
|
|
2005
|
+
promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
|
|
2006
|
+
executor = createPromptbookExecutor({
|
|
2007
|
+
promptbook: promptbook,
|
|
2008
|
+
tools: {
|
|
2009
|
+
llm: llmTools,
|
|
2010
|
+
script: [
|
|
2011
|
+
/* <- TODO: Allow to just not define script tools */
|
|
2012
|
+
],
|
|
2013
|
+
},
|
|
2014
|
+
});
|
|
2015
|
+
return [4 /*yield*/, executor({ content: content })];
|
|
2016
|
+
case 2:
|
|
2017
|
+
result = _a.sent();
|
|
2018
|
+
assertsExecutionSuccessful(result);
|
|
2019
|
+
outputParameters = result.outputParameters;
|
|
2020
|
+
knowledgeRaw = outputParameters.knowledge;
|
|
2021
|
+
knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
|
|
2022
|
+
return [4 /*yield*/, Promise.all(knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2023
|
+
var name, title, content, keywords, index, sources;
|
|
2024
|
+
return __generator(this, function (_a) {
|
|
2025
|
+
name = "piece-".concat(i);
|
|
2026
|
+
title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
|
|
2027
|
+
content = spaceTrim$1(knowledgeTextPiece);
|
|
2028
|
+
keywords = [];
|
|
2029
|
+
index = [];
|
|
2030
|
+
sources = [];
|
|
2031
|
+
try {
|
|
2032
|
+
// TODO: !!!! Summarize name and title from the content
|
|
2033
|
+
title = spaceTrim$1(knowledgeTextPiece.substring(0, 30));
|
|
2034
|
+
name = normalizeToKebabCase(title);
|
|
2035
|
+
// TODO: !!!! Extract keywords via prompt
|
|
2036
|
+
// TODO: !!!! Index through LLM model
|
|
2037
|
+
// TODO: [🖖] !!!! Make system for sources and identification of sources
|
|
2038
|
+
}
|
|
2039
|
+
catch (error) {
|
|
2040
|
+
console.error(error);
|
|
2041
|
+
}
|
|
2042
|
+
return [2 /*return*/, {
|
|
2043
|
+
name: name,
|
|
2044
|
+
title: title,
|
|
2045
|
+
content: content,
|
|
2046
|
+
keywords: keywords,
|
|
2047
|
+
index: index,
|
|
2048
|
+
sources: sources,
|
|
2049
|
+
}];
|
|
2050
|
+
});
|
|
2051
|
+
}); }))];
|
|
2052
|
+
case 3:
|
|
2053
|
+
knowledge = _a.sent();
|
|
2054
|
+
return [2 /*return*/, knowledge];
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
/**
|
|
2061
|
+
* Supported script languages
|
|
2062
|
+
*/
|
|
2063
|
+
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
2064
|
+
|
|
2065
|
+
/**
|
|
2066
|
+
* Computes the deepness of the markdown structure.
|
|
1200
2067
|
*
|
|
1201
|
-
*
|
|
1202
|
-
* > "ě" => "e"
|
|
1203
|
-
* > "Ă" => "A"
|
|
1204
|
-
* > ...
|
|
2068
|
+
* @private within the library
|
|
1205
2069
|
*/
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
2070
|
+
function countMarkdownStructureDeepness(markdownStructure) {
|
|
2071
|
+
var e_1, _a;
|
|
2072
|
+
var maxDeepness = 0;
|
|
2073
|
+
try {
|
|
2074
|
+
for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2075
|
+
var section = _c.value;
|
|
2076
|
+
maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2080
|
+
finally {
|
|
2081
|
+
try {
|
|
2082
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2083
|
+
}
|
|
2084
|
+
finally { if (e_1) throw e_1.error; }
|
|
1213
2085
|
}
|
|
2086
|
+
return maxDeepness + 1;
|
|
1214
2087
|
}
|
|
1215
|
-
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
1216
|
-
/*
|
|
1217
|
-
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
1218
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
1219
|
-
you may not use this file except in compliance with the License.
|
|
1220
|
-
You may obtain a copy of the License at
|
|
1221
2088
|
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
2089
|
+
/**
|
|
2090
|
+
* Parse a markdown string into a MarkdownStructure object.
|
|
2091
|
+
*
|
|
2092
|
+
* Note: This function does work with code blocks
|
|
2093
|
+
* Note: This function does not work with markdown comments
|
|
2094
|
+
*
|
|
2095
|
+
* @param markdown The markdown string to parse.
|
|
2096
|
+
* @returns The MarkdownStructure object.
|
|
2097
|
+
*
|
|
2098
|
+
* @private within the library
|
|
2099
|
+
*/
|
|
2100
|
+
function markdownToMarkdownStructure(markdown) {
|
|
2101
|
+
var e_1, _a;
|
|
2102
|
+
var lines = markdown.split('\n');
|
|
2103
|
+
var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
|
|
2104
|
+
var current = root;
|
|
2105
|
+
var isInsideCodeBlock = false;
|
|
2106
|
+
try {
|
|
2107
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2108
|
+
var line = lines_1_1.value;
|
|
2109
|
+
var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
|
|
2110
|
+
if (isInsideCodeBlock || !headingMatch) {
|
|
2111
|
+
if (line.startsWith('```')) {
|
|
2112
|
+
isInsideCodeBlock = !isInsideCodeBlock;
|
|
2113
|
+
}
|
|
2114
|
+
current.contentLines.push(line);
|
|
2115
|
+
}
|
|
2116
|
+
else {
|
|
2117
|
+
var level = headingMatch.groups.mark.length;
|
|
2118
|
+
var title = headingMatch.groups.title.trim();
|
|
2119
|
+
var parent_1 = void 0;
|
|
2120
|
+
if (level > current.level) {
|
|
2121
|
+
// Note: Going deeper (next section is child of current)
|
|
2122
|
+
parent_1 = current;
|
|
2123
|
+
}
|
|
2124
|
+
else {
|
|
2125
|
+
// Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
|
|
2126
|
+
parent_1 = current;
|
|
2127
|
+
var loopLimit = LOOP_LIMIT;
|
|
2128
|
+
while (parent_1.level !== level - 1) {
|
|
2129
|
+
if (loopLimit-- < 0) {
|
|
2130
|
+
throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
|
|
2131
|
+
}
|
|
2132
|
+
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
2133
|
+
// [🌻]
|
|
2134
|
+
throw new Error(spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
2135
|
+
}
|
|
2136
|
+
parent_1 = parent_1.parent;
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
|
|
2140
|
+
parent_1.sections.push(section);
|
|
2141
|
+
current = section;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2146
|
+
finally {
|
|
2147
|
+
try {
|
|
2148
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2149
|
+
}
|
|
2150
|
+
finally { if (e_1) throw e_1.error; }
|
|
2151
|
+
}
|
|
2152
|
+
if (root.sections.length === 1) {
|
|
2153
|
+
var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
|
|
2154
|
+
return markdownStructure;
|
|
2155
|
+
}
|
|
2156
|
+
// [🌻]
|
|
2157
|
+
throw new Error('The markdown file must have exactly one top-level section.');
|
|
2158
|
+
// return root;
|
|
2159
|
+
}
|
|
2160
|
+
/**
|
|
2161
|
+
* @private
|
|
2162
|
+
*/
|
|
2163
|
+
function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
2164
|
+
var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
|
|
2165
|
+
return {
|
|
2166
|
+
level: level,
|
|
2167
|
+
title: title,
|
|
2168
|
+
content: spaceTrim(contentLines.join('\n')),
|
|
2169
|
+
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
1230
2172
|
|
|
1231
2173
|
/**
|
|
2174
|
+
* Utility function to extract all list items from markdown
|
|
2175
|
+
*
|
|
2176
|
+
* Note: It works with both ul and ol
|
|
2177
|
+
* Note: It omits list items in code blocks
|
|
2178
|
+
* Note: It flattens nested lists
|
|
2179
|
+
* Note: It can not work with html syntax and comments
|
|
1232
2180
|
*
|
|
2181
|
+
* @param markdown any valid markdown
|
|
2182
|
+
* @returns
|
|
1233
2183
|
*/
|
|
1234
|
-
function
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
2184
|
+
function extractAllListItemsFromMarkdown(markdown) {
|
|
2185
|
+
var e_1, _a;
|
|
2186
|
+
var lines = markdown.split('\n');
|
|
2187
|
+
var listItems = [];
|
|
2188
|
+
var isInCodeBlock = false;
|
|
2189
|
+
try {
|
|
2190
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2191
|
+
var line = lines_1_1.value;
|
|
2192
|
+
var trimmedLine = line.trim();
|
|
2193
|
+
if (trimmedLine.startsWith('```')) {
|
|
2194
|
+
isInCodeBlock = !isInCodeBlock;
|
|
2195
|
+
}
|
|
2196
|
+
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
2197
|
+
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
2198
|
+
listItems.push(listItem);
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2203
|
+
finally {
|
|
2204
|
+
try {
|
|
2205
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2206
|
+
}
|
|
2207
|
+
finally { if (e_1) throw e_1.error; }
|
|
2208
|
+
}
|
|
2209
|
+
return listItems;
|
|
1239
2210
|
}
|
|
1240
2211
|
|
|
1241
|
-
|
|
1242
|
-
|
|
2212
|
+
/**
|
|
2213
|
+
* Extracts all code blocks from markdown.
|
|
2214
|
+
*
|
|
2215
|
+
* Note: There are 3 simmilar function:
|
|
2216
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2217
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2218
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2219
|
+
*
|
|
2220
|
+
* @param markdown any valid markdown
|
|
2221
|
+
* @returns code blocks with language and content
|
|
2222
|
+
*
|
|
2223
|
+
*/
|
|
2224
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
1243
2225
|
var e_1, _a;
|
|
1244
|
-
|
|
1245
|
-
var
|
|
1246
|
-
var
|
|
1247
|
-
var normalizedName = '';
|
|
2226
|
+
var codeBlocks = [];
|
|
2227
|
+
var lines = markdown.split('\n');
|
|
2228
|
+
var currentCodeBlock = null;
|
|
1248
2229
|
try {
|
|
1249
|
-
for (var
|
|
1250
|
-
var
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
else if (/^\/$/.test(char)) {
|
|
1265
|
-
charType = 'SLASH';
|
|
1266
|
-
normalizedChar = char;
|
|
1267
|
-
}
|
|
1268
|
-
else {
|
|
1269
|
-
charType = 'OTHER';
|
|
1270
|
-
normalizedChar = '-';
|
|
2230
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2231
|
+
var line = lines_1_1.value;
|
|
2232
|
+
if (line.startsWith('```')) {
|
|
2233
|
+
var language = line.slice(3).trim() || null;
|
|
2234
|
+
if (currentCodeBlock === null) {
|
|
2235
|
+
currentCodeBlock = { language: language, content: '' };
|
|
2236
|
+
}
|
|
2237
|
+
else {
|
|
2238
|
+
if (language !== null) {
|
|
2239
|
+
// [🌻]
|
|
2240
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2241
|
+
}
|
|
2242
|
+
codeBlocks.push(currentCodeBlock);
|
|
2243
|
+
currentCodeBlock = null;
|
|
2244
|
+
}
|
|
1271
2245
|
}
|
|
1272
|
-
if (
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
2246
|
+
else if (currentCodeBlock !== null) {
|
|
2247
|
+
if (currentCodeBlock.content !== '') {
|
|
2248
|
+
currentCodeBlock.content += '\n';
|
|
2249
|
+
}
|
|
2250
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
1277
2251
|
}
|
|
1278
|
-
normalizedName += normalizedChar;
|
|
1279
|
-
lastCharType = charType;
|
|
1280
2252
|
}
|
|
1281
2253
|
}
|
|
1282
2254
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1283
2255
|
finally {
|
|
1284
2256
|
try {
|
|
1285
|
-
if (
|
|
2257
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
1286
2258
|
}
|
|
1287
2259
|
finally { if (e_1) throw e_1.error; }
|
|
1288
2260
|
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
return
|
|
2261
|
+
if (currentCodeBlock !== null) {
|
|
2262
|
+
// [🌻]
|
|
2263
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2264
|
+
}
|
|
2265
|
+
return codeBlocks;
|
|
1294
2266
|
}
|
|
1295
2267
|
|
|
1296
2268
|
/**
|
|
1297
|
-
*
|
|
2269
|
+
* Extracts exactly ONE code block from markdown.
|
|
1298
2270
|
*
|
|
1299
|
-
*
|
|
1300
|
-
*
|
|
2271
|
+
* Note: If there are multiple or no code blocks the function throws an error
|
|
2272
|
+
*
|
|
2273
|
+
* Note: There are 3 simmilar function:
|
|
2274
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2275
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2276
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2277
|
+
*
|
|
2278
|
+
* @param markdown any valid markdown
|
|
2279
|
+
* @returns code block with language and content
|
|
1301
2280
|
*/
|
|
1302
|
-
function
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
return
|
|
2281
|
+
function extractOneBlockFromMarkdown(markdown) {
|
|
2282
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2283
|
+
if (codeBlocks.length !== 1) {
|
|
2284
|
+
// TODO: Report more specific place where the error happened
|
|
2285
|
+
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
2286
|
+
}
|
|
2287
|
+
return codeBlocks[0];
|
|
1309
2288
|
}
|
|
2289
|
+
/***
|
|
2290
|
+
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
2291
|
+
*/
|
|
1310
2292
|
|
|
1311
2293
|
/**
|
|
1312
|
-
*
|
|
2294
|
+
* Removes HTML or Markdown comments from a string.
|
|
2295
|
+
*
|
|
2296
|
+
* @param {string} content - The string to remove comments from.
|
|
2297
|
+
* @returns {string} The input string with all comments removed.
|
|
1313
2298
|
*/
|
|
1314
|
-
function
|
|
1315
|
-
|
|
1316
|
-
value = normalizeToKebabCase(value);
|
|
1317
|
-
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
1318
|
-
return value;
|
|
2299
|
+
function removeContentComments(content) {
|
|
2300
|
+
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
1319
2301
|
}
|
|
1320
2302
|
|
|
1321
2303
|
/**
|
|
1322
|
-
*
|
|
1323
|
-
*
|
|
1324
|
-
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1325
|
-
* @param llmTools {LlmExecutionTools} - tools for processing required for knowledge processing *(not for actual execution)*
|
|
1326
|
-
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1327
|
-
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1328
|
-
*
|
|
1329
|
-
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1330
|
-
* Note: This function acts as compilation process
|
|
2304
|
+
* Creates a new set with all elements that are present in either set
|
|
1331
2305
|
*/
|
|
1332
|
-
function
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
1343
|
-
parameters: [],
|
|
1344
|
-
promptTemplates: [],
|
|
1345
|
-
knowledge: [],
|
|
1346
|
-
};
|
|
1347
|
-
// =============================================================
|
|
1348
|
-
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
1349
|
-
promptbookString = removeContentComments(promptbookString);
|
|
1350
|
-
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
1351
|
-
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
1352
|
-
addParam = function (parameterCommand) {
|
|
1353
|
-
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
1354
|
-
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1355
|
-
if (existingParameter &&
|
|
1356
|
-
existingParameter.description &&
|
|
1357
|
-
existingParameter.description !== parameterDescription &&
|
|
1358
|
-
parameterDescription) {
|
|
1359
|
-
throw new PromptbookSyntaxError(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 "); }));
|
|
1360
|
-
}
|
|
1361
|
-
if (existingParameter) {
|
|
1362
|
-
if (parameterDescription) {
|
|
1363
|
-
existingParameter.description = parameterDescription;
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
else {
|
|
1367
|
-
promptbookJson.parameters.push({
|
|
1368
|
-
name: parameterName,
|
|
1369
|
-
description: parameterDescription || undefined,
|
|
1370
|
-
isInput: isInput,
|
|
1371
|
-
isOutput: isOutput,
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
};
|
|
1375
|
-
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1376
|
-
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1377
|
-
if (markdownStructureDeepness !== 2) {
|
|
1378
|
-
throw new PromptbookSyntaxError(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 ")));
|
|
1379
|
-
}
|
|
1380
|
-
promptbookJson.title = markdownStructure.title;
|
|
1381
|
-
description = markdownStructure.content;
|
|
1382
|
-
// Note: Remove codeblocks
|
|
1383
|
-
description = description.split(/^```.*^```/gms).join('');
|
|
1384
|
-
//Note: Remove lists and return statement
|
|
1385
|
-
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1386
|
-
description = spaceTrim(description);
|
|
1387
|
-
if (description === '') {
|
|
1388
|
-
description = undefined;
|
|
1389
|
-
}
|
|
1390
|
-
promptbookJson.description = description;
|
|
1391
|
-
defaultModelRequirements = {};
|
|
1392
|
-
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1393
|
-
try {
|
|
1394
|
-
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1395
|
-
listItem = listItems_1_1.value;
|
|
1396
|
-
command = parseCommand(listItem);
|
|
1397
|
-
switch (command.type) {
|
|
1398
|
-
case 'PROMPTBOOK_URL':
|
|
1399
|
-
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1400
|
-
break;
|
|
1401
|
-
case 'PROMPTBOOK_VERSION':
|
|
1402
|
-
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1403
|
-
break;
|
|
1404
|
-
case 'MODEL':
|
|
1405
|
-
defaultModelRequirements[command.key] = command.value;
|
|
1406
|
-
break;
|
|
1407
|
-
case 'PARAMETER':
|
|
1408
|
-
addParam(command);
|
|
1409
|
-
break;
|
|
1410
|
-
default:
|
|
1411
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1416
|
-
finally {
|
|
1417
|
-
try {
|
|
1418
|
-
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
1419
|
-
}
|
|
1420
|
-
finally { if (e_1) throw e_1.error; }
|
|
1421
|
-
}
|
|
1422
|
-
_loop_1 = function (section) {
|
|
1423
|
-
var e_3, _f;
|
|
1424
|
-
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1425
|
-
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1426
|
-
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1427
|
-
var dependentParameterNames = new Set();
|
|
1428
|
-
var executionType = 'PROMPT_TEMPLATE';
|
|
1429
|
-
var jokers = [];
|
|
1430
|
-
var postprocessing = [];
|
|
1431
|
-
var expectAmount = {};
|
|
1432
|
-
var expectFormat = undefined;
|
|
1433
|
-
var isExecutionTypeChanged = false;
|
|
1434
|
-
try {
|
|
1435
|
-
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()) {
|
|
1436
|
-
var listItem = listItems_2_1.value;
|
|
1437
|
-
var command = parseCommand(listItem);
|
|
1438
|
-
switch (command.type) {
|
|
1439
|
-
case 'JOKER':
|
|
1440
|
-
jokers.push(command.parameterName);
|
|
1441
|
-
dependentParameterNames.add(command.parameterName);
|
|
1442
|
-
break;
|
|
1443
|
-
case 'EXECUTE':
|
|
1444
|
-
if (isExecutionTypeChanged) {
|
|
1445
|
-
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1446
|
-
}
|
|
1447
|
-
executionType = command.executionType;
|
|
1448
|
-
isExecutionTypeChanged = true;
|
|
1449
|
-
break;
|
|
1450
|
-
case 'MODEL':
|
|
1451
|
-
templateModelRequirements[command.key] = command.value;
|
|
1452
|
-
break;
|
|
1453
|
-
case 'PARAMETER':
|
|
1454
|
-
// Note: This is just for detecting resulitng parameter name
|
|
1455
|
-
addParam(command);
|
|
1456
|
-
break;
|
|
1457
|
-
case 'POSTPROCESS':
|
|
1458
|
-
postprocessing.push(command.functionName);
|
|
1459
|
-
break;
|
|
1460
|
-
case 'EXPECT_AMOUNT':
|
|
1461
|
-
// eslint-disable-next-line no-case-declarations
|
|
1462
|
-
var unit = command.unit.toLowerCase();
|
|
1463
|
-
expectAmount[unit] = expectAmount[unit] || {};
|
|
1464
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1465
|
-
if (expectAmount[unit].min !== undefined) {
|
|
1466
|
-
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1467
|
-
}
|
|
1468
|
-
expectAmount[unit].min = command.amount;
|
|
1469
|
-
} /* not else */
|
|
1470
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1471
|
-
if (expectAmount[unit].max !== undefined) {
|
|
1472
|
-
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1473
|
-
}
|
|
1474
|
-
expectAmount[unit].max = command.amount;
|
|
1475
|
-
}
|
|
1476
|
-
break;
|
|
1477
|
-
case 'EXPECT_FORMAT':
|
|
1478
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1479
|
-
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1480
|
-
}
|
|
1481
|
-
expectFormat = command.format;
|
|
1482
|
-
break;
|
|
1483
|
-
default:
|
|
1484
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1489
|
-
finally {
|
|
1490
|
-
try {
|
|
1491
|
-
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
1492
|
-
}
|
|
1493
|
-
finally { if (e_3) throw e_3.error; }
|
|
1494
|
-
}
|
|
1495
|
-
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
1496
|
-
if (executionType === 'SCRIPT') {
|
|
1497
|
-
if (!language) {
|
|
1498
|
-
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1499
|
-
}
|
|
1500
|
-
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1501
|
-
throw new PromptbookSyntaxError(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 "); }));
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
var lastLine = section.content.split('\n').pop();
|
|
1505
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1506
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1507
|
-
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1508
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
1509
|
-
section.content
|
|
1510
|
-
.split('\n')
|
|
1511
|
-
.map(function (line) { return "> ".concat(line); })
|
|
1512
|
-
.join('\n')), "\n "); }));
|
|
1513
|
-
}
|
|
1514
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
1515
|
-
// TODO: [1] DRY description
|
|
1516
|
-
var description_1 = section.content;
|
|
1517
|
-
// Note: Remove codeblocks
|
|
1518
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1519
|
-
//Note: Remove lists and return statement
|
|
1520
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1521
|
-
description_1 = spaceTrim(description_1);
|
|
1522
|
-
if (description_1 === '') {
|
|
1523
|
-
description_1 = undefined;
|
|
1524
|
-
}
|
|
1525
|
-
if (Object.keys(jokers).length === 0) {
|
|
1526
|
-
jokers = undefined;
|
|
1527
|
-
}
|
|
1528
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
1529
|
-
expectAmount = undefined;
|
|
1530
|
-
}
|
|
1531
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
1532
|
-
postprocessing = undefined;
|
|
1533
|
-
}
|
|
1534
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1535
|
-
if (templateModelRequirements.modelVariant === undefined) {
|
|
1536
|
-
templateModelRequirements.modelVariant = 'CHAT';
|
|
1537
|
-
}
|
|
1538
|
-
promptbookJson.promptTemplates.push({
|
|
1539
|
-
name: titleToName(section.title),
|
|
1540
|
-
title: section.title,
|
|
1541
|
-
description: description_1,
|
|
1542
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1543
|
-
executionType: executionType,
|
|
1544
|
-
jokers: jokers,
|
|
1545
|
-
postprocessing: postprocessing,
|
|
1546
|
-
expectations: expectAmount,
|
|
1547
|
-
expectFormat: expectFormat,
|
|
1548
|
-
modelRequirements: templateModelRequirements,
|
|
1549
|
-
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1550
|
-
content: content,
|
|
1551
|
-
resultingParameterName: resultingParameterName,
|
|
1552
|
-
});
|
|
1553
|
-
};
|
|
2306
|
+
function union() {
|
|
2307
|
+
var e_1, _a, e_2, _b;
|
|
2308
|
+
var sets = [];
|
|
2309
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2310
|
+
sets[_i] = arguments[_i];
|
|
2311
|
+
}
|
|
2312
|
+
var union = new Set();
|
|
2313
|
+
try {
|
|
2314
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2315
|
+
var set = sets_1_1.value;
|
|
1554
2316
|
try {
|
|
1555
|
-
for (
|
|
1556
|
-
|
|
1557
|
-
|
|
2317
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2318
|
+
var item = _d.value;
|
|
2319
|
+
union.add(item);
|
|
1558
2320
|
}
|
|
1559
2321
|
}
|
|
1560
2322
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1561
2323
|
finally {
|
|
1562
2324
|
try {
|
|
1563
|
-
if (
|
|
2325
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1564
2326
|
}
|
|
1565
2327
|
finally { if (e_2) throw e_2.error; }
|
|
1566
2328
|
}
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2332
|
+
finally {
|
|
2333
|
+
try {
|
|
2334
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
2335
|
+
}
|
|
2336
|
+
finally { if (e_1) throw e_1.error; }
|
|
2337
|
+
}
|
|
2338
|
+
return union;
|
|
1571
2339
|
}
|
|
1572
|
-
/**
|
|
1573
|
-
* TODO: Report here line/column of error
|
|
1574
|
-
* TODO: Use spaceTrim more effectively
|
|
1575
|
-
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
1576
|
-
*/
|
|
1577
2340
|
|
|
1578
2341
|
/**
|
|
1579
|
-
*
|
|
2342
|
+
* Parses the template and returns the list of all parameter names
|
|
2343
|
+
*
|
|
2344
|
+
* @param template the template with parameters in {curly} braces
|
|
2345
|
+
* @returns the list of parameter names
|
|
1580
2346
|
*/
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
2347
|
+
function extractParameters(template) {
|
|
2348
|
+
var e_1, _a;
|
|
2349
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
2350
|
+
var parameterNames = new Set();
|
|
2351
|
+
try {
|
|
2352
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
2353
|
+
var match = matches_1_1.value;
|
|
2354
|
+
var parameterName = match[0].slice(1, -1);
|
|
2355
|
+
parameterNames.add(parameterName);
|
|
2356
|
+
}
|
|
1588
2357
|
}
|
|
1589
|
-
|
|
1590
|
-
|
|
2358
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2359
|
+
finally {
|
|
2360
|
+
try {
|
|
2361
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
2362
|
+
}
|
|
2363
|
+
finally { if (e_1) throw e_1.error; }
|
|
2364
|
+
}
|
|
2365
|
+
return parameterNames;
|
|
2366
|
+
}
|
|
1591
2367
|
|
|
1592
2368
|
/**
|
|
1593
|
-
*
|
|
2369
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
1594
2370
|
*
|
|
1595
|
-
*
|
|
2371
|
+
* @param script from which to extract the variables
|
|
2372
|
+
* @returns the list of variable names
|
|
2373
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
1596
2374
|
*/
|
|
1597
|
-
function
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
}
|
|
2375
|
+
function extractVariables(script) {
|
|
2376
|
+
var variables = new Set();
|
|
2377
|
+
script = "(()=>{".concat(script, "})()");
|
|
1601
2378
|
try {
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
2379
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2380
|
+
try {
|
|
2381
|
+
eval(script);
|
|
2382
|
+
}
|
|
2383
|
+
catch (error) {
|
|
2384
|
+
if (!(error instanceof ReferenceError)) {
|
|
2385
|
+
throw error;
|
|
2386
|
+
}
|
|
2387
|
+
var undefinedName = error.message.split(' ')[0];
|
|
2388
|
+
/*
|
|
2389
|
+
Note: Remapping error
|
|
2390
|
+
From: [ReferenceError: thing is not defined],
|
|
2391
|
+
To: [Error: Parameter {thing} is not defined],
|
|
2392
|
+
*/
|
|
2393
|
+
if (!undefinedName) {
|
|
2394
|
+
throw error;
|
|
2395
|
+
}
|
|
2396
|
+
if (script.includes(undefinedName + '(')) {
|
|
2397
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2398
|
+
}
|
|
2399
|
+
else {
|
|
2400
|
+
variables.add(undefinedName);
|
|
2401
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
1611
2404
|
}
|
|
1612
2405
|
catch (error) {
|
|
1613
|
-
|
|
2406
|
+
if (!(error instanceof Error)) {
|
|
2407
|
+
throw error;
|
|
2408
|
+
}
|
|
2409
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
1614
2410
|
}
|
|
2411
|
+
return variables;
|
|
1615
2412
|
}
|
|
2413
|
+
/**
|
|
2414
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
2415
|
+
*/
|
|
1616
2416
|
|
|
1617
2417
|
/**
|
|
1618
|
-
*
|
|
1619
|
-
*
|
|
1620
|
-
* It checks:
|
|
1621
|
-
* - if it has correct parameters dependency
|
|
1622
|
-
*
|
|
1623
|
-
* It does NOT check:
|
|
1624
|
-
* - if it is valid json
|
|
1625
|
-
* - if it is meaningful
|
|
2418
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
1626
2419
|
*
|
|
1627
|
-
* @param
|
|
1628
|
-
* @returns the
|
|
1629
|
-
* @throws {
|
|
2420
|
+
* @param promptTemplate the template with used parameters
|
|
2421
|
+
* @returns the set of parameter names
|
|
2422
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
1630
2423
|
*/
|
|
1631
|
-
function
|
|
1632
|
-
|
|
1633
|
-
var
|
|
1634
|
-
if (promptbook.promptbookUrl !== undefined) {
|
|
1635
|
-
if (!isValidUrl(promptbook.promptbookUrl)) {
|
|
1636
|
-
// TODO: This should be maybe the syntax error detected during parsing
|
|
1637
|
-
throw new PromptbookLogicError("Invalid promptbook URL \"".concat(promptbook.promptbookUrl, "\""));
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1641
|
-
if (!Array.isArray(promptbook.parameters)) {
|
|
1642
|
-
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1643
|
-
throw new PromptbookSyntaxError(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 ")));
|
|
1644
|
-
}
|
|
1645
|
-
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1646
|
-
if (!Array.isArray(promptbook.promptTemplates)) {
|
|
1647
|
-
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1648
|
-
throw new PromptbookSyntaxError(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 ")));
|
|
1649
|
-
}
|
|
1650
|
-
var _loop_1 = function (parameter) {
|
|
1651
|
-
if (parameter.isInput && parameter.isOutput) {
|
|
1652
|
-
throw new PromptbookLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
|
|
1653
|
-
}
|
|
1654
|
-
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
1655
|
-
if (!parameter.isInput &&
|
|
1656
|
-
!parameter.isOutput &&
|
|
1657
|
-
!promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
1658
|
-
throw new PromptbookLogicError(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 ")));
|
|
1659
|
-
}
|
|
1660
|
-
// Note: Testing that parameter is either input or result of some template
|
|
1661
|
-
if (!parameter.isInput &&
|
|
1662
|
-
!promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
1663
|
-
throw new PromptbookLogicError(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 ")));
|
|
1664
|
-
}
|
|
1665
|
-
};
|
|
2424
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
2425
|
+
var e_1, _a, e_2, _b;
|
|
2426
|
+
var parameterNames = new Set();
|
|
1666
2427
|
try {
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
_loop_1(parameter);
|
|
2428
|
+
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()) {
|
|
2429
|
+
var parameterName = _d.value;
|
|
2430
|
+
parameterNames.add(parameterName);
|
|
1671
2431
|
}
|
|
1672
2432
|
}
|
|
1673
2433
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1674
2434
|
finally {
|
|
1675
2435
|
try {
|
|
1676
|
-
if (
|
|
2436
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1677
2437
|
}
|
|
1678
2438
|
finally { if (e_1) throw e_1.error; }
|
|
1679
2439
|
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
2440
|
+
if (promptTemplate.executionType === 'SCRIPT') {
|
|
2441
|
+
try {
|
|
2442
|
+
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
2443
|
+
var parameterName = _f.value;
|
|
2444
|
+
parameterNames.add(parameterName);
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2448
|
+
finally {
|
|
2449
|
+
try {
|
|
2450
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
2451
|
+
}
|
|
2452
|
+
finally { if (e_2) throw e_2.error; }
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
return parameterNames;
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* TODO: [🔣] If script require contentLanguage
|
|
2459
|
+
*/
|
|
2460
|
+
|
|
2461
|
+
/* tslint:disable */
|
|
2462
|
+
/*
|
|
2463
|
+
TODO: Tests
|
|
2464
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
2465
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
2466
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
2467
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
2468
|
+
*/
|
|
2469
|
+
function normalizeTo_SCREAMING_CASE(sentence) {
|
|
2470
|
+
var e_1, _a;
|
|
2471
|
+
var charType;
|
|
2472
|
+
var lastCharType = 'OTHER';
|
|
2473
|
+
var normalizedName = '';
|
|
1688
2474
|
try {
|
|
1689
|
-
for (var
|
|
1690
|
-
var
|
|
1691
|
-
|
|
1692
|
-
|
|
2475
|
+
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
2476
|
+
var char = sentence_1_1.value;
|
|
2477
|
+
var normalizedChar = void 0;
|
|
2478
|
+
if (/^[a-z]$/.test(char)) {
|
|
2479
|
+
charType = 'LOWERCASE';
|
|
2480
|
+
normalizedChar = char.toUpperCase();
|
|
1693
2481
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
throw new PromptbookLogicError(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 ")));
|
|
2482
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
2483
|
+
charType = 'UPPERCASE';
|
|
2484
|
+
normalizedChar = char;
|
|
1698
2485
|
}
|
|
1699
|
-
if (
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
throw new PromptbookLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
|
|
1703
|
-
}
|
|
1704
|
-
try {
|
|
1705
|
-
for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1706
|
-
var joker = _k.value;
|
|
1707
|
-
if (!template.dependentParameterNames.includes(joker)) {
|
|
1708
|
-
throw new PromptbookLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1713
|
-
finally {
|
|
1714
|
-
try {
|
|
1715
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
1716
|
-
}
|
|
1717
|
-
finally { if (e_3) throw e_3.error; }
|
|
1718
|
-
}
|
|
2486
|
+
else if (/^[0-9]$/.test(char)) {
|
|
2487
|
+
charType = 'NUMBER';
|
|
2488
|
+
normalizedChar = char;
|
|
1719
2489
|
}
|
|
1720
|
-
if (
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1736
|
-
finally {
|
|
1737
|
-
try {
|
|
1738
|
-
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
1739
|
-
}
|
|
1740
|
-
finally { if (e_4) throw e_4.error; }
|
|
1741
|
-
}
|
|
2490
|
+
else if (/^\/$/.test(char)) {
|
|
2491
|
+
charType = 'SLASH';
|
|
2492
|
+
normalizedChar = char;
|
|
2493
|
+
}
|
|
2494
|
+
else {
|
|
2495
|
+
charType = 'OTHER';
|
|
2496
|
+
normalizedChar = '_';
|
|
2497
|
+
}
|
|
2498
|
+
if (charType !== lastCharType &&
|
|
2499
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
2500
|
+
!(lastCharType === 'NUMBER') &&
|
|
2501
|
+
!(charType === 'NUMBER')) {
|
|
2502
|
+
normalizedName += '_';
|
|
1742
2503
|
}
|
|
2504
|
+
normalizedName += normalizedChar;
|
|
2505
|
+
lastCharType = charType;
|
|
1743
2506
|
}
|
|
1744
2507
|
}
|
|
1745
|
-
catch (
|
|
2508
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1746
2509
|
finally {
|
|
1747
2510
|
try {
|
|
1748
|
-
if (
|
|
1749
|
-
}
|
|
1750
|
-
finally { if (e_2) throw e_2.error; }
|
|
1751
|
-
}
|
|
1752
|
-
// Note: Detect circular dependencies
|
|
1753
|
-
var resovedParameters = promptbook.parameters
|
|
1754
|
-
.filter(function (_a) {
|
|
1755
|
-
var isInput = _a.isInput;
|
|
1756
|
-
return isInput;
|
|
1757
|
-
})
|
|
1758
|
-
.map(function (_a) {
|
|
1759
|
-
var name = _a.name;
|
|
1760
|
-
return name;
|
|
1761
|
-
});
|
|
1762
|
-
var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
1763
|
-
var loopLimit = LOOP_LIMIT;
|
|
1764
|
-
var _loop_2 = function () {
|
|
1765
|
-
if (loopLimit-- < 0) {
|
|
1766
|
-
throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePromptbookJson`');
|
|
1767
|
-
}
|
|
1768
|
-
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
1769
|
-
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
1770
|
-
});
|
|
1771
|
-
if (currentlyResovedTemplates.length === 0) {
|
|
1772
|
-
throw new PromptbookLogicError(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
|
|
1773
|
-
.map(function (_a) {
|
|
1774
|
-
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1775
|
-
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
1776
|
-
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
1777
|
-
.join(', '));
|
|
1778
|
-
})
|
|
1779
|
-
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
2511
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
1780
2512
|
}
|
|
1781
|
-
|
|
1782
|
-
var resultingParameterName = _a.resultingParameterName;
|
|
1783
|
-
return resultingParameterName;
|
|
1784
|
-
})), false);
|
|
1785
|
-
unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
|
|
1786
|
-
};
|
|
1787
|
-
while (unresovedTemplates.length > 0) {
|
|
1788
|
-
_loop_2();
|
|
2513
|
+
finally { if (e_1) throw e_1.error; }
|
|
1789
2514
|
}
|
|
1790
|
-
|
|
2515
|
+
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
2516
|
+
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
2517
|
+
normalizedName = normalizedName.replace(/^_/, '');
|
|
2518
|
+
normalizedName = normalizedName.replace(/_$/, '');
|
|
2519
|
+
return normalizedName;
|
|
1791
2520
|
}
|
|
1792
2521
|
/**
|
|
1793
|
-
* TODO: [
|
|
1794
|
-
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
1795
|
-
* > /**
|
|
1796
|
-
* > * Validates PromptbookJson if it is logically valid.
|
|
1797
|
-
* > *
|
|
1798
|
-
* > * It checks:
|
|
1799
|
-
* > * - it has a valid structure
|
|
1800
|
-
* > * - ...
|
|
1801
|
-
* > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
|
|
2522
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
1802
2523
|
*/
|
|
1803
2524
|
|
|
1804
2525
|
/**
|
|
1805
|
-
*
|
|
2526
|
+
* Execution type describes the way how the block is executed
|
|
2527
|
+
*
|
|
2528
|
+
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
1806
2529
|
*/
|
|
1807
|
-
var
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
}
|
|
1815
|
-
return PromptbookLibraryError;
|
|
1816
|
-
}(Error));
|
|
2530
|
+
var ExecutionTypes = [
|
|
2531
|
+
'PROMPT_TEMPLATE',
|
|
2532
|
+
'SIMPLE_TEMPLATE',
|
|
2533
|
+
'SCRIPT',
|
|
2534
|
+
'PROMPT_DIALOG',
|
|
2535
|
+
// <- [🥻] Insert here when making new command
|
|
2536
|
+
];
|
|
1817
2537
|
|
|
1818
2538
|
/**
|
|
1819
|
-
*
|
|
2539
|
+
* Units of text measurement
|
|
1820
2540
|
*/
|
|
1821
|
-
|
|
2541
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
1822
2542
|
/**
|
|
1823
|
-
*
|
|
2543
|
+
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
2544
|
+
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
2545
|
+
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
1824
2546
|
*/
|
|
1825
|
-
|
|
2547
|
+
|
|
1826
2548
|
/**
|
|
1827
|
-
*
|
|
2549
|
+
* Removes Markdown formatting tags from a string.
|
|
2550
|
+
*
|
|
2551
|
+
* @param {string} str - The string to remove Markdown tags from.
|
|
2552
|
+
* @returns {string} The input string with all Markdown tags removed.
|
|
1828
2553
|
*/
|
|
1829
|
-
|
|
2554
|
+
function removeMarkdownFormatting(str) {
|
|
2555
|
+
// Remove bold formatting
|
|
2556
|
+
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
2557
|
+
// Remove italic formatting
|
|
2558
|
+
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
2559
|
+
// Remove code formatting
|
|
2560
|
+
str = str.replace(/`(.*?)`/g, '$1');
|
|
2561
|
+
return str;
|
|
2562
|
+
}
|
|
1830
2563
|
|
|
1831
2564
|
/**
|
|
1832
|
-
*
|
|
2565
|
+
* Function parseNumber will parse number from string
|
|
1833
2566
|
*
|
|
1834
|
-
*
|
|
1835
|
-
*
|
|
2567
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
2568
|
+
* Note: it also works only with decimal numbers
|
|
2569
|
+
*
|
|
2570
|
+
* @returns parsed number
|
|
2571
|
+
* @throws {PromptbookSyntaxError} if the value is not a number
|
|
2572
|
+
*
|
|
2573
|
+
* @private within the parseCommand
|
|
1836
2574
|
*/
|
|
1837
|
-
function
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
plugins: [parserHtml],
|
|
1842
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1843
|
-
endOfLine: 'lf',
|
|
1844
|
-
tabWidth: 4,
|
|
1845
|
-
singleQuote: true,
|
|
1846
|
-
trailingComma: 'all',
|
|
1847
|
-
arrowParens: 'always',
|
|
1848
|
-
printWidth: 120,
|
|
1849
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
1850
|
-
jsxBracketSameLine: false,
|
|
1851
|
-
bracketSpacing: true,
|
|
1852
|
-
});
|
|
2575
|
+
function parseNumber(value) {
|
|
2576
|
+
var originalValue = value;
|
|
2577
|
+
if (typeof value === 'number') {
|
|
2578
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
1853
2579
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
return
|
|
2580
|
+
if (typeof value !== 'string') {
|
|
2581
|
+
return 0;
|
|
2582
|
+
}
|
|
2583
|
+
value = value.trim();
|
|
2584
|
+
if (value.startsWith('+')) {
|
|
2585
|
+
return parseNumber(value.substring(1));
|
|
2586
|
+
}
|
|
2587
|
+
if (value.startsWith('-')) {
|
|
2588
|
+
var number = parseNumber(value.substring(1));
|
|
2589
|
+
if (number === 0) {
|
|
2590
|
+
return 0; // <- Note: To prevent -0
|
|
2591
|
+
}
|
|
2592
|
+
return -number;
|
|
2593
|
+
}
|
|
2594
|
+
value = value.replace(/,/g, '.');
|
|
2595
|
+
value = value.toUpperCase();
|
|
2596
|
+
if (value === '') {
|
|
2597
|
+
return 0;
|
|
2598
|
+
}
|
|
2599
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
2600
|
+
return Infinity;
|
|
2601
|
+
}
|
|
2602
|
+
if (value.includes('/')) {
|
|
2603
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
2604
|
+
var numerator = parseNumber(numerator_);
|
|
2605
|
+
var denominator = parseNumber(denominator_);
|
|
2606
|
+
if (denominator === 0) {
|
|
2607
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
2608
|
+
}
|
|
2609
|
+
return numerator / denominator;
|
|
2610
|
+
}
|
|
2611
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
2612
|
+
return 0;
|
|
2613
|
+
}
|
|
2614
|
+
if (value.includes('E')) {
|
|
2615
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
2616
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
2617
|
+
}
|
|
2618
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
2619
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
2620
|
+
}
|
|
2621
|
+
var num = parseFloat(value);
|
|
2622
|
+
if (isNaN(num)) {
|
|
2623
|
+
throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
1860
2624
|
}
|
|
2625
|
+
return num;
|
|
1861
2626
|
}
|
|
2627
|
+
/**
|
|
2628
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
2629
|
+
*/
|
|
1862
2630
|
|
|
1863
2631
|
/**
|
|
1864
|
-
*
|
|
2632
|
+
* Parses one line of ul/ol to command
|
|
1865
2633
|
*
|
|
1866
|
-
* @
|
|
1867
|
-
* @
|
|
2634
|
+
* @returns parsed command object
|
|
2635
|
+
* @throws {PromptbookSyntaxError} if the command is invalid
|
|
2636
|
+
*
|
|
2637
|
+
* @private within the promptbookStringToJson
|
|
1868
2638
|
*/
|
|
1869
|
-
function
|
|
1870
|
-
var e_1, _a
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
if (description) {
|
|
1874
|
-
promptbookString += '\n\n';
|
|
1875
|
-
promptbookString += description;
|
|
2639
|
+
function parseCommand(listItem) {
|
|
2640
|
+
var e_1, _a;
|
|
2641
|
+
if (listItem.includes('\n') || listItem.includes('\r')) {
|
|
2642
|
+
throw new PromptbookSyntaxError('Command can not contain new line characters:');
|
|
1876
2643
|
}
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
2644
|
+
var type = listItem.trim();
|
|
2645
|
+
type = type.split('`').join('');
|
|
2646
|
+
type = type.split('"').join('');
|
|
2647
|
+
type = type.split("'").join('');
|
|
2648
|
+
type = type.split('~').join('');
|
|
2649
|
+
type = type.split('[').join('');
|
|
2650
|
+
type = type.split(']').join('');
|
|
2651
|
+
type = type.split('(').join('');
|
|
2652
|
+
type = type.split(')').join('');
|
|
2653
|
+
type = normalizeTo_SCREAMING_CASE(type);
|
|
2654
|
+
type = type.split('DIALOGUE').join('DIALOG');
|
|
2655
|
+
var listItemParts = listItem
|
|
2656
|
+
.split(' ')
|
|
2657
|
+
.map(function (part) { return part.trim(); })
|
|
2658
|
+
.filter(function (item) { return item !== ''; })
|
|
2659
|
+
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
2660
|
+
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
2661
|
+
.map(removeMarkdownFormatting);
|
|
2662
|
+
if (type.startsWith('URL') ||
|
|
2663
|
+
type.startsWith('PTBK_URL') ||
|
|
2664
|
+
type.startsWith('PTBKURL') ||
|
|
2665
|
+
type.startsWith('PROMPTBOOK_URL') ||
|
|
2666
|
+
type.startsWith('PROMPTBOOKURL') ||
|
|
2667
|
+
type.startsWith('HTTPS')) {
|
|
2668
|
+
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
2669
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
2670
|
+
}
|
|
2671
|
+
var promptbookUrlString = listItemParts.pop();
|
|
2672
|
+
var promptbookUrl = new URL(promptbookUrlString);
|
|
2673
|
+
if (promptbookUrl.protocol !== 'https:') {
|
|
2674
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
2675
|
+
}
|
|
2676
|
+
if (promptbookUrl.hash !== '') {
|
|
2677
|
+
throw new PromptbookSyntaxError(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 ")));
|
|
2678
|
+
}
|
|
2679
|
+
return {
|
|
2680
|
+
type: 'PROMPTBOOK_URL',
|
|
2681
|
+
promptbookUrl: promptbookUrl,
|
|
2682
|
+
};
|
|
1881
2683
|
}
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
2684
|
+
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
2685
|
+
if (listItemParts.length !== 2) {
|
|
2686
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
2687
|
+
}
|
|
2688
|
+
var promptbookVersion = listItemParts.pop();
|
|
2689
|
+
// TODO: Validate version
|
|
2690
|
+
return {
|
|
2691
|
+
type: 'PROMPTBOOK_VERSION',
|
|
2692
|
+
promptbookVersion: promptbookVersion,
|
|
2693
|
+
};
|
|
2694
|
+
}
|
|
2695
|
+
else if (type.startsWith('EXECUTE') ||
|
|
2696
|
+
type.startsWith('EXEC') ||
|
|
2697
|
+
type.startsWith('PROMPT_DIALOG') ||
|
|
2698
|
+
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
2699
|
+
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
2700
|
+
if (executionTypes.length !== 1) {
|
|
2701
|
+
throw new PromptbookSyntaxError(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 "); }));
|
|
2702
|
+
}
|
|
2703
|
+
return {
|
|
2704
|
+
type: 'EXECUTE',
|
|
2705
|
+
executionType: executionTypes[0],
|
|
2706
|
+
};
|
|
2707
|
+
}
|
|
2708
|
+
else if (type.startsWith('MODEL')) {
|
|
2709
|
+
// TODO: Make this more elegant and dynamically
|
|
2710
|
+
if (type.startsWith('MODEL_VARIANT')) {
|
|
2711
|
+
if (type === 'MODEL_VARIANT_CHAT') {
|
|
2712
|
+
return {
|
|
2713
|
+
type: 'MODEL',
|
|
2714
|
+
key: 'modelVariant',
|
|
2715
|
+
value: 'CHAT',
|
|
2716
|
+
};
|
|
2717
|
+
}
|
|
2718
|
+
else if (type === 'MODEL_VARIANT_COMPLETION') {
|
|
2719
|
+
return {
|
|
2720
|
+
type: 'MODEL',
|
|
2721
|
+
key: 'modelVariant',
|
|
2722
|
+
value: 'COMPLETION',
|
|
2723
|
+
};
|
|
2724
|
+
}
|
|
2725
|
+
else {
|
|
2726
|
+
throw new PromptbookSyntaxError(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 "); }));
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
if (type.startsWith('MODEL_NAME')) {
|
|
2730
|
+
return {
|
|
2731
|
+
type: 'MODEL',
|
|
2732
|
+
key: 'modelName',
|
|
2733
|
+
value: listItemParts.pop(),
|
|
2734
|
+
};
|
|
2735
|
+
}
|
|
2736
|
+
else {
|
|
2737
|
+
throw new PromptbookSyntaxError(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 "); }));
|
|
1891
2738
|
}
|
|
1892
2739
|
}
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
2740
|
+
else if (type.startsWith('PARAM') ||
|
|
2741
|
+
type.startsWith('INPUT_PARAM') ||
|
|
2742
|
+
type.startsWith('OUTPUT_PARAM') ||
|
|
2743
|
+
listItem.startsWith('{') ||
|
|
2744
|
+
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
2745
|
+
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
2746
|
+
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2747
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
1897
2748
|
}
|
|
1898
|
-
|
|
2749
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2750
|
+
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
2751
|
+
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
2752
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
2753
|
+
}
|
|
2754
|
+
var isInput = type.startsWith('INPUT');
|
|
2755
|
+
var isOutput = type.startsWith('OUTPUT');
|
|
2756
|
+
if (listItem.startsWith('> {')) {
|
|
2757
|
+
isInput = false;
|
|
2758
|
+
isOutput = false;
|
|
2759
|
+
}
|
|
2760
|
+
return {
|
|
2761
|
+
type: 'PARAMETER',
|
|
2762
|
+
parameterName: parameterName,
|
|
2763
|
+
parameterDescription: parameterDescription.trim() || null,
|
|
2764
|
+
isInput: isInput,
|
|
2765
|
+
isOutput: isOutput,
|
|
2766
|
+
};
|
|
1899
2767
|
}
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
2768
|
+
else if (type.startsWith('JOKER')) {
|
|
2769
|
+
if (listItemParts.length !== 2) {
|
|
2770
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
2771
|
+
}
|
|
2772
|
+
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
2773
|
+
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2774
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
1907
2775
|
}
|
|
2776
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2777
|
+
var parameterName = parametersMatch.groups.parameterName;
|
|
2778
|
+
return {
|
|
2779
|
+
type: 'JOKER',
|
|
2780
|
+
parameterName: parameterName,
|
|
2781
|
+
};
|
|
1908
2782
|
}
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
2783
|
+
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
2784
|
+
if (listItemParts.length !== 2) {
|
|
2785
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
1913
2786
|
}
|
|
1914
|
-
|
|
2787
|
+
var functionName = listItemParts.pop();
|
|
2788
|
+
return {
|
|
2789
|
+
type: 'POSTPROCESS',
|
|
2790
|
+
functionName: functionName,
|
|
2791
|
+
};
|
|
1915
2792
|
}
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
if (
|
|
1929
|
-
|
|
1930
|
-
promptbookString += description_1;
|
|
2793
|
+
else if (type.startsWith('EXPECT_JSON')) {
|
|
2794
|
+
return {
|
|
2795
|
+
type: 'EXPECT_FORMAT',
|
|
2796
|
+
format: 'JSON',
|
|
2797
|
+
};
|
|
2798
|
+
// [🥤]
|
|
2799
|
+
}
|
|
2800
|
+
else if (type.startsWith('EXPECT')) {
|
|
2801
|
+
try {
|
|
2802
|
+
listItemParts.shift();
|
|
2803
|
+
var sign = void 0;
|
|
2804
|
+
var signRaw = listItemParts.shift();
|
|
2805
|
+
if (/^exact/i.test(signRaw)) {
|
|
2806
|
+
sign = 'EXACTLY';
|
|
1931
2807
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
var contentLanguage = 'text';
|
|
1935
|
-
if (executionType === 'PROMPT_TEMPLATE') {
|
|
1936
|
-
var modelRequirements = promptTemplate.modelRequirements;
|
|
1937
|
-
var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
|
|
1938
|
-
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
1939
|
-
if (modelVariant) {
|
|
1940
|
-
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
1941
|
-
}
|
|
1942
|
-
if (modelName) {
|
|
1943
|
-
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
1944
|
-
}
|
|
2808
|
+
else if (/^min/i.test(signRaw)) {
|
|
2809
|
+
sign = 'MINIMUM';
|
|
1945
2810
|
}
|
|
1946
|
-
else if (
|
|
1947
|
-
|
|
1948
|
-
// Note: Nothing special here
|
|
2811
|
+
else if (/^max/i.test(signRaw)) {
|
|
2812
|
+
sign = 'MAXIMUM';
|
|
1949
2813
|
}
|
|
1950
|
-
else
|
|
1951
|
-
|
|
1952
|
-
if (promptTemplate.contentLanguage) {
|
|
1953
|
-
contentLanguage = promptTemplate.contentLanguage;
|
|
1954
|
-
}
|
|
1955
|
-
else {
|
|
1956
|
-
contentLanguage = '';
|
|
1957
|
-
}
|
|
2814
|
+
else {
|
|
2815
|
+
throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
|
|
1958
2816
|
}
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
2817
|
+
var amountRaw = listItemParts.shift();
|
|
2818
|
+
var amount = parseNumber(amountRaw);
|
|
2819
|
+
if (amount < 0) {
|
|
2820
|
+
throw new PromptbookSyntaxError('Amount must be positive number or zero');
|
|
1962
2821
|
}
|
|
1963
|
-
if (
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
finally { if (e_4) throw e_4.error; }
|
|
1976
|
-
}
|
|
1977
|
-
} /* not else */
|
|
1978
|
-
if (postprocessing) {
|
|
1979
|
-
try {
|
|
1980
|
-
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()) {
|
|
1981
|
-
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
1982
|
-
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1986
|
-
finally {
|
|
1987
|
-
try {
|
|
1988
|
-
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
2822
|
+
if (amount !== Math.floor(amount)) {
|
|
2823
|
+
throw new PromptbookSyntaxError('Amount must be whole number');
|
|
2824
|
+
}
|
|
2825
|
+
var unitRaw = listItemParts.shift();
|
|
2826
|
+
var unit = undefined;
|
|
2827
|
+
try {
|
|
2828
|
+
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()) {
|
|
2829
|
+
var existingUnit = EXPECTATION_UNITS_1_1.value;
|
|
2830
|
+
var existingUnitText = existingUnit;
|
|
2831
|
+
existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
|
|
2832
|
+
if (existingUnitText === 'CHARACTER') {
|
|
2833
|
+
existingUnitText = 'CHAR';
|
|
1989
2834
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
try {
|
|
1995
|
-
for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1996
|
-
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
1997
|
-
if (min === max) {
|
|
1998
|
-
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1999
|
-
}
|
|
2000
|
-
else {
|
|
2001
|
-
if (min !== undefined) {
|
|
2002
|
-
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
2003
|
-
} /* not else */
|
|
2004
|
-
if (max !== undefined) {
|
|
2005
|
-
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
2006
|
-
}
|
|
2835
|
+
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
2836
|
+
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
2837
|
+
if (unit !== undefined) {
|
|
2838
|
+
throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
2007
2839
|
}
|
|
2840
|
+
unit = existingUnit;
|
|
2008
2841
|
}
|
|
2009
2842
|
}
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
finally { if (e_6) throw e_6.error; }
|
|
2016
|
-
}
|
|
2017
|
-
} /* not else */
|
|
2018
|
-
if (expectFormat) {
|
|
2019
|
-
if (expectFormat === 'JSON') {
|
|
2020
|
-
// TODO: @deprecated remove
|
|
2021
|
-
commands_1.push("EXPECT JSON");
|
|
2843
|
+
}
|
|
2844
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2845
|
+
finally {
|
|
2846
|
+
try {
|
|
2847
|
+
if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
|
|
2022
2848
|
}
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
promptbookString += '\n\n';
|
|
2035
|
-
promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
2849
|
+
finally { if (e_1) throw e_1.error; }
|
|
2850
|
+
}
|
|
2851
|
+
if (unit === undefined) {
|
|
2852
|
+
throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
|
|
2853
|
+
}
|
|
2854
|
+
return {
|
|
2855
|
+
type: 'EXPECT_AMOUNT',
|
|
2856
|
+
sign: sign,
|
|
2857
|
+
unit: unit,
|
|
2858
|
+
amount: amount,
|
|
2859
|
+
};
|
|
2036
2860
|
}
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2861
|
+
catch (error) {
|
|
2862
|
+
if (!(error instanceof Error)) {
|
|
2863
|
+
throw error;
|
|
2864
|
+
}
|
|
2865
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
2042
2866
|
}
|
|
2043
|
-
|
|
2867
|
+
/*
|
|
2868
|
+
} else if (type.startsWith('__________________')) {
|
|
2869
|
+
// <- [🥻] Insert here when making new command
|
|
2870
|
+
*/
|
|
2044
2871
|
}
|
|
2045
|
-
|
|
2046
|
-
}
|
|
2047
|
-
/**
|
|
2048
|
-
* @private internal util of promptbookJsonToString
|
|
2049
|
-
*/
|
|
2050
|
-
function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
2051
|
-
var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
|
|
2052
|
-
var parameterString = "{".concat(name, "}");
|
|
2053
|
-
if (description) {
|
|
2054
|
-
parameterString = "".concat(parameterString, " ").concat(description);
|
|
2872
|
+
else {
|
|
2873
|
+
throw new PromptbookSyntaxError(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 ")));
|
|
2055
2874
|
}
|
|
2056
|
-
return parameterString;
|
|
2057
2875
|
}
|
|
2058
|
-
/**
|
|
2059
|
-
* TODO: Escape all
|
|
2060
|
-
*/
|
|
2061
2876
|
|
|
2062
2877
|
/**
|
|
2063
|
-
*
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
function PromptbookNotFoundError(message) {
|
|
2068
|
-
var _this = _super.call(this, message) || this;
|
|
2069
|
-
_this.name = 'PromptbookNotFoundError';
|
|
2070
|
-
Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
|
|
2071
|
-
return _this;
|
|
2072
|
-
}
|
|
2073
|
-
return PromptbookNotFoundError;
|
|
2074
|
-
}(Error));
|
|
2075
|
-
|
|
2076
|
-
/**
|
|
2077
|
-
* This error indicates errors in referencing promptbooks between each other
|
|
2878
|
+
* Removes emojis from a string and fix whitespaces
|
|
2879
|
+
*
|
|
2880
|
+
* @param text with emojis
|
|
2881
|
+
* @returns text without emojis
|
|
2078
2882
|
*/
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
return PromptbookReferenceError;
|
|
2088
|
-
}(Error));
|
|
2883
|
+
function removeEmojis(text) {
|
|
2884
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
2885
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
2886
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
2887
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
2888
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
2889
|
+
return text;
|
|
2890
|
+
}
|
|
2089
2891
|
|
|
2090
2892
|
/**
|
|
2091
|
-
*
|
|
2092
|
-
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
2093
|
-
*
|
|
2094
|
-
* @see https://github.com/webgptorg/promptbook#promptbook-library
|
|
2893
|
+
* Function normalizes title to name which can be used as identifier
|
|
2095
2894
|
*/
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
* Note: During the construction logic of all promptbooks are validated
|
|
2103
|
-
* Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
|
|
2104
|
-
*/
|
|
2105
|
-
function SimplePromptbookLibrary() {
|
|
2106
|
-
var e_1, _a;
|
|
2107
|
-
var promptbooks = [];
|
|
2108
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2109
|
-
promptbooks[_i] = arguments[_i];
|
|
2110
|
-
}
|
|
2111
|
-
this.library = new Map();
|
|
2112
|
-
try {
|
|
2113
|
-
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
2114
|
-
var promptbook = promptbooks_1_1.value;
|
|
2115
|
-
if (promptbook.promptbookUrl === undefined) {
|
|
2116
|
-
throw new PromptbookReferenceError(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 ")));
|
|
2117
|
-
}
|
|
2118
|
-
validatePromptbookJson(promptbook);
|
|
2119
|
-
// Note: [🦄]
|
|
2120
|
-
if (this.library.has(promptbook.promptbookUrl) &&
|
|
2121
|
-
promptbookJsonToString(promptbook) !==
|
|
2122
|
-
promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
|
|
2123
|
-
throw new PromptbookReferenceError(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 ")));
|
|
2124
|
-
}
|
|
2125
|
-
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2129
|
-
finally {
|
|
2130
|
-
try {
|
|
2131
|
-
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
2132
|
-
}
|
|
2133
|
-
finally { if (e_1) throw e_1.error; }
|
|
2134
|
-
}
|
|
2135
|
-
}
|
|
2136
|
-
/**
|
|
2137
|
-
* Gets all promptbooks in the library
|
|
2138
|
-
*/
|
|
2139
|
-
SimplePromptbookLibrary.prototype.listPromptbooks = function () {
|
|
2140
|
-
return Array.from(this.library.keys());
|
|
2141
|
-
};
|
|
2142
|
-
/**
|
|
2143
|
-
* Gets promptbook by its URL
|
|
2144
|
-
*
|
|
2145
|
-
* Note: This is not a direct fetching from the URL, but a lookup in the library
|
|
2146
|
-
*/
|
|
2147
|
-
SimplePromptbookLibrary.prototype.getPromptbookByUrl = function (url) {
|
|
2148
|
-
var _this = this;
|
|
2149
|
-
var promptbook = this.library.get(url);
|
|
2150
|
-
if (!promptbook) {
|
|
2151
|
-
if (this.listPromptbooks().length === 0) {
|
|
2152
|
-
throw new PromptbookNotFoundError(spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
2153
|
-
}
|
|
2154
|
-
throw new PromptbookNotFoundError(spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
|
|
2155
|
-
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
2156
|
-
.join('\n')), "\n\n "); }));
|
|
2157
|
-
}
|
|
2158
|
-
return promptbook;
|
|
2159
|
-
};
|
|
2160
|
-
/**
|
|
2161
|
-
* Checks whether given prompt was defined in any promptbook in the library
|
|
2162
|
-
*/
|
|
2163
|
-
SimplePromptbookLibrary.prototype.isResponsibleForPrompt = function (prompt) {
|
|
2164
|
-
return true;
|
|
2165
|
-
};
|
|
2166
|
-
return SimplePromptbookLibrary;
|
|
2167
|
-
}());
|
|
2895
|
+
function titleToName(value) {
|
|
2896
|
+
value = removeEmojis(value);
|
|
2897
|
+
value = normalizeToKebabCase(value);
|
|
2898
|
+
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
2899
|
+
return value;
|
|
2900
|
+
}
|
|
2168
2901
|
|
|
2169
2902
|
/**
|
|
2170
|
-
*
|
|
2903
|
+
* Compile promptbook from string (markdown) format to JSON format
|
|
2171
2904
|
*
|
|
2172
|
-
*
|
|
2173
|
-
*
|
|
2905
|
+
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
2906
|
+
* @param options - Options and tools for the compilation
|
|
2907
|
+
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
2908
|
+
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
2174
2909
|
*
|
|
2175
|
-
*
|
|
2176
|
-
*
|
|
2910
|
+
* Note: This function does not validate logic of the pipeline only the syntax
|
|
2911
|
+
* Note: This function acts as compilation process
|
|
2177
2912
|
*/
|
|
2178
|
-
function
|
|
2179
|
-
|
|
2180
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2181
|
-
promptbookSources[_i] = arguments[_i];
|
|
2182
|
-
}
|
|
2913
|
+
function promptbookStringToJson(promptbookString, options) {
|
|
2914
|
+
if (options === void 0) { options = {}; }
|
|
2183
2915
|
return __awaiter(this, void 0, void 0, function () {
|
|
2184
|
-
var
|
|
2185
|
-
var e_1,
|
|
2186
|
-
return __generator(this, function (
|
|
2187
|
-
switch (
|
|
2916
|
+
var llmTools, promptbookJson, knowledge, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
2917
|
+
var e_1, _c, e_2, _d;
|
|
2918
|
+
return __generator(this, function (_e) {
|
|
2919
|
+
switch (_e.label) {
|
|
2188
2920
|
case 0:
|
|
2189
|
-
|
|
2190
|
-
|
|
2921
|
+
llmTools = options.llmTools;
|
|
2922
|
+
promptbookJson = {
|
|
2923
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2924
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
2925
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
2926
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2927
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
2928
|
+
parameters: [],
|
|
2929
|
+
promptTemplates: [],
|
|
2930
|
+
knowledge: [],
|
|
2931
|
+
};
|
|
2932
|
+
if (!llmTools) return [3 /*break*/, 2];
|
|
2933
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdown({
|
|
2934
|
+
content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
|
|
2935
|
+
llmTools: llmTools,
|
|
2936
|
+
})];
|
|
2191
2937
|
case 1:
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2938
|
+
knowledge = _e.sent();
|
|
2939
|
+
console.info('!!!! knowledge', knowledge);
|
|
2940
|
+
_e.label = 2;
|
|
2195
2941
|
case 2:
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2942
|
+
// =============================================================
|
|
2943
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
2944
|
+
promptbookString = removeContentComments(promptbookString);
|
|
2945
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
2946
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
2947
|
+
addParam = function (parameterCommand) {
|
|
2948
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
2949
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
2950
|
+
if (existingParameter &&
|
|
2951
|
+
existingParameter.description &&
|
|
2952
|
+
existingParameter.description !== parameterDescription &&
|
|
2953
|
+
parameterDescription) {
|
|
2954
|
+
throw new PromptbookSyntaxError(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 "); }));
|
|
2955
|
+
}
|
|
2956
|
+
if (existingParameter) {
|
|
2957
|
+
if (parameterDescription) {
|
|
2958
|
+
existingParameter.description = parameterDescription;
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
else {
|
|
2962
|
+
promptbookJson.parameters.push({
|
|
2963
|
+
name: parameterName,
|
|
2964
|
+
description: parameterDescription || undefined,
|
|
2965
|
+
isInput: isInput,
|
|
2966
|
+
isOutput: isOutput,
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
};
|
|
2970
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
2971
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
2972
|
+
if (markdownStructureDeepness !== 2) {
|
|
2973
|
+
throw new PromptbookSyntaxError(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 ")));
|
|
2974
|
+
}
|
|
2975
|
+
promptbookJson.title = markdownStructure.title;
|
|
2976
|
+
description = markdownStructure.content;
|
|
2977
|
+
// Note: Remove codeblocks
|
|
2978
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
2979
|
+
//Note: Remove lists and return statement
|
|
2980
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
2981
|
+
description = spaceTrim(description);
|
|
2982
|
+
if (description === '') {
|
|
2983
|
+
description = undefined;
|
|
2984
|
+
}
|
|
2985
|
+
promptbookJson.description = description;
|
|
2986
|
+
defaultModelRequirements = {};
|
|
2987
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
2221
2988
|
try {
|
|
2222
|
-
|
|
2989
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
2990
|
+
listItem = listItems_1_1.value;
|
|
2991
|
+
command = parseCommand(listItem);
|
|
2992
|
+
switch (command.type) {
|
|
2993
|
+
case 'PROMPTBOOK_URL':
|
|
2994
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
2995
|
+
break;
|
|
2996
|
+
case 'PROMPTBOOK_VERSION':
|
|
2997
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
2998
|
+
break;
|
|
2999
|
+
case 'MODEL':
|
|
3000
|
+
defaultModelRequirements[command.key] = command.value;
|
|
3001
|
+
break;
|
|
3002
|
+
case 'PARAMETER':
|
|
3003
|
+
addParam(command);
|
|
3004
|
+
break;
|
|
3005
|
+
default:
|
|
3006
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
2223
3009
|
}
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
3010
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3011
|
+
finally {
|
|
3012
|
+
try {
|
|
3013
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
3014
|
+
}
|
|
3015
|
+
finally { if (e_1) throw e_1.error; }
|
|
3016
|
+
}
|
|
3017
|
+
_loop_1 = function (section) {
|
|
3018
|
+
var e_3, _f;
|
|
3019
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
3020
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
3021
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
3022
|
+
var dependentParameterNames = new Set();
|
|
3023
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
3024
|
+
var jokers = [];
|
|
3025
|
+
var postprocessing = [];
|
|
3026
|
+
var expectAmount = {};
|
|
3027
|
+
var expectFormat = undefined;
|
|
3028
|
+
var isExecutionTypeChanged = false;
|
|
3029
|
+
try {
|
|
3030
|
+
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()) {
|
|
3031
|
+
var listItem = listItems_2_1.value;
|
|
3032
|
+
var command = parseCommand(listItem);
|
|
3033
|
+
switch (command.type) {
|
|
3034
|
+
case 'JOKER':
|
|
3035
|
+
jokers.push(command.parameterName);
|
|
3036
|
+
dependentParameterNames.add(command.parameterName);
|
|
3037
|
+
break;
|
|
3038
|
+
case 'EXECUTE':
|
|
3039
|
+
if (isExecutionTypeChanged) {
|
|
3040
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
3041
|
+
}
|
|
3042
|
+
executionType = command.executionType;
|
|
3043
|
+
isExecutionTypeChanged = true;
|
|
3044
|
+
break;
|
|
3045
|
+
case 'MODEL':
|
|
3046
|
+
templateModelRequirements[command.key] = command.value;
|
|
3047
|
+
break;
|
|
3048
|
+
case 'PARAMETER':
|
|
3049
|
+
// Note: This is just for detecting resulitng parameter name
|
|
3050
|
+
addParam(command);
|
|
3051
|
+
break;
|
|
3052
|
+
case 'POSTPROCESS':
|
|
3053
|
+
postprocessing.push(command.functionName);
|
|
3054
|
+
break;
|
|
3055
|
+
case 'EXPECT_AMOUNT':
|
|
3056
|
+
// eslint-disable-next-line no-case-declarations
|
|
3057
|
+
var unit = command.unit.toLowerCase();
|
|
3058
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
3059
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
3060
|
+
if (expectAmount[unit].min !== undefined) {
|
|
3061
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3062
|
+
}
|
|
3063
|
+
expectAmount[unit].min = command.amount;
|
|
3064
|
+
} /* not else */
|
|
3065
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
3066
|
+
if (expectAmount[unit].max !== undefined) {
|
|
3067
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3068
|
+
}
|
|
3069
|
+
expectAmount[unit].max = command.amount;
|
|
3070
|
+
}
|
|
3071
|
+
break;
|
|
3072
|
+
case 'EXPECT_FORMAT':
|
|
3073
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
3074
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
3075
|
+
}
|
|
3076
|
+
expectFormat = command.format;
|
|
3077
|
+
break;
|
|
3078
|
+
default:
|
|
3079
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
3084
|
+
finally {
|
|
3085
|
+
try {
|
|
3086
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
3087
|
+
}
|
|
3088
|
+
finally { if (e_3) throw e_3.error; }
|
|
3089
|
+
}
|
|
3090
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
3091
|
+
if (executionType === 'SCRIPT') {
|
|
3092
|
+
if (!language) {
|
|
3093
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
3094
|
+
}
|
|
3095
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
3096
|
+
throw new PromptbookSyntaxError(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 "); }));
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
var lastLine = section.content.split('\n').pop();
|
|
3100
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
3101
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
3102
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
3103
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
3104
|
+
section.content
|
|
3105
|
+
.split('\n')
|
|
3106
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3107
|
+
.join('\n')), "\n "); }));
|
|
3108
|
+
}
|
|
3109
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
3110
|
+
// TODO: [1] DRY description
|
|
3111
|
+
var description_1 = section.content;
|
|
3112
|
+
// Note: Remove codeblocks
|
|
3113
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
3114
|
+
//Note: Remove lists and return statement
|
|
3115
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
3116
|
+
description_1 = spaceTrim(description_1);
|
|
3117
|
+
if (description_1 === '') {
|
|
3118
|
+
description_1 = undefined;
|
|
3119
|
+
}
|
|
3120
|
+
if (Object.keys(jokers).length === 0) {
|
|
3121
|
+
jokers = undefined;
|
|
3122
|
+
}
|
|
3123
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
3124
|
+
expectAmount = undefined;
|
|
3125
|
+
}
|
|
3126
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
3127
|
+
postprocessing = undefined;
|
|
3128
|
+
}
|
|
3129
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
3130
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
3131
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
3132
|
+
}
|
|
3133
|
+
promptbookJson.promptTemplates.push({
|
|
3134
|
+
name: titleToName(section.title),
|
|
3135
|
+
title: section.title,
|
|
3136
|
+
description: description_1,
|
|
3137
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
3138
|
+
executionType: executionType,
|
|
3139
|
+
jokers: jokers,
|
|
3140
|
+
postprocessing: postprocessing,
|
|
3141
|
+
expectations: expectAmount,
|
|
3142
|
+
expectFormat: expectFormat,
|
|
3143
|
+
modelRequirements: templateModelRequirements,
|
|
3144
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
3145
|
+
content: content,
|
|
3146
|
+
resultingParameterName: resultingParameterName,
|
|
3147
|
+
});
|
|
3148
|
+
};
|
|
3149
|
+
try {
|
|
3150
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3151
|
+
section = _b.value;
|
|
3152
|
+
_loop_1(section);
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3156
|
+
finally {
|
|
3157
|
+
try {
|
|
3158
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
3159
|
+
}
|
|
3160
|
+
finally { if (e_2) throw e_2.error; }
|
|
3161
|
+
}
|
|
3162
|
+
// =============================================================
|
|
3163
|
+
return [2 /*return*/, promptbookJson];
|
|
2227
3164
|
}
|
|
2228
3165
|
});
|
|
2229
3166
|
});
|
|
2230
3167
|
}
|
|
2231
3168
|
/**
|
|
2232
|
-
* TODO:
|
|
3169
|
+
* TODO: Report here line/column of error
|
|
3170
|
+
* TODO: Use spaceTrim more effectively
|
|
3171
|
+
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
3172
|
+
*/
|
|
3173
|
+
|
|
3174
|
+
/**
|
|
3175
|
+
* This error indicates that the promptbook library cannot be propperly loaded
|
|
3176
|
+
*/
|
|
3177
|
+
var PromptbookLibraryError = /** @class */ (function (_super) {
|
|
3178
|
+
__extends(PromptbookLibraryError, _super);
|
|
3179
|
+
function PromptbookLibraryError(message) {
|
|
3180
|
+
var _this = _super.call(this, message) || this;
|
|
3181
|
+
_this.name = 'PromptbookLibraryError';
|
|
3182
|
+
Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
|
|
3183
|
+
return _this;
|
|
3184
|
+
}
|
|
3185
|
+
return PromptbookLibraryError;
|
|
3186
|
+
}(Error));
|
|
3187
|
+
|
|
3188
|
+
/**
|
|
3189
|
+
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
3190
|
+
*/
|
|
3191
|
+
new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
3192
|
+
/**
|
|
3193
|
+
* Detects if the code is running in a Node.js environment
|
|
3194
|
+
*/
|
|
3195
|
+
var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
3196
|
+
/**
|
|
3197
|
+
* Detects if the code is running in a web worker
|
|
2233
3198
|
*/
|
|
3199
|
+
new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
2234
3200
|
|
|
2235
3201
|
/**
|
|
2236
3202
|
* Constructs Promptbook from async sources
|