@promptbook/node 0.59.0 → 0.60.0-3
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 +2 -2
- package/esm/index.es.js +279 -280
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +23 -23
- package/esm/typings/src/_packages/node.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +11 -11
- package/esm/typings/src/_packages/utils.index.d.ts +9 -11
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +12 -0
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +32 -0
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +23 -0
- package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +1 -1
- package/{umd/typings/src/conversion/prettify/prettifyPromptbookString.d.ts → esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts} +2 -2
- package/esm/typings/src/conversion/prettify/{renderPromptbookMermaid.d.ts → renderPipelineMermaidOptions.d.ts} +4 -4
- package/esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/esm/typings/src/conversion/utils/extractVariables.d.ts +1 -1
- package/esm/typings/src/conversion/utils/parseCommand.d.ts +2 -2
- package/esm/typings/src/conversion/utils/parseNumber.d.ts +1 -1
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +4 -4
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +13 -0
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +27 -0
- package/{umd/typings/src/errors/PromptbookLibraryError.d.ts → esm/typings/src/errors/CollectionError.d.ts} +2 -2
- package/esm/typings/src/errors/{PromptbookExecutionError.d.ts → ExecutionError.d.ts} +2 -2
- package/{umd/typings/src/errors/PromptbookNotFoundError.d.ts → esm/typings/src/errors/NotFoundError.d.ts} +2 -2
- package/{umd/typings/src/errors/PromptbookLogicError.d.ts → esm/typings/src/errors/PipelineLogicError.d.ts} +2 -2
- package/{umd/typings/src/errors/PromptbookReferenceError.d.ts → esm/typings/src/errors/ReferenceError.d.ts} +2 -2
- package/esm/typings/src/errors/{PromptbookSyntaxError.d.ts → SyntaxError.d.ts} +2 -2
- package/esm/typings/src/errors/TemplateError.d.ts +1 -1
- package/esm/typings/src/errors/_ExpectError.d.ts +2 -2
- package/esm/typings/src/execution/ExecutionTools.d.ts +1 -1
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +4 -4
- package/esm/typings/src/execution/PromptResult.d.ts +1 -1
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -1
- package/esm/typings/src/execution/createPromptbookExecutor.d.ts +3 -3
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
- package/esm/typings/src/library/PipelineCollection.d.ts +25 -0
- package/esm/typings/src/library/{SimplePromptbookLibrary.d.ts → SimplePipelineCollection.d.ts} +11 -11
- package/{umd/typings/src/library/constructors/createLibraryFromDirectory.d.ts → esm/typings/src/library/constructors/createCollectionFromDirectory.d.ts} +5 -5
- package/esm/typings/src/library/constructors/createCollectionFromJson.d.ts +12 -0
- package/esm/typings/src/library/constructors/createCollectionFromPromise.d.ts +22 -0
- package/esm/typings/src/library/constructors/{createLibraryFromUrl.d.ts → createCollectionFromUrl.d.ts} +5 -5
- package/esm/typings/src/library/constructors/createSubcollection.d.ts +12 -0
- package/esm/typings/src/library/libraryToJson.d.ts +5 -5
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/types/Command.d.ts +4 -4
- package/esm/typings/src/types/Parameters.d.ts +1 -1
- package/esm/typings/src/types/{PromptbookJson/PromptbookJson.d.ts → PipelineJson/PipelineJson.d.ts} +4 -4
- package/{umd/typings/src/types/PromptbookString.d.ts → esm/typings/src/types/PipelineString.d.ts} +3 -3
- package/esm/typings/src/types/Prompt.d.ts +3 -3
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +2 -2
- package/esm/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +2 -2
- package/esm/typings/src/utils/emojis.d.ts +2 -2
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/index.d.ts +2 -2
- package/esm/typings/src/utils/formatNumber.d.ts +1 -1
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
- package/esm/typings/src/utils/markdown-json/MarkdownStructure.d.ts +1 -1
- package/esm/typings/src/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
- package/esm/typings/src/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
- package/package.json +3 -3
- package/umd/index.umd.js +279 -280
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/_packages/core.index.d.ts +23 -23
- package/umd/typings/src/_packages/node.index.d.ts +2 -2
- package/umd/typings/src/_packages/types.index.d.ts +11 -11
- package/umd/typings/src/_packages/utils.index.d.ts +9 -11
- package/umd/typings/src/config.d.ts +1 -1
- package/umd/typings/src/conversion/pipelineJsonToString.d.ts +12 -0
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +32 -0
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +23 -0
- package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +1 -1
- package/{esm/typings/src/conversion/prettify/prettifyPromptbookString.d.ts → umd/typings/src/conversion/prettify/prettifyPipelineString.d.ts} +2 -2
- package/umd/typings/src/conversion/prettify/{renderPromptbookMermaid.d.ts → renderPipelineMermaidOptions.d.ts} +4 -4
- package/umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/umd/typings/src/conversion/utils/extractVariables.d.ts +1 -1
- package/umd/typings/src/conversion/utils/parseCommand.d.ts +2 -2
- package/umd/typings/src/conversion/utils/parseNumber.d.ts +1 -1
- package/umd/typings/src/conversion/utils/renameParameter.d.ts +4 -4
- package/umd/typings/src/conversion/validation/_importPipeline.d.ts +13 -0
- package/umd/typings/src/conversion/validation/validatePipeline.d.ts +27 -0
- package/{esm/typings/src/errors/PromptbookLibraryError.d.ts → umd/typings/src/errors/CollectionError.d.ts} +2 -2
- package/umd/typings/src/errors/{PromptbookExecutionError.d.ts → ExecutionError.d.ts} +2 -2
- package/{esm/typings/src/errors/PromptbookNotFoundError.d.ts → umd/typings/src/errors/NotFoundError.d.ts} +2 -2
- package/{esm/typings/src/errors/PromptbookLogicError.d.ts → umd/typings/src/errors/PipelineLogicError.d.ts} +2 -2
- package/{esm/typings/src/errors/PromptbookReferenceError.d.ts → umd/typings/src/errors/ReferenceError.d.ts} +2 -2
- package/umd/typings/src/errors/{PromptbookSyntaxError.d.ts → SyntaxError.d.ts} +2 -2
- package/umd/typings/src/errors/TemplateError.d.ts +1 -1
- package/umd/typings/src/errors/_ExpectError.d.ts +2 -2
- package/umd/typings/src/execution/ExecutionTools.d.ts +1 -1
- package/umd/typings/src/execution/LlmExecutionTools.d.ts +4 -4
- package/umd/typings/src/execution/PromptResult.d.ts +1 -1
- package/umd/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -1
- package/umd/typings/src/execution/createPromptbookExecutor.d.ts +3 -3
- package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
- package/umd/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
- package/umd/typings/src/library/PipelineCollection.d.ts +25 -0
- package/umd/typings/src/library/{SimplePromptbookLibrary.d.ts → SimplePipelineCollection.d.ts} +11 -11
- package/{esm/typings/src/library/constructors/createLibraryFromDirectory.d.ts → umd/typings/src/library/constructors/createCollectionFromDirectory.d.ts} +5 -5
- package/umd/typings/src/library/constructors/createCollectionFromJson.d.ts +12 -0
- package/umd/typings/src/library/constructors/createCollectionFromPromise.d.ts +22 -0
- package/umd/typings/src/library/constructors/{createLibraryFromUrl.d.ts → createCollectionFromUrl.d.ts} +5 -5
- package/umd/typings/src/library/constructors/createSubcollection.d.ts +12 -0
- package/umd/typings/src/library/libraryToJson.d.ts +5 -5
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -3
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +3 -3
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/umd/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -1
- package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -3
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -3
- package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
- package/umd/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +3 -3
- package/umd/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +2 -2
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/umd/typings/src/types/Command.d.ts +4 -4
- package/umd/typings/src/types/Parameters.d.ts +1 -1
- package/umd/typings/src/types/{PromptbookJson/PromptbookJson.d.ts → PipelineJson/PipelineJson.d.ts} +4 -4
- package/{esm/typings/src/types/PromptbookString.d.ts → umd/typings/src/types/PipelineString.d.ts} +3 -3
- package/umd/typings/src/types/Prompt.d.ts +3 -3
- package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +2 -2
- package/umd/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/umd/typings/src/types/typeAliases.d.ts +2 -2
- package/umd/typings/src/utils/emojis.d.ts +2 -2
- package/umd/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/index.d.ts +2 -2
- package/umd/typings/src/utils/formatNumber.d.ts +1 -1
- package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
- package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
- package/umd/typings/src/utils/markdown-json/MarkdownStructure.d.ts +1 -1
- package/umd/typings/src/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
- package/umd/typings/src/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
- package/esm/typings/src/conversion/promptbookJsonToString.d.ts +0 -12
- package/esm/typings/src/conversion/promptbookStringToJson.d.ts +0 -32
- package/esm/typings/src/conversion/promptbookStringToJsonSync.d.ts +0 -23
- package/esm/typings/src/conversion/validation/_importPromptbook.d.ts +0 -13
- package/esm/typings/src/conversion/validation/validatePromptbook.d.ts +0 -27
- package/esm/typings/src/library/PromptbookLibrary.d.ts +0 -25
- package/esm/typings/src/library/constructors/createLibraryFromJson.d.ts +0 -12
- package/esm/typings/src/library/constructors/createLibraryFromPromise.d.ts +0 -22
- package/esm/typings/src/library/constructors/createSublibrary.d.ts +0 -12
- package/umd/typings/src/conversion/promptbookJsonToString.d.ts +0 -12
- package/umd/typings/src/conversion/promptbookStringToJson.d.ts +0 -32
- package/umd/typings/src/conversion/promptbookStringToJsonSync.d.ts +0 -23
- package/umd/typings/src/conversion/validation/_importPromptbook.d.ts +0 -13
- package/umd/typings/src/conversion/validation/validatePromptbook.d.ts +0 -27
- package/umd/typings/src/library/PromptbookLibrary.d.ts +0 -25
- package/umd/typings/src/library/constructors/createLibraryFromJson.d.ts +0 -12
- package/umd/typings/src/library/constructors/createLibraryFromPromise.d.ts +0 -22
- package/umd/typings/src/library/constructors/createSublibrary.d.ts +0 -12
- /package/esm/typings/{promptbook-library → promptbook-collection}/index.d.ts +0 -0
- /package/esm/typings/src/conversion/{promptbookStringToJson.test.d.ts → pipelineStringToJson.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/{promptbookStringToJsonSync.test.d.ts → pipelineStringToJsonSync.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/validation/{promptbookStringToJson-syntaxErrors.test.d.ts → pipelineStringToJson-syntaxErrors.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/validation/{validatePromptbook-logicErrors.test.d.ts → validatePipeline-logicErrors.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/validation/{validatePromptbook.test.d.ts → validatePipeline.test.d.ts} +0 -0
- /package/esm/typings/src/library/constructors/{createLibraryFromDirectory.test.d.ts → createCollectionFromDirectory.test.d.ts} +0 -0
- /package/esm/typings/src/library/constructors/{createLibraryFromJson.test.d.ts → createCollectionFromJson.test.d.ts} +0 -0
- /package/esm/typings/src/library/constructors/{createLibraryFromPromise.test.d.ts → createCollectionFromPromise.test.d.ts} +0 -0
- /package/esm/typings/src/types/{PromptbookJson → PipelineJson}/KnowledgeJson.d.ts +0 -0
- /package/esm/typings/src/types/{PromptbookJson → PipelineJson}/MaterialKnowledgePieceJson.d.ts +0 -0
- /package/esm/typings/src/types/{PromptbookJson → PipelineJson}/PromptTemplateJson.d.ts +0 -0
- /package/esm/typings/src/types/{PromptbookJson → PipelineJson}/PromptTemplateParameterJson.d.ts +0 -0
- /package/umd/typings/{promptbook-library → promptbook-collection}/index.d.ts +0 -0
- /package/umd/typings/src/conversion/{promptbookStringToJson.test.d.ts → pipelineStringToJson.test.d.ts} +0 -0
- /package/umd/typings/src/conversion/{promptbookStringToJsonSync.test.d.ts → pipelineStringToJsonSync.test.d.ts} +0 -0
- /package/umd/typings/src/conversion/validation/{promptbookStringToJson-syntaxErrors.test.d.ts → pipelineStringToJson-syntaxErrors.test.d.ts} +0 -0
- /package/umd/typings/src/conversion/validation/{validatePromptbook-logicErrors.test.d.ts → validatePipeline-logicErrors.test.d.ts} +0 -0
- /package/umd/typings/src/conversion/validation/{validatePromptbook.test.d.ts → validatePipeline.test.d.ts} +0 -0
- /package/umd/typings/src/library/constructors/{createLibraryFromDirectory.test.d.ts → createCollectionFromDirectory.test.d.ts} +0 -0
- /package/umd/typings/src/library/constructors/{createLibraryFromJson.test.d.ts → createCollectionFromJson.test.d.ts} +0 -0
- /package/umd/typings/src/library/constructors/{createLibraryFromPromise.test.d.ts → createCollectionFromPromise.test.d.ts} +0 -0
- /package/umd/typings/src/types/{PromptbookJson → PipelineJson}/KnowledgeJson.d.ts +0 -0
- /package/umd/typings/src/types/{PromptbookJson → PipelineJson}/MaterialKnowledgePieceJson.d.ts +0 -0
- /package/umd/typings/src/types/{PromptbookJson → PipelineJson}/PromptTemplateJson.d.ts +0 -0
- /package/umd/typings/src/types/{PromptbookJson → PipelineJson}/PromptTemplateParameterJson.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -129,31 +129,31 @@ function __spreadArray(to, from, pack) {
|
|
|
129
129
|
*/
|
|
130
130
|
var LOOP_LIMIT = 1000;
|
|
131
131
|
/**
|
|
132
|
-
* The name of the builded promptbook library made by CLI `promptbook make` and for lookup in `
|
|
132
|
+
* The name of the builded promptbook library made by CLI `promptbook make` and for lookup in `createCollectionFromDirectory`
|
|
133
133
|
*/
|
|
134
134
|
var PROMPTBOOK_MAKED_BASE_FILENAME = "index";
|
|
135
135
|
|
|
136
|
-
var
|
|
136
|
+
var PipelineCollection = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.60.0-2",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",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, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"keywords"}],knowledge:[]},{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.60.0-2",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:[]}];
|
|
137
137
|
|
|
138
138
|
/**
|
|
139
139
|
* This error indicates errors during the execution of the promptbook
|
|
140
140
|
*/
|
|
141
|
-
var
|
|
142
|
-
__extends(
|
|
143
|
-
function
|
|
141
|
+
var ExecutionError = /** @class */ (function (_super) {
|
|
142
|
+
__extends(ExecutionError, _super);
|
|
143
|
+
function ExecutionError(message) {
|
|
144
144
|
var _this = _super.call(this, message) || this;
|
|
145
|
-
_this.name = '
|
|
146
|
-
Object.setPrototypeOf(_this,
|
|
145
|
+
_this.name = 'ExecutionError';
|
|
146
|
+
Object.setPrototypeOf(_this, ExecutionError.prototype);
|
|
147
147
|
return _this;
|
|
148
148
|
}
|
|
149
|
-
return
|
|
149
|
+
return ExecutionError;
|
|
150
150
|
}(Error));
|
|
151
151
|
|
|
152
152
|
/**
|
|
153
153
|
* Asserts that the execution of a promptnook is successful
|
|
154
154
|
*
|
|
155
155
|
* @param executionResult - The partial result of the promptnook execution
|
|
156
|
-
* @throws {
|
|
156
|
+
* @throws {ExecutionError} If the execution is not successful or if multiple errors occurred
|
|
157
157
|
*/
|
|
158
158
|
function assertsExecutionSuccessful(executionResult) {
|
|
159
159
|
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
@@ -161,13 +161,13 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
163
|
if (errors.length === 0) {
|
|
164
|
-
throw new
|
|
164
|
+
throw new ExecutionError("Promptnook Execution failed because of unknown reason");
|
|
165
165
|
}
|
|
166
166
|
else if (errors.length === 1) {
|
|
167
167
|
throw errors[0];
|
|
168
168
|
}
|
|
169
169
|
else {
|
|
170
|
-
throw new
|
|
170
|
+
throw new ExecutionError(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 "); }));
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
@@ -177,29 +177,29 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
177
177
|
/**
|
|
178
178
|
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
179
179
|
*/
|
|
180
|
-
var
|
|
181
|
-
__extends(
|
|
182
|
-
function
|
|
180
|
+
var PipelineLogicError = /** @class */ (function (_super) {
|
|
181
|
+
__extends(PipelineLogicError, _super);
|
|
182
|
+
function PipelineLogicError(message) {
|
|
183
183
|
var _this = _super.call(this, message) || this;
|
|
184
|
-
_this.name = '
|
|
185
|
-
Object.setPrototypeOf(_this,
|
|
184
|
+
_this.name = 'PipelineLogicError';
|
|
185
|
+
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
186
186
|
return _this;
|
|
187
187
|
}
|
|
188
|
-
return
|
|
188
|
+
return PipelineLogicError;
|
|
189
189
|
}(Error));
|
|
190
190
|
|
|
191
191
|
/**
|
|
192
192
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
193
193
|
*/
|
|
194
|
-
var
|
|
195
|
-
__extends(
|
|
196
|
-
function
|
|
194
|
+
var SyntaxError = /** @class */ (function (_super) {
|
|
195
|
+
__extends(SyntaxError, _super);
|
|
196
|
+
function SyntaxError(message) {
|
|
197
197
|
var _this = _super.call(this, message) || this;
|
|
198
|
-
_this.name = '
|
|
199
|
-
Object.setPrototypeOf(_this,
|
|
198
|
+
_this.name = 'SyntaxError';
|
|
199
|
+
Object.setPrototypeOf(_this, SyntaxError.prototype);
|
|
200
200
|
return _this;
|
|
201
201
|
}
|
|
202
|
-
return
|
|
202
|
+
return SyntaxError;
|
|
203
203
|
}(Error));
|
|
204
204
|
|
|
205
205
|
/**
|
|
@@ -242,7 +242,7 @@ function isValidUrl(url) {
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
/**
|
|
245
|
-
* Validates
|
|
245
|
+
* Validates PipelineJson if it is logically valid
|
|
246
246
|
*
|
|
247
247
|
* It checks:
|
|
248
248
|
* - if it has correct parameters dependency
|
|
@@ -251,48 +251,48 @@ function isValidUrl(url) {
|
|
|
251
251
|
* - if it is valid json
|
|
252
252
|
* - if it is meaningful
|
|
253
253
|
*
|
|
254
|
-
* @param
|
|
255
|
-
* @returns the same
|
|
256
|
-
* @throws {
|
|
254
|
+
* @param pipeline valid or invalid PipelineJson
|
|
255
|
+
* @returns the same pipeline if it is logically valid
|
|
256
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
257
257
|
*/
|
|
258
|
-
function
|
|
258
|
+
function validatePipeline(pipeline) {
|
|
259
259
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
260
260
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
261
|
-
if (
|
|
262
|
-
if (!isValidUrl(
|
|
261
|
+
if (pipeline.promptbookUrl !== undefined) {
|
|
262
|
+
if (!isValidUrl(pipeline.promptbookUrl)) {
|
|
263
263
|
// TODO: This should be maybe the syntax error detected during parsing
|
|
264
|
-
throw new
|
|
264
|
+
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.promptbookUrl, "\""));
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
268
|
-
if (!Array.isArray(
|
|
268
|
+
if (!Array.isArray(pipeline.parameters)) {
|
|
269
269
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
270
|
-
throw new
|
|
270
|
+
throw new SyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof pipeline.parameters, "\n ")));
|
|
271
271
|
}
|
|
272
272
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
273
|
-
if (!Array.isArray(
|
|
273
|
+
if (!Array.isArray(pipeline.promptTemplates)) {
|
|
274
274
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
275
|
-
throw new
|
|
275
|
+
throw new SyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n ")));
|
|
276
276
|
}
|
|
277
277
|
var _loop_1 = function (parameter) {
|
|
278
278
|
if (parameter.isInput && parameter.isOutput) {
|
|
279
|
-
throw new
|
|
279
|
+
throw new PipelineLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
|
|
280
280
|
}
|
|
281
281
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
282
282
|
if (!parameter.isInput &&
|
|
283
283
|
!parameter.isOutput &&
|
|
284
|
-
!
|
|
285
|
-
throw new
|
|
284
|
+
!pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
285
|
+
throw new PipelineLogicError(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 ")));
|
|
286
286
|
}
|
|
287
287
|
// Note: Testing that parameter is either input or result of some template
|
|
288
288
|
if (!parameter.isInput &&
|
|
289
|
-
!
|
|
290
|
-
throw new
|
|
289
|
+
!pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
290
|
+
throw new PipelineLogicError(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 ")));
|
|
291
291
|
}
|
|
292
292
|
};
|
|
293
293
|
try {
|
|
294
294
|
// Note: Check each parameter individually
|
|
295
|
-
for (var _e = __values(
|
|
295
|
+
for (var _e = __values(pipeline.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
296
296
|
var parameter = _f.value;
|
|
297
297
|
_loop_1(parameter);
|
|
298
298
|
}
|
|
@@ -305,7 +305,7 @@ function validatePromptbook(promptbook) {
|
|
|
305
305
|
finally { if (e_1) throw e_1.error; }
|
|
306
306
|
}
|
|
307
307
|
// Note: Check each template individually
|
|
308
|
-
var definedParameters = new Set(
|
|
308
|
+
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
309
309
|
var isInput = _a.isInput;
|
|
310
310
|
return isInput;
|
|
311
311
|
}).map(function (_a) {
|
|
@@ -313,25 +313,25 @@ function validatePromptbook(promptbook) {
|
|
|
313
313
|
return name;
|
|
314
314
|
}));
|
|
315
315
|
try {
|
|
316
|
-
for (var _g = __values(
|
|
316
|
+
for (var _g = __values(pipeline.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
317
317
|
var template = _h.value;
|
|
318
318
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
319
|
-
throw new
|
|
319
|
+
throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
320
320
|
}
|
|
321
321
|
definedParameters.add(template.resultingParameterName);
|
|
322
322
|
if (template.executionType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
323
|
-
throw new
|
|
323
|
+
throw new PipelineLogicError(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 ")));
|
|
324
324
|
}
|
|
325
325
|
if (template.jokers && template.jokers.length > 0) {
|
|
326
326
|
if (!template.expectFormat &&
|
|
327
327
|
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
328
|
-
throw new
|
|
328
|
+
throw new PipelineLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
|
|
329
329
|
}
|
|
330
330
|
try {
|
|
331
331
|
for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
332
332
|
var joker = _k.value;
|
|
333
333
|
if (!template.dependentParameterNames.includes(joker)) {
|
|
334
|
-
throw new
|
|
334
|
+
throw new PipelineLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
}
|
|
@@ -348,13 +348,13 @@ function validatePromptbook(promptbook) {
|
|
|
348
348
|
for (var _l = (e_4 = void 0, __values(Object.entries(template.expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
349
349
|
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
350
350
|
if (min !== undefined && max !== undefined && min > max) {
|
|
351
|
-
throw new
|
|
351
|
+
throw new PipelineLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
352
352
|
}
|
|
353
353
|
if (min !== undefined && min < 0) {
|
|
354
|
-
throw new
|
|
354
|
+
throw new PipelineLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
|
|
355
355
|
}
|
|
356
356
|
if (max !== undefined && max <= 0) {
|
|
357
|
-
throw new
|
|
357
|
+
throw new PipelineLogicError("Max expectation of ".concat(unit, " must be positive"));
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
@@ -376,7 +376,7 @@ function validatePromptbook(promptbook) {
|
|
|
376
376
|
finally { if (e_2) throw e_2.error; }
|
|
377
377
|
}
|
|
378
378
|
// Note: Detect circular dependencies
|
|
379
|
-
var resovedParameters =
|
|
379
|
+
var resovedParameters = pipeline.parameters
|
|
380
380
|
.filter(function (_a) {
|
|
381
381
|
var isInput = _a.isInput;
|
|
382
382
|
return isInput;
|
|
@@ -385,17 +385,17 @@ function validatePromptbook(promptbook) {
|
|
|
385
385
|
var name = _a.name;
|
|
386
386
|
return name;
|
|
387
387
|
});
|
|
388
|
-
var unresovedTemplates = __spreadArray([], __read(
|
|
388
|
+
var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
389
389
|
var loopLimit = LOOP_LIMIT;
|
|
390
390
|
var _loop_2 = function () {
|
|
391
391
|
if (loopLimit-- < 0) {
|
|
392
|
-
throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `
|
|
392
|
+
throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePipeline`');
|
|
393
393
|
}
|
|
394
394
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
395
395
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
396
396
|
});
|
|
397
397
|
if (currentlyResovedTemplates.length === 0) {
|
|
398
|
-
throw new
|
|
398
|
+
throw new PipelineLogicError(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
|
|
399
399
|
.map(function (_a) {
|
|
400
400
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
401
401
|
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
@@ -413,25 +413,25 @@ function validatePromptbook(promptbook) {
|
|
|
413
413
|
while (unresovedTemplates.length > 0) {
|
|
414
414
|
_loop_2();
|
|
415
415
|
}
|
|
416
|
-
return
|
|
416
|
+
return pipeline;
|
|
417
417
|
}
|
|
418
418
|
/**
|
|
419
419
|
* TODO: [🧠] Work with promptbookVersion
|
|
420
420
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
421
421
|
* > /**
|
|
422
|
-
* > * Validates
|
|
422
|
+
* > * Validates PipelineJson if it is logically valid.
|
|
423
423
|
* > *
|
|
424
424
|
* > * It checks:
|
|
425
425
|
* > * - it has a valid structure
|
|
426
426
|
* > * - ...
|
|
427
|
-
* > ex port function
|
|
427
|
+
* > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
|
|
428
428
|
*/
|
|
429
429
|
|
|
430
430
|
/**
|
|
431
431
|
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
432
432
|
*
|
|
433
|
-
* @private Always catched and rethrown as `
|
|
434
|
-
* Note: This is a kindof subtype of
|
|
433
|
+
* @private Always catched and rethrown as `ExecutionError`
|
|
434
|
+
* Note: This is a kindof subtype of ExecutionError
|
|
435
435
|
*/
|
|
436
436
|
var ExpectError = /** @class */ (function (_super) {
|
|
437
437
|
__extends(ExpectError, _super);
|
|
@@ -466,7 +466,7 @@ function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
|
466
466
|
/**
|
|
467
467
|
* The version of the Promptbook library
|
|
468
468
|
*/
|
|
469
|
-
var PROMPTBOOK_VERSION = '0.
|
|
469
|
+
var PROMPTBOOK_VERSION = '0.60.0-2';
|
|
470
470
|
|
|
471
471
|
/**
|
|
472
472
|
* Function `addUsage` will add multiple usages into one
|
|
@@ -924,7 +924,7 @@ function checkExpectations(expectations, value) {
|
|
|
924
924
|
/**
|
|
925
925
|
* This error occurs during the parameter replacement in the template
|
|
926
926
|
*
|
|
927
|
-
* Note: This is a kindof subtype of
|
|
927
|
+
* Note: This is a kindof subtype of ExecutionError because it occurs during the execution of the pipeline
|
|
928
928
|
*/
|
|
929
929
|
var TemplateError = /** @class */ (function (_super) {
|
|
930
930
|
__extends(TemplateError, _super);
|
|
@@ -1001,13 +1001,13 @@ function replaceParameters(template, parameters) {
|
|
|
1001
1001
|
* Creates executor function from promptbook and execution tools.
|
|
1002
1002
|
*
|
|
1003
1003
|
* @returns The executor function
|
|
1004
|
-
* @throws {
|
|
1004
|
+
* @throws {PipelineLogicError} on logical error in the promptbook
|
|
1005
1005
|
*/
|
|
1006
1006
|
function createPromptbookExecutor(options) {
|
|
1007
1007
|
var _this = this;
|
|
1008
1008
|
var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1009
1009
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1010
|
-
|
|
1010
|
+
validatePipeline(promptbook);
|
|
1011
1011
|
var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1012
1012
|
function executeSingleTemplate(currentTemplate) {
|
|
1013
1013
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1054,7 +1054,7 @@ function createPromptbookExecutor(options) {
|
|
|
1054
1054
|
expectError = null;
|
|
1055
1055
|
if (isJokerAttempt) {
|
|
1056
1056
|
if (typeof parametersToPass[joker] === 'undefined') {
|
|
1057
|
-
throw new
|
|
1057
|
+
throw new ExecutionError("Joker parameter {".concat(joker, "} not defined"));
|
|
1058
1058
|
}
|
|
1059
1059
|
resultString = parametersToPass[joker];
|
|
1060
1060
|
}
|
|
@@ -1134,13 +1134,13 @@ function createPromptbookExecutor(options) {
|
|
|
1134
1134
|
return [7 /*endfinally*/];
|
|
1135
1135
|
case 10:
|
|
1136
1136
|
if (errors.length === 0) {
|
|
1137
|
-
throw new
|
|
1137
|
+
throw new ExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
|
|
1138
1138
|
}
|
|
1139
1139
|
else if (errors.length === 1) {
|
|
1140
1140
|
throw errors[0];
|
|
1141
1141
|
}
|
|
1142
1142
|
else {
|
|
1143
|
-
throw new
|
|
1143
|
+
throw new ExecutionError(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 "); }));
|
|
1144
1144
|
}
|
|
1145
1145
|
}
|
|
1146
1146
|
});
|
|
@@ -1152,27 +1152,27 @@ function createPromptbookExecutor(options) {
|
|
|
1152
1152
|
case 'COMPLETION': return [3 /*break*/, 9];
|
|
1153
1153
|
}
|
|
1154
1154
|
return [3 /*break*/, 11];
|
|
1155
|
-
case 7: return [4 /*yield*/, tools.llm.
|
|
1155
|
+
case 7: return [4 /*yield*/, tools.llm.callChatModel(prompt)];
|
|
1156
1156
|
case 8:
|
|
1157
1157
|
chatThread = _o.sent();
|
|
1158
1158
|
// TODO: [🍬] Destroy chatThread
|
|
1159
1159
|
result = chatThread;
|
|
1160
1160
|
resultString = chatThread.content;
|
|
1161
1161
|
return [3 /*break*/, 12];
|
|
1162
|
-
case 9: return [4 /*yield*/, tools.llm.
|
|
1162
|
+
case 9: return [4 /*yield*/, tools.llm.callCompletionModel(prompt)];
|
|
1163
1163
|
case 10:
|
|
1164
1164
|
completionResult = _o.sent();
|
|
1165
1165
|
result = completionResult;
|
|
1166
1166
|
resultString = completionResult.content;
|
|
1167
1167
|
return [3 /*break*/, 12];
|
|
1168
|
-
case 11: throw new
|
|
1168
|
+
case 11: throw new ExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
1169
1169
|
case 12: return [3 /*break*/, 27];
|
|
1170
1170
|
case 13:
|
|
1171
1171
|
if (tools.script.length === 0) {
|
|
1172
|
-
throw new
|
|
1172
|
+
throw new ExecutionError('No script execution tools are available');
|
|
1173
1173
|
}
|
|
1174
1174
|
if (!currentTemplate.contentLanguage) {
|
|
1175
|
-
throw new
|
|
1175
|
+
throw new ExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
1176
1176
|
}
|
|
1177
1177
|
// TODO: DRY [1]
|
|
1178
1178
|
scriptExecutionErrors = [];
|
|
@@ -1224,13 +1224,13 @@ function createPromptbookExecutor(options) {
|
|
|
1224
1224
|
throw scriptExecutionErrors[0];
|
|
1225
1225
|
}
|
|
1226
1226
|
else {
|
|
1227
|
-
throw new
|
|
1227
|
+
throw new ExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
|
|
1228
1228
|
.map(function (error) { return '- ' + error.message; })
|
|
1229
1229
|
.join('\n\n')), "\n "); }));
|
|
1230
1230
|
}
|
|
1231
1231
|
case 24:
|
|
1232
1232
|
if (tools.userInterface === undefined) {
|
|
1233
|
-
throw new
|
|
1233
|
+
throw new ExecutionError('User interface tools are not available');
|
|
1234
1234
|
}
|
|
1235
1235
|
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
1236
1236
|
promptTitle: currentTemplate.title,
|
|
@@ -1244,7 +1244,7 @@ function createPromptbookExecutor(options) {
|
|
|
1244
1244
|
// TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
1245
1245
|
resultString = _o.sent();
|
|
1246
1246
|
return [3 /*break*/, 27];
|
|
1247
|
-
case 26: throw new
|
|
1247
|
+
case 26: throw new ExecutionError(
|
|
1248
1248
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1249
1249
|
"Unknown execution type \"".concat(currentTemplate.executionType, "\""));
|
|
1250
1250
|
case 27:
|
|
@@ -1369,7 +1369,7 @@ function createPromptbookExecutor(options) {
|
|
|
1369
1369
|
return [7 /*endfinally*/];
|
|
1370
1370
|
case 47:
|
|
1371
1371
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
1372
|
-
throw new
|
|
1372
|
+
throw new ExecutionError(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 "); }));
|
|
1373
1373
|
}
|
|
1374
1374
|
_o.label = 48;
|
|
1375
1375
|
case 48:
|
|
@@ -1438,7 +1438,7 @@ function createPromptbookExecutor(options) {
|
|
|
1438
1438
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
1439
1439
|
});
|
|
1440
1440
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
1441
|
-
throw new UnexpectedError(spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during
|
|
1441
|
+
throw new UnexpectedError(spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePipeline\n "));
|
|
1442
1442
|
case 1:
|
|
1443
1443
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
1444
1444
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -1571,16 +1571,16 @@ function capitalize(word) {
|
|
|
1571
1571
|
/**
|
|
1572
1572
|
* Converts promptbook in JSON format to string format
|
|
1573
1573
|
*
|
|
1574
|
-
* @param
|
|
1574
|
+
* @param pipelineJson Promptbook in JSON format (.ptbk.json)
|
|
1575
1575
|
* @returns Promptbook in string format (.ptbk.md)
|
|
1576
1576
|
*/
|
|
1577
|
-
function
|
|
1577
|
+
function pipelineJsonToString(pipelineJson) {
|
|
1578
1578
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
1579
|
-
var title =
|
|
1580
|
-
var
|
|
1579
|
+
var title = pipelineJson.title, promptbookUrl = pipelineJson.promptbookUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, promptTemplates = pipelineJson.promptTemplates;
|
|
1580
|
+
var pipelineString = "# ".concat(title);
|
|
1581
1581
|
if (description) {
|
|
1582
|
-
|
|
1583
|
-
|
|
1582
|
+
pipelineString += '\n\n';
|
|
1583
|
+
pipelineString += description;
|
|
1584
1584
|
}
|
|
1585
1585
|
// TODO:> const commands: Array<Command>
|
|
1586
1586
|
var commands = [];
|
|
@@ -1588,7 +1588,7 @@ function promptbookJsonToString(promptbookJson) {
|
|
|
1588
1588
|
commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
|
|
1589
1589
|
}
|
|
1590
1590
|
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
1591
|
-
|
|
1591
|
+
pipelineString = prettifyMarkdown(pipelineString);
|
|
1592
1592
|
try {
|
|
1593
1593
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
1594
1594
|
var isInput = _a.isInput;
|
|
@@ -1621,8 +1621,8 @@ function promptbookJsonToString(promptbookJson) {
|
|
|
1621
1621
|
}
|
|
1622
1622
|
finally { if (e_2) throw e_2.error; }
|
|
1623
1623
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1624
|
+
pipelineString += '\n\n';
|
|
1625
|
+
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1626
1626
|
try {
|
|
1627
1627
|
for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
|
|
1628
1628
|
var promptTemplate = promptTemplates_1_1.value;
|
|
@@ -1631,11 +1631,11 @@ function promptbookJsonToString(promptbookJson) {
|
|
|
1631
1631
|
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
1632
1632
|
/* Note: dependentParameterNames, */
|
|
1633
1633
|
jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
1634
|
-
|
|
1635
|
-
|
|
1634
|
+
pipelineString += '\n\n';
|
|
1635
|
+
pipelineString += "## ".concat(title_1);
|
|
1636
1636
|
if (description_1) {
|
|
1637
|
-
|
|
1638
|
-
|
|
1637
|
+
pipelineString += '\n\n';
|
|
1638
|
+
pipelineString += description_1;
|
|
1639
1639
|
}
|
|
1640
1640
|
// TODO:> const commands: Array<Command>
|
|
1641
1641
|
var commands_1 = [];
|
|
@@ -1729,18 +1729,18 @@ function promptbookJsonToString(promptbookJson) {
|
|
|
1729
1729
|
commands_1.push("EXPECT JSON");
|
|
1730
1730
|
}
|
|
1731
1731
|
} /* not else */
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1732
|
+
pipelineString += '\n\n';
|
|
1733
|
+
pipelineString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1734
|
+
pipelineString += '\n\n';
|
|
1735
|
+
pipelineString += '```' + contentLanguage;
|
|
1736
|
+
pipelineString += '\n';
|
|
1737
|
+
pipelineString += spaceTrim$1(content);
|
|
1738
1738
|
// <- TODO: !!! Escape
|
|
1739
1739
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1740
|
+
pipelineString += '\n';
|
|
1741
|
+
pipelineString += '```';
|
|
1742
|
+
pipelineString += '\n\n';
|
|
1743
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
1744
1744
|
}
|
|
1745
1745
|
}
|
|
1746
1746
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -1750,10 +1750,10 @@ function promptbookJsonToString(promptbookJson) {
|
|
|
1750
1750
|
}
|
|
1751
1751
|
finally { if (e_3) throw e_3.error; }
|
|
1752
1752
|
}
|
|
1753
|
-
return
|
|
1753
|
+
return pipelineString;
|
|
1754
1754
|
}
|
|
1755
1755
|
/**
|
|
1756
|
-
* @private internal util of
|
|
1756
|
+
* @private internal util of pipelineJsonToString
|
|
1757
1757
|
*/
|
|
1758
1758
|
function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
1759
1759
|
var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
|
|
@@ -1770,49 +1770,49 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
1770
1770
|
/**
|
|
1771
1771
|
* This error indicates that promptbook not found in the library
|
|
1772
1772
|
*/
|
|
1773
|
-
var
|
|
1774
|
-
__extends(
|
|
1775
|
-
function
|
|
1773
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
1774
|
+
__extends(NotFoundError, _super);
|
|
1775
|
+
function NotFoundError(message) {
|
|
1776
1776
|
var _this = _super.call(this, message) || this;
|
|
1777
|
-
_this.name = '
|
|
1778
|
-
Object.setPrototypeOf(_this,
|
|
1777
|
+
_this.name = 'NotFoundError';
|
|
1778
|
+
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
1779
1779
|
return _this;
|
|
1780
1780
|
}
|
|
1781
|
-
return
|
|
1781
|
+
return NotFoundError;
|
|
1782
1782
|
}(Error));
|
|
1783
1783
|
|
|
1784
1784
|
/**
|
|
1785
1785
|
* This error indicates errors in referencing promptbooks between each other
|
|
1786
1786
|
*/
|
|
1787
|
-
var
|
|
1788
|
-
__extends(
|
|
1789
|
-
function
|
|
1787
|
+
var ReferenceError$1 = /** @class */ (function (_super) {
|
|
1788
|
+
__extends(ReferenceError, _super);
|
|
1789
|
+
function ReferenceError(message) {
|
|
1790
1790
|
var _this = _super.call(this, message) || this;
|
|
1791
|
-
_this.name = '
|
|
1792
|
-
Object.setPrototypeOf(_this,
|
|
1791
|
+
_this.name = 'ReferenceError';
|
|
1792
|
+
Object.setPrototypeOf(_this, ReferenceError.prototype);
|
|
1793
1793
|
return _this;
|
|
1794
1794
|
}
|
|
1795
|
-
return
|
|
1795
|
+
return ReferenceError;
|
|
1796
1796
|
}(Error));
|
|
1797
1797
|
|
|
1798
1798
|
/**
|
|
1799
1799
|
* Library of promptbooks that groups together promptbooks for an application.
|
|
1800
1800
|
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
1801
1801
|
*
|
|
1802
|
-
* @private use `
|
|
1803
|
-
* @see https://github.com/webgptorg/promptbook#promptbook-
|
|
1802
|
+
* @private use `createCollectionFromJson` instead
|
|
1803
|
+
* @see https://github.com/webgptorg/promptbook#promptbook-collection
|
|
1804
1804
|
*/
|
|
1805
|
-
var
|
|
1805
|
+
var SimplePipelineCollection = /** @class */ (function () {
|
|
1806
1806
|
/**
|
|
1807
1807
|
* Constructs a promptbook library from promptbooks
|
|
1808
1808
|
*
|
|
1809
1809
|
* @param promptbooks !!!
|
|
1810
1810
|
*
|
|
1811
|
-
* @private Use instead `
|
|
1811
|
+
* @private Use instead `createCollectionFromJson`
|
|
1812
1812
|
* Note: During the construction logic of all promptbooks are validated
|
|
1813
|
-
* Note: It is not recommended to use this constructor directly, use `
|
|
1813
|
+
* Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
|
|
1814
1814
|
*/
|
|
1815
|
-
function
|
|
1815
|
+
function SimplePipelineCollection() {
|
|
1816
1816
|
var e_1, _a;
|
|
1817
1817
|
var promptbooks = [];
|
|
1818
1818
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -1823,14 +1823,13 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
1823
1823
|
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
1824
1824
|
var promptbook = promptbooks_1_1.value;
|
|
1825
1825
|
if (promptbook.promptbookUrl === undefined) {
|
|
1826
|
-
throw new
|
|
1826
|
+
throw new ReferenceError$1(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 ")));
|
|
1827
1827
|
}
|
|
1828
|
-
|
|
1828
|
+
validatePipeline(promptbook);
|
|
1829
1829
|
// Note: [🦄]
|
|
1830
1830
|
if (this.library.has(promptbook.promptbookUrl) &&
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
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 ")));
|
|
1831
|
+
pipelineJsonToString(promptbook) !== pipelineJsonToString(this.library.get(promptbook.promptbookUrl))) {
|
|
1832
|
+
throw new ReferenceError$1(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 ")));
|
|
1834
1833
|
}
|
|
1835
1834
|
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
1836
1835
|
}
|
|
@@ -1846,7 +1845,7 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
1846
1845
|
/**
|
|
1847
1846
|
* Gets all promptbooks in the library
|
|
1848
1847
|
*/
|
|
1849
|
-
|
|
1848
|
+
SimplePipelineCollection.prototype.listPipelines = function () {
|
|
1850
1849
|
return Array.from(this.library.keys());
|
|
1851
1850
|
};
|
|
1852
1851
|
/**
|
|
@@ -1854,14 +1853,14 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
1854
1853
|
*
|
|
1855
1854
|
* Note: This is not a direct fetching from the URL, but a lookup in the library
|
|
1856
1855
|
*/
|
|
1857
|
-
|
|
1856
|
+
SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
|
|
1858
1857
|
var _this = this;
|
|
1859
1858
|
var promptbook = this.library.get(url);
|
|
1860
1859
|
if (!promptbook) {
|
|
1861
|
-
if (this.
|
|
1862
|
-
throw new
|
|
1860
|
+
if (this.listPipelines().length === 0) {
|
|
1861
|
+
throw new NotFoundError(spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
1863
1862
|
}
|
|
1864
|
-
throw new
|
|
1863
|
+
throw new NotFoundError(spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPipelines()
|
|
1865
1864
|
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
1866
1865
|
.join('\n')), "\n\n "); }));
|
|
1867
1866
|
}
|
|
@@ -1870,27 +1869,27 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
1870
1869
|
/**
|
|
1871
1870
|
* Checks whether given prompt was defined in any promptbook in the library
|
|
1872
1871
|
*/
|
|
1873
|
-
|
|
1872
|
+
SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
|
|
1874
1873
|
return true;
|
|
1875
1874
|
};
|
|
1876
|
-
return
|
|
1875
|
+
return SimplePipelineCollection;
|
|
1877
1876
|
}());
|
|
1878
1877
|
|
|
1879
1878
|
/**
|
|
1880
|
-
* Creates
|
|
1879
|
+
* Creates PipelineCollection from array of PipelineJson or PipelineString
|
|
1881
1880
|
*
|
|
1882
|
-
* Note: Functions `libraryToJson` and `
|
|
1881
|
+
* Note: Functions `libraryToJson` and `createCollectionFromJson` are complementary
|
|
1883
1882
|
* Note: During the construction syntax and logic of all sources are validated
|
|
1884
1883
|
*
|
|
1885
1884
|
* @param promptbookSources
|
|
1886
|
-
* @returns
|
|
1885
|
+
* @returns PipelineCollection
|
|
1887
1886
|
*/
|
|
1888
|
-
function
|
|
1887
|
+
function createCollectionFromJson() {
|
|
1889
1888
|
var promptbooks = [];
|
|
1890
1889
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1891
1890
|
promptbooks[_i] = arguments[_i];
|
|
1892
1891
|
}
|
|
1893
|
-
return new (
|
|
1892
|
+
return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
1894
1893
|
}
|
|
1895
1894
|
|
|
1896
1895
|
/* tslint:disable */
|
|
@@ -1956,8 +1955,8 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
1956
1955
|
switch (_b.label) {
|
|
1957
1956
|
case 0:
|
|
1958
1957
|
content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
1959
|
-
library =
|
|
1960
|
-
return [4 /*yield*/, library.
|
|
1958
|
+
library = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
1959
|
+
return [4 /*yield*/, library.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
1961
1960
|
case 1:
|
|
1962
1961
|
prepareKnowledgeFromMarkdownPromptbook = _b.sent();
|
|
1963
1962
|
prepareKnowledgeFromMarkdownExecutor = createPromptbookExecutor({
|
|
@@ -1969,7 +1968,7 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
1969
1968
|
],
|
|
1970
1969
|
},
|
|
1971
1970
|
});
|
|
1972
|
-
return [4 /*yield*/, library.
|
|
1971
|
+
return [4 /*yield*/, library.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-keywords.ptbk.md')];
|
|
1973
1972
|
case 2:
|
|
1974
1973
|
prepareKeywordsPromptbook = _b.sent();
|
|
1975
1974
|
prepareKeywordsExecutor = createPromptbookExecutor({
|
|
@@ -2058,7 +2057,7 @@ var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
|
2058
2057
|
/**
|
|
2059
2058
|
* Computes the deepness of the markdown structure.
|
|
2060
2059
|
*
|
|
2061
|
-
* @private within the
|
|
2060
|
+
* @private within the package
|
|
2062
2061
|
*/
|
|
2063
2062
|
function countMarkdownStructureDeepness(markdownStructure) {
|
|
2064
2063
|
var e_1, _a;
|
|
@@ -2088,7 +2087,7 @@ function countMarkdownStructureDeepness(markdownStructure) {
|
|
|
2088
2087
|
* @param markdown The markdown string to parse.
|
|
2089
2088
|
* @returns The MarkdownStructure object.
|
|
2090
2089
|
*
|
|
2091
|
-
* @private within the
|
|
2090
|
+
* @private within the package
|
|
2092
2091
|
*/
|
|
2093
2092
|
function markdownToMarkdownStructure(markdown) {
|
|
2094
2093
|
var e_1, _a;
|
|
@@ -2363,7 +2362,7 @@ function extractParameters(template) {
|
|
|
2363
2362
|
*
|
|
2364
2363
|
* @param script from which to extract the variables
|
|
2365
2364
|
* @returns the list of variable names
|
|
2366
|
-
* @throws {
|
|
2365
|
+
* @throws {SyntaxError} if the script is invalid
|
|
2367
2366
|
*/
|
|
2368
2367
|
function extractVariables(script) {
|
|
2369
2368
|
var variables = new Set();
|
|
@@ -2399,7 +2398,7 @@ function extractVariables(script) {
|
|
|
2399
2398
|
if (!(error instanceof Error)) {
|
|
2400
2399
|
throw error;
|
|
2401
2400
|
}
|
|
2402
|
-
throw new
|
|
2401
|
+
throw new SyntaxError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
2403
2402
|
}
|
|
2404
2403
|
return variables;
|
|
2405
2404
|
}
|
|
@@ -2412,7 +2411,7 @@ function extractVariables(script) {
|
|
|
2412
2411
|
*
|
|
2413
2412
|
* @param promptTemplate the template with used parameters
|
|
2414
2413
|
* @returns the set of parameter names
|
|
2415
|
-
* @throws {
|
|
2414
|
+
* @throws {SyntaxError} if the script is invalid
|
|
2416
2415
|
*/
|
|
2417
2416
|
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
2418
2417
|
var e_1, _a, e_2, _b;
|
|
@@ -2451,6 +2450,45 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
2451
2450
|
* TODO: [🔣] If script require contentLanguage
|
|
2452
2451
|
*/
|
|
2453
2452
|
|
|
2453
|
+
/**
|
|
2454
|
+
* Execution type describes the way how the block is executed
|
|
2455
|
+
*
|
|
2456
|
+
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
2457
|
+
*/
|
|
2458
|
+
var ExecutionTypes = [
|
|
2459
|
+
'PROMPT_TEMPLATE',
|
|
2460
|
+
'SIMPLE_TEMPLATE',
|
|
2461
|
+
'SCRIPT',
|
|
2462
|
+
'PROMPT_DIALOG',
|
|
2463
|
+
// <- [🥻] Insert here when making new command
|
|
2464
|
+
];
|
|
2465
|
+
|
|
2466
|
+
/**
|
|
2467
|
+
* Units of text measurement
|
|
2468
|
+
*/
|
|
2469
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2470
|
+
/**
|
|
2471
|
+
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
2472
|
+
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
2473
|
+
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
2474
|
+
*/
|
|
2475
|
+
|
|
2476
|
+
/**
|
|
2477
|
+
* Removes Markdown formatting tags from a string.
|
|
2478
|
+
*
|
|
2479
|
+
* @param {string} str - The string to remove Markdown tags from.
|
|
2480
|
+
* @returns {string} The input string with all Markdown tags removed.
|
|
2481
|
+
*/
|
|
2482
|
+
function removeMarkdownFormatting(str) {
|
|
2483
|
+
// Remove bold formatting
|
|
2484
|
+
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
2485
|
+
// Remove italic formatting
|
|
2486
|
+
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
2487
|
+
// Remove code formatting
|
|
2488
|
+
str = str.replace(/`(.*?)`/g, '$1');
|
|
2489
|
+
return str;
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2454
2492
|
/* tslint:disable */
|
|
2455
2493
|
/*
|
|
2456
2494
|
TODO: Tests
|
|
@@ -2515,45 +2553,6 @@ function normalizeTo_SCREAMING_CASE(sentence) {
|
|
|
2515
2553
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
2516
2554
|
*/
|
|
2517
2555
|
|
|
2518
|
-
/**
|
|
2519
|
-
* Execution type describes the way how the block is executed
|
|
2520
|
-
*
|
|
2521
|
-
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
2522
|
-
*/
|
|
2523
|
-
var ExecutionTypes = [
|
|
2524
|
-
'PROMPT_TEMPLATE',
|
|
2525
|
-
'SIMPLE_TEMPLATE',
|
|
2526
|
-
'SCRIPT',
|
|
2527
|
-
'PROMPT_DIALOG',
|
|
2528
|
-
// <- [🥻] Insert here when making new command
|
|
2529
|
-
];
|
|
2530
|
-
|
|
2531
|
-
/**
|
|
2532
|
-
* Units of text measurement
|
|
2533
|
-
*/
|
|
2534
|
-
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2535
|
-
/**
|
|
2536
|
-
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
2537
|
-
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
2538
|
-
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
2539
|
-
*/
|
|
2540
|
-
|
|
2541
|
-
/**
|
|
2542
|
-
* Removes Markdown formatting tags from a string.
|
|
2543
|
-
*
|
|
2544
|
-
* @param {string} str - The string to remove Markdown tags from.
|
|
2545
|
-
* @returns {string} The input string with all Markdown tags removed.
|
|
2546
|
-
*/
|
|
2547
|
-
function removeMarkdownFormatting(str) {
|
|
2548
|
-
// Remove bold formatting
|
|
2549
|
-
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
2550
|
-
// Remove italic formatting
|
|
2551
|
-
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
2552
|
-
// Remove code formatting
|
|
2553
|
-
str = str.replace(/`(.*?)`/g, '$1');
|
|
2554
|
-
return str;
|
|
2555
|
-
}
|
|
2556
|
-
|
|
2557
2556
|
/**
|
|
2558
2557
|
* Function parseNumber will parse number from string
|
|
2559
2558
|
*
|
|
@@ -2561,7 +2560,7 @@ function removeMarkdownFormatting(str) {
|
|
|
2561
2560
|
* Note: it also works only with decimal numbers
|
|
2562
2561
|
*
|
|
2563
2562
|
* @returns parsed number
|
|
2564
|
-
* @throws {
|
|
2563
|
+
* @throws {SyntaxError} if the value is not a number
|
|
2565
2564
|
*
|
|
2566
2565
|
* @private within the parseCommand
|
|
2567
2566
|
*/
|
|
@@ -2597,7 +2596,7 @@ function parseNumber(value) {
|
|
|
2597
2596
|
var numerator = parseNumber(numerator_);
|
|
2598
2597
|
var denominator = parseNumber(denominator_);
|
|
2599
2598
|
if (denominator === 0) {
|
|
2600
|
-
throw new
|
|
2599
|
+
throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
2601
2600
|
}
|
|
2602
2601
|
return numerator / denominator;
|
|
2603
2602
|
}
|
|
@@ -2609,11 +2608,11 @@ function parseNumber(value) {
|
|
|
2609
2608
|
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
2610
2609
|
}
|
|
2611
2610
|
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
2612
|
-
throw new
|
|
2611
|
+
throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
2613
2612
|
}
|
|
2614
2613
|
var num = parseFloat(value);
|
|
2615
2614
|
if (isNaN(num)) {
|
|
2616
|
-
throw new
|
|
2615
|
+
throw new SyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
2617
2616
|
}
|
|
2618
2617
|
return num;
|
|
2619
2618
|
}
|
|
@@ -2625,14 +2624,14 @@ function parseNumber(value) {
|
|
|
2625
2624
|
* Parses one line of ul/ol to command
|
|
2626
2625
|
*
|
|
2627
2626
|
* @returns parsed command object
|
|
2628
|
-
* @throws {
|
|
2627
|
+
* @throws {SyntaxError} if the command is invalid
|
|
2629
2628
|
*
|
|
2630
|
-
* @private within the
|
|
2629
|
+
* @private within the pipelineStringToJson
|
|
2631
2630
|
*/
|
|
2632
2631
|
function parseCommand(listItem) {
|
|
2633
2632
|
var e_1, _a;
|
|
2634
2633
|
if (listItem.includes('\n') || listItem.includes('\r')) {
|
|
2635
|
-
throw new
|
|
2634
|
+
throw new SyntaxError('Command can not contain new line characters:');
|
|
2636
2635
|
}
|
|
2637
2636
|
var type = listItem.trim();
|
|
2638
2637
|
type = type.split('`').join('');
|
|
@@ -2659,15 +2658,15 @@ function parseCommand(listItem) {
|
|
|
2659
2658
|
type.startsWith('PROMPTBOOKURL') ||
|
|
2660
2659
|
type.startsWith('HTTPS')) {
|
|
2661
2660
|
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
2662
|
-
throw new
|
|
2661
|
+
throw new SyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
2663
2662
|
}
|
|
2664
2663
|
var promptbookUrlString = listItemParts.pop();
|
|
2665
2664
|
var promptbookUrl = new URL(promptbookUrlString);
|
|
2666
2665
|
if (promptbookUrl.protocol !== 'https:') {
|
|
2667
|
-
throw new
|
|
2666
|
+
throw new SyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
2668
2667
|
}
|
|
2669
2668
|
if (promptbookUrl.hash !== '') {
|
|
2670
|
-
throw new
|
|
2669
|
+
throw new SyntaxError(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 ")));
|
|
2671
2670
|
}
|
|
2672
2671
|
return {
|
|
2673
2672
|
type: 'PROMPTBOOK_URL',
|
|
@@ -2676,7 +2675,7 @@ function parseCommand(listItem) {
|
|
|
2676
2675
|
}
|
|
2677
2676
|
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
2678
2677
|
if (listItemParts.length !== 2) {
|
|
2679
|
-
throw new
|
|
2678
|
+
throw new SyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
2680
2679
|
}
|
|
2681
2680
|
var promptbookVersion = listItemParts.pop();
|
|
2682
2681
|
// TODO: Validate version
|
|
@@ -2691,7 +2690,7 @@ function parseCommand(listItem) {
|
|
|
2691
2690
|
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
2692
2691
|
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
2693
2692
|
if (executionTypes.length !== 1) {
|
|
2694
|
-
throw new
|
|
2693
|
+
throw new SyntaxError(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 "); }));
|
|
2695
2694
|
}
|
|
2696
2695
|
return {
|
|
2697
2696
|
type: 'EXECUTE',
|
|
@@ -2716,7 +2715,7 @@ function parseCommand(listItem) {
|
|
|
2716
2715
|
};
|
|
2717
2716
|
}
|
|
2718
2717
|
else {
|
|
2719
|
-
throw new
|
|
2718
|
+
throw new SyntaxError(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 "); }));
|
|
2720
2719
|
}
|
|
2721
2720
|
}
|
|
2722
2721
|
if (type.startsWith('MODEL_NAME')) {
|
|
@@ -2727,7 +2726,7 @@ function parseCommand(listItem) {
|
|
|
2727
2726
|
};
|
|
2728
2727
|
}
|
|
2729
2728
|
else {
|
|
2730
|
-
throw new
|
|
2729
|
+
throw new SyntaxError(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 "); }));
|
|
2731
2730
|
}
|
|
2732
2731
|
}
|
|
2733
2732
|
else if (type.startsWith('PARAM') ||
|
|
@@ -2737,12 +2736,12 @@ function parseCommand(listItem) {
|
|
|
2737
2736
|
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
2738
2737
|
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
2739
2738
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2740
|
-
throw new
|
|
2739
|
+
throw new SyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2741
2740
|
}
|
|
2742
2741
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2743
2742
|
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
2744
2743
|
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
2745
|
-
throw new
|
|
2744
|
+
throw new SyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
2746
2745
|
}
|
|
2747
2746
|
var isInput = type.startsWith('INPUT');
|
|
2748
2747
|
var isOutput = type.startsWith('OUTPUT');
|
|
@@ -2760,11 +2759,11 @@ function parseCommand(listItem) {
|
|
|
2760
2759
|
}
|
|
2761
2760
|
else if (type.startsWith('JOKER')) {
|
|
2762
2761
|
if (listItemParts.length !== 2) {
|
|
2763
|
-
throw new
|
|
2762
|
+
throw new SyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
2764
2763
|
}
|
|
2765
2764
|
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
2766
2765
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2767
|
-
throw new
|
|
2766
|
+
throw new SyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2768
2767
|
}
|
|
2769
2768
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2770
2769
|
var parameterName = parametersMatch.groups.parameterName;
|
|
@@ -2775,7 +2774,7 @@ function parseCommand(listItem) {
|
|
|
2775
2774
|
}
|
|
2776
2775
|
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
2777
2776
|
if (listItemParts.length !== 2) {
|
|
2778
|
-
throw new
|
|
2777
|
+
throw new SyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
2779
2778
|
}
|
|
2780
2779
|
var functionName = listItemParts.pop();
|
|
2781
2780
|
return {
|
|
@@ -2805,15 +2804,15 @@ function parseCommand(listItem) {
|
|
|
2805
2804
|
sign = 'MAXIMUM';
|
|
2806
2805
|
}
|
|
2807
2806
|
else {
|
|
2808
|
-
throw new
|
|
2807
|
+
throw new SyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
|
|
2809
2808
|
}
|
|
2810
2809
|
var amountRaw = listItemParts.shift();
|
|
2811
2810
|
var amount = parseNumber(amountRaw);
|
|
2812
2811
|
if (amount < 0) {
|
|
2813
|
-
throw new
|
|
2812
|
+
throw new SyntaxError('Amount must be positive number or zero');
|
|
2814
2813
|
}
|
|
2815
2814
|
if (amount !== Math.floor(amount)) {
|
|
2816
|
-
throw new
|
|
2815
|
+
throw new SyntaxError('Amount must be whole number');
|
|
2817
2816
|
}
|
|
2818
2817
|
var unitRaw = listItemParts.shift();
|
|
2819
2818
|
var unit = undefined;
|
|
@@ -2828,7 +2827,7 @@ function parseCommand(listItem) {
|
|
|
2828
2827
|
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
2829
2828
|
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
2830
2829
|
if (unit !== undefined) {
|
|
2831
|
-
throw new
|
|
2830
|
+
throw new SyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
2832
2831
|
}
|
|
2833
2832
|
unit = existingUnit;
|
|
2834
2833
|
}
|
|
@@ -2842,7 +2841,7 @@ function parseCommand(listItem) {
|
|
|
2842
2841
|
finally { if (e_1) throw e_1.error; }
|
|
2843
2842
|
}
|
|
2844
2843
|
if (unit === undefined) {
|
|
2845
|
-
throw new
|
|
2844
|
+
throw new SyntaxError("Invalid unit \"".concat(unitRaw, "\""));
|
|
2846
2845
|
}
|
|
2847
2846
|
return {
|
|
2848
2847
|
type: 'EXPECT_AMOUNT',
|
|
@@ -2855,7 +2854,7 @@ function parseCommand(listItem) {
|
|
|
2855
2854
|
if (!(error instanceof Error)) {
|
|
2856
2855
|
throw error;
|
|
2857
2856
|
}
|
|
2858
|
-
throw new
|
|
2857
|
+
throw new SyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
2859
2858
|
}
|
|
2860
2859
|
/*
|
|
2861
2860
|
} else if (type.startsWith('__________________')) {
|
|
@@ -2863,7 +2862,7 @@ function parseCommand(listItem) {
|
|
|
2863
2862
|
*/
|
|
2864
2863
|
}
|
|
2865
2864
|
else {
|
|
2866
|
-
throw new
|
|
2865
|
+
throw new SyntaxError(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 ")));
|
|
2867
2866
|
}
|
|
2868
2867
|
}
|
|
2869
2868
|
|
|
@@ -2896,20 +2895,20 @@ function titleToName(value) {
|
|
|
2896
2895
|
* Compile promptbook from string (markdown) format to JSON format synchronously
|
|
2897
2896
|
*
|
|
2898
2897
|
* Note: There are two similar functions:
|
|
2899
|
-
* - `
|
|
2900
|
-
* - `
|
|
2898
|
+
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
2899
|
+
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
2901
2900
|
*
|
|
2902
|
-
* @param
|
|
2901
|
+
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
2903
2902
|
* @param options - Options and tools for the compilation
|
|
2904
2903
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
2905
|
-
* @throws {
|
|
2904
|
+
* @throws {SyntaxError} if the promptbook string is not valid
|
|
2906
2905
|
*
|
|
2907
2906
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
2908
2907
|
* Note: This function acts as compilation process
|
|
2909
2908
|
*/
|
|
2910
|
-
function
|
|
2909
|
+
function pipelineStringToJsonSync(pipelineString) {
|
|
2911
2910
|
var e_1, _a, e_2, _b;
|
|
2912
|
-
var
|
|
2911
|
+
var pipelineJson = {
|
|
2913
2912
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2914
2913
|
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
2915
2914
|
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
@@ -2921,19 +2920,19 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
2921
2920
|
};
|
|
2922
2921
|
// =============================================================
|
|
2923
2922
|
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2923
|
+
pipelineString = removeContentComments(pipelineString);
|
|
2924
|
+
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
2925
|
+
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
2927
2926
|
// =============================================================
|
|
2928
2927
|
///Note: 2️⃣ Function for adding parameters
|
|
2929
2928
|
var addParam = function (parameterCommand) {
|
|
2930
2929
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
2931
|
-
var existingParameter =
|
|
2930
|
+
var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
2932
2931
|
if (existingParameter &&
|
|
2933
2932
|
existingParameter.description &&
|
|
2934
2933
|
existingParameter.description !== parameterDescription &&
|
|
2935
2934
|
parameterDescription) {
|
|
2936
|
-
throw new
|
|
2935
|
+
throw new SyntaxError(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 "); }));
|
|
2937
2936
|
}
|
|
2938
2937
|
if (existingParameter) {
|
|
2939
2938
|
if (parameterDescription) {
|
|
@@ -2941,7 +2940,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
2941
2940
|
}
|
|
2942
2941
|
}
|
|
2943
2942
|
else {
|
|
2944
|
-
|
|
2943
|
+
pipelineJson.parameters.push({
|
|
2945
2944
|
name: parameterName,
|
|
2946
2945
|
description: parameterDescription || undefined,
|
|
2947
2946
|
isInput: isInput,
|
|
@@ -2950,13 +2949,13 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
2950
2949
|
}
|
|
2951
2950
|
};
|
|
2952
2951
|
// =============================================================
|
|
2953
|
-
// Note: 3️⃣ Parse the dynamic part - the
|
|
2954
|
-
var markdownStructure = markdownToMarkdownStructure(
|
|
2952
|
+
// Note: 3️⃣ Parse the dynamic part - the pipeline
|
|
2953
|
+
var markdownStructure = markdownToMarkdownStructure(pipelineString);
|
|
2955
2954
|
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
2956
2955
|
if (markdownStructureDeepness !== 2) {
|
|
2957
|
-
throw new
|
|
2956
|
+
throw new SyntaxError(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 ")));
|
|
2958
2957
|
}
|
|
2959
|
-
|
|
2958
|
+
pipelineJson.title = markdownStructure.title;
|
|
2960
2959
|
// TODO: [1] DRY description
|
|
2961
2960
|
var description = markdownStructure.content;
|
|
2962
2961
|
// Note: Remove codeblocks
|
|
@@ -2967,7 +2966,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
2967
2966
|
if (description === '') {
|
|
2968
2967
|
description = undefined;
|
|
2969
2968
|
}
|
|
2970
|
-
|
|
2969
|
+
pipelineJson.description = description;
|
|
2971
2970
|
var defaultModelRequirements = {};
|
|
2972
2971
|
var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
2973
2972
|
try {
|
|
@@ -2976,10 +2975,10 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
2976
2975
|
var command = parseCommand(listItem);
|
|
2977
2976
|
switch (command.type) {
|
|
2978
2977
|
case 'PROMPTBOOK_URL':
|
|
2979
|
-
|
|
2978
|
+
pipelineJson.promptbookUrl = command.promptbookUrl.href;
|
|
2980
2979
|
break;
|
|
2981
2980
|
case 'PROMPTBOOK_VERSION':
|
|
2982
|
-
|
|
2981
|
+
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
2983
2982
|
break;
|
|
2984
2983
|
case 'MODEL':
|
|
2985
2984
|
defaultModelRequirements[command.key] = command.value;
|
|
@@ -2988,7 +2987,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
2988
2987
|
addParam(command);
|
|
2989
2988
|
break;
|
|
2990
2989
|
default:
|
|
2991
|
-
throw new
|
|
2990
|
+
throw new SyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
2992
2991
|
}
|
|
2993
2992
|
}
|
|
2994
2993
|
}
|
|
@@ -3022,7 +3021,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3022
3021
|
break;
|
|
3023
3022
|
case 'EXECUTE':
|
|
3024
3023
|
if (isExecutionTypeChanged) {
|
|
3025
|
-
throw new
|
|
3024
|
+
throw new SyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
3026
3025
|
}
|
|
3027
3026
|
executionType = command.executionType;
|
|
3028
3027
|
isExecutionTypeChanged = true;
|
|
@@ -3043,25 +3042,25 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3043
3042
|
expectAmount[unit] = expectAmount[unit] || {};
|
|
3044
3043
|
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
3045
3044
|
if (expectAmount[unit].min !== undefined) {
|
|
3046
|
-
throw new
|
|
3045
|
+
throw new SyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3047
3046
|
}
|
|
3048
3047
|
expectAmount[unit].min = command.amount;
|
|
3049
3048
|
} /* not else */
|
|
3050
3049
|
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
3051
3050
|
if (expectAmount[unit].max !== undefined) {
|
|
3052
|
-
throw new
|
|
3051
|
+
throw new SyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3053
3052
|
}
|
|
3054
3053
|
expectAmount[unit].max = command.amount;
|
|
3055
3054
|
}
|
|
3056
3055
|
break;
|
|
3057
3056
|
case 'EXPECT_FORMAT':
|
|
3058
3057
|
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
3059
|
-
throw new
|
|
3058
|
+
throw new SyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
3060
3059
|
}
|
|
3061
3060
|
expectFormat = command.format;
|
|
3062
3061
|
break;
|
|
3063
3062
|
default:
|
|
3064
|
-
throw new
|
|
3063
|
+
throw new SyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
3065
3064
|
}
|
|
3066
3065
|
}
|
|
3067
3066
|
}
|
|
@@ -3075,16 +3074,16 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3075
3074
|
var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
|
|
3076
3075
|
if (executionType === 'SCRIPT') {
|
|
3077
3076
|
if (!language) {
|
|
3078
|
-
throw new
|
|
3077
|
+
throw new SyntaxError('You must specify the language of the script in the prompt template');
|
|
3079
3078
|
}
|
|
3080
3079
|
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
3081
|
-
throw new
|
|
3080
|
+
throw new SyntaxError(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 "); }));
|
|
3082
3081
|
}
|
|
3083
3082
|
}
|
|
3084
3083
|
var lastLine = section.content.split('\n').pop();
|
|
3085
3084
|
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
3086
3085
|
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
3087
|
-
throw new
|
|
3086
|
+
throw new SyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
3088
3087
|
// TODO: Show code of invalid sections each time + DRY
|
|
3089
3088
|
section.content
|
|
3090
3089
|
.split('\n')
|
|
@@ -3134,7 +3133,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3134
3133
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3135
3134
|
delete template.modelRequirements;
|
|
3136
3135
|
}
|
|
3137
|
-
|
|
3136
|
+
pipelineJson.promptTemplates.push(template);
|
|
3138
3137
|
};
|
|
3139
3138
|
try {
|
|
3140
3139
|
for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
@@ -3150,7 +3149,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3150
3149
|
finally { if (e_2) throw e_2.error; }
|
|
3151
3150
|
}
|
|
3152
3151
|
// =============================================================
|
|
3153
|
-
return
|
|
3152
|
+
return pipelineJson;
|
|
3154
3153
|
}
|
|
3155
3154
|
/**
|
|
3156
3155
|
* TODO: Report here line/column of error
|
|
@@ -3162,21 +3161,21 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3162
3161
|
* Compile promptbook from string (markdown) format to JSON format
|
|
3163
3162
|
*
|
|
3164
3163
|
* Note: There are two similar functions:
|
|
3165
|
-
* - `
|
|
3166
|
-
* - `
|
|
3164
|
+
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
3165
|
+
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
3167
3166
|
*
|
|
3168
|
-
* @param
|
|
3167
|
+
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
3169
3168
|
* @param options - Options and tools for the compilation
|
|
3170
3169
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
3171
|
-
* @throws {
|
|
3170
|
+
* @throws {SyntaxError} if the promptbook string is not valid
|
|
3172
3171
|
*
|
|
3173
3172
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
3174
3173
|
* Note: This function acts as compilation process
|
|
3175
3174
|
*/
|
|
3176
|
-
function
|
|
3175
|
+
function pipelineStringToJson(pipelineString, options) {
|
|
3177
3176
|
if (options === void 0) { options = {}; }
|
|
3178
3177
|
return __awaiter(this, void 0, void 0, function () {
|
|
3179
|
-
var llmTools, knowledge,
|
|
3178
|
+
var llmTools, knowledge, pipelineJson;
|
|
3180
3179
|
return __generator(this, function (_a) {
|
|
3181
3180
|
switch (_a.label) {
|
|
3182
3181
|
case 0:
|
|
@@ -3191,8 +3190,8 @@ function promptbookStringToJson(promptbookString, options) {
|
|
|
3191
3190
|
console.info('!!!! knowledge', knowledge);
|
|
3192
3191
|
_a.label = 2;
|
|
3193
3192
|
case 2:
|
|
3194
|
-
|
|
3195
|
-
return [2 /*return*/,
|
|
3193
|
+
pipelineJson = pipelineStringToJsonSync(pipelineString);
|
|
3194
|
+
return [2 /*return*/, pipelineJson];
|
|
3196
3195
|
}
|
|
3197
3196
|
});
|
|
3198
3197
|
});
|
|
@@ -3204,15 +3203,15 @@ function promptbookStringToJson(promptbookString, options) {
|
|
|
3204
3203
|
/**
|
|
3205
3204
|
* This error indicates that the promptbook library cannot be propperly loaded
|
|
3206
3205
|
*/
|
|
3207
|
-
var
|
|
3208
|
-
__extends(
|
|
3209
|
-
function
|
|
3206
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
3207
|
+
__extends(CollectionError, _super);
|
|
3208
|
+
function CollectionError(message) {
|
|
3210
3209
|
var _this = _super.call(this, message) || this;
|
|
3211
|
-
_this.name = '
|
|
3212
|
-
Object.setPrototypeOf(_this,
|
|
3210
|
+
_this.name = 'CollectionError';
|
|
3211
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
3213
3212
|
return _this;
|
|
3214
3213
|
}
|
|
3215
|
-
return
|
|
3214
|
+
return CollectionError;
|
|
3216
3215
|
}(Error));
|
|
3217
3216
|
|
|
3218
3217
|
/**
|
|
@@ -3231,23 +3230,23 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
|
|
|
3231
3230
|
/**
|
|
3232
3231
|
* Constructs Promptbook from async sources
|
|
3233
3232
|
* It can be one of the following:
|
|
3234
|
-
* - Promise of array of
|
|
3235
|
-
* - Factory function that returns Promise of array of
|
|
3233
|
+
* - Promise of array of PipelineJson or PipelineString
|
|
3234
|
+
* - Factory function that returns Promise of array of PipelineJson or PipelineString
|
|
3236
3235
|
*
|
|
3237
3236
|
* Note: This is useful as internal tool for other constructor functions like
|
|
3238
|
-
* `
|
|
3237
|
+
* `createCollectionFromUrl` or `createCollectionFromDirectory`
|
|
3239
3238
|
* Consider using those functions instead of this one
|
|
3240
3239
|
*
|
|
3241
3240
|
* Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
|
|
3242
|
-
* when error occurs in given promise or factory function, it is thrown during `
|
|
3241
|
+
* when error occurs in given promise or factory function, it is thrown during `listPipelines` or `getPipelineByUrl` call
|
|
3243
3242
|
*
|
|
3244
|
-
* Note: Consider using `
|
|
3243
|
+
* Note: Consider using `createCollectionFromDirectory` or `createCollectionFromUrl`
|
|
3245
3244
|
*
|
|
3246
3245
|
* @param promptbookSourcesPromiseOrFactory
|
|
3247
|
-
* @returns
|
|
3246
|
+
* @returns PipelineCollection
|
|
3248
3247
|
* @deprecated Do not use, it will became internal tool for other constructor functions
|
|
3249
3248
|
*/
|
|
3250
|
-
function
|
|
3249
|
+
function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
3251
3250
|
var library;
|
|
3252
3251
|
function forSources() {
|
|
3253
3252
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3262,32 +3261,32 @@ function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3262
3261
|
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
3263
3262
|
case 1:
|
|
3264
3263
|
promptbookSources = _a.sent();
|
|
3265
|
-
library =
|
|
3264
|
+
library = createCollectionFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false));
|
|
3266
3265
|
return [2 /*return*/];
|
|
3267
3266
|
}
|
|
3268
3267
|
});
|
|
3269
3268
|
});
|
|
3270
3269
|
}
|
|
3271
|
-
function
|
|
3270
|
+
function listPipelines() {
|
|
3272
3271
|
return __awaiter(this, void 0, void 0, function () {
|
|
3273
3272
|
return __generator(this, function (_a) {
|
|
3274
3273
|
switch (_a.label) {
|
|
3275
3274
|
case 0: return [4 /*yield*/, forSources()];
|
|
3276
3275
|
case 1:
|
|
3277
3276
|
_a.sent();
|
|
3278
|
-
return [2 /*return*/, /* not await */ library.
|
|
3277
|
+
return [2 /*return*/, /* not await */ library.listPipelines()];
|
|
3279
3278
|
}
|
|
3280
3279
|
});
|
|
3281
3280
|
});
|
|
3282
3281
|
}
|
|
3283
|
-
function
|
|
3282
|
+
function getPipelineByUrl(url) {
|
|
3284
3283
|
return __awaiter(this, void 0, void 0, function () {
|
|
3285
3284
|
return __generator(this, function (_a) {
|
|
3286
3285
|
switch (_a.label) {
|
|
3287
3286
|
case 0: return [4 /*yield*/, forSources()];
|
|
3288
3287
|
case 1:
|
|
3289
3288
|
_a.sent();
|
|
3290
|
-
return [2 /*return*/, /* not await */ library.
|
|
3289
|
+
return [2 /*return*/, /* not await */ library.getPipelineByUrl(url)];
|
|
3291
3290
|
}
|
|
3292
3291
|
});
|
|
3293
3292
|
});
|
|
@@ -3305,8 +3304,8 @@ function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3305
3304
|
});
|
|
3306
3305
|
}
|
|
3307
3306
|
return {
|
|
3308
|
-
|
|
3309
|
-
|
|
3307
|
+
listPipelines: listPipelines,
|
|
3308
|
+
getPipelineByUrl: getPipelineByUrl,
|
|
3310
3309
|
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3311
3310
|
};
|
|
3312
3311
|
}
|
|
@@ -3318,9 +3317,9 @@ function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3318
3317
|
*
|
|
3319
3318
|
* @param path - path to the directory with promptbooks
|
|
3320
3319
|
* @param options - Misc options for the library
|
|
3321
|
-
* @returns
|
|
3320
|
+
* @returns PipelineCollection
|
|
3322
3321
|
*/
|
|
3323
|
-
function
|
|
3322
|
+
function createCollectionFromDirectory(path, options) {
|
|
3324
3323
|
return __awaiter(this, void 0, void 0, function () {
|
|
3325
3324
|
var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, library;
|
|
3326
3325
|
var _this = this;
|
|
@@ -3328,7 +3327,7 @@ function createLibraryFromDirectory(path, options) {
|
|
|
3328
3327
|
switch (_f.label) {
|
|
3329
3328
|
case 0:
|
|
3330
3329
|
if (!isRunningInNode()) {
|
|
3331
|
-
throw new Error('Function `
|
|
3330
|
+
throw new Error('Function `createCollectionFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
3332
3331
|
}
|
|
3333
3332
|
makedLibraryFilePath = join(path, "".concat(PROMPTBOOK_MAKED_BASE_FILENAME, ".json"));
|
|
3334
3333
|
return [4 /*yield*/, access(makedLibraryFilePath, constants.R_OK)
|
|
@@ -3344,7 +3343,7 @@ function createLibraryFromDirectory(path, options) {
|
|
|
3344
3343
|
// TODO: !! Implement;
|
|
3345
3344
|
}
|
|
3346
3345
|
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashOnError, isCrashOnError = _e === void 0 ? true : _e;
|
|
3347
|
-
library =
|
|
3346
|
+
library = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3348
3347
|
var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
3349
3348
|
var e_1, _a;
|
|
3350
3349
|
return __generator(this, function (_b) {
|
|
@@ -3358,7 +3357,7 @@ function createLibraryFromDirectory(path, options) {
|
|
|
3358
3357
|
fileNames = _b.sent();
|
|
3359
3358
|
promptbooks = [];
|
|
3360
3359
|
_loop_1 = function (fileName) {
|
|
3361
|
-
var promptbook,
|
|
3360
|
+
var promptbook, pipelineString, _c, _d, error_1, wrappedErrorMessage;
|
|
3362
3361
|
return __generator(this, function (_e) {
|
|
3363
3362
|
switch (_e.label) {
|
|
3364
3363
|
case 0:
|
|
@@ -3367,8 +3366,8 @@ function createLibraryFromDirectory(path, options) {
|
|
|
3367
3366
|
if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 3];
|
|
3368
3367
|
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3369
3368
|
case 1:
|
|
3370
|
-
|
|
3371
|
-
return [4 /*yield*/,
|
|
3369
|
+
pipelineString = (_e.sent());
|
|
3370
|
+
return [4 /*yield*/, pipelineStringToJson(pipelineString)];
|
|
3372
3371
|
case 2:
|
|
3373
3372
|
promptbook = _e.sent();
|
|
3374
3373
|
return [3 /*break*/, 6];
|
|
@@ -3403,9 +3402,9 @@ function createLibraryFromDirectory(path, options) {
|
|
|
3403
3402
|
if (!isCrashOnError) {
|
|
3404
3403
|
// Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
|
|
3405
3404
|
// But be handled in current try-catch block
|
|
3406
|
-
|
|
3405
|
+
validatePipeline(promptbook);
|
|
3407
3406
|
}
|
|
3408
|
-
// Note: [🦄] Promptbook with same url uniqueness will be checked automatically in
|
|
3407
|
+
// Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePipelineCollection
|
|
3409
3408
|
promptbooks.push(promptbook);
|
|
3410
3409
|
}
|
|
3411
3410
|
}
|
|
@@ -3417,7 +3416,7 @@ function createLibraryFromDirectory(path, options) {
|
|
|
3417
3416
|
}
|
|
3418
3417
|
wrappedErrorMessage = spaceTrim$1(function (block) { return "\n Error during loading promptbook from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
3419
3418
|
if (isCrashOnError) {
|
|
3420
|
-
throw new
|
|
3419
|
+
throw new CollectionError(wrappedErrorMessage);
|
|
3421
3420
|
}
|
|
3422
3421
|
console.error(wrappedErrorMessage);
|
|
3423
3422
|
return [3 /*break*/, 8];
|
|
@@ -3456,7 +3455,7 @@ function createLibraryFromDirectory(path, options) {
|
|
|
3456
3455
|
});
|
|
3457
3456
|
}); });
|
|
3458
3457
|
if (!(isLazyLoaded === false)) return [3 /*break*/, 3];
|
|
3459
|
-
return [4 /*yield*/, library.
|
|
3458
|
+
return [4 /*yield*/, library.listPipelines()];
|
|
3460
3459
|
case 2:
|
|
3461
3460
|
_f.sent();
|
|
3462
3461
|
_f.label = 3;
|
|
@@ -3471,7 +3470,7 @@ function createLibraryFromDirectory(path, options) {
|
|
|
3471
3470
|
* @param path
|
|
3472
3471
|
* @param isRecursive
|
|
3473
3472
|
* @returns List of all files in the directory
|
|
3474
|
-
* @private internal function for `
|
|
3473
|
+
* @private internal function for `createCollectionFromDirectory`
|
|
3475
3474
|
*/
|
|
3476
3475
|
function listAllFiles(path, isRecursive) {
|
|
3477
3476
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3528,5 +3527,5 @@ function listAllFiles(path, isRecursive) {
|
|
|
3528
3527
|
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3529
3528
|
*/
|
|
3530
3529
|
|
|
3531
|
-
export { PROMPTBOOK_VERSION,
|
|
3530
|
+
export { PROMPTBOOK_VERSION, createCollectionFromDirectory };
|
|
3532
3531
|
//# sourceMappingURL=index.es.js.map
|