@promptbook/markdown-utils 0.75.0-1 → 0.75.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/esm/index.es.js +233 -218
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +6 -6
- package/esm/typings/src/_packages/core.index.d.ts +22 -20
- package/esm/typings/src/_packages/types.index.d.ts +58 -50
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/cli/cli-commands/about.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/hello.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/run.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +1 -0
- package/esm/typings/src/cli/main.d.ts +1 -0
- package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/collectionToJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/ExpectCommand.d.ts +2 -2
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/SECTION/SectionCommand.d.ts +11 -0
- package/esm/typings/src/commands/SECTION/SectionType.d.ts +13 -0
- package/esm/typings/src/commands/{TEMPLATE/templateCommandParser.d.ts → SECTION/sectionCommandParser.d.ts} +6 -6
- package/esm/typings/src/commands/_common/types/Command.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +17 -17
- package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +1 -1
- package/esm/typings/src/commands/index.d.ts +4 -1
- package/esm/typings/src/config.d.ts +2 -1
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +2 -2
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +2 -2
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +3 -3
- package/esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts +1 -1
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
- package/esm/typings/src/conversion/utils/{extractParameterNamesFromTemplate.d.ts → extractParameterNamesFromTask.d.ts} +2 -2
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +1 -1
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +3 -2
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +1 -1
- package/esm/typings/src/errors/index.d.ts +3 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptResultUsage.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/{$OngoingTemplateResult.d.ts → $OngoingTaskResult.d.ts} +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/{20-executeTemplate.d.ts → 20-executeTask.d.ts} +7 -7
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +5 -5
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/{getContextForTemplate.d.ts → getContextForTask.d.ts} +2 -2
- package/esm/typings/src/execution/createPipelineExecutor/{getExamplesForTemplate.d.ts → getExamplesForTask.d.ts} +2 -2
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +27 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +30 -0
- package/esm/typings/src/{types → execution}/execution-report/ExecutionPromptReportJson.d.ts +2 -2
- package/esm/typings/src/{types → execution}/execution-report/ExecutionReportJson.d.ts +4 -4
- package/esm/typings/src/{types → execution}/execution-report/ExecutionReportStringOptions.d.ts +1 -1
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/esm/typings/src/execution/utils/usage-constants.d.ts +3 -0
- package/esm/typings/src/formats/index.d.ts +3 -0
- package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +4 -1
- package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +3 -0
- package/esm/typings/src/formfactors/{chat/ChatFormfactorDefinition.d.ts → chatbot/ChatbotFormfactorDefinition.d.ts} +2 -2
- package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +1 -1
- package/esm/typings/src/formfactors/index.d.ts +15 -4
- package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +14 -0
- package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +1 -1
- package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +3 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +3 -0
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +3 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +1 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/PipelineInterface.d.ts +3 -0
- package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/constants.d.ts +5 -0
- package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/getPipelineInterface.d.ts +3 -1
- package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/isPipelineImplementingInterface.d.ts +5 -1
- package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/isPipelineInterfacesEqual.d.ts +2 -0
- package/esm/typings/src/pipeline/PipelineJson/DialogTaskJson.d.ts +13 -0
- package/esm/typings/src/{types → pipeline}/PipelineJson/Expectations.d.ts +2 -2
- package/esm/typings/src/{types → pipeline}/PipelineJson/KnowledgePieceJson.d.ts +7 -6
- package/esm/typings/src/{types → pipeline}/PipelineJson/KnowledgeSourceJson.d.ts +3 -3
- package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +96 -0
- package/esm/typings/src/{types → pipeline}/PipelineJson/PersonaJson.d.ts +4 -4
- package/esm/typings/src/{types → pipeline}/PipelineJson/PipelineJson.d.ts +10 -10
- package/esm/typings/src/{types → pipeline}/PipelineJson/PreparationJson.d.ts +1 -1
- package/esm/typings/src/{types/PipelineJson/PromptTemplateJson.d.ts → pipeline/PipelineJson/PromptTaskJson.d.ts} +8 -8
- package/esm/typings/src/pipeline/PipelineJson/ScriptTaskJson.d.ts +20 -0
- package/esm/typings/src/pipeline/PipelineJson/SimpleTaskJson.d.ts +13 -0
- package/esm/typings/src/pipeline/PipelineJson/TaskJson.d.ts +11 -0
- package/esm/typings/src/{types/PipelineJson/TemplateJsonCommon.d.ts → pipeline/PipelineJson/TaskJsonCommon.d.ts} +13 -13
- package/esm/typings/src/{types → pipeline}/PipelineString.d.ts +1 -1
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +2 -2
- package/esm/typings/src/prepare/preparePipeline.d.ts +1 -1
- package/esm/typings/src/prepare/{prepareTemplates.d.ts → prepareTasks.d.ts} +7 -7
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
- package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +3 -0
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +3 -0
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +3 -0
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +3 -0
- package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +3 -0
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +1 -0
- package/esm/typings/src/types/Prompt.d.ts +1 -1
- package/esm/typings/src/types/TaskProgress.d.ts +2 -2
- package/esm/typings/src/types/typeAliasEmoji.d.ts +3 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -0
- package/esm/typings/src/utils/emojis.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/constants.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/index.d.ts +3 -2
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -0
- package/esm/typings/src/utils/parameters/extractParameterNames.d.ts +2 -2
- package/esm/typings/src/utils/serialization/clonePipeline.d.ts +1 -1
- package/esm/typings/src/version.d.ts +2 -1
- package/package.json +4 -3
- package/umd/index.umd.js +233 -218
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/commands/TEMPLATE/TemplateCommand.d.ts +0 -11
- package/esm/typings/src/commands/TEMPLATE/TemplateTypes.d.ts +0 -15
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTemplate.d.ts +0 -27
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTemplate.d.ts +0 -30
- package/esm/typings/src/types/PipelineJson/DialogTemplateJson.d.ts +0 -13
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +0 -39
- package/esm/typings/src/types/PipelineJson/ScriptTemplateJson.d.ts +0 -20
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +0 -13
- package/esm/typings/src/types/PipelineJson/TemplateJson.d.ts +0 -11
- /package/esm/typings/src/commands/{TEMPLATE/templateCommand.test.d.ts → SECTION/sectionCommand.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{extractParameterNamesFromTemplate.test.d.ts → extractParameterNamesFromTask.test.d.ts} +0 -0
- /package/esm/typings/src/{types → execution}/execution-report/ExecutionReportString.d.ts +0 -0
- /package/esm/typings/src/{types → execution}/execution-report/countWorkingDuration.d.ts +0 -0
- /package/esm/typings/src/{types → execution}/execution-report/countWorkingDuration.test.d.ts +0 -0
- /package/esm/typings/src/{types → execution}/execution-report/executionReportJsonToString.d.ts +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
*
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.75.0-
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.75.0-1';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
28
29
|
*/
|
|
29
30
|
|
|
30
31
|
/*! *****************************************************************************
|
|
@@ -357,7 +358,7 @@
|
|
|
357
358
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
358
359
|
*/
|
|
359
360
|
|
|
360
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],
|
|
361
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",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}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.book.md"}];
|
|
361
362
|
|
|
362
363
|
/**
|
|
363
364
|
* Prettify the html code
|
|
@@ -402,7 +403,7 @@
|
|
|
402
403
|
*/
|
|
403
404
|
function pipelineJsonToString(pipelineJson) {
|
|
404
405
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
405
|
-
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters,
|
|
406
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, tasks = pipelineJson.tasks;
|
|
406
407
|
var pipelineString = "# ".concat(title);
|
|
407
408
|
if (description) {
|
|
408
409
|
pipelineString += '\n\n';
|
|
@@ -452,13 +453,13 @@
|
|
|
452
453
|
pipelineString += '\n\n';
|
|
453
454
|
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
454
455
|
try {
|
|
455
|
-
for (var
|
|
456
|
-
var template =
|
|
456
|
+
for (var tasks_1 = __values(tasks), tasks_1_1 = tasks_1.next(); !tasks_1_1.done; tasks_1_1 = tasks_1.next()) {
|
|
457
|
+
var template = tasks_1_1.value;
|
|
457
458
|
var
|
|
458
459
|
/* Note: Not using:> name, */
|
|
459
460
|
title_1 = template.title, description_1 = template.description,
|
|
460
461
|
/* Note: dependentParameterNames, */
|
|
461
|
-
jokers = template.jokerParameterNames,
|
|
462
|
+
jokers = template.jokerParameterNames, taskType = template.taskType, content = template.content, postprocessing = template.postprocessingFunctionNames, expectations = template.expectations, format = template.format, resultingParameterName = template.resultingParameterName;
|
|
462
463
|
pipelineString += '\n\n';
|
|
463
464
|
pipelineString += "## ".concat(title_1);
|
|
464
465
|
if (description_1) {
|
|
@@ -467,7 +468,7 @@
|
|
|
467
468
|
}
|
|
468
469
|
var commands_1 = [];
|
|
469
470
|
var contentLanguage = 'text';
|
|
470
|
-
if (
|
|
471
|
+
if (taskType === 'PROMPT_TASK') {
|
|
471
472
|
var modelRequirements = template.modelRequirements;
|
|
472
473
|
var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
|
|
473
474
|
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
@@ -478,11 +479,11 @@
|
|
|
478
479
|
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
479
480
|
}
|
|
480
481
|
}
|
|
481
|
-
else if (
|
|
482
|
+
else if (taskType === 'SIMPLE_TASK') {
|
|
482
483
|
commands_1.push("SIMPLE TEMPLATE");
|
|
483
484
|
// Note: Nothing special here
|
|
484
485
|
}
|
|
485
|
-
else if (
|
|
486
|
+
else if (taskType === 'SCRIPT_TASK') {
|
|
486
487
|
commands_1.push("SCRIPT TEMPLATE");
|
|
487
488
|
if (template.contentLanguage) {
|
|
488
489
|
contentLanguage = template.contentLanguage;
|
|
@@ -491,7 +492,7 @@
|
|
|
491
492
|
contentLanguage = '';
|
|
492
493
|
}
|
|
493
494
|
}
|
|
494
|
-
else if (
|
|
495
|
+
else if (taskType === 'DIALOG_TASK') {
|
|
495
496
|
commands_1.push("DIALOG TEMPLATE");
|
|
496
497
|
// Note: Nothing special here
|
|
497
498
|
} // <- }else if([🅱]
|
|
@@ -573,7 +574,7 @@
|
|
|
573
574
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
574
575
|
finally {
|
|
575
576
|
try {
|
|
576
|
-
if (
|
|
577
|
+
if (tasks_1_1 && !tasks_1_1.done && (_c = tasks_1.return)) _c.call(tasks_1);
|
|
577
578
|
}
|
|
578
579
|
finally { if (e_3) throw e_3.error; }
|
|
579
580
|
}
|
|
@@ -913,6 +914,7 @@
|
|
|
913
914
|
true);
|
|
914
915
|
/**
|
|
915
916
|
* TODO: Extract `constants.ts` from `config.ts`
|
|
917
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
916
918
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
917
919
|
*/
|
|
918
920
|
|
|
@@ -1149,9 +1151,9 @@
|
|
|
1149
1151
|
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1150
1152
|
}
|
|
1151
1153
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1152
|
-
if (!Array.isArray(pipeline.
|
|
1154
|
+
if (!Array.isArray(pipeline.tasks)) {
|
|
1153
1155
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1154
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.
|
|
1156
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.tasks` expected to be an array, but got ".concat(typeof pipeline.tasks, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1155
1157
|
}
|
|
1156
1158
|
var _loop_1 = function (parameter) {
|
|
1157
1159
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -1160,13 +1162,12 @@
|
|
|
1160
1162
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
1161
1163
|
if (!parameter.isInput &&
|
|
1162
1164
|
!parameter.isOutput &&
|
|
1163
|
-
!pipeline.
|
|
1165
|
+
!pipeline.tasks.some(function (task) { return task.dependentParameterNames.includes(parameter.name); })) {
|
|
1164
1166
|
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
1165
1167
|
}
|
|
1166
|
-
// Note: Testing that parameter is either input or result of some
|
|
1167
|
-
if (!parameter.isInput &&
|
|
1168
|
-
|
|
1169
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add template that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1168
|
+
// Note: Testing that parameter is either input or result of some task
|
|
1169
|
+
if (!parameter.isInput && !pipeline.tasks.some(function (task) { return task.resultingParameterName === parameter.name; })) {
|
|
1170
|
+
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add task that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1170
1171
|
}
|
|
1171
1172
|
};
|
|
1172
1173
|
try {
|
|
@@ -1183,7 +1184,7 @@
|
|
|
1183
1184
|
}
|
|
1184
1185
|
finally { if (e_1) throw e_1.error; }
|
|
1185
1186
|
}
|
|
1186
|
-
// Note: All input parameters are defined - so that they can be used as result of some
|
|
1187
|
+
// Note: All input parameters are defined - so that they can be used as result of some task
|
|
1187
1188
|
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
1188
1189
|
var isInput = _a.isInput;
|
|
1189
1190
|
return isInput;
|
|
@@ -1191,27 +1192,27 @@
|
|
|
1191
1192
|
var name = _a.name;
|
|
1192
1193
|
return name;
|
|
1193
1194
|
}));
|
|
1194
|
-
var _loop_2 = function (
|
|
1195
|
+
var _loop_2 = function (task) {
|
|
1195
1196
|
var e_4, _h, e_5, _j;
|
|
1196
|
-
if (definedParameters.has(
|
|
1197
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(
|
|
1197
|
+
if (definedParameters.has(task.resultingParameterName)) {
|
|
1198
|
+
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1198
1199
|
}
|
|
1199
|
-
if (RESERVED_PARAMETER_NAMES.includes(
|
|
1200
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter name {".concat(
|
|
1200
|
+
if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
|
|
1201
|
+
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter name {".concat(task.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1201
1202
|
}
|
|
1202
|
-
definedParameters.add(
|
|
1203
|
-
if (
|
|
1204
|
-
if (!
|
|
1205
|
-
!
|
|
1206
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(
|
|
1203
|
+
definedParameters.add(task.resultingParameterName);
|
|
1204
|
+
if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
|
|
1205
|
+
if (!task.format &&
|
|
1206
|
+
!task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
1207
|
+
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(task.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1207
1208
|
}
|
|
1208
1209
|
var _loop_4 = function (joker) {
|
|
1209
|
-
if (!
|
|
1210
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(
|
|
1210
|
+
if (!task.dependentParameterNames.includes(joker)) {
|
|
1211
|
+
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(task.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1211
1212
|
}
|
|
1212
1213
|
};
|
|
1213
1214
|
try {
|
|
1214
|
-
for (var _k = (e_4 = void 0, __values(
|
|
1215
|
+
for (var _k = (e_4 = void 0, __values(task.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
1215
1216
|
var joker = _l.value;
|
|
1216
1217
|
_loop_4(joker);
|
|
1217
1218
|
}
|
|
@@ -1224,7 +1225,7 @@
|
|
|
1224
1225
|
finally { if (e_4) throw e_4.error; }
|
|
1225
1226
|
}
|
|
1226
1227
|
}
|
|
1227
|
-
if (
|
|
1228
|
+
if (task.expectations) {
|
|
1228
1229
|
var _loop_5 = function (unit, min, max) {
|
|
1229
1230
|
if (min !== undefined && max !== undefined && min > max) {
|
|
1230
1231
|
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
@@ -1237,7 +1238,7 @@
|
|
|
1237
1238
|
}
|
|
1238
1239
|
};
|
|
1239
1240
|
try {
|
|
1240
|
-
for (var _m = (e_5 = void 0, __values(Object.entries(
|
|
1241
|
+
for (var _m = (e_5 = void 0, __values(Object.entries(task.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
1241
1242
|
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
1242
1243
|
_loop_5(unit, min, max);
|
|
1243
1244
|
}
|
|
@@ -1252,10 +1253,10 @@
|
|
|
1252
1253
|
}
|
|
1253
1254
|
};
|
|
1254
1255
|
try {
|
|
1255
|
-
// Note: Checking each
|
|
1256
|
-
for (var _f = __values(pipeline.
|
|
1257
|
-
var
|
|
1258
|
-
_loop_2(
|
|
1256
|
+
// Note: Checking each task individually
|
|
1257
|
+
for (var _f = __values(pipeline.tasks), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1258
|
+
var task = _g.value;
|
|
1259
|
+
_loop_2(task);
|
|
1259
1260
|
}
|
|
1260
1261
|
}
|
|
1261
1262
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -1289,15 +1290,15 @@
|
|
|
1289
1290
|
}
|
|
1290
1291
|
finally { if (e_3) throw e_3.error; }
|
|
1291
1292
|
}
|
|
1292
|
-
var unresovedTemplates = __spreadArray([], __read(pipeline.
|
|
1293
|
+
var unresovedTemplates = __spreadArray([], __read(pipeline.tasks), false);
|
|
1293
1294
|
var loopLimit = LOOP_LIMIT;
|
|
1294
1295
|
var _loop_3 = function () {
|
|
1295
1296
|
if (loopLimit-- < 0) {
|
|
1296
1297
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
1297
1298
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
1298
1299
|
}
|
|
1299
|
-
var currentlyResovedTemplates = unresovedTemplates.filter(function (
|
|
1300
|
-
return
|
|
1300
|
+
var currentlyResovedTemplates = unresovedTemplates.filter(function (task) {
|
|
1301
|
+
return task.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
1301
1302
|
});
|
|
1302
1303
|
if (currentlyResovedTemplates.length === 0) {
|
|
1303
1304
|
throw new PipelineLogicError(
|
|
@@ -1325,7 +1326,7 @@
|
|
|
1325
1326
|
var resultingParameterName = _a.resultingParameterName;
|
|
1326
1327
|
return resultingParameterName;
|
|
1327
1328
|
})), false);
|
|
1328
|
-
unresovedTemplates = unresovedTemplates.filter(function (
|
|
1329
|
+
unresovedTemplates = unresovedTemplates.filter(function (task) { return !currentlyResovedTemplates.includes(task); });
|
|
1329
1330
|
};
|
|
1330
1331
|
while (unresovedTemplates.length > 0) {
|
|
1331
1332
|
_loop_3();
|
|
@@ -1387,9 +1388,9 @@
|
|
|
1387
1388
|
}(Error));
|
|
1388
1389
|
|
|
1389
1390
|
/**
|
|
1390
|
-
* Parses the
|
|
1391
|
+
* Parses the task and returns the list of all parameter names
|
|
1391
1392
|
*
|
|
1392
|
-
* @param template the
|
|
1393
|
+
* @param template the task with parameters in {curly} braces
|
|
1393
1394
|
* @returns the list of parameter names
|
|
1394
1395
|
* @public exported from `@promptbook/utils`
|
|
1395
1396
|
*/
|
|
@@ -1420,10 +1421,10 @@
|
|
|
1420
1421
|
* @public exported from `@promptbook/core`
|
|
1421
1422
|
*/
|
|
1422
1423
|
function unpreparePipeline(pipeline) {
|
|
1423
|
-
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources,
|
|
1424
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, tasks = pipeline.tasks;
|
|
1424
1425
|
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
1425
1426
|
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
1426
|
-
|
|
1427
|
+
tasks = tasks.map(function (template) {
|
|
1427
1428
|
var dependentParameterNames = template.dependentParameterNames;
|
|
1428
1429
|
var parameterNames = extractParameterNames(template.preparedContent || '');
|
|
1429
1430
|
dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
|
|
@@ -1431,7 +1432,7 @@
|
|
|
1431
1432
|
delete templateUnprepared.preparedContent;
|
|
1432
1433
|
return templateUnprepared;
|
|
1433
1434
|
});
|
|
1434
|
-
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), {
|
|
1435
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1435
1436
|
}
|
|
1436
1437
|
/**
|
|
1437
1438
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1863,6 +1864,9 @@
|
|
|
1863
1864
|
normalizedName = normalizedName.replace(/-$/, '');
|
|
1864
1865
|
return normalizedName;
|
|
1865
1866
|
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1869
|
+
*/
|
|
1866
1870
|
|
|
1867
1871
|
/**
|
|
1868
1872
|
* Removes emojis from a string and fix whitespaces
|
|
@@ -2064,6 +2068,9 @@
|
|
|
2064
2068
|
UnexpectedError: UnexpectedError,
|
|
2065
2069
|
// TODO: [🪑]> VersionMismatchError,
|
|
2066
2070
|
};
|
|
2071
|
+
/**
|
|
2072
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2073
|
+
*/
|
|
2067
2074
|
|
|
2068
2075
|
/**
|
|
2069
2076
|
* Deserializes the error object
|
|
@@ -2125,8 +2132,8 @@
|
|
|
2125
2132
|
return false;
|
|
2126
2133
|
}
|
|
2127
2134
|
/*
|
|
2128
|
-
TODO: [🧠][🍫] `
|
|
2129
|
-
> if (!pipeline.
|
|
2135
|
+
TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2136
|
+
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2130
2137
|
> return false;
|
|
2131
2138
|
> }
|
|
2132
2139
|
*/
|
|
@@ -2139,7 +2146,7 @@
|
|
|
2139
2146
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2140
2147
|
* - [🏍] ? Is context in each template
|
|
2141
2148
|
* - [♨] Are examples prepared
|
|
2142
|
-
* - [♨] Are
|
|
2149
|
+
* - [♨] Are tasks prepared
|
|
2143
2150
|
*/
|
|
2144
2151
|
|
|
2145
2152
|
/**
|
|
@@ -2287,6 +2294,9 @@
|
|
|
2287
2294
|
pagesCount: { value: 0, isUncertain: true },
|
|
2288
2295
|
},
|
|
2289
2296
|
});
|
|
2297
|
+
/**
|
|
2298
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2299
|
+
*/
|
|
2290
2300
|
|
|
2291
2301
|
/**
|
|
2292
2302
|
* @@@
|
|
@@ -3473,7 +3483,7 @@
|
|
|
3473
3483
|
*/
|
|
3474
3484
|
function clonePipeline(pipeline) {
|
|
3475
3485
|
// Note: Not using spread operator (...) because @@@
|
|
3476
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters,
|
|
3486
|
+
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
3477
3487
|
return {
|
|
3478
3488
|
pipelineUrl: pipelineUrl,
|
|
3479
3489
|
sourceFile: sourceFile,
|
|
@@ -3482,7 +3492,7 @@
|
|
|
3482
3492
|
description: description,
|
|
3483
3493
|
formfactorName: formfactorName,
|
|
3484
3494
|
parameters: parameters,
|
|
3485
|
-
|
|
3495
|
+
tasks: tasks,
|
|
3486
3496
|
knowledgeSources: knowledgeSources,
|
|
3487
3497
|
knowledgePieces: knowledgePieces,
|
|
3488
3498
|
personas: personas,
|
|
@@ -3498,17 +3508,17 @@
|
|
|
3498
3508
|
*
|
|
3499
3509
|
* @public exported from `@promptbook/core`
|
|
3500
3510
|
*/
|
|
3501
|
-
function
|
|
3511
|
+
function prepareTasks(pipeline, tools, options) {
|
|
3502
3512
|
return __awaiter(this, void 0, void 0, function () {
|
|
3503
|
-
var _a, maxParallelCount,
|
|
3513
|
+
var _a, maxParallelCount, tasks, knowledgePiecesCount, tasksPrepared;
|
|
3504
3514
|
var _this = this;
|
|
3505
3515
|
return __generator(this, function (_b) {
|
|
3506
3516
|
switch (_b.label) {
|
|
3507
3517
|
case 0:
|
|
3508
3518
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
return [4 /*yield*/, forEachAsync(
|
|
3519
|
+
tasks = pipeline.tasks, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3520
|
+
tasksPrepared = new Array(tasks.length);
|
|
3521
|
+
return [4 /*yield*/, forEachAsync(tasks, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3512
3522
|
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
3513
3523
|
return __generator(this, function (_a) {
|
|
3514
3524
|
dependentParameterNames = template.dependentParameterNames;
|
|
@@ -3521,13 +3531,13 @@
|
|
|
3521
3531
|
], false);
|
|
3522
3532
|
}
|
|
3523
3533
|
preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
|
|
3524
|
-
|
|
3534
|
+
tasksPrepared[index] = preparedTemplate;
|
|
3525
3535
|
return [2 /*return*/];
|
|
3526
3536
|
});
|
|
3527
3537
|
}); })];
|
|
3528
3538
|
case 1:
|
|
3529
3539
|
_b.sent();
|
|
3530
|
-
return [2 /*return*/, {
|
|
3540
|
+
return [2 /*return*/, { tasksPrepared: tasksPrepared }];
|
|
3531
3541
|
}
|
|
3532
3542
|
});
|
|
3533
3543
|
});
|
|
@@ -3535,7 +3545,7 @@
|
|
|
3535
3545
|
/**
|
|
3536
3546
|
* TODO: [🧠] Add context to each template (if missing)
|
|
3537
3547
|
* TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
3538
|
-
* TODO: [♨][main] !!! Prepare index the examples and maybe
|
|
3548
|
+
* TODO: [♨][main] !!! Prepare index the examples and maybe tasks
|
|
3539
3549
|
* TODO: Write tests for `preparePipeline`
|
|
3540
3550
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3541
3551
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3552,12 +3562,12 @@
|
|
|
3552
3562
|
*/
|
|
3553
3563
|
function preparePipeline(pipeline, tools, options) {
|
|
3554
3564
|
return __awaiter(this, void 0, void 0, function () {
|
|
3555
|
-
var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters,
|
|
3565
|
+
var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters, tasks,
|
|
3556
3566
|
/*
|
|
3557
3567
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
3558
3568
|
knowledgeSources /*
|
|
3559
3569
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3560
|
-
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared,
|
|
3570
|
+
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3561
3571
|
var _this = this;
|
|
3562
3572
|
return __generator(this, function (_c) {
|
|
3563
3573
|
switch (_c.label) {
|
|
@@ -3566,7 +3576,7 @@
|
|
|
3566
3576
|
return [2 /*return*/, pipeline];
|
|
3567
3577
|
}
|
|
3568
3578
|
rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
3569
|
-
parameters = pipeline.parameters,
|
|
3579
|
+
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3570
3580
|
if (tools === undefined || tools.llm === undefined) {
|
|
3571
3581
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
3572
3582
|
}
|
|
@@ -3609,9 +3619,9 @@
|
|
|
3609
3619
|
case 2:
|
|
3610
3620
|
partialknowledgePiecesPrepared = _c.sent();
|
|
3611
3621
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3612
|
-
return [4 /*yield*/,
|
|
3622
|
+
return [4 /*yield*/, prepareTasks({
|
|
3613
3623
|
parameters: parameters,
|
|
3614
|
-
|
|
3624
|
+
tasks: tasks,
|
|
3615
3625
|
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
3616
3626
|
}, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
3617
3627
|
rootDirname: rootDirname,
|
|
@@ -3619,12 +3629,12 @@
|
|
|
3619
3629
|
isVerbose: isVerbose,
|
|
3620
3630
|
})];
|
|
3621
3631
|
case 3:
|
|
3622
|
-
|
|
3632
|
+
tasksPrepared = (_c.sent()).tasksPrepared;
|
|
3623
3633
|
// ----- /Templates preparation -----
|
|
3624
3634
|
// Note: Count total usage
|
|
3625
3635
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
3626
|
-
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), {
|
|
3627
|
-
// <- TODO: [🪓] Here should be no need for spreading new array, just `
|
|
3636
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3637
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
3628
3638
|
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }))];
|
|
3629
3639
|
}
|
|
3630
3640
|
});
|
|
@@ -3696,9 +3706,9 @@
|
|
|
3696
3706
|
* @throws {ParseError} if the script is invalid
|
|
3697
3707
|
* @public exported from `@promptbook/utils`
|
|
3698
3708
|
*/
|
|
3699
|
-
function
|
|
3709
|
+
function extractParameterNamesFromTask(template) {
|
|
3700
3710
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
3701
|
-
var title = template.title, description = template.description,
|
|
3711
|
+
var title = template.title, description = template.description, taskType = template.taskType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
|
|
3702
3712
|
var parameterNames = new Set();
|
|
3703
3713
|
try {
|
|
3704
3714
|
for (var _e = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
@@ -3713,7 +3723,7 @@
|
|
|
3713
3723
|
}
|
|
3714
3724
|
finally { if (e_1) throw e_1.error; }
|
|
3715
3725
|
}
|
|
3716
|
-
if (
|
|
3726
|
+
if (taskType === 'SCRIPT_TASK') {
|
|
3717
3727
|
try {
|
|
3718
3728
|
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
3719
3729
|
var parameterName = _h.value;
|
|
@@ -4123,6 +4133,9 @@
|
|
|
4123
4133
|
TextFormatDefinition,
|
|
4124
4134
|
CsvFormatDefinition,
|
|
4125
4135
|
];
|
|
4136
|
+
/**
|
|
4137
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4138
|
+
*/
|
|
4126
4139
|
|
|
4127
4140
|
/**
|
|
4128
4141
|
* Maps available parameters to expected parameters
|
|
@@ -4223,7 +4236,7 @@
|
|
|
4223
4236
|
}
|
|
4224
4237
|
finally { if (e_1) throw e_1.error; }
|
|
4225
4238
|
}
|
|
4226
|
-
var
|
|
4239
|
+
var replacedTemplates = template;
|
|
4227
4240
|
var match;
|
|
4228
4241
|
var loopLimit = LOOP_LIMIT;
|
|
4229
4242
|
var _loop_1 = function () {
|
|
@@ -4252,24 +4265,24 @@
|
|
|
4252
4265
|
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
4253
4266
|
.join('\n');
|
|
4254
4267
|
}
|
|
4255
|
-
|
|
4256
|
-
|
|
4268
|
+
replacedTemplates =
|
|
4269
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
4257
4270
|
parameterValue +
|
|
4258
|
-
|
|
4271
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
4259
4272
|
};
|
|
4260
4273
|
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
4261
|
-
.exec(
|
|
4274
|
+
.exec(replacedTemplates))) {
|
|
4262
4275
|
_loop_1();
|
|
4263
4276
|
}
|
|
4264
4277
|
// [💫] Check if there are parameters that are not closed properly
|
|
4265
|
-
if (/{\w+$/.test(
|
|
4278
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
4266
4279
|
throw new PipelineExecutionError('Parameter is not closed');
|
|
4267
4280
|
}
|
|
4268
4281
|
// [💫] Check if there are parameters that are not opened properly
|
|
4269
|
-
if (/^\w+}/.test(
|
|
4282
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
4270
4283
|
throw new PipelineExecutionError('Parameter is not opened');
|
|
4271
4284
|
}
|
|
4272
|
-
return
|
|
4285
|
+
return replacedTemplates;
|
|
4273
4286
|
}
|
|
4274
4287
|
|
|
4275
4288
|
/**
|
|
@@ -4301,6 +4314,7 @@
|
|
|
4301
4314
|
var LINES_PER_STANDARD_PAGE = 44;
|
|
4302
4315
|
/**
|
|
4303
4316
|
* TODO: [🧠] Should be this `constants.ts` or `config.ts`?
|
|
4317
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4304
4318
|
*/
|
|
4305
4319
|
|
|
4306
4320
|
/**
|
|
@@ -4380,6 +4394,7 @@
|
|
|
4380
4394
|
};
|
|
4381
4395
|
/**
|
|
4382
4396
|
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
4397
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4383
4398
|
*/
|
|
4384
4399
|
|
|
4385
4400
|
/**
|
|
@@ -4428,12 +4443,12 @@
|
|
|
4428
4443
|
*/
|
|
4429
4444
|
function executeAttempts(options) {
|
|
4430
4445
|
return __awaiter(this, void 0, void 0, function () {
|
|
4431
|
-
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters,
|
|
4446
|
+
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTaskResult, _llms, llmTools, _loop_1, attempt, state_1;
|
|
4432
4447
|
return __generator(this, function (_a) {
|
|
4433
4448
|
switch (_a.label) {
|
|
4434
4449
|
case 0:
|
|
4435
|
-
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters,
|
|
4436
|
-
$
|
|
4450
|
+
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, task = options.task, preparedPipeline = options.preparedPipeline, tools = options.tools, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, maxExecutionAttempts = options.maxExecutionAttempts;
|
|
4451
|
+
$ongoingTaskResult = {
|
|
4437
4452
|
$result: null,
|
|
4438
4453
|
$resultString: null,
|
|
4439
4454
|
$expectError: null,
|
|
@@ -4453,52 +4468,51 @@
|
|
|
4453
4468
|
if (isJokerAttempt && !jokerParameterName) {
|
|
4454
4469
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4455
4470
|
}
|
|
4456
|
-
$
|
|
4457
|
-
$
|
|
4458
|
-
$
|
|
4471
|
+
$ongoingTaskResult.$result = null;
|
|
4472
|
+
$ongoingTaskResult.$resultString = null;
|
|
4473
|
+
$ongoingTaskResult.$expectError = null;
|
|
4459
4474
|
if (isJokerAttempt) {
|
|
4460
4475
|
if (parameters[jokerParameterName] === undefined) {
|
|
4461
4476
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4462
4477
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
4463
4478
|
}
|
|
4464
4479
|
else {
|
|
4465
|
-
$
|
|
4480
|
+
$ongoingTaskResult.$resultString = parameters[jokerParameterName];
|
|
4466
4481
|
}
|
|
4467
4482
|
}
|
|
4468
4483
|
_t.label = 1;
|
|
4469
4484
|
case 1:
|
|
4470
4485
|
_t.trys.push([1, 43, 44, 45]);
|
|
4471
4486
|
if (!!isJokerAttempt) return [3 /*break*/, 25];
|
|
4472
|
-
_b =
|
|
4487
|
+
_b = task.taskType;
|
|
4473
4488
|
switch (_b) {
|
|
4474
|
-
case '
|
|
4475
|
-
case '
|
|
4476
|
-
case '
|
|
4477
|
-
case '
|
|
4489
|
+
case 'SIMPLE_TASK': return [3 /*break*/, 2];
|
|
4490
|
+
case 'PROMPT_TASK': return [3 /*break*/, 3];
|
|
4491
|
+
case 'SCRIPT_TASK': return [3 /*break*/, 11];
|
|
4492
|
+
case 'DIALOG_TASK': return [3 /*break*/, 22];
|
|
4478
4493
|
}
|
|
4479
4494
|
return [3 /*break*/, 24];
|
|
4480
4495
|
case 2:
|
|
4481
|
-
$
|
|
4496
|
+
$ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
4482
4497
|
return [3 /*break*/, 25];
|
|
4483
4498
|
case 3:
|
|
4484
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (
|
|
4485
|
-
$
|
|
4486
|
-
title:
|
|
4499
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
4500
|
+
$ongoingTaskResult.$prompt = {
|
|
4501
|
+
title: task.title,
|
|
4487
4502
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
4488
4503
|
? preparedPipeline.pipelineUrl
|
|
4489
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(
|
|
4490
|
-
// <- TODO: Here should be maybe also subformat index to distinguish between same
|
|
4504
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(task.name
|
|
4505
|
+
// <- TODO: Here should be maybe also subformat index to distinguish between same task with different subformat values
|
|
4491
4506
|
),
|
|
4492
4507
|
parameters: parameters,
|
|
4493
4508
|
content: preparedContent,
|
|
4494
4509
|
modelRequirements: modelRequirements,
|
|
4495
4510
|
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
4496
4511
|
var name = _a.name;
|
|
4497
|
-
return name ===
|
|
4498
|
-
}) ||
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
postprocessingFunctionNames: template.postprocessingFunctionNames,
|
|
4512
|
+
return name === task.personaName;
|
|
4513
|
+
}) || {})), task.expectations),
|
|
4514
|
+
format: task.format,
|
|
4515
|
+
postprocessingFunctionNames: task.postprocessingFunctionNames,
|
|
4502
4516
|
}; // <- TODO: Not very good type guard
|
|
4503
4517
|
_c = modelRequirements.modelVariant;
|
|
4504
4518
|
switch (_c) {
|
|
@@ -4508,36 +4522,35 @@
|
|
|
4508
4522
|
}
|
|
4509
4523
|
return [3 /*break*/, 9];
|
|
4510
4524
|
case 4:
|
|
4511
|
-
_d = $
|
|
4525
|
+
_d = $ongoingTaskResult;
|
|
4512
4526
|
return [4 /*yield*/, llmTools.callChatModel(
|
|
4513
4527
|
// <- TODO: [🧁] Check that `callChatModel` is defined
|
|
4514
|
-
$deepFreeze($
|
|
4528
|
+
$deepFreeze($ongoingTaskResult.$prompt))];
|
|
4515
4529
|
case 5:
|
|
4516
4530
|
_d.$chatResult = _t.sent();
|
|
4517
4531
|
// TODO: [🍬] Destroy chatThread
|
|
4518
|
-
$
|
|
4519
|
-
$
|
|
4532
|
+
$ongoingTaskResult.$result = $ongoingTaskResult.$chatResult;
|
|
4533
|
+
$ongoingTaskResult.$resultString = $ongoingTaskResult.$chatResult.content;
|
|
4520
4534
|
return [3 /*break*/, 10];
|
|
4521
4535
|
case 6:
|
|
4522
|
-
_e = $
|
|
4536
|
+
_e = $ongoingTaskResult;
|
|
4523
4537
|
return [4 /*yield*/, llmTools.callCompletionModel(
|
|
4524
4538
|
// <- TODO: [🧁] Check that `callCompletionModel` is defined
|
|
4525
|
-
$deepFreeze($
|
|
4539
|
+
$deepFreeze($ongoingTaskResult.$prompt))];
|
|
4526
4540
|
case 7:
|
|
4527
4541
|
_e.$completionResult = _t.sent();
|
|
4528
|
-
$
|
|
4529
|
-
$
|
|
4530
|
-
$ongoingTemplateResult.$completionResult.content;
|
|
4542
|
+
$ongoingTaskResult.$result = $ongoingTaskResult.$completionResult;
|
|
4543
|
+
$ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
|
|
4531
4544
|
return [3 /*break*/, 10];
|
|
4532
4545
|
case 8: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Embedding model can not be used in pipeline\n\n This should be catched during parsing\n\n ".concat(block(pipelineIdentification), "\n\n "); }));
|
|
4533
|
-
case 9: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(
|
|
4546
|
+
case 9: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(task.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
4534
4547
|
case 10: return [3 /*break*/, 25];
|
|
4535
4548
|
case 11:
|
|
4536
4549
|
if (arrayableToArray(tools.script).length === 0) {
|
|
4537
4550
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4538
4551
|
}
|
|
4539
|
-
if (!
|
|
4540
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT
|
|
4552
|
+
if (!task.contentLanguage) {
|
|
4553
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TASK \"".concat(task.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4541
4554
|
}
|
|
4542
4555
|
_t.label = 12;
|
|
4543
4556
|
case 12:
|
|
@@ -4550,9 +4563,9 @@
|
|
|
4550
4563
|
_t.label = 14;
|
|
4551
4564
|
case 14:
|
|
4552
4565
|
_t.trys.push([14, 16, , 17]);
|
|
4553
|
-
_h = $
|
|
4566
|
+
_h = $ongoingTaskResult;
|
|
4554
4567
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
4555
|
-
scriptLanguage:
|
|
4568
|
+
scriptLanguage: task.contentLanguage,
|
|
4556
4569
|
script: preparedContent,
|
|
4557
4570
|
parameters: parameters,
|
|
4558
4571
|
}))];
|
|
@@ -4567,7 +4580,7 @@
|
|
|
4567
4580
|
if (error_1 instanceof UnexpectedError) {
|
|
4568
4581
|
throw error_1;
|
|
4569
4582
|
}
|
|
4570
|
-
$
|
|
4583
|
+
$ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
4571
4584
|
return [3 /*break*/, 17];
|
|
4572
4585
|
case 17:
|
|
4573
4586
|
_g = _f.next();
|
|
@@ -4584,14 +4597,14 @@
|
|
|
4584
4597
|
finally { if (e_1) throw e_1.error; }
|
|
4585
4598
|
return [7 /*endfinally*/];
|
|
4586
4599
|
case 21:
|
|
4587
|
-
if ($
|
|
4600
|
+
if ($ongoingTaskResult.$resultString !== null) {
|
|
4588
4601
|
return [3 /*break*/, 25];
|
|
4589
4602
|
}
|
|
4590
|
-
if ($
|
|
4591
|
-
throw $
|
|
4603
|
+
if ($ongoingTaskResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
4604
|
+
throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
|
|
4592
4605
|
}
|
|
4593
4606
|
else {
|
|
4594
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat($
|
|
4607
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingTaskResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTaskResult.$scriptPipelineExecutionErrors
|
|
4595
4608
|
.map(function (error) { return '- ' + error.message; })
|
|
4596
4609
|
.join('\n\n')), "\n "); }));
|
|
4597
4610
|
}
|
|
@@ -4599,27 +4612,27 @@
|
|
|
4599
4612
|
if (tools.userInterface === undefined) {
|
|
4600
4613
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4601
4614
|
}
|
|
4602
|
-
// TODO: [🌹] When making next attempt for `DIALOG
|
|
4603
|
-
_j = $
|
|
4615
|
+
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
4616
|
+
_j = $ongoingTaskResult;
|
|
4604
4617
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
4605
|
-
promptTitle:
|
|
4606
|
-
promptMessage: replaceParameters(
|
|
4618
|
+
promptTitle: task.title,
|
|
4619
|
+
promptMessage: replaceParameters(task.description || '', parameters),
|
|
4607
4620
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
4608
4621
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
4609
4622
|
placeholder: undefined,
|
|
4610
4623
|
priority: priority,
|
|
4611
4624
|
}))];
|
|
4612
4625
|
case 23:
|
|
4613
|
-
// TODO: [🌹] When making next attempt for `DIALOG
|
|
4626
|
+
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
4614
4627
|
_j.$resultString = _t.sent();
|
|
4615
4628
|
return [3 /*break*/, 25];
|
|
4616
|
-
case 24: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(
|
|
4629
|
+
case 24: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4617
4630
|
case 25:
|
|
4618
|
-
if (!(!isJokerAttempt &&
|
|
4631
|
+
if (!(!isJokerAttempt && task.postprocessingFunctionNames)) return [3 /*break*/, 42];
|
|
4619
4632
|
_t.label = 26;
|
|
4620
4633
|
case 26:
|
|
4621
4634
|
_t.trys.push([26, 40, 41, 42]);
|
|
4622
|
-
_k = (e_3 = void 0, __values(
|
|
4635
|
+
_k = (e_3 = void 0, __values(task.postprocessingFunctionNames)), _l = _k.next();
|
|
4623
4636
|
_t.label = 27;
|
|
4624
4637
|
case 27:
|
|
4625
4638
|
if (!!_l.done) return [3 /*break*/, 39];
|
|
@@ -4636,13 +4649,13 @@
|
|
|
4636
4649
|
_t.label = 30;
|
|
4637
4650
|
case 30:
|
|
4638
4651
|
_t.trys.push([30, 32, , 33]);
|
|
4639
|
-
_p = $
|
|
4652
|
+
_p = $ongoingTaskResult;
|
|
4640
4653
|
return [4 /*yield*/, scriptTools.execute({
|
|
4641
4654
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
4642
4655
|
script: "".concat(functionName, "(resultString)"),
|
|
4643
4656
|
parameters: {
|
|
4644
|
-
resultString: $
|
|
4645
|
-
// Note: No ...
|
|
4657
|
+
resultString: $ongoingTaskResult.$resultString || '',
|
|
4658
|
+
// Note: No ...parametersForTask, because working with result only
|
|
4646
4659
|
},
|
|
4647
4660
|
})];
|
|
4648
4661
|
case 31:
|
|
@@ -4658,7 +4671,7 @@
|
|
|
4658
4671
|
throw error_2;
|
|
4659
4672
|
}
|
|
4660
4673
|
postprocessingError = error_2;
|
|
4661
|
-
$
|
|
4674
|
+
$ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
4662
4675
|
return [3 /*break*/, 33];
|
|
4663
4676
|
case 33:
|
|
4664
4677
|
_o = _m.next();
|
|
@@ -4695,12 +4708,12 @@
|
|
|
4695
4708
|
return [7 /*endfinally*/];
|
|
4696
4709
|
case 42:
|
|
4697
4710
|
// TODO: [💝] Unite object for expecting amount and format
|
|
4698
|
-
if (
|
|
4699
|
-
if (
|
|
4700
|
-
if (!isValidJsonString($
|
|
4711
|
+
if (task.format) {
|
|
4712
|
+
if (task.format === 'JSON') {
|
|
4713
|
+
if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
|
|
4701
4714
|
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
4702
4715
|
try {
|
|
4703
|
-
$
|
|
4716
|
+
$ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
|
|
4704
4717
|
}
|
|
4705
4718
|
catch (error) {
|
|
4706
4719
|
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
@@ -4709,12 +4722,12 @@
|
|
|
4709
4722
|
}
|
|
4710
4723
|
}
|
|
4711
4724
|
else {
|
|
4712
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(
|
|
4725
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4713
4726
|
}
|
|
4714
4727
|
}
|
|
4715
4728
|
// TODO: [💝] Unite object for expecting amount and format
|
|
4716
|
-
if (
|
|
4717
|
-
checkExpectations(
|
|
4729
|
+
if (task.expectations) {
|
|
4730
|
+
checkExpectations(task.expectations, $ongoingTaskResult.$resultString || '');
|
|
4718
4731
|
}
|
|
4719
4732
|
return [2 /*return*/, "break-attempts"];
|
|
4720
4733
|
case 43:
|
|
@@ -4722,38 +4735,38 @@
|
|
|
4722
4735
|
if (!(error_3 instanceof ExpectError)) {
|
|
4723
4736
|
throw error_3;
|
|
4724
4737
|
}
|
|
4725
|
-
$
|
|
4738
|
+
$ongoingTaskResult.$expectError = error_3;
|
|
4726
4739
|
return [3 /*break*/, 45];
|
|
4727
4740
|
case 44:
|
|
4728
4741
|
if (!isJokerAttempt &&
|
|
4729
|
-
|
|
4730
|
-
$
|
|
4742
|
+
task.taskType === 'PROMPT_TASK' &&
|
|
4743
|
+
$ongoingTaskResult.$prompt
|
|
4731
4744
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
4732
4745
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
4733
4746
|
) {
|
|
4734
|
-
// TODO: [🧠] Maybe put other
|
|
4747
|
+
// TODO: [🧠] Maybe put other taskTypes into report
|
|
4735
4748
|
$executionReport.promptExecutions.push({
|
|
4736
|
-
prompt: __assign({}, $
|
|
4737
|
-
result: $
|
|
4738
|
-
error: $
|
|
4749
|
+
prompt: __assign({}, $ongoingTaskResult.$prompt),
|
|
4750
|
+
result: $ongoingTaskResult.$result || undefined,
|
|
4751
|
+
error: $ongoingTaskResult.$expectError === null
|
|
4739
4752
|
? undefined
|
|
4740
|
-
: serializeError($
|
|
4753
|
+
: serializeError($ongoingTaskResult.$expectError),
|
|
4741
4754
|
});
|
|
4742
4755
|
}
|
|
4743
4756
|
return [7 /*endfinally*/];
|
|
4744
4757
|
case 45:
|
|
4745
|
-
if ($
|
|
4758
|
+
if ($ongoingTaskResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
4746
4759
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
|
|
4747
4760
|
var _a, _b, _c;
|
|
4748
|
-
return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $
|
|
4761
|
+
return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTaskResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
|
|
4749
4762
|
.split('\n')
|
|
4750
4763
|
.map(function (line) { return "> ".concat(line); })
|
|
4751
|
-
.join('\n')), "\n\n Last error ").concat(((_b = $
|
|
4764
|
+
.join('\n')), "\n\n Last error ").concat(((_b = $ongoingTaskResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingTaskResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
|
|
4752
4765
|
.split('\n')
|
|
4753
4766
|
.map(function (line) { return "> ".concat(line); })
|
|
4754
|
-
.join('\n')), "\n\n Last result:\n ").concat(block($
|
|
4767
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingTaskResult.$resultString === null
|
|
4755
4768
|
? 'null'
|
|
4756
|
-
: $
|
|
4769
|
+
: $ongoingTaskResult.$resultString
|
|
4757
4770
|
.split('\n')
|
|
4758
4771
|
.map(function (line) { return "> ".concat(line); })
|
|
4759
4772
|
.join('\n')), "\n ---\n ");
|
|
@@ -4778,10 +4791,10 @@
|
|
|
4778
4791
|
attempt++;
|
|
4779
4792
|
return [3 /*break*/, 1];
|
|
4780
4793
|
case 4:
|
|
4781
|
-
if ($
|
|
4794
|
+
if ($ongoingTaskResult.$resultString === null) {
|
|
4782
4795
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4783
4796
|
}
|
|
4784
|
-
return [2 /*return*/, $
|
|
4797
|
+
return [2 /*return*/, $ongoingTaskResult.$resultString];
|
|
4785
4798
|
}
|
|
4786
4799
|
});
|
|
4787
4800
|
});
|
|
@@ -4797,36 +4810,36 @@
|
|
|
4797
4810
|
*/
|
|
4798
4811
|
function executeFormatSubvalues(options) {
|
|
4799
4812
|
return __awaiter(this, void 0, void 0, function () {
|
|
4800
|
-
var
|
|
4813
|
+
var task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
|
|
4801
4814
|
var _this = this;
|
|
4802
4815
|
return __generator(this, function (_a) {
|
|
4803
4816
|
switch (_a.label) {
|
|
4804
4817
|
case 0:
|
|
4805
|
-
|
|
4806
|
-
if (
|
|
4818
|
+
task = options.task, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, csvSettings = options.csvSettings, pipelineIdentification = options.pipelineIdentification;
|
|
4819
|
+
if (task.foreach === undefined) {
|
|
4807
4820
|
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
4808
4821
|
}
|
|
4809
4822
|
if (jokerParameterNames.length !== 0) {
|
|
4810
4823
|
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n JOKER parameters are not supported together with FOREACH command\n\n [\uD83E\uDDDE\u200D\u2640\uFE0F] This should be prevented in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4811
4824
|
}
|
|
4812
|
-
parameterValue = parameters[
|
|
4825
|
+
parameterValue = parameters[task.foreach.parameterName] || '';
|
|
4813
4826
|
formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
|
|
4814
|
-
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(
|
|
4827
|
+
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(task.foreach.formatName);
|
|
4815
4828
|
});
|
|
4816
4829
|
if (formatDefinition === undefined) {
|
|
4817
4830
|
throw new UnexpectedError(
|
|
4818
4831
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
4819
|
-
spaceTrim__default["default"](function (block) { return "\n Unsupported format \"".concat(
|
|
4832
|
+
spaceTrim__default["default"](function (block) { return "\n Unsupported format \"".concat(task.foreach.formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
|
|
4820
4833
|
.map(function (formatName) { return "- ".concat(formatName); })
|
|
4821
4834
|
.join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4822
4835
|
}
|
|
4823
4836
|
subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
4824
|
-
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(
|
|
4837
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(task.foreach.subformatName);
|
|
4825
4838
|
});
|
|
4826
4839
|
if (subvalueDefinition === undefined) {
|
|
4827
4840
|
throw new UnexpectedError(
|
|
4828
4841
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
4829
|
-
spaceTrim__default["default"](function (block) { return "\n Unsupported subformat name \"".concat(
|
|
4842
|
+
spaceTrim__default["default"](function (block) { return "\n Unsupported subformat name \"".concat(task.foreach.subformatName, "\" for format \"").concat(task.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
|
|
4830
4843
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
4831
4844
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
4832
4845
|
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
@@ -4835,7 +4848,7 @@
|
|
|
4835
4848
|
formatSettings = csvSettings;
|
|
4836
4849
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
4837
4850
|
}
|
|
4838
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue,
|
|
4851
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4839
4852
|
var mappedParameters, allSubparameters, subresultString;
|
|
4840
4853
|
return __generator(this, function (_a) {
|
|
4841
4854
|
switch (_a.label) {
|
|
@@ -4844,7 +4857,7 @@
|
|
|
4844
4857
|
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
4845
4858
|
try {
|
|
4846
4859
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
4847
|
-
expectedParameters: Object.fromEntries(
|
|
4860
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
4848
4861
|
availableParameters: subparameters,
|
|
4849
4862
|
});
|
|
4850
4863
|
}
|
|
@@ -4877,7 +4890,7 @@
|
|
|
4877
4890
|
*
|
|
4878
4891
|
* @private internal utility of `createPipelineExecutor`
|
|
4879
4892
|
*/
|
|
4880
|
-
function
|
|
4893
|
+
function getContextForTask(task) {
|
|
4881
4894
|
return __awaiter(this, void 0, void 0, function () {
|
|
4882
4895
|
return __generator(this, function (_a) {
|
|
4883
4896
|
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
@@ -4890,15 +4903,10 @@
|
|
|
4890
4903
|
*
|
|
4891
4904
|
* @private internal utility of `createPipelineExecutor`
|
|
4892
4905
|
*/
|
|
4893
|
-
function
|
|
4906
|
+
function getExamplesForTask(task) {
|
|
4894
4907
|
return __awaiter(this, void 0, void 0, function () {
|
|
4895
|
-
var preparedPipeline;
|
|
4896
4908
|
return __generator(this, function (_a) {
|
|
4897
|
-
|
|
4898
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
4899
|
-
var content = _a.content;
|
|
4900
|
-
return "- ".concat(content);
|
|
4901
|
-
}).join('\n')];
|
|
4909
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
4902
4910
|
});
|
|
4903
4911
|
});
|
|
4904
4912
|
}
|
|
@@ -4908,10 +4916,15 @@
|
|
|
4908
4916
|
*
|
|
4909
4917
|
* @private internal utility of `createPipelineExecutor`
|
|
4910
4918
|
*/
|
|
4911
|
-
function
|
|
4919
|
+
function getKnowledgeForTask(options) {
|
|
4912
4920
|
return __awaiter(this, void 0, void 0, function () {
|
|
4921
|
+
var preparedPipeline;
|
|
4913
4922
|
return __generator(this, function (_a) {
|
|
4914
|
-
|
|
4923
|
+
preparedPipeline = options.preparedPipeline, options.task;
|
|
4924
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
4925
|
+
var content = _a.content;
|
|
4926
|
+
return "- ".concat(content);
|
|
4927
|
+
}).join('\n')];
|
|
4915
4928
|
});
|
|
4916
4929
|
});
|
|
4917
4930
|
}
|
|
@@ -4921,21 +4934,21 @@
|
|
|
4921
4934
|
*
|
|
4922
4935
|
* @private internal utility of `createPipelineExecutor`
|
|
4923
4936
|
*/
|
|
4924
|
-
function
|
|
4937
|
+
function getReservedParametersForTask(options) {
|
|
4925
4938
|
return __awaiter(this, void 0, void 0, function () {
|
|
4926
|
-
var preparedPipeline,
|
|
4939
|
+
var preparedPipeline, task, pipelineIdentification, context, knowledge, examples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
4927
4940
|
var e_1, _a;
|
|
4928
4941
|
return __generator(this, function (_b) {
|
|
4929
4942
|
switch (_b.label) {
|
|
4930
4943
|
case 0:
|
|
4931
|
-
preparedPipeline = options.preparedPipeline,
|
|
4932
|
-
return [4 /*yield*/,
|
|
4944
|
+
preparedPipeline = options.preparedPipeline, task = options.task, pipelineIdentification = options.pipelineIdentification;
|
|
4945
|
+
return [4 /*yield*/, getContextForTask()];
|
|
4933
4946
|
case 1:
|
|
4934
4947
|
context = _b.sent();
|
|
4935
|
-
return [4 /*yield*/,
|
|
4948
|
+
return [4 /*yield*/, getKnowledgeForTask({ preparedPipeline: preparedPipeline, task: task })];
|
|
4936
4949
|
case 2:
|
|
4937
4950
|
knowledge = _b.sent();
|
|
4938
|
-
return [4 /*yield*/,
|
|
4951
|
+
return [4 /*yield*/, getExamplesForTask()];
|
|
4939
4952
|
case 3:
|
|
4940
4953
|
examples = _b.sent();
|
|
4941
4954
|
currentDate = new Date().toISOString();
|
|
@@ -4978,31 +4991,31 @@
|
|
|
4978
4991
|
*
|
|
4979
4992
|
* @private internal utility of `createPipelineExecutor`
|
|
4980
4993
|
*/
|
|
4981
|
-
function
|
|
4994
|
+
function executeTask(options) {
|
|
4982
4995
|
return __awaiter(this, void 0, void 0, function () {
|
|
4983
|
-
var
|
|
4996
|
+
var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, _a, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _b, _c, _d, definedParameterNames, parameters, _loop_1, _e, _f, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
|
|
4984
4997
|
var e_1, _g, _h;
|
|
4985
4998
|
return __generator(this, function (_j) {
|
|
4986
4999
|
switch (_j.label) {
|
|
4987
5000
|
case 0:
|
|
4988
|
-
|
|
4989
|
-
name = "pipeline-executor-frame-".concat(
|
|
4990
|
-
title =
|
|
4991
|
-
priority = preparedPipeline.
|
|
5001
|
+
currentTask = options.currentTask, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a;
|
|
5002
|
+
name = "pipeline-executor-frame-".concat(currentTask.name);
|
|
5003
|
+
title = currentTask.title;
|
|
5004
|
+
priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
4992
5005
|
return [4 /*yield*/, onProgress({
|
|
4993
5006
|
name: name,
|
|
4994
5007
|
title: title,
|
|
4995
5008
|
isStarted: false,
|
|
4996
5009
|
isDone: false,
|
|
4997
|
-
|
|
4998
|
-
parameterName:
|
|
5010
|
+
taskType: currentTask.taskType,
|
|
5011
|
+
parameterName: currentTask.resultingParameterName,
|
|
4999
5012
|
parameterValue: null,
|
|
5000
5013
|
// <- [🍸]
|
|
5001
5014
|
})];
|
|
5002
5015
|
case 1:
|
|
5003
5016
|
_j.sent();
|
|
5004
|
-
usedParameterNames =
|
|
5005
|
-
dependentParameterNames = new Set(
|
|
5017
|
+
usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5018
|
+
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
5006
5019
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
5007
5020
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
5008
5021
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames)
|
|
@@ -5013,9 +5026,9 @@
|
|
|
5013
5026
|
}
|
|
5014
5027
|
_c = (_b = Object).freeze;
|
|
5015
5028
|
_d = [{}];
|
|
5016
|
-
return [4 /*yield*/,
|
|
5029
|
+
return [4 /*yield*/, getReservedParametersForTask({
|
|
5017
5030
|
preparedPipeline: preparedPipeline,
|
|
5018
|
-
|
|
5031
|
+
task: currentTask,
|
|
5019
5032
|
pipelineIdentification: pipelineIdentification,
|
|
5020
5033
|
})];
|
|
5021
5034
|
case 2:
|
|
@@ -5033,11 +5046,11 @@
|
|
|
5033
5046
|
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
5034
5047
|
// Houston, we have a problem
|
|
5035
5048
|
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
5036
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in
|
|
5049
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in task \"").concat(currentTask.title || currentTask.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
5037
5050
|
}
|
|
5038
5051
|
};
|
|
5039
5052
|
try {
|
|
5040
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this
|
|
5053
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this task
|
|
5041
5054
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
5042
5055
|
for (_e = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
5043
5056
|
parameterName = _f.value;
|
|
@@ -5053,18 +5066,16 @@
|
|
|
5053
5066
|
}
|
|
5054
5067
|
// Note: [👨👨👧] Now we can freeze `parameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
5055
5068
|
Object.freeze(parameters);
|
|
5056
|
-
maxAttempts =
|
|
5057
|
-
jokerParameterNames =
|
|
5058
|
-
preparedContent = (
|
|
5059
|
-
.split('{content}')
|
|
5060
|
-
.join(currentTemplate.content);
|
|
5069
|
+
maxAttempts = currentTask.taskType === 'DIALOG_TASK' ? Infinity : maxExecutionAttempts;
|
|
5070
|
+
jokerParameterNames = currentTask.jokerParameterNames || [];
|
|
5071
|
+
preparedContent = (currentTask.preparedContent || '{content}').split('{content}').join(currentTask.content);
|
|
5061
5072
|
return [4 /*yield*/, executeFormatSubvalues({
|
|
5062
5073
|
jokerParameterNames: jokerParameterNames,
|
|
5063
5074
|
priority: priority,
|
|
5064
5075
|
maxAttempts: maxAttempts,
|
|
5065
5076
|
preparedContent: preparedContent,
|
|
5066
5077
|
parameters: parameters,
|
|
5067
|
-
|
|
5078
|
+
task: currentTask,
|
|
5068
5079
|
preparedPipeline: preparedPipeline,
|
|
5069
5080
|
tools: tools,
|
|
5070
5081
|
$executionReport: $executionReport,
|
|
@@ -5077,15 +5088,15 @@
|
|
|
5077
5088
|
title: title,
|
|
5078
5089
|
isStarted: true,
|
|
5079
5090
|
isDone: true,
|
|
5080
|
-
|
|
5081
|
-
parameterName:
|
|
5091
|
+
taskType: currentTask.taskType,
|
|
5092
|
+
parameterName: currentTask.resultingParameterName,
|
|
5082
5093
|
parameterValue: resultString,
|
|
5083
5094
|
// <- [🍸]
|
|
5084
5095
|
})];
|
|
5085
5096
|
case 4:
|
|
5086
5097
|
_j.sent();
|
|
5087
5098
|
return [2 /*return*/, Object.freeze((_h = {},
|
|
5088
|
-
_h[
|
|
5099
|
+
_h[currentTask.resultingParameterName] =
|
|
5089
5100
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5090
5101
|
resultString,
|
|
5091
5102
|
_h))];
|
|
@@ -5147,7 +5158,7 @@
|
|
|
5147
5158
|
*/
|
|
5148
5159
|
function executePipeline(options) {
|
|
5149
5160
|
return __awaiter(this, void 0, void 0, function () {
|
|
5150
|
-
var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, maxParallelCount, rootDirname, _a, isVerbose, preparedPipeline, errors, warnings, executionReport, isReturned, _b, _c, parameter, e_1_1, _loop_1, _d, _e, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1,
|
|
5161
|
+
var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, maxParallelCount, rootDirname, _a, isVerbose, preparedPipeline, errors, warnings, executionReport, isReturned, _b, _c, parameter, e_1_1, _loop_1, _d, _e, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTasks_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
5151
5162
|
var e_1, _f, e_2, _g;
|
|
5152
5163
|
return __generator(this, function (_h) {
|
|
5153
5164
|
switch (_h.label) {
|
|
@@ -5301,11 +5312,11 @@
|
|
|
5301
5312
|
var name = _a.name;
|
|
5302
5313
|
return name;
|
|
5303
5314
|
});
|
|
5304
|
-
|
|
5315
|
+
unresovedTasks_1 = __spreadArray([], __read(preparedPipeline.tasks), false);
|
|
5305
5316
|
resolving_1 = [];
|
|
5306
5317
|
loopLimit = LOOP_LIMIT;
|
|
5307
5318
|
_loop_2 = function () {
|
|
5308
|
-
var
|
|
5319
|
+
var currentTask, work_1;
|
|
5309
5320
|
return __generator(this, function (_k) {
|
|
5310
5321
|
switch (_k.label) {
|
|
5311
5322
|
case 0:
|
|
@@ -5313,15 +5324,15 @@
|
|
|
5313
5324
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
5314
5325
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
5315
5326
|
}
|
|
5316
|
-
|
|
5317
|
-
return
|
|
5327
|
+
currentTask = unresovedTasks_1.find(function (task) {
|
|
5328
|
+
return task.dependentParameterNames.every(function (name) {
|
|
5318
5329
|
return __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), __read(RESERVED_PARAMETER_NAMES), false).includes(name);
|
|
5319
5330
|
});
|
|
5320
5331
|
});
|
|
5321
|
-
if (!(!
|
|
5332
|
+
if (!(!currentTask && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
5322
5333
|
throw new UnexpectedError(
|
|
5323
5334
|
// TODO: [🐎] DRY
|
|
5324
|
-
spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(
|
|
5335
|
+
spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks_1
|
|
5325
5336
|
.map(function (_a) {
|
|
5326
5337
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
5327
5338
|
return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
|
|
@@ -5340,14 +5351,14 @@
|
|
|
5340
5351
|
.map(function (name) { return "- Parameter `{".concat(name, "}`"); })
|
|
5341
5352
|
.join('\n')), "\n\n *Note: This should be catched in `validatePipeline`*\n "); }));
|
|
5342
5353
|
case 1:
|
|
5343
|
-
if (!!
|
|
5354
|
+
if (!!currentTask) return [3 /*break*/, 3];
|
|
5344
5355
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
5345
5356
|
case 2:
|
|
5346
5357
|
/* [🤹♂️] */ _k.sent();
|
|
5347
5358
|
return [3 /*break*/, 4];
|
|
5348
5359
|
case 3:
|
|
5349
|
-
|
|
5350
|
-
work_1 =
|
|
5360
|
+
unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
|
|
5361
|
+
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
|
|
5351
5362
|
if (isReturned) {
|
|
5352
5363
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
|
|
5353
5364
|
.split('\n')
|
|
@@ -5357,16 +5368,16 @@
|
|
|
5357
5368
|
if (onProgress) {
|
|
5358
5369
|
onProgress(progress);
|
|
5359
5370
|
}
|
|
5360
|
-
}, $executionReport: executionReport, pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n
|
|
5371
|
+
}, $executionReport: executionReport, pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
5361
5372
|
.then(function (newParametersToPass) {
|
|
5362
5373
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
5363
|
-
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [
|
|
5374
|
+
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTask.resultingParameterName], false);
|
|
5364
5375
|
})
|
|
5365
5376
|
.then(function () {
|
|
5366
5377
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
5367
5378
|
});
|
|
5368
5379
|
// <- Note: Errors are catched here [3]
|
|
5369
|
-
// TODO: BUT if in multiple
|
|
5380
|
+
// TODO: BUT if in multiple tasks are errors, only the first one is catched so maybe we should catch errors here and save them to errors array here
|
|
5370
5381
|
resolving_1.push(work_1);
|
|
5371
5382
|
_k.label = 4;
|
|
5372
5383
|
case 4: return [2 /*return*/];
|
|
@@ -5375,7 +5386,7 @@
|
|
|
5375
5386
|
};
|
|
5376
5387
|
_h.label = 21;
|
|
5377
5388
|
case 21:
|
|
5378
|
-
if (!(
|
|
5389
|
+
if (!(unresovedTasks_1.length > 0)) return [3 /*break*/, 23];
|
|
5379
5390
|
return [5 /*yield**/, _loop_2()];
|
|
5380
5391
|
case 22:
|
|
5381
5392
|
_h.sent();
|
|
@@ -5533,6 +5544,9 @@
|
|
|
5533
5544
|
* @public exported from `@promptbook/cli`
|
|
5534
5545
|
*/
|
|
5535
5546
|
$scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
5547
|
+
/**
|
|
5548
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5549
|
+
*/
|
|
5536
5550
|
|
|
5537
5551
|
/**
|
|
5538
5552
|
* Scraper for markdown files
|
|
@@ -5727,6 +5741,7 @@
|
|
|
5727
5741
|
var _MarkdownScraperRegistration = $scrapersRegister.register(createMarkdownScraper);
|
|
5728
5742
|
/**
|
|
5729
5743
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
5744
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5730
5745
|
*/
|
|
5731
5746
|
|
|
5732
5747
|
/**
|