@promptbook/pdf 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 +268 -249
- 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 +5 -4
- package/umd/index.umd.js +268 -249
- 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
|
/*! *****************************************************************************
|
|
@@ -175,7 +176,7 @@
|
|
|
175
176
|
function TODO_USE() {
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
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}],
|
|
179
|
+
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"}];
|
|
179
180
|
|
|
180
181
|
/**
|
|
181
182
|
* Prettify the html code
|
|
@@ -229,7 +230,7 @@
|
|
|
229
230
|
*/
|
|
230
231
|
function pipelineJsonToString(pipelineJson) {
|
|
231
232
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
232
|
-
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters,
|
|
233
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, tasks = pipelineJson.tasks;
|
|
233
234
|
var pipelineString = "# ".concat(title);
|
|
234
235
|
if (description) {
|
|
235
236
|
pipelineString += '\n\n';
|
|
@@ -250,7 +251,7 @@
|
|
|
250
251
|
return isInput;
|
|
251
252
|
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
252
253
|
var parameter = _h.value;
|
|
253
|
-
commands.push("INPUT PARAMETER ".concat(
|
|
254
|
+
commands.push("INPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
257
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -266,7 +267,7 @@
|
|
|
266
267
|
return isOutput;
|
|
267
268
|
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
268
269
|
var parameter = _k.value;
|
|
269
|
-
commands.push("OUTPUT PARAMETER ".concat(
|
|
270
|
+
commands.push("OUTPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
|
|
270
271
|
}
|
|
271
272
|
}
|
|
272
273
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -279,13 +280,13 @@
|
|
|
279
280
|
pipelineString += '\n\n';
|
|
280
281
|
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
281
282
|
try {
|
|
282
|
-
for (var
|
|
283
|
-
var
|
|
283
|
+
for (var tasks_1 = __values(tasks), tasks_1_1 = tasks_1.next(); !tasks_1_1.done; tasks_1_1 = tasks_1.next()) {
|
|
284
|
+
var task = tasks_1_1.value;
|
|
284
285
|
var
|
|
285
286
|
/* Note: Not using:> name, */
|
|
286
|
-
title_1 =
|
|
287
|
+
title_1 = task.title, description_1 = task.description,
|
|
287
288
|
/* Note: dependentParameterNames, */
|
|
288
|
-
jokers =
|
|
289
|
+
jokers = task.jokerParameterNames, taskType = task.taskType, content = task.content, postprocessing = task.postprocessingFunctionNames, expectations = task.expectations, format = task.format, resultingParameterName = task.resultingParameterName;
|
|
289
290
|
pipelineString += '\n\n';
|
|
290
291
|
pipelineString += "## ".concat(title_1);
|
|
291
292
|
if (description_1) {
|
|
@@ -294,10 +295,11 @@
|
|
|
294
295
|
}
|
|
295
296
|
var commands_1 = [];
|
|
296
297
|
var contentLanguage = 'text';
|
|
297
|
-
if (
|
|
298
|
-
var modelRequirements =
|
|
298
|
+
if (taskType === 'PROMPT_TASK') {
|
|
299
|
+
var modelRequirements = task.modelRequirements;
|
|
299
300
|
var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
|
|
300
|
-
|
|
301
|
+
// Note: Do nothing, it is default
|
|
302
|
+
// commands.push(`PROMPT`);
|
|
301
303
|
if (modelVariant) {
|
|
302
304
|
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
303
305
|
}
|
|
@@ -305,21 +307,21 @@
|
|
|
305
307
|
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
306
308
|
}
|
|
307
309
|
}
|
|
308
|
-
else if (
|
|
310
|
+
else if (taskType === 'SIMPLE_TASK') {
|
|
309
311
|
commands_1.push("SIMPLE TEMPLATE");
|
|
310
312
|
// Note: Nothing special here
|
|
311
313
|
}
|
|
312
|
-
else if (
|
|
313
|
-
commands_1.push("SCRIPT
|
|
314
|
-
if (
|
|
315
|
-
contentLanguage =
|
|
314
|
+
else if (taskType === 'SCRIPT_TASK') {
|
|
315
|
+
commands_1.push("SCRIPT");
|
|
316
|
+
if (task.contentLanguage) {
|
|
317
|
+
contentLanguage = task.contentLanguage;
|
|
316
318
|
}
|
|
317
319
|
else {
|
|
318
320
|
contentLanguage = '';
|
|
319
321
|
}
|
|
320
322
|
}
|
|
321
|
-
else if (
|
|
322
|
-
commands_1.push("DIALOG
|
|
323
|
+
else if (taskType === 'DIALOG_TASK') {
|
|
324
|
+
commands_1.push("DIALOG");
|
|
323
325
|
// Note: Nothing special here
|
|
324
326
|
} // <- }else if([🅱]
|
|
325
327
|
if (jokers) {
|
|
@@ -394,13 +396,13 @@
|
|
|
394
396
|
pipelineString += '\n';
|
|
395
397
|
pipelineString += '```';
|
|
396
398
|
pipelineString += '\n\n';
|
|
397
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use
|
|
399
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
|
|
398
400
|
}
|
|
399
401
|
}
|
|
400
402
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
401
403
|
finally {
|
|
402
404
|
try {
|
|
403
|
-
if (
|
|
405
|
+
if (tasks_1_1 && !tasks_1_1.done && (_c = tasks_1.return)) _c.call(tasks_1);
|
|
404
406
|
}
|
|
405
407
|
finally { if (e_3) throw e_3.error; }
|
|
406
408
|
}
|
|
@@ -409,8 +411,8 @@
|
|
|
409
411
|
/**
|
|
410
412
|
* @private internal utility of `pipelineJsonToString`
|
|
411
413
|
*/
|
|
412
|
-
function
|
|
413
|
-
var name =
|
|
414
|
+
function taskParameterJsonToString(taskParameterJson) {
|
|
415
|
+
var name = taskParameterJson.name, description = taskParameterJson.description;
|
|
414
416
|
var parameterString = "{".concat(name, "}");
|
|
415
417
|
if (description) {
|
|
416
418
|
parameterString = "".concat(parameterString, " ").concat(description);
|
|
@@ -418,7 +420,7 @@
|
|
|
418
420
|
return parameterString;
|
|
419
421
|
}
|
|
420
422
|
/**
|
|
421
|
-
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `
|
|
423
|
+
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
422
424
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
423
425
|
* TODO: [🏛] Maybe make some markdown builder
|
|
424
426
|
* TODO: [🏛] Escape all
|
|
@@ -727,6 +729,7 @@
|
|
|
727
729
|
true);
|
|
728
730
|
/**
|
|
729
731
|
* TODO: Extract `constants.ts` from `config.ts`
|
|
732
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
730
733
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
731
734
|
*/
|
|
732
735
|
|
|
@@ -982,9 +985,9 @@
|
|
|
982
985
|
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 "); }));
|
|
983
986
|
}
|
|
984
987
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
985
|
-
if (!Array.isArray(pipeline.
|
|
988
|
+
if (!Array.isArray(pipeline.tasks)) {
|
|
986
989
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
987
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.
|
|
990
|
+
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 "); }));
|
|
988
991
|
}
|
|
989
992
|
var _loop_1 = function (parameter) {
|
|
990
993
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -993,13 +996,12 @@
|
|
|
993
996
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
994
997
|
if (!parameter.isInput &&
|
|
995
998
|
!parameter.isOutput &&
|
|
996
|
-
!pipeline.
|
|
999
|
+
!pipeline.tasks.some(function (task) { return task.dependentParameterNames.includes(parameter.name); })) {
|
|
997
1000
|
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 "); }));
|
|
998
1001
|
}
|
|
999
|
-
// Note: Testing that parameter is either input or result of some
|
|
1000
|
-
if (!parameter.isInput &&
|
|
1001
|
-
|
|
1002
|
-
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 "); }));
|
|
1002
|
+
// Note: Testing that parameter is either input or result of some task
|
|
1003
|
+
if (!parameter.isInput && !pipeline.tasks.some(function (task) { return task.resultingParameterName === parameter.name; })) {
|
|
1004
|
+
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 "); }));
|
|
1003
1005
|
}
|
|
1004
1006
|
};
|
|
1005
1007
|
try {
|
|
@@ -1016,7 +1018,7 @@
|
|
|
1016
1018
|
}
|
|
1017
1019
|
finally { if (e_1) throw e_1.error; }
|
|
1018
1020
|
}
|
|
1019
|
-
// Note: All input parameters are defined - so that they can be used as result of some
|
|
1021
|
+
// Note: All input parameters are defined - so that they can be used as result of some task
|
|
1020
1022
|
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
1021
1023
|
var isInput = _a.isInput;
|
|
1022
1024
|
return isInput;
|
|
@@ -1024,27 +1026,27 @@
|
|
|
1024
1026
|
var name = _a.name;
|
|
1025
1027
|
return name;
|
|
1026
1028
|
}));
|
|
1027
|
-
var _loop_2 = function (
|
|
1029
|
+
var _loop_2 = function (task) {
|
|
1028
1030
|
var e_4, _h, e_5, _j;
|
|
1029
|
-
if (definedParameters.has(
|
|
1030
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(
|
|
1031
|
+
if (definedParameters.has(task.resultingParameterName)) {
|
|
1032
|
+
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1031
1033
|
}
|
|
1032
|
-
if (RESERVED_PARAMETER_NAMES.includes(
|
|
1033
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter name {".concat(
|
|
1034
|
+
if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
|
|
1035
|
+
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 "); }));
|
|
1034
1036
|
}
|
|
1035
|
-
definedParameters.add(
|
|
1036
|
-
if (
|
|
1037
|
-
if (!
|
|
1038
|
-
!
|
|
1039
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(
|
|
1037
|
+
definedParameters.add(task.resultingParameterName);
|
|
1038
|
+
if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
|
|
1039
|
+
if (!task.format &&
|
|
1040
|
+
!task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
1041
|
+
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 "); }));
|
|
1040
1042
|
}
|
|
1041
1043
|
var _loop_4 = function (joker) {
|
|
1042
|
-
if (!
|
|
1043
|
-
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(
|
|
1044
|
+
if (!task.dependentParameterNames.includes(joker)) {
|
|
1045
|
+
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 "); }));
|
|
1044
1046
|
}
|
|
1045
1047
|
};
|
|
1046
1048
|
try {
|
|
1047
|
-
for (var _k = (e_4 = void 0, __values(
|
|
1049
|
+
for (var _k = (e_4 = void 0, __values(task.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
1048
1050
|
var joker = _l.value;
|
|
1049
1051
|
_loop_4(joker);
|
|
1050
1052
|
}
|
|
@@ -1057,7 +1059,7 @@
|
|
|
1057
1059
|
finally { if (e_4) throw e_4.error; }
|
|
1058
1060
|
}
|
|
1059
1061
|
}
|
|
1060
|
-
if (
|
|
1062
|
+
if (task.expectations) {
|
|
1061
1063
|
var _loop_5 = function (unit, min, max) {
|
|
1062
1064
|
if (min !== undefined && max !== undefined && min > max) {
|
|
1063
1065
|
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 "); }));
|
|
@@ -1070,7 +1072,7 @@
|
|
|
1070
1072
|
}
|
|
1071
1073
|
};
|
|
1072
1074
|
try {
|
|
1073
|
-
for (var _m = (e_5 = void 0, __values(Object.entries(
|
|
1075
|
+
for (var _m = (e_5 = void 0, __values(Object.entries(task.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
1074
1076
|
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
1075
1077
|
_loop_5(unit, min, max);
|
|
1076
1078
|
}
|
|
@@ -1085,10 +1087,10 @@
|
|
|
1085
1087
|
}
|
|
1086
1088
|
};
|
|
1087
1089
|
try {
|
|
1088
|
-
// Note: Checking each
|
|
1089
|
-
for (var _f = __values(pipeline.
|
|
1090
|
-
var
|
|
1091
|
-
_loop_2(
|
|
1090
|
+
// Note: Checking each task individually
|
|
1091
|
+
for (var _f = __values(pipeline.tasks), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1092
|
+
var task = _g.value;
|
|
1093
|
+
_loop_2(task);
|
|
1092
1094
|
}
|
|
1093
1095
|
}
|
|
1094
1096
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -1122,20 +1124,20 @@
|
|
|
1122
1124
|
}
|
|
1123
1125
|
finally { if (e_3) throw e_3.error; }
|
|
1124
1126
|
}
|
|
1125
|
-
var
|
|
1127
|
+
var unresovedTasks = __spreadArray([], __read(pipeline.tasks), false);
|
|
1126
1128
|
var loopLimit = LOOP_LIMIT;
|
|
1127
1129
|
var _loop_3 = function () {
|
|
1128
1130
|
if (loopLimit-- < 0) {
|
|
1129
1131
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
1130
1132
|
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 "); }));
|
|
1131
1133
|
}
|
|
1132
|
-
var
|
|
1133
|
-
return
|
|
1134
|
+
var currentlyResovedTasks = unresovedTasks.filter(function (task) {
|
|
1135
|
+
return task.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
1134
1136
|
});
|
|
1135
|
-
if (
|
|
1137
|
+
if (currentlyResovedTasks.length === 0) {
|
|
1136
1138
|
throw new PipelineLogicError(
|
|
1137
1139
|
// TODO: [🐎] DRY
|
|
1138
|
-
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(
|
|
1140
|
+
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
|
|
1139
1141
|
.map(function (_a) {
|
|
1140
1142
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1141
1143
|
return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
|
|
@@ -1154,13 +1156,13 @@
|
|
|
1154
1156
|
.map(function (name) { return "- Parameter `{".concat(name, "}`"); })
|
|
1155
1157
|
.join('\n')), "\n\n\n "); }));
|
|
1156
1158
|
}
|
|
1157
|
-
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(
|
|
1159
|
+
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTasks.map(function (_a) {
|
|
1158
1160
|
var resultingParameterName = _a.resultingParameterName;
|
|
1159
1161
|
return resultingParameterName;
|
|
1160
1162
|
})), false);
|
|
1161
|
-
|
|
1163
|
+
unresovedTasks = unresovedTasks.filter(function (task) { return !currentlyResovedTasks.includes(task); });
|
|
1162
1164
|
};
|
|
1163
|
-
while (
|
|
1165
|
+
while (unresovedTasks.length > 0) {
|
|
1164
1166
|
_loop_3();
|
|
1165
1167
|
}
|
|
1166
1168
|
// TODO: !!!!!! Test that pipeline interface implements declared formfactor interface
|
|
@@ -1220,9 +1222,9 @@
|
|
|
1220
1222
|
}(Error));
|
|
1221
1223
|
|
|
1222
1224
|
/**
|
|
1223
|
-
* Parses the
|
|
1225
|
+
* Parses the task and returns the list of all parameter names
|
|
1224
1226
|
*
|
|
1225
|
-
* @param template the template with parameters in {curly} braces
|
|
1227
|
+
* @param template the string template with parameters in {curly} braces
|
|
1226
1228
|
* @returns the list of parameter names
|
|
1227
1229
|
* @public exported from `@promptbook/utils`
|
|
1228
1230
|
*/
|
|
@@ -1253,18 +1255,18 @@
|
|
|
1253
1255
|
* @public exported from `@promptbook/core`
|
|
1254
1256
|
*/
|
|
1255
1257
|
function unpreparePipeline(pipeline) {
|
|
1256
|
-
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources,
|
|
1258
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, tasks = pipeline.tasks;
|
|
1257
1259
|
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
1258
1260
|
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
1259
|
-
|
|
1260
|
-
var dependentParameterNames =
|
|
1261
|
-
var parameterNames = extractParameterNames(
|
|
1261
|
+
tasks = tasks.map(function (task) {
|
|
1262
|
+
var dependentParameterNames = task.dependentParameterNames;
|
|
1263
|
+
var parameterNames = extractParameterNames(task.preparedContent || '');
|
|
1262
1264
|
dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
|
|
1263
|
-
var
|
|
1264
|
-
delete
|
|
1265
|
-
return
|
|
1265
|
+
var taskUnprepared = __assign(__assign({}, task), { dependentParameterNames: dependentParameterNames });
|
|
1266
|
+
delete taskUnprepared.preparedContent;
|
|
1267
|
+
return taskUnprepared;
|
|
1266
1268
|
});
|
|
1267
|
-
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), {
|
|
1269
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1268
1270
|
}
|
|
1269
1271
|
/**
|
|
1270
1272
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1696,6 +1698,9 @@
|
|
|
1696
1698
|
normalizedName = normalizedName.replace(/-$/, '');
|
|
1697
1699
|
return normalizedName;
|
|
1698
1700
|
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1703
|
+
*/
|
|
1699
1704
|
|
|
1700
1705
|
/**
|
|
1701
1706
|
* Removes emojis from a string and fix whitespaces
|
|
@@ -1881,6 +1886,9 @@
|
|
|
1881
1886
|
UnexpectedError: UnexpectedError,
|
|
1882
1887
|
// TODO: [🪑]> VersionMismatchError,
|
|
1883
1888
|
};
|
|
1889
|
+
/**
|
|
1890
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1891
|
+
*/
|
|
1884
1892
|
|
|
1885
1893
|
/**
|
|
1886
1894
|
* Deserializes the error object
|
|
@@ -1942,8 +1950,8 @@
|
|
|
1942
1950
|
return false;
|
|
1943
1951
|
}
|
|
1944
1952
|
/*
|
|
1945
|
-
TODO: [🧠][🍫] `
|
|
1946
|
-
> if (!pipeline.
|
|
1953
|
+
TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
1954
|
+
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
1947
1955
|
> return false;
|
|
1948
1956
|
> }
|
|
1949
1957
|
*/
|
|
@@ -1954,9 +1962,9 @@
|
|
|
1954
1962
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
1955
1963
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
1956
1964
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
1957
|
-
* - [🏍] ? Is context in each
|
|
1965
|
+
* - [🏍] ? Is context in each task
|
|
1958
1966
|
* - [♨] Are examples prepared
|
|
1959
|
-
* - [♨] Are
|
|
1967
|
+
* - [♨] Are tasks prepared
|
|
1960
1968
|
*/
|
|
1961
1969
|
|
|
1962
1970
|
/**
|
|
@@ -2104,6 +2112,9 @@
|
|
|
2104
2112
|
pagesCount: { value: 0, isUncertain: true },
|
|
2105
2113
|
},
|
|
2106
2114
|
});
|
|
2115
|
+
/**
|
|
2116
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2117
|
+
*/
|
|
2107
2118
|
|
|
2108
2119
|
/**
|
|
2109
2120
|
* @@@
|
|
@@ -3290,7 +3301,7 @@
|
|
|
3290
3301
|
*/
|
|
3291
3302
|
function clonePipeline(pipeline) {
|
|
3292
3303
|
// Note: Not using spread operator (...) because @@@
|
|
3293
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters,
|
|
3304
|
+
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;
|
|
3294
3305
|
return {
|
|
3295
3306
|
pipelineUrl: pipelineUrl,
|
|
3296
3307
|
sourceFile: sourceFile,
|
|
@@ -3299,7 +3310,7 @@
|
|
|
3299
3310
|
description: description,
|
|
3300
3311
|
formfactorName: formfactorName,
|
|
3301
3312
|
parameters: parameters,
|
|
3302
|
-
|
|
3313
|
+
tasks: tasks,
|
|
3303
3314
|
knowledgeSources: knowledgeSources,
|
|
3304
3315
|
knowledgePieces: knowledgePieces,
|
|
3305
3316
|
personas: personas,
|
|
@@ -3315,20 +3326,20 @@
|
|
|
3315
3326
|
*
|
|
3316
3327
|
* @public exported from `@promptbook/core`
|
|
3317
3328
|
*/
|
|
3318
|
-
function
|
|
3329
|
+
function prepareTasks(pipeline, tools, options) {
|
|
3319
3330
|
return __awaiter(this, void 0, void 0, function () {
|
|
3320
|
-
var _a, maxParallelCount,
|
|
3331
|
+
var _a, maxParallelCount, tasks, knowledgePiecesCount, tasksPrepared;
|
|
3321
3332
|
var _this = this;
|
|
3322
3333
|
return __generator(this, function (_b) {
|
|
3323
3334
|
switch (_b.label) {
|
|
3324
3335
|
case 0:
|
|
3325
3336
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
return [4 /*yield*/, forEachAsync(
|
|
3329
|
-
var dependentParameterNames, preparedContent,
|
|
3337
|
+
tasks = pipeline.tasks, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3338
|
+
tasksPrepared = new Array(tasks.length);
|
|
3339
|
+
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 () {
|
|
3340
|
+
var dependentParameterNames, preparedContent, preparedTask;
|
|
3330
3341
|
return __generator(this, function (_a) {
|
|
3331
|
-
dependentParameterNames =
|
|
3342
|
+
dependentParameterNames = task.dependentParameterNames;
|
|
3332
3343
|
preparedContent = undefined;
|
|
3333
3344
|
if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
|
|
3334
3345
|
preparedContent = spaceTrim.spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
@@ -3337,22 +3348,22 @@
|
|
|
3337
3348
|
'knowledge',
|
|
3338
3349
|
], false);
|
|
3339
3350
|
}
|
|
3340
|
-
|
|
3341
|
-
|
|
3351
|
+
preparedTask = __assign(__assign({}, task), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
|
|
3352
|
+
tasksPrepared[index] = preparedTask;
|
|
3342
3353
|
return [2 /*return*/];
|
|
3343
3354
|
});
|
|
3344
3355
|
}); })];
|
|
3345
3356
|
case 1:
|
|
3346
3357
|
_b.sent();
|
|
3347
|
-
return [2 /*return*/, {
|
|
3358
|
+
return [2 /*return*/, { tasksPrepared: tasksPrepared }];
|
|
3348
3359
|
}
|
|
3349
3360
|
});
|
|
3350
3361
|
});
|
|
3351
3362
|
}
|
|
3352
3363
|
/**
|
|
3353
|
-
* TODO: [🧠] Add context to each
|
|
3354
|
-
* TODO: [🧠] What is better name `
|
|
3355
|
-
* TODO: [♨][main] !!! Prepare index the examples and maybe
|
|
3364
|
+
* TODO: [🧠] Add context to each task (if missing)
|
|
3365
|
+
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
3366
|
+
* TODO: [♨][main] !!! Prepare index the examples and maybe tasks
|
|
3356
3367
|
* TODO: Write tests for `preparePipeline`
|
|
3357
3368
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3358
3369
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3369,12 +3380,12 @@
|
|
|
3369
3380
|
*/
|
|
3370
3381
|
function preparePipeline(pipeline, tools, options) {
|
|
3371
3382
|
return __awaiter(this, void 0, void 0, function () {
|
|
3372
|
-
var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters,
|
|
3383
|
+
var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters, tasks,
|
|
3373
3384
|
/*
|
|
3374
3385
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
3375
3386
|
knowledgeSources /*
|
|
3376
3387
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3377
|
-
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared,
|
|
3388
|
+
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3378
3389
|
var _this = this;
|
|
3379
3390
|
return __generator(this, function (_c) {
|
|
3380
3391
|
switch (_c.label) {
|
|
@@ -3383,7 +3394,7 @@
|
|
|
3383
3394
|
return [2 /*return*/, pipeline];
|
|
3384
3395
|
}
|
|
3385
3396
|
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;
|
|
3386
|
-
parameters = pipeline.parameters,
|
|
3397
|
+
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3387
3398
|
if (tools === undefined || tools.llm === undefined) {
|
|
3388
3399
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
3389
3400
|
}
|
|
@@ -3426,9 +3437,9 @@
|
|
|
3426
3437
|
case 2:
|
|
3427
3438
|
partialknowledgePiecesPrepared = _c.sent();
|
|
3428
3439
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3429
|
-
return [4 /*yield*/,
|
|
3440
|
+
return [4 /*yield*/, prepareTasks({
|
|
3430
3441
|
parameters: parameters,
|
|
3431
|
-
|
|
3442
|
+
tasks: tasks,
|
|
3432
3443
|
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
3433
3444
|
}, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
3434
3445
|
rootDirname: rootDirname,
|
|
@@ -3436,12 +3447,12 @@
|
|
|
3436
3447
|
isVerbose: isVerbose,
|
|
3437
3448
|
})];
|
|
3438
3449
|
case 3:
|
|
3439
|
-
|
|
3440
|
-
// ----- /
|
|
3450
|
+
tasksPrepared = (_c.sent()).tasksPrepared;
|
|
3451
|
+
// ----- /Tasks preparation -----
|
|
3441
3452
|
// Note: Count total usage
|
|
3442
3453
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
3443
|
-
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), {
|
|
3444
|
-
// <- TODO: [🪓] Here should be no need for spreading new array, just `
|
|
3454
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3455
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
3445
3456
|
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }))];
|
|
3446
3457
|
}
|
|
3447
3458
|
});
|
|
@@ -3506,16 +3517,16 @@
|
|
|
3506
3517
|
*/
|
|
3507
3518
|
|
|
3508
3519
|
/**
|
|
3509
|
-
* Parses the
|
|
3520
|
+
* Parses the task and returns the set of all used parameters
|
|
3510
3521
|
*
|
|
3511
|
-
* @param
|
|
3522
|
+
* @param task the task with used parameters
|
|
3512
3523
|
* @returns the set of parameter names
|
|
3513
3524
|
* @throws {ParseError} if the script is invalid
|
|
3514
3525
|
* @public exported from `@promptbook/utils`
|
|
3515
3526
|
*/
|
|
3516
|
-
function
|
|
3527
|
+
function extractParameterNamesFromTask(task) {
|
|
3517
3528
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
3518
|
-
var title =
|
|
3529
|
+
var title = task.title, description = task.description, taskType = task.taskType, content = task.content, preparedContent = task.preparedContent, jokerParameterNames = task.jokerParameterNames, foreach = task.foreach;
|
|
3519
3530
|
var parameterNames = new Set();
|
|
3520
3531
|
try {
|
|
3521
3532
|
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()) {
|
|
@@ -3530,7 +3541,7 @@
|
|
|
3530
3541
|
}
|
|
3531
3542
|
finally { if (e_1) throw e_1.error; }
|
|
3532
3543
|
}
|
|
3533
|
-
if (
|
|
3544
|
+
if (taskType === 'SCRIPT_TASK') {
|
|
3534
3545
|
try {
|
|
3535
3546
|
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
3536
3547
|
var parameterName = _h.value;
|
|
@@ -3961,6 +3972,9 @@
|
|
|
3961
3972
|
TextFormatDefinition,
|
|
3962
3973
|
CsvFormatDefinition,
|
|
3963
3974
|
];
|
|
3975
|
+
/**
|
|
3976
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3977
|
+
*/
|
|
3964
3978
|
|
|
3965
3979
|
/**
|
|
3966
3980
|
* Maps available parameters to expected parameters
|
|
@@ -4177,7 +4191,7 @@
|
|
|
4177
4191
|
}
|
|
4178
4192
|
finally { if (e_1) throw e_1.error; }
|
|
4179
4193
|
}
|
|
4180
|
-
var
|
|
4194
|
+
var replacedTemplates = template;
|
|
4181
4195
|
var match;
|
|
4182
4196
|
var loopLimit = LOOP_LIMIT;
|
|
4183
4197
|
var _loop_1 = function () {
|
|
@@ -4206,24 +4220,24 @@
|
|
|
4206
4220
|
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
4207
4221
|
.join('\n');
|
|
4208
4222
|
}
|
|
4209
|
-
|
|
4210
|
-
|
|
4223
|
+
replacedTemplates =
|
|
4224
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
4211
4225
|
parameterValue +
|
|
4212
|
-
|
|
4226
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
4213
4227
|
};
|
|
4214
4228
|
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
4215
|
-
.exec(
|
|
4229
|
+
.exec(replacedTemplates))) {
|
|
4216
4230
|
_loop_1();
|
|
4217
4231
|
}
|
|
4218
4232
|
// [💫] Check if there are parameters that are not closed properly
|
|
4219
|
-
if (/{\w+$/.test(
|
|
4233
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
4220
4234
|
throw new PipelineExecutionError('Parameter is not closed');
|
|
4221
4235
|
}
|
|
4222
4236
|
// [💫] Check if there are parameters that are not opened properly
|
|
4223
|
-
if (/^\w+}/.test(
|
|
4237
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
4224
4238
|
throw new PipelineExecutionError('Parameter is not opened');
|
|
4225
4239
|
}
|
|
4226
|
-
return
|
|
4240
|
+
return replacedTemplates;
|
|
4227
4241
|
}
|
|
4228
4242
|
|
|
4229
4243
|
/**
|
|
@@ -4255,6 +4269,7 @@
|
|
|
4255
4269
|
var LINES_PER_STANDARD_PAGE = 44;
|
|
4256
4270
|
/**
|
|
4257
4271
|
* TODO: [🧠] Should be this `constants.ts` or `config.ts`?
|
|
4272
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4258
4273
|
*/
|
|
4259
4274
|
|
|
4260
4275
|
/**
|
|
@@ -4334,6 +4349,7 @@
|
|
|
4334
4349
|
};
|
|
4335
4350
|
/**
|
|
4336
4351
|
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
4352
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4337
4353
|
*/
|
|
4338
4354
|
|
|
4339
4355
|
/**
|
|
@@ -4382,12 +4398,12 @@
|
|
|
4382
4398
|
*/
|
|
4383
4399
|
function executeAttempts(options) {
|
|
4384
4400
|
return __awaiter(this, void 0, void 0, function () {
|
|
4385
|
-
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters,
|
|
4401
|
+
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTaskResult, _llms, llmTools, _loop_1, attempt, state_1;
|
|
4386
4402
|
return __generator(this, function (_a) {
|
|
4387
4403
|
switch (_a.label) {
|
|
4388
4404
|
case 0:
|
|
4389
|
-
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters,
|
|
4390
|
-
$
|
|
4405
|
+
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;
|
|
4406
|
+
$ongoingTaskResult = {
|
|
4391
4407
|
$result: null,
|
|
4392
4408
|
$resultString: null,
|
|
4393
4409
|
$expectError: null,
|
|
@@ -4407,52 +4423,51 @@
|
|
|
4407
4423
|
if (isJokerAttempt && !jokerParameterName) {
|
|
4408
4424
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4409
4425
|
}
|
|
4410
|
-
$
|
|
4411
|
-
$
|
|
4412
|
-
$
|
|
4426
|
+
$ongoingTaskResult.$result = null;
|
|
4427
|
+
$ongoingTaskResult.$resultString = null;
|
|
4428
|
+
$ongoingTaskResult.$expectError = null;
|
|
4413
4429
|
if (isJokerAttempt) {
|
|
4414
4430
|
if (parameters[jokerParameterName] === undefined) {
|
|
4415
4431
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4416
4432
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
4417
4433
|
}
|
|
4418
4434
|
else {
|
|
4419
|
-
$
|
|
4435
|
+
$ongoingTaskResult.$resultString = parameters[jokerParameterName];
|
|
4420
4436
|
}
|
|
4421
4437
|
}
|
|
4422
4438
|
_t.label = 1;
|
|
4423
4439
|
case 1:
|
|
4424
4440
|
_t.trys.push([1, 43, 44, 45]);
|
|
4425
4441
|
if (!!isJokerAttempt) return [3 /*break*/, 25];
|
|
4426
|
-
_b =
|
|
4442
|
+
_b = task.taskType;
|
|
4427
4443
|
switch (_b) {
|
|
4428
|
-
case '
|
|
4429
|
-
case '
|
|
4430
|
-
case '
|
|
4431
|
-
case '
|
|
4444
|
+
case 'SIMPLE_TASK': return [3 /*break*/, 2];
|
|
4445
|
+
case 'PROMPT_TASK': return [3 /*break*/, 3];
|
|
4446
|
+
case 'SCRIPT_TASK': return [3 /*break*/, 11];
|
|
4447
|
+
case 'DIALOG_TASK': return [3 /*break*/, 22];
|
|
4432
4448
|
}
|
|
4433
4449
|
return [3 /*break*/, 24];
|
|
4434
4450
|
case 2:
|
|
4435
|
-
$
|
|
4451
|
+
$ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
4436
4452
|
return [3 /*break*/, 25];
|
|
4437
4453
|
case 3:
|
|
4438
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (
|
|
4439
|
-
$
|
|
4440
|
-
title:
|
|
4454
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
4455
|
+
$ongoingTaskResult.$prompt = {
|
|
4456
|
+
title: task.title,
|
|
4441
4457
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
4442
4458
|
? preparedPipeline.pipelineUrl
|
|
4443
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(
|
|
4444
|
-
// <- TODO: Here should be maybe also subformat index to distinguish between same
|
|
4459
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(task.name
|
|
4460
|
+
// <- TODO: Here should be maybe also subformat index to distinguish between same task with different subformat values
|
|
4445
4461
|
),
|
|
4446
4462
|
parameters: parameters,
|
|
4447
4463
|
content: preparedContent,
|
|
4448
4464
|
modelRequirements: modelRequirements,
|
|
4449
4465
|
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
4450
4466
|
var name = _a.name;
|
|
4451
|
-
return name ===
|
|
4452
|
-
}) ||
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
postprocessingFunctionNames: template.postprocessingFunctionNames,
|
|
4467
|
+
return name === task.personaName;
|
|
4468
|
+
}) || {})), task.expectations),
|
|
4469
|
+
format: task.format,
|
|
4470
|
+
postprocessingFunctionNames: task.postprocessingFunctionNames,
|
|
4456
4471
|
}; // <- TODO: Not very good type guard
|
|
4457
4472
|
_c = modelRequirements.modelVariant;
|
|
4458
4473
|
switch (_c) {
|
|
@@ -4462,36 +4477,35 @@
|
|
|
4462
4477
|
}
|
|
4463
4478
|
return [3 /*break*/, 9];
|
|
4464
4479
|
case 4:
|
|
4465
|
-
_d = $
|
|
4480
|
+
_d = $ongoingTaskResult;
|
|
4466
4481
|
return [4 /*yield*/, llmTools.callChatModel(
|
|
4467
4482
|
// <- TODO: [🧁] Check that `callChatModel` is defined
|
|
4468
|
-
$deepFreeze($
|
|
4483
|
+
$deepFreeze($ongoingTaskResult.$prompt))];
|
|
4469
4484
|
case 5:
|
|
4470
4485
|
_d.$chatResult = _t.sent();
|
|
4471
4486
|
// TODO: [🍬] Destroy chatThread
|
|
4472
|
-
$
|
|
4473
|
-
$
|
|
4487
|
+
$ongoingTaskResult.$result = $ongoingTaskResult.$chatResult;
|
|
4488
|
+
$ongoingTaskResult.$resultString = $ongoingTaskResult.$chatResult.content;
|
|
4474
4489
|
return [3 /*break*/, 10];
|
|
4475
4490
|
case 6:
|
|
4476
|
-
_e = $
|
|
4491
|
+
_e = $ongoingTaskResult;
|
|
4477
4492
|
return [4 /*yield*/, llmTools.callCompletionModel(
|
|
4478
4493
|
// <- TODO: [🧁] Check that `callCompletionModel` is defined
|
|
4479
|
-
$deepFreeze($
|
|
4494
|
+
$deepFreeze($ongoingTaskResult.$prompt))];
|
|
4480
4495
|
case 7:
|
|
4481
4496
|
_e.$completionResult = _t.sent();
|
|
4482
|
-
$
|
|
4483
|
-
$
|
|
4484
|
-
$ongoingTemplateResult.$completionResult.content;
|
|
4497
|
+
$ongoingTaskResult.$result = $ongoingTaskResult.$completionResult;
|
|
4498
|
+
$ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
|
|
4485
4499
|
return [3 /*break*/, 10];
|
|
4486
4500
|
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 "); }));
|
|
4487
|
-
case 9: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(
|
|
4501
|
+
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 "); }));
|
|
4488
4502
|
case 10: return [3 /*break*/, 25];
|
|
4489
4503
|
case 11:
|
|
4490
4504
|
if (arrayableToArray(tools.script).length === 0) {
|
|
4491
4505
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4492
4506
|
}
|
|
4493
|
-
if (!
|
|
4494
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT
|
|
4507
|
+
if (!task.contentLanguage) {
|
|
4508
|
+
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 "); }));
|
|
4495
4509
|
}
|
|
4496
4510
|
_t.label = 12;
|
|
4497
4511
|
case 12:
|
|
@@ -4504,9 +4518,9 @@
|
|
|
4504
4518
|
_t.label = 14;
|
|
4505
4519
|
case 14:
|
|
4506
4520
|
_t.trys.push([14, 16, , 17]);
|
|
4507
|
-
_h = $
|
|
4521
|
+
_h = $ongoingTaskResult;
|
|
4508
4522
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
4509
|
-
scriptLanguage:
|
|
4523
|
+
scriptLanguage: task.contentLanguage,
|
|
4510
4524
|
script: preparedContent,
|
|
4511
4525
|
parameters: parameters,
|
|
4512
4526
|
}))];
|
|
@@ -4521,7 +4535,7 @@
|
|
|
4521
4535
|
if (error_1 instanceof UnexpectedError) {
|
|
4522
4536
|
throw error_1;
|
|
4523
4537
|
}
|
|
4524
|
-
$
|
|
4538
|
+
$ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
4525
4539
|
return [3 /*break*/, 17];
|
|
4526
4540
|
case 17:
|
|
4527
4541
|
_g = _f.next();
|
|
@@ -4538,14 +4552,14 @@
|
|
|
4538
4552
|
finally { if (e_1) throw e_1.error; }
|
|
4539
4553
|
return [7 /*endfinally*/];
|
|
4540
4554
|
case 21:
|
|
4541
|
-
if ($
|
|
4555
|
+
if ($ongoingTaskResult.$resultString !== null) {
|
|
4542
4556
|
return [3 /*break*/, 25];
|
|
4543
4557
|
}
|
|
4544
|
-
if ($
|
|
4545
|
-
throw $
|
|
4558
|
+
if ($ongoingTaskResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
4559
|
+
throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
|
|
4546
4560
|
}
|
|
4547
4561
|
else {
|
|
4548
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat($
|
|
4562
|
+
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
|
|
4549
4563
|
.map(function (error) { return '- ' + error.message; })
|
|
4550
4564
|
.join('\n\n')), "\n "); }));
|
|
4551
4565
|
}
|
|
@@ -4553,27 +4567,27 @@
|
|
|
4553
4567
|
if (tools.userInterface === undefined) {
|
|
4554
4568
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4555
4569
|
}
|
|
4556
|
-
// TODO: [🌹] When making next attempt for `DIALOG
|
|
4557
|
-
_j = $
|
|
4570
|
+
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
4571
|
+
_j = $ongoingTaskResult;
|
|
4558
4572
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
4559
|
-
promptTitle:
|
|
4560
|
-
promptMessage: replaceParameters(
|
|
4573
|
+
promptTitle: task.title,
|
|
4574
|
+
promptMessage: replaceParameters(task.description || '', parameters),
|
|
4561
4575
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
4562
4576
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
4563
4577
|
placeholder: undefined,
|
|
4564
4578
|
priority: priority,
|
|
4565
4579
|
}))];
|
|
4566
4580
|
case 23:
|
|
4567
|
-
// TODO: [🌹] When making next attempt for `DIALOG
|
|
4581
|
+
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
4568
4582
|
_j.$resultString = _t.sent();
|
|
4569
4583
|
return [3 /*break*/, 25];
|
|
4570
|
-
case 24: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(
|
|
4584
|
+
case 24: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4571
4585
|
case 25:
|
|
4572
|
-
if (!(!isJokerAttempt &&
|
|
4586
|
+
if (!(!isJokerAttempt && task.postprocessingFunctionNames)) return [3 /*break*/, 42];
|
|
4573
4587
|
_t.label = 26;
|
|
4574
4588
|
case 26:
|
|
4575
4589
|
_t.trys.push([26, 40, 41, 42]);
|
|
4576
|
-
_k = (e_3 = void 0, __values(
|
|
4590
|
+
_k = (e_3 = void 0, __values(task.postprocessingFunctionNames)), _l = _k.next();
|
|
4577
4591
|
_t.label = 27;
|
|
4578
4592
|
case 27:
|
|
4579
4593
|
if (!!_l.done) return [3 /*break*/, 39];
|
|
@@ -4590,13 +4604,13 @@
|
|
|
4590
4604
|
_t.label = 30;
|
|
4591
4605
|
case 30:
|
|
4592
4606
|
_t.trys.push([30, 32, , 33]);
|
|
4593
|
-
_p = $
|
|
4607
|
+
_p = $ongoingTaskResult;
|
|
4594
4608
|
return [4 /*yield*/, scriptTools.execute({
|
|
4595
4609
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
4596
4610
|
script: "".concat(functionName, "(resultString)"),
|
|
4597
4611
|
parameters: {
|
|
4598
|
-
resultString: $
|
|
4599
|
-
// Note: No ...
|
|
4612
|
+
resultString: $ongoingTaskResult.$resultString || '',
|
|
4613
|
+
// Note: No ...parametersForTask, because working with result only
|
|
4600
4614
|
},
|
|
4601
4615
|
})];
|
|
4602
4616
|
case 31:
|
|
@@ -4612,7 +4626,7 @@
|
|
|
4612
4626
|
throw error_2;
|
|
4613
4627
|
}
|
|
4614
4628
|
postprocessingError = error_2;
|
|
4615
|
-
$
|
|
4629
|
+
$ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
4616
4630
|
return [3 /*break*/, 33];
|
|
4617
4631
|
case 33:
|
|
4618
4632
|
_o = _m.next();
|
|
@@ -4649,12 +4663,12 @@
|
|
|
4649
4663
|
return [7 /*endfinally*/];
|
|
4650
4664
|
case 42:
|
|
4651
4665
|
// TODO: [💝] Unite object for expecting amount and format
|
|
4652
|
-
if (
|
|
4653
|
-
if (
|
|
4654
|
-
if (!isValidJsonString($
|
|
4666
|
+
if (task.format) {
|
|
4667
|
+
if (task.format === 'JSON') {
|
|
4668
|
+
if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
|
|
4655
4669
|
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
4656
4670
|
try {
|
|
4657
|
-
$
|
|
4671
|
+
$ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
|
|
4658
4672
|
}
|
|
4659
4673
|
catch (error) {
|
|
4660
4674
|
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
@@ -4663,12 +4677,12 @@
|
|
|
4663
4677
|
}
|
|
4664
4678
|
}
|
|
4665
4679
|
else {
|
|
4666
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(
|
|
4680
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4667
4681
|
}
|
|
4668
4682
|
}
|
|
4669
4683
|
// TODO: [💝] Unite object for expecting amount and format
|
|
4670
|
-
if (
|
|
4671
|
-
checkExpectations(
|
|
4684
|
+
if (task.expectations) {
|
|
4685
|
+
checkExpectations(task.expectations, $ongoingTaskResult.$resultString || '');
|
|
4672
4686
|
}
|
|
4673
4687
|
return [2 /*return*/, "break-attempts"];
|
|
4674
4688
|
case 43:
|
|
@@ -4676,38 +4690,38 @@
|
|
|
4676
4690
|
if (!(error_3 instanceof ExpectError)) {
|
|
4677
4691
|
throw error_3;
|
|
4678
4692
|
}
|
|
4679
|
-
$
|
|
4693
|
+
$ongoingTaskResult.$expectError = error_3;
|
|
4680
4694
|
return [3 /*break*/, 45];
|
|
4681
4695
|
case 44:
|
|
4682
4696
|
if (!isJokerAttempt &&
|
|
4683
|
-
|
|
4684
|
-
$
|
|
4697
|
+
task.taskType === 'PROMPT_TASK' &&
|
|
4698
|
+
$ongoingTaskResult.$prompt
|
|
4685
4699
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
4686
4700
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
4687
4701
|
) {
|
|
4688
|
-
// TODO: [🧠] Maybe put other
|
|
4702
|
+
// TODO: [🧠] Maybe put other taskTypes into report
|
|
4689
4703
|
$executionReport.promptExecutions.push({
|
|
4690
|
-
prompt: __assign({}, $
|
|
4691
|
-
result: $
|
|
4692
|
-
error: $
|
|
4704
|
+
prompt: __assign({}, $ongoingTaskResult.$prompt),
|
|
4705
|
+
result: $ongoingTaskResult.$result || undefined,
|
|
4706
|
+
error: $ongoingTaskResult.$expectError === null
|
|
4693
4707
|
? undefined
|
|
4694
|
-
: serializeError($
|
|
4708
|
+
: serializeError($ongoingTaskResult.$expectError),
|
|
4695
4709
|
});
|
|
4696
4710
|
}
|
|
4697
4711
|
return [7 /*endfinally*/];
|
|
4698
4712
|
case 45:
|
|
4699
|
-
if ($
|
|
4713
|
+
if ($ongoingTaskResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
4700
4714
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
|
|
4701
4715
|
var _a, _b, _c;
|
|
4702
|
-
return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $
|
|
4716
|
+
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) || '')
|
|
4703
4717
|
.split('\n')
|
|
4704
4718
|
.map(function (line) { return "> ".concat(line); })
|
|
4705
|
-
.join('\n')), "\n\n Last error ").concat(((_b = $
|
|
4719
|
+
.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) || '')
|
|
4706
4720
|
.split('\n')
|
|
4707
4721
|
.map(function (line) { return "> ".concat(line); })
|
|
4708
|
-
.join('\n')), "\n\n Last result:\n ").concat(block($
|
|
4722
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingTaskResult.$resultString === null
|
|
4709
4723
|
? 'null'
|
|
4710
|
-
: $
|
|
4724
|
+
: $ongoingTaskResult.$resultString
|
|
4711
4725
|
.split('\n')
|
|
4712
4726
|
.map(function (line) { return "> ".concat(line); })
|
|
4713
4727
|
.join('\n')), "\n ---\n ");
|
|
@@ -4732,10 +4746,10 @@
|
|
|
4732
4746
|
attempt++;
|
|
4733
4747
|
return [3 /*break*/, 1];
|
|
4734
4748
|
case 4:
|
|
4735
|
-
if ($
|
|
4749
|
+
if ($ongoingTaskResult.$resultString === null) {
|
|
4736
4750
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4737
4751
|
}
|
|
4738
|
-
return [2 /*return*/, $
|
|
4752
|
+
return [2 /*return*/, $ongoingTaskResult.$resultString];
|
|
4739
4753
|
}
|
|
4740
4754
|
});
|
|
4741
4755
|
});
|
|
@@ -4751,36 +4765,36 @@
|
|
|
4751
4765
|
*/
|
|
4752
4766
|
function executeFormatSubvalues(options) {
|
|
4753
4767
|
return __awaiter(this, void 0, void 0, function () {
|
|
4754
|
-
var
|
|
4768
|
+
var task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
|
|
4755
4769
|
var _this = this;
|
|
4756
4770
|
return __generator(this, function (_a) {
|
|
4757
4771
|
switch (_a.label) {
|
|
4758
4772
|
case 0:
|
|
4759
|
-
|
|
4760
|
-
if (
|
|
4773
|
+
task = options.task, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, csvSettings = options.csvSettings, pipelineIdentification = options.pipelineIdentification;
|
|
4774
|
+
if (task.foreach === undefined) {
|
|
4761
4775
|
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
4762
4776
|
}
|
|
4763
4777
|
if (jokerParameterNames.length !== 0) {
|
|
4764
4778
|
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 "); }));
|
|
4765
4779
|
}
|
|
4766
|
-
parameterValue = parameters[
|
|
4780
|
+
parameterValue = parameters[task.foreach.parameterName] || '';
|
|
4767
4781
|
formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
|
|
4768
|
-
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(
|
|
4782
|
+
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(task.foreach.formatName);
|
|
4769
4783
|
});
|
|
4770
4784
|
if (formatDefinition === undefined) {
|
|
4771
4785
|
throw new UnexpectedError(
|
|
4772
4786
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
4773
|
-
spaceTrim__default["default"](function (block) { return "\n Unsupported format \"".concat(
|
|
4787
|
+
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; })
|
|
4774
4788
|
.map(function (formatName) { return "- ".concat(formatName); })
|
|
4775
4789
|
.join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4776
4790
|
}
|
|
4777
4791
|
subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
4778
|
-
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(
|
|
4792
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(task.foreach.subformatName);
|
|
4779
4793
|
});
|
|
4780
4794
|
if (subvalueDefinition === undefined) {
|
|
4781
4795
|
throw new UnexpectedError(
|
|
4782
4796
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
4783
|
-
spaceTrim__default["default"](function (block) { return "\n Unsupported subformat name \"".concat(
|
|
4797
|
+
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
|
|
4784
4798
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
4785
4799
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
4786
4800
|
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
@@ -4789,7 +4803,7 @@
|
|
|
4789
4803
|
formatSettings = csvSettings;
|
|
4790
4804
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
4791
4805
|
}
|
|
4792
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue,
|
|
4806
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4793
4807
|
var mappedParameters, allSubparameters, subresultString;
|
|
4794
4808
|
return __generator(this, function (_a) {
|
|
4795
4809
|
switch (_a.label) {
|
|
@@ -4798,7 +4812,7 @@
|
|
|
4798
4812
|
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
4799
4813
|
try {
|
|
4800
4814
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
4801
|
-
expectedParameters: Object.fromEntries(
|
|
4815
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
4802
4816
|
availableParameters: subparameters,
|
|
4803
4817
|
});
|
|
4804
4818
|
}
|
|
@@ -4831,7 +4845,7 @@
|
|
|
4831
4845
|
*
|
|
4832
4846
|
* @private internal utility of `createPipelineExecutor`
|
|
4833
4847
|
*/
|
|
4834
|
-
function
|
|
4848
|
+
function getContextForTask(task) {
|
|
4835
4849
|
return __awaiter(this, void 0, void 0, function () {
|
|
4836
4850
|
return __generator(this, function (_a) {
|
|
4837
4851
|
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
@@ -4844,15 +4858,10 @@
|
|
|
4844
4858
|
*
|
|
4845
4859
|
* @private internal utility of `createPipelineExecutor`
|
|
4846
4860
|
*/
|
|
4847
|
-
function
|
|
4861
|
+
function getExamplesForTask(task) {
|
|
4848
4862
|
return __awaiter(this, void 0, void 0, function () {
|
|
4849
|
-
var preparedPipeline;
|
|
4850
4863
|
return __generator(this, function (_a) {
|
|
4851
|
-
|
|
4852
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
4853
|
-
var content = _a.content;
|
|
4854
|
-
return "- ".concat(content);
|
|
4855
|
-
}).join('\n')];
|
|
4864
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
4856
4865
|
});
|
|
4857
4866
|
});
|
|
4858
4867
|
}
|
|
@@ -4862,10 +4871,15 @@
|
|
|
4862
4871
|
*
|
|
4863
4872
|
* @private internal utility of `createPipelineExecutor`
|
|
4864
4873
|
*/
|
|
4865
|
-
function
|
|
4874
|
+
function getKnowledgeForTask(options) {
|
|
4866
4875
|
return __awaiter(this, void 0, void 0, function () {
|
|
4876
|
+
var preparedPipeline;
|
|
4867
4877
|
return __generator(this, function (_a) {
|
|
4868
|
-
|
|
4878
|
+
preparedPipeline = options.preparedPipeline, options.task;
|
|
4879
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
4880
|
+
var content = _a.content;
|
|
4881
|
+
return "- ".concat(content);
|
|
4882
|
+
}).join('\n')];
|
|
4869
4883
|
});
|
|
4870
4884
|
});
|
|
4871
4885
|
}
|
|
@@ -4875,21 +4889,21 @@
|
|
|
4875
4889
|
*
|
|
4876
4890
|
* @private internal utility of `createPipelineExecutor`
|
|
4877
4891
|
*/
|
|
4878
|
-
function
|
|
4892
|
+
function getReservedParametersForTask(options) {
|
|
4879
4893
|
return __awaiter(this, void 0, void 0, function () {
|
|
4880
|
-
var preparedPipeline,
|
|
4894
|
+
var preparedPipeline, task, pipelineIdentification, context, knowledge, examples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
4881
4895
|
var e_1, _a;
|
|
4882
4896
|
return __generator(this, function (_b) {
|
|
4883
4897
|
switch (_b.label) {
|
|
4884
4898
|
case 0:
|
|
4885
|
-
preparedPipeline = options.preparedPipeline,
|
|
4886
|
-
return [4 /*yield*/,
|
|
4899
|
+
preparedPipeline = options.preparedPipeline, task = options.task, pipelineIdentification = options.pipelineIdentification;
|
|
4900
|
+
return [4 /*yield*/, getContextForTask()];
|
|
4887
4901
|
case 1:
|
|
4888
4902
|
context = _b.sent();
|
|
4889
|
-
return [4 /*yield*/,
|
|
4903
|
+
return [4 /*yield*/, getKnowledgeForTask({ preparedPipeline: preparedPipeline, task: task })];
|
|
4890
4904
|
case 2:
|
|
4891
4905
|
knowledge = _b.sent();
|
|
4892
|
-
return [4 /*yield*/,
|
|
4906
|
+
return [4 /*yield*/, getExamplesForTask()];
|
|
4893
4907
|
case 3:
|
|
4894
4908
|
examples = _b.sent();
|
|
4895
4909
|
currentDate = new Date().toISOString();
|
|
@@ -4932,31 +4946,31 @@
|
|
|
4932
4946
|
*
|
|
4933
4947
|
* @private internal utility of `createPipelineExecutor`
|
|
4934
4948
|
*/
|
|
4935
|
-
function
|
|
4949
|
+
function executeTask(options) {
|
|
4936
4950
|
return __awaiter(this, void 0, void 0, function () {
|
|
4937
|
-
var
|
|
4951
|
+
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;
|
|
4938
4952
|
var e_1, _g, _h;
|
|
4939
4953
|
return __generator(this, function (_j) {
|
|
4940
4954
|
switch (_j.label) {
|
|
4941
4955
|
case 0:
|
|
4942
|
-
|
|
4943
|
-
name = "pipeline-executor-frame-".concat(
|
|
4944
|
-
title =
|
|
4945
|
-
priority = preparedPipeline.
|
|
4956
|
+
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;
|
|
4957
|
+
name = "pipeline-executor-frame-".concat(currentTask.name);
|
|
4958
|
+
title = currentTask.title;
|
|
4959
|
+
priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
4946
4960
|
return [4 /*yield*/, onProgress({
|
|
4947
4961
|
name: name,
|
|
4948
4962
|
title: title,
|
|
4949
4963
|
isStarted: false,
|
|
4950
4964
|
isDone: false,
|
|
4951
|
-
|
|
4952
|
-
parameterName:
|
|
4965
|
+
taskType: currentTask.taskType,
|
|
4966
|
+
parameterName: currentTask.resultingParameterName,
|
|
4953
4967
|
parameterValue: null,
|
|
4954
4968
|
// <- [🍸]
|
|
4955
4969
|
})];
|
|
4956
4970
|
case 1:
|
|
4957
4971
|
_j.sent();
|
|
4958
|
-
usedParameterNames =
|
|
4959
|
-
dependentParameterNames = new Set(
|
|
4972
|
+
usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
4973
|
+
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
4960
4974
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
4961
4975
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
4962
4976
|
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)
|
|
@@ -4967,9 +4981,9 @@
|
|
|
4967
4981
|
}
|
|
4968
4982
|
_c = (_b = Object).freeze;
|
|
4969
4983
|
_d = [{}];
|
|
4970
|
-
return [4 /*yield*/,
|
|
4984
|
+
return [4 /*yield*/, getReservedParametersForTask({
|
|
4971
4985
|
preparedPipeline: preparedPipeline,
|
|
4972
|
-
|
|
4986
|
+
task: currentTask,
|
|
4973
4987
|
pipelineIdentification: pipelineIdentification,
|
|
4974
4988
|
})];
|
|
4975
4989
|
case 2:
|
|
@@ -4987,11 +5001,11 @@
|
|
|
4987
5001
|
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
4988
5002
|
// Houston, we have a problem
|
|
4989
5003
|
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
4990
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in
|
|
5004
|
+
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 "); }));
|
|
4991
5005
|
}
|
|
4992
5006
|
};
|
|
4993
5007
|
try {
|
|
4994
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this
|
|
5008
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this task
|
|
4995
5009
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
4996
5010
|
for (_e = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
4997
5011
|
parameterName = _f.value;
|
|
@@ -5007,18 +5021,16 @@
|
|
|
5007
5021
|
}
|
|
5008
5022
|
// 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
|
|
5009
5023
|
Object.freeze(parameters);
|
|
5010
|
-
maxAttempts =
|
|
5011
|
-
jokerParameterNames =
|
|
5012
|
-
preparedContent = (
|
|
5013
|
-
.split('{content}')
|
|
5014
|
-
.join(currentTemplate.content);
|
|
5024
|
+
maxAttempts = currentTask.taskType === 'DIALOG_TASK' ? Infinity : maxExecutionAttempts;
|
|
5025
|
+
jokerParameterNames = currentTask.jokerParameterNames || [];
|
|
5026
|
+
preparedContent = (currentTask.preparedContent || '{content}').split('{content}').join(currentTask.content);
|
|
5015
5027
|
return [4 /*yield*/, executeFormatSubvalues({
|
|
5016
5028
|
jokerParameterNames: jokerParameterNames,
|
|
5017
5029
|
priority: priority,
|
|
5018
5030
|
maxAttempts: maxAttempts,
|
|
5019
5031
|
preparedContent: preparedContent,
|
|
5020
5032
|
parameters: parameters,
|
|
5021
|
-
|
|
5033
|
+
task: currentTask,
|
|
5022
5034
|
preparedPipeline: preparedPipeline,
|
|
5023
5035
|
tools: tools,
|
|
5024
5036
|
$executionReport: $executionReport,
|
|
@@ -5031,15 +5043,15 @@
|
|
|
5031
5043
|
title: title,
|
|
5032
5044
|
isStarted: true,
|
|
5033
5045
|
isDone: true,
|
|
5034
|
-
|
|
5035
|
-
parameterName:
|
|
5046
|
+
taskType: currentTask.taskType,
|
|
5047
|
+
parameterName: currentTask.resultingParameterName,
|
|
5036
5048
|
parameterValue: resultString,
|
|
5037
5049
|
// <- [🍸]
|
|
5038
5050
|
})];
|
|
5039
5051
|
case 4:
|
|
5040
5052
|
_j.sent();
|
|
5041
5053
|
return [2 /*return*/, Object.freeze((_h = {},
|
|
5042
|
-
_h[
|
|
5054
|
+
_h[currentTask.resultingParameterName] =
|
|
5043
5055
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5044
5056
|
resultString,
|
|
5045
5057
|
_h))];
|
|
@@ -5101,7 +5113,7 @@
|
|
|
5101
5113
|
*/
|
|
5102
5114
|
function executePipeline(options) {
|
|
5103
5115
|
return __awaiter(this, void 0, void 0, function () {
|
|
5104
|
-
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,
|
|
5116
|
+
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;
|
|
5105
5117
|
var e_1, _f, e_2, _g;
|
|
5106
5118
|
return __generator(this, function (_h) {
|
|
5107
5119
|
switch (_h.label) {
|
|
@@ -5255,11 +5267,11 @@
|
|
|
5255
5267
|
var name = _a.name;
|
|
5256
5268
|
return name;
|
|
5257
5269
|
});
|
|
5258
|
-
|
|
5270
|
+
unresovedTasks_1 = __spreadArray([], __read(preparedPipeline.tasks), false);
|
|
5259
5271
|
resolving_1 = [];
|
|
5260
5272
|
loopLimit = LOOP_LIMIT;
|
|
5261
5273
|
_loop_2 = function () {
|
|
5262
|
-
var
|
|
5274
|
+
var currentTask, work_1;
|
|
5263
5275
|
return __generator(this, function (_k) {
|
|
5264
5276
|
switch (_k.label) {
|
|
5265
5277
|
case 0:
|
|
@@ -5267,15 +5279,15 @@
|
|
|
5267
5279
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
5268
5280
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
5269
5281
|
}
|
|
5270
|
-
|
|
5271
|
-
return
|
|
5282
|
+
currentTask = unresovedTasks_1.find(function (task) {
|
|
5283
|
+
return task.dependentParameterNames.every(function (name) {
|
|
5272
5284
|
return __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), __read(RESERVED_PARAMETER_NAMES), false).includes(name);
|
|
5273
5285
|
});
|
|
5274
5286
|
});
|
|
5275
|
-
if (!(!
|
|
5287
|
+
if (!(!currentTask && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
5276
5288
|
throw new UnexpectedError(
|
|
5277
5289
|
// TODO: [🐎] DRY
|
|
5278
|
-
spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(
|
|
5290
|
+
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
|
|
5279
5291
|
.map(function (_a) {
|
|
5280
5292
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
5281
5293
|
return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
|
|
@@ -5294,14 +5306,14 @@
|
|
|
5294
5306
|
.map(function (name) { return "- Parameter `{".concat(name, "}`"); })
|
|
5295
5307
|
.join('\n')), "\n\n *Note: This should be catched in `validatePipeline`*\n "); }));
|
|
5296
5308
|
case 1:
|
|
5297
|
-
if (!!
|
|
5309
|
+
if (!!currentTask) return [3 /*break*/, 3];
|
|
5298
5310
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
5299
5311
|
case 2:
|
|
5300
5312
|
/* [🤹♂️] */ _k.sent();
|
|
5301
5313
|
return [3 /*break*/, 4];
|
|
5302
5314
|
case 3:
|
|
5303
|
-
|
|
5304
|
-
work_1 =
|
|
5315
|
+
unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
|
|
5316
|
+
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
|
|
5305
5317
|
if (isReturned) {
|
|
5306
5318
|
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)
|
|
5307
5319
|
.split('\n')
|
|
@@ -5311,16 +5323,16 @@
|
|
|
5311
5323
|
if (onProgress) {
|
|
5312
5324
|
onProgress(progress);
|
|
5313
5325
|
}
|
|
5314
|
-
}, $executionReport: executionReport, pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n
|
|
5326
|
+
}, $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 "); }) }))
|
|
5315
5327
|
.then(function (newParametersToPass) {
|
|
5316
5328
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
5317
|
-
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [
|
|
5329
|
+
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTask.resultingParameterName], false);
|
|
5318
5330
|
})
|
|
5319
5331
|
.then(function () {
|
|
5320
5332
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
5321
5333
|
});
|
|
5322
5334
|
// <- Note: Errors are catched here [3]
|
|
5323
|
-
// TODO: BUT if in multiple
|
|
5335
|
+
// 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
|
|
5324
5336
|
resolving_1.push(work_1);
|
|
5325
5337
|
_k.label = 4;
|
|
5326
5338
|
case 4: return [2 /*return*/];
|
|
@@ -5329,7 +5341,7 @@
|
|
|
5329
5341
|
};
|
|
5330
5342
|
_h.label = 21;
|
|
5331
5343
|
case 21:
|
|
5332
|
-
if (!(
|
|
5344
|
+
if (!(unresovedTasks_1.length > 0)) return [3 /*break*/, 23];
|
|
5333
5345
|
return [5 /*yield**/, _loop_2()];
|
|
5334
5346
|
case 22:
|
|
5335
5347
|
_h.sent();
|
|
@@ -5487,6 +5499,9 @@
|
|
|
5487
5499
|
* @public exported from `@promptbook/cli`
|
|
5488
5500
|
*/
|
|
5489
5501
|
$scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
5502
|
+
/**
|
|
5503
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5504
|
+
*/
|
|
5490
5505
|
|
|
5491
5506
|
/**
|
|
5492
5507
|
* Scraper for markdown files
|
|
@@ -5681,6 +5696,9 @@
|
|
|
5681
5696
|
* @public exported from `@promptbook/cli`
|
|
5682
5697
|
*/
|
|
5683
5698
|
$scrapersMetadataRegister.register(pdfScraperMetadata);
|
|
5699
|
+
/**
|
|
5700
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5701
|
+
*/
|
|
5684
5702
|
|
|
5685
5703
|
/**
|
|
5686
5704
|
* Scraper for .pdf files
|
|
@@ -5764,6 +5782,7 @@
|
|
|
5764
5782
|
var _PdfScraperRegistration = $scrapersRegister.register(createPdfScraper);
|
|
5765
5783
|
/**
|
|
5766
5784
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
5785
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5767
5786
|
*/
|
|
5768
5787
|
|
|
5769
5788
|
exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
|