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