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