@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/esm/index.es.js
CHANGED
|
@@ -20,9 +20,10 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
20
20
|
*
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.75.0-
|
|
23
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.75.0-1';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
26
27
|
*/
|
|
27
28
|
|
|
28
29
|
/*! *****************************************************************************
|
|
@@ -355,7 +356,7 @@ function extractJsonBlock(markdown) {
|
|
|
355
356
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
356
357
|
*/
|
|
357
358
|
|
|
358
|
-
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}],
|
|
359
|
+
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"}];
|
|
359
360
|
|
|
360
361
|
/**
|
|
361
362
|
* Prettify the html code
|
|
@@ -400,7 +401,7 @@ function prettifyMarkdown(content) {
|
|
|
400
401
|
*/
|
|
401
402
|
function pipelineJsonToString(pipelineJson) {
|
|
402
403
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
403
|
-
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters,
|
|
404
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, tasks = pipelineJson.tasks;
|
|
404
405
|
var pipelineString = "# ".concat(title);
|
|
405
406
|
if (description) {
|
|
406
407
|
pipelineString += '\n\n';
|
|
@@ -450,13 +451,13 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
450
451
|
pipelineString += '\n\n';
|
|
451
452
|
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
452
453
|
try {
|
|
453
|
-
for (var
|
|
454
|
-
var template =
|
|
454
|
+
for (var tasks_1 = __values(tasks), tasks_1_1 = tasks_1.next(); !tasks_1_1.done; tasks_1_1 = tasks_1.next()) {
|
|
455
|
+
var template = tasks_1_1.value;
|
|
455
456
|
var
|
|
456
457
|
/* Note: Not using:> name, */
|
|
457
458
|
title_1 = template.title, description_1 = template.description,
|
|
458
459
|
/* Note: dependentParameterNames, */
|
|
459
|
-
jokers = template.jokerParameterNames,
|
|
460
|
+
jokers = template.jokerParameterNames, taskType = template.taskType, content = template.content, postprocessing = template.postprocessingFunctionNames, expectations = template.expectations, format = template.format, resultingParameterName = template.resultingParameterName;
|
|
460
461
|
pipelineString += '\n\n';
|
|
461
462
|
pipelineString += "## ".concat(title_1);
|
|
462
463
|
if (description_1) {
|
|
@@ -465,7 +466,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
465
466
|
}
|
|
466
467
|
var commands_1 = [];
|
|
467
468
|
var contentLanguage = 'text';
|
|
468
|
-
if (
|
|
469
|
+
if (taskType === 'PROMPT_TASK') {
|
|
469
470
|
var modelRequirements = template.modelRequirements;
|
|
470
471
|
var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
|
|
471
472
|
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
@@ -476,11 +477,11 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
476
477
|
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
477
478
|
}
|
|
478
479
|
}
|
|
479
|
-
else if (
|
|
480
|
+
else if (taskType === 'SIMPLE_TASK') {
|
|
480
481
|
commands_1.push("SIMPLE TEMPLATE");
|
|
481
482
|
// Note: Nothing special here
|
|
482
483
|
}
|
|
483
|
-
else if (
|
|
484
|
+
else if (taskType === 'SCRIPT_TASK') {
|
|
484
485
|
commands_1.push("SCRIPT TEMPLATE");
|
|
485
486
|
if (template.contentLanguage) {
|
|
486
487
|
contentLanguage = template.contentLanguage;
|
|
@@ -489,7 +490,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
489
490
|
contentLanguage = '';
|
|
490
491
|
}
|
|
491
492
|
}
|
|
492
|
-
else if (
|
|
493
|
+
else if (taskType === 'DIALOG_TASK') {
|
|
493
494
|
commands_1.push("DIALOG TEMPLATE");
|
|
494
495
|
// Note: Nothing special here
|
|
495
496
|
} // <- }else if([🅱]
|
|
@@ -571,7 +572,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
571
572
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
572
573
|
finally {
|
|
573
574
|
try {
|
|
574
|
-
if (
|
|
575
|
+
if (tasks_1_1 && !tasks_1_1.done && (_c = tasks_1.return)) _c.call(tasks_1);
|
|
575
576
|
}
|
|
576
577
|
finally { if (e_3) throw e_3.error; }
|
|
577
578
|
}
|
|
@@ -911,6 +912,7 @@ var IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
911
912
|
true);
|
|
912
913
|
/**
|
|
913
914
|
* TODO: Extract `constants.ts` from `config.ts`
|
|
915
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
914
916
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
915
917
|
*/
|
|
916
918
|
|
|
@@ -1147,9 +1149,9 @@ function validatePipelineCore(pipeline) {
|
|
|
1147
1149
|
throw new ParseError(spaceTrim$1(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 "); }));
|
|
1148
1150
|
}
|
|
1149
1151
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1150
|
-
if (!Array.isArray(pipeline.
|
|
1152
|
+
if (!Array.isArray(pipeline.tasks)) {
|
|
1151
1153
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1152
|
-
throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.
|
|
1154
|
+
throw new ParseError(spaceTrim$1(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 "); }));
|
|
1153
1155
|
}
|
|
1154
1156
|
var _loop_1 = function (parameter) {
|
|
1155
1157
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -1158,13 +1160,12 @@ function validatePipelineCore(pipeline) {
|
|
|
1158
1160
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
1159
1161
|
if (!parameter.isInput &&
|
|
1160
1162
|
!parameter.isOutput &&
|
|
1161
|
-
!pipeline.
|
|
1163
|
+
!pipeline.tasks.some(function (task) { return task.dependentParameterNames.includes(parameter.name); })) {
|
|
1162
1164
|
throw new PipelineLogicError(spaceTrim$1(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 "); }));
|
|
1163
1165
|
}
|
|
1164
|
-
// Note: Testing that parameter is either input or result of some
|
|
1165
|
-
if (!parameter.isInput &&
|
|
1166
|
-
|
|
1167
|
-
throw new PipelineLogicError(spaceTrim$1(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 "); }));
|
|
1166
|
+
// Note: Testing that parameter is either input or result of some task
|
|
1167
|
+
if (!parameter.isInput && !pipeline.tasks.some(function (task) { return task.resultingParameterName === parameter.name; })) {
|
|
1168
|
+
throw new PipelineLogicError(spaceTrim$1(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 "); }));
|
|
1168
1169
|
}
|
|
1169
1170
|
};
|
|
1170
1171
|
try {
|
|
@@ -1181,7 +1182,7 @@ function validatePipelineCore(pipeline) {
|
|
|
1181
1182
|
}
|
|
1182
1183
|
finally { if (e_1) throw e_1.error; }
|
|
1183
1184
|
}
|
|
1184
|
-
// Note: All input parameters are defined - so that they can be used as result of some
|
|
1185
|
+
// Note: All input parameters are defined - so that they can be used as result of some task
|
|
1185
1186
|
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
1186
1187
|
var isInput = _a.isInput;
|
|
1187
1188
|
return isInput;
|
|
@@ -1189,27 +1190,27 @@ function validatePipelineCore(pipeline) {
|
|
|
1189
1190
|
var name = _a.name;
|
|
1190
1191
|
return name;
|
|
1191
1192
|
}));
|
|
1192
|
-
var _loop_2 = function (
|
|
1193
|
+
var _loop_2 = function (task) {
|
|
1193
1194
|
var e_4, _h, e_5, _j;
|
|
1194
|
-
if (definedParameters.has(
|
|
1195
|
-
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(
|
|
1195
|
+
if (definedParameters.has(task.resultingParameterName)) {
|
|
1196
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1196
1197
|
}
|
|
1197
|
-
if (RESERVED_PARAMETER_NAMES.includes(
|
|
1198
|
-
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(
|
|
1198
|
+
if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
|
|
1199
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(task.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1199
1200
|
}
|
|
1200
|
-
definedParameters.add(
|
|
1201
|
-
if (
|
|
1202
|
-
if (!
|
|
1203
|
-
!
|
|
1204
|
-
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(
|
|
1201
|
+
definedParameters.add(task.resultingParameterName);
|
|
1202
|
+
if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
|
|
1203
|
+
if (!task.format &&
|
|
1204
|
+
!task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
1205
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(task.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1205
1206
|
}
|
|
1206
1207
|
var _loop_4 = function (joker) {
|
|
1207
|
-
if (!
|
|
1208
|
-
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(
|
|
1208
|
+
if (!task.dependentParameterNames.includes(joker)) {
|
|
1209
|
+
throw new PipelineLogicError(spaceTrim$1(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 "); }));
|
|
1209
1210
|
}
|
|
1210
1211
|
};
|
|
1211
1212
|
try {
|
|
1212
|
-
for (var _k = (e_4 = void 0, __values(
|
|
1213
|
+
for (var _k = (e_4 = void 0, __values(task.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
1213
1214
|
var joker = _l.value;
|
|
1214
1215
|
_loop_4(joker);
|
|
1215
1216
|
}
|
|
@@ -1222,7 +1223,7 @@ function validatePipelineCore(pipeline) {
|
|
|
1222
1223
|
finally { if (e_4) throw e_4.error; }
|
|
1223
1224
|
}
|
|
1224
1225
|
}
|
|
1225
|
-
if (
|
|
1226
|
+
if (task.expectations) {
|
|
1226
1227
|
var _loop_5 = function (unit, min, max) {
|
|
1227
1228
|
if (min !== undefined && max !== undefined && min > max) {
|
|
1228
1229
|
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
@@ -1235,7 +1236,7 @@ function validatePipelineCore(pipeline) {
|
|
|
1235
1236
|
}
|
|
1236
1237
|
};
|
|
1237
1238
|
try {
|
|
1238
|
-
for (var _m = (e_5 = void 0, __values(Object.entries(
|
|
1239
|
+
for (var _m = (e_5 = void 0, __values(Object.entries(task.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
1239
1240
|
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
1240
1241
|
_loop_5(unit, min, max);
|
|
1241
1242
|
}
|
|
@@ -1250,10 +1251,10 @@ function validatePipelineCore(pipeline) {
|
|
|
1250
1251
|
}
|
|
1251
1252
|
};
|
|
1252
1253
|
try {
|
|
1253
|
-
// Note: Checking each
|
|
1254
|
-
for (var _f = __values(pipeline.
|
|
1255
|
-
var
|
|
1256
|
-
_loop_2(
|
|
1254
|
+
// Note: Checking each task individually
|
|
1255
|
+
for (var _f = __values(pipeline.tasks), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1256
|
+
var task = _g.value;
|
|
1257
|
+
_loop_2(task);
|
|
1257
1258
|
}
|
|
1258
1259
|
}
|
|
1259
1260
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -1287,15 +1288,15 @@ function validatePipelineCore(pipeline) {
|
|
|
1287
1288
|
}
|
|
1288
1289
|
finally { if (e_3) throw e_3.error; }
|
|
1289
1290
|
}
|
|
1290
|
-
var unresovedTemplates = __spreadArray([], __read(pipeline.
|
|
1291
|
+
var unresovedTemplates = __spreadArray([], __read(pipeline.tasks), false);
|
|
1291
1292
|
var loopLimit = LOOP_LIMIT;
|
|
1292
1293
|
var _loop_3 = function () {
|
|
1293
1294
|
if (loopLimit-- < 0) {
|
|
1294
1295
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
1295
1296
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
1296
1297
|
}
|
|
1297
|
-
var currentlyResovedTemplates = unresovedTemplates.filter(function (
|
|
1298
|
-
return
|
|
1298
|
+
var currentlyResovedTemplates = unresovedTemplates.filter(function (task) {
|
|
1299
|
+
return task.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
1299
1300
|
});
|
|
1300
1301
|
if (currentlyResovedTemplates.length === 0) {
|
|
1301
1302
|
throw new PipelineLogicError(
|
|
@@ -1323,7 +1324,7 @@ function validatePipelineCore(pipeline) {
|
|
|
1323
1324
|
var resultingParameterName = _a.resultingParameterName;
|
|
1324
1325
|
return resultingParameterName;
|
|
1325
1326
|
})), false);
|
|
1326
|
-
unresovedTemplates = unresovedTemplates.filter(function (
|
|
1327
|
+
unresovedTemplates = unresovedTemplates.filter(function (task) { return !currentlyResovedTemplates.includes(task); });
|
|
1327
1328
|
};
|
|
1328
1329
|
while (unresovedTemplates.length > 0) {
|
|
1329
1330
|
_loop_3();
|
|
@@ -1385,9 +1386,9 @@ var PipelineUrlError = /** @class */ (function (_super) {
|
|
|
1385
1386
|
}(Error));
|
|
1386
1387
|
|
|
1387
1388
|
/**
|
|
1388
|
-
* Parses the
|
|
1389
|
+
* Parses the task and returns the list of all parameter names
|
|
1389
1390
|
*
|
|
1390
|
-
* @param template the
|
|
1391
|
+
* @param template the task with parameters in {curly} braces
|
|
1391
1392
|
* @returns the list of parameter names
|
|
1392
1393
|
* @public exported from `@promptbook/utils`
|
|
1393
1394
|
*/
|
|
@@ -1418,10 +1419,10 @@ function extractParameterNames(template) {
|
|
|
1418
1419
|
* @public exported from `@promptbook/core`
|
|
1419
1420
|
*/
|
|
1420
1421
|
function unpreparePipeline(pipeline) {
|
|
1421
|
-
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources,
|
|
1422
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, tasks = pipeline.tasks;
|
|
1422
1423
|
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
1423
1424
|
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
1424
|
-
|
|
1425
|
+
tasks = tasks.map(function (template) {
|
|
1425
1426
|
var dependentParameterNames = template.dependentParameterNames;
|
|
1426
1427
|
var parameterNames = extractParameterNames(template.preparedContent || '');
|
|
1427
1428
|
dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
|
|
@@ -1429,7 +1430,7 @@ function unpreparePipeline(pipeline) {
|
|
|
1429
1430
|
delete templateUnprepared.preparedContent;
|
|
1430
1431
|
return templateUnprepared;
|
|
1431
1432
|
});
|
|
1432
|
-
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), {
|
|
1433
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1433
1434
|
}
|
|
1434
1435
|
/**
|
|
1435
1436
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1861,6 +1862,9 @@ function normalizeToKebabCase(text) {
|
|
|
1861
1862
|
normalizedName = normalizedName.replace(/-$/, '');
|
|
1862
1863
|
return normalizedName;
|
|
1863
1864
|
}
|
|
1865
|
+
/**
|
|
1866
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1867
|
+
*/
|
|
1864
1868
|
|
|
1865
1869
|
/**
|
|
1866
1870
|
* Removes emojis from a string and fix whitespaces
|
|
@@ -2062,6 +2066,9 @@ var ERRORS = {
|
|
|
2062
2066
|
UnexpectedError: UnexpectedError,
|
|
2063
2067
|
// TODO: [🪑]> VersionMismatchError,
|
|
2064
2068
|
};
|
|
2069
|
+
/**
|
|
2070
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2071
|
+
*/
|
|
2065
2072
|
|
|
2066
2073
|
/**
|
|
2067
2074
|
* Deserializes the error object
|
|
@@ -2123,8 +2130,8 @@ function isPipelinePrepared(pipeline) {
|
|
|
2123
2130
|
return false;
|
|
2124
2131
|
}
|
|
2125
2132
|
/*
|
|
2126
|
-
TODO: [🧠][🍫] `
|
|
2127
|
-
> if (!pipeline.
|
|
2133
|
+
TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2134
|
+
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2128
2135
|
> return false;
|
|
2129
2136
|
> }
|
|
2130
2137
|
*/
|
|
@@ -2137,7 +2144,7 @@ function isPipelinePrepared(pipeline) {
|
|
|
2137
2144
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2138
2145
|
* - [🏍] ? Is context in each template
|
|
2139
2146
|
* - [♨] Are examples prepared
|
|
2140
|
-
* - [♨] Are
|
|
2147
|
+
* - [♨] Are tasks prepared
|
|
2141
2148
|
*/
|
|
2142
2149
|
|
|
2143
2150
|
/**
|
|
@@ -2285,6 +2292,9 @@ $deepFreeze({
|
|
|
2285
2292
|
pagesCount: { value: 0, isUncertain: true },
|
|
2286
2293
|
},
|
|
2287
2294
|
});
|
|
2295
|
+
/**
|
|
2296
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2297
|
+
*/
|
|
2288
2298
|
|
|
2289
2299
|
/**
|
|
2290
2300
|
* @@@
|
|
@@ -3471,7 +3481,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
3471
3481
|
*/
|
|
3472
3482
|
function clonePipeline(pipeline) {
|
|
3473
3483
|
// Note: Not using spread operator (...) because @@@
|
|
3474
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters,
|
|
3484
|
+
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;
|
|
3475
3485
|
return {
|
|
3476
3486
|
pipelineUrl: pipelineUrl,
|
|
3477
3487
|
sourceFile: sourceFile,
|
|
@@ -3480,7 +3490,7 @@ function clonePipeline(pipeline) {
|
|
|
3480
3490
|
description: description,
|
|
3481
3491
|
formfactorName: formfactorName,
|
|
3482
3492
|
parameters: parameters,
|
|
3483
|
-
|
|
3493
|
+
tasks: tasks,
|
|
3484
3494
|
knowledgeSources: knowledgeSources,
|
|
3485
3495
|
knowledgePieces: knowledgePieces,
|
|
3486
3496
|
personas: personas,
|
|
@@ -3496,17 +3506,17 @@ function clonePipeline(pipeline) {
|
|
|
3496
3506
|
*
|
|
3497
3507
|
* @public exported from `@promptbook/core`
|
|
3498
3508
|
*/
|
|
3499
|
-
function
|
|
3509
|
+
function prepareTasks(pipeline, tools, options) {
|
|
3500
3510
|
return __awaiter(this, void 0, void 0, function () {
|
|
3501
|
-
var _a, maxParallelCount,
|
|
3511
|
+
var _a, maxParallelCount, tasks, knowledgePiecesCount, tasksPrepared;
|
|
3502
3512
|
var _this = this;
|
|
3503
3513
|
return __generator(this, function (_b) {
|
|
3504
3514
|
switch (_b.label) {
|
|
3505
3515
|
case 0:
|
|
3506
3516
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
return [4 /*yield*/, forEachAsync(
|
|
3517
|
+
tasks = pipeline.tasks, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3518
|
+
tasksPrepared = new Array(tasks.length);
|
|
3519
|
+
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 () {
|
|
3510
3520
|
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
3511
3521
|
return __generator(this, function (_a) {
|
|
3512
3522
|
dependentParameterNames = template.dependentParameterNames;
|
|
@@ -3519,13 +3529,13 @@ function prepareTemplates(pipeline, tools, options) {
|
|
|
3519
3529
|
], false);
|
|
3520
3530
|
}
|
|
3521
3531
|
preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
|
|
3522
|
-
|
|
3532
|
+
tasksPrepared[index] = preparedTemplate;
|
|
3523
3533
|
return [2 /*return*/];
|
|
3524
3534
|
});
|
|
3525
3535
|
}); })];
|
|
3526
3536
|
case 1:
|
|
3527
3537
|
_b.sent();
|
|
3528
|
-
return [2 /*return*/, {
|
|
3538
|
+
return [2 /*return*/, { tasksPrepared: tasksPrepared }];
|
|
3529
3539
|
}
|
|
3530
3540
|
});
|
|
3531
3541
|
});
|
|
@@ -3533,7 +3543,7 @@ function prepareTemplates(pipeline, tools, options) {
|
|
|
3533
3543
|
/**
|
|
3534
3544
|
* TODO: [🧠] Add context to each template (if missing)
|
|
3535
3545
|
* TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
3536
|
-
* TODO: [♨][main] !!! Prepare index the examples and maybe
|
|
3546
|
+
* TODO: [♨][main] !!! Prepare index the examples and maybe tasks
|
|
3537
3547
|
* TODO: Write tests for `preparePipeline`
|
|
3538
3548
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3539
3549
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3550,12 +3560,12 @@ function prepareTemplates(pipeline, tools, options) {
|
|
|
3550
3560
|
*/
|
|
3551
3561
|
function preparePipeline(pipeline, tools, options) {
|
|
3552
3562
|
return __awaiter(this, void 0, void 0, function () {
|
|
3553
|
-
var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters,
|
|
3563
|
+
var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters, tasks,
|
|
3554
3564
|
/*
|
|
3555
3565
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
3556
3566
|
knowledgeSources /*
|
|
3557
3567
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3558
|
-
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared,
|
|
3568
|
+
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3559
3569
|
var _this = this;
|
|
3560
3570
|
return __generator(this, function (_c) {
|
|
3561
3571
|
switch (_c.label) {
|
|
@@ -3564,7 +3574,7 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3564
3574
|
return [2 /*return*/, pipeline];
|
|
3565
3575
|
}
|
|
3566
3576
|
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;
|
|
3567
|
-
parameters = pipeline.parameters,
|
|
3577
|
+
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3568
3578
|
if (tools === undefined || tools.llm === undefined) {
|
|
3569
3579
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
3570
3580
|
}
|
|
@@ -3607,9 +3617,9 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3607
3617
|
case 2:
|
|
3608
3618
|
partialknowledgePiecesPrepared = _c.sent();
|
|
3609
3619
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3610
|
-
return [4 /*yield*/,
|
|
3620
|
+
return [4 /*yield*/, prepareTasks({
|
|
3611
3621
|
parameters: parameters,
|
|
3612
|
-
|
|
3622
|
+
tasks: tasks,
|
|
3613
3623
|
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
3614
3624
|
}, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
3615
3625
|
rootDirname: rootDirname,
|
|
@@ -3617,12 +3627,12 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3617
3627
|
isVerbose: isVerbose,
|
|
3618
3628
|
})];
|
|
3619
3629
|
case 3:
|
|
3620
|
-
|
|
3630
|
+
tasksPrepared = (_c.sent()).tasksPrepared;
|
|
3621
3631
|
// ----- /Templates preparation -----
|
|
3622
3632
|
// Note: Count total usage
|
|
3623
3633
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
3624
|
-
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), {
|
|
3625
|
-
// <- TODO: [🪓] Here should be no need for spreading new array, just `
|
|
3634
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3635
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
3626
3636
|
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }))];
|
|
3627
3637
|
}
|
|
3628
3638
|
});
|
|
@@ -3694,9 +3704,9 @@ function extractVariables(script) {
|
|
|
3694
3704
|
* @throws {ParseError} if the script is invalid
|
|
3695
3705
|
* @public exported from `@promptbook/utils`
|
|
3696
3706
|
*/
|
|
3697
|
-
function
|
|
3707
|
+
function extractParameterNamesFromTask(template) {
|
|
3698
3708
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
3699
|
-
var title = template.title, description = template.description,
|
|
3709
|
+
var title = template.title, description = template.description, taskType = template.taskType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
|
|
3700
3710
|
var parameterNames = new Set();
|
|
3701
3711
|
try {
|
|
3702
3712
|
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()) {
|
|
@@ -3711,7 +3721,7 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
3711
3721
|
}
|
|
3712
3722
|
finally { if (e_1) throw e_1.error; }
|
|
3713
3723
|
}
|
|
3714
|
-
if (
|
|
3724
|
+
if (taskType === 'SCRIPT_TASK') {
|
|
3715
3725
|
try {
|
|
3716
3726
|
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
3717
3727
|
var parameterName = _h.value;
|
|
@@ -4121,6 +4131,9 @@ var FORMAT_DEFINITIONS = [
|
|
|
4121
4131
|
TextFormatDefinition,
|
|
4122
4132
|
CsvFormatDefinition,
|
|
4123
4133
|
];
|
|
4134
|
+
/**
|
|
4135
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4136
|
+
*/
|
|
4124
4137
|
|
|
4125
4138
|
/**
|
|
4126
4139
|
* Maps available parameters to expected parameters
|
|
@@ -4221,7 +4234,7 @@ function replaceParameters(template, parameters) {
|
|
|
4221
4234
|
}
|
|
4222
4235
|
finally { if (e_1) throw e_1.error; }
|
|
4223
4236
|
}
|
|
4224
|
-
var
|
|
4237
|
+
var replacedTemplates = template;
|
|
4225
4238
|
var match;
|
|
4226
4239
|
var loopLimit = LOOP_LIMIT;
|
|
4227
4240
|
var _loop_1 = function () {
|
|
@@ -4250,24 +4263,24 @@ function replaceParameters(template, parameters) {
|
|
|
4250
4263
|
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
4251
4264
|
.join('\n');
|
|
4252
4265
|
}
|
|
4253
|
-
|
|
4254
|
-
|
|
4266
|
+
replacedTemplates =
|
|
4267
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
4255
4268
|
parameterValue +
|
|
4256
|
-
|
|
4269
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
4257
4270
|
};
|
|
4258
4271
|
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
4259
|
-
.exec(
|
|
4272
|
+
.exec(replacedTemplates))) {
|
|
4260
4273
|
_loop_1();
|
|
4261
4274
|
}
|
|
4262
4275
|
// [💫] Check if there are parameters that are not closed properly
|
|
4263
|
-
if (/{\w+$/.test(
|
|
4276
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
4264
4277
|
throw new PipelineExecutionError('Parameter is not closed');
|
|
4265
4278
|
}
|
|
4266
4279
|
// [💫] Check if there are parameters that are not opened properly
|
|
4267
|
-
if (/^\w+}/.test(
|
|
4280
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
4268
4281
|
throw new PipelineExecutionError('Parameter is not opened');
|
|
4269
4282
|
}
|
|
4270
|
-
return
|
|
4283
|
+
return replacedTemplates;
|
|
4271
4284
|
}
|
|
4272
4285
|
|
|
4273
4286
|
/**
|
|
@@ -4299,6 +4312,7 @@ var CHARACTERS_PER_STANDARD_LINE = 63;
|
|
|
4299
4312
|
var LINES_PER_STANDARD_PAGE = 44;
|
|
4300
4313
|
/**
|
|
4301
4314
|
* TODO: [🧠] Should be this `constants.ts` or `config.ts`?
|
|
4315
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4302
4316
|
*/
|
|
4303
4317
|
|
|
4304
4318
|
/**
|
|
@@ -4378,6 +4392,7 @@ var CountUtils = {
|
|
|
4378
4392
|
};
|
|
4379
4393
|
/**
|
|
4380
4394
|
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
4395
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4381
4396
|
*/
|
|
4382
4397
|
|
|
4383
4398
|
/**
|
|
@@ -4426,12 +4441,12 @@ function checkExpectations(expectations, value) {
|
|
|
4426
4441
|
*/
|
|
4427
4442
|
function executeAttempts(options) {
|
|
4428
4443
|
return __awaiter(this, void 0, void 0, function () {
|
|
4429
|
-
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters,
|
|
4444
|
+
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTaskResult, _llms, llmTools, _loop_1, attempt, state_1;
|
|
4430
4445
|
return __generator(this, function (_a) {
|
|
4431
4446
|
switch (_a.label) {
|
|
4432
4447
|
case 0:
|
|
4433
|
-
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters,
|
|
4434
|
-
$
|
|
4448
|
+
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;
|
|
4449
|
+
$ongoingTaskResult = {
|
|
4435
4450
|
$result: null,
|
|
4436
4451
|
$resultString: null,
|
|
4437
4452
|
$expectError: null,
|
|
@@ -4451,52 +4466,51 @@ function executeAttempts(options) {
|
|
|
4451
4466
|
if (isJokerAttempt && !jokerParameterName) {
|
|
4452
4467
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4453
4468
|
}
|
|
4454
|
-
$
|
|
4455
|
-
$
|
|
4456
|
-
$
|
|
4469
|
+
$ongoingTaskResult.$result = null;
|
|
4470
|
+
$ongoingTaskResult.$resultString = null;
|
|
4471
|
+
$ongoingTaskResult.$expectError = null;
|
|
4457
4472
|
if (isJokerAttempt) {
|
|
4458
4473
|
if (parameters[jokerParameterName] === undefined) {
|
|
4459
4474
|
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4460
4475
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
4461
4476
|
}
|
|
4462
4477
|
else {
|
|
4463
|
-
$
|
|
4478
|
+
$ongoingTaskResult.$resultString = parameters[jokerParameterName];
|
|
4464
4479
|
}
|
|
4465
4480
|
}
|
|
4466
4481
|
_t.label = 1;
|
|
4467
4482
|
case 1:
|
|
4468
4483
|
_t.trys.push([1, 43, 44, 45]);
|
|
4469
4484
|
if (!!isJokerAttempt) return [3 /*break*/, 25];
|
|
4470
|
-
_b =
|
|
4485
|
+
_b = task.taskType;
|
|
4471
4486
|
switch (_b) {
|
|
4472
|
-
case '
|
|
4473
|
-
case '
|
|
4474
|
-
case '
|
|
4475
|
-
case '
|
|
4487
|
+
case 'SIMPLE_TASK': return [3 /*break*/, 2];
|
|
4488
|
+
case 'PROMPT_TASK': return [3 /*break*/, 3];
|
|
4489
|
+
case 'SCRIPT_TASK': return [3 /*break*/, 11];
|
|
4490
|
+
case 'DIALOG_TASK': return [3 /*break*/, 22];
|
|
4476
4491
|
}
|
|
4477
4492
|
return [3 /*break*/, 24];
|
|
4478
4493
|
case 2:
|
|
4479
|
-
$
|
|
4494
|
+
$ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
4480
4495
|
return [3 /*break*/, 25];
|
|
4481
4496
|
case 3:
|
|
4482
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (
|
|
4483
|
-
$
|
|
4484
|
-
title:
|
|
4497
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
4498
|
+
$ongoingTaskResult.$prompt = {
|
|
4499
|
+
title: task.title,
|
|
4485
4500
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
4486
4501
|
? preparedPipeline.pipelineUrl
|
|
4487
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(
|
|
4488
|
-
// <- TODO: Here should be maybe also subformat index to distinguish between same
|
|
4502
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(task.name
|
|
4503
|
+
// <- TODO: Here should be maybe also subformat index to distinguish between same task with different subformat values
|
|
4489
4504
|
),
|
|
4490
4505
|
parameters: parameters,
|
|
4491
4506
|
content: preparedContent,
|
|
4492
4507
|
modelRequirements: modelRequirements,
|
|
4493
4508
|
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
4494
4509
|
var name = _a.name;
|
|
4495
|
-
return name ===
|
|
4496
|
-
}) ||
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
postprocessingFunctionNames: template.postprocessingFunctionNames,
|
|
4510
|
+
return name === task.personaName;
|
|
4511
|
+
}) || {})), task.expectations),
|
|
4512
|
+
format: task.format,
|
|
4513
|
+
postprocessingFunctionNames: task.postprocessingFunctionNames,
|
|
4500
4514
|
}; // <- TODO: Not very good type guard
|
|
4501
4515
|
_c = modelRequirements.modelVariant;
|
|
4502
4516
|
switch (_c) {
|
|
@@ -4506,36 +4520,35 @@ function executeAttempts(options) {
|
|
|
4506
4520
|
}
|
|
4507
4521
|
return [3 /*break*/, 9];
|
|
4508
4522
|
case 4:
|
|
4509
|
-
_d = $
|
|
4523
|
+
_d = $ongoingTaskResult;
|
|
4510
4524
|
return [4 /*yield*/, llmTools.callChatModel(
|
|
4511
4525
|
// <- TODO: [🧁] Check that `callChatModel` is defined
|
|
4512
|
-
$deepFreeze($
|
|
4526
|
+
$deepFreeze($ongoingTaskResult.$prompt))];
|
|
4513
4527
|
case 5:
|
|
4514
4528
|
_d.$chatResult = _t.sent();
|
|
4515
4529
|
// TODO: [🍬] Destroy chatThread
|
|
4516
|
-
$
|
|
4517
|
-
$
|
|
4530
|
+
$ongoingTaskResult.$result = $ongoingTaskResult.$chatResult;
|
|
4531
|
+
$ongoingTaskResult.$resultString = $ongoingTaskResult.$chatResult.content;
|
|
4518
4532
|
return [3 /*break*/, 10];
|
|
4519
4533
|
case 6:
|
|
4520
|
-
_e = $
|
|
4534
|
+
_e = $ongoingTaskResult;
|
|
4521
4535
|
return [4 /*yield*/, llmTools.callCompletionModel(
|
|
4522
4536
|
// <- TODO: [🧁] Check that `callCompletionModel` is defined
|
|
4523
|
-
$deepFreeze($
|
|
4537
|
+
$deepFreeze($ongoingTaskResult.$prompt))];
|
|
4524
4538
|
case 7:
|
|
4525
4539
|
_e.$completionResult = _t.sent();
|
|
4526
|
-
$
|
|
4527
|
-
$
|
|
4528
|
-
$ongoingTemplateResult.$completionResult.content;
|
|
4540
|
+
$ongoingTaskResult.$result = $ongoingTaskResult.$completionResult;
|
|
4541
|
+
$ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
|
|
4529
4542
|
return [3 /*break*/, 10];
|
|
4530
4543
|
case 8: throw new PipelineExecutionError(spaceTrim$1(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 "); }));
|
|
4531
|
-
case 9: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(
|
|
4544
|
+
case 9: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(task.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
4532
4545
|
case 10: return [3 /*break*/, 25];
|
|
4533
4546
|
case 11:
|
|
4534
4547
|
if (arrayableToArray(tools.script).length === 0) {
|
|
4535
4548
|
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4536
4549
|
}
|
|
4537
|
-
if (!
|
|
4538
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT
|
|
4550
|
+
if (!task.contentLanguage) {
|
|
4551
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT TASK \"".concat(task.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4539
4552
|
}
|
|
4540
4553
|
_t.label = 12;
|
|
4541
4554
|
case 12:
|
|
@@ -4548,9 +4561,9 @@ function executeAttempts(options) {
|
|
|
4548
4561
|
_t.label = 14;
|
|
4549
4562
|
case 14:
|
|
4550
4563
|
_t.trys.push([14, 16, , 17]);
|
|
4551
|
-
_h = $
|
|
4564
|
+
_h = $ongoingTaskResult;
|
|
4552
4565
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
4553
|
-
scriptLanguage:
|
|
4566
|
+
scriptLanguage: task.contentLanguage,
|
|
4554
4567
|
script: preparedContent,
|
|
4555
4568
|
parameters: parameters,
|
|
4556
4569
|
}))];
|
|
@@ -4565,7 +4578,7 @@ function executeAttempts(options) {
|
|
|
4565
4578
|
if (error_1 instanceof UnexpectedError) {
|
|
4566
4579
|
throw error_1;
|
|
4567
4580
|
}
|
|
4568
|
-
$
|
|
4581
|
+
$ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
4569
4582
|
return [3 /*break*/, 17];
|
|
4570
4583
|
case 17:
|
|
4571
4584
|
_g = _f.next();
|
|
@@ -4582,14 +4595,14 @@ function executeAttempts(options) {
|
|
|
4582
4595
|
finally { if (e_1) throw e_1.error; }
|
|
4583
4596
|
return [7 /*endfinally*/];
|
|
4584
4597
|
case 21:
|
|
4585
|
-
if ($
|
|
4598
|
+
if ($ongoingTaskResult.$resultString !== null) {
|
|
4586
4599
|
return [3 /*break*/, 25];
|
|
4587
4600
|
}
|
|
4588
|
-
if ($
|
|
4589
|
-
throw $
|
|
4601
|
+
if ($ongoingTaskResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
4602
|
+
throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
|
|
4590
4603
|
}
|
|
4591
4604
|
else {
|
|
4592
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($
|
|
4605
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($ongoingTaskResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTaskResult.$scriptPipelineExecutionErrors
|
|
4593
4606
|
.map(function (error) { return '- ' + error.message; })
|
|
4594
4607
|
.join('\n\n')), "\n "); }));
|
|
4595
4608
|
}
|
|
@@ -4597,27 +4610,27 @@ function executeAttempts(options) {
|
|
|
4597
4610
|
if (tools.userInterface === undefined) {
|
|
4598
4611
|
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4599
4612
|
}
|
|
4600
|
-
// TODO: [🌹] When making next attempt for `DIALOG
|
|
4601
|
-
_j = $
|
|
4613
|
+
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
4614
|
+
_j = $ongoingTaskResult;
|
|
4602
4615
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
4603
|
-
promptTitle:
|
|
4604
|
-
promptMessage: replaceParameters(
|
|
4616
|
+
promptTitle: task.title,
|
|
4617
|
+
promptMessage: replaceParameters(task.description || '', parameters),
|
|
4605
4618
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
4606
4619
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
4607
4620
|
placeholder: undefined,
|
|
4608
4621
|
priority: priority,
|
|
4609
4622
|
}))];
|
|
4610
4623
|
case 23:
|
|
4611
|
-
// TODO: [🌹] When making next attempt for `DIALOG
|
|
4624
|
+
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
4612
4625
|
_j.$resultString = _t.sent();
|
|
4613
4626
|
return [3 /*break*/, 25];
|
|
4614
|
-
case 24: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(
|
|
4627
|
+
case 24: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4615
4628
|
case 25:
|
|
4616
|
-
if (!(!isJokerAttempt &&
|
|
4629
|
+
if (!(!isJokerAttempt && task.postprocessingFunctionNames)) return [3 /*break*/, 42];
|
|
4617
4630
|
_t.label = 26;
|
|
4618
4631
|
case 26:
|
|
4619
4632
|
_t.trys.push([26, 40, 41, 42]);
|
|
4620
|
-
_k = (e_3 = void 0, __values(
|
|
4633
|
+
_k = (e_3 = void 0, __values(task.postprocessingFunctionNames)), _l = _k.next();
|
|
4621
4634
|
_t.label = 27;
|
|
4622
4635
|
case 27:
|
|
4623
4636
|
if (!!_l.done) return [3 /*break*/, 39];
|
|
@@ -4634,13 +4647,13 @@ function executeAttempts(options) {
|
|
|
4634
4647
|
_t.label = 30;
|
|
4635
4648
|
case 30:
|
|
4636
4649
|
_t.trys.push([30, 32, , 33]);
|
|
4637
|
-
_p = $
|
|
4650
|
+
_p = $ongoingTaskResult;
|
|
4638
4651
|
return [4 /*yield*/, scriptTools.execute({
|
|
4639
4652
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
4640
4653
|
script: "".concat(functionName, "(resultString)"),
|
|
4641
4654
|
parameters: {
|
|
4642
|
-
resultString: $
|
|
4643
|
-
// Note: No ...
|
|
4655
|
+
resultString: $ongoingTaskResult.$resultString || '',
|
|
4656
|
+
// Note: No ...parametersForTask, because working with result only
|
|
4644
4657
|
},
|
|
4645
4658
|
})];
|
|
4646
4659
|
case 31:
|
|
@@ -4656,7 +4669,7 @@ function executeAttempts(options) {
|
|
|
4656
4669
|
throw error_2;
|
|
4657
4670
|
}
|
|
4658
4671
|
postprocessingError = error_2;
|
|
4659
|
-
$
|
|
4672
|
+
$ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
4660
4673
|
return [3 /*break*/, 33];
|
|
4661
4674
|
case 33:
|
|
4662
4675
|
_o = _m.next();
|
|
@@ -4693,12 +4706,12 @@ function executeAttempts(options) {
|
|
|
4693
4706
|
return [7 /*endfinally*/];
|
|
4694
4707
|
case 42:
|
|
4695
4708
|
// TODO: [💝] Unite object for expecting amount and format
|
|
4696
|
-
if (
|
|
4697
|
-
if (
|
|
4698
|
-
if (!isValidJsonString($
|
|
4709
|
+
if (task.format) {
|
|
4710
|
+
if (task.format === 'JSON') {
|
|
4711
|
+
if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
|
|
4699
4712
|
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
4700
4713
|
try {
|
|
4701
|
-
$
|
|
4714
|
+
$ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
|
|
4702
4715
|
}
|
|
4703
4716
|
catch (error) {
|
|
4704
4717
|
throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
@@ -4707,12 +4720,12 @@ function executeAttempts(options) {
|
|
|
4707
4720
|
}
|
|
4708
4721
|
}
|
|
4709
4722
|
else {
|
|
4710
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(
|
|
4723
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4711
4724
|
}
|
|
4712
4725
|
}
|
|
4713
4726
|
// TODO: [💝] Unite object for expecting amount and format
|
|
4714
|
-
if (
|
|
4715
|
-
checkExpectations(
|
|
4727
|
+
if (task.expectations) {
|
|
4728
|
+
checkExpectations(task.expectations, $ongoingTaskResult.$resultString || '');
|
|
4716
4729
|
}
|
|
4717
4730
|
return [2 /*return*/, "break-attempts"];
|
|
4718
4731
|
case 43:
|
|
@@ -4720,38 +4733,38 @@ function executeAttempts(options) {
|
|
|
4720
4733
|
if (!(error_3 instanceof ExpectError)) {
|
|
4721
4734
|
throw error_3;
|
|
4722
4735
|
}
|
|
4723
|
-
$
|
|
4736
|
+
$ongoingTaskResult.$expectError = error_3;
|
|
4724
4737
|
return [3 /*break*/, 45];
|
|
4725
4738
|
case 44:
|
|
4726
4739
|
if (!isJokerAttempt &&
|
|
4727
|
-
|
|
4728
|
-
$
|
|
4740
|
+
task.taskType === 'PROMPT_TASK' &&
|
|
4741
|
+
$ongoingTaskResult.$prompt
|
|
4729
4742
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
4730
4743
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
4731
4744
|
) {
|
|
4732
|
-
// TODO: [🧠] Maybe put other
|
|
4745
|
+
// TODO: [🧠] Maybe put other taskTypes into report
|
|
4733
4746
|
$executionReport.promptExecutions.push({
|
|
4734
|
-
prompt: __assign({}, $
|
|
4735
|
-
result: $
|
|
4736
|
-
error: $
|
|
4747
|
+
prompt: __assign({}, $ongoingTaskResult.$prompt),
|
|
4748
|
+
result: $ongoingTaskResult.$result || undefined,
|
|
4749
|
+
error: $ongoingTaskResult.$expectError === null
|
|
4737
4750
|
? undefined
|
|
4738
|
-
: serializeError($
|
|
4751
|
+
: serializeError($ongoingTaskResult.$expectError),
|
|
4739
4752
|
});
|
|
4740
4753
|
}
|
|
4741
4754
|
return [7 /*endfinally*/];
|
|
4742
4755
|
case 45:
|
|
4743
|
-
if ($
|
|
4756
|
+
if ($ongoingTaskResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
4744
4757
|
throw new PipelineExecutionError(spaceTrim$1(function (block) {
|
|
4745
4758
|
var _a, _b, _c;
|
|
4746
|
-
return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $
|
|
4759
|
+
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) || '')
|
|
4747
4760
|
.split('\n')
|
|
4748
4761
|
.map(function (line) { return "> ".concat(line); })
|
|
4749
|
-
.join('\n')), "\n\n Last error ").concat(((_b = $
|
|
4762
|
+
.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) || '')
|
|
4750
4763
|
.split('\n')
|
|
4751
4764
|
.map(function (line) { return "> ".concat(line); })
|
|
4752
|
-
.join('\n')), "\n\n Last result:\n ").concat(block($
|
|
4765
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingTaskResult.$resultString === null
|
|
4753
4766
|
? 'null'
|
|
4754
|
-
: $
|
|
4767
|
+
: $ongoingTaskResult.$resultString
|
|
4755
4768
|
.split('\n')
|
|
4756
4769
|
.map(function (line) { return "> ".concat(line); })
|
|
4757
4770
|
.join('\n')), "\n ---\n ");
|
|
@@ -4776,10 +4789,10 @@ function executeAttempts(options) {
|
|
|
4776
4789
|
attempt++;
|
|
4777
4790
|
return [3 /*break*/, 1];
|
|
4778
4791
|
case 4:
|
|
4779
|
-
if ($
|
|
4792
|
+
if ($ongoingTaskResult.$resultString === null) {
|
|
4780
4793
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4781
4794
|
}
|
|
4782
|
-
return [2 /*return*/, $
|
|
4795
|
+
return [2 /*return*/, $ongoingTaskResult.$resultString];
|
|
4783
4796
|
}
|
|
4784
4797
|
});
|
|
4785
4798
|
});
|
|
@@ -4795,36 +4808,36 @@ function executeAttempts(options) {
|
|
|
4795
4808
|
*/
|
|
4796
4809
|
function executeFormatSubvalues(options) {
|
|
4797
4810
|
return __awaiter(this, void 0, void 0, function () {
|
|
4798
|
-
var
|
|
4811
|
+
var task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
|
|
4799
4812
|
var _this = this;
|
|
4800
4813
|
return __generator(this, function (_a) {
|
|
4801
4814
|
switch (_a.label) {
|
|
4802
4815
|
case 0:
|
|
4803
|
-
|
|
4804
|
-
if (
|
|
4816
|
+
task = options.task, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, csvSettings = options.csvSettings, pipelineIdentification = options.pipelineIdentification;
|
|
4817
|
+
if (task.foreach === undefined) {
|
|
4805
4818
|
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
4806
4819
|
}
|
|
4807
4820
|
if (jokerParameterNames.length !== 0) {
|
|
4808
4821
|
throw new UnexpectedError(spaceTrim(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 "); }));
|
|
4809
4822
|
}
|
|
4810
|
-
parameterValue = parameters[
|
|
4823
|
+
parameterValue = parameters[task.foreach.parameterName] || '';
|
|
4811
4824
|
formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
|
|
4812
|
-
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(
|
|
4825
|
+
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(task.foreach.formatName);
|
|
4813
4826
|
});
|
|
4814
4827
|
if (formatDefinition === undefined) {
|
|
4815
4828
|
throw new UnexpectedError(
|
|
4816
4829
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
4817
|
-
spaceTrim(function (block) { return "\n Unsupported format \"".concat(
|
|
4830
|
+
spaceTrim(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; })
|
|
4818
4831
|
.map(function (formatName) { return "- ".concat(formatName); })
|
|
4819
4832
|
.join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4820
4833
|
}
|
|
4821
4834
|
subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
4822
|
-
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(
|
|
4835
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(task.foreach.subformatName);
|
|
4823
4836
|
});
|
|
4824
4837
|
if (subvalueDefinition === undefined) {
|
|
4825
4838
|
throw new UnexpectedError(
|
|
4826
4839
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
4827
|
-
spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(
|
|
4840
|
+
spaceTrim(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
|
|
4828
4841
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
4829
4842
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
4830
4843
|
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
@@ -4833,7 +4846,7 @@ function executeFormatSubvalues(options) {
|
|
|
4833
4846
|
formatSettings = csvSettings;
|
|
4834
4847
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
4835
4848
|
}
|
|
4836
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue,
|
|
4849
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4837
4850
|
var mappedParameters, allSubparameters, subresultString;
|
|
4838
4851
|
return __generator(this, function (_a) {
|
|
4839
4852
|
switch (_a.label) {
|
|
@@ -4842,7 +4855,7 @@ function executeFormatSubvalues(options) {
|
|
|
4842
4855
|
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
4843
4856
|
try {
|
|
4844
4857
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
4845
|
-
expectedParameters: Object.fromEntries(
|
|
4858
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
4846
4859
|
availableParameters: subparameters,
|
|
4847
4860
|
});
|
|
4848
4861
|
}
|
|
@@ -4875,7 +4888,7 @@ function executeFormatSubvalues(options) {
|
|
|
4875
4888
|
*
|
|
4876
4889
|
* @private internal utility of `createPipelineExecutor`
|
|
4877
4890
|
*/
|
|
4878
|
-
function
|
|
4891
|
+
function getContextForTask(task) {
|
|
4879
4892
|
return __awaiter(this, void 0, void 0, function () {
|
|
4880
4893
|
return __generator(this, function (_a) {
|
|
4881
4894
|
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
@@ -4888,15 +4901,10 @@ function getContextForTemplate(template) {
|
|
|
4888
4901
|
*
|
|
4889
4902
|
* @private internal utility of `createPipelineExecutor`
|
|
4890
4903
|
*/
|
|
4891
|
-
function
|
|
4904
|
+
function getExamplesForTask(task) {
|
|
4892
4905
|
return __awaiter(this, void 0, void 0, function () {
|
|
4893
|
-
var preparedPipeline;
|
|
4894
4906
|
return __generator(this, function (_a) {
|
|
4895
|
-
|
|
4896
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
4897
|
-
var content = _a.content;
|
|
4898
|
-
return "- ".concat(content);
|
|
4899
|
-
}).join('\n')];
|
|
4907
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
4900
4908
|
});
|
|
4901
4909
|
});
|
|
4902
4910
|
}
|
|
@@ -4906,10 +4914,15 @@ function getKnowledgeForTemplate(options) {
|
|
|
4906
4914
|
*
|
|
4907
4915
|
* @private internal utility of `createPipelineExecutor`
|
|
4908
4916
|
*/
|
|
4909
|
-
function
|
|
4917
|
+
function getKnowledgeForTask(options) {
|
|
4910
4918
|
return __awaiter(this, void 0, void 0, function () {
|
|
4919
|
+
var preparedPipeline;
|
|
4911
4920
|
return __generator(this, function (_a) {
|
|
4912
|
-
|
|
4921
|
+
preparedPipeline = options.preparedPipeline, options.task;
|
|
4922
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
4923
|
+
var content = _a.content;
|
|
4924
|
+
return "- ".concat(content);
|
|
4925
|
+
}).join('\n')];
|
|
4913
4926
|
});
|
|
4914
4927
|
});
|
|
4915
4928
|
}
|
|
@@ -4919,21 +4932,21 @@ function getExamplesForTemplate(template) {
|
|
|
4919
4932
|
*
|
|
4920
4933
|
* @private internal utility of `createPipelineExecutor`
|
|
4921
4934
|
*/
|
|
4922
|
-
function
|
|
4935
|
+
function getReservedParametersForTask(options) {
|
|
4923
4936
|
return __awaiter(this, void 0, void 0, function () {
|
|
4924
|
-
var preparedPipeline,
|
|
4937
|
+
var preparedPipeline, task, pipelineIdentification, context, knowledge, examples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
4925
4938
|
var e_1, _a;
|
|
4926
4939
|
return __generator(this, function (_b) {
|
|
4927
4940
|
switch (_b.label) {
|
|
4928
4941
|
case 0:
|
|
4929
|
-
preparedPipeline = options.preparedPipeline,
|
|
4930
|
-
return [4 /*yield*/,
|
|
4942
|
+
preparedPipeline = options.preparedPipeline, task = options.task, pipelineIdentification = options.pipelineIdentification;
|
|
4943
|
+
return [4 /*yield*/, getContextForTask()];
|
|
4931
4944
|
case 1:
|
|
4932
4945
|
context = _b.sent();
|
|
4933
|
-
return [4 /*yield*/,
|
|
4946
|
+
return [4 /*yield*/, getKnowledgeForTask({ preparedPipeline: preparedPipeline, task: task })];
|
|
4934
4947
|
case 2:
|
|
4935
4948
|
knowledge = _b.sent();
|
|
4936
|
-
return [4 /*yield*/,
|
|
4949
|
+
return [4 /*yield*/, getExamplesForTask()];
|
|
4937
4950
|
case 3:
|
|
4938
4951
|
examples = _b.sent();
|
|
4939
4952
|
currentDate = new Date().toISOString();
|
|
@@ -4976,31 +4989,31 @@ function getReservedParametersForTemplate(options) {
|
|
|
4976
4989
|
*
|
|
4977
4990
|
* @private internal utility of `createPipelineExecutor`
|
|
4978
4991
|
*/
|
|
4979
|
-
function
|
|
4992
|
+
function executeTask(options) {
|
|
4980
4993
|
return __awaiter(this, void 0, void 0, function () {
|
|
4981
|
-
var
|
|
4994
|
+
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;
|
|
4982
4995
|
var e_1, _g, _h;
|
|
4983
4996
|
return __generator(this, function (_j) {
|
|
4984
4997
|
switch (_j.label) {
|
|
4985
4998
|
case 0:
|
|
4986
|
-
|
|
4987
|
-
name = "pipeline-executor-frame-".concat(
|
|
4988
|
-
title =
|
|
4989
|
-
priority = preparedPipeline.
|
|
4999
|
+
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;
|
|
5000
|
+
name = "pipeline-executor-frame-".concat(currentTask.name);
|
|
5001
|
+
title = currentTask.title;
|
|
5002
|
+
priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
4990
5003
|
return [4 /*yield*/, onProgress({
|
|
4991
5004
|
name: name,
|
|
4992
5005
|
title: title,
|
|
4993
5006
|
isStarted: false,
|
|
4994
5007
|
isDone: false,
|
|
4995
|
-
|
|
4996
|
-
parameterName:
|
|
5008
|
+
taskType: currentTask.taskType,
|
|
5009
|
+
parameterName: currentTask.resultingParameterName,
|
|
4997
5010
|
parameterValue: null,
|
|
4998
5011
|
// <- [🍸]
|
|
4999
5012
|
})];
|
|
5000
5013
|
case 1:
|
|
5001
5014
|
_j.sent();
|
|
5002
|
-
usedParameterNames =
|
|
5003
|
-
dependentParameterNames = new Set(
|
|
5015
|
+
usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5016
|
+
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
5004
5017
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
5005
5018
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
5006
5019
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames)
|
|
@@ -5011,9 +5024,9 @@ function executeTemplate(options) {
|
|
|
5011
5024
|
}
|
|
5012
5025
|
_c = (_b = Object).freeze;
|
|
5013
5026
|
_d = [{}];
|
|
5014
|
-
return [4 /*yield*/,
|
|
5027
|
+
return [4 /*yield*/, getReservedParametersForTask({
|
|
5015
5028
|
preparedPipeline: preparedPipeline,
|
|
5016
|
-
|
|
5029
|
+
task: currentTask,
|
|
5017
5030
|
pipelineIdentification: pipelineIdentification,
|
|
5018
5031
|
})];
|
|
5019
5032
|
case 2:
|
|
@@ -5031,11 +5044,11 @@ function executeTemplate(options) {
|
|
|
5031
5044
|
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
5032
5045
|
// Houston, we have a problem
|
|
5033
5046
|
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
5034
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in
|
|
5047
|
+
throw new UnexpectedError(spaceTrim$1(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 "); }));
|
|
5035
5048
|
}
|
|
5036
5049
|
};
|
|
5037
5050
|
try {
|
|
5038
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this
|
|
5051
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this task
|
|
5039
5052
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
5040
5053
|
for (_e = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
5041
5054
|
parameterName = _f.value;
|
|
@@ -5051,18 +5064,16 @@ function executeTemplate(options) {
|
|
|
5051
5064
|
}
|
|
5052
5065
|
// 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
|
|
5053
5066
|
Object.freeze(parameters);
|
|
5054
|
-
maxAttempts =
|
|
5055
|
-
jokerParameterNames =
|
|
5056
|
-
preparedContent = (
|
|
5057
|
-
.split('{content}')
|
|
5058
|
-
.join(currentTemplate.content);
|
|
5067
|
+
maxAttempts = currentTask.taskType === 'DIALOG_TASK' ? Infinity : maxExecutionAttempts;
|
|
5068
|
+
jokerParameterNames = currentTask.jokerParameterNames || [];
|
|
5069
|
+
preparedContent = (currentTask.preparedContent || '{content}').split('{content}').join(currentTask.content);
|
|
5059
5070
|
return [4 /*yield*/, executeFormatSubvalues({
|
|
5060
5071
|
jokerParameterNames: jokerParameterNames,
|
|
5061
5072
|
priority: priority,
|
|
5062
5073
|
maxAttempts: maxAttempts,
|
|
5063
5074
|
preparedContent: preparedContent,
|
|
5064
5075
|
parameters: parameters,
|
|
5065
|
-
|
|
5076
|
+
task: currentTask,
|
|
5066
5077
|
preparedPipeline: preparedPipeline,
|
|
5067
5078
|
tools: tools,
|
|
5068
5079
|
$executionReport: $executionReport,
|
|
@@ -5075,15 +5086,15 @@ function executeTemplate(options) {
|
|
|
5075
5086
|
title: title,
|
|
5076
5087
|
isStarted: true,
|
|
5077
5088
|
isDone: true,
|
|
5078
|
-
|
|
5079
|
-
parameterName:
|
|
5089
|
+
taskType: currentTask.taskType,
|
|
5090
|
+
parameterName: currentTask.resultingParameterName,
|
|
5080
5091
|
parameterValue: resultString,
|
|
5081
5092
|
// <- [🍸]
|
|
5082
5093
|
})];
|
|
5083
5094
|
case 4:
|
|
5084
5095
|
_j.sent();
|
|
5085
5096
|
return [2 /*return*/, Object.freeze((_h = {},
|
|
5086
|
-
_h[
|
|
5097
|
+
_h[currentTask.resultingParameterName] =
|
|
5087
5098
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5088
5099
|
resultString,
|
|
5089
5100
|
_h))];
|
|
@@ -5145,7 +5156,7 @@ function filterJustOutputParameters(options) {
|
|
|
5145
5156
|
*/
|
|
5146
5157
|
function executePipeline(options) {
|
|
5147
5158
|
return __awaiter(this, void 0, void 0, function () {
|
|
5148
|
-
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,
|
|
5159
|
+
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;
|
|
5149
5160
|
var e_1, _f, e_2, _g;
|
|
5150
5161
|
return __generator(this, function (_h) {
|
|
5151
5162
|
switch (_h.label) {
|
|
@@ -5299,11 +5310,11 @@ function executePipeline(options) {
|
|
|
5299
5310
|
var name = _a.name;
|
|
5300
5311
|
return name;
|
|
5301
5312
|
});
|
|
5302
|
-
|
|
5313
|
+
unresovedTasks_1 = __spreadArray([], __read(preparedPipeline.tasks), false);
|
|
5303
5314
|
resolving_1 = [];
|
|
5304
5315
|
loopLimit = LOOP_LIMIT;
|
|
5305
5316
|
_loop_2 = function () {
|
|
5306
|
-
var
|
|
5317
|
+
var currentTask, work_1;
|
|
5307
5318
|
return __generator(this, function (_k) {
|
|
5308
5319
|
switch (_k.label) {
|
|
5309
5320
|
case 0:
|
|
@@ -5311,15 +5322,15 @@ function executePipeline(options) {
|
|
|
5311
5322
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
5312
5323
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
5313
5324
|
}
|
|
5314
|
-
|
|
5315
|
-
return
|
|
5325
|
+
currentTask = unresovedTasks_1.find(function (task) {
|
|
5326
|
+
return task.dependentParameterNames.every(function (name) {
|
|
5316
5327
|
return __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), __read(RESERVED_PARAMETER_NAMES), false).includes(name);
|
|
5317
5328
|
});
|
|
5318
5329
|
});
|
|
5319
|
-
if (!(!
|
|
5330
|
+
if (!(!currentTask && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
5320
5331
|
throw new UnexpectedError(
|
|
5321
5332
|
// TODO: [🐎] DRY
|
|
5322
|
-
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(
|
|
5333
|
+
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks_1
|
|
5323
5334
|
.map(function (_a) {
|
|
5324
5335
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
5325
5336
|
return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
|
|
@@ -5338,14 +5349,14 @@ function executePipeline(options) {
|
|
|
5338
5349
|
.map(function (name) { return "- Parameter `{".concat(name, "}`"); })
|
|
5339
5350
|
.join('\n')), "\n\n *Note: This should be catched in `validatePipeline`*\n "); }));
|
|
5340
5351
|
case 1:
|
|
5341
|
-
if (!!
|
|
5352
|
+
if (!!currentTask) return [3 /*break*/, 3];
|
|
5342
5353
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
5343
5354
|
case 2:
|
|
5344
5355
|
/* [🤹♂️] */ _k.sent();
|
|
5345
5356
|
return [3 /*break*/, 4];
|
|
5346
5357
|
case 3:
|
|
5347
|
-
|
|
5348
|
-
work_1 =
|
|
5358
|
+
unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
|
|
5359
|
+
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
|
|
5349
5360
|
if (isReturned) {
|
|
5350
5361
|
throw new UnexpectedError(spaceTrim$1(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)
|
|
5351
5362
|
.split('\n')
|
|
@@ -5355,16 +5366,16 @@ function executePipeline(options) {
|
|
|
5355
5366
|
if (onProgress) {
|
|
5356
5367
|
onProgress(progress);
|
|
5357
5368
|
}
|
|
5358
|
-
}, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n
|
|
5369
|
+
}, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
5359
5370
|
.then(function (newParametersToPass) {
|
|
5360
5371
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
5361
|
-
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [
|
|
5372
|
+
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTask.resultingParameterName], false);
|
|
5362
5373
|
})
|
|
5363
5374
|
.then(function () {
|
|
5364
5375
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
5365
5376
|
});
|
|
5366
5377
|
// <- Note: Errors are catched here [3]
|
|
5367
|
-
// TODO: BUT if in multiple
|
|
5378
|
+
// 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
|
|
5368
5379
|
resolving_1.push(work_1);
|
|
5369
5380
|
_k.label = 4;
|
|
5370
5381
|
case 4: return [2 /*return*/];
|
|
@@ -5373,7 +5384,7 @@ function executePipeline(options) {
|
|
|
5373
5384
|
};
|
|
5374
5385
|
_h.label = 21;
|
|
5375
5386
|
case 21:
|
|
5376
|
-
if (!(
|
|
5387
|
+
if (!(unresovedTasks_1.length > 0)) return [3 /*break*/, 23];
|
|
5377
5388
|
return [5 /*yield**/, _loop_2()];
|
|
5378
5389
|
case 22:
|
|
5379
5390
|
_h.sent();
|
|
@@ -5531,6 +5542,9 @@ var markdownScraperMetadata = $deepFreeze({
|
|
|
5531
5542
|
* @public exported from `@promptbook/cli`
|
|
5532
5543
|
*/
|
|
5533
5544
|
$scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
5545
|
+
/**
|
|
5546
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5547
|
+
*/
|
|
5534
5548
|
|
|
5535
5549
|
/**
|
|
5536
5550
|
* Scraper for markdown files
|
|
@@ -5725,6 +5739,7 @@ var createMarkdownScraper = Object.assign(function (tools, options) {
|
|
|
5725
5739
|
var _MarkdownScraperRegistration = $scrapersRegister.register(createMarkdownScraper);
|
|
5726
5740
|
/**
|
|
5727
5741
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
5742
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5728
5743
|
*/
|
|
5729
5744
|
|
|
5730
5745
|
/**
|