@promptbook/core 0.61.0-1 → 0.61.0-11
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/esm/index.es.js +766 -346
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +196 -23
- package/esm/typings/src/_packages/core.index.d.ts +5 -1
- package/esm/typings/src/_packages/types.index.d.ts +6 -4
- package/esm/typings/src/_packages/utils.index.d.ts +4 -3
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
- package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +1 -1
- package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +15 -12
- package/esm/typings/src/config.d.ts +8 -0
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +9 -5
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +5 -3
- package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +2 -2
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +4 -0
- package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
- package/esm/typings/src/errors/VersionMismatchError.d.ts +8 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +3 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +8 -7
- package/esm/typings/src/execution/PromptResult.d.ts +17 -5
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +6 -4
- package/esm/typings/src/execution/UserInterfaceTools.d.ts +5 -5
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +4 -1
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +1 -1
- package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +8 -23
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +7 -14
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
- package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +3 -2
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/utils/cache/CacheItem.d.ts +29 -0
- package/esm/typings/src/llm-providers/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
- package/esm/typings/src/llm-providers/utils/cache/cacheLlmTools.d.ts +17 -0
- package/esm/typings/src/llm-providers/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
- package/esm/typings/src/llm-providers/utils/count-total-cost/countTotalCost.d.ts +14 -0
- package/esm/typings/src/llm-providers/utils/createLlmToolsFromEnv.d.ts +21 -0
- package/esm/typings/src/personas/preparePersona.d.ts +10 -0
- package/esm/typings/src/personas/preparePersona.test.d.ts +1 -0
- package/esm/typings/src/prepare/PrepareOptions.d.ts +22 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +16 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +8 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +24 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
- package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +28 -0
- package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +10 -0
- package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
- package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +8 -0
- package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +8 -0
- package/esm/typings/src/storage/memory/MemoryStorage.d.ts +31 -0
- package/esm/typings/src/storage/utils/PrefixStorage.d.ts +23 -0
- package/esm/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +12 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +22 -1
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +8 -1
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +40 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +27 -3
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +21 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +8 -1
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/Prompt.d.ts +5 -2
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
- package/esm/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
- package/esm/typings/src/types/typeAliases.d.ts +62 -14
- package/esm/typings/src/utils/FromtoItems.d.ts +3 -3
- package/esm/typings/src/utils/currentDate.d.ts +7 -0
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +2 -2
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +6 -9
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +9 -2
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
- package/esm/typings/src/utils/organization/TODO.d.ts +4 -0
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +11 -0
- package/esm/typings/src/utils/organization/___.d.ts +4 -0
- package/esm/typings/src/utils/organization/notUsing.d.ts +11 -0
- package/esm/typings/src/utils/organization/really_any.d.ts +4 -0
- package/esm/typings/src/utils/random/randomSeed.d.ts +7 -0
- package/package.json +1 -1
- package/umd/index.umd.js +768 -345
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +196 -23
- package/umd/typings/src/_packages/core.index.d.ts +5 -1
- package/umd/typings/src/_packages/types.index.d.ts +6 -4
- package/umd/typings/src/_packages/utils.index.d.ts +4 -3
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
- package/umd/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
- package/umd/typings/src/commands/MODEL/ModelCommand.d.ts +1 -1
- package/umd/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +15 -12
- package/umd/typings/src/config.d.ts +8 -0
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +9 -5
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +5 -3
- package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
- package/umd/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/umd/typings/src/conversion/validation/_importPipeline.d.ts +2 -2
- package/umd/typings/src/conversion/validation/validatePipeline.d.ts +4 -0
- package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
- package/umd/typings/src/errors/VersionMismatchError.d.ts +8 -0
- package/umd/typings/src/execution/LlmExecutionTools.d.ts +3 -1
- package/umd/typings/src/execution/PipelineExecutor.d.ts +8 -7
- package/umd/typings/src/execution/PromptResult.d.ts +17 -5
- package/umd/typings/src/execution/ScriptExecutionTools.d.ts +6 -4
- package/umd/typings/src/execution/UserInterfaceTools.d.ts +5 -5
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +4 -1
- package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
- package/umd/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -1
- package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -1
- package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +1 -1
- package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +8 -23
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +7 -14
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
- package/umd/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +3 -2
- package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/utils/cache/CacheItem.d.ts +29 -0
- package/umd/typings/src/llm-providers/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
- package/umd/typings/src/llm-providers/utils/cache/cacheLlmTools.d.ts +17 -0
- package/umd/typings/src/llm-providers/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
- package/umd/typings/src/llm-providers/utils/count-total-cost/countTotalCost.d.ts +14 -0
- package/umd/typings/src/llm-providers/utils/createLlmToolsFromEnv.d.ts +21 -0
- package/umd/typings/src/personas/preparePersona.d.ts +10 -0
- package/umd/typings/src/personas/preparePersona.test.d.ts +1 -0
- package/umd/typings/src/prepare/PrepareOptions.d.ts +22 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +16 -0
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +8 -0
- package/umd/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +24 -0
- package/umd/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
- package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +28 -0
- package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +10 -0
- package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
- package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +8 -0
- package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +8 -0
- package/umd/typings/src/storage/memory/MemoryStorage.d.ts +31 -0
- package/umd/typings/src/storage/utils/PrefixStorage.d.ts +23 -0
- package/umd/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +12 -0
- package/umd/typings/src/types/ModelRequirements.d.ts +22 -1
- package/umd/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
- package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
- package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +8 -1
- package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +40 -0
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +27 -3
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +21 -0
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +2 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +8 -1
- package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
- package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
- package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
- package/umd/typings/src/types/Prompt.d.ts +5 -2
- package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
- package/umd/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
- package/umd/typings/src/types/typeAliases.d.ts +62 -14
- package/umd/typings/src/utils/FromtoItems.d.ts +3 -3
- package/umd/typings/src/utils/currentDate.d.ts +7 -0
- package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +2 -2
- package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +6 -9
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +9 -2
- package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
- package/umd/typings/src/utils/organization/TODO.d.ts +4 -0
- package/umd/typings/src/utils/organization/TODO_USE.d.ts +11 -0
- package/umd/typings/src/utils/organization/___.d.ts +4 -0
- package/umd/typings/src/utils/organization/notUsing.d.ts +11 -0
- package/umd/typings/src/utils/organization/really_any.d.ts +4 -0
- package/umd/typings/src/utils/random/randomSeed.d.ts +7 -0
- package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
- package/esm/typings/src/personas/personaToModelRequirements.d.ts +0 -6
- package/esm/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
- package/esm/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
- package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
- package/umd/typings/src/personas/personaToModelRequirements.d.ts +0 -6
- package/umd/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
- package/umd/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
- /package/esm/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
- /package/esm/typings/src/utils/{just.d.ts → organization/just.d.ts} +0 -0
- /package/umd/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
- /package/umd/typings/src/utils/{just.d.ts → organization/just.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -394,6 +394,10 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
394
394
|
* The maximum number of iterations for a loops
|
|
395
395
|
*/
|
|
396
396
|
var LOOP_LIMIT = 1000;
|
|
397
|
+
/**
|
|
398
|
+
* The maximum number of (LLM) tasks running in parallel
|
|
399
|
+
*/
|
|
400
|
+
var MAX_PARALLEL_COUNT = 5;
|
|
397
401
|
/**
|
|
398
402
|
* The names of the parameters that are reserved for special purposes
|
|
399
403
|
*/
|
|
@@ -775,6 +779,10 @@ function validatePipeline(pipeline) {
|
|
|
775
779
|
* > * - ...
|
|
776
780
|
* > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
|
|
777
781
|
*/
|
|
782
|
+
/**
|
|
783
|
+
* TODO: [🧠] !!!!! Validate new things
|
|
784
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
785
|
+
*/
|
|
778
786
|
|
|
779
787
|
/**
|
|
780
788
|
* This error indicates that promptbook not found in the collection
|
|
@@ -1119,7 +1127,172 @@ var BlockTypes = [
|
|
|
1119
1127
|
// <- [🩻]
|
|
1120
1128
|
];
|
|
1121
1129
|
|
|
1122
|
-
|
|
1130
|
+
/**
|
|
1131
|
+
* Function `addUsage` will add multiple usages into one
|
|
1132
|
+
*
|
|
1133
|
+
* Note: If you provide 0 values, it returns void usage
|
|
1134
|
+
*/
|
|
1135
|
+
function addUsage() {
|
|
1136
|
+
var usageItems = [];
|
|
1137
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1138
|
+
usageItems[_i] = arguments[_i];
|
|
1139
|
+
}
|
|
1140
|
+
var initialStructure = {
|
|
1141
|
+
price: { value: 0 },
|
|
1142
|
+
input: {
|
|
1143
|
+
tokensCount: { value: 0 },
|
|
1144
|
+
charactersCount: { value: 0 },
|
|
1145
|
+
wordsCount: { value: 0 },
|
|
1146
|
+
sentencesCount: { value: 0 },
|
|
1147
|
+
linesCount: { value: 0 },
|
|
1148
|
+
paragraphsCount: { value: 0 },
|
|
1149
|
+
pagesCount: { value: 0 },
|
|
1150
|
+
},
|
|
1151
|
+
output: {
|
|
1152
|
+
tokensCount: { value: 0 },
|
|
1153
|
+
charactersCount: { value: 0 },
|
|
1154
|
+
wordsCount: { value: 0 },
|
|
1155
|
+
sentencesCount: { value: 0 },
|
|
1156
|
+
linesCount: { value: 0 },
|
|
1157
|
+
paragraphsCount: { value: 0 },
|
|
1158
|
+
pagesCount: { value: 0 },
|
|
1159
|
+
},
|
|
1160
|
+
};
|
|
1161
|
+
return usageItems.reduce(function (acc, item) {
|
|
1162
|
+
var e_1, _a, e_2, _b;
|
|
1163
|
+
var _c;
|
|
1164
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1165
|
+
try {
|
|
1166
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1167
|
+
var key = _e.value;
|
|
1168
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1169
|
+
//@ts-ignore
|
|
1170
|
+
if (item.input[key]) {
|
|
1171
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1172
|
+
//@ts-ignore
|
|
1173
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
1174
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1175
|
+
//@ts-ignore
|
|
1176
|
+
if (item.input[key].isUncertain) {
|
|
1177
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1178
|
+
//@ts-ignore
|
|
1179
|
+
acc.input[key].isUncertain = true;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1185
|
+
finally {
|
|
1186
|
+
try {
|
|
1187
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1188
|
+
}
|
|
1189
|
+
finally { if (e_1) throw e_1.error; }
|
|
1190
|
+
}
|
|
1191
|
+
try {
|
|
1192
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1193
|
+
var key = _g.value;
|
|
1194
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1195
|
+
//@ts-ignore
|
|
1196
|
+
if (item.output[key]) {
|
|
1197
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1198
|
+
//@ts-ignore
|
|
1199
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
1200
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1201
|
+
//@ts-ignore
|
|
1202
|
+
if (item.output[key].isUncertain) {
|
|
1203
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1204
|
+
//@ts-ignore
|
|
1205
|
+
acc.output[key].isUncertain = true;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1211
|
+
finally {
|
|
1212
|
+
try {
|
|
1213
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1214
|
+
}
|
|
1215
|
+
finally { if (e_2) throw e_2.error; }
|
|
1216
|
+
}
|
|
1217
|
+
return acc;
|
|
1218
|
+
}, initialStructure);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Async version of Array.forEach
|
|
1223
|
+
*
|
|
1224
|
+
* @param array - Array to iterate over
|
|
1225
|
+
* @param options - Options for the function
|
|
1226
|
+
* @param callbackfunction - Function to call for each item
|
|
1227
|
+
*/
|
|
1228
|
+
function forEachAsync(array, options, callbackfunction) {
|
|
1229
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1230
|
+
var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
|
|
1231
|
+
var e_1, _d;
|
|
1232
|
+
return __generator(this, function (_e) {
|
|
1233
|
+
switch (_e.label) {
|
|
1234
|
+
case 0:
|
|
1235
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
1236
|
+
index = 0;
|
|
1237
|
+
runningTasks = [];
|
|
1238
|
+
tasks = [];
|
|
1239
|
+
_loop_1 = function (item) {
|
|
1240
|
+
var currentIndex, task;
|
|
1241
|
+
return __generator(this, function (_f) {
|
|
1242
|
+
switch (_f.label) {
|
|
1243
|
+
case 0:
|
|
1244
|
+
currentIndex = index++;
|
|
1245
|
+
task = callbackfunction(item, currentIndex, array);
|
|
1246
|
+
tasks.push(task);
|
|
1247
|
+
runningTasks.push(task);
|
|
1248
|
+
/* not await */ Promise.resolve(task).then(function () {
|
|
1249
|
+
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
1250
|
+
});
|
|
1251
|
+
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
1252
|
+
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
1253
|
+
case 1:
|
|
1254
|
+
_f.sent();
|
|
1255
|
+
_f.label = 2;
|
|
1256
|
+
case 2: return [2 /*return*/];
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
};
|
|
1260
|
+
_e.label = 1;
|
|
1261
|
+
case 1:
|
|
1262
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
1263
|
+
_b = __values(array), _c = _b.next();
|
|
1264
|
+
_e.label = 2;
|
|
1265
|
+
case 2:
|
|
1266
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
1267
|
+
item = _c.value;
|
|
1268
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
1269
|
+
case 3:
|
|
1270
|
+
_e.sent();
|
|
1271
|
+
_e.label = 4;
|
|
1272
|
+
case 4:
|
|
1273
|
+
_c = _b.next();
|
|
1274
|
+
return [3 /*break*/, 2];
|
|
1275
|
+
case 5: return [3 /*break*/, 8];
|
|
1276
|
+
case 6:
|
|
1277
|
+
e_1_1 = _e.sent();
|
|
1278
|
+
e_1 = { error: e_1_1 };
|
|
1279
|
+
return [3 /*break*/, 8];
|
|
1280
|
+
case 7:
|
|
1281
|
+
try {
|
|
1282
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
1283
|
+
}
|
|
1284
|
+
finally { if (e_1) throw e_1.error; }
|
|
1285
|
+
return [7 /*endfinally*/];
|
|
1286
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
1287
|
+
case 9:
|
|
1288
|
+
_e.sent();
|
|
1289
|
+
return [2 /*return*/];
|
|
1290
|
+
}
|
|
1291
|
+
});
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-10",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"],blockType:"PROMPT_TEMPLATE",personaName:null,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"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-10",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-10",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"],blockType:"PROMPT_TEMPLATE",personaName:null,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"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-10",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-10",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",expectations:{words:{min:1,max:8}},personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {content}",resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-10",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-10",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{name:"make-model-requirements",title:"Make modelRequirements",dependentParameterNames:["availableModelNames","personaDescription"],blockType:"PROMPT_TEMPLATE",expectFormat:"JSON",personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-10",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1123
1296
|
|
|
1124
1297
|
var defaultDiacriticsRemovalMap = [
|
|
1125
1298
|
{
|
|
@@ -1446,6 +1619,14 @@ function removeEmojis(text) {
|
|
|
1446
1619
|
* Function normalizes title to name which can be used as identifier
|
|
1447
1620
|
*/
|
|
1448
1621
|
function titleToName(value) {
|
|
1622
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
1623
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1624
|
+
return value;
|
|
1625
|
+
}
|
|
1626
|
+
if (value.startsWith('./') || value.startsWith('../')) {
|
|
1627
|
+
// TODO: Maybe check against some list unallowed characters
|
|
1628
|
+
return value;
|
|
1629
|
+
}
|
|
1449
1630
|
value = removeEmojis(value);
|
|
1450
1631
|
value = normalizeToKebabCase(value);
|
|
1451
1632
|
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
@@ -1667,7 +1848,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1667
1848
|
};
|
|
1668
1849
|
/**
|
|
1669
1850
|
* List all available models that can be used
|
|
1670
|
-
* This
|
|
1851
|
+
* This lists is a combination of all available models from all execution tools
|
|
1671
1852
|
*/
|
|
1672
1853
|
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
1673
1854
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1713,6 +1894,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1713
1894
|
}());
|
|
1714
1895
|
/**
|
|
1715
1896
|
* TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
|
|
1897
|
+
* TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
|
|
1898
|
+
* Look how `countTotalUsage` (and `cacheLlmTools`) implements it
|
|
1716
1899
|
*/
|
|
1717
1900
|
|
|
1718
1901
|
/**
|
|
@@ -1783,100 +1966,9 @@ function arrayableToArray(input) {
|
|
|
1783
1966
|
/**
|
|
1784
1967
|
* The version of the Promptbook library
|
|
1785
1968
|
*/
|
|
1786
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
1969
|
+
var PROMPTBOOK_VERSION = '0.61.0-10';
|
|
1787
1970
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
1788
1971
|
|
|
1789
|
-
/**
|
|
1790
|
-
* Function `addUsage` will add multiple usages into one
|
|
1791
|
-
*
|
|
1792
|
-
* Note: If you provide 0 values, it returns void usage
|
|
1793
|
-
*/
|
|
1794
|
-
function addUsage() {
|
|
1795
|
-
var usageItems = [];
|
|
1796
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1797
|
-
usageItems[_i] = arguments[_i];
|
|
1798
|
-
}
|
|
1799
|
-
var initialStructure = {
|
|
1800
|
-
price: { value: 0 },
|
|
1801
|
-
input: {
|
|
1802
|
-
tokensCount: { value: 0 },
|
|
1803
|
-
charactersCount: { value: 0 },
|
|
1804
|
-
wordsCount: { value: 0 },
|
|
1805
|
-
sentencesCount: { value: 0 },
|
|
1806
|
-
linesCount: { value: 0 },
|
|
1807
|
-
paragraphsCount: { value: 0 },
|
|
1808
|
-
pagesCount: { value: 0 },
|
|
1809
|
-
},
|
|
1810
|
-
output: {
|
|
1811
|
-
tokensCount: { value: 0 },
|
|
1812
|
-
charactersCount: { value: 0 },
|
|
1813
|
-
wordsCount: { value: 0 },
|
|
1814
|
-
sentencesCount: { value: 0 },
|
|
1815
|
-
linesCount: { value: 0 },
|
|
1816
|
-
paragraphsCount: { value: 0 },
|
|
1817
|
-
pagesCount: { value: 0 },
|
|
1818
|
-
},
|
|
1819
|
-
};
|
|
1820
|
-
return usageItems.reduce(function (acc, item) {
|
|
1821
|
-
var e_1, _a, e_2, _b;
|
|
1822
|
-
var _c;
|
|
1823
|
-
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
1824
|
-
try {
|
|
1825
|
-
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1826
|
-
var key = _e.value;
|
|
1827
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1828
|
-
//@ts-ignore
|
|
1829
|
-
if (item.input[key]) {
|
|
1830
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1831
|
-
//@ts-ignore
|
|
1832
|
-
acc.input[key].value += item.input[key].value || 0;
|
|
1833
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1834
|
-
//@ts-ignore
|
|
1835
|
-
if (item.input[key].isUncertain) {
|
|
1836
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1837
|
-
//@ts-ignore
|
|
1838
|
-
acc.input[key].isUncertain = true;
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1844
|
-
finally {
|
|
1845
|
-
try {
|
|
1846
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1847
|
-
}
|
|
1848
|
-
finally { if (e_1) throw e_1.error; }
|
|
1849
|
-
}
|
|
1850
|
-
try {
|
|
1851
|
-
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1852
|
-
var key = _g.value;
|
|
1853
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1854
|
-
//@ts-ignore
|
|
1855
|
-
if (item.output[key]) {
|
|
1856
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1857
|
-
//@ts-ignore
|
|
1858
|
-
acc.output[key].value += item.output[key].value || 0;
|
|
1859
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1860
|
-
//@ts-ignore
|
|
1861
|
-
if (item.output[key].isUncertain) {
|
|
1862
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1863
|
-
//@ts-ignore
|
|
1864
|
-
acc.output[key].isUncertain = true;
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1870
|
-
finally {
|
|
1871
|
-
try {
|
|
1872
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1873
|
-
}
|
|
1874
|
-
finally { if (e_2) throw e_2.error; }
|
|
1875
|
-
}
|
|
1876
|
-
return acc;
|
|
1877
|
-
}, initialStructure);
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
1972
|
/**
|
|
1881
1973
|
* Counts number of characters in the text
|
|
1882
1974
|
*/
|
|
@@ -2078,10 +2170,7 @@ function createPipelineExecutor(options) {
|
|
|
2078
2170
|
var _this = this;
|
|
2079
2171
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2080
2172
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
2081
|
-
// TODO: !!!!! Implement new commands
|
|
2082
2173
|
validatePipeline(pipeline);
|
|
2083
|
-
// TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
|
|
2084
|
-
// TODO: !!!!! Do here personaToModelRequirements
|
|
2085
2174
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2086
2175
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2087
2176
|
function executeSingleTemplate(currentTemplate) {
|
|
@@ -2156,7 +2245,10 @@ function createPipelineExecutor(options) {
|
|
|
2156
2245
|
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
2157
2246
|
parameters: parametersToPass,
|
|
2158
2247
|
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
2248
|
+
// <- TODO: !!!!! Apply {context} and knowledges
|
|
2249
|
+
// <- TODO: !!!!! Apply samples
|
|
2159
2250
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2251
|
+
// <- TODO: !!!!! Apply persona
|
|
2160
2252
|
expectations: currentTemplate.expectations,
|
|
2161
2253
|
expectFormat: currentTemplate.expectFormat,
|
|
2162
2254
|
postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -2602,53 +2694,75 @@ function createPipelineExecutor(options) {
|
|
|
2602
2694
|
return pipelineExecutor;
|
|
2603
2695
|
}
|
|
2604
2696
|
/**
|
|
2697
|
+
* TODO: [🪂] Pass maxParallelCount here
|
|
2698
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
2605
2699
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2606
2700
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2607
2701
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2608
2702
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2703
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2704
|
+
*/
|
|
2705
|
+
|
|
2706
|
+
/**
|
|
2707
|
+
* Just marks a place of place where should be something implemented
|
|
2708
|
+
* No side effects.
|
|
2709
|
+
*
|
|
2710
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2711
|
+
*
|
|
2712
|
+
* @param value any values
|
|
2713
|
+
* @returns void
|
|
2609
2714
|
*/
|
|
2715
|
+
function TODO_USE() {
|
|
2716
|
+
var value = [];
|
|
2717
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2718
|
+
value[_i] = arguments[_i];
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2610
2721
|
|
|
2611
|
-
|
|
2722
|
+
/**
|
|
2723
|
+
* @@@
|
|
2724
|
+
*/
|
|
2725
|
+
function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
2612
2726
|
return __awaiter(this, void 0, void 0, function () {
|
|
2613
|
-
var
|
|
2614
|
-
var
|
|
2727
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
2728
|
+
var _f, _g, _h;
|
|
2615
2729
|
var _this = this;
|
|
2616
|
-
return __generator(this, function (
|
|
2617
|
-
switch (
|
|
2730
|
+
return __generator(this, function (_j) {
|
|
2731
|
+
switch (_j.label) {
|
|
2618
2732
|
case 0:
|
|
2619
|
-
|
|
2733
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
2734
|
+
TODO_USE(maxParallelCount); // <- [🪂]
|
|
2620
2735
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2621
|
-
_b = createPipelineExecutor;
|
|
2622
|
-
_e = {};
|
|
2623
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2624
|
-
case 1:
|
|
2625
|
-
prepareKnowledgeFromMarkdownExecutor = _b.apply(void 0, [(_e.pipeline = _h.sent(),
|
|
2626
|
-
_e.tools = {
|
|
2627
|
-
llm: llmTools,
|
|
2628
|
-
},
|
|
2629
|
-
_e)]);
|
|
2630
2736
|
_c = createPipelineExecutor;
|
|
2631
2737
|
_f = {};
|
|
2632
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2633
|
-
case
|
|
2634
|
-
|
|
2738
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2739
|
+
case 1:
|
|
2740
|
+
prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
|
|
2635
2741
|
_f.tools = {
|
|
2636
2742
|
llm: llmTools,
|
|
2637
2743
|
},
|
|
2638
2744
|
_f)]);
|
|
2639
2745
|
_d = createPipelineExecutor;
|
|
2640
2746
|
_g = {};
|
|
2641
|
-
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-
|
|
2642
|
-
case
|
|
2643
|
-
|
|
2747
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
|
|
2748
|
+
case 2:
|
|
2749
|
+
prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
|
|
2644
2750
|
_g.tools = {
|
|
2645
2751
|
llm: llmTools,
|
|
2646
2752
|
},
|
|
2647
2753
|
_g)]);
|
|
2754
|
+
_e = createPipelineExecutor;
|
|
2755
|
+
_h = {};
|
|
2756
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
|
|
2757
|
+
case 3:
|
|
2758
|
+
prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
|
|
2759
|
+
_h.tools = {
|
|
2760
|
+
llm: llmTools,
|
|
2761
|
+
},
|
|
2762
|
+
_h)]);
|
|
2648
2763
|
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
|
|
2649
2764
|
case 4:
|
|
2650
|
-
result =
|
|
2651
|
-
// TODO: [0] !!! Aggeregate usage
|
|
2765
|
+
result = _j.sent();
|
|
2652
2766
|
assertsExecutionSuccessful(result);
|
|
2653
2767
|
outputParameters = result.outputParameters;
|
|
2654
2768
|
knowledgeRaw = outputParameters.knowledge;
|
|
@@ -2657,9 +2771,9 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2657
2771
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
2658
2772
|
}
|
|
2659
2773
|
return [4 /*yield*/, Promise.all(
|
|
2660
|
-
// TODO:
|
|
2774
|
+
// TODO: [🪂] !! Do not send all at once but in chunks
|
|
2661
2775
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2662
|
-
var name, title, content, keywords, index,
|
|
2776
|
+
var name, title, content, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
2663
2777
|
return __generator(this, function (_c) {
|
|
2664
2778
|
switch (_c.label) {
|
|
2665
2779
|
case 0:
|
|
@@ -2668,12 +2782,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2668
2782
|
content = spaceTrim(knowledgeTextPiece);
|
|
2669
2783
|
keywords = [];
|
|
2670
2784
|
index = [];
|
|
2671
|
-
sources = [
|
|
2672
|
-
{
|
|
2673
|
-
title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
|
|
2674
|
-
href: '#' /* <- TODO: !!! Unhardcode */,
|
|
2675
|
-
},
|
|
2676
|
-
];
|
|
2677
2785
|
_c.label = 1;
|
|
2678
2786
|
case 1:
|
|
2679
2787
|
_c.trys.push([1, 7, , 8]);
|
|
@@ -2708,7 +2816,6 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2708
2816
|
})];
|
|
2709
2817
|
case 5:
|
|
2710
2818
|
embeddingResult = _c.sent();
|
|
2711
|
-
// TODO: [0] !!! Aggeregate usage embeddingResult.usage
|
|
2712
2819
|
index.push({
|
|
2713
2820
|
modelName: embeddingResult.modelName,
|
|
2714
2821
|
position: embeddingResult.content,
|
|
@@ -2726,21 +2833,388 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2726
2833
|
content: content,
|
|
2727
2834
|
keywords: keywords,
|
|
2728
2835
|
index: index,
|
|
2729
|
-
|
|
2836
|
+
// <- TODO: [☀] sources,
|
|
2730
2837
|
}];
|
|
2731
2838
|
}
|
|
2732
2839
|
});
|
|
2733
2840
|
}); }))];
|
|
2734
2841
|
case 5:
|
|
2735
|
-
knowledge =
|
|
2842
|
+
knowledge = _j.sent();
|
|
2736
2843
|
return [2 /*return*/, knowledge];
|
|
2737
2844
|
}
|
|
2738
2845
|
});
|
|
2739
2846
|
});
|
|
2740
2847
|
}
|
|
2741
2848
|
/**
|
|
2742
|
-
* 11:11
|
|
2849
|
+
* TODO: [🪂] Do it in parallel 11:11
|
|
2850
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2851
|
+
*/
|
|
2852
|
+
|
|
2853
|
+
/**
|
|
2854
|
+
* Prepares the knowle
|
|
2855
|
+
*
|
|
2856
|
+
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
2857
|
+
* @private within the package
|
|
2858
|
+
*/
|
|
2859
|
+
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
2860
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2861
|
+
var _a, maxParallelCount, knowledgePrepared;
|
|
2862
|
+
var _this = this;
|
|
2863
|
+
return __generator(this, function (_b) {
|
|
2864
|
+
switch (_b.label) {
|
|
2865
|
+
case 0:
|
|
2866
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2867
|
+
knowledgePrepared = [];
|
|
2868
|
+
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
|
|
2869
|
+
var partialPieces, pieces;
|
|
2870
|
+
return __generator(this, function (_a) {
|
|
2871
|
+
switch (_a.label) {
|
|
2872
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
|
|
2873
|
+
options)];
|
|
2874
|
+
case 1:
|
|
2875
|
+
partialPieces = _a.sent();
|
|
2876
|
+
pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
|
|
2877
|
+
{
|
|
2878
|
+
name: knowledgeSource.name,
|
|
2879
|
+
// line, column <- TODO: [☀]
|
|
2880
|
+
// <- TODO: [❎]
|
|
2881
|
+
},
|
|
2882
|
+
] })); });
|
|
2883
|
+
knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
|
|
2884
|
+
return [2 /*return*/];
|
|
2885
|
+
}
|
|
2886
|
+
});
|
|
2887
|
+
}); })];
|
|
2888
|
+
case 1:
|
|
2889
|
+
_b.sent();
|
|
2890
|
+
return [2 /*return*/, knowledgePrepared];
|
|
2891
|
+
}
|
|
2892
|
+
});
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2895
|
+
/*
|
|
2896
|
+
TODO: [🧊] This is how it can look in future
|
|
2897
|
+
> type PrepareKnowledgeKnowledge = {
|
|
2898
|
+
> /**
|
|
2899
|
+
> * Unprepared knowledge
|
|
2900
|
+
> * /
|
|
2901
|
+
> readonly knowledgeSources: Array<KnowledgeSourceJson>;
|
|
2902
|
+
> };
|
|
2903
|
+
>
|
|
2904
|
+
> export async function prepareKnowledgePieces(
|
|
2905
|
+
> knowledge: PrepareKnowledgeKnowledge,
|
|
2906
|
+
> options: PrepareOptions,
|
|
2907
|
+
> ):
|
|
2908
|
+
*/
|
|
2909
|
+
/**
|
|
2910
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2911
|
+
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2912
|
+
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
2913
|
+
* TODO: [🧠][❎] Do here propper M:N mapping
|
|
2914
|
+
* [x] One source can make multiple pieces
|
|
2915
|
+
* [ ] One piece can have multiple sources
|
|
2916
|
+
*/
|
|
2917
|
+
|
|
2918
|
+
/**
|
|
2919
|
+
* Prepares the persona for the pipeline
|
|
2920
|
+
*
|
|
2921
|
+
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
2922
|
+
* @private within the package
|
|
2923
|
+
*/
|
|
2924
|
+
function preparePersona(personaDescription, options) {
|
|
2925
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2926
|
+
var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
2927
|
+
var _c;
|
|
2928
|
+
return __generator(this, function (_d) {
|
|
2929
|
+
switch (_d.label) {
|
|
2930
|
+
case 0:
|
|
2931
|
+
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
2932
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2933
|
+
_b = createPipelineExecutor;
|
|
2934
|
+
_c = {};
|
|
2935
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
|
|
2936
|
+
case 1:
|
|
2937
|
+
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
2938
|
+
_c.tools = {
|
|
2939
|
+
llm: llmTools,
|
|
2940
|
+
},
|
|
2941
|
+
_c)]);
|
|
2942
|
+
return [4 /*yield*/, llmTools.listModels()];
|
|
2943
|
+
case 2:
|
|
2944
|
+
availableModels = _d.sent();
|
|
2945
|
+
availableModelNames = availableModels
|
|
2946
|
+
.filter(function (_a) {
|
|
2947
|
+
var modelVariant = _a.modelVariant;
|
|
2948
|
+
return modelVariant === 'CHAT';
|
|
2949
|
+
})
|
|
2950
|
+
.map(function (_a) {
|
|
2951
|
+
var modelName = _a.modelName;
|
|
2952
|
+
return modelName;
|
|
2953
|
+
})
|
|
2954
|
+
.join(',');
|
|
2955
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
2956
|
+
case 3:
|
|
2957
|
+
result = _d.sent();
|
|
2958
|
+
assertsExecutionSuccessful(result);
|
|
2959
|
+
outputParameters = result.outputParameters;
|
|
2960
|
+
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
2961
|
+
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
2962
|
+
if (isVerbose) {
|
|
2963
|
+
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
2964
|
+
}
|
|
2965
|
+
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
2966
|
+
// TODO: !!! Check validity of `modelName`
|
|
2967
|
+
// TODO: !!! Check validity of `systemMessage`
|
|
2968
|
+
// TODO: !!! Check validity of `temperature`
|
|
2969
|
+
return [2 /*return*/, {
|
|
2970
|
+
modelVariant: 'CHAT',
|
|
2971
|
+
modelName: modelName,
|
|
2972
|
+
systemMessage: systemMessage,
|
|
2973
|
+
temperature: temperature,
|
|
2974
|
+
}];
|
|
2975
|
+
}
|
|
2976
|
+
});
|
|
2977
|
+
});
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
/**
|
|
2981
|
+
* Prepare pipeline from string (markdown) format to JSON format
|
|
2982
|
+
*
|
|
2983
|
+
* Note: This function does not validate logic of the pipeline
|
|
2984
|
+
* Note: This function acts as part of compilation process
|
|
2985
|
+
*/
|
|
2986
|
+
function preparePipeline(pipeline, options) {
|
|
2987
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2988
|
+
var _a, maxParallelCount,
|
|
2989
|
+
/*
|
|
2990
|
+
<- TODO: [🧠][0] `promptbookVersion` */
|
|
2991
|
+
knowledgeSources /*
|
|
2992
|
+
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
2993
|
+
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
|
|
2994
|
+
var _this = this;
|
|
2995
|
+
return __generator(this, function (_b) {
|
|
2996
|
+
switch (_b.label) {
|
|
2997
|
+
case 0:
|
|
2998
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
2999
|
+
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3000
|
+
currentPreparation = {
|
|
3001
|
+
id: 1,
|
|
3002
|
+
// TODO: [🍥]> date: $currentDate(),
|
|
3003
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
3004
|
+
modelUsage: addUsage(),
|
|
3005
|
+
};
|
|
3006
|
+
preparations = [
|
|
3007
|
+
// ...preparations
|
|
3008
|
+
// <- TODO: [🧊]
|
|
3009
|
+
currentPreparation,
|
|
3010
|
+
];
|
|
3011
|
+
preparedPersonas = new Array(personas.length);
|
|
3012
|
+
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3013
|
+
var modelRequirements, preparedPersona;
|
|
3014
|
+
return __generator(this, function (_a) {
|
|
3015
|
+
switch (_a.label) {
|
|
3016
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
|
|
3017
|
+
case 1:
|
|
3018
|
+
modelRequirements = _a.sent();
|
|
3019
|
+
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
3020
|
+
preparedPersonas[index] = preparedPersona;
|
|
3021
|
+
return [2 /*return*/];
|
|
3022
|
+
}
|
|
3023
|
+
});
|
|
3024
|
+
}); })];
|
|
3025
|
+
case 1:
|
|
3026
|
+
_b.sent();
|
|
3027
|
+
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3028
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
|
|
3029
|
+
case 2:
|
|
3030
|
+
partialknowledgePiecesPrepared = _b.sent();
|
|
3031
|
+
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3032
|
+
// ----- /Knowledge preparation -----
|
|
3033
|
+
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3034
|
+
}
|
|
3035
|
+
});
|
|
3036
|
+
});
|
|
3037
|
+
}
|
|
3038
|
+
/**
|
|
3039
|
+
* TODO: Write tests for `preparePipeline`
|
|
3040
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3041
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3042
|
+
* TODO: !!!!! Use here countTotalUsage
|
|
3043
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3044
|
+
*/
|
|
3045
|
+
|
|
3046
|
+
/**
|
|
3047
|
+
* Tests if given string is valid URL.
|
|
3048
|
+
*
|
|
3049
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
3050
|
+
*/
|
|
3051
|
+
function isValidFilePath(filePath) {
|
|
3052
|
+
if (typeof filePath !== 'string') {
|
|
3053
|
+
return false;
|
|
3054
|
+
}
|
|
3055
|
+
var filePathSlashes = filePath.split('\\').join('/');
|
|
3056
|
+
// Absolute Unix path: /hello.txt
|
|
3057
|
+
if (/^(\/)/i.test(filePathSlashes)) {
|
|
3058
|
+
return true;
|
|
3059
|
+
}
|
|
3060
|
+
// Absolute Windows path: /hello.txt
|
|
3061
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
3062
|
+
return true;
|
|
3063
|
+
}
|
|
3064
|
+
// Relative path: ./hello.txt
|
|
3065
|
+
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
3066
|
+
return true;
|
|
3067
|
+
}
|
|
3068
|
+
return false;
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
/**
|
|
3072
|
+
* Parses the knowledge command
|
|
3073
|
+
*
|
|
3074
|
+
* @see ./KNOWLEDGE-README.md for more details
|
|
3075
|
+
* @private within the commands folder
|
|
2743
3076
|
*/
|
|
3077
|
+
var knowledgeCommandParser = {
|
|
3078
|
+
/**
|
|
3079
|
+
* Name of the command
|
|
3080
|
+
*/
|
|
3081
|
+
name: 'KNOWLEDGE',
|
|
3082
|
+
/**
|
|
3083
|
+
* BOILERPLATE command can be used in:
|
|
3084
|
+
*/
|
|
3085
|
+
usagePlaces: ['PIPELINE_HEAD'],
|
|
3086
|
+
/**
|
|
3087
|
+
* Description of the KNOWLEDGE command
|
|
3088
|
+
*/
|
|
3089
|
+
description: "Tells promptbook which external knowledge to use",
|
|
3090
|
+
/**
|
|
3091
|
+
* Link to discussion
|
|
3092
|
+
*/
|
|
3093
|
+
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3094
|
+
/**
|
|
3095
|
+
* Example usages of the KNOWLEDGE command
|
|
3096
|
+
*/
|
|
3097
|
+
examples: [
|
|
3098
|
+
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
3099
|
+
'KNOWLEDGE ./hejny-cv.txt',
|
|
3100
|
+
'KNOWLEDGE ./hejny-cv.md',
|
|
3101
|
+
'KNOWLEDGE ./hejny-cv.pdf',
|
|
3102
|
+
'KNOWLEDGE ./hejny-cv.docx',
|
|
3103
|
+
],
|
|
3104
|
+
/**
|
|
3105
|
+
* Parses the KNOWLEDGE command
|
|
3106
|
+
*/
|
|
3107
|
+
parse: function (input) {
|
|
3108
|
+
var args = input.args;
|
|
3109
|
+
var source = args[0];
|
|
3110
|
+
if (source === undefined) {
|
|
3111
|
+
throw new ParsingError("Source is not defined");
|
|
3112
|
+
}
|
|
3113
|
+
if (source.startsWith('http://')) {
|
|
3114
|
+
throw new ParsingError("Source is not secure");
|
|
3115
|
+
}
|
|
3116
|
+
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
3117
|
+
throw new ParsingError("Source not valid");
|
|
3118
|
+
}
|
|
3119
|
+
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
3120
|
+
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
3121
|
+
}
|
|
3122
|
+
return {
|
|
3123
|
+
type: 'KNOWLEDGE',
|
|
3124
|
+
source: source,
|
|
3125
|
+
};
|
|
3126
|
+
},
|
|
3127
|
+
/**
|
|
3128
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3129
|
+
*/
|
|
3130
|
+
applyToPipelineJson: function (pipelineJson, personaCommand) {
|
|
3131
|
+
var source = personaCommand.source;
|
|
3132
|
+
var name = titleToName(source);
|
|
3133
|
+
pipelineJson.knowledgeSources.push({
|
|
3134
|
+
name: name,
|
|
3135
|
+
source: source,
|
|
3136
|
+
});
|
|
3137
|
+
},
|
|
3138
|
+
};
|
|
3139
|
+
|
|
3140
|
+
/**
|
|
3141
|
+
* Parses the persona command
|
|
3142
|
+
*
|
|
3143
|
+
* @see ./PERSONA-README.md for more details
|
|
3144
|
+
* @private within the commands folder
|
|
3145
|
+
*/
|
|
3146
|
+
var personaCommandParser = {
|
|
3147
|
+
/**
|
|
3148
|
+
* Name of the command
|
|
3149
|
+
*/
|
|
3150
|
+
name: 'PERSONA',
|
|
3151
|
+
/**
|
|
3152
|
+
* Aliases for the PERSONA command
|
|
3153
|
+
*/
|
|
3154
|
+
aliasNames: ['PERSON'],
|
|
3155
|
+
/**
|
|
3156
|
+
* PERSONA command can be used in:
|
|
3157
|
+
*/
|
|
3158
|
+
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3159
|
+
/**
|
|
3160
|
+
* Description of the PERSONA command
|
|
3161
|
+
*/
|
|
3162
|
+
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
3163
|
+
/**
|
|
3164
|
+
* Link to discussion
|
|
3165
|
+
*/
|
|
3166
|
+
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3167
|
+
/**
|
|
3168
|
+
* Example usages of the PERSONA command
|
|
3169
|
+
*/
|
|
3170
|
+
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
3171
|
+
/**
|
|
3172
|
+
* Parses the PERSONA command
|
|
3173
|
+
*/
|
|
3174
|
+
parse: function (input) {
|
|
3175
|
+
var rawArgs = input.rawArgs;
|
|
3176
|
+
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
3177
|
+
var personaName = (personaNameRaw || '').trim();
|
|
3178
|
+
if (personaName === '') {
|
|
3179
|
+
throw new ParsingError("You must set name for the persona");
|
|
3180
|
+
}
|
|
3181
|
+
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
3182
|
+
if (personaDescription === '') {
|
|
3183
|
+
personaDescription = null;
|
|
3184
|
+
}
|
|
3185
|
+
return {
|
|
3186
|
+
type: 'PERSONA',
|
|
3187
|
+
personaName: personaName,
|
|
3188
|
+
personaDescription: personaDescription,
|
|
3189
|
+
};
|
|
3190
|
+
},
|
|
3191
|
+
/**
|
|
3192
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3193
|
+
*/
|
|
3194
|
+
applyToPipelineJson: function (pipelineJson, personaCommand) {
|
|
3195
|
+
var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
|
|
3196
|
+
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
3197
|
+
if (persona === undefined) {
|
|
3198
|
+
pipelineJson.personas.push({
|
|
3199
|
+
name: personaName,
|
|
3200
|
+
description: personaDescription || '',
|
|
3201
|
+
});
|
|
3202
|
+
return;
|
|
3203
|
+
}
|
|
3204
|
+
if (persona.description === personaDescription) {
|
|
3205
|
+
return;
|
|
3206
|
+
}
|
|
3207
|
+
if (personaDescription === null) {
|
|
3208
|
+
return;
|
|
3209
|
+
}
|
|
3210
|
+
if (persona.description === '') {
|
|
3211
|
+
persona.description = personaDescription;
|
|
3212
|
+
return;
|
|
3213
|
+
}
|
|
3214
|
+
console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
|
|
3215
|
+
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
3216
|
+
},
|
|
3217
|
+
};
|
|
2744
3218
|
|
|
2745
3219
|
/**
|
|
2746
3220
|
* Removes Markdown formatting tags from a string.
|
|
@@ -2896,7 +3370,6 @@ var blockCommandParser = {
|
|
|
2896
3370
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
2897
3371
|
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
2898
3372
|
if (blockTypes.length !== 1) {
|
|
2899
|
-
// console.log('!!!', { blockType });
|
|
2900
3373
|
throw new ParsingError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
|
|
2901
3374
|
}
|
|
2902
3375
|
// TODO: !!!! Not supported yet
|
|
@@ -2909,6 +3382,7 @@ var blockCommandParser = {
|
|
|
2909
3382
|
|
|
2910
3383
|
/**
|
|
2911
3384
|
* Units of text measurement
|
|
3385
|
+
* @see https://github.com/webgptorg/promptbook/discussions/30
|
|
2912
3386
|
*/
|
|
2913
3387
|
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2914
3388
|
/**
|
|
@@ -3144,94 +3618,15 @@ var jokerCommandParser = {
|
|
|
3144
3618
|
},
|
|
3145
3619
|
};
|
|
3146
3620
|
|
|
3147
|
-
/**
|
|
3148
|
-
* Tests if given string is valid URL.
|
|
3149
|
-
*
|
|
3150
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
3151
|
-
*/
|
|
3152
|
-
function isValidFilePath(filePath) {
|
|
3153
|
-
if (typeof filePath !== 'string') {
|
|
3154
|
-
return false;
|
|
3155
|
-
}
|
|
3156
|
-
var filePathSlashes = filePath.split('\\').join('/');
|
|
3157
|
-
// Absolute Unix path: /hello.txt
|
|
3158
|
-
if (/^(\/)/i.test(filePathSlashes)) {
|
|
3159
|
-
return true;
|
|
3160
|
-
}
|
|
3161
|
-
// Absolute Windows path: /hello.txt
|
|
3162
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
3163
|
-
return true;
|
|
3164
|
-
}
|
|
3165
|
-
// Relative path: ./hello.txt
|
|
3166
|
-
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
3167
|
-
return true;
|
|
3168
|
-
}
|
|
3169
|
-
return false;
|
|
3170
|
-
}
|
|
3171
|
-
|
|
3172
|
-
/**
|
|
3173
|
-
* Parses the knowledge command
|
|
3174
|
-
*
|
|
3175
|
-
* @see ./KNOWLEDGE-README.md for more details
|
|
3176
|
-
* @private within the commands folder
|
|
3177
|
-
*/
|
|
3178
|
-
var knowledgeCommandParser = {
|
|
3179
|
-
/**
|
|
3180
|
-
* Name of the command
|
|
3181
|
-
*/
|
|
3182
|
-
name: 'KNOWLEDGE',
|
|
3183
|
-
/**
|
|
3184
|
-
* BOILERPLATE command can be used in:
|
|
3185
|
-
*/
|
|
3186
|
-
usagePlaces: ['PIPELINE_HEAD'],
|
|
3187
|
-
/**
|
|
3188
|
-
* Description of the KNOWLEDGE command
|
|
3189
|
-
*/
|
|
3190
|
-
description: "Tells promptbook which external knowledge to use",
|
|
3191
|
-
/**
|
|
3192
|
-
* Link to discussion
|
|
3193
|
-
*/
|
|
3194
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3195
|
-
/**
|
|
3196
|
-
* Example usages of the KNOWLEDGE command
|
|
3197
|
-
*/
|
|
3198
|
-
examples: [
|
|
3199
|
-
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
3200
|
-
'KNOWLEDGE ./hejny-cv.txt',
|
|
3201
|
-
'KNOWLEDGE ./hejny-cv.md',
|
|
3202
|
-
'KNOWLEDGE ./hejny-cv.pdf',
|
|
3203
|
-
'KNOWLEDGE ./hejny-cv.docx',
|
|
3204
|
-
],
|
|
3205
|
-
/**
|
|
3206
|
-
* Parses the KNOWLEDGE command
|
|
3207
|
-
*/
|
|
3208
|
-
parse: function (input) {
|
|
3209
|
-
var args = input.args;
|
|
3210
|
-
var source = args[0];
|
|
3211
|
-
if (source === undefined) {
|
|
3212
|
-
throw new ParsingError("Source is not defined");
|
|
3213
|
-
}
|
|
3214
|
-
if (source.startsWith('http://')) {
|
|
3215
|
-
throw new ParsingError("Source is not secure");
|
|
3216
|
-
}
|
|
3217
|
-
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
3218
|
-
throw new ParsingError("Source not valid");
|
|
3219
|
-
}
|
|
3220
|
-
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
3221
|
-
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
3222
|
-
}
|
|
3223
|
-
return {
|
|
3224
|
-
type: 'KNOWLEDGE',
|
|
3225
|
-
source: source,
|
|
3226
|
-
};
|
|
3227
|
-
},
|
|
3228
|
-
};
|
|
3229
|
-
|
|
3230
3621
|
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
3231
3622
|
/**
|
|
3623
|
+
* TODO: [🈁] `seed` should maybe be somewhere else (not in `ModelRequirements`) (simmilar that `user` identification is not here)
|
|
3624
|
+
* TODO: [🧠][💱] Add more model options: `stop_token`, `logit_bias`, `logprobs` (`top_logprobs`), `top_k`, `top_p`, `presence_penalty`, `frequency_penalty`, `bestOf`, `logitBias`, `logitBiasType`,...
|
|
3625
|
+
* [💱] Probbably keep using just `temperature` in Promptbook (not `top_k` and `top_p`)
|
|
3626
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3232
3627
|
* TODO: Maybe figure out better word than "variant"
|
|
3233
3628
|
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
3234
|
-
* TODO: [
|
|
3629
|
+
* TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
|
|
3235
3630
|
*/
|
|
3236
3631
|
|
|
3237
3632
|
/**
|
|
@@ -3370,59 +3765,6 @@ var parameterCommandParser = {
|
|
|
3370
3765
|
},
|
|
3371
3766
|
};
|
|
3372
3767
|
|
|
3373
|
-
/**
|
|
3374
|
-
* Parses the persona command
|
|
3375
|
-
*
|
|
3376
|
-
* @see ./PERSONA-README.md for more details
|
|
3377
|
-
* @private within the commands folder
|
|
3378
|
-
*/
|
|
3379
|
-
var personaCommandParser = {
|
|
3380
|
-
/**
|
|
3381
|
-
* Name of the command
|
|
3382
|
-
*/
|
|
3383
|
-
name: 'PERSONA',
|
|
3384
|
-
/**
|
|
3385
|
-
* Aliases for the PERSONA command
|
|
3386
|
-
*/
|
|
3387
|
-
aliasNames: ['PERSON'],
|
|
3388
|
-
/**
|
|
3389
|
-
* PERSONA command can be used in:
|
|
3390
|
-
*/
|
|
3391
|
-
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3392
|
-
/**
|
|
3393
|
-
* Description of the PERSONA command
|
|
3394
|
-
*/
|
|
3395
|
-
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
3396
|
-
/**
|
|
3397
|
-
* Link to discussion
|
|
3398
|
-
*/
|
|
3399
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3400
|
-
/**
|
|
3401
|
-
* Example usages of the PERSONA command
|
|
3402
|
-
*/
|
|
3403
|
-
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
3404
|
-
/**
|
|
3405
|
-
* Parses the PERSONA command
|
|
3406
|
-
*/
|
|
3407
|
-
parse: function (input) {
|
|
3408
|
-
var rawArgs = input.rawArgs;
|
|
3409
|
-
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
3410
|
-
var personaName = (personaNameRaw || '').trim();
|
|
3411
|
-
if (personaName === '') {
|
|
3412
|
-
throw new ParsingError("You must set name for the persona");
|
|
3413
|
-
}
|
|
3414
|
-
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
3415
|
-
if (personaDescription === '') {
|
|
3416
|
-
personaDescription = null;
|
|
3417
|
-
}
|
|
3418
|
-
return {
|
|
3419
|
-
type: 'PERSONA',
|
|
3420
|
-
personaName: personaName,
|
|
3421
|
-
personaDescription: personaDescription,
|
|
3422
|
-
};
|
|
3423
|
-
},
|
|
3424
|
-
};
|
|
3425
|
-
|
|
3426
3768
|
function isValidJavascriptName(javascriptName) {
|
|
3427
3769
|
if (typeof javascriptName !== 'string') {
|
|
3428
3770
|
return false;
|
|
@@ -3609,22 +3951,6 @@ var urlCommandParser = {
|
|
|
3609
3951
|
},
|
|
3610
3952
|
};
|
|
3611
3953
|
|
|
3612
|
-
/**
|
|
3613
|
-
* Returns the same value that is passed as argument.
|
|
3614
|
-
* No side effects.
|
|
3615
|
-
*
|
|
3616
|
-
* Note: It can be usefull for leveling indentation
|
|
3617
|
-
*
|
|
3618
|
-
* @param value any values
|
|
3619
|
-
* @returns the same values
|
|
3620
|
-
*/
|
|
3621
|
-
function just(value) {
|
|
3622
|
-
if (value === undefined) {
|
|
3623
|
-
return undefined;
|
|
3624
|
-
}
|
|
3625
|
-
return value;
|
|
3626
|
-
}
|
|
3627
|
-
|
|
3628
3954
|
/**
|
|
3629
3955
|
* Parses the action command
|
|
3630
3956
|
*
|
|
@@ -3656,7 +3982,8 @@ var actionCommandParser = {
|
|
|
3656
3982
|
* Parses the ACTION command
|
|
3657
3983
|
*/
|
|
3658
3984
|
parse: function (input) {
|
|
3659
|
-
input.args;
|
|
3985
|
+
var args = input.args;
|
|
3986
|
+
TODO_USE(args);
|
|
3660
3987
|
return {
|
|
3661
3988
|
type: 'ACTION',
|
|
3662
3989
|
};
|
|
@@ -3694,7 +4021,8 @@ var instrumentCommandParser = {
|
|
|
3694
4021
|
* Parses the INSTRUMENT command
|
|
3695
4022
|
*/
|
|
3696
4023
|
parse: function (input) {
|
|
3697
|
-
input.args;
|
|
4024
|
+
var args = input.args;
|
|
4025
|
+
TODO_USE(args);
|
|
3698
4026
|
return {
|
|
3699
4027
|
type: 'INSTRUMENT',
|
|
3700
4028
|
};
|
|
@@ -3876,7 +4204,6 @@ function parseCommandVariant(input) {
|
|
|
3876
4204
|
var _loop_1 = function (commandParser) {
|
|
3877
4205
|
var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
|
|
3878
4206
|
var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
|
|
3879
|
-
// console.log('!!!', { commandName, names });
|
|
3880
4207
|
if (names.includes(commandName)) {
|
|
3881
4208
|
try {
|
|
3882
4209
|
return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
|
|
@@ -3986,25 +4313,42 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
3986
4313
|
var e_1, _a;
|
|
3987
4314
|
var codeBlocks = [];
|
|
3988
4315
|
var lines = markdown.split('\n');
|
|
4316
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
4317
|
+
lines.push('');
|
|
3989
4318
|
var currentCodeBlock = null;
|
|
3990
4319
|
try {
|
|
3991
4320
|
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
3992
4321
|
var line = lines_1_1.value;
|
|
4322
|
+
if (line.startsWith('> ') || line === '>') {
|
|
4323
|
+
if (currentCodeBlock === null) {
|
|
4324
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
4325
|
+
} /* not else */
|
|
4326
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
4327
|
+
if (currentCodeBlock.content !== '') {
|
|
4328
|
+
currentCodeBlock.content += '\n';
|
|
4329
|
+
}
|
|
4330
|
+
currentCodeBlock.content += line.slice(2);
|
|
4331
|
+
}
|
|
4332
|
+
}
|
|
4333
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
4334
|
+
codeBlocks.push(currentCodeBlock);
|
|
4335
|
+
currentCodeBlock = null;
|
|
4336
|
+
}
|
|
4337
|
+
/* not else */
|
|
3993
4338
|
if (line.startsWith('```')) {
|
|
3994
4339
|
var language = line.slice(3).trim() || null;
|
|
3995
4340
|
if (currentCodeBlock === null) {
|
|
3996
|
-
currentCodeBlock = { language: language, content: '' };
|
|
4341
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
3997
4342
|
}
|
|
3998
4343
|
else {
|
|
3999
4344
|
if (language !== null) {
|
|
4000
|
-
|
|
4001
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4345
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4002
4346
|
}
|
|
4003
4347
|
codeBlocks.push(currentCodeBlock);
|
|
4004
4348
|
currentCodeBlock = null;
|
|
4005
4349
|
}
|
|
4006
4350
|
}
|
|
4007
|
-
else if (currentCodeBlock !== null) {
|
|
4351
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
4008
4352
|
if (currentCodeBlock.content !== '') {
|
|
4009
4353
|
currentCodeBlock.content += '\n';
|
|
4010
4354
|
}
|
|
@@ -4020,11 +4364,13 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4020
4364
|
finally { if (e_1) throw e_1.error; }
|
|
4021
4365
|
}
|
|
4022
4366
|
if (currentCodeBlock !== null) {
|
|
4023
|
-
|
|
4024
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4367
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4025
4368
|
}
|
|
4026
4369
|
return codeBlocks;
|
|
4027
4370
|
}
|
|
4371
|
+
/**
|
|
4372
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
4373
|
+
*/
|
|
4028
4374
|
|
|
4029
4375
|
/**
|
|
4030
4376
|
* Extracts exactly ONE code block from markdown.
|
|
@@ -4042,13 +4388,12 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4042
4388
|
function extractOneBlockFromMarkdown(markdown) {
|
|
4043
4389
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
4044
4390
|
if (codeBlocks.length !== 1) {
|
|
4045
|
-
|
|
4046
|
-
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
4391
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
4047
4392
|
}
|
|
4048
4393
|
return codeBlocks[0];
|
|
4049
4394
|
}
|
|
4050
4395
|
/***
|
|
4051
|
-
* TODO: [🍓][🌻]
|
|
4396
|
+
* TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
|
|
4052
4397
|
*/
|
|
4053
4398
|
|
|
4054
4399
|
/**
|
|
@@ -4058,13 +4403,13 @@ function parseMarkdownSection(value) {
|
|
|
4058
4403
|
var _a, _b;
|
|
4059
4404
|
var lines = value.split('\n');
|
|
4060
4405
|
if (!lines[0].startsWith('#')) {
|
|
4061
|
-
throw new
|
|
4406
|
+
throw new ParsingError('Markdown section must start with heading');
|
|
4062
4407
|
}
|
|
4063
4408
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
4064
4409
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
4065
4410
|
var content = spaceTrim(lines.slice(1).join('\n'));
|
|
4066
4411
|
if (level < 1 || level > 6) {
|
|
4067
|
-
throw new
|
|
4412
|
+
throw new ParsingError('Markdown section must have heading level between 1 and 6');
|
|
4068
4413
|
}
|
|
4069
4414
|
return { title: title, level: level, content: content };
|
|
4070
4415
|
}
|
|
@@ -4390,14 +4735,14 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
4390
4735
|
*/
|
|
4391
4736
|
|
|
4392
4737
|
/**
|
|
4393
|
-
* Compile
|
|
4738
|
+
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4394
4739
|
*
|
|
4395
|
-
* Note: There are
|
|
4740
|
+
* Note: There are 3 similar functions:
|
|
4396
4741
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4397
4742
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
4743
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4398
4744
|
*
|
|
4399
4745
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4400
|
-
* @param options - Options and tools for the compilation
|
|
4401
4746
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
4402
4747
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
4403
4748
|
*
|
|
@@ -4413,7 +4758,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4413
4758
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
4414
4759
|
parameters: [],
|
|
4415
4760
|
promptTemplates: [],
|
|
4416
|
-
|
|
4761
|
+
knowledgeSources: [],
|
|
4762
|
+
knowledgePieces: [],
|
|
4763
|
+
personas: [],
|
|
4764
|
+
preparations: [],
|
|
4417
4765
|
};
|
|
4418
4766
|
// =============================================================
|
|
4419
4767
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
@@ -4443,7 +4791,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4443
4791
|
existingParameter.description &&
|
|
4444
4792
|
existingParameter.description !== parameterDescription &&
|
|
4445
4793
|
parameterDescription) {
|
|
4446
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description
|
|
4794
|
+
throw new ParsingError(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 "); }));
|
|
4447
4795
|
}
|
|
4448
4796
|
if (existingParameter) {
|
|
4449
4797
|
if (parameterDescription) {
|
|
@@ -4462,11 +4810,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4462
4810
|
// =============================================================
|
|
4463
4811
|
// Note: 3️⃣ Process pipeline head
|
|
4464
4812
|
pipelineJson.title = pipelineHead.title;
|
|
4465
|
-
// TODO: [1] DRY description
|
|
4813
|
+
// TODO: [🎾][1] DRY description
|
|
4466
4814
|
var description = pipelineHead.content;
|
|
4467
|
-
// Note: Remove codeblocks - TODO:
|
|
4815
|
+
// Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
|
|
4468
4816
|
description = description.split(/^```.*^```/gms).join('');
|
|
4469
|
-
|
|
4817
|
+
description = description.split(/^>.*$/gm).join('');
|
|
4818
|
+
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
4470
4819
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4471
4820
|
description = spaceTrim$1(description);
|
|
4472
4821
|
if (description === '') {
|
|
@@ -4494,7 +4843,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4494
4843
|
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
4495
4844
|
break;
|
|
4496
4845
|
case 'KNOWLEDGE':
|
|
4497
|
-
|
|
4846
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4498
4847
|
break;
|
|
4499
4848
|
case 'ACTION':
|
|
4500
4849
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
@@ -4503,7 +4852,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4503
4852
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4504
4853
|
break;
|
|
4505
4854
|
case 'PERSONA':
|
|
4506
|
-
|
|
4855
|
+
personaCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4856
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4507
4857
|
break;
|
|
4508
4858
|
case 'BOILERPLATE':
|
|
4509
4859
|
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
@@ -4532,7 +4882,27 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4532
4882
|
var postprocessing = [];
|
|
4533
4883
|
var expectAmount = {};
|
|
4534
4884
|
var expectFormat = undefined;
|
|
4535
|
-
var
|
|
4885
|
+
var isBlockTypeSet = false;
|
|
4886
|
+
var lastLine = section.content.split('\n').pop();
|
|
4887
|
+
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4888
|
+
var resultingParameterName = null;
|
|
4889
|
+
if (resultingParameterNameMatch &&
|
|
4890
|
+
resultingParameterNameMatch.groups !== undefined &&
|
|
4891
|
+
resultingParameterNameMatch.groups.resultingParamName !== undefined) {
|
|
4892
|
+
resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
|
|
4893
|
+
}
|
|
4894
|
+
var expectResultingParameterName = function () {
|
|
4895
|
+
if (resultingParameterName !== null) {
|
|
4896
|
+
return resultingParameterName;
|
|
4897
|
+
}
|
|
4898
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
4899
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
4900
|
+
section.content
|
|
4901
|
+
.split('\n')
|
|
4902
|
+
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
4903
|
+
.join('\n')), "\n "); }));
|
|
4904
|
+
};
|
|
4905
|
+
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
4536
4906
|
try {
|
|
4537
4907
|
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
4538
4908
|
var listItem = listItems_2_1.value;
|
|
@@ -4540,15 +4910,24 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4540
4910
|
switch (command.type) {
|
|
4541
4911
|
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
4542
4912
|
case 'BLOCK':
|
|
4543
|
-
if (
|
|
4913
|
+
if (isBlockTypeSet) {
|
|
4544
4914
|
throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
|
|
4545
4915
|
}
|
|
4546
4916
|
if (command.blockType === 'SAMPLE') {
|
|
4547
|
-
|
|
4917
|
+
expectResultingParameterName();
|
|
4918
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
4919
|
+
if (parameter === undefined) {
|
|
4920
|
+
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
4921
|
+
}
|
|
4922
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
4923
|
+
parameter.sampleValues.push(content);
|
|
4548
4924
|
return "continue-templates";
|
|
4549
4925
|
}
|
|
4550
4926
|
if (command.blockType === 'KNOWLEDGE') {
|
|
4551
|
-
|
|
4927
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, {
|
|
4928
|
+
type: 'KNOWLEDGE',
|
|
4929
|
+
source: content, // <- TODO: !!!! Working KNOWLEDGE which not referring to the source file/wweb, but its content itseld
|
|
4930
|
+
});
|
|
4552
4931
|
return "continue-templates";
|
|
4553
4932
|
}
|
|
4554
4933
|
if (command.blockType === 'ACTION') {
|
|
@@ -4559,8 +4938,9 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4559
4938
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4560
4939
|
return "continue-templates";
|
|
4561
4940
|
}
|
|
4941
|
+
expectResultingParameterName();
|
|
4562
4942
|
blockType = command.blockType;
|
|
4563
|
-
|
|
4943
|
+
isBlockTypeSet = true;
|
|
4564
4944
|
break;
|
|
4565
4945
|
case 'EXPECT_AMOUNT':
|
|
4566
4946
|
// eslint-disable-next-line no-case-declarations
|
|
@@ -4600,16 +4980,20 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4600
4980
|
postprocessing.push(command.functionName);
|
|
4601
4981
|
break;
|
|
4602
4982
|
case 'KNOWLEDGE':
|
|
4603
|
-
|
|
4983
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
4984
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4604
4985
|
break;
|
|
4605
4986
|
case 'ACTION':
|
|
4987
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
4606
4988
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
4607
4989
|
break;
|
|
4608
4990
|
case 'INSTRUMENT':
|
|
4991
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
4609
4992
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4610
4993
|
break;
|
|
4611
4994
|
case 'PERSONA':
|
|
4612
|
-
|
|
4995
|
+
personaCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4996
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4613
4997
|
break;
|
|
4614
4998
|
case 'BOILERPLATE':
|
|
4615
4999
|
console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
|
|
@@ -4627,7 +5011,6 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4627
5011
|
}
|
|
4628
5012
|
finally { if (e_3) throw e_3.error; }
|
|
4629
5013
|
}
|
|
4630
|
-
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
4631
5014
|
if (blockType === 'SCRIPT') {
|
|
4632
5015
|
if (!language) {
|
|
4633
5016
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
@@ -4636,22 +5019,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4636
5019
|
throw new ParsingError(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 "); }));
|
|
4637
5020
|
}
|
|
4638
5021
|
}
|
|
4639
|
-
|
|
4640
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4641
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
4642
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Each section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
4643
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
4644
|
-
section.content
|
|
4645
|
-
.split('\n')
|
|
4646
|
-
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
4647
|
-
.join('\n')), "\n "); }));
|
|
4648
|
-
}
|
|
4649
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
4650
|
-
// TODO: [1] DRY description
|
|
5022
|
+
// TODO: [🎾][1] DRY description
|
|
4651
5023
|
var description_1 = section.content;
|
|
4652
|
-
// Note: Remove codeblocks
|
|
5024
|
+
// Note: Remove codeblocks - TODO: [🎾]
|
|
4653
5025
|
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
4654
|
-
|
|
5026
|
+
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5027
|
+
//Note: Remove lists and return statement - TODO: [🎾]
|
|
4655
5028
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4656
5029
|
description_1 = spaceTrim$1(description_1);
|
|
4657
5030
|
if (description_1 === '') {
|
|
@@ -4681,10 +5054,11 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4681
5054
|
postprocessing: postprocessing,
|
|
4682
5055
|
expectations: expectAmount,
|
|
4683
5056
|
expectFormat: expectFormat,
|
|
5057
|
+
personaName: null,
|
|
4684
5058
|
modelRequirements: templateModelRequirements,
|
|
4685
5059
|
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4686
5060
|
content: content,
|
|
4687
|
-
resultingParameterName:
|
|
5061
|
+
resultingParameterName: expectResultingParameterName( /* <- Note: This is once more redundant */),
|
|
4688
5062
|
};
|
|
4689
5063
|
if (blockType !== 'PROMPT_TEMPLATE') {
|
|
4690
5064
|
delete template.modelRequirements;
|
|
@@ -4757,14 +5131,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4757
5131
|
* TODO: Use spaceTrim more effectively
|
|
4758
5132
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
4759
5133
|
* TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
5134
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
5135
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4760
5136
|
*/
|
|
4761
5137
|
|
|
4762
5138
|
/**
|
|
4763
|
-
* Compile
|
|
5139
|
+
* Compile pipeline from string (markdown) format to JSON format
|
|
4764
5140
|
*
|
|
4765
|
-
* Note: There are
|
|
5141
|
+
* Note: There are 3 similar functions:
|
|
4766
5142
|
* - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
4767
5143
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5144
|
+
* - `preparePipeline` - just one step in the compilation process
|
|
4768
5145
|
*
|
|
4769
5146
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
4770
5147
|
* @param options - Options and tools for the compilation
|
|
@@ -4775,22 +5152,18 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4775
5152
|
* Note: This function acts as compilation process
|
|
4776
5153
|
*/
|
|
4777
5154
|
function pipelineStringToJson(pipelineString, options) {
|
|
4778
|
-
if (options === void 0) { options = {}; }
|
|
5155
|
+
if (options === void 0) { options = { llmTools: null }; }
|
|
4779
5156
|
return __awaiter(this, void 0, void 0, function () {
|
|
4780
|
-
var llmTools, pipelineJson
|
|
5157
|
+
var llmTools, pipelineJson;
|
|
4781
5158
|
return __generator(this, function (_a) {
|
|
4782
5159
|
switch (_a.label) {
|
|
4783
5160
|
case 0:
|
|
4784
5161
|
llmTools = options.llmTools;
|
|
4785
5162
|
pipelineJson = pipelineStringToJsonSync(pipelineString);
|
|
4786
|
-
if (!llmTools) return [3 /*break*/, 2];
|
|
4787
|
-
return [4 /*yield*/,
|
|
4788
|
-
content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
|
|
4789
|
-
llmTools: llmTools,
|
|
4790
|
-
})];
|
|
5163
|
+
if (!(llmTools !== null)) return [3 /*break*/, 2];
|
|
5164
|
+
return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
|
|
4791
5165
|
case 1:
|
|
4792
|
-
|
|
4793
|
-
pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
|
|
5166
|
+
pipelineJson = _a.sent();
|
|
4794
5167
|
_a.label = 2;
|
|
4795
5168
|
case 2: return [2 /*return*/, pipelineJson];
|
|
4796
5169
|
}
|
|
@@ -4799,6 +5172,7 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
4799
5172
|
}
|
|
4800
5173
|
/**
|
|
4801
5174
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
5175
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4802
5176
|
*/
|
|
4803
5177
|
|
|
4804
5178
|
/**
|
|
@@ -4816,7 +5190,10 @@ function addAutoGeneratedSection(content, options) {
|
|
|
4816
5190
|
}
|
|
4817
5191
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
4818
5192
|
if (!placeForSection) {
|
|
4819
|
-
throw new
|
|
5193
|
+
throw new ParsingError(
|
|
5194
|
+
// <- [🧠] Maybe something better than `ParsingError`
|
|
5195
|
+
"No place where to put the section <!--".concat(sectionName, "-->"));
|
|
5196
|
+
// <- [🚞]
|
|
4820
5197
|
}
|
|
4821
5198
|
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
4822
5199
|
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
@@ -4987,6 +5364,20 @@ var CollectionError = /** @class */ (function (_super) {
|
|
|
4987
5364
|
return CollectionError;
|
|
4988
5365
|
}(Error));
|
|
4989
5366
|
|
|
5367
|
+
/**
|
|
5368
|
+
* This error type indicates that the version of the pipeline is not matching the expected version
|
|
5369
|
+
*/
|
|
5370
|
+
var VersionMismatchError = /** @class */ (function (_super) {
|
|
5371
|
+
__extends(VersionMismatchError, _super);
|
|
5372
|
+
function VersionMismatchError(message, expectedVersion) {
|
|
5373
|
+
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n This error indicates that there is error with compatibility\n\n Expected version:\n ").concat(expectedVersion, "\n\n Current version:\n ").concat(PROMPTBOOK_VERSION, "\n\n "); })) || this;
|
|
5374
|
+
_this.name = 'UnexpectedError';
|
|
5375
|
+
Object.setPrototypeOf(_this, VersionMismatchError.prototype);
|
|
5376
|
+
return _this;
|
|
5377
|
+
}
|
|
5378
|
+
return VersionMismatchError;
|
|
5379
|
+
}(Error));
|
|
5380
|
+
|
|
4990
5381
|
/**
|
|
4991
5382
|
* Pretty print an embedding vector for logging
|
|
4992
5383
|
*/
|
|
@@ -5075,6 +5466,19 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
|
5075
5466
|
return SimplePromptInterfaceTools;
|
|
5076
5467
|
}());
|
|
5077
5468
|
|
|
5469
|
+
/**
|
|
5470
|
+
* Unprepare just strips the preparation data of the pipeline
|
|
5471
|
+
*/
|
|
5472
|
+
function unpreparePipeline(pipeline) {
|
|
5473
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
|
|
5474
|
+
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
5475
|
+
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
5476
|
+
return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
5477
|
+
}
|
|
5478
|
+
/**
|
|
5479
|
+
* TODO: Write tests for `preparePipeline`
|
|
5480
|
+
*/
|
|
5481
|
+
|
|
5078
5482
|
/**
|
|
5079
5483
|
* Default options for generating an execution report string
|
|
5080
5484
|
*/
|
|
@@ -5175,6 +5579,22 @@ function escapeMarkdownBlock(value) {
|
|
|
5175
5579
|
return value.replace(/```/g, '\\`\\`\\`');
|
|
5176
5580
|
}
|
|
5177
5581
|
|
|
5582
|
+
/**
|
|
5583
|
+
* Returns the same value that is passed as argument.
|
|
5584
|
+
* No side effects.
|
|
5585
|
+
*
|
|
5586
|
+
* Note: It can be usefull for leveling indentation
|
|
5587
|
+
*
|
|
5588
|
+
* @param value any values
|
|
5589
|
+
* @returns the same values
|
|
5590
|
+
*/
|
|
5591
|
+
function just(value) {
|
|
5592
|
+
if (value === undefined) {
|
|
5593
|
+
return undefined;
|
|
5594
|
+
}
|
|
5595
|
+
return value;
|
|
5596
|
+
}
|
|
5597
|
+
|
|
5178
5598
|
/**
|
|
5179
5599
|
* The thresholds for the relative time in the `moment` NPM package.
|
|
5180
5600
|
*
|
|
@@ -5385,5 +5805,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
5385
5805
|
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
5386
5806
|
*/
|
|
5387
5807
|
|
|
5388
|
-
export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prettifyPipelineString, usageToWorktime, validatePipeline };
|
|
5808
|
+
export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatchError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, preparePipeline, prettifyPipelineString, unpreparePipeline, usageToWorktime, validatePipeline };
|
|
5389
5809
|
//# sourceMappingURL=index.es.js.map
|