@promptbook/core 0.60.0-0 → 0.60.0-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/esm/index.es.js +630 -631
- 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} +5 -5
- 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 +4 -4
- 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 +4 -4
- 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 +2 -2
- package/umd/index.umd.js +624 -625
- 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} +5 -5
- 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 +4 -4
- 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 +4 -4
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import spaceTrim
|
|
1
|
+
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
2
2
|
import { format } from 'prettier';
|
|
3
3
|
import parserHtml from 'prettier/parser-html';
|
|
4
4
|
import moment from 'moment';
|
|
@@ -122,37 +122,6 @@ function __spreadArray(to, from, pack) {
|
|
|
122
122
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
/**
|
|
126
|
-
* Removes HTML or Markdown comments from a string.
|
|
127
|
-
*
|
|
128
|
-
* @param {string} content - The string to remove comments from.
|
|
129
|
-
* @returns {string} The input string with all comments removed.
|
|
130
|
-
*/
|
|
131
|
-
function removeContentComments(content) {
|
|
132
|
-
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Add or modify an auto-generated section in a markdown file
|
|
137
|
-
*
|
|
138
|
-
* @private within the library
|
|
139
|
-
*/
|
|
140
|
-
function addAutoGeneratedSection(content, options) {
|
|
141
|
-
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
142
|
-
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
143
|
-
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
144
|
-
var sectionMatch = content.match(sectionRegex);
|
|
145
|
-
if (sectionMatch) {
|
|
146
|
-
return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
147
|
-
}
|
|
148
|
-
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
149
|
-
if (!placeForSection) {
|
|
150
|
-
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
151
|
-
}
|
|
152
|
-
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
153
|
-
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
125
|
/**
|
|
157
126
|
* Prettify the html code
|
|
158
127
|
*
|
|
@@ -185,27 +154,234 @@ function prettifyMarkdown(content) {
|
|
|
185
154
|
}
|
|
186
155
|
}
|
|
187
156
|
|
|
188
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Makes first letter of a string uppercase
|
|
159
|
+
*
|
|
160
|
+
*/
|
|
161
|
+
function capitalize(word) {
|
|
162
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Converts promptbook in JSON format to string format
|
|
167
|
+
*
|
|
168
|
+
* @param pipelineJson Promptbook in JSON format (.ptbk.json)
|
|
169
|
+
* @returns Promptbook in string format (.ptbk.md)
|
|
170
|
+
*/
|
|
171
|
+
function pipelineJsonToString(pipelineJson) {
|
|
172
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
173
|
+
var title = pipelineJson.title, promptbookUrl = pipelineJson.promptbookUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, promptTemplates = pipelineJson.promptTemplates;
|
|
174
|
+
var pipelineString = "# ".concat(title);
|
|
175
|
+
if (description) {
|
|
176
|
+
pipelineString += '\n\n';
|
|
177
|
+
pipelineString += description;
|
|
178
|
+
}
|
|
179
|
+
// TODO:> const commands: Array<Command>
|
|
180
|
+
var commands = [];
|
|
181
|
+
if (promptbookUrl) {
|
|
182
|
+
commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
|
|
183
|
+
}
|
|
184
|
+
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
185
|
+
pipelineString = prettifyMarkdown(pipelineString);
|
|
186
|
+
try {
|
|
187
|
+
for (var _g = __values(parameters.filter(function (_a) {
|
|
188
|
+
var isInput = _a.isInput;
|
|
189
|
+
return isInput;
|
|
190
|
+
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
191
|
+
var parameter = _h.value;
|
|
192
|
+
commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
196
|
+
finally {
|
|
197
|
+
try {
|
|
198
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
199
|
+
}
|
|
200
|
+
finally { if (e_1) throw e_1.error; }
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
for (var _j = __values(parameters.filter(function (_a) {
|
|
204
|
+
var isOutput = _a.isOutput;
|
|
205
|
+
return isOutput;
|
|
206
|
+
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
207
|
+
var parameter = _k.value;
|
|
208
|
+
commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
212
|
+
finally {
|
|
213
|
+
try {
|
|
214
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
215
|
+
}
|
|
216
|
+
finally { if (e_2) throw e_2.error; }
|
|
217
|
+
}
|
|
218
|
+
pipelineString += '\n\n';
|
|
219
|
+
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
220
|
+
try {
|
|
221
|
+
for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
|
|
222
|
+
var promptTemplate = promptTemplates_1_1.value;
|
|
223
|
+
var
|
|
224
|
+
/* Note: Not using:> name, */
|
|
225
|
+
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
226
|
+
/* Note: dependentParameterNames, */
|
|
227
|
+
jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
228
|
+
pipelineString += '\n\n';
|
|
229
|
+
pipelineString += "## ".concat(title_1);
|
|
230
|
+
if (description_1) {
|
|
231
|
+
pipelineString += '\n\n';
|
|
232
|
+
pipelineString += description_1;
|
|
233
|
+
}
|
|
234
|
+
// TODO:> const commands: Array<Command>
|
|
235
|
+
var commands_1 = [];
|
|
236
|
+
var contentLanguage = 'text';
|
|
237
|
+
if (executionType === 'PROMPT_TEMPLATE') {
|
|
238
|
+
var modelRequirements = promptTemplate.modelRequirements;
|
|
239
|
+
var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
|
|
240
|
+
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
241
|
+
if (modelVariant) {
|
|
242
|
+
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
243
|
+
}
|
|
244
|
+
if (modelName) {
|
|
245
|
+
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
else if (executionType === 'SIMPLE_TEMPLATE') {
|
|
249
|
+
commands_1.push("SIMPLE TEMPLATE");
|
|
250
|
+
// Note: Nothing special here
|
|
251
|
+
}
|
|
252
|
+
else if (executionType === 'SCRIPT') {
|
|
253
|
+
commands_1.push("EXECUTE SCRIPT");
|
|
254
|
+
if (promptTemplate.contentLanguage) {
|
|
255
|
+
contentLanguage = promptTemplate.contentLanguage;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
contentLanguage = '';
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else if (executionType === 'PROMPT_DIALOG') {
|
|
262
|
+
commands_1.push("PROMPT DIALOG");
|
|
263
|
+
// Note: Nothing special here
|
|
264
|
+
}
|
|
265
|
+
if (jokers) {
|
|
266
|
+
try {
|
|
267
|
+
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
268
|
+
var joker = jokers_1_1.value;
|
|
269
|
+
commands_1.push("JOKER {".concat(joker, "}"));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
273
|
+
finally {
|
|
274
|
+
try {
|
|
275
|
+
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
276
|
+
}
|
|
277
|
+
finally { if (e_4) throw e_4.error; }
|
|
278
|
+
}
|
|
279
|
+
} /* not else */
|
|
280
|
+
if (postprocessing) {
|
|
281
|
+
try {
|
|
282
|
+
for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
|
|
283
|
+
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
284
|
+
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
288
|
+
finally {
|
|
289
|
+
try {
|
|
290
|
+
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
291
|
+
}
|
|
292
|
+
finally { if (e_5) throw e_5.error; }
|
|
293
|
+
}
|
|
294
|
+
} /* not else */
|
|
295
|
+
if (expectations) {
|
|
296
|
+
try {
|
|
297
|
+
for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
298
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
299
|
+
if (min === max) {
|
|
300
|
+
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
if (min !== undefined) {
|
|
304
|
+
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
305
|
+
} /* not else */
|
|
306
|
+
if (max !== undefined) {
|
|
307
|
+
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
313
|
+
finally {
|
|
314
|
+
try {
|
|
315
|
+
if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
|
|
316
|
+
}
|
|
317
|
+
finally { if (e_6) throw e_6.error; }
|
|
318
|
+
}
|
|
319
|
+
} /* not else */
|
|
320
|
+
if (expectFormat) {
|
|
321
|
+
if (expectFormat === 'JSON') {
|
|
322
|
+
// TODO: @deprecated remove
|
|
323
|
+
commands_1.push("EXPECT JSON");
|
|
324
|
+
}
|
|
325
|
+
} /* not else */
|
|
326
|
+
pipelineString += '\n\n';
|
|
327
|
+
pipelineString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
328
|
+
pipelineString += '\n\n';
|
|
329
|
+
pipelineString += '```' + contentLanguage;
|
|
330
|
+
pipelineString += '\n';
|
|
331
|
+
pipelineString += spaceTrim(content);
|
|
332
|
+
// <- TODO: !!! Escape
|
|
333
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
334
|
+
pipelineString += '\n';
|
|
335
|
+
pipelineString += '```';
|
|
336
|
+
pipelineString += '\n\n';
|
|
337
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
341
|
+
finally {
|
|
342
|
+
try {
|
|
343
|
+
if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
|
|
344
|
+
}
|
|
345
|
+
finally { if (e_3) throw e_3.error; }
|
|
346
|
+
}
|
|
347
|
+
return pipelineString;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* @private internal util of pipelineJsonToString
|
|
351
|
+
*/
|
|
352
|
+
function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
353
|
+
var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
|
|
354
|
+
var parameterString = "{".concat(name, "}");
|
|
355
|
+
if (description) {
|
|
356
|
+
parameterString = "".concat(parameterString, " ").concat(description);
|
|
357
|
+
}
|
|
358
|
+
return parameterString;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* TODO: Escape all
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
var PipelineCollection = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.60.0-3",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-3",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:[]}];
|
|
189
365
|
|
|
190
366
|
/**
|
|
191
367
|
* This error indicates errors during the execution of the promptbook
|
|
192
368
|
*/
|
|
193
|
-
var
|
|
194
|
-
__extends(
|
|
195
|
-
function
|
|
369
|
+
var ExecutionError = /** @class */ (function (_super) {
|
|
370
|
+
__extends(ExecutionError, _super);
|
|
371
|
+
function ExecutionError(message) {
|
|
196
372
|
var _this = _super.call(this, message) || this;
|
|
197
|
-
_this.name = '
|
|
198
|
-
Object.setPrototypeOf(_this,
|
|
373
|
+
_this.name = 'ExecutionError';
|
|
374
|
+
Object.setPrototypeOf(_this, ExecutionError.prototype);
|
|
199
375
|
return _this;
|
|
200
376
|
}
|
|
201
|
-
return
|
|
377
|
+
return ExecutionError;
|
|
202
378
|
}(Error));
|
|
203
379
|
|
|
204
380
|
/**
|
|
205
381
|
* Asserts that the execution of a promptnook is successful
|
|
206
382
|
*
|
|
207
383
|
* @param executionResult - The partial result of the promptnook execution
|
|
208
|
-
* @throws {
|
|
384
|
+
* @throws {ExecutionError} If the execution is not successful or if multiple errors occurred
|
|
209
385
|
*/
|
|
210
386
|
function assertsExecutionSuccessful(executionResult) {
|
|
211
387
|
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
@@ -213,13 +389,13 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
213
389
|
return;
|
|
214
390
|
}
|
|
215
391
|
if (errors.length === 0) {
|
|
216
|
-
throw new
|
|
392
|
+
throw new ExecutionError("Promptnook Execution failed because of unknown reason");
|
|
217
393
|
}
|
|
218
394
|
else if (errors.length === 1) {
|
|
219
395
|
throw errors[0];
|
|
220
396
|
}
|
|
221
397
|
else {
|
|
222
|
-
throw new
|
|
398
|
+
throw new ExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
|
|
223
399
|
}
|
|
224
400
|
}
|
|
225
401
|
/**
|
|
@@ -234,29 +410,29 @@ var LOOP_LIMIT = 1000;
|
|
|
234
410
|
/**
|
|
235
411
|
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
236
412
|
*/
|
|
237
|
-
var
|
|
238
|
-
__extends(
|
|
239
|
-
function
|
|
413
|
+
var PipelineLogicError = /** @class */ (function (_super) {
|
|
414
|
+
__extends(PipelineLogicError, _super);
|
|
415
|
+
function PipelineLogicError(message) {
|
|
240
416
|
var _this = _super.call(this, message) || this;
|
|
241
|
-
_this.name = '
|
|
242
|
-
Object.setPrototypeOf(_this,
|
|
417
|
+
_this.name = 'PipelineLogicError';
|
|
418
|
+
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
243
419
|
return _this;
|
|
244
420
|
}
|
|
245
|
-
return
|
|
421
|
+
return PipelineLogicError;
|
|
246
422
|
}(Error));
|
|
247
423
|
|
|
248
424
|
/**
|
|
249
425
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
250
426
|
*/
|
|
251
|
-
var
|
|
252
|
-
__extends(
|
|
253
|
-
function
|
|
427
|
+
var SyntaxError = /** @class */ (function (_super) {
|
|
428
|
+
__extends(SyntaxError, _super);
|
|
429
|
+
function SyntaxError(message) {
|
|
254
430
|
var _this = _super.call(this, message) || this;
|
|
255
|
-
_this.name = '
|
|
256
|
-
Object.setPrototypeOf(_this,
|
|
431
|
+
_this.name = 'SyntaxError';
|
|
432
|
+
Object.setPrototypeOf(_this, SyntaxError.prototype);
|
|
257
433
|
return _this;
|
|
258
434
|
}
|
|
259
|
-
return
|
|
435
|
+
return SyntaxError;
|
|
260
436
|
}(Error));
|
|
261
437
|
|
|
262
438
|
/**
|
|
@@ -265,7 +441,7 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
265
441
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
266
442
|
__extends(UnexpectedError, _super);
|
|
267
443
|
function UnexpectedError(message) {
|
|
268
|
-
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
444
|
+
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
269
445
|
_this.name = 'UnexpectedError';
|
|
270
446
|
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
271
447
|
return _this;
|
|
@@ -299,7 +475,7 @@ function isValidUrl(url) {
|
|
|
299
475
|
}
|
|
300
476
|
|
|
301
477
|
/**
|
|
302
|
-
* Validates
|
|
478
|
+
* Validates PipelineJson if it is logically valid
|
|
303
479
|
*
|
|
304
480
|
* It checks:
|
|
305
481
|
* - if it has correct parameters dependency
|
|
@@ -308,48 +484,48 @@ function isValidUrl(url) {
|
|
|
308
484
|
* - if it is valid json
|
|
309
485
|
* - if it is meaningful
|
|
310
486
|
*
|
|
311
|
-
* @param
|
|
312
|
-
* @returns the same
|
|
313
|
-
* @throws {
|
|
487
|
+
* @param pipeline valid or invalid PipelineJson
|
|
488
|
+
* @returns the same pipeline if it is logically valid
|
|
489
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
314
490
|
*/
|
|
315
|
-
function
|
|
491
|
+
function validatePipeline(pipeline) {
|
|
316
492
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
317
493
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
318
|
-
if (
|
|
319
|
-
if (!isValidUrl(
|
|
494
|
+
if (pipeline.promptbookUrl !== undefined) {
|
|
495
|
+
if (!isValidUrl(pipeline.promptbookUrl)) {
|
|
320
496
|
// TODO: This should be maybe the syntax error detected during parsing
|
|
321
|
-
throw new
|
|
497
|
+
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.promptbookUrl, "\""));
|
|
322
498
|
}
|
|
323
499
|
}
|
|
324
500
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
325
|
-
if (!Array.isArray(
|
|
501
|
+
if (!Array.isArray(pipeline.parameters)) {
|
|
326
502
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
327
|
-
throw new
|
|
503
|
+
throw new SyntaxError(spaceTrim$1("\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 ")));
|
|
328
504
|
}
|
|
329
505
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
330
|
-
if (!Array.isArray(
|
|
506
|
+
if (!Array.isArray(pipeline.promptTemplates)) {
|
|
331
507
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
332
|
-
throw new
|
|
508
|
+
throw new SyntaxError(spaceTrim$1("\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 ")));
|
|
333
509
|
}
|
|
334
510
|
var _loop_1 = function (parameter) {
|
|
335
511
|
if (parameter.isInput && parameter.isOutput) {
|
|
336
|
-
throw new
|
|
512
|
+
throw new PipelineLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
|
|
337
513
|
}
|
|
338
514
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
339
515
|
if (!parameter.isInput &&
|
|
340
516
|
!parameter.isOutput &&
|
|
341
|
-
!
|
|
342
|
-
throw new
|
|
517
|
+
!pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
518
|
+
throw new PipelineLogicError(spaceTrim$1("\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 ")));
|
|
343
519
|
}
|
|
344
520
|
// Note: Testing that parameter is either input or result of some template
|
|
345
521
|
if (!parameter.isInput &&
|
|
346
|
-
!
|
|
347
|
-
throw new
|
|
522
|
+
!pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
523
|
+
throw new PipelineLogicError(spaceTrim$1("\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 ")));
|
|
348
524
|
}
|
|
349
525
|
};
|
|
350
526
|
try {
|
|
351
527
|
// Note: Check each parameter individually
|
|
352
|
-
for (var _e = __values(
|
|
528
|
+
for (var _e = __values(pipeline.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
353
529
|
var parameter = _f.value;
|
|
354
530
|
_loop_1(parameter);
|
|
355
531
|
}
|
|
@@ -362,7 +538,7 @@ function validatePromptbook(promptbook) {
|
|
|
362
538
|
finally { if (e_1) throw e_1.error; }
|
|
363
539
|
}
|
|
364
540
|
// Note: Check each template individually
|
|
365
|
-
var definedParameters = new Set(
|
|
541
|
+
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
366
542
|
var isInput = _a.isInput;
|
|
367
543
|
return isInput;
|
|
368
544
|
}).map(function (_a) {
|
|
@@ -370,25 +546,25 @@ function validatePromptbook(promptbook) {
|
|
|
370
546
|
return name;
|
|
371
547
|
}));
|
|
372
548
|
try {
|
|
373
|
-
for (var _g = __values(
|
|
549
|
+
for (var _g = __values(pipeline.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
374
550
|
var template = _h.value;
|
|
375
551
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
376
|
-
throw new
|
|
552
|
+
throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
377
553
|
}
|
|
378
554
|
definedParameters.add(template.resultingParameterName);
|
|
379
555
|
if (template.executionType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
380
|
-
throw new
|
|
556
|
+
throw new PipelineLogicError(spaceTrim$1("\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 ")));
|
|
381
557
|
}
|
|
382
558
|
if (template.jokers && template.jokers.length > 0) {
|
|
383
559
|
if (!template.expectFormat &&
|
|
384
560
|
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
385
|
-
throw new
|
|
561
|
+
throw new PipelineLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
|
|
386
562
|
}
|
|
387
563
|
try {
|
|
388
564
|
for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
389
565
|
var joker = _k.value;
|
|
390
566
|
if (!template.dependentParameterNames.includes(joker)) {
|
|
391
|
-
throw new
|
|
567
|
+
throw new PipelineLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
392
568
|
}
|
|
393
569
|
}
|
|
394
570
|
}
|
|
@@ -405,13 +581,13 @@ function validatePromptbook(promptbook) {
|
|
|
405
581
|
for (var _l = (e_4 = void 0, __values(Object.entries(template.expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
406
582
|
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
407
583
|
if (min !== undefined && max !== undefined && min > max) {
|
|
408
|
-
throw new
|
|
584
|
+
throw new PipelineLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
409
585
|
}
|
|
410
586
|
if (min !== undefined && min < 0) {
|
|
411
|
-
throw new
|
|
587
|
+
throw new PipelineLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
|
|
412
588
|
}
|
|
413
589
|
if (max !== undefined && max <= 0) {
|
|
414
|
-
throw new
|
|
590
|
+
throw new PipelineLogicError("Max expectation of ".concat(unit, " must be positive"));
|
|
415
591
|
}
|
|
416
592
|
}
|
|
417
593
|
}
|
|
@@ -433,7 +609,7 @@ function validatePromptbook(promptbook) {
|
|
|
433
609
|
finally { if (e_2) throw e_2.error; }
|
|
434
610
|
}
|
|
435
611
|
// Note: Detect circular dependencies
|
|
436
|
-
var resovedParameters =
|
|
612
|
+
var resovedParameters = pipeline.parameters
|
|
437
613
|
.filter(function (_a) {
|
|
438
614
|
var isInput = _a.isInput;
|
|
439
615
|
return isInput;
|
|
@@ -442,17 +618,17 @@ function validatePromptbook(promptbook) {
|
|
|
442
618
|
var name = _a.name;
|
|
443
619
|
return name;
|
|
444
620
|
});
|
|
445
|
-
var unresovedTemplates = __spreadArray([], __read(
|
|
621
|
+
var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
446
622
|
var loopLimit = LOOP_LIMIT;
|
|
447
623
|
var _loop_2 = function () {
|
|
448
624
|
if (loopLimit-- < 0) {
|
|
449
|
-
throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `
|
|
625
|
+
throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePipeline`');
|
|
450
626
|
}
|
|
451
627
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
452
628
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
453
629
|
});
|
|
454
630
|
if (currentlyResovedTemplates.length === 0) {
|
|
455
|
-
throw new
|
|
631
|
+
throw new PipelineLogicError(spaceTrim$1(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
|
|
456
632
|
.map(function (_a) {
|
|
457
633
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
458
634
|
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
@@ -470,25 +646,25 @@ function validatePromptbook(promptbook) {
|
|
|
470
646
|
while (unresovedTemplates.length > 0) {
|
|
471
647
|
_loop_2();
|
|
472
648
|
}
|
|
473
|
-
return
|
|
649
|
+
return pipeline;
|
|
474
650
|
}
|
|
475
651
|
/**
|
|
476
652
|
* TODO: [🧠] Work with promptbookVersion
|
|
477
653
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
478
654
|
* > /**
|
|
479
|
-
* > * Validates
|
|
655
|
+
* > * Validates PipelineJson if it is logically valid.
|
|
480
656
|
* > *
|
|
481
657
|
* > * It checks:
|
|
482
658
|
* > * - it has a valid structure
|
|
483
659
|
* > * - ...
|
|
484
|
-
* > ex port function
|
|
660
|
+
* > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
|
|
485
661
|
*/
|
|
486
662
|
|
|
487
663
|
/**
|
|
488
664
|
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
489
665
|
*
|
|
490
|
-
* @private Always catched and rethrown as `
|
|
491
|
-
* Note: This is a kindof subtype of
|
|
666
|
+
* @private Always catched and rethrown as `ExecutionError`
|
|
667
|
+
* Note: This is a kindof subtype of ExecutionError
|
|
492
668
|
*/
|
|
493
669
|
var ExpectError = /** @class */ (function (_super) {
|
|
494
670
|
__extends(ExpectError, _super);
|
|
@@ -523,7 +699,7 @@ function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
|
523
699
|
/**
|
|
524
700
|
* The version of the Promptbook library
|
|
525
701
|
*/
|
|
526
|
-
var PROMPTBOOK_VERSION = '0.
|
|
702
|
+
var PROMPTBOOK_VERSION = '0.60.0-3';
|
|
527
703
|
|
|
528
704
|
/**
|
|
529
705
|
* Function `addUsage` will add multiple usages into one
|
|
@@ -1002,7 +1178,7 @@ function isPassingExpectations(expectations, value) {
|
|
|
1002
1178
|
/**
|
|
1003
1179
|
* This error occurs during the parameter replacement in the template
|
|
1004
1180
|
*
|
|
1005
|
-
* Note: This is a kindof subtype of
|
|
1181
|
+
* Note: This is a kindof subtype of ExecutionError because it occurs during the execution of the pipeline
|
|
1006
1182
|
*/
|
|
1007
1183
|
var TemplateError = /** @class */ (function (_super) {
|
|
1008
1184
|
__extends(TemplateError, _super);
|
|
@@ -1079,13 +1255,13 @@ function replaceParameters(template, parameters) {
|
|
|
1079
1255
|
* Creates executor function from promptbook and execution tools.
|
|
1080
1256
|
*
|
|
1081
1257
|
* @returns The executor function
|
|
1082
|
-
* @throws {
|
|
1258
|
+
* @throws {PipelineLogicError} on logical error in the promptbook
|
|
1083
1259
|
*/
|
|
1084
1260
|
function createPromptbookExecutor(options) {
|
|
1085
1261
|
var _this = this;
|
|
1086
1262
|
var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1087
1263
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1088
|
-
|
|
1264
|
+
validatePipeline(promptbook);
|
|
1089
1265
|
var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1090
1266
|
function executeSingleTemplate(currentTemplate) {
|
|
1091
1267
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1132,7 +1308,7 @@ function createPromptbookExecutor(options) {
|
|
|
1132
1308
|
expectError = null;
|
|
1133
1309
|
if (isJokerAttempt) {
|
|
1134
1310
|
if (typeof parametersToPass[joker] === 'undefined') {
|
|
1135
|
-
throw new
|
|
1311
|
+
throw new ExecutionError("Joker parameter {".concat(joker, "} not defined"));
|
|
1136
1312
|
}
|
|
1137
1313
|
resultString = parametersToPass[joker];
|
|
1138
1314
|
}
|
|
@@ -1212,13 +1388,13 @@ function createPromptbookExecutor(options) {
|
|
|
1212
1388
|
return [7 /*endfinally*/];
|
|
1213
1389
|
case 10:
|
|
1214
1390
|
if (errors.length === 0) {
|
|
1215
|
-
throw new
|
|
1391
|
+
throw new ExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
|
|
1216
1392
|
}
|
|
1217
1393
|
else if (errors.length === 1) {
|
|
1218
1394
|
throw errors[0];
|
|
1219
1395
|
}
|
|
1220
1396
|
else {
|
|
1221
|
-
throw new
|
|
1397
|
+
throw new ExecutionError(spaceTrim$1(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 "); }));
|
|
1222
1398
|
}
|
|
1223
1399
|
}
|
|
1224
1400
|
});
|
|
@@ -1230,27 +1406,27 @@ function createPromptbookExecutor(options) {
|
|
|
1230
1406
|
case 'COMPLETION': return [3 /*break*/, 9];
|
|
1231
1407
|
}
|
|
1232
1408
|
return [3 /*break*/, 11];
|
|
1233
|
-
case 7: return [4 /*yield*/, tools.llm.
|
|
1409
|
+
case 7: return [4 /*yield*/, tools.llm.callChatModel(prompt)];
|
|
1234
1410
|
case 8:
|
|
1235
1411
|
chatThread = _o.sent();
|
|
1236
1412
|
// TODO: [🍬] Destroy chatThread
|
|
1237
1413
|
result = chatThread;
|
|
1238
1414
|
resultString = chatThread.content;
|
|
1239
1415
|
return [3 /*break*/, 12];
|
|
1240
|
-
case 9: return [4 /*yield*/, tools.llm.
|
|
1416
|
+
case 9: return [4 /*yield*/, tools.llm.callCompletionModel(prompt)];
|
|
1241
1417
|
case 10:
|
|
1242
1418
|
completionResult = _o.sent();
|
|
1243
1419
|
result = completionResult;
|
|
1244
1420
|
resultString = completionResult.content;
|
|
1245
1421
|
return [3 /*break*/, 12];
|
|
1246
|
-
case 11: throw new
|
|
1422
|
+
case 11: throw new ExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
1247
1423
|
case 12: return [3 /*break*/, 27];
|
|
1248
1424
|
case 13:
|
|
1249
1425
|
if (tools.script.length === 0) {
|
|
1250
|
-
throw new
|
|
1426
|
+
throw new ExecutionError('No script execution tools are available');
|
|
1251
1427
|
}
|
|
1252
1428
|
if (!currentTemplate.contentLanguage) {
|
|
1253
|
-
throw new
|
|
1429
|
+
throw new ExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
1254
1430
|
}
|
|
1255
1431
|
// TODO: DRY [1]
|
|
1256
1432
|
scriptExecutionErrors = [];
|
|
@@ -1302,13 +1478,13 @@ function createPromptbookExecutor(options) {
|
|
|
1302
1478
|
throw scriptExecutionErrors[0];
|
|
1303
1479
|
}
|
|
1304
1480
|
else {
|
|
1305
|
-
throw new
|
|
1481
|
+
throw new ExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
|
|
1306
1482
|
.map(function (error) { return '- ' + error.message; })
|
|
1307
1483
|
.join('\n\n')), "\n "); }));
|
|
1308
1484
|
}
|
|
1309
1485
|
case 24:
|
|
1310
1486
|
if (tools.userInterface === undefined) {
|
|
1311
|
-
throw new
|
|
1487
|
+
throw new ExecutionError('User interface tools are not available');
|
|
1312
1488
|
}
|
|
1313
1489
|
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
1314
1490
|
promptTitle: currentTemplate.title,
|
|
@@ -1322,7 +1498,7 @@ function createPromptbookExecutor(options) {
|
|
|
1322
1498
|
// TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
1323
1499
|
resultString = _o.sent();
|
|
1324
1500
|
return [3 /*break*/, 27];
|
|
1325
|
-
case 26: throw new
|
|
1501
|
+
case 26: throw new ExecutionError(
|
|
1326
1502
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1327
1503
|
"Unknown execution type \"".concat(currentTemplate.executionType, "\""));
|
|
1328
1504
|
case 27:
|
|
@@ -1447,7 +1623,7 @@ function createPromptbookExecutor(options) {
|
|
|
1447
1623
|
return [7 /*endfinally*/];
|
|
1448
1624
|
case 47:
|
|
1449
1625
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
1450
|
-
throw new
|
|
1626
|
+
throw new ExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
1451
1627
|
}
|
|
1452
1628
|
_o.label = 48;
|
|
1453
1629
|
case 48:
|
|
@@ -1516,349 +1692,142 @@ function createPromptbookExecutor(options) {
|
|
|
1516
1692
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
1517
1693
|
});
|
|
1518
1694
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
1519
|
-
throw new UnexpectedError(spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during
|
|
1695
|
+
throw new UnexpectedError(spaceTrim$1("\n Can not resolve some parameters\n\n Note: This should be catched during validatePipeline\n "));
|
|
1520
1696
|
case 1:
|
|
1521
1697
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
1522
|
-
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
1523
|
-
case 2:
|
|
1524
|
-
/* [5] */ _e.sent();
|
|
1525
|
-
return [3 /*break*/, 4];
|
|
1526
|
-
case 3:
|
|
1527
|
-
unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
|
|
1528
|
-
work_1 = executeSingleTemplate(currentTemplate)
|
|
1529
|
-
.then(function () {
|
|
1530
|
-
resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
|
|
1531
|
-
})
|
|
1532
|
-
.then(function () {
|
|
1533
|
-
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
1534
|
-
});
|
|
1535
|
-
resolving_1.push(work_1);
|
|
1536
|
-
_e.label = 4;
|
|
1537
|
-
case 4: return [2 /*return*/];
|
|
1538
|
-
}
|
|
1539
|
-
});
|
|
1540
|
-
};
|
|
1541
|
-
_d.label = 2;
|
|
1542
|
-
case 2:
|
|
1543
|
-
if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
|
|
1544
|
-
return [5 /*yield**/, _loop_1()];
|
|
1545
|
-
case 3:
|
|
1546
|
-
_d.sent();
|
|
1547
|
-
return [3 /*break*/, 2];
|
|
1548
|
-
case 4: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
1549
|
-
case 5:
|
|
1550
|
-
_d.sent();
|
|
1551
|
-
return [3 /*break*/, 7];
|
|
1552
|
-
case 6:
|
|
1553
|
-
error_1 = _d.sent();
|
|
1554
|
-
if (!(error_1 instanceof Error)) {
|
|
1555
|
-
throw error_1;
|
|
1556
|
-
}
|
|
1557
|
-
usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1558
|
-
var result = _a.result;
|
|
1559
|
-
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1560
|
-
})), false));
|
|
1561
|
-
return [2 /*return*/, {
|
|
1562
|
-
isSuccessful: false,
|
|
1563
|
-
errors: [error_1],
|
|
1564
|
-
usage: usage_1,
|
|
1565
|
-
executionReport: executionReport,
|
|
1566
|
-
outputParameters: parametersToPass,
|
|
1567
|
-
}];
|
|
1568
|
-
case 7:
|
|
1569
|
-
try {
|
|
1570
|
-
// Note: Filter ONLY output parameters
|
|
1571
|
-
for (_a = __values(promptbook.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1572
|
-
parameter = _b.value;
|
|
1573
|
-
if (parameter.isOutput) {
|
|
1574
|
-
continue;
|
|
1575
|
-
}
|
|
1576
|
-
delete parametersToPass[parameter.name];
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1580
|
-
finally {
|
|
1581
|
-
try {
|
|
1582
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1583
|
-
}
|
|
1584
|
-
finally { if (e_1) throw e_1.error; }
|
|
1585
|
-
}
|
|
1586
|
-
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1587
|
-
var result = _a.result;
|
|
1588
|
-
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1589
|
-
})), false));
|
|
1590
|
-
return [2 /*return*/, {
|
|
1591
|
-
isSuccessful: true,
|
|
1592
|
-
errors: [],
|
|
1593
|
-
usage: usage,
|
|
1594
|
-
executionReport: executionReport,
|
|
1595
|
-
outputParameters: parametersToPass,
|
|
1596
|
-
}];
|
|
1597
|
-
}
|
|
1598
|
-
});
|
|
1599
|
-
}); };
|
|
1600
|
-
return promptbookExecutor;
|
|
1601
|
-
}
|
|
1602
|
-
/**
|
|
1603
|
-
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
1604
|
-
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
1605
|
-
* Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
|
|
1606
|
-
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
1607
|
-
*/
|
|
1608
|
-
|
|
1609
|
-
/**
|
|
1610
|
-
* Makes first letter of a string uppercase
|
|
1611
|
-
*
|
|
1612
|
-
*/
|
|
1613
|
-
function capitalize(word) {
|
|
1614
|
-
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
/**
|
|
1618
|
-
* Converts promptbook in JSON format to string format
|
|
1619
|
-
*
|
|
1620
|
-
* @param promptbookJson Promptbook in JSON format (.ptbk.json)
|
|
1621
|
-
* @returns Promptbook in string format (.ptbk.md)
|
|
1622
|
-
*/
|
|
1623
|
-
function promptbookJsonToString(promptbookJson) {
|
|
1624
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
1625
|
-
var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
|
|
1626
|
-
var promptbookString = "# ".concat(title);
|
|
1627
|
-
if (description) {
|
|
1628
|
-
promptbookString += '\n\n';
|
|
1629
|
-
promptbookString += description;
|
|
1630
|
-
}
|
|
1631
|
-
// TODO:> const commands: Array<Command>
|
|
1632
|
-
var commands = [];
|
|
1633
|
-
if (promptbookUrl) {
|
|
1634
|
-
commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
|
|
1635
|
-
}
|
|
1636
|
-
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
1637
|
-
promptbookString = prettifyMarkdown(promptbookString);
|
|
1638
|
-
try {
|
|
1639
|
-
for (var _g = __values(parameters.filter(function (_a) {
|
|
1640
|
-
var isInput = _a.isInput;
|
|
1641
|
-
return isInput;
|
|
1642
|
-
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1643
|
-
var parameter = _h.value;
|
|
1644
|
-
commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1648
|
-
finally {
|
|
1649
|
-
try {
|
|
1650
|
-
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
1651
|
-
}
|
|
1652
|
-
finally { if (e_1) throw e_1.error; }
|
|
1653
|
-
}
|
|
1654
|
-
try {
|
|
1655
|
-
for (var _j = __values(parameters.filter(function (_a) {
|
|
1656
|
-
var isOutput = _a.isOutput;
|
|
1657
|
-
return isOutput;
|
|
1658
|
-
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1659
|
-
var parameter = _k.value;
|
|
1660
|
-
commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1664
|
-
finally {
|
|
1665
|
-
try {
|
|
1666
|
-
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
1667
|
-
}
|
|
1668
|
-
finally { if (e_2) throw e_2.error; }
|
|
1669
|
-
}
|
|
1670
|
-
promptbookString += '\n\n';
|
|
1671
|
-
promptbookString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1672
|
-
try {
|
|
1673
|
-
for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
|
|
1674
|
-
var promptTemplate = promptTemplates_1_1.value;
|
|
1675
|
-
var
|
|
1676
|
-
/* Note: Not using:> name, */
|
|
1677
|
-
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
1678
|
-
/* Note: dependentParameterNames, */
|
|
1679
|
-
jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
1680
|
-
promptbookString += '\n\n';
|
|
1681
|
-
promptbookString += "## ".concat(title_1);
|
|
1682
|
-
if (description_1) {
|
|
1683
|
-
promptbookString += '\n\n';
|
|
1684
|
-
promptbookString += description_1;
|
|
1685
|
-
}
|
|
1686
|
-
// TODO:> const commands: Array<Command>
|
|
1687
|
-
var commands_1 = [];
|
|
1688
|
-
var contentLanguage = 'text';
|
|
1689
|
-
if (executionType === 'PROMPT_TEMPLATE') {
|
|
1690
|
-
var modelRequirements = promptTemplate.modelRequirements;
|
|
1691
|
-
var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
|
|
1692
|
-
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
1693
|
-
if (modelVariant) {
|
|
1694
|
-
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
1695
|
-
}
|
|
1696
|
-
if (modelName) {
|
|
1697
|
-
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
else if (executionType === 'SIMPLE_TEMPLATE') {
|
|
1701
|
-
commands_1.push("SIMPLE TEMPLATE");
|
|
1702
|
-
// Note: Nothing special here
|
|
1703
|
-
}
|
|
1704
|
-
else if (executionType === 'SCRIPT') {
|
|
1705
|
-
commands_1.push("EXECUTE SCRIPT");
|
|
1706
|
-
if (promptTemplate.contentLanguage) {
|
|
1707
|
-
contentLanguage = promptTemplate.contentLanguage;
|
|
1708
|
-
}
|
|
1709
|
-
else {
|
|
1710
|
-
contentLanguage = '';
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
else if (executionType === 'PROMPT_DIALOG') {
|
|
1714
|
-
commands_1.push("PROMPT DIALOG");
|
|
1715
|
-
// Note: Nothing special here
|
|
1716
|
-
}
|
|
1717
|
-
if (jokers) {
|
|
1718
|
-
try {
|
|
1719
|
-
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
1720
|
-
var joker = jokers_1_1.value;
|
|
1721
|
-
commands_1.push("JOKER {".concat(joker, "}"));
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1725
|
-
finally {
|
|
1726
|
-
try {
|
|
1727
|
-
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
1728
|
-
}
|
|
1729
|
-
finally { if (e_4) throw e_4.error; }
|
|
1730
|
-
}
|
|
1731
|
-
} /* not else */
|
|
1732
|
-
if (postprocessing) {
|
|
1733
|
-
try {
|
|
1734
|
-
for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
|
|
1735
|
-
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
1736
|
-
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
1698
|
+
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
1699
|
+
case 2:
|
|
1700
|
+
/* [5] */ _e.sent();
|
|
1701
|
+
return [3 /*break*/, 4];
|
|
1702
|
+
case 3:
|
|
1703
|
+
unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
|
|
1704
|
+
work_1 = executeSingleTemplate(currentTemplate)
|
|
1705
|
+
.then(function () {
|
|
1706
|
+
resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
|
|
1707
|
+
})
|
|
1708
|
+
.then(function () {
|
|
1709
|
+
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
1710
|
+
});
|
|
1711
|
+
resolving_1.push(work_1);
|
|
1712
|
+
_e.label = 4;
|
|
1713
|
+
case 4: return [2 /*return*/];
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
};
|
|
1717
|
+
_d.label = 2;
|
|
1718
|
+
case 2:
|
|
1719
|
+
if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
|
|
1720
|
+
return [5 /*yield**/, _loop_1()];
|
|
1721
|
+
case 3:
|
|
1722
|
+
_d.sent();
|
|
1723
|
+
return [3 /*break*/, 2];
|
|
1724
|
+
case 4: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
1725
|
+
case 5:
|
|
1726
|
+
_d.sent();
|
|
1727
|
+
return [3 /*break*/, 7];
|
|
1728
|
+
case 6:
|
|
1729
|
+
error_1 = _d.sent();
|
|
1730
|
+
if (!(error_1 instanceof Error)) {
|
|
1731
|
+
throw error_1;
|
|
1737
1732
|
}
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1733
|
+
usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1734
|
+
var result = _a.result;
|
|
1735
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1736
|
+
})), false));
|
|
1737
|
+
return [2 /*return*/, {
|
|
1738
|
+
isSuccessful: false,
|
|
1739
|
+
errors: [error_1],
|
|
1740
|
+
usage: usage_1,
|
|
1741
|
+
executionReport: executionReport,
|
|
1742
|
+
outputParameters: parametersToPass,
|
|
1743
|
+
}];
|
|
1744
|
+
case 7:
|
|
1741
1745
|
try {
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
if (expectations) {
|
|
1748
|
-
try {
|
|
1749
|
-
for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1750
|
-
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
1751
|
-
if (min === max) {
|
|
1752
|
-
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1753
|
-
}
|
|
1754
|
-
else {
|
|
1755
|
-
if (min !== undefined) {
|
|
1756
|
-
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1757
|
-
} /* not else */
|
|
1758
|
-
if (max !== undefined) {
|
|
1759
|
-
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
1746
|
+
// Note: Filter ONLY output parameters
|
|
1747
|
+
for (_a = __values(promptbook.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1748
|
+
parameter = _b.value;
|
|
1749
|
+
if (parameter.isOutput) {
|
|
1750
|
+
continue;
|
|
1760
1751
|
}
|
|
1752
|
+
delete parametersToPass[parameter.name];
|
|
1761
1753
|
}
|
|
1762
1754
|
}
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1755
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1756
|
+
finally {
|
|
1757
|
+
try {
|
|
1758
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1759
|
+
}
|
|
1760
|
+
finally { if (e_1) throw e_1.error; }
|
|
1768
1761
|
}
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
// <- TODO: !!! Escape
|
|
1785
|
-
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1786
|
-
promptbookString += '\n';
|
|
1787
|
-
promptbookString += '```';
|
|
1788
|
-
promptbookString += '\n\n';
|
|
1789
|
-
promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1793
|
-
finally {
|
|
1794
|
-
try {
|
|
1795
|
-
if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
|
|
1796
|
-
}
|
|
1797
|
-
finally { if (e_3) throw e_3.error; }
|
|
1798
|
-
}
|
|
1799
|
-
return promptbookString;
|
|
1800
|
-
}
|
|
1801
|
-
/**
|
|
1802
|
-
* @private internal util of promptbookJsonToString
|
|
1803
|
-
*/
|
|
1804
|
-
function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
1805
|
-
var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
|
|
1806
|
-
var parameterString = "{".concat(name, "}");
|
|
1807
|
-
if (description) {
|
|
1808
|
-
parameterString = "".concat(parameterString, " ").concat(description);
|
|
1809
|
-
}
|
|
1810
|
-
return parameterString;
|
|
1762
|
+
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1763
|
+
var result = _a.result;
|
|
1764
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1765
|
+
})), false));
|
|
1766
|
+
return [2 /*return*/, {
|
|
1767
|
+
isSuccessful: true,
|
|
1768
|
+
errors: [],
|
|
1769
|
+
usage: usage,
|
|
1770
|
+
executionReport: executionReport,
|
|
1771
|
+
outputParameters: parametersToPass,
|
|
1772
|
+
}];
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
}); };
|
|
1776
|
+
return promptbookExecutor;
|
|
1811
1777
|
}
|
|
1812
1778
|
/**
|
|
1813
|
-
* TODO:
|
|
1779
|
+
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
1780
|
+
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
1781
|
+
* Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
|
|
1782
|
+
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
1814
1783
|
*/
|
|
1815
1784
|
|
|
1816
1785
|
/**
|
|
1817
1786
|
* This error indicates that promptbook not found in the library
|
|
1818
1787
|
*/
|
|
1819
|
-
var
|
|
1820
|
-
__extends(
|
|
1821
|
-
function
|
|
1788
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
1789
|
+
__extends(NotFoundError, _super);
|
|
1790
|
+
function NotFoundError(message) {
|
|
1822
1791
|
var _this = _super.call(this, message) || this;
|
|
1823
|
-
_this.name = '
|
|
1824
|
-
Object.setPrototypeOf(_this,
|
|
1792
|
+
_this.name = 'NotFoundError';
|
|
1793
|
+
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
1825
1794
|
return _this;
|
|
1826
1795
|
}
|
|
1827
|
-
return
|
|
1796
|
+
return NotFoundError;
|
|
1828
1797
|
}(Error));
|
|
1829
1798
|
|
|
1830
1799
|
/**
|
|
1831
1800
|
* This error indicates errors in referencing promptbooks between each other
|
|
1832
1801
|
*/
|
|
1833
|
-
var
|
|
1834
|
-
__extends(
|
|
1835
|
-
function
|
|
1802
|
+
var ReferenceError$1 = /** @class */ (function (_super) {
|
|
1803
|
+
__extends(ReferenceError, _super);
|
|
1804
|
+
function ReferenceError(message) {
|
|
1836
1805
|
var _this = _super.call(this, message) || this;
|
|
1837
|
-
_this.name = '
|
|
1838
|
-
Object.setPrototypeOf(_this,
|
|
1806
|
+
_this.name = 'ReferenceError';
|
|
1807
|
+
Object.setPrototypeOf(_this, ReferenceError.prototype);
|
|
1839
1808
|
return _this;
|
|
1840
1809
|
}
|
|
1841
|
-
return
|
|
1810
|
+
return ReferenceError;
|
|
1842
1811
|
}(Error));
|
|
1843
1812
|
|
|
1844
1813
|
/**
|
|
1845
1814
|
* Library of promptbooks that groups together promptbooks for an application.
|
|
1846
1815
|
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
1847
1816
|
*
|
|
1848
|
-
* @private use `
|
|
1849
|
-
* @see https://github.com/webgptorg/promptbook#promptbook-
|
|
1817
|
+
* @private use `createCollectionFromJson` instead
|
|
1818
|
+
* @see https://github.com/webgptorg/promptbook#promptbook-collection
|
|
1850
1819
|
*/
|
|
1851
|
-
var
|
|
1820
|
+
var SimplePipelineCollection = /** @class */ (function () {
|
|
1852
1821
|
/**
|
|
1853
1822
|
* Constructs a promptbook library from promptbooks
|
|
1854
1823
|
*
|
|
1855
1824
|
* @param promptbooks !!!
|
|
1856
1825
|
*
|
|
1857
|
-
* @private Use instead `
|
|
1826
|
+
* @private Use instead `createCollectionFromJson`
|
|
1858
1827
|
* Note: During the construction logic of all promptbooks are validated
|
|
1859
|
-
* Note: It is not recommended to use this constructor directly, use `
|
|
1828
|
+
* Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
|
|
1860
1829
|
*/
|
|
1861
|
-
function
|
|
1830
|
+
function SimplePipelineCollection() {
|
|
1862
1831
|
var e_1, _a;
|
|
1863
1832
|
var promptbooks = [];
|
|
1864
1833
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -1869,14 +1838,13 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
1869
1838
|
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
1870
1839
|
var promptbook = promptbooks_1_1.value;
|
|
1871
1840
|
if (promptbook.promptbookUrl === undefined) {
|
|
1872
|
-
throw new
|
|
1841
|
+
throw new ReferenceError$1(spaceTrim$1("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
|
|
1873
1842
|
}
|
|
1874
|
-
|
|
1843
|
+
validatePipeline(promptbook);
|
|
1875
1844
|
// Note: [🦄]
|
|
1876
1845
|
if (this.library.has(promptbook.promptbookUrl) &&
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
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 ")));
|
|
1846
|
+
pipelineJsonToString(promptbook) !== pipelineJsonToString(this.library.get(promptbook.promptbookUrl))) {
|
|
1847
|
+
throw new ReferenceError$1(spaceTrim$1("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
|
|
1880
1848
|
}
|
|
1881
1849
|
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
1882
1850
|
}
|
|
@@ -1892,7 +1860,7 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
1892
1860
|
/**
|
|
1893
1861
|
* Gets all promptbooks in the library
|
|
1894
1862
|
*/
|
|
1895
|
-
|
|
1863
|
+
SimplePipelineCollection.prototype.listPipelines = function () {
|
|
1896
1864
|
return Array.from(this.library.keys());
|
|
1897
1865
|
};
|
|
1898
1866
|
/**
|
|
@@ -1900,14 +1868,14 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
1900
1868
|
*
|
|
1901
1869
|
* Note: This is not a direct fetching from the URL, but a lookup in the library
|
|
1902
1870
|
*/
|
|
1903
|
-
|
|
1871
|
+
SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
|
|
1904
1872
|
var _this = this;
|
|
1905
1873
|
var promptbook = this.library.get(url);
|
|
1906
1874
|
if (!promptbook) {
|
|
1907
|
-
if (this.
|
|
1908
|
-
throw new
|
|
1875
|
+
if (this.listPipelines().length === 0) {
|
|
1876
|
+
throw new NotFoundError(spaceTrim$1("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
1909
1877
|
}
|
|
1910
|
-
throw new
|
|
1878
|
+
throw new NotFoundError(spaceTrim$1(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPipelines()
|
|
1911
1879
|
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
1912
1880
|
.join('\n')), "\n\n "); }));
|
|
1913
1881
|
}
|
|
@@ -1916,27 +1884,27 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
1916
1884
|
/**
|
|
1917
1885
|
* Checks whether given prompt was defined in any promptbook in the library
|
|
1918
1886
|
*/
|
|
1919
|
-
|
|
1887
|
+
SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
|
|
1920
1888
|
return true;
|
|
1921
1889
|
};
|
|
1922
|
-
return
|
|
1890
|
+
return SimplePipelineCollection;
|
|
1923
1891
|
}());
|
|
1924
1892
|
|
|
1925
1893
|
/**
|
|
1926
|
-
* Creates
|
|
1894
|
+
* Creates PipelineCollection from array of PipelineJson or PipelineString
|
|
1927
1895
|
*
|
|
1928
|
-
* Note: Functions `libraryToJson` and `
|
|
1896
|
+
* Note: Functions `libraryToJson` and `createCollectionFromJson` are complementary
|
|
1929
1897
|
* Note: During the construction syntax and logic of all sources are validated
|
|
1930
1898
|
*
|
|
1931
1899
|
* @param promptbookSources
|
|
1932
|
-
* @returns
|
|
1900
|
+
* @returns PipelineCollection
|
|
1933
1901
|
*/
|
|
1934
|
-
function
|
|
1902
|
+
function createCollectionFromJson() {
|
|
1935
1903
|
var promptbooks = [];
|
|
1936
1904
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1937
1905
|
promptbooks[_i] = arguments[_i];
|
|
1938
1906
|
}
|
|
1939
|
-
return new (
|
|
1907
|
+
return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
1940
1908
|
}
|
|
1941
1909
|
|
|
1942
1910
|
/* tslint:disable */
|
|
@@ -2002,8 +1970,8 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2002
1970
|
switch (_b.label) {
|
|
2003
1971
|
case 0:
|
|
2004
1972
|
content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
2005
|
-
library =
|
|
2006
|
-
return [4 /*yield*/, library.
|
|
1973
|
+
library = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
1974
|
+
return [4 /*yield*/, library.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2007
1975
|
case 1:
|
|
2008
1976
|
prepareKnowledgeFromMarkdownPromptbook = _b.sent();
|
|
2009
1977
|
prepareKnowledgeFromMarkdownExecutor = createPromptbookExecutor({
|
|
@@ -2015,7 +1983,7 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2015
1983
|
],
|
|
2016
1984
|
},
|
|
2017
1985
|
});
|
|
2018
|
-
return [4 /*yield*/, library.
|
|
1986
|
+
return [4 /*yield*/, library.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-keywords.ptbk.md')];
|
|
2019
1987
|
case 2:
|
|
2020
1988
|
prepareKeywordsPromptbook = _b.sent();
|
|
2021
1989
|
prepareKeywordsExecutor = createPromptbookExecutor({
|
|
@@ -2043,8 +2011,8 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2043
2011
|
switch (_b.label) {
|
|
2044
2012
|
case 0:
|
|
2045
2013
|
name = "piece-".concat(i);
|
|
2046
|
-
title = spaceTrim
|
|
2047
|
-
content = spaceTrim
|
|
2014
|
+
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
2015
|
+
content = spaceTrim(knowledgeTextPiece);
|
|
2048
2016
|
keywords = [];
|
|
2049
2017
|
index = [];
|
|
2050
2018
|
sources = [];
|
|
@@ -2052,7 +2020,7 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2052
2020
|
case 1:
|
|
2053
2021
|
_b.trys.push([1, 3, , 4]);
|
|
2054
2022
|
// TODO: !!!! Summarize name and title from the content
|
|
2055
|
-
title = spaceTrim
|
|
2023
|
+
title = spaceTrim(knowledgeTextPiece.substring(0, 30));
|
|
2056
2024
|
name = normalizeToKebabCase(title);
|
|
2057
2025
|
return [4 /*yield*/, prepareKeywordsExecutor({ content: content })];
|
|
2058
2026
|
case 2:
|
|
@@ -2121,7 +2089,7 @@ var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
|
2121
2089
|
/**
|
|
2122
2090
|
* Computes the deepness of the markdown structure.
|
|
2123
2091
|
*
|
|
2124
|
-
* @private within the
|
|
2092
|
+
* @private within the package
|
|
2125
2093
|
*/
|
|
2126
2094
|
function countMarkdownStructureDeepness(markdownStructure) {
|
|
2127
2095
|
var e_1, _a;
|
|
@@ -2151,7 +2119,7 @@ function countMarkdownStructureDeepness(markdownStructure) {
|
|
|
2151
2119
|
* @param markdown The markdown string to parse.
|
|
2152
2120
|
* @returns The MarkdownStructure object.
|
|
2153
2121
|
*
|
|
2154
|
-
* @private within the
|
|
2122
|
+
* @private within the package
|
|
2155
2123
|
*/
|
|
2156
2124
|
function markdownToMarkdownStructure(markdown) {
|
|
2157
2125
|
var e_1, _a;
|
|
@@ -2187,7 +2155,7 @@ function markdownToMarkdownStructure(markdown) {
|
|
|
2187
2155
|
}
|
|
2188
2156
|
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
2189
2157
|
// [🌻]
|
|
2190
|
-
throw new Error(spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
2158
|
+
throw new Error(spaceTrim$1("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
2191
2159
|
}
|
|
2192
2160
|
parent_1 = parent_1.parent;
|
|
2193
2161
|
}
|
|
@@ -2221,7 +2189,7 @@ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
|
2221
2189
|
return {
|
|
2222
2190
|
level: level,
|
|
2223
2191
|
title: title,
|
|
2224
|
-
content: spaceTrim(contentLines.join('\n')),
|
|
2192
|
+
content: spaceTrim$1(contentLines.join('\n')),
|
|
2225
2193
|
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
2226
2194
|
};
|
|
2227
2195
|
}
|
|
@@ -2346,6 +2314,16 @@ function extractOneBlockFromMarkdown(markdown) {
|
|
|
2346
2314
|
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
2347
2315
|
*/
|
|
2348
2316
|
|
|
2317
|
+
/**
|
|
2318
|
+
* Removes HTML or Markdown comments from a string.
|
|
2319
|
+
*
|
|
2320
|
+
* @param {string} content - The string to remove comments from.
|
|
2321
|
+
* @returns {string} The input string with all comments removed.
|
|
2322
|
+
*/
|
|
2323
|
+
function removeContentComments(content) {
|
|
2324
|
+
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2349
2327
|
/**
|
|
2350
2328
|
* Creates a new set with all elements that are present in either set
|
|
2351
2329
|
*/
|
|
@@ -2416,7 +2394,7 @@ function extractParameters(template) {
|
|
|
2416
2394
|
*
|
|
2417
2395
|
* @param script from which to extract the variables
|
|
2418
2396
|
* @returns the list of variable names
|
|
2419
|
-
* @throws {
|
|
2397
|
+
* @throws {SyntaxError} if the script is invalid
|
|
2420
2398
|
*/
|
|
2421
2399
|
function extractVariables(script) {
|
|
2422
2400
|
var variables = new Set();
|
|
@@ -2452,7 +2430,7 @@ function extractVariables(script) {
|
|
|
2452
2430
|
if (!(error instanceof Error)) {
|
|
2453
2431
|
throw error;
|
|
2454
2432
|
}
|
|
2455
|
-
throw new
|
|
2433
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
2456
2434
|
}
|
|
2457
2435
|
return variables;
|
|
2458
2436
|
}
|
|
@@ -2465,7 +2443,7 @@ function extractVariables(script) {
|
|
|
2465
2443
|
*
|
|
2466
2444
|
* @param promptTemplate the template with used parameters
|
|
2467
2445
|
* @returns the set of parameter names
|
|
2468
|
-
* @throws {
|
|
2446
|
+
* @throws {SyntaxError} if the script is invalid
|
|
2469
2447
|
*/
|
|
2470
2448
|
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
2471
2449
|
var e_1, _a, e_2, _b;
|
|
@@ -2504,6 +2482,45 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
2504
2482
|
* TODO: [🔣] If script require contentLanguage
|
|
2505
2483
|
*/
|
|
2506
2484
|
|
|
2485
|
+
/**
|
|
2486
|
+
* Execution type describes the way how the block is executed
|
|
2487
|
+
*
|
|
2488
|
+
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
2489
|
+
*/
|
|
2490
|
+
var ExecutionTypes = [
|
|
2491
|
+
'PROMPT_TEMPLATE',
|
|
2492
|
+
'SIMPLE_TEMPLATE',
|
|
2493
|
+
'SCRIPT',
|
|
2494
|
+
'PROMPT_DIALOG',
|
|
2495
|
+
// <- [🥻] Insert here when making new command
|
|
2496
|
+
];
|
|
2497
|
+
|
|
2498
|
+
/**
|
|
2499
|
+
* Units of text measurement
|
|
2500
|
+
*/
|
|
2501
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2502
|
+
/**
|
|
2503
|
+
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
2504
|
+
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
2505
|
+
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
2506
|
+
*/
|
|
2507
|
+
|
|
2508
|
+
/**
|
|
2509
|
+
* Removes Markdown formatting tags from a string.
|
|
2510
|
+
*
|
|
2511
|
+
* @param {string} str - The string to remove Markdown tags from.
|
|
2512
|
+
* @returns {string} The input string with all Markdown tags removed.
|
|
2513
|
+
*/
|
|
2514
|
+
function removeMarkdownFormatting(str) {
|
|
2515
|
+
// Remove bold formatting
|
|
2516
|
+
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
2517
|
+
// Remove italic formatting
|
|
2518
|
+
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
2519
|
+
// Remove code formatting
|
|
2520
|
+
str = str.replace(/`(.*?)`/g, '$1');
|
|
2521
|
+
return str;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2507
2524
|
/* tslint:disable */
|
|
2508
2525
|
/*
|
|
2509
2526
|
TODO: Tests
|
|
@@ -2568,45 +2585,6 @@ function normalizeTo_SCREAMING_CASE(sentence) {
|
|
|
2568
2585
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
2569
2586
|
*/
|
|
2570
2587
|
|
|
2571
|
-
/**
|
|
2572
|
-
* Execution type describes the way how the block is executed
|
|
2573
|
-
*
|
|
2574
|
-
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
2575
|
-
*/
|
|
2576
|
-
var ExecutionTypes = [
|
|
2577
|
-
'PROMPT_TEMPLATE',
|
|
2578
|
-
'SIMPLE_TEMPLATE',
|
|
2579
|
-
'SCRIPT',
|
|
2580
|
-
'PROMPT_DIALOG',
|
|
2581
|
-
// <- [🥻] Insert here when making new command
|
|
2582
|
-
];
|
|
2583
|
-
|
|
2584
|
-
/**
|
|
2585
|
-
* Units of text measurement
|
|
2586
|
-
*/
|
|
2587
|
-
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2588
|
-
/**
|
|
2589
|
-
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
2590
|
-
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
2591
|
-
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
2592
|
-
*/
|
|
2593
|
-
|
|
2594
|
-
/**
|
|
2595
|
-
* Removes Markdown formatting tags from a string.
|
|
2596
|
-
*
|
|
2597
|
-
* @param {string} str - The string to remove Markdown tags from.
|
|
2598
|
-
* @returns {string} The input string with all Markdown tags removed.
|
|
2599
|
-
*/
|
|
2600
|
-
function removeMarkdownFormatting(str) {
|
|
2601
|
-
// Remove bold formatting
|
|
2602
|
-
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
2603
|
-
// Remove italic formatting
|
|
2604
|
-
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
2605
|
-
// Remove code formatting
|
|
2606
|
-
str = str.replace(/`(.*?)`/g, '$1');
|
|
2607
|
-
return str;
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2610
2588
|
/**
|
|
2611
2589
|
* Function parseNumber will parse number from string
|
|
2612
2590
|
*
|
|
@@ -2614,7 +2592,7 @@ function removeMarkdownFormatting(str) {
|
|
|
2614
2592
|
* Note: it also works only with decimal numbers
|
|
2615
2593
|
*
|
|
2616
2594
|
* @returns parsed number
|
|
2617
|
-
* @throws {
|
|
2595
|
+
* @throws {SyntaxError} if the value is not a number
|
|
2618
2596
|
*
|
|
2619
2597
|
* @private within the parseCommand
|
|
2620
2598
|
*/
|
|
@@ -2650,7 +2628,7 @@ function parseNumber(value) {
|
|
|
2650
2628
|
var numerator = parseNumber(numerator_);
|
|
2651
2629
|
var denominator = parseNumber(denominator_);
|
|
2652
2630
|
if (denominator === 0) {
|
|
2653
|
-
throw new
|
|
2631
|
+
throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
2654
2632
|
}
|
|
2655
2633
|
return numerator / denominator;
|
|
2656
2634
|
}
|
|
@@ -2662,11 +2640,11 @@ function parseNumber(value) {
|
|
|
2662
2640
|
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
2663
2641
|
}
|
|
2664
2642
|
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
2665
|
-
throw new
|
|
2643
|
+
throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
2666
2644
|
}
|
|
2667
2645
|
var num = parseFloat(value);
|
|
2668
2646
|
if (isNaN(num)) {
|
|
2669
|
-
throw new
|
|
2647
|
+
throw new SyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
2670
2648
|
}
|
|
2671
2649
|
return num;
|
|
2672
2650
|
}
|
|
@@ -2678,14 +2656,14 @@ function parseNumber(value) {
|
|
|
2678
2656
|
* Parses one line of ul/ol to command
|
|
2679
2657
|
*
|
|
2680
2658
|
* @returns parsed command object
|
|
2681
|
-
* @throws {
|
|
2659
|
+
* @throws {SyntaxError} if the command is invalid
|
|
2682
2660
|
*
|
|
2683
|
-
* @private within the
|
|
2661
|
+
* @private within the pipelineStringToJson
|
|
2684
2662
|
*/
|
|
2685
2663
|
function parseCommand(listItem) {
|
|
2686
2664
|
var e_1, _a;
|
|
2687
2665
|
if (listItem.includes('\n') || listItem.includes('\r')) {
|
|
2688
|
-
throw new
|
|
2666
|
+
throw new SyntaxError('Command can not contain new line characters:');
|
|
2689
2667
|
}
|
|
2690
2668
|
var type = listItem.trim();
|
|
2691
2669
|
type = type.split('`').join('');
|
|
@@ -2712,15 +2690,15 @@ function parseCommand(listItem) {
|
|
|
2712
2690
|
type.startsWith('PROMPTBOOKURL') ||
|
|
2713
2691
|
type.startsWith('HTTPS')) {
|
|
2714
2692
|
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
2715
|
-
throw new
|
|
2693
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
2716
2694
|
}
|
|
2717
2695
|
var promptbookUrlString = listItemParts.pop();
|
|
2718
2696
|
var promptbookUrl = new URL(promptbookUrlString);
|
|
2719
2697
|
if (promptbookUrl.protocol !== 'https:') {
|
|
2720
|
-
throw new
|
|
2698
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
2721
2699
|
}
|
|
2722
2700
|
if (promptbookUrl.hash !== '') {
|
|
2723
|
-
throw new
|
|
2701
|
+
throw new SyntaxError(spaceTrim$1("\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 ")));
|
|
2724
2702
|
}
|
|
2725
2703
|
return {
|
|
2726
2704
|
type: 'PROMPTBOOK_URL',
|
|
@@ -2729,7 +2707,7 @@ function parseCommand(listItem) {
|
|
|
2729
2707
|
}
|
|
2730
2708
|
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
2731
2709
|
if (listItemParts.length !== 2) {
|
|
2732
|
-
throw new
|
|
2710
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
2733
2711
|
}
|
|
2734
2712
|
var promptbookVersion = listItemParts.pop();
|
|
2735
2713
|
// TODO: Validate version
|
|
@@ -2744,7 +2722,7 @@ function parseCommand(listItem) {
|
|
|
2744
2722
|
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
2745
2723
|
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
2746
2724
|
if (executionTypes.length !== 1) {
|
|
2747
|
-
throw new
|
|
2725
|
+
throw new SyntaxError(spaceTrim$1(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 "); }));
|
|
2748
2726
|
}
|
|
2749
2727
|
return {
|
|
2750
2728
|
type: 'EXECUTE',
|
|
@@ -2769,7 +2747,7 @@ function parseCommand(listItem) {
|
|
|
2769
2747
|
};
|
|
2770
2748
|
}
|
|
2771
2749
|
else {
|
|
2772
|
-
throw new
|
|
2750
|
+
throw new SyntaxError(spaceTrim$1(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 "); }));
|
|
2773
2751
|
}
|
|
2774
2752
|
}
|
|
2775
2753
|
if (type.startsWith('MODEL_NAME')) {
|
|
@@ -2780,7 +2758,7 @@ function parseCommand(listItem) {
|
|
|
2780
2758
|
};
|
|
2781
2759
|
}
|
|
2782
2760
|
else {
|
|
2783
|
-
throw new
|
|
2761
|
+
throw new SyntaxError(spaceTrim$1(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 "); }));
|
|
2784
2762
|
}
|
|
2785
2763
|
}
|
|
2786
2764
|
else if (type.startsWith('PARAM') ||
|
|
@@ -2790,12 +2768,12 @@ function parseCommand(listItem) {
|
|
|
2790
2768
|
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
2791
2769
|
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
2792
2770
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2793
|
-
throw new
|
|
2771
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2794
2772
|
}
|
|
2795
2773
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2796
2774
|
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
2797
2775
|
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
2798
|
-
throw new
|
|
2776
|
+
throw new SyntaxError(spaceTrim$1("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
2799
2777
|
}
|
|
2800
2778
|
var isInput = type.startsWith('INPUT');
|
|
2801
2779
|
var isOutput = type.startsWith('OUTPUT');
|
|
@@ -2813,11 +2791,11 @@ function parseCommand(listItem) {
|
|
|
2813
2791
|
}
|
|
2814
2792
|
else if (type.startsWith('JOKER')) {
|
|
2815
2793
|
if (listItemParts.length !== 2) {
|
|
2816
|
-
throw new
|
|
2794
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
2817
2795
|
}
|
|
2818
2796
|
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
2819
2797
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2820
|
-
throw new
|
|
2798
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2821
2799
|
}
|
|
2822
2800
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2823
2801
|
var parameterName = parametersMatch.groups.parameterName;
|
|
@@ -2828,7 +2806,7 @@ function parseCommand(listItem) {
|
|
|
2828
2806
|
}
|
|
2829
2807
|
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
2830
2808
|
if (listItemParts.length !== 2) {
|
|
2831
|
-
throw new
|
|
2809
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
2832
2810
|
}
|
|
2833
2811
|
var functionName = listItemParts.pop();
|
|
2834
2812
|
return {
|
|
@@ -2858,15 +2836,15 @@ function parseCommand(listItem) {
|
|
|
2858
2836
|
sign = 'MAXIMUM';
|
|
2859
2837
|
}
|
|
2860
2838
|
else {
|
|
2861
|
-
throw new
|
|
2839
|
+
throw new SyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
|
|
2862
2840
|
}
|
|
2863
2841
|
var amountRaw = listItemParts.shift();
|
|
2864
2842
|
var amount = parseNumber(amountRaw);
|
|
2865
2843
|
if (amount < 0) {
|
|
2866
|
-
throw new
|
|
2844
|
+
throw new SyntaxError('Amount must be positive number or zero');
|
|
2867
2845
|
}
|
|
2868
2846
|
if (amount !== Math.floor(amount)) {
|
|
2869
|
-
throw new
|
|
2847
|
+
throw new SyntaxError('Amount must be whole number');
|
|
2870
2848
|
}
|
|
2871
2849
|
var unitRaw = listItemParts.shift();
|
|
2872
2850
|
var unit = undefined;
|
|
@@ -2881,7 +2859,7 @@ function parseCommand(listItem) {
|
|
|
2881
2859
|
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
2882
2860
|
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
2883
2861
|
if (unit !== undefined) {
|
|
2884
|
-
throw new
|
|
2862
|
+
throw new SyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
2885
2863
|
}
|
|
2886
2864
|
unit = existingUnit;
|
|
2887
2865
|
}
|
|
@@ -2895,7 +2873,7 @@ function parseCommand(listItem) {
|
|
|
2895
2873
|
finally { if (e_1) throw e_1.error; }
|
|
2896
2874
|
}
|
|
2897
2875
|
if (unit === undefined) {
|
|
2898
|
-
throw new
|
|
2876
|
+
throw new SyntaxError("Invalid unit \"".concat(unitRaw, "\""));
|
|
2899
2877
|
}
|
|
2900
2878
|
return {
|
|
2901
2879
|
type: 'EXPECT_AMOUNT',
|
|
@@ -2908,7 +2886,7 @@ function parseCommand(listItem) {
|
|
|
2908
2886
|
if (!(error instanceof Error)) {
|
|
2909
2887
|
throw error;
|
|
2910
2888
|
}
|
|
2911
|
-
throw new
|
|
2889
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
2912
2890
|
}
|
|
2913
2891
|
/*
|
|
2914
2892
|
} else if (type.startsWith('__________________')) {
|
|
@@ -2916,7 +2894,7 @@ function parseCommand(listItem) {
|
|
|
2916
2894
|
*/
|
|
2917
2895
|
}
|
|
2918
2896
|
else {
|
|
2919
|
-
throw new
|
|
2897
|
+
throw new SyntaxError(spaceTrim$1("\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 ")));
|
|
2920
2898
|
}
|
|
2921
2899
|
}
|
|
2922
2900
|
|
|
@@ -2949,20 +2927,20 @@ function titleToName(value) {
|
|
|
2949
2927
|
* Compile promptbook from string (markdown) format to JSON format synchronously
|
|
2950
2928
|
*
|
|
2951
2929
|
* Note: There are two similar functions:
|
|
2952
|
-
* - `
|
|
2953
|
-
* - `
|
|
2930
|
+
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
2931
|
+
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
2954
2932
|
*
|
|
2955
|
-
* @param
|
|
2933
|
+
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
2956
2934
|
* @param options - Options and tools for the compilation
|
|
2957
2935
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
2958
|
-
* @throws {
|
|
2936
|
+
* @throws {SyntaxError} if the promptbook string is not valid
|
|
2959
2937
|
*
|
|
2960
2938
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
2961
2939
|
* Note: This function acts as compilation process
|
|
2962
2940
|
*/
|
|
2963
|
-
function
|
|
2941
|
+
function pipelineStringToJsonSync(pipelineString) {
|
|
2964
2942
|
var e_1, _a, e_2, _b;
|
|
2965
|
-
var
|
|
2943
|
+
var pipelineJson = {
|
|
2966
2944
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2967
2945
|
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
2968
2946
|
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
@@ -2974,19 +2952,19 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
2974
2952
|
};
|
|
2975
2953
|
// =============================================================
|
|
2976
2954
|
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2955
|
+
pipelineString = removeContentComments(pipelineString);
|
|
2956
|
+
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
2957
|
+
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
2980
2958
|
// =============================================================
|
|
2981
2959
|
///Note: 2️⃣ Function for adding parameters
|
|
2982
2960
|
var addParam = function (parameterCommand) {
|
|
2983
2961
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
2984
|
-
var existingParameter =
|
|
2962
|
+
var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
2985
2963
|
if (existingParameter &&
|
|
2986
2964
|
existingParameter.description &&
|
|
2987
2965
|
existingParameter.description !== parameterDescription &&
|
|
2988
2966
|
parameterDescription) {
|
|
2989
|
-
throw new
|
|
2967
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
2990
2968
|
}
|
|
2991
2969
|
if (existingParameter) {
|
|
2992
2970
|
if (parameterDescription) {
|
|
@@ -2994,7 +2972,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
2994
2972
|
}
|
|
2995
2973
|
}
|
|
2996
2974
|
else {
|
|
2997
|
-
|
|
2975
|
+
pipelineJson.parameters.push({
|
|
2998
2976
|
name: parameterName,
|
|
2999
2977
|
description: parameterDescription || undefined,
|
|
3000
2978
|
isInput: isInput,
|
|
@@ -3003,24 +2981,24 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3003
2981
|
}
|
|
3004
2982
|
};
|
|
3005
2983
|
// =============================================================
|
|
3006
|
-
// Note: 3️⃣ Parse the dynamic part - the
|
|
3007
|
-
var markdownStructure = markdownToMarkdownStructure(
|
|
2984
|
+
// Note: 3️⃣ Parse the dynamic part - the pipeline
|
|
2985
|
+
var markdownStructure = markdownToMarkdownStructure(pipelineString);
|
|
3008
2986
|
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
3009
2987
|
if (markdownStructureDeepness !== 2) {
|
|
3010
|
-
throw new
|
|
2988
|
+
throw new SyntaxError(spaceTrim$1("\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 ")));
|
|
3011
2989
|
}
|
|
3012
|
-
|
|
2990
|
+
pipelineJson.title = markdownStructure.title;
|
|
3013
2991
|
// TODO: [1] DRY description
|
|
3014
2992
|
var description = markdownStructure.content;
|
|
3015
2993
|
// Note: Remove codeblocks
|
|
3016
2994
|
description = description.split(/^```.*^```/gms).join('');
|
|
3017
2995
|
//Note: Remove lists and return statement
|
|
3018
2996
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
3019
|
-
description = spaceTrim(description);
|
|
2997
|
+
description = spaceTrim$1(description);
|
|
3020
2998
|
if (description === '') {
|
|
3021
2999
|
description = undefined;
|
|
3022
3000
|
}
|
|
3023
|
-
|
|
3001
|
+
pipelineJson.description = description;
|
|
3024
3002
|
var defaultModelRequirements = {};
|
|
3025
3003
|
var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
3026
3004
|
try {
|
|
@@ -3029,10 +3007,10 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3029
3007
|
var command = parseCommand(listItem);
|
|
3030
3008
|
switch (command.type) {
|
|
3031
3009
|
case 'PROMPTBOOK_URL':
|
|
3032
|
-
|
|
3010
|
+
pipelineJson.promptbookUrl = command.promptbookUrl.href;
|
|
3033
3011
|
break;
|
|
3034
3012
|
case 'PROMPTBOOK_VERSION':
|
|
3035
|
-
|
|
3013
|
+
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
3036
3014
|
break;
|
|
3037
3015
|
case 'MODEL':
|
|
3038
3016
|
defaultModelRequirements[command.key] = command.value;
|
|
@@ -3041,7 +3019,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3041
3019
|
addParam(command);
|
|
3042
3020
|
break;
|
|
3043
3021
|
default:
|
|
3044
|
-
throw new
|
|
3022
|
+
throw new SyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
3045
3023
|
}
|
|
3046
3024
|
}
|
|
3047
3025
|
}
|
|
@@ -3075,7 +3053,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3075
3053
|
break;
|
|
3076
3054
|
case 'EXECUTE':
|
|
3077
3055
|
if (isExecutionTypeChanged) {
|
|
3078
|
-
throw new
|
|
3056
|
+
throw new SyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
3079
3057
|
}
|
|
3080
3058
|
executionType = command.executionType;
|
|
3081
3059
|
isExecutionTypeChanged = true;
|
|
@@ -3096,25 +3074,25 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3096
3074
|
expectAmount[unit] = expectAmount[unit] || {};
|
|
3097
3075
|
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
3098
3076
|
if (expectAmount[unit].min !== undefined) {
|
|
3099
|
-
throw new
|
|
3077
|
+
throw new SyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3100
3078
|
}
|
|
3101
3079
|
expectAmount[unit].min = command.amount;
|
|
3102
3080
|
} /* not else */
|
|
3103
3081
|
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
3104
3082
|
if (expectAmount[unit].max !== undefined) {
|
|
3105
|
-
throw new
|
|
3083
|
+
throw new SyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3106
3084
|
}
|
|
3107
3085
|
expectAmount[unit].max = command.amount;
|
|
3108
3086
|
}
|
|
3109
3087
|
break;
|
|
3110
3088
|
case 'EXPECT_FORMAT':
|
|
3111
3089
|
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
3112
|
-
throw new
|
|
3090
|
+
throw new SyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
3113
3091
|
}
|
|
3114
3092
|
expectFormat = command.format;
|
|
3115
3093
|
break;
|
|
3116
3094
|
default:
|
|
3117
|
-
throw new
|
|
3095
|
+
throw new SyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
3118
3096
|
}
|
|
3119
3097
|
}
|
|
3120
3098
|
}
|
|
@@ -3128,16 +3106,16 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3128
3106
|
var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
|
|
3129
3107
|
if (executionType === 'SCRIPT') {
|
|
3130
3108
|
if (!language) {
|
|
3131
|
-
throw new
|
|
3109
|
+
throw new SyntaxError('You must specify the language of the script in the prompt template');
|
|
3132
3110
|
}
|
|
3133
3111
|
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
3134
|
-
throw new
|
|
3112
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
3135
3113
|
}
|
|
3136
3114
|
}
|
|
3137
3115
|
var lastLine = section.content.split('\n').pop();
|
|
3138
3116
|
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
3139
3117
|
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
3140
|
-
throw new
|
|
3118
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
3141
3119
|
// TODO: Show code of invalid sections each time + DRY
|
|
3142
3120
|
section.content
|
|
3143
3121
|
.split('\n')
|
|
@@ -3151,7 +3129,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3151
3129
|
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
3152
3130
|
//Note: Remove lists and return statement
|
|
3153
3131
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
3154
|
-
description_1 = spaceTrim(description_1);
|
|
3132
|
+
description_1 = spaceTrim$1(description_1);
|
|
3155
3133
|
if (description_1 === '') {
|
|
3156
3134
|
description_1 = undefined;
|
|
3157
3135
|
}
|
|
@@ -3187,7 +3165,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3187
3165
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3188
3166
|
delete template.modelRequirements;
|
|
3189
3167
|
}
|
|
3190
|
-
|
|
3168
|
+
pipelineJson.promptTemplates.push(template);
|
|
3191
3169
|
};
|
|
3192
3170
|
try {
|
|
3193
3171
|
for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
@@ -3203,7 +3181,7 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3203
3181
|
finally { if (e_2) throw e_2.error; }
|
|
3204
3182
|
}
|
|
3205
3183
|
// =============================================================
|
|
3206
|
-
return
|
|
3184
|
+
return pipelineJson;
|
|
3207
3185
|
}
|
|
3208
3186
|
/**
|
|
3209
3187
|
* TODO: Report here line/column of error
|
|
@@ -3215,21 +3193,21 @@ function promptbookStringToJsonSync(promptbookString) {
|
|
|
3215
3193
|
* Compile promptbook from string (markdown) format to JSON format
|
|
3216
3194
|
*
|
|
3217
3195
|
* Note: There are two similar functions:
|
|
3218
|
-
* - `
|
|
3219
|
-
* - `
|
|
3196
|
+
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
3197
|
+
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
3220
3198
|
*
|
|
3221
|
-
* @param
|
|
3199
|
+
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
3222
3200
|
* @param options - Options and tools for the compilation
|
|
3223
3201
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
3224
|
-
* @throws {
|
|
3202
|
+
* @throws {SyntaxError} if the promptbook string is not valid
|
|
3225
3203
|
*
|
|
3226
3204
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
3227
3205
|
* Note: This function acts as compilation process
|
|
3228
3206
|
*/
|
|
3229
|
-
function
|
|
3207
|
+
function pipelineStringToJson(pipelineString, options) {
|
|
3230
3208
|
if (options === void 0) { options = {}; }
|
|
3231
3209
|
return __awaiter(this, void 0, void 0, function () {
|
|
3232
|
-
var llmTools, knowledge,
|
|
3210
|
+
var llmTools, knowledge, pipelineJson;
|
|
3233
3211
|
return __generator(this, function (_a) {
|
|
3234
3212
|
switch (_a.label) {
|
|
3235
3213
|
case 0:
|
|
@@ -3244,8 +3222,8 @@ function promptbookStringToJson(promptbookString, options) {
|
|
|
3244
3222
|
console.info('!!!! knowledge', knowledge);
|
|
3245
3223
|
_a.label = 2;
|
|
3246
3224
|
case 2:
|
|
3247
|
-
|
|
3248
|
-
return [2 /*return*/,
|
|
3225
|
+
pipelineJson = pipelineStringToJsonSync(pipelineString);
|
|
3226
|
+
return [2 /*return*/, pipelineJson];
|
|
3249
3227
|
}
|
|
3250
3228
|
});
|
|
3251
3229
|
});
|
|
@@ -3254,6 +3232,27 @@ function promptbookStringToJson(promptbookString, options) {
|
|
|
3254
3232
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3255
3233
|
*/
|
|
3256
3234
|
|
|
3235
|
+
/**
|
|
3236
|
+
* Add or modify an auto-generated section in a markdown file
|
|
3237
|
+
*
|
|
3238
|
+
* @private within the package
|
|
3239
|
+
*/
|
|
3240
|
+
function addAutoGeneratedSection(content, options) {
|
|
3241
|
+
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
3242
|
+
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
3243
|
+
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
3244
|
+
var sectionMatch = content.match(sectionRegex);
|
|
3245
|
+
if (sectionMatch) {
|
|
3246
|
+
return content.replace(sectionRegex, spaceTrim$1(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
3247
|
+
}
|
|
3248
|
+
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
3249
|
+
if (!placeForSection) {
|
|
3250
|
+
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
3251
|
+
}
|
|
3252
|
+
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
3253
|
+
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3257
3256
|
/* tslint:disable */
|
|
3258
3257
|
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
3259
3258
|
var e_1, _a;
|
|
@@ -3314,23 +3313,23 @@ function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
|
3314
3313
|
*
|
|
3315
3314
|
* Note: The result is not wrapped in a Markdown code block
|
|
3316
3315
|
*/
|
|
3317
|
-
function renderPromptbookMermaid(
|
|
3316
|
+
function renderPromptbookMermaid(pipelineJson, options) {
|
|
3318
3317
|
var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
|
|
3319
3318
|
var parameterNameToTemplateName = function (parameterName) {
|
|
3320
|
-
var parameter =
|
|
3319
|
+
var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
3321
3320
|
if (!parameter) {
|
|
3322
3321
|
throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
|
|
3323
3322
|
}
|
|
3324
3323
|
if (parameter.isInput) {
|
|
3325
3324
|
return 'input';
|
|
3326
3325
|
}
|
|
3327
|
-
var template =
|
|
3326
|
+
var template = pipelineJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
|
|
3328
3327
|
if (!template) {
|
|
3329
3328
|
throw new Error("Could not find template for {".concat(parameterName, "}"));
|
|
3330
3329
|
}
|
|
3331
3330
|
return normalizeTo_camelCase('template-' + titleToName(template.title));
|
|
3332
3331
|
};
|
|
3333
|
-
var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(
|
|
3332
|
+
var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.promptTemplates
|
|
3334
3333
|
.flatMap(function (_a) {
|
|
3335
3334
|
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
3336
3335
|
return __spreadArray([
|
|
@@ -3339,7 +3338,7 @@ function renderPromptbookMermaid(promptbookJson, options) {
|
|
|
3339
3338
|
return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
|
|
3340
3339
|
})), false);
|
|
3341
3340
|
})
|
|
3342
|
-
.join('\n')), "\n\n ").concat(block(
|
|
3341
|
+
.join('\n')), "\n\n ").concat(block(pipelineJson.parameters
|
|
3343
3342
|
.filter(function (_a) {
|
|
3344
3343
|
var isOutput = _a.isOutput;
|
|
3345
3344
|
return isOutput;
|
|
@@ -3348,7 +3347,7 @@ function renderPromptbookMermaid(promptbookJson, options) {
|
|
|
3348
3347
|
var name = _a.name;
|
|
3349
3348
|
return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
|
|
3350
3349
|
})
|
|
3351
|
-
.join('\n')), "\n output((Output)):::output\n\n ").concat(block(
|
|
3350
|
+
.join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.promptTemplates
|
|
3352
3351
|
.map(function (promptTemplate) {
|
|
3353
3352
|
var link = linkPromptTemplate(promptTemplate);
|
|
3354
3353
|
if (link === null) {
|
|
@@ -3370,33 +3369,33 @@ function renderPromptbookMermaid(promptbookJson, options) {
|
|
|
3370
3369
|
/**
|
|
3371
3370
|
* Prettyfies Promptbook string and adds Mermaid graph
|
|
3372
3371
|
*/
|
|
3373
|
-
function
|
|
3372
|
+
function prettifyPipelineString(pipelineString, options) {
|
|
3374
3373
|
return __awaiter(this, void 0, void 0, function () {
|
|
3375
|
-
var isGraphAdded, isPrettifyed,
|
|
3374
|
+
var isGraphAdded, isPrettifyed, pipelineJson, promptbookMermaid_1, promptbookMermaidBlock;
|
|
3376
3375
|
return __generator(this, function (_a) {
|
|
3377
3376
|
switch (_a.label) {
|
|
3378
3377
|
case 0:
|
|
3379
3378
|
isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
|
|
3380
3379
|
if (!isGraphAdded) return [3 /*break*/, 2];
|
|
3381
|
-
return [4 /*yield*/,
|
|
3380
|
+
return [4 /*yield*/, pipelineStringToJson(pipelineString)];
|
|
3382
3381
|
case 1:
|
|
3383
|
-
|
|
3384
|
-
promptbookMermaid_1 = renderPromptbookMermaid(
|
|
3382
|
+
pipelineJson = _a.sent();
|
|
3383
|
+
promptbookMermaid_1 = renderPromptbookMermaid(pipelineJson, {
|
|
3385
3384
|
linkPromptTemplate: function (promptTemplate) {
|
|
3386
3385
|
return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
|
|
3387
3386
|
},
|
|
3388
3387
|
});
|
|
3389
|
-
promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
3390
|
-
|
|
3388
|
+
promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
3389
|
+
pipelineString = addAutoGeneratedSection(pipelineString, {
|
|
3391
3390
|
sectionName: 'Graph',
|
|
3392
3391
|
sectionContent: promptbookMermaidBlock,
|
|
3393
3392
|
});
|
|
3394
3393
|
_a.label = 2;
|
|
3395
3394
|
case 2:
|
|
3396
3395
|
if (isPrettifyed) {
|
|
3397
|
-
|
|
3396
|
+
pipelineString = prettifyMarkdown(pipelineString);
|
|
3398
3397
|
}
|
|
3399
|
-
return [2 /*return*/,
|
|
3398
|
+
return [2 /*return*/, pipelineString];
|
|
3400
3399
|
}
|
|
3401
3400
|
});
|
|
3402
3401
|
});
|
|
@@ -3409,15 +3408,15 @@ function prettifyPromptbookString(promptbookString, options) {
|
|
|
3409
3408
|
/**
|
|
3410
3409
|
* This error indicates that the promptbook library cannot be propperly loaded
|
|
3411
3410
|
*/
|
|
3412
|
-
var
|
|
3413
|
-
__extends(
|
|
3414
|
-
function
|
|
3411
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
3412
|
+
__extends(CollectionError, _super);
|
|
3413
|
+
function CollectionError(message) {
|
|
3415
3414
|
var _this = _super.call(this, message) || this;
|
|
3416
|
-
_this.name = '
|
|
3417
|
-
Object.setPrototypeOf(_this,
|
|
3415
|
+
_this.name = 'CollectionError';
|
|
3416
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
3418
3417
|
return _this;
|
|
3419
3418
|
}
|
|
3420
|
-
return
|
|
3419
|
+
return CollectionError;
|
|
3421
3420
|
}(Error));
|
|
3422
3421
|
|
|
3423
3422
|
/**
|
|
@@ -3466,7 +3465,7 @@ var CallbackInterfaceTools = /** @class */ (function () {
|
|
|
3466
3465
|
case 1:
|
|
3467
3466
|
answer = _a.sent();
|
|
3468
3467
|
if (this.options.isVerbose) {
|
|
3469
|
-
console.info(spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
|
|
3468
|
+
console.info(spaceTrim$1(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
|
|
3470
3469
|
}
|
|
3471
3470
|
return [2 /*return*/, answer];
|
|
3472
3471
|
}
|
|
@@ -3494,12 +3493,12 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
|
3494
3493
|
return __awaiter(this, void 0, void 0, function () {
|
|
3495
3494
|
var answer;
|
|
3496
3495
|
return __generator(this, function (_a) {
|
|
3497
|
-
answer = window.prompt(spaceTrim(function (block) { return "\n ".concat(block(options.promptTitle), "\n\n ").concat(block(options.promptMessage), "\n "); }));
|
|
3496
|
+
answer = window.prompt(spaceTrim$1(function (block) { return "\n ".concat(block(options.promptTitle), "\n\n ").concat(block(options.promptMessage), "\n "); }));
|
|
3498
3497
|
if (this.options.isVerbose) {
|
|
3499
|
-
console.info(spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer || '🚫 User cancelled prompt'), "\n "); }));
|
|
3498
|
+
console.info(spaceTrim$1(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer || '🚫 User cancelled prompt'), "\n "); }));
|
|
3500
3499
|
}
|
|
3501
3500
|
if (answer === null) {
|
|
3502
|
-
throw new
|
|
3501
|
+
throw new ExecutionError('User cancelled prompt');
|
|
3503
3502
|
}
|
|
3504
3503
|
return [2 /*return*/, answer];
|
|
3505
3504
|
});
|
|
@@ -3511,23 +3510,23 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
|
3511
3510
|
/**
|
|
3512
3511
|
* Constructs Promptbook from async sources
|
|
3513
3512
|
* It can be one of the following:
|
|
3514
|
-
* - Promise of array of
|
|
3515
|
-
* - Factory function that returns Promise of array of
|
|
3513
|
+
* - Promise of array of PipelineJson or PipelineString
|
|
3514
|
+
* - Factory function that returns Promise of array of PipelineJson or PipelineString
|
|
3516
3515
|
*
|
|
3517
3516
|
* Note: This is useful as internal tool for other constructor functions like
|
|
3518
|
-
* `
|
|
3517
|
+
* `createCollectionFromUrl` or `createCollectionFromDirectory`
|
|
3519
3518
|
* Consider using those functions instead of this one
|
|
3520
3519
|
*
|
|
3521
3520
|
* Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
|
|
3522
|
-
* when error occurs in given promise or factory function, it is thrown during `
|
|
3521
|
+
* when error occurs in given promise or factory function, it is thrown during `listPipelines` or `getPipelineByUrl` call
|
|
3523
3522
|
*
|
|
3524
|
-
* Note: Consider using `
|
|
3523
|
+
* Note: Consider using `createCollectionFromDirectory` or `createCollectionFromUrl`
|
|
3525
3524
|
*
|
|
3526
3525
|
* @param promptbookSourcesPromiseOrFactory
|
|
3527
|
-
* @returns
|
|
3526
|
+
* @returns PipelineCollection
|
|
3528
3527
|
* @deprecated Do not use, it will became internal tool for other constructor functions
|
|
3529
3528
|
*/
|
|
3530
|
-
function
|
|
3529
|
+
function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
3531
3530
|
var library;
|
|
3532
3531
|
function forSources() {
|
|
3533
3532
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3542,32 +3541,32 @@ function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3542
3541
|
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
3543
3542
|
case 1:
|
|
3544
3543
|
promptbookSources = _a.sent();
|
|
3545
|
-
library =
|
|
3544
|
+
library = createCollectionFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false));
|
|
3546
3545
|
return [2 /*return*/];
|
|
3547
3546
|
}
|
|
3548
3547
|
});
|
|
3549
3548
|
});
|
|
3550
3549
|
}
|
|
3551
|
-
function
|
|
3550
|
+
function listPipelines() {
|
|
3552
3551
|
return __awaiter(this, void 0, void 0, function () {
|
|
3553
3552
|
return __generator(this, function (_a) {
|
|
3554
3553
|
switch (_a.label) {
|
|
3555
3554
|
case 0: return [4 /*yield*/, forSources()];
|
|
3556
3555
|
case 1:
|
|
3557
3556
|
_a.sent();
|
|
3558
|
-
return [2 /*return*/, /* not await */ library.
|
|
3557
|
+
return [2 /*return*/, /* not await */ library.listPipelines()];
|
|
3559
3558
|
}
|
|
3560
3559
|
});
|
|
3561
3560
|
});
|
|
3562
3561
|
}
|
|
3563
|
-
function
|
|
3562
|
+
function getPipelineByUrl(url) {
|
|
3564
3563
|
return __awaiter(this, void 0, void 0, function () {
|
|
3565
3564
|
return __generator(this, function (_a) {
|
|
3566
3565
|
switch (_a.label) {
|
|
3567
3566
|
case 0: return [4 /*yield*/, forSources()];
|
|
3568
3567
|
case 1:
|
|
3569
3568
|
_a.sent();
|
|
3570
|
-
return [2 /*return*/, /* not await */ library.
|
|
3569
|
+
return [2 /*return*/, /* not await */ library.getPipelineByUrl(url)];
|
|
3571
3570
|
}
|
|
3572
3571
|
});
|
|
3573
3572
|
});
|
|
@@ -3585,8 +3584,8 @@ function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3585
3584
|
});
|
|
3586
3585
|
}
|
|
3587
3586
|
return {
|
|
3588
|
-
|
|
3589
|
-
|
|
3587
|
+
listPipelines: listPipelines,
|
|
3588
|
+
getPipelineByUrl: getPipelineByUrl,
|
|
3590
3589
|
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3591
3590
|
};
|
|
3592
3591
|
}
|
|
@@ -3594,9 +3593,9 @@ function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3594
3593
|
/**
|
|
3595
3594
|
* Constructs Promptbook from remote Promptbase URL
|
|
3596
3595
|
|
|
3597
|
-
* @returns
|
|
3596
|
+
* @returns PipelineCollection
|
|
3598
3597
|
*/
|
|
3599
|
-
function
|
|
3598
|
+
function createCollectionFromUrl(url, options) {
|
|
3600
3599
|
return __awaiter(this, void 0, void 0, function () {
|
|
3601
3600
|
var _a, _b, isVerbose, _c, isLazyLoaded, library;
|
|
3602
3601
|
var _this = this;
|
|
@@ -3604,7 +3603,7 @@ function createLibraryFromUrl(url, options) {
|
|
|
3604
3603
|
switch (_d.label) {
|
|
3605
3604
|
case 0:
|
|
3606
3605
|
_a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
|
|
3607
|
-
library =
|
|
3606
|
+
library = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3608
3607
|
return __generator(this, function (_a) {
|
|
3609
3608
|
if (isVerbose) {
|
|
3610
3609
|
console.info("Creating promptbook library from url ".concat(url.toString()));
|
|
@@ -3613,7 +3612,7 @@ function createLibraryFromUrl(url, options) {
|
|
|
3613
3612
|
});
|
|
3614
3613
|
}); });
|
|
3615
3614
|
if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
|
|
3616
|
-
return [4 /*yield*/, library.
|
|
3615
|
+
return [4 /*yield*/, library.listPipelines()];
|
|
3617
3616
|
case 1:
|
|
3618
3617
|
_d.sent();
|
|
3619
3618
|
_d.label = 2;
|
|
@@ -3627,21 +3626,21 @@ function createLibraryFromUrl(url, options) {
|
|
|
3627
3626
|
*/
|
|
3628
3627
|
|
|
3629
3628
|
/**
|
|
3630
|
-
* Creates
|
|
3629
|
+
* Creates PipelineCollection as a subset of another PipelineCollection
|
|
3631
3630
|
*
|
|
3632
3631
|
* Note: You can use any type of library as a parent library - local, remote, etc.
|
|
3633
3632
|
* Note: This is just a thin wrapper / proxy around the parent library
|
|
3634
3633
|
*
|
|
3635
3634
|
* @param promptbookSources
|
|
3636
|
-
* @returns
|
|
3635
|
+
* @returns PipelineCollection
|
|
3637
3636
|
*/
|
|
3638
|
-
function
|
|
3639
|
-
function
|
|
3637
|
+
function createSubcollection(library, predicate) {
|
|
3638
|
+
function listPipelines() {
|
|
3640
3639
|
return __awaiter(this, void 0, void 0, function () {
|
|
3641
3640
|
var promptbooks;
|
|
3642
3641
|
return __generator(this, function (_a) {
|
|
3643
3642
|
switch (_a.label) {
|
|
3644
|
-
case 0: return [4 /*yield*/, library.
|
|
3643
|
+
case 0: return [4 /*yield*/, library.listPipelines()];
|
|
3645
3644
|
case 1:
|
|
3646
3645
|
promptbooks = _a.sent();
|
|
3647
3646
|
promptbooks = promptbooks.filter(predicate);
|
|
@@ -3650,7 +3649,7 @@ function createSublibrary(library, predicate) {
|
|
|
3650
3649
|
});
|
|
3651
3650
|
});
|
|
3652
3651
|
}
|
|
3653
|
-
function
|
|
3652
|
+
function getPipelineByUrl(url) {
|
|
3654
3653
|
return __awaiter(this, void 0, void 0, function () {
|
|
3655
3654
|
var _a, promptbook;
|
|
3656
3655
|
var _this = this;
|
|
@@ -3658,25 +3657,25 @@ function createSublibrary(library, predicate) {
|
|
|
3658
3657
|
switch (_b.label) {
|
|
3659
3658
|
case 0:
|
|
3660
3659
|
if (!!predicate(url)) return [3 /*break*/, 2];
|
|
3661
|
-
_a =
|
|
3662
|
-
return [4 /*yield*/, spaceTrim(function (block) { return __awaiter(_this, void 0, void 0, function () {
|
|
3660
|
+
_a = NotFoundError.bind;
|
|
3661
|
+
return [4 /*yield*/, spaceTrim$1(function (block) { return __awaiter(_this, void 0, void 0, function () {
|
|
3663
3662
|
var _a, _b, _c, _d, _e, _f;
|
|
3664
3663
|
return __generator(this, function (_g) {
|
|
3665
3664
|
switch (_g.label) {
|
|
3666
3665
|
case 0:
|
|
3667
3666
|
_c = (_b = "\n Promptbook with url \"".concat(url, "\" not found or not accessible\n\n Available promptbooks:\n ")).concat;
|
|
3668
3667
|
_d = block;
|
|
3669
|
-
return [4 /*yield*/,
|
|
3668
|
+
return [4 /*yield*/, listPipelines()];
|
|
3670
3669
|
case 1:
|
|
3671
3670
|
_e = (_a = _c.apply(_b, [_d.apply(void 0, [(_g.sent()).map(function (promptbookUrl) { return "- ".concat(promptbookUrl); }).join('\n')]), "\n\n All available promptbooks in parent library:\n "])).concat;
|
|
3672
3671
|
_f = block;
|
|
3673
|
-
return [4 /*yield*/, library.
|
|
3672
|
+
return [4 /*yield*/, library.listPipelines()];
|
|
3674
3673
|
case 2: return [2 /*return*/, _e.apply(_a, [_f.apply(void 0, [(_g.sent()).map(function (promptbookUrl) { return "- ".concat(promptbookUrl); }).join('\n')]), "\n\n "])];
|
|
3675
3674
|
}
|
|
3676
3675
|
});
|
|
3677
3676
|
}); })];
|
|
3678
|
-
case 1: throw new (_a.apply(
|
|
3679
|
-
case 2: return [4 /*yield*/, library.
|
|
3677
|
+
case 1: throw new (_a.apply(NotFoundError, [void 0, _b.sent()]))();
|
|
3678
|
+
case 2: return [4 /*yield*/, library.getPipelineByUrl(url)];
|
|
3680
3679
|
case 3:
|
|
3681
3680
|
promptbook = _b.sent();
|
|
3682
3681
|
return [2 /*return*/, promptbook];
|
|
@@ -3699,26 +3698,26 @@ function createSublibrary(library, predicate) {
|
|
|
3699
3698
|
});
|
|
3700
3699
|
}
|
|
3701
3700
|
return {
|
|
3702
|
-
|
|
3703
|
-
|
|
3701
|
+
listPipelines: listPipelines,
|
|
3702
|
+
getPipelineByUrl: getPipelineByUrl,
|
|
3704
3703
|
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3705
3704
|
};
|
|
3706
3705
|
}
|
|
3707
3706
|
|
|
3708
3707
|
/**
|
|
3709
|
-
* Converts
|
|
3708
|
+
* Converts PipelineCollection to serialized JSON
|
|
3710
3709
|
*
|
|
3711
|
-
* Note: Functions `libraryToJson` and `
|
|
3710
|
+
* Note: Functions `libraryToJson` and `createCollectionFromJson` are complementary
|
|
3712
3711
|
*/
|
|
3713
3712
|
function libraryToJson(library) {
|
|
3714
3713
|
return __awaiter(this, void 0, void 0, function () {
|
|
3715
3714
|
var promptbookUrls, promptbooks;
|
|
3716
3715
|
return __generator(this, function (_a) {
|
|
3717
3716
|
switch (_a.label) {
|
|
3718
|
-
case 0: return [4 /*yield*/, library.
|
|
3717
|
+
case 0: return [4 /*yield*/, library.listPipelines()];
|
|
3719
3718
|
case 1:
|
|
3720
3719
|
promptbookUrls = _a.sent();
|
|
3721
|
-
return [4 /*yield*/, Promise.all(promptbookUrls.map(function (url) { return library.
|
|
3720
|
+
return [4 /*yield*/, Promise.all(promptbookUrls.map(function (url) { return library.getPipelineByUrl(url); }))];
|
|
3722
3721
|
case 2:
|
|
3723
3722
|
promptbooks = _a.sent();
|
|
3724
3723
|
return [2 /*return*/, promptbooks];
|
|
@@ -3746,19 +3745,19 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3746
3745
|
/**
|
|
3747
3746
|
* Calls the best available chat model
|
|
3748
3747
|
*/
|
|
3749
|
-
MultipleLlmExecutionTools.prototype.
|
|
3750
|
-
return this.
|
|
3748
|
+
MultipleLlmExecutionTools.prototype.callChatModel = function (prompt) {
|
|
3749
|
+
return this.callModelCommon(prompt);
|
|
3751
3750
|
};
|
|
3752
3751
|
/**
|
|
3753
3752
|
* Calls the best available completion model
|
|
3754
3753
|
*/
|
|
3755
|
-
MultipleLlmExecutionTools.prototype.
|
|
3756
|
-
return this.
|
|
3754
|
+
MultipleLlmExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
3755
|
+
return this.callModelCommon(prompt);
|
|
3757
3756
|
};
|
|
3758
3757
|
/**
|
|
3759
3758
|
* Calls the best available model
|
|
3760
3759
|
*/
|
|
3761
|
-
MultipleLlmExecutionTools.prototype.
|
|
3760
|
+
MultipleLlmExecutionTools.prototype.callModelCommon = function (prompt) {
|
|
3762
3761
|
return __awaiter(this, void 0, void 0, function () {
|
|
3763
3762
|
var errors, _a, _b, llmExecutionTools, error_1, e_1_1;
|
|
3764
3763
|
var e_1, _c;
|
|
@@ -3778,11 +3777,11 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3778
3777
|
case 3:
|
|
3779
3778
|
_d.trys.push([3, 8, , 9]);
|
|
3780
3779
|
if (!(prompt.modelRequirements.modelVariant === 'CHAT')) return [3 /*break*/, 5];
|
|
3781
|
-
return [4 /*yield*/, llmExecutionTools.
|
|
3780
|
+
return [4 /*yield*/, llmExecutionTools.callChatModel(prompt)];
|
|
3782
3781
|
case 4: return [2 /*return*/, _d.sent()];
|
|
3783
3782
|
case 5:
|
|
3784
3783
|
if (!(prompt.modelRequirements.modelVariant === 'COMPLETION')) return [3 /*break*/, 7];
|
|
3785
|
-
return [4 /*yield*/, llmExecutionTools.
|
|
3784
|
+
return [4 /*yield*/, llmExecutionTools.callCompletionModel(prompt)];
|
|
3786
3785
|
case 6: return [2 /*return*/, _d.sent()];
|
|
3787
3786
|
case 7: return [3 /*break*/, 9];
|
|
3788
3787
|
case 8:
|
|
@@ -3806,7 +3805,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3806
3805
|
}
|
|
3807
3806
|
finally { if (e_1) throw e_1.error; }
|
|
3808
3807
|
return [7 /*endfinally*/];
|
|
3809
|
-
case 13: throw new Error(spaceTrim
|
|
3808
|
+
case 13: throw new Error(spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n\n "); }));
|
|
3810
3809
|
}
|
|
3811
3810
|
});
|
|
3812
3811
|
});
|
|
@@ -3858,10 +3857,18 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3858
3857
|
return MultipleLlmExecutionTools;
|
|
3859
3858
|
}());
|
|
3860
3859
|
|
|
3860
|
+
/**
|
|
3861
|
+
* Default options for generating an execution report string
|
|
3862
|
+
*/
|
|
3863
|
+
var ExecutionReportStringOptionsDefaults = {
|
|
3864
|
+
taxRate: 0,
|
|
3865
|
+
chartsWidth: 36,
|
|
3866
|
+
};
|
|
3867
|
+
|
|
3861
3868
|
/**
|
|
3862
3869
|
* Format either small or big number
|
|
3863
3870
|
*
|
|
3864
|
-
* @private within the
|
|
3871
|
+
* @private within the package
|
|
3865
3872
|
*/
|
|
3866
3873
|
function formatNumber(value) {
|
|
3867
3874
|
if (value === 0) {
|
|
@@ -3881,7 +3888,7 @@ function formatNumber(value) {
|
|
|
3881
3888
|
/**
|
|
3882
3889
|
* Create a markdown table from a 2D array of strings
|
|
3883
3890
|
*
|
|
3884
|
-
* @private within the
|
|
3891
|
+
* @private within the package
|
|
3885
3892
|
*/
|
|
3886
3893
|
function createMarkdownTable(table) {
|
|
3887
3894
|
var columnWidths = table.reduce(function (widths, row) {
|
|
@@ -3909,7 +3916,7 @@ function createMarkdownTable(table) {
|
|
|
3909
3916
|
/**
|
|
3910
3917
|
* Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
|
|
3911
3918
|
*
|
|
3912
|
-
* @private within the
|
|
3919
|
+
* @private within the package
|
|
3913
3920
|
*/
|
|
3914
3921
|
function createMarkdownChart(options) {
|
|
3915
3922
|
var e_1, _a;
|
|
@@ -3950,14 +3957,6 @@ function escapeMarkdownBlock(value) {
|
|
|
3950
3957
|
return value.replace(/```/g, '\\`\\`\\`');
|
|
3951
3958
|
}
|
|
3952
3959
|
|
|
3953
|
-
/**
|
|
3954
|
-
* Default options for generating an execution report string
|
|
3955
|
-
*/
|
|
3956
|
-
var ExecutionReportStringOptionsDefaults = {
|
|
3957
|
-
taxRate: 0,
|
|
3958
|
-
chartsWidth: 36,
|
|
3959
|
-
};
|
|
3960
|
-
|
|
3961
3960
|
/**
|
|
3962
3961
|
* The thresholds for the relative time in the `moment` library.
|
|
3963
3962
|
*
|
|
@@ -3970,7 +3969,7 @@ var MOMENT_ARG_THRESHOLDS = {
|
|
|
3970
3969
|
/**
|
|
3971
3970
|
* Count the duration of working time
|
|
3972
3971
|
*
|
|
3973
|
-
* @private within the
|
|
3972
|
+
* @private within the package
|
|
3974
3973
|
*/
|
|
3975
3974
|
function countWorkingDuration(items) {
|
|
3976
3975
|
var e_1, _a;
|
|
@@ -4007,7 +4006,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
4007
4006
|
var e_1, _a;
|
|
4008
4007
|
var _b, _c, _d, _e, _f, _g;
|
|
4009
4008
|
var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
|
|
4010
|
-
var executionReportString = spaceTrim(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
4009
|
+
var executionReportString = spaceTrim$1(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
4011
4010
|
var headerList = [];
|
|
4012
4011
|
if (executionReportJson.promptbookUrl) {
|
|
4013
4012
|
headerList.push("PROMPTBOOK URL ".concat(executionReportJson.promptbookUrl));
|
|
@@ -4127,17 +4126,17 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
4127
4126
|
if (just(true)) {
|
|
4128
4127
|
executionReportString +=
|
|
4129
4128
|
'\n\n\n\n' +
|
|
4130
|
-
spaceTrim(function (block) { return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.prompt.content)), "\n ```\n\n "); });
|
|
4129
|
+
spaceTrim$1(function (block) { return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.prompt.content)), "\n ```\n\n "); });
|
|
4131
4130
|
}
|
|
4132
4131
|
if (promptExecution.result && promptExecution.result.content) {
|
|
4133
4132
|
executionReportString +=
|
|
4134
4133
|
'\n\n\n\n' +
|
|
4135
|
-
spaceTrim(function (block) { return "\n\n ### Result\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
|
|
4134
|
+
spaceTrim$1(function (block) { return "\n\n ### Result\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
|
|
4136
4135
|
}
|
|
4137
4136
|
if (promptExecution.error && promptExecution.error.message) {
|
|
4138
4137
|
executionReportString +=
|
|
4139
4138
|
'\n\n\n\n' +
|
|
4140
|
-
spaceTrim(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
|
|
4139
|
+
spaceTrim$1(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
|
|
4141
4140
|
}
|
|
4142
4141
|
};
|
|
4143
4142
|
try {
|
|
@@ -4161,5 +4160,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
4161
4160
|
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
4162
4161
|
*/
|
|
4163
4162
|
|
|
4164
|
-
export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, ExpectError, MultipleLlmExecutionTools,
|
|
4163
|
+
export { CallbackInterfaceTools, CollectionError, ExecutionError, ExecutionReportStringOptionsDefaults, ExecutionTypes, ExpectError, MultipleLlmExecutionTools, NotFoundError, PROMPTBOOK_VERSION, PipelineLogicError, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, SyntaxError, TemplateError, UnexpectedError, addUsage, assertsExecutionSuccessful, checkExpectations, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPromptbookExecutor, createSubcollection as createSublibrary, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, libraryToJson, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prettifyPipelineString, usageToWorktime, validatePipeline };
|
|
4165
4164
|
//# sourceMappingURL=index.es.js.map
|