@promptbook/core 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 +1162 -997
- package/esm/index.es.js.map +1 -1
- package/esm/typings/{promptbook-collection → books}/index.d.ts +6 -6
- package/esm/typings/src/_packages/core.index.d.ts +28 -20
- package/esm/typings/src/_packages/types.index.d.ts +62 -52
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/cli/cli-commands/about.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/hello.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/run.d.ts +1 -0
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +1 -0
- package/esm/typings/src/cli/main.d.ts +1 -0
- package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/collectionToJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/ExpectCommand.d.ts +3 -3
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/SECTION/SectionCommand.d.ts +11 -0
- package/esm/typings/src/commands/{TEMPLATE/templateCommandParser.d.ts → SECTION/sectionCommandParser.d.ts} +6 -6
- package/esm/typings/src/commands/_common/types/Command.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +17 -19
- package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +1 -1
- package/esm/typings/src/commands/index.d.ts +4 -1
- package/esm/typings/src/config.d.ts +11 -3
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +3 -3
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +2 -2
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +3 -3
- package/esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts +1 -1
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +4 -4
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +15 -0
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +3 -2
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +1 -1
- package/esm/typings/src/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
- package/esm/typings/src/errors/index.d.ts +3 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptResultUsage.d.ts +1 -1
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/{$OngoingTemplateResult.d.ts → $OngoingTaskResult.d.ts} +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/{20-executeTemplate.d.ts → 20-executeTask.d.ts} +7 -7
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +5 -5
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/{getContextForTemplate.d.ts → getContextForTask.d.ts} +2 -2
- package/esm/typings/src/execution/createPipelineExecutor/{getExamplesForTemplate.d.ts → getExamplesForTask.d.ts} +2 -2
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +27 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +30 -0
- package/esm/typings/src/{types → execution}/execution-report/ExecutionPromptReportJson.d.ts +2 -2
- package/esm/typings/src/{types → execution}/execution-report/ExecutionReportJson.d.ts +4 -4
- package/esm/typings/src/{types → execution}/execution-report/ExecutionReportStringOptions.d.ts +1 -1
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/esm/typings/src/execution/utils/usage-constants.d.ts +3 -0
- package/esm/typings/src/formats/index.d.ts +3 -0
- package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +2 -2
- package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +7 -1
- package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +3 -0
- package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +45 -0
- package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +14 -0
- package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +3 -3
- package/esm/typings/src/formfactors/index.d.ts +85 -12
- package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +14 -0
- package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +13 -3
- package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +13 -3
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +3 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +3 -0
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +3 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +1 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +26 -0
- package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +14 -0
- package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/getPipelineInterface.d.ts +3 -1
- package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/isPipelineImplementingInterface.d.ts +5 -1
- package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/isPipelineInterfacesEqual.d.ts +2 -0
- package/esm/typings/src/{types/PipelineJson/TemplateJsonCommon.d.ts → pipeline/PipelineJson/CommonTaskJson.d.ts} +24 -24
- package/esm/typings/src/pipeline/PipelineJson/DialogTaskJson.d.ts +13 -0
- package/esm/typings/src/{types → pipeline}/PipelineJson/Expectations.d.ts +2 -2
- package/esm/typings/src/{types → pipeline}/PipelineJson/KnowledgePieceJson.d.ts +7 -6
- package/esm/typings/src/{types → pipeline}/PipelineJson/KnowledgeSourceJson.d.ts +3 -3
- package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +98 -0
- package/esm/typings/src/{types → pipeline}/PipelineJson/PersonaJson.d.ts +5 -5
- package/esm/typings/src/{types → pipeline}/PipelineJson/PipelineJson.d.ts +11 -11
- package/esm/typings/src/{types → pipeline}/PipelineJson/PreparationJson.d.ts +1 -1
- package/esm/typings/src/{types/PipelineJson/PromptTemplateJson.d.ts → pipeline/PipelineJson/PromptTaskJson.d.ts} +8 -8
- package/esm/typings/src/pipeline/PipelineJson/ScriptTaskJson.d.ts +20 -0
- package/esm/typings/src/pipeline/PipelineJson/SimpleTaskJson.d.ts +13 -0
- package/esm/typings/src/pipeline/PipelineJson/TaskJson.d.ts +11 -0
- package/esm/typings/src/{types → pipeline}/PipelineString.d.ts +1 -1
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +3 -3
- package/esm/typings/src/prepare/preparePipeline.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTasks.d.ts +32 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
- package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +3 -0
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +3 -0
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +3 -0
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +3 -0
- package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +3 -0
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +1 -0
- package/esm/typings/src/types/Prompt.d.ts +4 -4
- package/esm/typings/src/types/SectionType.d.ts +21 -0
- package/esm/typings/src/types/TaskProgress.d.ts +2 -2
- package/esm/typings/src/types/TaskType.d.ts +15 -0
- package/esm/typings/src/types/typeAliasEmoji.d.ts +3 -0
- package/esm/typings/src/types/typeAliases.d.ts +2 -1
- package/esm/typings/src/utils/emojis.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/constants.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/index.d.ts +3 -2
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -0
- package/esm/typings/src/utils/organization/TODO_remove_as.d.ts +6 -0
- package/esm/typings/src/utils/parameters/extractParameterNames.d.ts +2 -2
- package/esm/typings/src/utils/serialization/clonePipeline.d.ts +1 -1
- package/esm/typings/src/version.d.ts +2 -1
- package/package.json +4 -3
- package/umd/index.umd.js +1173 -1003
- 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
|
@@ -7,8 +7,8 @@ import { join, basename } from 'path';
|
|
|
7
7
|
import { SHA256 } from 'crypto-js';
|
|
8
8
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
9
9
|
import { lookup } from 'mime-types';
|
|
10
|
-
import sha256 from 'crypto-js/sha256';
|
|
11
10
|
import moment from 'moment';
|
|
11
|
+
import sha256 from 'crypto-js/sha256';
|
|
12
12
|
|
|
13
13
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
14
14
|
/**
|
|
@@ -22,9 +22,10 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
22
22
|
*
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.75.0-
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.75.0-3';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
28
29
|
*/
|
|
29
30
|
|
|
30
31
|
/*! *****************************************************************************
|
|
@@ -225,7 +226,7 @@ function capitalize(word) {
|
|
|
225
226
|
*/
|
|
226
227
|
function pipelineJsonToString(pipelineJson) {
|
|
227
228
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
228
|
-
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters,
|
|
229
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, tasks = pipelineJson.tasks;
|
|
229
230
|
var pipelineString = "# ".concat(title);
|
|
230
231
|
if (description) {
|
|
231
232
|
pipelineString += '\n\n';
|
|
@@ -246,7 +247,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
246
247
|
return isInput;
|
|
247
248
|
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
248
249
|
var parameter = _h.value;
|
|
249
|
-
commands.push("INPUT PARAMETER ".concat(
|
|
250
|
+
commands.push("INPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -262,7 +263,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
262
263
|
return isOutput;
|
|
263
264
|
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
264
265
|
var parameter = _k.value;
|
|
265
|
-
commands.push("OUTPUT PARAMETER ".concat(
|
|
266
|
+
commands.push("OUTPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
269
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -275,13 +276,13 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
275
276
|
pipelineString += '\n\n';
|
|
276
277
|
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
277
278
|
try {
|
|
278
|
-
for (var
|
|
279
|
-
var
|
|
279
|
+
for (var tasks_1 = __values(tasks), tasks_1_1 = tasks_1.next(); !tasks_1_1.done; tasks_1_1 = tasks_1.next()) {
|
|
280
|
+
var task = tasks_1_1.value;
|
|
280
281
|
var
|
|
281
282
|
/* Note: Not using:> name, */
|
|
282
|
-
title_1 =
|
|
283
|
+
title_1 = task.title, description_1 = task.description,
|
|
283
284
|
/* Note: dependentParameterNames, */
|
|
284
|
-
jokers =
|
|
285
|
+
jokers = task.jokerParameterNames, taskType = task.taskType, content = task.content, postprocessing = task.postprocessingFunctionNames, expectations = task.expectations, format = task.format, resultingParameterName = task.resultingParameterName;
|
|
285
286
|
pipelineString += '\n\n';
|
|
286
287
|
pipelineString += "## ".concat(title_1);
|
|
287
288
|
if (description_1) {
|
|
@@ -290,10 +291,11 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
290
291
|
}
|
|
291
292
|
var commands_1 = [];
|
|
292
293
|
var contentLanguage = 'text';
|
|
293
|
-
if (
|
|
294
|
-
var modelRequirements =
|
|
294
|
+
if (taskType === 'PROMPT_TASK') {
|
|
295
|
+
var modelRequirements = task.modelRequirements;
|
|
295
296
|
var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
|
|
296
|
-
|
|
297
|
+
// Note: Do nothing, it is default
|
|
298
|
+
// commands.push(`PROMPT`);
|
|
297
299
|
if (modelVariant) {
|
|
298
300
|
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
299
301
|
}
|
|
@@ -301,21 +303,21 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
301
303
|
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
302
304
|
}
|
|
303
305
|
}
|
|
304
|
-
else if (
|
|
306
|
+
else if (taskType === 'SIMPLE_TASK') {
|
|
305
307
|
commands_1.push("SIMPLE TEMPLATE");
|
|
306
308
|
// Note: Nothing special here
|
|
307
309
|
}
|
|
308
|
-
else if (
|
|
309
|
-
commands_1.push("SCRIPT
|
|
310
|
-
if (
|
|
311
|
-
contentLanguage =
|
|
310
|
+
else if (taskType === 'SCRIPT_TASK') {
|
|
311
|
+
commands_1.push("SCRIPT");
|
|
312
|
+
if (task.contentLanguage) {
|
|
313
|
+
contentLanguage = task.contentLanguage;
|
|
312
314
|
}
|
|
313
315
|
else {
|
|
314
316
|
contentLanguage = '';
|
|
315
317
|
}
|
|
316
318
|
}
|
|
317
|
-
else if (
|
|
318
|
-
commands_1.push("DIALOG
|
|
319
|
+
else if (taskType === 'DIALOG_TASK') {
|
|
320
|
+
commands_1.push("DIALOG");
|
|
319
321
|
// Note: Nothing special here
|
|
320
322
|
} // <- }else if([🅱]
|
|
321
323
|
if (jokers) {
|
|
@@ -390,13 +392,13 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
390
392
|
pipelineString += '\n';
|
|
391
393
|
pipelineString += '```';
|
|
392
394
|
pipelineString += '\n\n';
|
|
393
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use
|
|
395
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
|
|
394
396
|
}
|
|
395
397
|
}
|
|
396
398
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
397
399
|
finally {
|
|
398
400
|
try {
|
|
399
|
-
if (
|
|
401
|
+
if (tasks_1_1 && !tasks_1_1.done && (_c = tasks_1.return)) _c.call(tasks_1);
|
|
400
402
|
}
|
|
401
403
|
finally { if (e_3) throw e_3.error; }
|
|
402
404
|
}
|
|
@@ -405,8 +407,8 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
405
407
|
/**
|
|
406
408
|
* @private internal utility of `pipelineJsonToString`
|
|
407
409
|
*/
|
|
408
|
-
function
|
|
409
|
-
var name =
|
|
410
|
+
function taskParameterJsonToString(taskParameterJson) {
|
|
411
|
+
var name = taskParameterJson.name, description = taskParameterJson.description;
|
|
410
412
|
var parameterString = "{".concat(name, "}");
|
|
411
413
|
if (description) {
|
|
412
414
|
parameterString = "".concat(parameterString, " ").concat(description);
|
|
@@ -414,7 +416,7 @@ function templateParameterJsonToString(templateParameterJson) {
|
|
|
414
416
|
return parameterString;
|
|
415
417
|
}
|
|
416
418
|
/**
|
|
417
|
-
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `
|
|
419
|
+
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
418
420
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
419
421
|
* TODO: [🏛] Maybe make some markdown builder
|
|
420
422
|
* TODO: [🏛] Escape all
|
|
@@ -647,7 +649,7 @@ var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so t
|
|
|
647
649
|
*
|
|
648
650
|
* @public exported from `@promptbook/core`
|
|
649
651
|
*/
|
|
650
|
-
var CLAIM = "
|
|
652
|
+
var CLAIM = "It's time for a paradigm shift. The future of software in plain English, French or Latin";
|
|
651
653
|
// <- TODO: [🐊] Pick the best claim
|
|
652
654
|
/**
|
|
653
655
|
* When the title is not provided, the default title is used
|
|
@@ -707,6 +709,13 @@ var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH = 3;
|
|
|
707
709
|
* @public exported from `@promptbook/core`
|
|
708
710
|
*/
|
|
709
711
|
var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
|
|
712
|
+
/**
|
|
713
|
+
* Where to store your books
|
|
714
|
+
* This is kind of a "src" for your books
|
|
715
|
+
*
|
|
716
|
+
* @public exported from `@promptbook/core`
|
|
717
|
+
*/
|
|
718
|
+
var DEFAULT_BOOKS_DIRNAME = './books';
|
|
710
719
|
/**
|
|
711
720
|
* Where to store the cache of executions for promptbook CLI
|
|
712
721
|
*
|
|
@@ -714,7 +723,7 @@ var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
|
|
|
714
723
|
*
|
|
715
724
|
* @public exported from `@promptbook/core`
|
|
716
725
|
*/
|
|
717
|
-
var DEFAULT_EXECUTIONS_CACHE_DIRNAME = '
|
|
726
|
+
var DEFAULT_EXECUTIONS_CACHE_DIRNAME = './.promptbook/executions-cache';
|
|
718
727
|
/**
|
|
719
728
|
* Where to store the scrape cache
|
|
720
729
|
*
|
|
@@ -722,7 +731,7 @@ var DEFAULT_EXECUTIONS_CACHE_DIRNAME = '/.promptbook/executions-cache';
|
|
|
722
731
|
*
|
|
723
732
|
* @public exported from `@promptbook/core`
|
|
724
733
|
*/
|
|
725
|
-
var DEFAULT_SCRAPE_CACHE_DIRNAME = '
|
|
734
|
+
var DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
726
735
|
/**
|
|
727
736
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
728
737
|
*
|
|
@@ -819,6 +828,7 @@ var IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
819
828
|
true);
|
|
820
829
|
/**
|
|
821
830
|
* TODO: Extract `constants.ts` from `config.ts`
|
|
831
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
822
832
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
823
833
|
*/
|
|
824
834
|
|
|
@@ -1074,9 +1084,9 @@ function validatePipelineCore(pipeline) {
|
|
|
1074
1084
|
throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1075
1085
|
}
|
|
1076
1086
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1077
|
-
if (!Array.isArray(pipeline.
|
|
1087
|
+
if (!Array.isArray(pipeline.tasks)) {
|
|
1078
1088
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1079
|
-
throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.
|
|
1089
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.tasks` expected to be an array, but got ".concat(typeof pipeline.tasks, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1080
1090
|
}
|
|
1081
1091
|
var _loop_1 = function (parameter) {
|
|
1082
1092
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -1085,13 +1095,12 @@ function validatePipelineCore(pipeline) {
|
|
|
1085
1095
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
1086
1096
|
if (!parameter.isInput &&
|
|
1087
1097
|
!parameter.isOutput &&
|
|
1088
|
-
!pipeline.
|
|
1098
|
+
!pipeline.tasks.some(function (task) { return task.dependentParameterNames.includes(parameter.name); })) {
|
|
1089
1099
|
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
1090
1100
|
}
|
|
1091
|
-
// Note: Testing that parameter is either input or result of some
|
|
1092
|
-
if (!parameter.isInput &&
|
|
1093
|
-
|
|
1094
|
-
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add template that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1101
|
+
// Note: Testing that parameter is either input or result of some task
|
|
1102
|
+
if (!parameter.isInput && !pipeline.tasks.some(function (task) { return task.resultingParameterName === parameter.name; })) {
|
|
1103
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add task that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1095
1104
|
}
|
|
1096
1105
|
};
|
|
1097
1106
|
try {
|
|
@@ -1108,7 +1117,7 @@ function validatePipelineCore(pipeline) {
|
|
|
1108
1117
|
}
|
|
1109
1118
|
finally { if (e_1) throw e_1.error; }
|
|
1110
1119
|
}
|
|
1111
|
-
// Note: All input parameters are defined - so that they can be used as result of some
|
|
1120
|
+
// Note: All input parameters are defined - so that they can be used as result of some task
|
|
1112
1121
|
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
1113
1122
|
var isInput = _a.isInput;
|
|
1114
1123
|
return isInput;
|
|
@@ -1116,27 +1125,27 @@ function validatePipelineCore(pipeline) {
|
|
|
1116
1125
|
var name = _a.name;
|
|
1117
1126
|
return name;
|
|
1118
1127
|
}));
|
|
1119
|
-
var _loop_2 = function (
|
|
1128
|
+
var _loop_2 = function (task) {
|
|
1120
1129
|
var e_4, _h, e_5, _j;
|
|
1121
|
-
if (definedParameters.has(
|
|
1122
|
-
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(
|
|
1130
|
+
if (definedParameters.has(task.resultingParameterName)) {
|
|
1131
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1123
1132
|
}
|
|
1124
|
-
if (RESERVED_PARAMETER_NAMES.includes(
|
|
1125
|
-
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(
|
|
1133
|
+
if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
|
|
1134
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(task.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1126
1135
|
}
|
|
1127
|
-
definedParameters.add(
|
|
1128
|
-
if (
|
|
1129
|
-
if (!
|
|
1130
|
-
!
|
|
1131
|
-
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(
|
|
1136
|
+
definedParameters.add(task.resultingParameterName);
|
|
1137
|
+
if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
|
|
1138
|
+
if (!task.format &&
|
|
1139
|
+
!task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
1140
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(task.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1132
1141
|
}
|
|
1133
1142
|
var _loop_4 = function (joker) {
|
|
1134
|
-
if (!
|
|
1135
|
-
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(
|
|
1143
|
+
if (!task.dependentParameterNames.includes(joker)) {
|
|
1144
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(task.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1136
1145
|
}
|
|
1137
1146
|
};
|
|
1138
1147
|
try {
|
|
1139
|
-
for (var _k = (e_4 = void 0, __values(
|
|
1148
|
+
for (var _k = (e_4 = void 0, __values(task.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
1140
1149
|
var joker = _l.value;
|
|
1141
1150
|
_loop_4(joker);
|
|
1142
1151
|
}
|
|
@@ -1149,7 +1158,7 @@ function validatePipelineCore(pipeline) {
|
|
|
1149
1158
|
finally { if (e_4) throw e_4.error; }
|
|
1150
1159
|
}
|
|
1151
1160
|
}
|
|
1152
|
-
if (
|
|
1161
|
+
if (task.expectations) {
|
|
1153
1162
|
var _loop_5 = function (unit, min, max) {
|
|
1154
1163
|
if (min !== undefined && max !== undefined && min > max) {
|
|
1155
1164
|
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
@@ -1162,7 +1171,7 @@ function validatePipelineCore(pipeline) {
|
|
|
1162
1171
|
}
|
|
1163
1172
|
};
|
|
1164
1173
|
try {
|
|
1165
|
-
for (var _m = (e_5 = void 0, __values(Object.entries(
|
|
1174
|
+
for (var _m = (e_5 = void 0, __values(Object.entries(task.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
1166
1175
|
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
1167
1176
|
_loop_5(unit, min, max);
|
|
1168
1177
|
}
|
|
@@ -1177,10 +1186,10 @@ function validatePipelineCore(pipeline) {
|
|
|
1177
1186
|
}
|
|
1178
1187
|
};
|
|
1179
1188
|
try {
|
|
1180
|
-
// Note: Checking each
|
|
1181
|
-
for (var _f = __values(pipeline.
|
|
1182
|
-
var
|
|
1183
|
-
_loop_2(
|
|
1189
|
+
// Note: Checking each task individually
|
|
1190
|
+
for (var _f = __values(pipeline.tasks), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1191
|
+
var task = _g.value;
|
|
1192
|
+
_loop_2(task);
|
|
1184
1193
|
}
|
|
1185
1194
|
}
|
|
1186
1195
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -1214,20 +1223,20 @@ function validatePipelineCore(pipeline) {
|
|
|
1214
1223
|
}
|
|
1215
1224
|
finally { if (e_3) throw e_3.error; }
|
|
1216
1225
|
}
|
|
1217
|
-
var
|
|
1226
|
+
var unresovedTasks = __spreadArray([], __read(pipeline.tasks), false);
|
|
1218
1227
|
var loopLimit = LOOP_LIMIT;
|
|
1219
1228
|
var _loop_3 = function () {
|
|
1220
1229
|
if (loopLimit-- < 0) {
|
|
1221
1230
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
1222
1231
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
1223
1232
|
}
|
|
1224
|
-
var
|
|
1225
|
-
return
|
|
1233
|
+
var currentlyResovedTasks = unresovedTasks.filter(function (task) {
|
|
1234
|
+
return task.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
1226
1235
|
});
|
|
1227
|
-
if (
|
|
1236
|
+
if (currentlyResovedTasks.length === 0) {
|
|
1228
1237
|
throw new PipelineLogicError(
|
|
1229
1238
|
// TODO: [🐎] DRY
|
|
1230
|
-
spaceTrim$1(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(
|
|
1239
|
+
spaceTrim$1(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
|
|
1231
1240
|
.map(function (_a) {
|
|
1232
1241
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1233
1242
|
return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
|
|
@@ -1246,13 +1255,13 @@ function validatePipelineCore(pipeline) {
|
|
|
1246
1255
|
.map(function (name) { return "- Parameter `{".concat(name, "}`"); })
|
|
1247
1256
|
.join('\n')), "\n\n\n "); }));
|
|
1248
1257
|
}
|
|
1249
|
-
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(
|
|
1258
|
+
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTasks.map(function (_a) {
|
|
1250
1259
|
var resultingParameterName = _a.resultingParameterName;
|
|
1251
1260
|
return resultingParameterName;
|
|
1252
1261
|
})), false);
|
|
1253
|
-
|
|
1262
|
+
unresovedTasks = unresovedTasks.filter(function (task) { return !currentlyResovedTasks.includes(task); });
|
|
1254
1263
|
};
|
|
1255
|
-
while (
|
|
1264
|
+
while (unresovedTasks.length > 0) {
|
|
1256
1265
|
_loop_3();
|
|
1257
1266
|
}
|
|
1258
1267
|
// TODO: !!!!!! Test that pipeline interface implements declared formfactor interface
|
|
@@ -1312,9 +1321,9 @@ var PipelineUrlError = /** @class */ (function (_super) {
|
|
|
1312
1321
|
}(Error));
|
|
1313
1322
|
|
|
1314
1323
|
/**
|
|
1315
|
-
* Parses the
|
|
1324
|
+
* Parses the task and returns the list of all parameter names
|
|
1316
1325
|
*
|
|
1317
|
-
* @param template the template with parameters in {curly} braces
|
|
1326
|
+
* @param template the string template with parameters in {curly} braces
|
|
1318
1327
|
* @returns the list of parameter names
|
|
1319
1328
|
* @public exported from `@promptbook/utils`
|
|
1320
1329
|
*/
|
|
@@ -1345,18 +1354,18 @@ function extractParameterNames(template) {
|
|
|
1345
1354
|
* @public exported from `@promptbook/core`
|
|
1346
1355
|
*/
|
|
1347
1356
|
function unpreparePipeline(pipeline) {
|
|
1348
|
-
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources,
|
|
1357
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, tasks = pipeline.tasks;
|
|
1349
1358
|
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
1350
1359
|
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
1351
|
-
|
|
1352
|
-
var dependentParameterNames =
|
|
1353
|
-
var parameterNames = extractParameterNames(
|
|
1360
|
+
tasks = tasks.map(function (task) {
|
|
1361
|
+
var dependentParameterNames = task.dependentParameterNames;
|
|
1362
|
+
var parameterNames = extractParameterNames(task.preparedContent || '');
|
|
1354
1363
|
dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
|
|
1355
|
-
var
|
|
1356
|
-
delete
|
|
1357
|
-
return
|
|
1364
|
+
var taskUnprepared = __assign(__assign({}, task), { dependentParameterNames: dependentParameterNames });
|
|
1365
|
+
delete taskUnprepared.preparedContent;
|
|
1366
|
+
return taskUnprepared;
|
|
1358
1367
|
});
|
|
1359
|
-
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), {
|
|
1368
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1360
1369
|
}
|
|
1361
1370
|
/**
|
|
1362
1371
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1671,24 +1680,6 @@ function createSubcollection(collection, predicate) {
|
|
|
1671
1680
|
};
|
|
1672
1681
|
}
|
|
1673
1682
|
|
|
1674
|
-
/**
|
|
1675
|
-
* Template type describes the way how the template is templated
|
|
1676
|
-
*
|
|
1677
|
-
* @see https://github.com/webgptorg/promptbook#template-type
|
|
1678
|
-
* @public exported from `@promptbook/core`
|
|
1679
|
-
*/
|
|
1680
|
-
var TemplateTypes = [
|
|
1681
|
-
'PROMPT_TEMPLATE',
|
|
1682
|
-
'SIMPLE_TEMPLATE',
|
|
1683
|
-
'SCRIPT_TEMPLATE',
|
|
1684
|
-
'DIALOG_TEMPLATE',
|
|
1685
|
-
'EXAMPLE',
|
|
1686
|
-
'KNOWLEDGE',
|
|
1687
|
-
'INSTRUMENT',
|
|
1688
|
-
'ACTION',
|
|
1689
|
-
// <- [🅱]
|
|
1690
|
-
];
|
|
1691
|
-
|
|
1692
1683
|
/**
|
|
1693
1684
|
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
1694
1685
|
*
|
|
@@ -1833,6 +1824,9 @@ var UNCERTAIN_USAGE = $deepFreeze({
|
|
|
1833
1824
|
pagesCount: { value: 0, isUncertain: true },
|
|
1834
1825
|
},
|
|
1835
1826
|
});
|
|
1827
|
+
/**
|
|
1828
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1829
|
+
*/
|
|
1836
1830
|
|
|
1837
1831
|
/**
|
|
1838
1832
|
* @@@
|
|
@@ -2324,7 +2318,7 @@ function joinLlmExecutionTools() {
|
|
|
2324
2318
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2325
2319
|
*/
|
|
2326
2320
|
|
|
2327
|
-
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}],
|
|
2321
|
+
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"}];
|
|
2328
2322
|
|
|
2329
2323
|
/**
|
|
2330
2324
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
@@ -2428,6 +2422,9 @@ var ERRORS = {
|
|
|
2428
2422
|
UnexpectedError: UnexpectedError,
|
|
2429
2423
|
// TODO: [🪑]> VersionMismatchError,
|
|
2430
2424
|
};
|
|
2425
|
+
/**
|
|
2426
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2427
|
+
*/
|
|
2431
2428
|
|
|
2432
2429
|
/**
|
|
2433
2430
|
* Deserializes the error object
|
|
@@ -2489,8 +2486,8 @@ function isPipelinePrepared(pipeline) {
|
|
|
2489
2486
|
return false;
|
|
2490
2487
|
}
|
|
2491
2488
|
/*
|
|
2492
|
-
TODO: [🧠][🍫] `
|
|
2493
|
-
> if (!pipeline.
|
|
2489
|
+
TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2490
|
+
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2494
2491
|
> return false;
|
|
2495
2492
|
> }
|
|
2496
2493
|
*/
|
|
@@ -2501,9 +2498,9 @@ function isPipelinePrepared(pipeline) {
|
|
|
2501
2498
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2502
2499
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2503
2500
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2504
|
-
* - [🏍] ? Is context in each
|
|
2501
|
+
* - [🏍] ? Is context in each task
|
|
2505
2502
|
* - [♨] Are examples prepared
|
|
2506
|
-
* - [♨] Are
|
|
2503
|
+
* - [♨] Are tasks prepared
|
|
2507
2504
|
*/
|
|
2508
2505
|
|
|
2509
2506
|
/**
|
|
@@ -2573,16 +2570,16 @@ function extractVariables(script) {
|
|
|
2573
2570
|
*/
|
|
2574
2571
|
|
|
2575
2572
|
/**
|
|
2576
|
-
* Parses the
|
|
2573
|
+
* Parses the task and returns the set of all used parameters
|
|
2577
2574
|
*
|
|
2578
|
-
* @param
|
|
2575
|
+
* @param task the task with used parameters
|
|
2579
2576
|
* @returns the set of parameter names
|
|
2580
2577
|
* @throws {ParseError} if the script is invalid
|
|
2581
2578
|
* @public exported from `@promptbook/utils`
|
|
2582
2579
|
*/
|
|
2583
|
-
function
|
|
2580
|
+
function extractParameterNamesFromTask(task) {
|
|
2584
2581
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
2585
|
-
var title =
|
|
2582
|
+
var title = task.title, description = task.description, taskType = task.taskType, content = task.content, preparedContent = task.preparedContent, jokerParameterNames = task.jokerParameterNames, foreach = task.foreach;
|
|
2586
2583
|
var parameterNames = new Set();
|
|
2587
2584
|
try {
|
|
2588
2585
|
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()) {
|
|
@@ -2597,7 +2594,7 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
2597
2594
|
}
|
|
2598
2595
|
finally { if (e_1) throw e_1.error; }
|
|
2599
2596
|
}
|
|
2600
|
-
if (
|
|
2597
|
+
if (taskType === 'SCRIPT_TASK') {
|
|
2601
2598
|
try {
|
|
2602
2599
|
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2603
2600
|
var parameterName = _h.value;
|
|
@@ -3028,6 +3025,9 @@ var FORMAT_DEFINITIONS = [
|
|
|
3028
3025
|
TextFormatDefinition,
|
|
3029
3026
|
CsvFormatDefinition,
|
|
3030
3027
|
];
|
|
3028
|
+
/**
|
|
3029
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3030
|
+
*/
|
|
3031
3031
|
|
|
3032
3032
|
/**
|
|
3033
3033
|
* Maps available parameters to expected parameters
|
|
@@ -3263,7 +3263,7 @@ function replaceParameters(template, parameters) {
|
|
|
3263
3263
|
}
|
|
3264
3264
|
finally { if (e_1) throw e_1.error; }
|
|
3265
3265
|
}
|
|
3266
|
-
var
|
|
3266
|
+
var replacedTemplates = template;
|
|
3267
3267
|
var match;
|
|
3268
3268
|
var loopLimit = LOOP_LIMIT;
|
|
3269
3269
|
var _loop_1 = function () {
|
|
@@ -3292,24 +3292,24 @@ function replaceParameters(template, parameters) {
|
|
|
3292
3292
|
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
3293
3293
|
.join('\n');
|
|
3294
3294
|
}
|
|
3295
|
-
|
|
3296
|
-
|
|
3295
|
+
replacedTemplates =
|
|
3296
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
3297
3297
|
parameterValue +
|
|
3298
|
-
|
|
3298
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
3299
3299
|
};
|
|
3300
3300
|
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
3301
|
-
.exec(
|
|
3301
|
+
.exec(replacedTemplates))) {
|
|
3302
3302
|
_loop_1();
|
|
3303
3303
|
}
|
|
3304
3304
|
// [💫] Check if there are parameters that are not closed properly
|
|
3305
|
-
if (/{\w+$/.test(
|
|
3305
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
3306
3306
|
throw new PipelineExecutionError('Parameter is not closed');
|
|
3307
3307
|
}
|
|
3308
3308
|
// [💫] Check if there are parameters that are not opened properly
|
|
3309
|
-
if (/^\w+}/.test(
|
|
3309
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
3310
3310
|
throw new PipelineExecutionError('Parameter is not opened');
|
|
3311
3311
|
}
|
|
3312
|
-
return
|
|
3312
|
+
return replacedTemplates;
|
|
3313
3313
|
}
|
|
3314
3314
|
|
|
3315
3315
|
/**
|
|
@@ -3341,6 +3341,7 @@ var CHARACTERS_PER_STANDARD_LINE = 63;
|
|
|
3341
3341
|
var LINES_PER_STANDARD_PAGE = 44;
|
|
3342
3342
|
/**
|
|
3343
3343
|
* TODO: [🧠] Should be this `constants.ts` or `config.ts`?
|
|
3344
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3344
3345
|
*/
|
|
3345
3346
|
|
|
3346
3347
|
/**
|
|
@@ -3681,6 +3682,7 @@ var CountUtils = {
|
|
|
3681
3682
|
};
|
|
3682
3683
|
/**
|
|
3683
3684
|
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
3685
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3684
3686
|
*/
|
|
3685
3687
|
|
|
3686
3688
|
/**
|
|
@@ -3751,12 +3753,12 @@ function isPassingExpectations(expectations, value) {
|
|
|
3751
3753
|
*/
|
|
3752
3754
|
function executeAttempts(options) {
|
|
3753
3755
|
return __awaiter(this, void 0, void 0, function () {
|
|
3754
|
-
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters,
|
|
3756
|
+
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTaskResult, _llms, llmTools, _loop_1, attempt, state_1;
|
|
3755
3757
|
return __generator(this, function (_a) {
|
|
3756
3758
|
switch (_a.label) {
|
|
3757
3759
|
case 0:
|
|
3758
|
-
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters,
|
|
3759
|
-
$
|
|
3760
|
+
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;
|
|
3761
|
+
$ongoingTaskResult = {
|
|
3760
3762
|
$result: null,
|
|
3761
3763
|
$resultString: null,
|
|
3762
3764
|
$expectError: null,
|
|
@@ -3776,52 +3778,51 @@ function executeAttempts(options) {
|
|
|
3776
3778
|
if (isJokerAttempt && !jokerParameterName) {
|
|
3777
3779
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3778
3780
|
}
|
|
3779
|
-
$
|
|
3780
|
-
$
|
|
3781
|
-
$
|
|
3781
|
+
$ongoingTaskResult.$result = null;
|
|
3782
|
+
$ongoingTaskResult.$resultString = null;
|
|
3783
|
+
$ongoingTaskResult.$expectError = null;
|
|
3782
3784
|
if (isJokerAttempt) {
|
|
3783
3785
|
if (parameters[jokerParameterName] === undefined) {
|
|
3784
3786
|
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3785
3787
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3786
3788
|
}
|
|
3787
3789
|
else {
|
|
3788
|
-
$
|
|
3790
|
+
$ongoingTaskResult.$resultString = parameters[jokerParameterName];
|
|
3789
3791
|
}
|
|
3790
3792
|
}
|
|
3791
3793
|
_t.label = 1;
|
|
3792
3794
|
case 1:
|
|
3793
3795
|
_t.trys.push([1, 43, 44, 45]);
|
|
3794
3796
|
if (!!isJokerAttempt) return [3 /*break*/, 25];
|
|
3795
|
-
_b =
|
|
3797
|
+
_b = task.taskType;
|
|
3796
3798
|
switch (_b) {
|
|
3797
|
-
case '
|
|
3798
|
-
case '
|
|
3799
|
-
case '
|
|
3800
|
-
case '
|
|
3799
|
+
case 'SIMPLE_TASK': return [3 /*break*/, 2];
|
|
3800
|
+
case 'PROMPT_TASK': return [3 /*break*/, 3];
|
|
3801
|
+
case 'SCRIPT_TASK': return [3 /*break*/, 11];
|
|
3802
|
+
case 'DIALOG_TASK': return [3 /*break*/, 22];
|
|
3801
3803
|
}
|
|
3802
3804
|
return [3 /*break*/, 24];
|
|
3803
3805
|
case 2:
|
|
3804
|
-
$
|
|
3806
|
+
$ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
3805
3807
|
return [3 /*break*/, 25];
|
|
3806
3808
|
case 3:
|
|
3807
|
-
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (
|
|
3808
|
-
$
|
|
3809
|
-
title:
|
|
3809
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
3810
|
+
$ongoingTaskResult.$prompt = {
|
|
3811
|
+
title: task.title,
|
|
3810
3812
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3811
3813
|
? preparedPipeline.pipelineUrl
|
|
3812
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(
|
|
3813
|
-
// <- TODO: Here should be maybe also subformat index to distinguish between same
|
|
3814
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(task.name
|
|
3815
|
+
// <- TODO: Here should be maybe also subformat index to distinguish between same task with different subformat values
|
|
3814
3816
|
),
|
|
3815
3817
|
parameters: parameters,
|
|
3816
3818
|
content: preparedContent,
|
|
3817
3819
|
modelRequirements: modelRequirements,
|
|
3818
3820
|
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3819
3821
|
var name = _a.name;
|
|
3820
|
-
return name ===
|
|
3821
|
-
}) ||
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
postprocessingFunctionNames: template.postprocessingFunctionNames,
|
|
3822
|
+
return name === task.personaName;
|
|
3823
|
+
}) || {})), task.expectations),
|
|
3824
|
+
format: task.format,
|
|
3825
|
+
postprocessingFunctionNames: task.postprocessingFunctionNames,
|
|
3825
3826
|
}; // <- TODO: Not very good type guard
|
|
3826
3827
|
_c = modelRequirements.modelVariant;
|
|
3827
3828
|
switch (_c) {
|
|
@@ -3831,36 +3832,35 @@ function executeAttempts(options) {
|
|
|
3831
3832
|
}
|
|
3832
3833
|
return [3 /*break*/, 9];
|
|
3833
3834
|
case 4:
|
|
3834
|
-
_d = $
|
|
3835
|
+
_d = $ongoingTaskResult;
|
|
3835
3836
|
return [4 /*yield*/, llmTools.callChatModel(
|
|
3836
3837
|
// <- TODO: [🧁] Check that `callChatModel` is defined
|
|
3837
|
-
$deepFreeze($
|
|
3838
|
+
$deepFreeze($ongoingTaskResult.$prompt))];
|
|
3838
3839
|
case 5:
|
|
3839
3840
|
_d.$chatResult = _t.sent();
|
|
3840
3841
|
// TODO: [🍬] Destroy chatThread
|
|
3841
|
-
$
|
|
3842
|
-
$
|
|
3842
|
+
$ongoingTaskResult.$result = $ongoingTaskResult.$chatResult;
|
|
3843
|
+
$ongoingTaskResult.$resultString = $ongoingTaskResult.$chatResult.content;
|
|
3843
3844
|
return [3 /*break*/, 10];
|
|
3844
3845
|
case 6:
|
|
3845
|
-
_e = $
|
|
3846
|
+
_e = $ongoingTaskResult;
|
|
3846
3847
|
return [4 /*yield*/, llmTools.callCompletionModel(
|
|
3847
3848
|
// <- TODO: [🧁] Check that `callCompletionModel` is defined
|
|
3848
|
-
$deepFreeze($
|
|
3849
|
+
$deepFreeze($ongoingTaskResult.$prompt))];
|
|
3849
3850
|
case 7:
|
|
3850
3851
|
_e.$completionResult = _t.sent();
|
|
3851
|
-
$
|
|
3852
|
-
$
|
|
3853
|
-
$ongoingTemplateResult.$completionResult.content;
|
|
3852
|
+
$ongoingTaskResult.$result = $ongoingTaskResult.$completionResult;
|
|
3853
|
+
$ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
|
|
3854
3854
|
return [3 /*break*/, 10];
|
|
3855
3855
|
case 8: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Embedding model can not be used in pipeline\n\n This should be catched during parsing\n\n ".concat(block(pipelineIdentification), "\n\n "); }));
|
|
3856
|
-
case 9: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(
|
|
3856
|
+
case 9: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(task.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3857
3857
|
case 10: return [3 /*break*/, 25];
|
|
3858
3858
|
case 11:
|
|
3859
3859
|
if (arrayableToArray(tools.script).length === 0) {
|
|
3860
3860
|
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3861
3861
|
}
|
|
3862
|
-
if (!
|
|
3863
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT
|
|
3862
|
+
if (!task.contentLanguage) {
|
|
3863
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT TASK \"".concat(task.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3864
3864
|
}
|
|
3865
3865
|
_t.label = 12;
|
|
3866
3866
|
case 12:
|
|
@@ -3873,9 +3873,9 @@ function executeAttempts(options) {
|
|
|
3873
3873
|
_t.label = 14;
|
|
3874
3874
|
case 14:
|
|
3875
3875
|
_t.trys.push([14, 16, , 17]);
|
|
3876
|
-
_h = $
|
|
3876
|
+
_h = $ongoingTaskResult;
|
|
3877
3877
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3878
|
-
scriptLanguage:
|
|
3878
|
+
scriptLanguage: task.contentLanguage,
|
|
3879
3879
|
script: preparedContent,
|
|
3880
3880
|
parameters: parameters,
|
|
3881
3881
|
}))];
|
|
@@ -3890,7 +3890,7 @@ function executeAttempts(options) {
|
|
|
3890
3890
|
if (error_1 instanceof UnexpectedError) {
|
|
3891
3891
|
throw error_1;
|
|
3892
3892
|
}
|
|
3893
|
-
$
|
|
3893
|
+
$ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
3894
3894
|
return [3 /*break*/, 17];
|
|
3895
3895
|
case 17:
|
|
3896
3896
|
_g = _f.next();
|
|
@@ -3907,14 +3907,14 @@ function executeAttempts(options) {
|
|
|
3907
3907
|
finally { if (e_1) throw e_1.error; }
|
|
3908
3908
|
return [7 /*endfinally*/];
|
|
3909
3909
|
case 21:
|
|
3910
|
-
if ($
|
|
3910
|
+
if ($ongoingTaskResult.$resultString !== null) {
|
|
3911
3911
|
return [3 /*break*/, 25];
|
|
3912
3912
|
}
|
|
3913
|
-
if ($
|
|
3914
|
-
throw $
|
|
3913
|
+
if ($ongoingTaskResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
3914
|
+
throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
|
|
3915
3915
|
}
|
|
3916
3916
|
else {
|
|
3917
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($
|
|
3917
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($ongoingTaskResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTaskResult.$scriptPipelineExecutionErrors
|
|
3918
3918
|
.map(function (error) { return '- ' + error.message; })
|
|
3919
3919
|
.join('\n\n')), "\n "); }));
|
|
3920
3920
|
}
|
|
@@ -3922,27 +3922,27 @@ function executeAttempts(options) {
|
|
|
3922
3922
|
if (tools.userInterface === undefined) {
|
|
3923
3923
|
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3924
3924
|
}
|
|
3925
|
-
// TODO: [🌹] When making next attempt for `DIALOG
|
|
3926
|
-
_j = $
|
|
3925
|
+
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
3926
|
+
_j = $ongoingTaskResult;
|
|
3927
3927
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3928
|
-
promptTitle:
|
|
3929
|
-
promptMessage: replaceParameters(
|
|
3928
|
+
promptTitle: task.title,
|
|
3929
|
+
promptMessage: replaceParameters(task.description || '', parameters),
|
|
3930
3930
|
defaultValue: replaceParameters(preparedContent, parameters),
|
|
3931
3931
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
3932
3932
|
placeholder: undefined,
|
|
3933
3933
|
priority: priority,
|
|
3934
3934
|
}))];
|
|
3935
3935
|
case 23:
|
|
3936
|
-
// TODO: [🌹] When making next attempt for `DIALOG
|
|
3936
|
+
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
3937
3937
|
_j.$resultString = _t.sent();
|
|
3938
3938
|
return [3 /*break*/, 25];
|
|
3939
|
-
case 24: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(
|
|
3939
|
+
case 24: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3940
3940
|
case 25:
|
|
3941
|
-
if (!(!isJokerAttempt &&
|
|
3941
|
+
if (!(!isJokerAttempt && task.postprocessingFunctionNames)) return [3 /*break*/, 42];
|
|
3942
3942
|
_t.label = 26;
|
|
3943
3943
|
case 26:
|
|
3944
3944
|
_t.trys.push([26, 40, 41, 42]);
|
|
3945
|
-
_k = (e_3 = void 0, __values(
|
|
3945
|
+
_k = (e_3 = void 0, __values(task.postprocessingFunctionNames)), _l = _k.next();
|
|
3946
3946
|
_t.label = 27;
|
|
3947
3947
|
case 27:
|
|
3948
3948
|
if (!!_l.done) return [3 /*break*/, 39];
|
|
@@ -3959,13 +3959,13 @@ function executeAttempts(options) {
|
|
|
3959
3959
|
_t.label = 30;
|
|
3960
3960
|
case 30:
|
|
3961
3961
|
_t.trys.push([30, 32, , 33]);
|
|
3962
|
-
_p = $
|
|
3962
|
+
_p = $ongoingTaskResult;
|
|
3963
3963
|
return [4 /*yield*/, scriptTools.execute({
|
|
3964
3964
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3965
3965
|
script: "".concat(functionName, "(resultString)"),
|
|
3966
3966
|
parameters: {
|
|
3967
|
-
resultString: $
|
|
3968
|
-
// Note: No ...
|
|
3967
|
+
resultString: $ongoingTaskResult.$resultString || '',
|
|
3968
|
+
// Note: No ...parametersForTask, because working with result only
|
|
3969
3969
|
},
|
|
3970
3970
|
})];
|
|
3971
3971
|
case 31:
|
|
@@ -3981,7 +3981,7 @@ function executeAttempts(options) {
|
|
|
3981
3981
|
throw error_2;
|
|
3982
3982
|
}
|
|
3983
3983
|
postprocessingError = error_2;
|
|
3984
|
-
$
|
|
3984
|
+
$ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
3985
3985
|
return [3 /*break*/, 33];
|
|
3986
3986
|
case 33:
|
|
3987
3987
|
_o = _m.next();
|
|
@@ -4018,12 +4018,12 @@ function executeAttempts(options) {
|
|
|
4018
4018
|
return [7 /*endfinally*/];
|
|
4019
4019
|
case 42:
|
|
4020
4020
|
// TODO: [💝] Unite object for expecting amount and format
|
|
4021
|
-
if (
|
|
4022
|
-
if (
|
|
4023
|
-
if (!isValidJsonString($
|
|
4021
|
+
if (task.format) {
|
|
4022
|
+
if (task.format === 'JSON') {
|
|
4023
|
+
if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
|
|
4024
4024
|
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
4025
4025
|
try {
|
|
4026
|
-
$
|
|
4026
|
+
$ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
|
|
4027
4027
|
}
|
|
4028
4028
|
catch (error) {
|
|
4029
4029
|
throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
@@ -4032,12 +4032,12 @@ function executeAttempts(options) {
|
|
|
4032
4032
|
}
|
|
4033
4033
|
}
|
|
4034
4034
|
else {
|
|
4035
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(
|
|
4035
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4036
4036
|
}
|
|
4037
4037
|
}
|
|
4038
4038
|
// TODO: [💝] Unite object for expecting amount and format
|
|
4039
|
-
if (
|
|
4040
|
-
checkExpectations(
|
|
4039
|
+
if (task.expectations) {
|
|
4040
|
+
checkExpectations(task.expectations, $ongoingTaskResult.$resultString || '');
|
|
4041
4041
|
}
|
|
4042
4042
|
return [2 /*return*/, "break-attempts"];
|
|
4043
4043
|
case 43:
|
|
@@ -4045,38 +4045,38 @@ function executeAttempts(options) {
|
|
|
4045
4045
|
if (!(error_3 instanceof ExpectError)) {
|
|
4046
4046
|
throw error_3;
|
|
4047
4047
|
}
|
|
4048
|
-
$
|
|
4048
|
+
$ongoingTaskResult.$expectError = error_3;
|
|
4049
4049
|
return [3 /*break*/, 45];
|
|
4050
4050
|
case 44:
|
|
4051
4051
|
if (!isJokerAttempt &&
|
|
4052
|
-
|
|
4053
|
-
$
|
|
4052
|
+
task.taskType === 'PROMPT_TASK' &&
|
|
4053
|
+
$ongoingTaskResult.$prompt
|
|
4054
4054
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
4055
4055
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
4056
4056
|
) {
|
|
4057
|
-
// TODO: [🧠] Maybe put other
|
|
4057
|
+
// TODO: [🧠] Maybe put other taskTypes into report
|
|
4058
4058
|
$executionReport.promptExecutions.push({
|
|
4059
|
-
prompt: __assign({}, $
|
|
4060
|
-
result: $
|
|
4061
|
-
error: $
|
|
4059
|
+
prompt: __assign({}, $ongoingTaskResult.$prompt),
|
|
4060
|
+
result: $ongoingTaskResult.$result || undefined,
|
|
4061
|
+
error: $ongoingTaskResult.$expectError === null
|
|
4062
4062
|
? undefined
|
|
4063
|
-
: serializeError($
|
|
4063
|
+
: serializeError($ongoingTaskResult.$expectError),
|
|
4064
4064
|
});
|
|
4065
4065
|
}
|
|
4066
4066
|
return [7 /*endfinally*/];
|
|
4067
4067
|
case 45:
|
|
4068
|
-
if ($
|
|
4068
|
+
if ($ongoingTaskResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
4069
4069
|
throw new PipelineExecutionError(spaceTrim$1(function (block) {
|
|
4070
4070
|
var _a, _b, _c;
|
|
4071
|
-
return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $
|
|
4071
|
+
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) || '')
|
|
4072
4072
|
.split('\n')
|
|
4073
4073
|
.map(function (line) { return "> ".concat(line); })
|
|
4074
|
-
.join('\n')), "\n\n Last error ").concat(((_b = $
|
|
4074
|
+
.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) || '')
|
|
4075
4075
|
.split('\n')
|
|
4076
4076
|
.map(function (line) { return "> ".concat(line); })
|
|
4077
|
-
.join('\n')), "\n\n Last result:\n ").concat(block($
|
|
4077
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingTaskResult.$resultString === null
|
|
4078
4078
|
? 'null'
|
|
4079
|
-
: $
|
|
4079
|
+
: $ongoingTaskResult.$resultString
|
|
4080
4080
|
.split('\n')
|
|
4081
4081
|
.map(function (line) { return "> ".concat(line); })
|
|
4082
4082
|
.join('\n')), "\n ---\n ");
|
|
@@ -4101,10 +4101,10 @@ function executeAttempts(options) {
|
|
|
4101
4101
|
attempt++;
|
|
4102
4102
|
return [3 /*break*/, 1];
|
|
4103
4103
|
case 4:
|
|
4104
|
-
if ($
|
|
4104
|
+
if ($ongoingTaskResult.$resultString === null) {
|
|
4105
4105
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4106
4106
|
}
|
|
4107
|
-
return [2 /*return*/, $
|
|
4107
|
+
return [2 /*return*/, $ongoingTaskResult.$resultString];
|
|
4108
4108
|
}
|
|
4109
4109
|
});
|
|
4110
4110
|
});
|
|
@@ -4120,36 +4120,36 @@ function executeAttempts(options) {
|
|
|
4120
4120
|
*/
|
|
4121
4121
|
function executeFormatSubvalues(options) {
|
|
4122
4122
|
return __awaiter(this, void 0, void 0, function () {
|
|
4123
|
-
var
|
|
4123
|
+
var task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
|
|
4124
4124
|
var _this = this;
|
|
4125
4125
|
return __generator(this, function (_a) {
|
|
4126
4126
|
switch (_a.label) {
|
|
4127
4127
|
case 0:
|
|
4128
|
-
|
|
4129
|
-
if (
|
|
4128
|
+
task = options.task, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, csvSettings = options.csvSettings, pipelineIdentification = options.pipelineIdentification;
|
|
4129
|
+
if (task.foreach === undefined) {
|
|
4130
4130
|
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
4131
4131
|
}
|
|
4132
4132
|
if (jokerParameterNames.length !== 0) {
|
|
4133
4133
|
throw new UnexpectedError(spaceTrim(function (block) { return "\n JOKER parameters are not supported together with FOREACH command\n\n [\uD83E\uDDDE\u200D\u2640\uFE0F] This should be prevented in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4134
4134
|
}
|
|
4135
|
-
parameterValue = parameters[
|
|
4135
|
+
parameterValue = parameters[task.foreach.parameterName] || '';
|
|
4136
4136
|
formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
|
|
4137
|
-
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(
|
|
4137
|
+
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(task.foreach.formatName);
|
|
4138
4138
|
});
|
|
4139
4139
|
if (formatDefinition === undefined) {
|
|
4140
4140
|
throw new UnexpectedError(
|
|
4141
4141
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
4142
|
-
spaceTrim(function (block) { return "\n Unsupported format \"".concat(
|
|
4142
|
+
spaceTrim(function (block) { return "\n Unsupported format \"".concat(task.foreach.formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
|
|
4143
4143
|
.map(function (formatName) { return "- ".concat(formatName); })
|
|
4144
4144
|
.join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4145
4145
|
}
|
|
4146
4146
|
subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
4147
|
-
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(
|
|
4147
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(task.foreach.subformatName);
|
|
4148
4148
|
});
|
|
4149
4149
|
if (subvalueDefinition === undefined) {
|
|
4150
4150
|
throw new UnexpectedError(
|
|
4151
4151
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
4152
|
-
spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(
|
|
4152
|
+
spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(task.foreach.subformatName, "\" for format \"").concat(task.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
|
|
4153
4153
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
4154
4154
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
4155
4155
|
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
@@ -4158,7 +4158,7 @@ function executeFormatSubvalues(options) {
|
|
|
4158
4158
|
formatSettings = csvSettings;
|
|
4159
4159
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
4160
4160
|
}
|
|
4161
|
-
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue,
|
|
4161
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4162
4162
|
var mappedParameters, allSubparameters, subresultString;
|
|
4163
4163
|
return __generator(this, function (_a) {
|
|
4164
4164
|
switch (_a.label) {
|
|
@@ -4167,7 +4167,7 @@ function executeFormatSubvalues(options) {
|
|
|
4167
4167
|
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
4168
4168
|
try {
|
|
4169
4169
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
4170
|
-
expectedParameters: Object.fromEntries(
|
|
4170
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
4171
4171
|
availableParameters: subparameters,
|
|
4172
4172
|
});
|
|
4173
4173
|
}
|
|
@@ -4200,7 +4200,7 @@ function executeFormatSubvalues(options) {
|
|
|
4200
4200
|
*
|
|
4201
4201
|
* @private internal utility of `createPipelineExecutor`
|
|
4202
4202
|
*/
|
|
4203
|
-
function
|
|
4203
|
+
function getContextForTask(task) {
|
|
4204
4204
|
return __awaiter(this, void 0, void 0, function () {
|
|
4205
4205
|
return __generator(this, function (_a) {
|
|
4206
4206
|
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
@@ -4213,15 +4213,10 @@ function getContextForTemplate(template) {
|
|
|
4213
4213
|
*
|
|
4214
4214
|
* @private internal utility of `createPipelineExecutor`
|
|
4215
4215
|
*/
|
|
4216
|
-
function
|
|
4216
|
+
function getExamplesForTask(task) {
|
|
4217
4217
|
return __awaiter(this, void 0, void 0, function () {
|
|
4218
|
-
var preparedPipeline;
|
|
4219
4218
|
return __generator(this, function (_a) {
|
|
4220
|
-
|
|
4221
|
-
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
4222
|
-
var content = _a.content;
|
|
4223
|
-
return "- ".concat(content);
|
|
4224
|
-
}).join('\n')];
|
|
4219
|
+
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
4225
4220
|
});
|
|
4226
4221
|
});
|
|
4227
4222
|
}
|
|
@@ -4231,10 +4226,15 @@ function getKnowledgeForTemplate(options) {
|
|
|
4231
4226
|
*
|
|
4232
4227
|
* @private internal utility of `createPipelineExecutor`
|
|
4233
4228
|
*/
|
|
4234
|
-
function
|
|
4229
|
+
function getKnowledgeForTask(options) {
|
|
4235
4230
|
return __awaiter(this, void 0, void 0, function () {
|
|
4231
|
+
var preparedPipeline;
|
|
4236
4232
|
return __generator(this, function (_a) {
|
|
4237
|
-
|
|
4233
|
+
preparedPipeline = options.preparedPipeline, options.task;
|
|
4234
|
+
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
4235
|
+
var content = _a.content;
|
|
4236
|
+
return "- ".concat(content);
|
|
4237
|
+
}).join('\n')];
|
|
4238
4238
|
});
|
|
4239
4239
|
});
|
|
4240
4240
|
}
|
|
@@ -4244,21 +4244,21 @@ function getExamplesForTemplate(template) {
|
|
|
4244
4244
|
*
|
|
4245
4245
|
* @private internal utility of `createPipelineExecutor`
|
|
4246
4246
|
*/
|
|
4247
|
-
function
|
|
4247
|
+
function getReservedParametersForTask(options) {
|
|
4248
4248
|
return __awaiter(this, void 0, void 0, function () {
|
|
4249
|
-
var preparedPipeline,
|
|
4249
|
+
var preparedPipeline, task, pipelineIdentification, context, knowledge, examples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
4250
4250
|
var e_1, _a;
|
|
4251
4251
|
return __generator(this, function (_b) {
|
|
4252
4252
|
switch (_b.label) {
|
|
4253
4253
|
case 0:
|
|
4254
|
-
preparedPipeline = options.preparedPipeline,
|
|
4255
|
-
return [4 /*yield*/,
|
|
4254
|
+
preparedPipeline = options.preparedPipeline, task = options.task, pipelineIdentification = options.pipelineIdentification;
|
|
4255
|
+
return [4 /*yield*/, getContextForTask()];
|
|
4256
4256
|
case 1:
|
|
4257
4257
|
context = _b.sent();
|
|
4258
|
-
return [4 /*yield*/,
|
|
4258
|
+
return [4 /*yield*/, getKnowledgeForTask({ preparedPipeline: preparedPipeline, task: task })];
|
|
4259
4259
|
case 2:
|
|
4260
4260
|
knowledge = _b.sent();
|
|
4261
|
-
return [4 /*yield*/,
|
|
4261
|
+
return [4 /*yield*/, getExamplesForTask()];
|
|
4262
4262
|
case 3:
|
|
4263
4263
|
examples = _b.sent();
|
|
4264
4264
|
currentDate = new Date().toISOString();
|
|
@@ -4301,31 +4301,31 @@ function getReservedParametersForTemplate(options) {
|
|
|
4301
4301
|
*
|
|
4302
4302
|
* @private internal utility of `createPipelineExecutor`
|
|
4303
4303
|
*/
|
|
4304
|
-
function
|
|
4304
|
+
function executeTask(options) {
|
|
4305
4305
|
return __awaiter(this, void 0, void 0, function () {
|
|
4306
|
-
var
|
|
4306
|
+
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;
|
|
4307
4307
|
var e_1, _g, _h;
|
|
4308
4308
|
return __generator(this, function (_j) {
|
|
4309
4309
|
switch (_j.label) {
|
|
4310
4310
|
case 0:
|
|
4311
|
-
|
|
4312
|
-
name = "pipeline-executor-frame-".concat(
|
|
4313
|
-
title =
|
|
4314
|
-
priority = preparedPipeline.
|
|
4311
|
+
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;
|
|
4312
|
+
name = "pipeline-executor-frame-".concat(currentTask.name);
|
|
4313
|
+
title = currentTask.title;
|
|
4314
|
+
priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
4315
4315
|
return [4 /*yield*/, onProgress({
|
|
4316
4316
|
name: name,
|
|
4317
4317
|
title: title,
|
|
4318
4318
|
isStarted: false,
|
|
4319
4319
|
isDone: false,
|
|
4320
|
-
|
|
4321
|
-
parameterName:
|
|
4320
|
+
taskType: currentTask.taskType,
|
|
4321
|
+
parameterName: currentTask.resultingParameterName,
|
|
4322
4322
|
parameterValue: null,
|
|
4323
4323
|
// <- [🍸]
|
|
4324
4324
|
})];
|
|
4325
4325
|
case 1:
|
|
4326
4326
|
_j.sent();
|
|
4327
|
-
usedParameterNames =
|
|
4328
|
-
dependentParameterNames = new Set(
|
|
4327
|
+
usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
4328
|
+
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
4329
4329
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
4330
4330
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
4331
4331
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames)
|
|
@@ -4336,9 +4336,9 @@ function executeTemplate(options) {
|
|
|
4336
4336
|
}
|
|
4337
4337
|
_c = (_b = Object).freeze;
|
|
4338
4338
|
_d = [{}];
|
|
4339
|
-
return [4 /*yield*/,
|
|
4339
|
+
return [4 /*yield*/, getReservedParametersForTask({
|
|
4340
4340
|
preparedPipeline: preparedPipeline,
|
|
4341
|
-
|
|
4341
|
+
task: currentTask,
|
|
4342
4342
|
pipelineIdentification: pipelineIdentification,
|
|
4343
4343
|
})];
|
|
4344
4344
|
case 2:
|
|
@@ -4356,11 +4356,11 @@ function executeTemplate(options) {
|
|
|
4356
4356
|
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
4357
4357
|
// Houston, we have a problem
|
|
4358
4358
|
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
4359
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in
|
|
4359
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in task \"").concat(currentTask.title || currentTask.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
4360
4360
|
}
|
|
4361
4361
|
};
|
|
4362
4362
|
try {
|
|
4363
|
-
// Note: [2] Check that all used parameters are defined and removing unused parameters for this
|
|
4363
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this task
|
|
4364
4364
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
4365
4365
|
for (_e = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
4366
4366
|
parameterName = _f.value;
|
|
@@ -4376,18 +4376,16 @@ function executeTemplate(options) {
|
|
|
4376
4376
|
}
|
|
4377
4377
|
// 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
|
|
4378
4378
|
Object.freeze(parameters);
|
|
4379
|
-
maxAttempts =
|
|
4380
|
-
jokerParameterNames =
|
|
4381
|
-
preparedContent = (
|
|
4382
|
-
.split('{content}')
|
|
4383
|
-
.join(currentTemplate.content);
|
|
4379
|
+
maxAttempts = currentTask.taskType === 'DIALOG_TASK' ? Infinity : maxExecutionAttempts;
|
|
4380
|
+
jokerParameterNames = currentTask.jokerParameterNames || [];
|
|
4381
|
+
preparedContent = (currentTask.preparedContent || '{content}').split('{content}').join(currentTask.content);
|
|
4384
4382
|
return [4 /*yield*/, executeFormatSubvalues({
|
|
4385
4383
|
jokerParameterNames: jokerParameterNames,
|
|
4386
4384
|
priority: priority,
|
|
4387
4385
|
maxAttempts: maxAttempts,
|
|
4388
4386
|
preparedContent: preparedContent,
|
|
4389
4387
|
parameters: parameters,
|
|
4390
|
-
|
|
4388
|
+
task: currentTask,
|
|
4391
4389
|
preparedPipeline: preparedPipeline,
|
|
4392
4390
|
tools: tools,
|
|
4393
4391
|
$executionReport: $executionReport,
|
|
@@ -4400,15 +4398,15 @@ function executeTemplate(options) {
|
|
|
4400
4398
|
title: title,
|
|
4401
4399
|
isStarted: true,
|
|
4402
4400
|
isDone: true,
|
|
4403
|
-
|
|
4404
|
-
parameterName:
|
|
4401
|
+
taskType: currentTask.taskType,
|
|
4402
|
+
parameterName: currentTask.resultingParameterName,
|
|
4405
4403
|
parameterValue: resultString,
|
|
4406
4404
|
// <- [🍸]
|
|
4407
4405
|
})];
|
|
4408
4406
|
case 4:
|
|
4409
4407
|
_j.sent();
|
|
4410
4408
|
return [2 /*return*/, Object.freeze((_h = {},
|
|
4411
|
-
_h[
|
|
4409
|
+
_h[currentTask.resultingParameterName] =
|
|
4412
4410
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
4413
4411
|
resultString,
|
|
4414
4412
|
_h))];
|
|
@@ -4470,7 +4468,7 @@ function filterJustOutputParameters(options) {
|
|
|
4470
4468
|
*/
|
|
4471
4469
|
function executePipeline(options) {
|
|
4472
4470
|
return __awaiter(this, void 0, void 0, function () {
|
|
4473
|
-
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,
|
|
4471
|
+
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;
|
|
4474
4472
|
var e_1, _f, e_2, _g;
|
|
4475
4473
|
return __generator(this, function (_h) {
|
|
4476
4474
|
switch (_h.label) {
|
|
@@ -4624,11 +4622,11 @@ function executePipeline(options) {
|
|
|
4624
4622
|
var name = _a.name;
|
|
4625
4623
|
return name;
|
|
4626
4624
|
});
|
|
4627
|
-
|
|
4625
|
+
unresovedTasks_1 = __spreadArray([], __read(preparedPipeline.tasks), false);
|
|
4628
4626
|
resolving_1 = [];
|
|
4629
4627
|
loopLimit = LOOP_LIMIT;
|
|
4630
4628
|
_loop_2 = function () {
|
|
4631
|
-
var
|
|
4629
|
+
var currentTask, work_1;
|
|
4632
4630
|
return __generator(this, function (_k) {
|
|
4633
4631
|
switch (_k.label) {
|
|
4634
4632
|
case 0:
|
|
@@ -4636,15 +4634,15 @@ function executePipeline(options) {
|
|
|
4636
4634
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
4637
4635
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4638
4636
|
}
|
|
4639
|
-
|
|
4640
|
-
return
|
|
4637
|
+
currentTask = unresovedTasks_1.find(function (task) {
|
|
4638
|
+
return task.dependentParameterNames.every(function (name) {
|
|
4641
4639
|
return __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), __read(RESERVED_PARAMETER_NAMES), false).includes(name);
|
|
4642
4640
|
});
|
|
4643
4641
|
});
|
|
4644
|
-
if (!(!
|
|
4642
|
+
if (!(!currentTask && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
4645
4643
|
throw new UnexpectedError(
|
|
4646
4644
|
// TODO: [🐎] DRY
|
|
4647
|
-
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(
|
|
4645
|
+
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks_1
|
|
4648
4646
|
.map(function (_a) {
|
|
4649
4647
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
4650
4648
|
return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
|
|
@@ -4663,14 +4661,14 @@ function executePipeline(options) {
|
|
|
4663
4661
|
.map(function (name) { return "- Parameter `{".concat(name, "}`"); })
|
|
4664
4662
|
.join('\n')), "\n\n *Note: This should be catched in `validatePipeline`*\n "); }));
|
|
4665
4663
|
case 1:
|
|
4666
|
-
if (!!
|
|
4664
|
+
if (!!currentTask) return [3 /*break*/, 3];
|
|
4667
4665
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
4668
4666
|
case 2:
|
|
4669
4667
|
/* [🤹♂️] */ _k.sent();
|
|
4670
4668
|
return [3 /*break*/, 4];
|
|
4671
4669
|
case 3:
|
|
4672
|
-
|
|
4673
|
-
work_1 =
|
|
4670
|
+
unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
|
|
4671
|
+
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
|
|
4674
4672
|
if (isReturned) {
|
|
4675
4673
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
|
|
4676
4674
|
.split('\n')
|
|
@@ -4680,16 +4678,16 @@ function executePipeline(options) {
|
|
|
4680
4678
|
if (onProgress) {
|
|
4681
4679
|
onProgress(progress);
|
|
4682
4680
|
}
|
|
4683
|
-
}, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n
|
|
4681
|
+
}, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
4684
4682
|
.then(function (newParametersToPass) {
|
|
4685
4683
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
4686
|
-
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [
|
|
4684
|
+
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTask.resultingParameterName], false);
|
|
4687
4685
|
})
|
|
4688
4686
|
.then(function () {
|
|
4689
4687
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
4690
4688
|
});
|
|
4691
4689
|
// <- Note: Errors are catched here [3]
|
|
4692
|
-
// TODO: BUT if in multiple
|
|
4690
|
+
// 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
|
|
4693
4691
|
resolving_1.push(work_1);
|
|
4694
4692
|
_k.label = 4;
|
|
4695
4693
|
case 4: return [2 /*return*/];
|
|
@@ -4698,7 +4696,7 @@ function executePipeline(options) {
|
|
|
4698
4696
|
};
|
|
4699
4697
|
_h.label = 21;
|
|
4700
4698
|
case 21:
|
|
4701
|
-
if (!(
|
|
4699
|
+
if (!(unresovedTasks_1.length > 0)) return [3 /*break*/, 23];
|
|
4702
4700
|
return [5 /*yield**/, _loop_2()];
|
|
4703
4701
|
case 22:
|
|
4704
4702
|
_h.sent();
|
|
@@ -5239,6 +5237,9 @@ function normalizeToKebabCase(text) {
|
|
|
5239
5237
|
normalizedName = normalizedName.replace(/-$/, '');
|
|
5240
5238
|
return normalizedName;
|
|
5241
5239
|
}
|
|
5240
|
+
/**
|
|
5241
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5242
|
+
*/
|
|
5242
5243
|
|
|
5243
5244
|
/**
|
|
5244
5245
|
* Creates unique name for the source
|
|
@@ -5610,7 +5611,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
5610
5611
|
*/
|
|
5611
5612
|
function clonePipeline(pipeline) {
|
|
5612
5613
|
// Note: Not using spread operator (...) because @@@
|
|
5613
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters,
|
|
5614
|
+
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;
|
|
5614
5615
|
return {
|
|
5615
5616
|
pipelineUrl: pipelineUrl,
|
|
5616
5617
|
sourceFile: sourceFile,
|
|
@@ -5619,7 +5620,7 @@ function clonePipeline(pipeline) {
|
|
|
5619
5620
|
description: description,
|
|
5620
5621
|
formfactorName: formfactorName,
|
|
5621
5622
|
parameters: parameters,
|
|
5622
|
-
|
|
5623
|
+
tasks: tasks,
|
|
5623
5624
|
knowledgeSources: knowledgeSources,
|
|
5624
5625
|
knowledgePieces: knowledgePieces,
|
|
5625
5626
|
personas: personas,
|
|
@@ -5635,20 +5636,20 @@ function clonePipeline(pipeline) {
|
|
|
5635
5636
|
*
|
|
5636
5637
|
* @public exported from `@promptbook/core`
|
|
5637
5638
|
*/
|
|
5638
|
-
function
|
|
5639
|
+
function prepareTasks(pipeline, tools, options) {
|
|
5639
5640
|
return __awaiter(this, void 0, void 0, function () {
|
|
5640
|
-
var _a, maxParallelCount,
|
|
5641
|
+
var _a, maxParallelCount, tasks, knowledgePiecesCount, tasksPrepared;
|
|
5641
5642
|
var _this = this;
|
|
5642
5643
|
return __generator(this, function (_b) {
|
|
5643
5644
|
switch (_b.label) {
|
|
5644
5645
|
case 0:
|
|
5645
5646
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
return [4 /*yield*/, forEachAsync(
|
|
5649
|
-
var dependentParameterNames, preparedContent,
|
|
5647
|
+
tasks = pipeline.tasks, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
5648
|
+
tasksPrepared = new Array(tasks.length);
|
|
5649
|
+
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 () {
|
|
5650
|
+
var dependentParameterNames, preparedContent, preparedTask;
|
|
5650
5651
|
return __generator(this, function (_a) {
|
|
5651
|
-
dependentParameterNames =
|
|
5652
|
+
dependentParameterNames = task.dependentParameterNames;
|
|
5652
5653
|
preparedContent = undefined;
|
|
5653
5654
|
if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
|
|
5654
5655
|
preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
@@ -5657,22 +5658,22 @@ function prepareTemplates(pipeline, tools, options) {
|
|
|
5657
5658
|
'knowledge',
|
|
5658
5659
|
], false);
|
|
5659
5660
|
}
|
|
5660
|
-
|
|
5661
|
-
|
|
5661
|
+
preparedTask = __assign(__assign({}, task), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
|
|
5662
|
+
tasksPrepared[index] = preparedTask;
|
|
5662
5663
|
return [2 /*return*/];
|
|
5663
5664
|
});
|
|
5664
5665
|
}); })];
|
|
5665
5666
|
case 1:
|
|
5666
5667
|
_b.sent();
|
|
5667
|
-
return [2 /*return*/, {
|
|
5668
|
+
return [2 /*return*/, { tasksPrepared: tasksPrepared }];
|
|
5668
5669
|
}
|
|
5669
5670
|
});
|
|
5670
5671
|
});
|
|
5671
5672
|
}
|
|
5672
5673
|
/**
|
|
5673
|
-
* TODO: [🧠] Add context to each
|
|
5674
|
-
* TODO: [🧠] What is better name `
|
|
5675
|
-
* TODO: [♨][main] !!! Prepare index the examples and maybe
|
|
5674
|
+
* TODO: [🧠] Add context to each task (if missing)
|
|
5675
|
+
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
5676
|
+
* TODO: [♨][main] !!! Prepare index the examples and maybe tasks
|
|
5676
5677
|
* TODO: Write tests for `preparePipeline`
|
|
5677
5678
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
5678
5679
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -5689,12 +5690,12 @@ function prepareTemplates(pipeline, tools, options) {
|
|
|
5689
5690
|
*/
|
|
5690
5691
|
function preparePipeline(pipeline, tools, options) {
|
|
5691
5692
|
return __awaiter(this, void 0, void 0, function () {
|
|
5692
|
-
var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters,
|
|
5693
|
+
var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters, tasks,
|
|
5693
5694
|
/*
|
|
5694
5695
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
5695
5696
|
knowledgeSources /*
|
|
5696
5697
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
5697
|
-
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared,
|
|
5698
|
+
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
5698
5699
|
var _this = this;
|
|
5699
5700
|
return __generator(this, function (_c) {
|
|
5700
5701
|
switch (_c.label) {
|
|
@@ -5703,7 +5704,7 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
5703
5704
|
return [2 /*return*/, pipeline];
|
|
5704
5705
|
}
|
|
5705
5706
|
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;
|
|
5706
|
-
parameters = pipeline.parameters,
|
|
5707
|
+
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
5707
5708
|
if (tools === undefined || tools.llm === undefined) {
|
|
5708
5709
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
5709
5710
|
}
|
|
@@ -5746,9 +5747,9 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
5746
5747
|
case 2:
|
|
5747
5748
|
partialknowledgePiecesPrepared = _c.sent();
|
|
5748
5749
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
5749
|
-
return [4 /*yield*/,
|
|
5750
|
+
return [4 /*yield*/, prepareTasks({
|
|
5750
5751
|
parameters: parameters,
|
|
5751
|
-
|
|
5752
|
+
tasks: tasks,
|
|
5752
5753
|
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
5753
5754
|
}, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
5754
5755
|
rootDirname: rootDirname,
|
|
@@ -5756,12 +5757,12 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
5756
5757
|
isVerbose: isVerbose,
|
|
5757
5758
|
})];
|
|
5758
5759
|
case 3:
|
|
5759
|
-
|
|
5760
|
-
// ----- /
|
|
5760
|
+
tasksPrepared = (_c.sent()).tasksPrepared;
|
|
5761
|
+
// ----- /Tasks preparation -----
|
|
5761
5762
|
// Note: Count total usage
|
|
5762
5763
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
5763
|
-
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), {
|
|
5764
|
-
// <- TODO: [🪓] Here should be no need for spreading new array, just `
|
|
5764
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
5765
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
5765
5766
|
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }))];
|
|
5766
5767
|
}
|
|
5767
5768
|
});
|
|
@@ -5776,6 +5777,40 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
5776
5777
|
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
5777
5778
|
*/
|
|
5778
5779
|
|
|
5780
|
+
/**
|
|
5781
|
+
* All available task types
|
|
5782
|
+
*
|
|
5783
|
+
* There is is distinction between task types and section types
|
|
5784
|
+
* - Every section in markdown has its SectionType
|
|
5785
|
+
* - Some sections are tasks but other can be non-task sections
|
|
5786
|
+
*
|
|
5787
|
+
* @public exported from `@promptbook/core`
|
|
5788
|
+
*/
|
|
5789
|
+
var TaskTypes = [
|
|
5790
|
+
'PROMPT',
|
|
5791
|
+
'SIMPLE',
|
|
5792
|
+
'SCRIPT',
|
|
5793
|
+
'DIALOG',
|
|
5794
|
+
// <- [🅱]
|
|
5795
|
+
];
|
|
5796
|
+
|
|
5797
|
+
/**
|
|
5798
|
+
* All available sections which are not tasks
|
|
5799
|
+
*
|
|
5800
|
+
* @public exported from `@promptbook/core`
|
|
5801
|
+
*/
|
|
5802
|
+
var NonTaskSectionTypes = ['EXAMPLE', 'KNOWLEDGE', 'INSTRUMENT', 'ACTION'];
|
|
5803
|
+
/**
|
|
5804
|
+
* All available section types
|
|
5805
|
+
*
|
|
5806
|
+
* There is is distinction between task types and section types
|
|
5807
|
+
* - Every section in markdown has its SectionType
|
|
5808
|
+
* - Some sections are tasks but other can be non-task sections
|
|
5809
|
+
*
|
|
5810
|
+
* @public exported from `@promptbook/core`
|
|
5811
|
+
*/
|
|
5812
|
+
var SectionTypes = __spreadArray(__spreadArray([], __read(TaskTypes.map(function (TaskType) { return "".concat(TaskType, "_TASK"); })), false), __read(NonTaskSectionTypes), false);
|
|
5813
|
+
|
|
5779
5814
|
/**
|
|
5780
5815
|
* Parses the knowledge command
|
|
5781
5816
|
*
|
|
@@ -5791,7 +5826,7 @@ var knowledgeCommandParser = {
|
|
|
5791
5826
|
* BOILERPLATE command can be used in:
|
|
5792
5827
|
*/
|
|
5793
5828
|
isUsedInPipelineHead: true,
|
|
5794
|
-
|
|
5829
|
+
isUsedInPipelineTask: false,
|
|
5795
5830
|
/**
|
|
5796
5831
|
* Description of the KNOWLEDGE command
|
|
5797
5832
|
*/
|
|
@@ -5869,18 +5904,18 @@ var knowledgeCommandParser = {
|
|
|
5869
5904
|
*/
|
|
5870
5905
|
|
|
5871
5906
|
/**
|
|
5872
|
-
* Parses the
|
|
5907
|
+
* Parses the section command
|
|
5873
5908
|
*
|
|
5874
5909
|
* @see `documentationUrl` for more details
|
|
5875
5910
|
* @private within the commands folder
|
|
5876
5911
|
*/
|
|
5877
|
-
var
|
|
5912
|
+
var sectionCommandParser = {
|
|
5878
5913
|
/**
|
|
5879
5914
|
* Name of the command
|
|
5880
5915
|
*/
|
|
5881
|
-
name: '
|
|
5916
|
+
name: 'SECTION',
|
|
5882
5917
|
/**
|
|
5883
|
-
* Aliases for the
|
|
5918
|
+
* Aliases for the SECTION command
|
|
5884
5919
|
*/
|
|
5885
5920
|
aliasNames: [
|
|
5886
5921
|
'PROMPT',
|
|
@@ -5894,24 +5929,24 @@ var templateCommandParser = {
|
|
|
5894
5929
|
'ACTION', // <- Note: [⛱]
|
|
5895
5930
|
],
|
|
5896
5931
|
/**
|
|
5897
|
-
* Aliases for the
|
|
5932
|
+
* Aliases for the SECTION command
|
|
5898
5933
|
*/
|
|
5899
|
-
deprecatedNames: ['BLOCK', 'EXECUTE'],
|
|
5934
|
+
deprecatedNames: ['TEMPLATE', 'BLOCK', 'EXECUTE'],
|
|
5900
5935
|
/**
|
|
5901
5936
|
* BOILERPLATE command can be used in:
|
|
5902
5937
|
*/
|
|
5903
5938
|
isUsedInPipelineHead: false,
|
|
5904
|
-
|
|
5939
|
+
isUsedInPipelineTask: true,
|
|
5905
5940
|
/**
|
|
5906
|
-
* Description of the
|
|
5941
|
+
* Description of the SECTION command
|
|
5907
5942
|
*/
|
|
5908
|
-
description: "
|
|
5943
|
+
description: "Defines the purpose of the markdown section - if its a task and which type or something else",
|
|
5909
5944
|
/**
|
|
5910
5945
|
* Link to documentation
|
|
5911
5946
|
*/
|
|
5912
5947
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
|
|
5913
5948
|
/**
|
|
5914
|
-
* Example usages of the
|
|
5949
|
+
* Example usages of the SECTION command
|
|
5915
5950
|
*/
|
|
5916
5951
|
examples: [
|
|
5917
5952
|
// Short form:
|
|
@@ -5926,101 +5961,103 @@ var templateCommandParser = {
|
|
|
5926
5961
|
'ACTION',
|
|
5927
5962
|
// -----------------
|
|
5928
5963
|
// Recommended (reversed) form:
|
|
5929
|
-
'PROMPT
|
|
5930
|
-
'SIMPLE
|
|
5931
|
-
'SCRIPT
|
|
5932
|
-
'DIALOG
|
|
5964
|
+
'PROMPT SECTION',
|
|
5965
|
+
'SIMPLE SECTION',
|
|
5966
|
+
'SCRIPT SECTION',
|
|
5967
|
+
'DIALOG SECTION',
|
|
5933
5968
|
// <- [🅱]
|
|
5934
|
-
'
|
|
5935
|
-
'KNOWLEDGE
|
|
5936
|
-
'INSTRUMENT
|
|
5937
|
-
'ACTION
|
|
5969
|
+
'EXAMPLE SECTION',
|
|
5970
|
+
'KNOWLEDGE SECTION',
|
|
5971
|
+
'INSTRUMENT SECTION',
|
|
5972
|
+
'ACTION SECTION',
|
|
5938
5973
|
// -----------------
|
|
5939
5974
|
// Standard form:
|
|
5940
|
-
'
|
|
5941
|
-
'
|
|
5942
|
-
'
|
|
5943
|
-
'
|
|
5975
|
+
'SECTION PROMPT',
|
|
5976
|
+
'SECTION SIMPLE',
|
|
5977
|
+
'SECTION SCRIPT',
|
|
5978
|
+
'SECTION DIALOG',
|
|
5944
5979
|
// <- [🅱]
|
|
5945
|
-
'
|
|
5946
|
-
'KNOWLEDGE
|
|
5947
|
-
'INSTRUMENT
|
|
5948
|
-
'ACTION
|
|
5980
|
+
'SECTION EXAMPLE',
|
|
5981
|
+
'SECTION KNOWLEDGE',
|
|
5982
|
+
'SECTION INSTRUMENT',
|
|
5983
|
+
'SECTION ACTION',
|
|
5949
5984
|
],
|
|
5950
5985
|
// TODO: [♓️] order: -10 /* <- Note: Putting before other commands */
|
|
5951
5986
|
/**
|
|
5952
|
-
* Parses the
|
|
5987
|
+
* Parses the SECTION command
|
|
5953
5988
|
*/
|
|
5954
5989
|
parse: function (input) {
|
|
5955
5990
|
var normalized = input.normalized;
|
|
5956
5991
|
normalized = normalized.split('SAMPLE').join('EXAMPLE');
|
|
5957
|
-
|
|
5958
|
-
|
|
5992
|
+
normalized = normalized.split('EXECUTE_').join('');
|
|
5993
|
+
normalized = normalized.split('DIALOGUE').join('DIALOG');
|
|
5994
|
+
var taskTypes = SectionTypes.filter(function (sectionType) {
|
|
5995
|
+
return normalized.includes(sectionType.split('_TASK').join(''));
|
|
5959
5996
|
});
|
|
5960
|
-
if (
|
|
5961
|
-
throw new ParseError(spaceTrim(function (
|
|
5997
|
+
if (taskTypes.length !== 1) {
|
|
5998
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Unknown section type \"".concat(normalized, "\"\n\n Supported section types are:\n ").concat(block(SectionTypes.join(', ')), "\n "); }));
|
|
5962
5999
|
}
|
|
5963
|
-
var
|
|
6000
|
+
var taskType = taskTypes[0];
|
|
5964
6001
|
return {
|
|
5965
|
-
type: '
|
|
5966
|
-
|
|
6002
|
+
type: 'SECTION',
|
|
6003
|
+
taskType: taskType,
|
|
5967
6004
|
};
|
|
5968
6005
|
},
|
|
5969
6006
|
/**
|
|
5970
|
-
* Apply the
|
|
6007
|
+
* Apply the SECTION command to the `pipelineJson`
|
|
5971
6008
|
*
|
|
5972
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
6009
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
5973
6010
|
*/
|
|
5974
|
-
$
|
|
5975
|
-
if ($
|
|
5976
|
-
throw new ParseError(spaceTrim("\n
|
|
6011
|
+
$applyToTaskJson: function (command, $taskJson, $pipelineJson) {
|
|
6012
|
+
if ($taskJson.isSectionTypeSet === true) {
|
|
6013
|
+
throw new ParseError(spaceTrim("\n Section type is already defined in the section.\n It can be defined only once.\n "));
|
|
5977
6014
|
}
|
|
5978
|
-
$
|
|
6015
|
+
$taskJson.isSectionTypeSet = true;
|
|
5979
6016
|
// TODO: [🍧] Rearrange better - but at bottom and unwrap from function
|
|
5980
6017
|
var expectResultingParameterName = function () {
|
|
5981
|
-
if ($
|
|
6018
|
+
if ($taskJson.resultingParameterName) {
|
|
5982
6019
|
return;
|
|
5983
6020
|
}
|
|
5984
|
-
throw new ParseError("
|
|
6021
|
+
throw new ParseError("Task section and example section must end with return statement -> {parameterName}");
|
|
5985
6022
|
};
|
|
5986
|
-
if ($
|
|
5987
|
-
throw new UnexpectedError("Content is missing in the
|
|
6023
|
+
if ($taskJson.content === undefined) {
|
|
6024
|
+
throw new UnexpectedError("Content is missing in the taskJson - probbably commands are applied in wrong order");
|
|
5988
6025
|
}
|
|
5989
|
-
if (command.
|
|
6026
|
+
if (command.taskType === 'EXAMPLE') {
|
|
5990
6027
|
expectResultingParameterName();
|
|
5991
|
-
var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $
|
|
6028
|
+
var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $taskJson.resultingParameterName; });
|
|
5992
6029
|
if (parameter === undefined) {
|
|
5993
|
-
throw new ParseError("Can not find parameter {".concat($
|
|
6030
|
+
throw new ParseError("Can not find parameter {".concat($taskJson.resultingParameterName, "} to assign example value on it"));
|
|
5994
6031
|
}
|
|
5995
6032
|
parameter.exampleValues = parameter.exampleValues || [];
|
|
5996
|
-
parameter.exampleValues.push($
|
|
5997
|
-
$
|
|
6033
|
+
parameter.exampleValues.push($taskJson.content);
|
|
6034
|
+
$taskJson.isTask = false;
|
|
5998
6035
|
return;
|
|
5999
6036
|
}
|
|
6000
|
-
if (command.
|
|
6037
|
+
if (command.taskType === 'KNOWLEDGE') {
|
|
6001
6038
|
knowledgeCommandParser.$applyToPipelineJson({
|
|
6002
6039
|
type: 'KNOWLEDGE',
|
|
6003
|
-
sourceContent: $
|
|
6040
|
+
sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
6004
6041
|
}, $pipelineJson);
|
|
6005
|
-
$
|
|
6042
|
+
$taskJson.isTask = false;
|
|
6006
6043
|
return;
|
|
6007
6044
|
}
|
|
6008
|
-
if (command.
|
|
6045
|
+
if (command.taskType === 'ACTION') {
|
|
6009
6046
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6010
|
-
$
|
|
6047
|
+
$taskJson.isTask = false;
|
|
6011
6048
|
return;
|
|
6012
6049
|
}
|
|
6013
|
-
if (command.
|
|
6050
|
+
if (command.taskType === 'INSTRUMENT') {
|
|
6014
6051
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6015
|
-
$
|
|
6052
|
+
$taskJson.isTask = false;
|
|
6016
6053
|
return;
|
|
6017
6054
|
}
|
|
6018
6055
|
expectResultingParameterName();
|
|
6019
|
-
$
|
|
6020
|
-
$
|
|
6056
|
+
$taskJson.taskType = command.taskType;
|
|
6057
|
+
$taskJson.isTask = true;
|
|
6021
6058
|
},
|
|
6022
6059
|
/**
|
|
6023
|
-
* Converts the
|
|
6060
|
+
* Converts the SECTION command back to string
|
|
6024
6061
|
*
|
|
6025
6062
|
* Note: This is used in `pipelineJsonToString` utility
|
|
6026
6063
|
*/
|
|
@@ -6028,11 +6065,11 @@ var templateCommandParser = {
|
|
|
6028
6065
|
return "---"; // <- TODO: [🛋] Implement
|
|
6029
6066
|
},
|
|
6030
6067
|
/**
|
|
6031
|
-
* Reads the
|
|
6068
|
+
* Reads the SECTION command from the `TaskJson`
|
|
6032
6069
|
*
|
|
6033
6070
|
* Note: This is used in `pipelineJsonToString` utility
|
|
6034
6071
|
*/
|
|
6035
|
-
|
|
6072
|
+
takeFromTaskJson: function ($taskJson) {
|
|
6036
6073
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
6037
6074
|
},
|
|
6038
6075
|
};
|
|
@@ -6040,8 +6077,8 @@ var templateCommandParser = {
|
|
|
6040
6077
|
* Note: [⛱] There are two types of KNOWLEDGE, ACTION and INSTRUMENT commands:
|
|
6041
6078
|
* 1) There are commands `KNOWLEDGE`, `ACTION` and `INSTRUMENT` used in the pipeline head, they just define the knowledge, action or instrument as single line after the command
|
|
6042
6079
|
* - KNOWLEDGE Look at https://en.wikipedia.org/wiki/Artificial_intelligence
|
|
6043
|
-
* 2) `KNOWLEDGE
|
|
6044
|
-
* - KNOWLEDGE
|
|
6080
|
+
* 2) `KNOWLEDGE SECTION` which has short form `KNOWLEDGE` is used in the sectiom, does not refer the line itself, but the content of the section block
|
|
6081
|
+
* - KNOWLEDGE SECTION
|
|
6045
6082
|
*
|
|
6046
6083
|
* ```
|
|
6047
6084
|
* Look at https://en.wikipedia.org/wiki/Artificial_intelligence
|
|
@@ -6069,7 +6106,7 @@ var boilerplateCommandParser = {
|
|
|
6069
6106
|
* BOILERPLATE command can be used in:
|
|
6070
6107
|
*/
|
|
6071
6108
|
isUsedInPipelineHead: true,
|
|
6072
|
-
|
|
6109
|
+
isUsedInPipelineTask: true,
|
|
6073
6110
|
/**
|
|
6074
6111
|
* Description of the BOILERPLATE command
|
|
6075
6112
|
*/
|
|
@@ -6110,9 +6147,9 @@ var boilerplateCommandParser = {
|
|
|
6110
6147
|
/**
|
|
6111
6148
|
* Apply the BOILERPLATE command to the `pipelineJson`
|
|
6112
6149
|
*
|
|
6113
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
6150
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
6114
6151
|
*/
|
|
6115
|
-
$
|
|
6152
|
+
$applyToTaskJson: function (command, $taskJson, $pipelineJson) {
|
|
6116
6153
|
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
|
|
6117
6154
|
},
|
|
6118
6155
|
/**
|
|
@@ -6132,11 +6169,11 @@ var boilerplateCommandParser = {
|
|
|
6132
6169
|
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
|
|
6133
6170
|
},
|
|
6134
6171
|
/**
|
|
6135
|
-
* Reads the BOILERPLATE command from the `
|
|
6172
|
+
* Reads the BOILERPLATE command from the `TaskJson`
|
|
6136
6173
|
*
|
|
6137
6174
|
* Note: This is used in `pipelineJsonToString` utility
|
|
6138
6175
|
*/
|
|
6139
|
-
|
|
6176
|
+
takeFromTaskJson: function ($taskJson) {
|
|
6140
6177
|
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
|
|
6141
6178
|
},
|
|
6142
6179
|
};
|
|
@@ -6157,7 +6194,7 @@ var bookVersionCommandParser = {
|
|
|
6157
6194
|
* BOILERPLATE command can be used in:
|
|
6158
6195
|
*/
|
|
6159
6196
|
isUsedInPipelineHead: true,
|
|
6160
|
-
|
|
6197
|
+
isUsedInPipelineTask: false,
|
|
6161
6198
|
/**
|
|
6162
6199
|
* Description of the BOOK_VERSION command
|
|
6163
6200
|
*/
|
|
@@ -6311,11 +6348,11 @@ var expectCommandParser = {
|
|
|
6311
6348
|
* BOILERPLATE command can be used in:
|
|
6312
6349
|
*/
|
|
6313
6350
|
isUsedInPipelineHead: false,
|
|
6314
|
-
|
|
6351
|
+
isUsedInPipelineTask: true,
|
|
6315
6352
|
/**
|
|
6316
6353
|
* Description of the FORMAT command
|
|
6317
6354
|
*/
|
|
6318
|
-
description: spaceTrim("\n Expect command describes the desired output of the
|
|
6355
|
+
description: spaceTrim("\n Expect command describes the desired output of the task *(after post-processing)*\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
6319
6356
|
/**
|
|
6320
6357
|
* Link to documentation
|
|
6321
6358
|
*/
|
|
@@ -6407,24 +6444,24 @@ var expectCommandParser = {
|
|
|
6407
6444
|
/**
|
|
6408
6445
|
* Apply the FORMAT command to the `pipelineJson`
|
|
6409
6446
|
*
|
|
6410
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
6447
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
6411
6448
|
*/
|
|
6412
|
-
$
|
|
6449
|
+
$applyToTaskJson: function (command, $taskJson) {
|
|
6413
6450
|
// eslint-disable-next-line no-case-declarations
|
|
6414
6451
|
var unit = command.unit.toLowerCase();
|
|
6415
|
-
$
|
|
6416
|
-
$
|
|
6452
|
+
$taskJson.expectations = $taskJson.expectations || {};
|
|
6453
|
+
$taskJson.expectations[unit] = $taskJson.expectations[unit] || {};
|
|
6417
6454
|
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
6418
|
-
if ($
|
|
6419
|
-
throw new ParseError("Already defined minumum ".concat($
|
|
6455
|
+
if ($taskJson.expectations[unit].min !== undefined) {
|
|
6456
|
+
throw new ParseError("Already defined minumum ".concat($taskJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
6420
6457
|
}
|
|
6421
|
-
$
|
|
6458
|
+
$taskJson.expectations[unit].min = command.amount;
|
|
6422
6459
|
} /* not else */
|
|
6423
6460
|
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
6424
|
-
if ($
|
|
6425
|
-
throw new ParseError("Already defined maximum ".concat($
|
|
6461
|
+
if ($taskJson.expectations[unit].max !== undefined) {
|
|
6462
|
+
throw new ParseError("Already defined maximum ".concat($taskJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
6426
6463
|
}
|
|
6427
|
-
$
|
|
6464
|
+
$taskJson.expectations[unit].max = command.amount;
|
|
6428
6465
|
}
|
|
6429
6466
|
},
|
|
6430
6467
|
/**
|
|
@@ -6436,11 +6473,11 @@ var expectCommandParser = {
|
|
|
6436
6473
|
return "---"; // <- TODO: [🛋] Implement
|
|
6437
6474
|
},
|
|
6438
6475
|
/**
|
|
6439
|
-
* Reads the FORMAT command from the `
|
|
6476
|
+
* Reads the FORMAT command from the `TaskJson`
|
|
6440
6477
|
*
|
|
6441
6478
|
* Note: This is used in `pipelineJsonToString` utility
|
|
6442
6479
|
*/
|
|
6443
|
-
|
|
6480
|
+
takeFromTaskJson: function ($taskJson) {
|
|
6444
6481
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
6445
6482
|
},
|
|
6446
6483
|
};
|
|
@@ -6647,7 +6684,7 @@ var foreachCommandParser = {
|
|
|
6647
6684
|
* FOREACH command can be used in:
|
|
6648
6685
|
*/
|
|
6649
6686
|
isUsedInPipelineHead: false,
|
|
6650
|
-
|
|
6687
|
+
isUsedInPipelineTask: true,
|
|
6651
6688
|
/**
|
|
6652
6689
|
* Description of the FOREACH command
|
|
6653
6690
|
*/
|
|
@@ -6746,13 +6783,13 @@ var foreachCommandParser = {
|
|
|
6746
6783
|
/**
|
|
6747
6784
|
* Apply the FOREACH command to the `pipelineJson`
|
|
6748
6785
|
*
|
|
6749
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
6786
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
6750
6787
|
*/
|
|
6751
|
-
$
|
|
6788
|
+
$applyToTaskJson: function (command, $taskJson, $pipelineJson) {
|
|
6752
6789
|
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
6753
6790
|
// TODO: [🍭] Detect double use
|
|
6754
6791
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
6755
|
-
$
|
|
6792
|
+
$taskJson.foreach = {
|
|
6756
6793
|
formatName: formatName,
|
|
6757
6794
|
subformatName: subformatName,
|
|
6758
6795
|
parameterName: parameterName,
|
|
@@ -6770,11 +6807,11 @@ var foreachCommandParser = {
|
|
|
6770
6807
|
return "---"; // <- TODO: [🛋] Implement
|
|
6771
6808
|
},
|
|
6772
6809
|
/**
|
|
6773
|
-
* Reads the FOREACH command from the `
|
|
6810
|
+
* Reads the FOREACH command from the `TaskJson`
|
|
6774
6811
|
*
|
|
6775
6812
|
* Note: This is used in `pipelineJsonToString` utility
|
|
6776
6813
|
*/
|
|
6777
|
-
|
|
6814
|
+
takeFromTaskJson: function ($taskJson) {
|
|
6778
6815
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
6779
6816
|
},
|
|
6780
6817
|
};
|
|
@@ -6797,11 +6834,11 @@ var formatCommandParser = {
|
|
|
6797
6834
|
* BOILERPLATE command can be used in:
|
|
6798
6835
|
*/
|
|
6799
6836
|
isUsedInPipelineHead: false,
|
|
6800
|
-
|
|
6837
|
+
isUsedInPipelineTask: true,
|
|
6801
6838
|
/**
|
|
6802
6839
|
* Description of the FORMAT command
|
|
6803
6840
|
*/
|
|
6804
|
-
description: spaceTrim("\n Format command describes the desired output of the
|
|
6841
|
+
description: spaceTrim("\n Format command describes the desired output of the task (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
6805
6842
|
/**
|
|
6806
6843
|
* Link to documentation
|
|
6807
6844
|
*/
|
|
@@ -6828,13 +6865,13 @@ var formatCommandParser = {
|
|
|
6828
6865
|
/**
|
|
6829
6866
|
* Apply the FORMAT command to the `pipelineJson`
|
|
6830
6867
|
*
|
|
6831
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
6868
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
6832
6869
|
*/
|
|
6833
|
-
$
|
|
6834
|
-
if ($
|
|
6835
|
-
throw new ParseError("Format format is already defined to \"".concat($
|
|
6870
|
+
$applyToTaskJson: function (command, $taskJson) {
|
|
6871
|
+
if ($taskJson.format !== undefined && command.format !== $taskJson.format) {
|
|
6872
|
+
throw new ParseError("Format format is already defined to \"".concat($taskJson.format, "\".\n Now you try to redefine it by \"").concat(command.format, "\""));
|
|
6836
6873
|
}
|
|
6837
|
-
$
|
|
6874
|
+
$taskJson.format = command.format;
|
|
6838
6875
|
},
|
|
6839
6876
|
/**
|
|
6840
6877
|
* Converts the FORMAT command back to string
|
|
@@ -6845,11 +6882,11 @@ var formatCommandParser = {
|
|
|
6845
6882
|
return "---"; // <- TODO: [🛋] Implement
|
|
6846
6883
|
},
|
|
6847
6884
|
/**
|
|
6848
|
-
* Reads the FORMAT command from the `
|
|
6885
|
+
* Reads the FORMAT command from the `TaskJson`
|
|
6849
6886
|
*
|
|
6850
6887
|
* Note: This is used in `pipelineJsonToString` utility
|
|
6851
6888
|
*/
|
|
6852
|
-
|
|
6889
|
+
takeFromTaskJson: function ($taskJson) {
|
|
6853
6890
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
6854
6891
|
},
|
|
6855
6892
|
};
|
|
@@ -6859,37 +6896,68 @@ var formatCommandParser = {
|
|
|
6859
6896
|
*
|
|
6860
6897
|
* @public exported from `@promptbook/core`
|
|
6861
6898
|
*/
|
|
6862
|
-
var
|
|
6899
|
+
var ChatbotFormfactorDefinition = {
|
|
6863
6900
|
name: 'CHATBOT',
|
|
6864
6901
|
aliasNames: ['CHAT'],
|
|
6865
6902
|
description: "@@@",
|
|
6866
|
-
documentationUrl: "https://github.com/webgptorg/promptbook/discussions
|
|
6903
|
+
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/174",
|
|
6867
6904
|
pipelineInterface: {
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
|
|
6905
|
+
inputParameters: [
|
|
6906
|
+
{
|
|
6907
|
+
name: 'previousTitle',
|
|
6908
|
+
description: "Previous title of the conversation",
|
|
6909
|
+
isInput: true,
|
|
6910
|
+
isOutput: false,
|
|
6911
|
+
},
|
|
6912
|
+
{
|
|
6913
|
+
name: 'previousConversationSummary',
|
|
6914
|
+
description: "Previous conversation summary",
|
|
6915
|
+
isInput: true,
|
|
6916
|
+
isOutput: false,
|
|
6917
|
+
},
|
|
6918
|
+
{ name: 'userMessage', description: "User message", isInput: true, isOutput: false },
|
|
6919
|
+
],
|
|
6920
|
+
outputParameters: [
|
|
6921
|
+
{ name: 'title', description: "Title of the conversation", isInput: false, isOutput: true },
|
|
6922
|
+
{ name: 'conversationSummary', description: "Summary of the conversation", isInput: false, isOutput: true },
|
|
6923
|
+
{ name: 'chatbotResponse', description: "Chatbot response", isInput: false, isOutput: true },
|
|
6924
|
+
],
|
|
6925
|
+
},
|
|
6926
|
+
};
|
|
6879
6927
|
|
|
6880
|
-
|
|
6928
|
+
/**
|
|
6929
|
+
* Generator is form of app that @@@
|
|
6930
|
+
*
|
|
6931
|
+
* @public exported from `@promptbook/core`
|
|
6932
|
+
*/
|
|
6933
|
+
var GeneratorFormfactorDefinition = {
|
|
6934
|
+
name: 'GENERATOR',
|
|
6935
|
+
description: "@@@",
|
|
6936
|
+
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/184",
|
|
6937
|
+
pipelineInterface: {
|
|
6938
|
+
inputParameters: [
|
|
6939
|
+
/* @@@ */
|
|
6940
|
+
],
|
|
6941
|
+
outputParameters: [
|
|
6942
|
+
/* @@@ */
|
|
6943
|
+
],
|
|
6881
6944
|
},
|
|
6882
6945
|
};
|
|
6883
6946
|
|
|
6884
6947
|
/**
|
|
6885
6948
|
* @@@
|
|
6886
6949
|
*
|
|
6950
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
6951
|
+
*
|
|
6887
6952
|
* @public exported from `@promptbook/core`
|
|
6888
6953
|
*/
|
|
6889
6954
|
var GENERIC_PIPELINE_INTERFACE = {
|
|
6890
|
-
|
|
6891
|
-
|
|
6955
|
+
inputParameters: [],
|
|
6956
|
+
outputParameters: [],
|
|
6892
6957
|
};
|
|
6958
|
+
/**
|
|
6959
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
6960
|
+
*/
|
|
6893
6961
|
|
|
6894
6962
|
/**
|
|
6895
6963
|
* @@@
|
|
@@ -6899,10 +6967,29 @@ var GENERIC_PIPELINE_INTERFACE = {
|
|
|
6899
6967
|
var GenericFormfactorDefinition = {
|
|
6900
6968
|
name: 'GENERIC',
|
|
6901
6969
|
description: "@@@",
|
|
6902
|
-
documentationUrl: "https://github.com/webgptorg/promptbook/discussions
|
|
6970
|
+
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/173",
|
|
6903
6971
|
pipelineInterface: GENERIC_PIPELINE_INTERFACE,
|
|
6904
6972
|
};
|
|
6905
6973
|
|
|
6974
|
+
/**
|
|
6975
|
+
* Matcher is form of app that @@@
|
|
6976
|
+
*
|
|
6977
|
+
* @public exported from `@promptbook/core`
|
|
6978
|
+
*/
|
|
6979
|
+
var MatcherFormfactorDefinition = {
|
|
6980
|
+
name: 'EXPERIMENTAL_MATCHER',
|
|
6981
|
+
description: "@@@",
|
|
6982
|
+
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/177",
|
|
6983
|
+
pipelineInterface: {
|
|
6984
|
+
inputParameters: [
|
|
6985
|
+
/* @@@ */
|
|
6986
|
+
],
|
|
6987
|
+
outputParameters: [
|
|
6988
|
+
/* @@@ */
|
|
6989
|
+
],
|
|
6990
|
+
},
|
|
6991
|
+
};
|
|
6992
|
+
|
|
6906
6993
|
/**
|
|
6907
6994
|
* Sheets is form of app that @@@
|
|
6908
6995
|
*
|
|
@@ -6911,10 +6998,24 @@ var GenericFormfactorDefinition = {
|
|
|
6911
6998
|
var SheetsFormfactorDefinition = {
|
|
6912
6999
|
name: 'SHEETS',
|
|
6913
7000
|
description: "@@@",
|
|
6914
|
-
documentationUrl: "https://github.com/webgptorg/promptbook/discussions
|
|
7001
|
+
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/176",
|
|
6915
7002
|
pipelineInterface: {
|
|
6916
|
-
|
|
6917
|
-
|
|
7003
|
+
inputParameters: [
|
|
7004
|
+
{
|
|
7005
|
+
name: 'inputSheet',
|
|
7006
|
+
description: "Input sheet to be processed as csv",
|
|
7007
|
+
isInput: true,
|
|
7008
|
+
isOutput: false,
|
|
7009
|
+
},
|
|
7010
|
+
],
|
|
7011
|
+
outputParameters: [
|
|
7012
|
+
{
|
|
7013
|
+
name: 'outputSheet',
|
|
7014
|
+
description: "Output sheet as csv",
|
|
7015
|
+
isInput: false,
|
|
7016
|
+
isOutput: true,
|
|
7017
|
+
},
|
|
7018
|
+
],
|
|
6918
7019
|
},
|
|
6919
7020
|
};
|
|
6920
7021
|
|
|
@@ -6926,10 +7027,26 @@ var SheetsFormfactorDefinition = {
|
|
|
6926
7027
|
var TranslatorFormfactorDefinition = {
|
|
6927
7028
|
name: 'TRANSLATOR',
|
|
6928
7029
|
description: "@@@",
|
|
6929
|
-
documentationUrl: "https://github.com/webgptorg/promptbook/discussions
|
|
7030
|
+
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/175",
|
|
6930
7031
|
pipelineInterface: {
|
|
6931
|
-
|
|
6932
|
-
|
|
7032
|
+
inputParameters: [
|
|
7033
|
+
{
|
|
7034
|
+
name: 'inputMessage',
|
|
7035
|
+
description: "Input message to be translated",
|
|
7036
|
+
isInput: true,
|
|
7037
|
+
isOutput: false,
|
|
7038
|
+
},
|
|
7039
|
+
],
|
|
7040
|
+
outputParameters: [
|
|
7041
|
+
{
|
|
7042
|
+
name: 'outputMessage',
|
|
7043
|
+
description: "Translated output message",
|
|
7044
|
+
isInput: false,
|
|
7045
|
+
isOutput: true,
|
|
7046
|
+
},
|
|
7047
|
+
],
|
|
7048
|
+
// <- TODO: [🤓] Maybe add {summary}
|
|
7049
|
+
// <- TODO: [🧠] maybe change to {inputText}, {inputText} / or make system for any name of first input and first outpur parameter
|
|
6933
7050
|
},
|
|
6934
7051
|
};
|
|
6935
7052
|
|
|
@@ -6940,10 +7057,15 @@ var TranslatorFormfactorDefinition = {
|
|
|
6940
7057
|
*/
|
|
6941
7058
|
var FORMFACTOR_DEFINITIONS = [
|
|
6942
7059
|
GenericFormfactorDefinition,
|
|
6943
|
-
|
|
7060
|
+
ChatbotFormfactorDefinition,
|
|
6944
7061
|
TranslatorFormfactorDefinition,
|
|
6945
7062
|
SheetsFormfactorDefinition,
|
|
7063
|
+
MatcherFormfactorDefinition,
|
|
7064
|
+
GeneratorFormfactorDefinition,
|
|
6946
7065
|
];
|
|
7066
|
+
/**
|
|
7067
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
7068
|
+
*/
|
|
6947
7069
|
|
|
6948
7070
|
/**
|
|
6949
7071
|
* Parses the formfactor command
|
|
@@ -6966,7 +7088,7 @@ var formfactorCommandParser = {
|
|
|
6966
7088
|
* FORMFACTOR command can be used in:
|
|
6967
7089
|
*/
|
|
6968
7090
|
isUsedInPipelineHead: true,
|
|
6969
|
-
|
|
7091
|
+
isUsedInPipelineTask: false,
|
|
6970
7092
|
/**
|
|
6971
7093
|
* Description of the FORMFACTOR command
|
|
6972
7094
|
*/
|
|
@@ -7048,11 +7170,11 @@ var jokerCommandParser = {
|
|
|
7048
7170
|
* BOILERPLATE command can be used in:
|
|
7049
7171
|
*/
|
|
7050
7172
|
isUsedInPipelineHead: false,
|
|
7051
|
-
|
|
7173
|
+
isUsedInPipelineTask: true,
|
|
7052
7174
|
/**
|
|
7053
7175
|
* Description of the JOKER command
|
|
7054
7176
|
*/
|
|
7055
|
-
description: "Joker parameter is used instead of executing the
|
|
7177
|
+
description: "Joker parameter is used instead of executing the task result if jokers value meets the expectations requirements",
|
|
7056
7178
|
/**
|
|
7057
7179
|
* Link to documentation
|
|
7058
7180
|
*/
|
|
@@ -7079,11 +7201,11 @@ var jokerCommandParser = {
|
|
|
7079
7201
|
/**
|
|
7080
7202
|
* Apply the JOKER command to the `pipelineJson`
|
|
7081
7203
|
*
|
|
7082
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
7204
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
7083
7205
|
*/
|
|
7084
|
-
$
|
|
7085
|
-
$
|
|
7086
|
-
$
|
|
7206
|
+
$applyToTaskJson: function (command, $taskJson) {
|
|
7207
|
+
$taskJson.jokerParameterNames = $taskJson.jokerParameterNames || [];
|
|
7208
|
+
$taskJson.jokerParameterNames.push(command.parameterName);
|
|
7087
7209
|
},
|
|
7088
7210
|
/**
|
|
7089
7211
|
* Converts the JOKER command back to string
|
|
@@ -7094,11 +7216,11 @@ var jokerCommandParser = {
|
|
|
7094
7216
|
return "---"; // <- TODO: [🛋] Implement
|
|
7095
7217
|
},
|
|
7096
7218
|
/**
|
|
7097
|
-
* Reads the JOKER command from the `
|
|
7219
|
+
* Reads the JOKER command from the `TaskJson`
|
|
7098
7220
|
*
|
|
7099
7221
|
* Note: This is used in `pipelineJsonToString` utility
|
|
7100
7222
|
*/
|
|
7101
|
-
|
|
7223
|
+
takeFromTaskJson: function ($taskJson) {
|
|
7102
7224
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
7103
7225
|
},
|
|
7104
7226
|
};
|
|
@@ -7125,11 +7247,11 @@ var modelCommandParser = {
|
|
|
7125
7247
|
* BOILERPLATE command can be used in:
|
|
7126
7248
|
*/
|
|
7127
7249
|
isUsedInPipelineHead: true,
|
|
7128
|
-
|
|
7250
|
+
isUsedInPipelineTask: true,
|
|
7129
7251
|
/**
|
|
7130
7252
|
* Description of the MODEL command
|
|
7131
7253
|
*/
|
|
7132
|
-
description: "Tells which `modelRequirements` (for example which model) to use for the prompt
|
|
7254
|
+
description: "Tells which `modelRequirements` (for example which model) to use for the prompt task execution",
|
|
7133
7255
|
/**
|
|
7134
7256
|
* Link to documentation
|
|
7135
7257
|
*/
|
|
@@ -7203,30 +7325,30 @@ var modelCommandParser = {
|
|
|
7203
7325
|
/**
|
|
7204
7326
|
* Apply the MODEL command to the `pipelineJson`
|
|
7205
7327
|
*
|
|
7206
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
7328
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
7207
7329
|
*/
|
|
7208
|
-
$
|
|
7209
|
-
if ($
|
|
7210
|
-
throw new ParseError("MODEL command can only be used in
|
|
7330
|
+
$applyToTaskJson: function (command, $taskJson, $pipelineJson) {
|
|
7331
|
+
if ($taskJson.taskType !== 'PROMPT_TASK') {
|
|
7332
|
+
throw new ParseError("MODEL command can only be used in PROMPT_TASK block");
|
|
7211
7333
|
}
|
|
7212
|
-
$
|
|
7334
|
+
$taskJson.modelRequirements = $taskJson.modelRequirements || {};
|
|
7213
7335
|
// TODO: [🚜] DRY
|
|
7214
|
-
if ($
|
|
7215
|
-
if ($
|
|
7336
|
+
if ($taskJson.modelRequirements[command.key] !== undefined) {
|
|
7337
|
+
if ($taskJson.modelRequirements[command.key] === command.value) {
|
|
7216
7338
|
console.warn("Multiple commands `MODEL ".concat({
|
|
7217
7339
|
modelName: 'NAME',
|
|
7218
7340
|
modelVariant: 'VARIANT',
|
|
7219
7341
|
maxTokens: '???',
|
|
7220
|
-
}[command.key], " ").concat(command.value, "` in the
|
|
7342
|
+
}[command.key], " ").concat(command.value, "` in the task \"").concat($taskJson.title || $taskJson.name, "\""));
|
|
7221
7343
|
}
|
|
7222
7344
|
else {
|
|
7223
|
-
throw new ParseError(spaceTrim("\n Redefinition of MODEL `".concat(command.key, "` in the
|
|
7345
|
+
throw new ParseError(spaceTrim("\n Redefinition of MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\"\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($taskJson.modelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
|
|
7224
7346
|
}
|
|
7225
7347
|
}
|
|
7226
7348
|
if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
|
|
7227
|
-
console.log(spaceTrim("\n Setting MODEL `".concat(command.key, "` in the
|
|
7349
|
+
console.log(spaceTrim("\n Setting MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\" to the same value as in the pipeline head\n\n In pipeline head:\n - MODEL ").concat(command.key, " ").concat(($pipelineJson.defaultModelRequirements || {})[command.key], "\n\n But same value is used in the task:\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
|
|
7228
7350
|
}
|
|
7229
|
-
$
|
|
7351
|
+
$taskJson.modelRequirements[command.key] = command.value;
|
|
7230
7352
|
},
|
|
7231
7353
|
/**
|
|
7232
7354
|
* Converts the MODEL command back to string
|
|
@@ -7245,11 +7367,11 @@ var modelCommandParser = {
|
|
|
7245
7367
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
7246
7368
|
},
|
|
7247
7369
|
/**
|
|
7248
|
-
* Reads the MODEL command from the `
|
|
7370
|
+
* Reads the MODEL command from the `TaskJson`
|
|
7249
7371
|
*
|
|
7250
7372
|
* Note: This is used in `pipelineJsonToString` utility
|
|
7251
7373
|
*/
|
|
7252
|
-
|
|
7374
|
+
takeFromTaskJson: function ($taskJson) {
|
|
7253
7375
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
7254
7376
|
},
|
|
7255
7377
|
};
|
|
@@ -7276,11 +7398,11 @@ var parameterCommandParser = {
|
|
|
7276
7398
|
* BOILERPLATE command can be used in:
|
|
7277
7399
|
*/
|
|
7278
7400
|
isUsedInPipelineHead: true,
|
|
7279
|
-
|
|
7401
|
+
isUsedInPipelineTask: true,
|
|
7280
7402
|
/**
|
|
7281
7403
|
* Description of the PARAMETER command
|
|
7282
7404
|
*/
|
|
7283
|
-
description: "Describes one parameter of the
|
|
7405
|
+
description: "Describes one parameter of the task",
|
|
7284
7406
|
/**
|
|
7285
7407
|
* Link to documentation
|
|
7286
7408
|
*/
|
|
@@ -7328,9 +7450,9 @@ var parameterCommandParser = {
|
|
|
7328
7450
|
/**
|
|
7329
7451
|
* Apply the PARAMETER command to the `pipelineJson`
|
|
7330
7452
|
*
|
|
7331
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
7453
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
7332
7454
|
*/
|
|
7333
|
-
$
|
|
7455
|
+
$applyToTaskJson: function (command, $taskJson, $pipelineJson) {
|
|
7334
7456
|
// Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
|
|
7335
7457
|
},
|
|
7336
7458
|
/**
|
|
@@ -7350,11 +7472,11 @@ var parameterCommandParser = {
|
|
|
7350
7472
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
7351
7473
|
},
|
|
7352
7474
|
/**
|
|
7353
|
-
* Reads the PARAMETER command from the `
|
|
7475
|
+
* Reads the PARAMETER command from the `TaskJson`
|
|
7354
7476
|
*
|
|
7355
7477
|
* Note: This is used in `pipelineJsonToString` utility
|
|
7356
7478
|
*/
|
|
7357
|
-
|
|
7479
|
+
takeFromTaskJson: function ($taskJson) {
|
|
7358
7480
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
7359
7481
|
},
|
|
7360
7482
|
};
|
|
@@ -7378,7 +7500,7 @@ var personaCommandParser = {
|
|
|
7378
7500
|
* PERSONA command can be used in:
|
|
7379
7501
|
*/
|
|
7380
7502
|
isUsedInPipelineHead: true,
|
|
7381
|
-
|
|
7503
|
+
isUsedInPipelineTask: true,
|
|
7382
7504
|
/**
|
|
7383
7505
|
* Description of the PERSONA command
|
|
7384
7506
|
*/
|
|
@@ -7417,9 +7539,9 @@ var personaCommandParser = {
|
|
|
7417
7539
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
7418
7540
|
*/
|
|
7419
7541
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
7420
|
-
$
|
|
7542
|
+
$applyToTaskJson(command, null, $pipelineJson);
|
|
7421
7543
|
},
|
|
7422
|
-
$
|
|
7544
|
+
$applyToTaskJson: $applyToTaskJson,
|
|
7423
7545
|
/**
|
|
7424
7546
|
* Converts the PERSONA command back to string
|
|
7425
7547
|
*
|
|
@@ -7437,26 +7559,26 @@ var personaCommandParser = {
|
|
|
7437
7559
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
7438
7560
|
},
|
|
7439
7561
|
/**
|
|
7440
|
-
* Reads the PERSONA command from the `
|
|
7562
|
+
* Reads the PERSONA command from the `TaskJson`
|
|
7441
7563
|
*
|
|
7442
7564
|
* Note: This is used in `pipelineJsonToString` utility
|
|
7443
7565
|
*/
|
|
7444
|
-
|
|
7566
|
+
takeFromTaskJson: function ($taskJson) {
|
|
7445
7567
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
7446
7568
|
},
|
|
7447
7569
|
};
|
|
7448
7570
|
/**
|
|
7449
7571
|
* Apply the PERSONA command to the `pipelineJson`
|
|
7450
7572
|
*
|
|
7451
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
7573
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
7452
7574
|
*/
|
|
7453
|
-
function $
|
|
7575
|
+
function $applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
7454
7576
|
var personaName = command.personaName, personaDescription = command.personaDescription;
|
|
7455
|
-
if ($
|
|
7456
|
-
if ($
|
|
7457
|
-
throw new ParseError("PERSONA command can be used only in
|
|
7577
|
+
if ($taskJson !== null) {
|
|
7578
|
+
if ($taskJson.taskType !== 'PROMPT_TASK') {
|
|
7579
|
+
throw new ParseError("PERSONA command can be used only in PROMPT_TASK block");
|
|
7458
7580
|
}
|
|
7459
|
-
$
|
|
7581
|
+
$taskJson.personaName = personaName;
|
|
7460
7582
|
}
|
|
7461
7583
|
var persona = $pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
7462
7584
|
if (persona === undefined) {
|
|
@@ -7510,7 +7632,7 @@ var postprocessCommandParser = {
|
|
|
7510
7632
|
* BOILERPLATE command can be used in:
|
|
7511
7633
|
*/
|
|
7512
7634
|
isUsedInPipelineHead: false,
|
|
7513
|
-
|
|
7635
|
+
isUsedInPipelineTask: true,
|
|
7514
7636
|
/**
|
|
7515
7637
|
* Description of the POSTPROCESS command
|
|
7516
7638
|
*/
|
|
@@ -7548,11 +7670,11 @@ var postprocessCommandParser = {
|
|
|
7548
7670
|
/**
|
|
7549
7671
|
* Apply the POSTPROCESS command to the `pipelineJson`
|
|
7550
7672
|
*
|
|
7551
|
-
* Note: `$` is used to indicate that this function mutates given `
|
|
7673
|
+
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
7552
7674
|
*/
|
|
7553
|
-
$
|
|
7554
|
-
$
|
|
7555
|
-
$
|
|
7675
|
+
$applyToTaskJson: function (command, $taskJson) {
|
|
7676
|
+
$taskJson.postprocessingFunctionNames = $taskJson.postprocessingFunctionNames || [];
|
|
7677
|
+
$taskJson.postprocessingFunctionNames.push(command.functionName);
|
|
7556
7678
|
},
|
|
7557
7679
|
/**
|
|
7558
7680
|
* Converts the POSTPROCESS command back to string
|
|
@@ -7563,11 +7685,11 @@ var postprocessCommandParser = {
|
|
|
7563
7685
|
return "---"; // <- TODO: [🛋] Implement
|
|
7564
7686
|
},
|
|
7565
7687
|
/**
|
|
7566
|
-
* Reads the POSTPROCESS command from the `
|
|
7688
|
+
* Reads the POSTPROCESS command from the `TaskJson`
|
|
7567
7689
|
*
|
|
7568
7690
|
* Note: This is used in `pipelineJsonToString` utility
|
|
7569
7691
|
*/
|
|
7570
|
-
|
|
7692
|
+
takeFromTaskJson: function ($taskJson) {
|
|
7571
7693
|
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
7572
7694
|
},
|
|
7573
7695
|
};
|
|
@@ -7592,7 +7714,7 @@ var urlCommandParser = {
|
|
|
7592
7714
|
* BOILERPLATE command can be used in:
|
|
7593
7715
|
*/
|
|
7594
7716
|
isUsedInPipelineHead: true,
|
|
7595
|
-
|
|
7717
|
+
isUsedInPipelineTask: false,
|
|
7596
7718
|
/**
|
|
7597
7719
|
* Description of the URL command
|
|
7598
7720
|
*/
|
|
@@ -7636,7 +7758,7 @@ var urlCommandParser = {
|
|
|
7636
7758
|
spaceTrim(
|
|
7637
7759
|
`
|
|
7638
7760
|
URL must not contain hash
|
|
7639
|
-
Hash is used for identification of the
|
|
7761
|
+
Hash is used for identification of the section of the pipeline
|
|
7640
7762
|
`,
|
|
7641
7763
|
),
|
|
7642
7764
|
);
|
|
@@ -7688,11 +7810,11 @@ var actionCommandParser = {
|
|
|
7688
7810
|
* ACTION command can be used in:
|
|
7689
7811
|
*/
|
|
7690
7812
|
isUsedInPipelineHead: true,
|
|
7691
|
-
|
|
7813
|
+
isUsedInPipelineTask: false,
|
|
7692
7814
|
/**
|
|
7693
7815
|
* Description of the ACTION command
|
|
7694
7816
|
*/
|
|
7695
|
-
description: "Actions influences from the pipeline or
|
|
7817
|
+
description: "Actions influences from the pipeline or task into external world. Like turning on a light, sending an email, etc.",
|
|
7696
7818
|
/**
|
|
7697
7819
|
* Link to documentation
|
|
7698
7820
|
*/
|
|
@@ -7754,11 +7876,11 @@ var instrumentCommandParser = {
|
|
|
7754
7876
|
* INSTRUMENT command can be used in:
|
|
7755
7877
|
*/
|
|
7756
7878
|
isUsedInPipelineHead: true,
|
|
7757
|
-
|
|
7879
|
+
isUsedInPipelineTask: false,
|
|
7758
7880
|
/**
|
|
7759
7881
|
* Description of the INSTRUMENT command
|
|
7760
7882
|
*/
|
|
7761
|
-
description: "Instrument command is used to specify the instrument to be used in the pipeline or
|
|
7883
|
+
description: "Instrument command is used to specify the instrument to be used in the pipeline or task like search, calculate, etc.",
|
|
7762
7884
|
/**
|
|
7763
7885
|
* Link to documentation
|
|
7764
7886
|
*/
|
|
@@ -7811,7 +7933,7 @@ var instrumentCommandParser = {
|
|
|
7811
7933
|
* @private internal index of `parseCommand`
|
|
7812
7934
|
*/
|
|
7813
7935
|
var COMMANDS = [
|
|
7814
|
-
|
|
7936
|
+
sectionCommandParser,
|
|
7815
7937
|
expectCommandParser,
|
|
7816
7938
|
formatCommandParser,
|
|
7817
7939
|
jokerCommandParser,
|
|
@@ -7829,6 +7951,9 @@ var COMMANDS = [
|
|
|
7829
7951
|
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
7830
7952
|
// <- Note: [♓️] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
|
|
7831
7953
|
];
|
|
7954
|
+
/**
|
|
7955
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
7956
|
+
*/
|
|
7832
7957
|
|
|
7833
7958
|
/**
|
|
7834
7959
|
* Gets the parser for the command
|
|
@@ -7889,7 +8014,6 @@ function parseCommand(raw, usagePlace) {
|
|
|
7889
8014
|
normalized = normalized.split('(').join('');
|
|
7890
8015
|
normalized = normalized.split(')').join('');
|
|
7891
8016
|
normalized = normalizeTo_SCREAMING_CASE(normalized);
|
|
7892
|
-
normalized = normalized.split('DIALOGUE').join('DIALOG');
|
|
7893
8017
|
var items = raw
|
|
7894
8018
|
.trim()
|
|
7895
8019
|
// Note: [🐡]
|
|
@@ -7970,12 +8094,12 @@ function parseCommandVariant(input) {
|
|
|
7970
8094
|
var commandName = normalizeTo_SCREAMING_CASE(commandNameRaw);
|
|
7971
8095
|
var _loop_1 = function (commandParser) {
|
|
7972
8096
|
// <- Note: [🦦] Its strange that this type assertion is needed
|
|
7973
|
-
var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead,
|
|
8097
|
+
var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead, isUsedInPipelineTask = commandParser.isUsedInPipelineTask, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
|
|
7974
8098
|
if (just(false)) ;
|
|
7975
8099
|
else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
|
|
7976
8100
|
return "continue";
|
|
7977
8101
|
}
|
|
7978
|
-
else if (usagePlace === '
|
|
8102
|
+
else if (usagePlace === 'PIPELINE_TASK' && !isUsedInPipelineTask) {
|
|
7979
8103
|
return "continue";
|
|
7980
8104
|
}
|
|
7981
8105
|
var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
|
|
@@ -8077,7 +8201,7 @@ function extractAllListItemsFromMarkdown(markdown) {
|
|
|
8077
8201
|
function extractOneBlockFromMarkdown(markdown) {
|
|
8078
8202
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
8079
8203
|
if (codeBlocks.length !== 1) {
|
|
8080
|
-
throw new ParseError(spaceTrim(function (block) { return "\n There should be exactly 1 code block in
|
|
8204
|
+
throw new ParseError(spaceTrim(function (block) { return "\n There should be exactly 1 code block in task section, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
8081
8205
|
}
|
|
8082
8206
|
return codeBlocks[0];
|
|
8083
8207
|
}
|
|
@@ -8292,7 +8416,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8292
8416
|
description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
|
|
8293
8417
|
formfactorName: 'GENERIC',
|
|
8294
8418
|
parameters: [],
|
|
8295
|
-
|
|
8419
|
+
tasks: [],
|
|
8296
8420
|
knowledgeSources: [],
|
|
8297
8421
|
knowledgePieces: [],
|
|
8298
8422
|
personas: [],
|
|
@@ -8384,7 +8508,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8384
8508
|
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
8385
8509
|
var commandParser = getParserForCommand(command);
|
|
8386
8510
|
if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
|
|
8387
|
-
throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the head of the
|
|
8511
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the head of the pipeline ONLY at the pipeline task\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
8388
8512
|
}
|
|
8389
8513
|
try {
|
|
8390
8514
|
commandParser.$applyToPipelineJson(command, $pipelineJson);
|
|
@@ -8416,7 +8540,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8416
8540
|
}
|
|
8417
8541
|
var _loop_2 = function (section) {
|
|
8418
8542
|
var e_5, _l, e_6, _m;
|
|
8419
|
-
// TODO: Parse
|
|
8543
|
+
// TODO: Parse section's description (the content out of the codeblock and lists)
|
|
8420
8544
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
8421
8545
|
var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
|
|
8422
8546
|
// TODO: [🎾][1] DRY description
|
|
@@ -8430,10 +8554,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8430
8554
|
if (description_1 === '') {
|
|
8431
8555
|
description_1 = undefined;
|
|
8432
8556
|
}
|
|
8433
|
-
var $
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8557
|
+
var $taskJson = {
|
|
8558
|
+
isSectionTypeSet: false,
|
|
8559
|
+
isTask: true,
|
|
8560
|
+
taskType: undefined /* <- Note: [🍙] Putting here placeholder to keep `taskType` on top at final JSON */,
|
|
8437
8561
|
name: titleToName(section.title),
|
|
8438
8562
|
title: section.title,
|
|
8439
8563
|
description: description_1,
|
|
@@ -8445,35 +8569,35 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8445
8569
|
if (resultingParameterNameMatch &&
|
|
8446
8570
|
resultingParameterNameMatch.groups !== undefined &&
|
|
8447
8571
|
resultingParameterNameMatch.groups.resultingParamName !== undefined) {
|
|
8448
|
-
$
|
|
8572
|
+
$taskJson.resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
|
|
8449
8573
|
}
|
|
8450
|
-
// TODO: [🥥] Maybe move this logic to `$
|
|
8574
|
+
// TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineTaskCommands`
|
|
8451
8575
|
var commands = listItems_2.map(function (listItem) { return ({
|
|
8452
8576
|
listItem: listItem,
|
|
8453
|
-
command: parseCommand(listItem, '
|
|
8577
|
+
command: parseCommand(listItem, 'PIPELINE_TASK'),
|
|
8454
8578
|
}); });
|
|
8455
|
-
// Note: If block type is not set, set it to '
|
|
8579
|
+
// Note: If block type is not set, set it to 'PROMPT_TASK'
|
|
8456
8580
|
if (commands.some(function (_a) {
|
|
8457
8581
|
var command = _a.command;
|
|
8458
|
-
return command.type === '
|
|
8582
|
+
return command.type === 'SECTION';
|
|
8459
8583
|
}) === false) {
|
|
8460
|
-
|
|
8584
|
+
sectionCommandParser.$applyToTaskJson({ type: 'SECTION', taskType: 'PROMPT_TASK' }, $taskJson, $pipelineJson);
|
|
8461
8585
|
}
|
|
8462
8586
|
var _loop_4 = function (listItem, command) {
|
|
8463
8587
|
var commandParser = getParserForCommand(command);
|
|
8464
|
-
if (commandParser.
|
|
8465
|
-
throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the
|
|
8588
|
+
if (commandParser.isUsedInPipelineTask !== true /* <- Note: [🦦][4] */) {
|
|
8589
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the task of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
8466
8590
|
}
|
|
8467
8591
|
try {
|
|
8468
|
-
commandParser.$
|
|
8592
|
+
commandParser.$applyToTaskJson(
|
|
8469
8593
|
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
|
|
8470
|
-
command, $
|
|
8594
|
+
command, $taskJson, $pipelineJson);
|
|
8471
8595
|
}
|
|
8472
8596
|
catch (error) {
|
|
8473
8597
|
if (!(error instanceof ParseError)) {
|
|
8474
8598
|
throw error;
|
|
8475
8599
|
}
|
|
8476
|
-
throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " failed to apply to the
|
|
8600
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` failed to apply to the task\n\n The error:\n ").concat(block(error.message), "\n\n Current state of the task:\n ").concat(block(JSON.stringify($taskJson, null, 4)), "\n *<- Maybe wrong order of commands?*\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
8477
8601
|
}
|
|
8478
8602
|
if (command.type === 'PARAMETER') {
|
|
8479
8603
|
defineParam(command);
|
|
@@ -8494,22 +8618,21 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8494
8618
|
}
|
|
8495
8619
|
finally { if (e_5) throw e_5.error; }
|
|
8496
8620
|
}
|
|
8497
|
-
// TODO: [🍧] Should be done in
|
|
8498
|
-
if ($
|
|
8621
|
+
// TODO: [🍧] Should be done in SECTION command
|
|
8622
|
+
if ($taskJson.taskType === 'SCRIPT_TASK') {
|
|
8499
8623
|
if (!language) {
|
|
8500
|
-
throw new ParseError(spaceTrim$1(function (block) { return "\n You must specify the language of the script in the SCRIPT
|
|
8624
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n You must specify the language of the script in the `SCRIPT` task\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
|
|
8501
8625
|
}
|
|
8502
8626
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
8503
8627
|
throw new ParseError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
8504
8628
|
}
|
|
8505
|
-
$
|
|
8506
|
-
language;
|
|
8629
|
+
$taskJson.contentLanguage = language;
|
|
8507
8630
|
}
|
|
8508
|
-
$
|
|
8631
|
+
$taskJson.dependentParameterNames = Array.from(extractParameterNamesFromTask($taskJson));
|
|
8509
8632
|
try {
|
|
8510
|
-
for (var _q = (e_6 = void 0, __values($
|
|
8633
|
+
for (var _q = (e_6 = void 0, __values($taskJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
|
|
8511
8634
|
var parameterName = _r.value;
|
|
8512
|
-
// TODO: [🧠] This definition should be made first in the
|
|
8635
|
+
// TODO: [🧠] This definition should be made first in the task
|
|
8513
8636
|
defineParam({
|
|
8514
8637
|
parameterName: parameterName,
|
|
8515
8638
|
parameterDescription: null,
|
|
@@ -8528,13 +8651,13 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8528
8651
|
}
|
|
8529
8652
|
/*
|
|
8530
8653
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
8531
|
-
if ($
|
|
8654
|
+
if ($taskJson.taskType !== 'PROMPT_TASK' && $taskJson.modelRequirements !== undefined) {
|
|
8532
8655
|
throw new UnexpectedError(
|
|
8533
8656
|
spaceTrim(
|
|
8534
8657
|
(block) => `
|
|
8535
8658
|
Model requirements are defined for the block type ${
|
|
8536
|
-
$
|
|
8537
|
-
} which is not a PROMPT
|
|
8659
|
+
$taskJson.taskType
|
|
8660
|
+
} which is not a \`PROMPT\` task
|
|
8538
8661
|
|
|
8539
8662
|
This should be avoided by the \`modelCommandParser\`
|
|
8540
8663
|
|
|
@@ -8544,16 +8667,16 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8544
8667
|
);
|
|
8545
8668
|
}
|
|
8546
8669
|
*/
|
|
8547
|
-
if ($
|
|
8548
|
-
delete $
|
|
8549
|
-
delete $
|
|
8550
|
-
// TODO: [🍙] Maybe do reorder of `$
|
|
8551
|
-
$pipelineJson.
|
|
8670
|
+
if ($taskJson.isTask) {
|
|
8671
|
+
delete $taskJson.isSectionTypeSet;
|
|
8672
|
+
delete $taskJson.isTask;
|
|
8673
|
+
// TODO: [🍙] Maybe do reorder of `$taskJson` here
|
|
8674
|
+
$pipelineJson.tasks.push($taskJson);
|
|
8552
8675
|
}
|
|
8553
8676
|
};
|
|
8554
8677
|
try {
|
|
8555
8678
|
// =============================================================
|
|
8556
|
-
// Note: 4️⃣ Process each
|
|
8679
|
+
// Note: 4️⃣ Process each section of the pipeline
|
|
8557
8680
|
for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
8558
8681
|
var section = pipelineSections_1_1.value;
|
|
8559
8682
|
_loop_2(section);
|
|
@@ -8570,7 +8693,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8570
8693
|
// Note: 5️⃣ Mark parameters as INPUT if not explicitly set
|
|
8571
8694
|
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
|
|
8572
8695
|
var _loop_3 = function (parameter) {
|
|
8573
|
-
var isThisParameterResulting = $pipelineJson.
|
|
8696
|
+
var isThisParameterResulting = $pipelineJson.tasks.some(function (task) { return task.resultingParameterName === parameter.name; });
|
|
8574
8697
|
if (!isThisParameterResulting) {
|
|
8575
8698
|
parameter.isInput = true;
|
|
8576
8699
|
}
|
|
@@ -8610,13 +8733,13 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8610
8733
|
}
|
|
8611
8734
|
// =============================================================
|
|
8612
8735
|
// Note: 7️⃣ Cleanup of undefined values
|
|
8613
|
-
$pipelineJson.
|
|
8736
|
+
$pipelineJson.tasks.forEach(function (tasks) {
|
|
8614
8737
|
var e_7, _a;
|
|
8615
8738
|
try {
|
|
8616
|
-
for (var _b = __values(Object.entries(
|
|
8739
|
+
for (var _b = __values(Object.entries(tasks)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8617
8740
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
8618
8741
|
if (value === undefined) {
|
|
8619
|
-
delete
|
|
8742
|
+
delete tasks[key];
|
|
8620
8743
|
}
|
|
8621
8744
|
}
|
|
8622
8745
|
}
|
|
@@ -8656,7 +8779,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8656
8779
|
* TODO: Use spaceTrim more effectively
|
|
8657
8780
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
8658
8781
|
* TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
8659
|
-
* TODO: [♈] Probbably move expectations from
|
|
8782
|
+
* TODO: [♈] Probbably move expectations from tasks to parameters
|
|
8660
8783
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
8661
8784
|
* TODO: [🍙] Make some standard order of json properties
|
|
8662
8785
|
*/
|
|
@@ -8741,8 +8864,8 @@ function addAutoGeneratedSection(content, options) {
|
|
|
8741
8864
|
* @public exported from `@promptbook/utils`
|
|
8742
8865
|
*/
|
|
8743
8866
|
function renderPromptbookMermaid(pipelineJson, options) {
|
|
8744
|
-
var _a = (options || {}).
|
|
8745
|
-
var
|
|
8867
|
+
var _a = (options || {}).linkTask, linkTask = _a === void 0 ? function () { return null; } : _a;
|
|
8868
|
+
var parameterNameToTaskName = function (parameterName) {
|
|
8746
8869
|
var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
8747
8870
|
if (!parameter) {
|
|
8748
8871
|
throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
|
|
@@ -8750,19 +8873,19 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
8750
8873
|
if (parameter.isInput) {
|
|
8751
8874
|
return 'input';
|
|
8752
8875
|
}
|
|
8753
|
-
var
|
|
8754
|
-
if (!
|
|
8755
|
-
throw new Error("Could not find
|
|
8876
|
+
var task = pipelineJson.tasks.find(function (task) { return task.resultingParameterName === parameterName; });
|
|
8877
|
+
if (!task) {
|
|
8878
|
+
throw new Error("Could not find task for {".concat(parameterName, "}"));
|
|
8756
8879
|
}
|
|
8757
|
-
return normalizeTo_camelCase('
|
|
8880
|
+
return normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
8758
8881
|
};
|
|
8759
|
-
var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.
|
|
8882
|
+
var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
|
|
8760
8883
|
.flatMap(function (_a) {
|
|
8761
8884
|
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
8762
8885
|
return __spreadArray([
|
|
8763
|
-
"".concat(
|
|
8886
|
+
"".concat(parameterNameToTaskName(resultingParameterName), "(\"").concat(title, "\")")
|
|
8764
8887
|
], __read(dependentParameterNames.map(function (dependentParameterName) {
|
|
8765
|
-
return "".concat(
|
|
8888
|
+
return "".concat(parameterNameToTaskName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTaskName(resultingParameterName));
|
|
8766
8889
|
})), false);
|
|
8767
8890
|
})
|
|
8768
8891
|
.join('\n')), "\n\n ").concat(block(pipelineJson.parameters
|
|
@@ -8772,17 +8895,17 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
8772
8895
|
})
|
|
8773
8896
|
.map(function (_a) {
|
|
8774
8897
|
var name = _a.name;
|
|
8775
|
-
return "".concat(
|
|
8898
|
+
return "".concat(parameterNameToTaskName(name), "--\"{").concat(name, "}\"-->output");
|
|
8776
8899
|
})
|
|
8777
|
-
.join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.
|
|
8778
|
-
.map(function (
|
|
8779
|
-
var link =
|
|
8900
|
+
.join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.tasks
|
|
8901
|
+
.map(function (task) {
|
|
8902
|
+
var link = linkTask(task);
|
|
8780
8903
|
if (link === null) {
|
|
8781
8904
|
return '';
|
|
8782
8905
|
}
|
|
8783
8906
|
var href = link.href, title = link.title;
|
|
8784
|
-
var
|
|
8785
|
-
return "click ".concat(
|
|
8907
|
+
var taskName = parameterNameToTaskName(task.resultingParameterName);
|
|
8908
|
+
return "click ".concat(taskName, " href \"").concat(href, "\" \"").concat(title, "\";");
|
|
8786
8909
|
})
|
|
8787
8910
|
.filter(function (line) { return line !== ''; })
|
|
8788
8911
|
.join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
|
|
@@ -8813,8 +8936,8 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
8813
8936
|
case 1:
|
|
8814
8937
|
pipelineJson = _a.sent();
|
|
8815
8938
|
promptbookMermaid_1 = renderPromptbookMermaid(pipelineJson, {
|
|
8816
|
-
|
|
8817
|
-
return { href: "#".concat(
|
|
8939
|
+
linkTask: function (task) {
|
|
8940
|
+
return { href: "#".concat(task.name), title: task.title };
|
|
8818
8941
|
},
|
|
8819
8942
|
});
|
|
8820
8943
|
promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
@@ -8940,228 +9063,551 @@ function embeddingVectorToString(embeddingVector) {
|
|
|
8940
9063
|
}
|
|
8941
9064
|
|
|
8942
9065
|
/**
|
|
8943
|
-
*
|
|
8944
|
-
*
|
|
8945
|
-
* Note: This is an estimate based of theese sources:
|
|
8946
|
-
* - https://jecas.cz/doba-cteni
|
|
8947
|
-
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
9066
|
+
* Format either small or big number
|
|
8948
9067
|
*
|
|
8949
|
-
* @
|
|
9068
|
+
* @private within the repository
|
|
8950
9069
|
*/
|
|
8951
|
-
function
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
var isUncertain = usage.input.wordsCount.isUncertain || usage.output.wordsCount.isUncertain;
|
|
8955
|
-
var uncertainNumber = { value: value };
|
|
8956
|
-
if (isUncertain === true) {
|
|
8957
|
-
uncertainNumber.isUncertain = true;
|
|
9070
|
+
function formatNumber(value) {
|
|
9071
|
+
if (value === 0) {
|
|
9072
|
+
return '0';
|
|
8958
9073
|
}
|
|
8959
|
-
|
|
9074
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
9075
|
+
var factor = Math.pow(10, exponent);
|
|
9076
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
9077
|
+
if (Math.abs(value - valueRounded) / value <
|
|
9078
|
+
0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
|
|
9079
|
+
return valueRounded.toFixed(exponent);
|
|
9080
|
+
}
|
|
9081
|
+
}
|
|
9082
|
+
return value.toString();
|
|
8960
9083
|
}
|
|
8961
9084
|
|
|
8962
9085
|
/**
|
|
8963
|
-
*
|
|
9086
|
+
* Create a markdown table from a 2D array of strings
|
|
8964
9087
|
*
|
|
8965
|
-
* @public exported from `@promptbook/
|
|
9088
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
8966
9089
|
*/
|
|
8967
|
-
function
|
|
8968
|
-
var
|
|
8969
|
-
|
|
8970
|
-
|
|
8971
|
-
|
|
8972
|
-
|
|
8973
|
-
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
8978
|
-
|
|
8979
|
-
|
|
8980
|
-
}
|
|
8981
|
-
var
|
|
8982
|
-
|
|
8983
|
-
|
|
8984
|
-
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
|
|
8988
|
-
}
|
|
8989
|
-
if (usage.output.charactersCount.value > 0) {
|
|
8990
|
-
reportItems.push("Written ".concat(uncertainNumberToHuman(usage.output.charactersCount), " characters"));
|
|
8991
|
-
}
|
|
8992
|
-
if (reportItems.length === 0) {
|
|
8993
|
-
// Note: For negligible usage, we report at least something
|
|
8994
|
-
reportItems.push('Negligible');
|
|
8995
|
-
}
|
|
8996
|
-
return spaceTrim(function (block) { return "\n Usage:\n ".concat(block(reportItems.map(function (item) { return "- ".concat(item); }).join('\n')), "\n "); });
|
|
9090
|
+
function createMarkdownTable(table) {
|
|
9091
|
+
var columnWidths = table.reduce(function (widths, row) {
|
|
9092
|
+
row.forEach(function (subformat, columnIndex) {
|
|
9093
|
+
var cellLength = subformat.length;
|
|
9094
|
+
if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
|
|
9095
|
+
widths[columnIndex] = cellLength;
|
|
9096
|
+
}
|
|
9097
|
+
});
|
|
9098
|
+
return widths;
|
|
9099
|
+
}, []);
|
|
9100
|
+
var header = "| ".concat(table[0]
|
|
9101
|
+
.map(function (subformat, columnIndex) { return subformat.padEnd(columnWidths[columnIndex]); })
|
|
9102
|
+
.join(' | '), " |");
|
|
9103
|
+
var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
|
|
9104
|
+
var rows = table.slice(1).map(function (row) {
|
|
9105
|
+
var paddedRow = row.map(function (subformat, columnIndex) {
|
|
9106
|
+
return subformat.padEnd(columnWidths[columnIndex]);
|
|
9107
|
+
});
|
|
9108
|
+
return "| ".concat(paddedRow.join(' | '), " |");
|
|
9109
|
+
});
|
|
9110
|
+
return __spreadArray([header, separator], __read(rows), false).join('\n');
|
|
8997
9111
|
}
|
|
8998
9112
|
/**
|
|
8999
|
-
* TODO: [
|
|
9000
|
-
* TODO: [🍓][🧞♂️] Use markdown formatting like "Cost approximately **$1**"
|
|
9001
|
-
* TODO: [🍓][🧞♂️] Report in minutes, seconds, days NOT 0.1 hours
|
|
9002
|
-
* TODO: [🧠] Maybe make from `uncertainNumberToHuman` separate exported utility
|
|
9003
|
-
* TODO: [🧠] Maybe use "~" instead of "approximately"
|
|
9004
|
-
* TODO: [🏛] Maybe make some markdown builder
|
|
9113
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
9005
9114
|
*/
|
|
9006
9115
|
|
|
9007
9116
|
/**
|
|
9008
|
-
*
|
|
9117
|
+
* Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
|
|
9009
9118
|
*
|
|
9010
|
-
* @public exported from `@promptbook/
|
|
9119
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
9120
|
+
*/
|
|
9121
|
+
function createMarkdownChart(options) {
|
|
9122
|
+
var e_1, _a;
|
|
9123
|
+
var nameHeader = options.nameHeader, valueHeader = options.valueHeader, items = options.items, width = options.width, unitName = options.unitName;
|
|
9124
|
+
var from = Math.min.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.from; })), false));
|
|
9125
|
+
var to = Math.max.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.to; })), false));
|
|
9126
|
+
var scale = width / (to - from);
|
|
9127
|
+
var table = [[nameHeader, valueHeader]];
|
|
9128
|
+
try {
|
|
9129
|
+
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
9130
|
+
var item = items_1_1.value;
|
|
9131
|
+
var before = Math.round((item.from - from) * scale);
|
|
9132
|
+
var during = Math.round((item.to - item.from) * scale);
|
|
9133
|
+
var after = width - before - during;
|
|
9134
|
+
table.push([removeEmojis(item.title).trim(), '░'.repeat(before) + '█'.repeat(during) + '░'.repeat(after)]);
|
|
9135
|
+
}
|
|
9136
|
+
}
|
|
9137
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9138
|
+
finally {
|
|
9139
|
+
try {
|
|
9140
|
+
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
9141
|
+
}
|
|
9142
|
+
finally { if (e_1) throw e_1.error; }
|
|
9143
|
+
}
|
|
9144
|
+
var legend = "_Note: Each \u2588 represents ".concat(formatNumber(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(formatNumber(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
|
|
9145
|
+
return createMarkdownTable(table) + '\n\n' + legend;
|
|
9146
|
+
}
|
|
9147
|
+
/**
|
|
9148
|
+
* TODO: Maybe use Mermain Gant Diagrams
|
|
9149
|
+
* @see https://jojozhuang.github.io/tutorial/mermaid-cheat-sheet/
|
|
9011
9150
|
*/
|
|
9012
|
-
var BoilerplateFormfactorDefinition = {
|
|
9013
|
-
name: 'BOILERPLATE',
|
|
9014
|
-
description: "@@@",
|
|
9015
|
-
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@",
|
|
9016
|
-
pipelineInterface: {
|
|
9017
|
-
inputParameterNames: [],
|
|
9018
|
-
outputParameterNames: [],
|
|
9019
|
-
},
|
|
9020
|
-
};
|
|
9021
9151
|
|
|
9022
9152
|
/**
|
|
9023
|
-
*
|
|
9153
|
+
* Function escapeMarkdownBlock will escape markdown block if needed
|
|
9154
|
+
* It is useful when you want have block in block
|
|
9024
9155
|
*
|
|
9025
|
-
*
|
|
9026
|
-
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
9027
|
-
* @public exported from `@promptbook/core`
|
|
9156
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
9028
9157
|
*/
|
|
9029
|
-
|
|
9158
|
+
function escapeMarkdownBlock(value) {
|
|
9159
|
+
return value.replace(/```/g, '\\`\\`\\`');
|
|
9160
|
+
}
|
|
9030
9161
|
/**
|
|
9031
|
-
* TODO: [
|
|
9162
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
9032
9163
|
*/
|
|
9033
9164
|
|
|
9034
9165
|
/**
|
|
9035
|
-
*
|
|
9166
|
+
* Default options for generating an execution report string
|
|
9036
9167
|
*
|
|
9037
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
9038
|
-
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
9039
9168
|
* @public exported from `@promptbook/core`
|
|
9040
9169
|
*/
|
|
9041
|
-
var
|
|
9042
|
-
|
|
9043
|
-
|
|
9044
|
-
|
|
9170
|
+
var ExecutionReportStringOptionsDefaults = {
|
|
9171
|
+
taxRate: 0,
|
|
9172
|
+
chartsWidth: 36,
|
|
9173
|
+
};
|
|
9045
9174
|
|
|
9046
9175
|
/**
|
|
9047
|
-
*
|
|
9048
|
-
*
|
|
9049
|
-
* Note: This function is used to create a (error) message when there is no constructor for some LLM provider
|
|
9176
|
+
* Count the duration of working time
|
|
9050
9177
|
*
|
|
9051
|
-
* @private
|
|
9178
|
+
* @private within the repository
|
|
9052
9179
|
*/
|
|
9053
|
-
function
|
|
9054
|
-
var e_1, _a
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
var
|
|
9059
|
-
var _loop_1 = function (
|
|
9060
|
-
|
|
9061
|
-
|
|
9180
|
+
function countWorkingDuration(items) {
|
|
9181
|
+
var e_1, _a;
|
|
9182
|
+
var steps = Array.from(new Set(items.flatMap(function (item) { return [item.from, item.to]; })));
|
|
9183
|
+
steps.sort(function (a, b) { return a - b; });
|
|
9184
|
+
var intervals = steps.map(function (step, index) { return [step, steps[index + 1] || 0]; }).slice(0, -1);
|
|
9185
|
+
var duration = 0;
|
|
9186
|
+
var _loop_1 = function (interval) {
|
|
9187
|
+
var _b = __read(interval, 2), from = _b[0], to = _b[1];
|
|
9188
|
+
if (items.some(function (item) { return item.from < to && item.to > from; })) {
|
|
9189
|
+
duration += to - from;
|
|
9062
9190
|
}
|
|
9063
|
-
all.push({ packageName: packageName, className: className });
|
|
9064
9191
|
};
|
|
9065
9192
|
try {
|
|
9066
|
-
for (var
|
|
9067
|
-
var
|
|
9068
|
-
_loop_1(
|
|
9193
|
+
for (var intervals_1 = __values(intervals), intervals_1_1 = intervals_1.next(); !intervals_1_1.done; intervals_1_1 = intervals_1.next()) {
|
|
9194
|
+
var interval = intervals_1_1.value;
|
|
9195
|
+
_loop_1(interval);
|
|
9069
9196
|
}
|
|
9070
9197
|
}
|
|
9071
9198
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9072
9199
|
finally {
|
|
9073
9200
|
try {
|
|
9074
|
-
if (
|
|
9201
|
+
if (intervals_1_1 && !intervals_1_1.done && (_a = intervals_1.return)) _a.call(intervals_1);
|
|
9075
9202
|
}
|
|
9076
9203
|
finally { if (e_1) throw e_1.error; }
|
|
9077
9204
|
}
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
}
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
}
|
|
9095
|
-
finally { if (e_2) throw e_2.error; }
|
|
9205
|
+
return duration;
|
|
9206
|
+
}
|
|
9207
|
+
|
|
9208
|
+
/**
|
|
9209
|
+
* Converts execution report from JSON to string format
|
|
9210
|
+
*
|
|
9211
|
+
* @public exported from `@promptbook/core`
|
|
9212
|
+
*/
|
|
9213
|
+
function executionReportJsonToString(executionReportJson, options) {
|
|
9214
|
+
var e_1, _a;
|
|
9215
|
+
var _b, _c, _d, _e, _f, _g;
|
|
9216
|
+
var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
|
|
9217
|
+
var executionReportString = spaceTrim$1(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
9218
|
+
var headerList = [];
|
|
9219
|
+
if (executionReportJson.pipelineUrl) {
|
|
9220
|
+
headerList.push("PIPELINE URL ".concat(executionReportJson.pipelineUrl));
|
|
9096
9221
|
}
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
.
|
|
9101
|
-
|
|
9102
|
-
|
|
9222
|
+
headerList.push("PROMPTBOOK VERSION ".concat(executionReportJson.promptbookUsedVersion) +
|
|
9223
|
+
(!executionReportJson.promptbookRequestedVersion
|
|
9224
|
+
? ''
|
|
9225
|
+
: " *(requested ".concat(executionReportJson.promptbookRequestedVersion, ")*")));
|
|
9226
|
+
if (executionReportJson.promptExecutions.length !== 0) {
|
|
9227
|
+
// TODO: What if startedAt OR/AND completedAt is not defined?
|
|
9228
|
+
var startedAt = moment(Math.min.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
|
|
9229
|
+
.filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start; })
|
|
9230
|
+
.map(function (promptExecution) { return moment(promptExecution.result.timing.start).valueOf(); })), false)));
|
|
9231
|
+
var completedAt = moment(Math.max.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
|
|
9232
|
+
.filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.complete; })
|
|
9233
|
+
.map(function (promptExecution) { return moment(promptExecution.result.timing.complete).valueOf(); })), false)));
|
|
9234
|
+
var timingItems = executionReportJson.promptExecutions.map(function (promptExecution) {
|
|
9235
|
+
var _a, _b, _c, _d;
|
|
9236
|
+
return ({
|
|
9237
|
+
title: promptExecution.prompt.title,
|
|
9238
|
+
from: moment((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start).valueOf() / 1000,
|
|
9239
|
+
to: moment((_d = (_c = promptExecution.result) === null || _c === void 0 ? void 0 : _c.timing) === null || _d === void 0 ? void 0 : _d.complete).valueOf() / 1000,
|
|
9240
|
+
});
|
|
9103
9241
|
});
|
|
9104
|
-
var
|
|
9105
|
-
.
|
|
9106
|
-
.
|
|
9107
|
-
var
|
|
9108
|
-
return
|
|
9242
|
+
var costItems = executionReportJson.promptExecutions
|
|
9243
|
+
.filter(function (promptExecution) { var _a, _b; return typeof ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) === 'number'; })
|
|
9244
|
+
.map(function (promptExecution) {
|
|
9245
|
+
var _a, _b;
|
|
9246
|
+
return ({
|
|
9247
|
+
title: promptExecution.prompt.title,
|
|
9248
|
+
from: 0,
|
|
9249
|
+
to: (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price.value) || 0) /* <- TODO: look at uncertain numbers */ *
|
|
9250
|
+
(1 + taxRate),
|
|
9251
|
+
});
|
|
9109
9252
|
});
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9253
|
+
var duration = moment.duration(completedAt.diff(startedAt));
|
|
9254
|
+
var llmDuration = moment.duration(countWorkingDuration(timingItems) * 1000);
|
|
9255
|
+
var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
|
|
9256
|
+
var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) {
|
|
9257
|
+
return cost + (promptExecution.result.usage.price.value /* <- Look at uncertain number */ || 0);
|
|
9258
|
+
}, 0);
|
|
9259
|
+
headerList.push("STARTED AT ".concat(moment(startedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
9260
|
+
headerList.push("COMPLETED AT ".concat(moment(completedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
9261
|
+
headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
9262
|
+
headerList.push("TOTAL LLM DURATION ".concat(llmDuration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
9263
|
+
headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
|
|
9264
|
+
(executionsWithKnownCost.length === executionReportJson.promptExecutions.length
|
|
9265
|
+
? ''
|
|
9266
|
+
: " *(Some cost is unknown)*") +
|
|
9267
|
+
(taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
|
|
9268
|
+
executionReportString += '\n\n' + headerList.map(function (header) { return "- ".concat(header); }).join('\n');
|
|
9269
|
+
executionReportString +=
|
|
9270
|
+
'\n\n' +
|
|
9271
|
+
'## 🗃 Index' +
|
|
9272
|
+
'\n\n' +
|
|
9273
|
+
executionReportJson.promptExecutions
|
|
9274
|
+
.map(function (promptExecution) {
|
|
9275
|
+
// TODO: Make some better system to convert hedings to links
|
|
9276
|
+
var hash = normalizeToKebabCase(promptExecution.prompt.title);
|
|
9277
|
+
if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
|
|
9278
|
+
hash = '-' + hash;
|
|
9279
|
+
}
|
|
9280
|
+
// TODO: Make working hash link for the task in md + pdf
|
|
9281
|
+
return "- [".concat(promptExecution.prompt.title, "](#").concat(hash, ")");
|
|
9282
|
+
})
|
|
9283
|
+
.join('\n');
|
|
9284
|
+
executionReportString +=
|
|
9285
|
+
'\n\n' +
|
|
9286
|
+
'## ⌚ Time chart' +
|
|
9287
|
+
'\n\n' +
|
|
9288
|
+
createMarkdownChart({
|
|
9289
|
+
nameHeader: 'Task',
|
|
9290
|
+
valueHeader: 'Timeline',
|
|
9291
|
+
items: timingItems,
|
|
9292
|
+
width: chartsWidth,
|
|
9293
|
+
unitName: 'seconds',
|
|
9294
|
+
});
|
|
9295
|
+
executionReportString +=
|
|
9296
|
+
'\n\n' +
|
|
9297
|
+
'## 💸 Cost chart' +
|
|
9298
|
+
'\n\n' +
|
|
9299
|
+
createMarkdownChart({
|
|
9300
|
+
nameHeader: 'Task',
|
|
9301
|
+
valueHeader: 'Cost',
|
|
9302
|
+
items: costItems,
|
|
9303
|
+
width: chartsWidth,
|
|
9304
|
+
unitName: 'USD',
|
|
9305
|
+
});
|
|
9114
9306
|
}
|
|
9115
|
-
|
|
9116
|
-
.
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9307
|
+
else {
|
|
9308
|
+
headerList.push("TOTAL COST $0 *(Nothing executed)*");
|
|
9309
|
+
}
|
|
9310
|
+
var _loop_1 = function (promptExecution) {
|
|
9311
|
+
executionReportString += '\n\n\n\n' + "## ".concat(promptExecution.prompt.title);
|
|
9312
|
+
var taskList = [];
|
|
9313
|
+
// TODO: What if startedAt OR/AND completedAt is not defined?
|
|
9314
|
+
var startedAt = moment((_c = (_b = promptExecution.result) === null || _b === void 0 ? void 0 : _b.timing) === null || _c === void 0 ? void 0 : _c.start);
|
|
9315
|
+
var completedAt = moment((_e = (_d = promptExecution.result) === null || _d === void 0 ? void 0 : _d.timing) === null || _e === void 0 ? void 0 : _e.complete);
|
|
9316
|
+
var duration = moment.duration(completedAt.diff(startedAt));
|
|
9317
|
+
// Not need here:
|
|
9318
|
+
// > taskList.push(`STARTED AT ${moment(startedAt).calendar()}`);
|
|
9319
|
+
taskList.push("DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
9320
|
+
if (typeof ((_g = (_f = promptExecution.result) === null || _f === void 0 ? void 0 : _f.usage) === null || _g === void 0 ? void 0 : _g.price) === 'number') {
|
|
9321
|
+
taskList.push("COST $".concat(formatNumber(promptExecution.result.usage.price * (1 + taxRate))) +
|
|
9322
|
+
(taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
|
|
9121
9323
|
}
|
|
9122
|
-
else
|
|
9123
|
-
|
|
9124
|
-
more = "(not installed and no metadata, looks like a unexpected behavior)";
|
|
9324
|
+
else {
|
|
9325
|
+
taskList.push("COST UNKNOWN");
|
|
9125
9326
|
}
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9327
|
+
executionReportString += '\n\n' + taskList.map(function (header) { return "- ".concat(header); }).join('\n');
|
|
9328
|
+
/*
|
|
9329
|
+
- MODEL VARIANT ${promptExecution.prompt.modelRequirements.modelVariant}
|
|
9330
|
+
- MODEL NAME \`${promptExecution.result?.model}\` (requested \`${
|
|
9331
|
+
promptExecution.prompt.modelRequirements.modelName
|
|
9332
|
+
|
|
9333
|
+
*/
|
|
9334
|
+
if (just(true)) {
|
|
9335
|
+
executionReportString +=
|
|
9336
|
+
'\n\n\n\n' +
|
|
9337
|
+
spaceTrim$1(function (block) {
|
|
9338
|
+
var _a;
|
|
9339
|
+
return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(((_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.rawPromptContent) || promptExecution.prompt.content)), "\n ```\n\n ");
|
|
9340
|
+
});
|
|
9129
9341
|
}
|
|
9130
|
-
|
|
9131
|
-
|
|
9342
|
+
if (promptExecution.result && promptExecution.result.content) {
|
|
9343
|
+
executionReportString += '\n\n\n\n' + '### Result' + '\n\n';
|
|
9344
|
+
if (promptExecution.result === undefined) {
|
|
9345
|
+
executionReportString += '*No result*';
|
|
9346
|
+
}
|
|
9347
|
+
else if (typeof promptExecution.result.content === 'string') {
|
|
9348
|
+
executionReportString += spaceTrim$1(function (block) { return "\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
|
|
9349
|
+
}
|
|
9350
|
+
else {
|
|
9351
|
+
executionReportString += embeddingVectorToString(promptExecution.result.content);
|
|
9352
|
+
}
|
|
9132
9353
|
}
|
|
9133
|
-
|
|
9134
|
-
|
|
9354
|
+
if (promptExecution.error && promptExecution.error.message) {
|
|
9355
|
+
executionReportString +=
|
|
9356
|
+
'\n\n\n\n' +
|
|
9357
|
+
spaceTrim$1(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
|
|
9135
9358
|
}
|
|
9136
|
-
|
|
9137
|
-
|
|
9359
|
+
};
|
|
9360
|
+
try {
|
|
9361
|
+
for (var _j = __values(executionReportJson.promptExecutions), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
9362
|
+
var promptExecution = _k.value;
|
|
9363
|
+
_loop_1(promptExecution);
|
|
9138
9364
|
}
|
|
9139
|
-
|
|
9140
|
-
}
|
|
9141
|
-
|
|
9365
|
+
}
|
|
9366
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9367
|
+
finally {
|
|
9368
|
+
try {
|
|
9369
|
+
if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
|
|
9370
|
+
}
|
|
9371
|
+
finally { if (e_1) throw e_1.error; }
|
|
9372
|
+
}
|
|
9373
|
+
executionReportString = prettifyMarkdown(executionReportString);
|
|
9374
|
+
return executionReportString;
|
|
9142
9375
|
}
|
|
9143
9376
|
/**
|
|
9144
|
-
* TODO:
|
|
9377
|
+
* TODO: Add mermaid chart for every report
|
|
9378
|
+
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
9379
|
+
* TODO: [🧠] Should be in generated file GENERATOR_WARNING
|
|
9145
9380
|
*/
|
|
9146
9381
|
|
|
9147
9382
|
/**
|
|
9148
|
-
*
|
|
9383
|
+
* Function usageToWorktime will take usage and estimate saved worktime in hours of reading / writing
|
|
9149
9384
|
*
|
|
9150
|
-
* Note: This
|
|
9385
|
+
* Note: This is an estimate based of theese sources:
|
|
9386
|
+
* - https://jecas.cz/doba-cteni
|
|
9387
|
+
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
9151
9388
|
*
|
|
9152
|
-
* @returns @@@
|
|
9153
9389
|
* @public exported from `@promptbook/core`
|
|
9154
9390
|
*/
|
|
9155
|
-
function
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
var
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9391
|
+
function usageToWorktime(usage) {
|
|
9392
|
+
var value = usage.input.wordsCount.value / (200 /* words per minute */ * 60) +
|
|
9393
|
+
usage.output.wordsCount.value / (40 /* words per minute */ * 60);
|
|
9394
|
+
var isUncertain = usage.input.wordsCount.isUncertain || usage.output.wordsCount.isUncertain;
|
|
9395
|
+
var uncertainNumber = { value: value };
|
|
9396
|
+
if (isUncertain === true) {
|
|
9397
|
+
uncertainNumber.isUncertain = true;
|
|
9398
|
+
}
|
|
9399
|
+
return uncertainNumber;
|
|
9400
|
+
}
|
|
9401
|
+
|
|
9402
|
+
/**
|
|
9403
|
+
* Function `usageToHuman` will take usage and convert it to human readable report
|
|
9404
|
+
*
|
|
9405
|
+
* @public exported from `@promptbook/core`
|
|
9406
|
+
*/
|
|
9407
|
+
function usageToHuman(usage) {
|
|
9408
|
+
var reportItems = [];
|
|
9409
|
+
var uncertainNumberToHuman = function (_a) {
|
|
9410
|
+
var value = _a.value, isUncertain = _a.isUncertain;
|
|
9411
|
+
return "".concat(isUncertain ? 'approximately ' : '').concat(Math.round(value * 100) / 100);
|
|
9412
|
+
};
|
|
9413
|
+
if (usage.price.value > 0.01
|
|
9414
|
+
// <- TODO: [🍓][🧞♂️][👩🏽🤝🧑🏻] Configure negligible value - default value to config + value to `UsageToHumanSettings`
|
|
9415
|
+
) {
|
|
9416
|
+
reportItems.push("Cost ".concat(uncertainNumberToHuman(usage.price), " USD"));
|
|
9417
|
+
}
|
|
9418
|
+
else {
|
|
9419
|
+
reportItems.push("Negligible cost");
|
|
9420
|
+
}
|
|
9421
|
+
var worktime = usageToWorktime(usage);
|
|
9422
|
+
if (worktime.value >
|
|
9423
|
+
1 / 60
|
|
9424
|
+
// <- TODO: [🍓][🧞♂️][👩🏽🤝🧑🏻]
|
|
9425
|
+
) {
|
|
9426
|
+
reportItems.push("Saved ".concat(uncertainNumberToHuman(usageToWorktime(usage)), " hours of human time"));
|
|
9427
|
+
// TODO: [🍓][🧞♂️] Show minutes, seconds, days NOT 0.1 hours
|
|
9428
|
+
}
|
|
9429
|
+
if (usage.output.charactersCount.value > 0) {
|
|
9430
|
+
reportItems.push("Written ".concat(uncertainNumberToHuman(usage.output.charactersCount), " characters"));
|
|
9431
|
+
}
|
|
9432
|
+
if (reportItems.length === 0) {
|
|
9433
|
+
// Note: For negligible usage, we report at least something
|
|
9434
|
+
reportItems.push('Negligible');
|
|
9435
|
+
}
|
|
9436
|
+
return spaceTrim(function (block) { return "\n Usage:\n ".concat(block(reportItems.map(function (item) { return "- ".concat(item); }).join('\n')), "\n "); });
|
|
9437
|
+
}
|
|
9438
|
+
/**
|
|
9439
|
+
* TODO: [🍓][🧞♂️] Use "$1" not "1 USD"
|
|
9440
|
+
* TODO: [🍓][🧞♂️] Use markdown formatting like "Cost approximately **$1**"
|
|
9441
|
+
* TODO: [🍓][🧞♂️] Report in minutes, seconds, days NOT 0.1 hours
|
|
9442
|
+
* TODO: [🧠] Maybe make from `uncertainNumberToHuman` separate exported utility
|
|
9443
|
+
* TODO: [🧠] Maybe use "~" instead of "approximately"
|
|
9444
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
9445
|
+
*/
|
|
9446
|
+
|
|
9447
|
+
/**
|
|
9448
|
+
* Boilerplate is form of app that @@@
|
|
9449
|
+
*
|
|
9450
|
+
* @public exported from `@promptbook/core`
|
|
9451
|
+
*/
|
|
9452
|
+
var BoilerplateFormfactorDefinition = {
|
|
9453
|
+
name: 'BOILERPLATE',
|
|
9454
|
+
description: "@@@",
|
|
9455
|
+
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@",
|
|
9456
|
+
// <- TODO: https://github.com/webgptorg/promptbook/discussions/new?category=concepts
|
|
9457
|
+
// "🔠 Boilerplate Formfactor"
|
|
9458
|
+
pipelineInterface: {
|
|
9459
|
+
inputParameters: [
|
|
9460
|
+
/* @@@ */
|
|
9461
|
+
],
|
|
9462
|
+
outputParameters: [
|
|
9463
|
+
/* @@@ */
|
|
9464
|
+
],
|
|
9465
|
+
},
|
|
9466
|
+
};
|
|
9467
|
+
|
|
9468
|
+
/**
|
|
9469
|
+
* @@@
|
|
9470
|
+
*
|
|
9471
|
+
* Note: `$` is used to indicate that this interacts with the global scope
|
|
9472
|
+
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
9473
|
+
* @public exported from `@promptbook/core`
|
|
9474
|
+
*/
|
|
9475
|
+
var $llmToolsMetadataRegister = new $Register('llm_tools_metadata');
|
|
9476
|
+
/**
|
|
9477
|
+
* TODO: [®] DRY Register logic
|
|
9478
|
+
*/
|
|
9479
|
+
|
|
9480
|
+
/**
|
|
9481
|
+
* @@@
|
|
9482
|
+
*
|
|
9483
|
+
* Note: `$` is used to indicate that this interacts with the global scope
|
|
9484
|
+
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
9485
|
+
* @public exported from `@promptbook/core`
|
|
9486
|
+
*/
|
|
9487
|
+
var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
|
|
9488
|
+
/**
|
|
9489
|
+
* TODO: [®] DRY Register logic
|
|
9490
|
+
*/
|
|
9491
|
+
|
|
9492
|
+
/**
|
|
9493
|
+
* Creates a message with all registered LLM tools
|
|
9494
|
+
*
|
|
9495
|
+
* Note: This function is used to create a (error) message when there is no constructor for some LLM provider
|
|
9496
|
+
*
|
|
9497
|
+
* @private internal function of `createLlmToolsFromConfiguration` and `$provideLlmToolsFromEnv`
|
|
9498
|
+
*/
|
|
9499
|
+
function $registeredLlmToolsMessage() {
|
|
9500
|
+
var e_1, _a, e_2, _b;
|
|
9501
|
+
/**
|
|
9502
|
+
* Mixes registered LLM tools from $llmToolsMetadataRegister and $llmToolsRegister
|
|
9503
|
+
*/
|
|
9504
|
+
var all = [];
|
|
9505
|
+
var _loop_1 = function (packageName, className) {
|
|
9506
|
+
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
9507
|
+
return "continue";
|
|
9508
|
+
}
|
|
9509
|
+
all.push({ packageName: packageName, className: className });
|
|
9510
|
+
};
|
|
9511
|
+
try {
|
|
9512
|
+
for (var _c = __values($llmToolsMetadataRegister.list()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
9513
|
+
var _e = _d.value, packageName = _e.packageName, className = _e.className;
|
|
9514
|
+
_loop_1(packageName, className);
|
|
9515
|
+
}
|
|
9516
|
+
}
|
|
9517
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9518
|
+
finally {
|
|
9519
|
+
try {
|
|
9520
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
9521
|
+
}
|
|
9522
|
+
finally { if (e_1) throw e_1.error; }
|
|
9523
|
+
}
|
|
9524
|
+
var _loop_2 = function (packageName, className) {
|
|
9525
|
+
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
9526
|
+
return "continue";
|
|
9527
|
+
}
|
|
9528
|
+
all.push({ packageName: packageName, className: className });
|
|
9529
|
+
};
|
|
9530
|
+
try {
|
|
9531
|
+
for (var _f = __values($llmToolsRegister.list()), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
9532
|
+
var _h = _g.value, packageName = _h.packageName, className = _h.className;
|
|
9533
|
+
_loop_2(packageName, className);
|
|
9534
|
+
}
|
|
9535
|
+
}
|
|
9536
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
9537
|
+
finally {
|
|
9538
|
+
try {
|
|
9539
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
9540
|
+
}
|
|
9541
|
+
finally { if (e_2) throw e_2.error; }
|
|
9542
|
+
}
|
|
9543
|
+
var metadata = all.map(function (metadata) {
|
|
9544
|
+
var isMetadataAviailable = $llmToolsMetadataRegister
|
|
9545
|
+
.list()
|
|
9546
|
+
.find(function (_a) {
|
|
9547
|
+
var packageName = _a.packageName, className = _a.className;
|
|
9548
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
9549
|
+
});
|
|
9550
|
+
var isInstalled = $llmToolsRegister
|
|
9551
|
+
.list()
|
|
9552
|
+
.find(function (_a) {
|
|
9553
|
+
var packageName = _a.packageName, className = _a.className;
|
|
9554
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
9555
|
+
});
|
|
9556
|
+
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
|
|
9557
|
+
});
|
|
9558
|
+
if (metadata.length === 0) {
|
|
9559
|
+
return "No LLM providers are available.";
|
|
9560
|
+
}
|
|
9561
|
+
return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
|
|
9562
|
+
.map(function (_a, i) {
|
|
9563
|
+
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
|
|
9564
|
+
var more;
|
|
9565
|
+
if (just(false)) {
|
|
9566
|
+
more = '';
|
|
9567
|
+
}
|
|
9568
|
+
else if (!isMetadataAviailable && !isInstalled) {
|
|
9569
|
+
// TODO: [�][�] Maybe do allow to do auto-install if package not registered and not found
|
|
9570
|
+
more = "(not installed and no metadata, looks like a unexpected behavior)";
|
|
9571
|
+
}
|
|
9572
|
+
else if (isMetadataAviailable && !isInstalled) {
|
|
9573
|
+
// TODO: [�][�]
|
|
9574
|
+
more = "(not installed)";
|
|
9575
|
+
}
|
|
9576
|
+
else if (!isMetadataAviailable && isInstalled) {
|
|
9577
|
+
more = "(no metadata, looks like a unexpected behavior)";
|
|
9578
|
+
}
|
|
9579
|
+
else if (isMetadataAviailable && isInstalled) {
|
|
9580
|
+
more = "(installed)";
|
|
9581
|
+
}
|
|
9582
|
+
else {
|
|
9583
|
+
more = "(unknown state, looks like a unexpected behavior)";
|
|
9584
|
+
}
|
|
9585
|
+
return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` ").concat(more);
|
|
9586
|
+
})
|
|
9587
|
+
.join('\n')), "\n "); });
|
|
9588
|
+
}
|
|
9589
|
+
/**
|
|
9590
|
+
* TODO: [®] DRY Register logic
|
|
9591
|
+
*/
|
|
9592
|
+
|
|
9593
|
+
/**
|
|
9594
|
+
* @@@
|
|
9595
|
+
*
|
|
9596
|
+
* Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
|
|
9597
|
+
*
|
|
9598
|
+
* @returns @@@
|
|
9599
|
+
* @public exported from `@promptbook/core`
|
|
9600
|
+
*/
|
|
9601
|
+
function createLlmToolsFromConfiguration(configuration, options) {
|
|
9602
|
+
if (options === void 0) { options = {}; }
|
|
9603
|
+
var _a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a, userId = options.userId;
|
|
9604
|
+
var llmTools = configuration.map(function (llmConfiguration) {
|
|
9605
|
+
var registeredItem = $llmToolsRegister
|
|
9606
|
+
.list()
|
|
9607
|
+
.find(function (_a) {
|
|
9608
|
+
var packageName = _a.packageName, className = _a.className;
|
|
9609
|
+
return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
|
|
9610
|
+
});
|
|
9165
9611
|
if (registeredItem === undefined) {
|
|
9166
9612
|
throw new Error(spaceTrim(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
|
|
9167
9613
|
}
|
|
@@ -9445,6 +9891,9 @@ var _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
9445
9891
|
return null;
|
|
9446
9892
|
},
|
|
9447
9893
|
});
|
|
9894
|
+
/**
|
|
9895
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
9896
|
+
*/
|
|
9448
9897
|
|
|
9449
9898
|
/**
|
|
9450
9899
|
* Registration of LLM provider metadata
|
|
@@ -9492,6 +9941,9 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
9492
9941
|
return null;
|
|
9493
9942
|
},
|
|
9494
9943
|
});
|
|
9944
|
+
/**
|
|
9945
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
9946
|
+
*/
|
|
9495
9947
|
|
|
9496
9948
|
/**
|
|
9497
9949
|
* Registration of LLM provider metadata
|
|
@@ -9572,27 +10024,32 @@ var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
9572
10024
|
*/
|
|
9573
10025
|
},
|
|
9574
10026
|
});
|
|
10027
|
+
/**
|
|
10028
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10029
|
+
*/
|
|
9575
10030
|
|
|
9576
10031
|
/**
|
|
9577
10032
|
* @@@
|
|
9578
10033
|
*
|
|
10034
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
10035
|
+
*
|
|
9579
10036
|
* @public exported from `@promptbook/core`
|
|
9580
10037
|
*/
|
|
9581
10038
|
function getPipelineInterface(pipeline) {
|
|
9582
10039
|
var e_1, _a, e_2, _b;
|
|
9583
10040
|
var pipelineInterface = {
|
|
9584
|
-
|
|
9585
|
-
|
|
10041
|
+
inputParameters: [],
|
|
10042
|
+
outputParameters: [],
|
|
9586
10043
|
};
|
|
9587
10044
|
try {
|
|
9588
10045
|
for (var _c = __values(pipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
9589
10046
|
var parameter = _d.value;
|
|
9590
|
-
var
|
|
10047
|
+
var isInput = parameter.isInput, isOutput = parameter.isOutput;
|
|
9591
10048
|
if (isInput) {
|
|
9592
|
-
pipelineInterface.
|
|
10049
|
+
pipelineInterface.inputParameters.push(parameter);
|
|
9593
10050
|
}
|
|
9594
10051
|
if (isOutput) {
|
|
9595
|
-
pipelineInterface.
|
|
10052
|
+
pipelineInterface.outputParameters.push(parameter);
|
|
9596
10053
|
}
|
|
9597
10054
|
}
|
|
9598
10055
|
}
|
|
@@ -9604,9 +10061,15 @@ function getPipelineInterface(pipeline) {
|
|
|
9604
10061
|
finally { if (e_1) throw e_1.error; }
|
|
9605
10062
|
}
|
|
9606
10063
|
try {
|
|
9607
|
-
for (var _e = __values(['
|
|
10064
|
+
for (var _e = __values(['inputParameters', 'outputParameters']), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
9608
10065
|
var key = _f.value;
|
|
9609
|
-
pipelineInterface[key].sort(function (
|
|
10066
|
+
pipelineInterface[key].sort(function (_a, _b) {
|
|
10067
|
+
var name1 = _a.name;
|
|
10068
|
+
var name2 = _b.name;
|
|
10069
|
+
return name1.localeCompare(name2);
|
|
10070
|
+
});
|
|
10071
|
+
// <- TODO: [🧠] Should we compare a descriptions?
|
|
10072
|
+
// <- TODO: [🧠][🛴] Maybe add type + expectations into the intefrace, like "a person name"
|
|
9610
10073
|
}
|
|
9611
10074
|
}
|
|
9612
10075
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -9625,6 +10088,8 @@ function getPipelineInterface(pipeline) {
|
|
|
9625
10088
|
/**
|
|
9626
10089
|
* @@@
|
|
9627
10090
|
*
|
|
10091
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
10092
|
+
*
|
|
9628
10093
|
* @public exported from `@promptbook/core`
|
|
9629
10094
|
*/
|
|
9630
10095
|
function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
|
|
@@ -9639,6 +10104,8 @@ function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
|
|
|
9639
10104
|
/**
|
|
9640
10105
|
* @@@
|
|
9641
10106
|
*
|
|
10107
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
10108
|
+
*
|
|
9642
10109
|
* @public exported from `@promptbook/core`
|
|
9643
10110
|
*/
|
|
9644
10111
|
function isPipelineImplementingInterface(options) {
|
|
@@ -9677,6 +10144,9 @@ var legacyDocumentScraperMetadata = $deepFreeze({
|
|
|
9677
10144
|
* @public exported from `@promptbook/cli`
|
|
9678
10145
|
*/
|
|
9679
10146
|
var _LegacyDocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
|
|
10147
|
+
/**
|
|
10148
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10149
|
+
*/
|
|
9680
10150
|
|
|
9681
10151
|
/**
|
|
9682
10152
|
* Metadata of the scraper
|
|
@@ -9701,6 +10171,9 @@ var documentScraperMetadata = $deepFreeze({
|
|
|
9701
10171
|
* @public exported from `@promptbook/cli`
|
|
9702
10172
|
*/
|
|
9703
10173
|
var _DocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(documentScraperMetadata);
|
|
10174
|
+
/**
|
|
10175
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10176
|
+
*/
|
|
9704
10177
|
|
|
9705
10178
|
/**
|
|
9706
10179
|
* Metadata of the scraper
|
|
@@ -9725,6 +10198,9 @@ var markdownScraperMetadata = $deepFreeze({
|
|
|
9725
10198
|
* @public exported from `@promptbook/cli`
|
|
9726
10199
|
*/
|
|
9727
10200
|
var _MarkdownScraperMetadataRegistration = $scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
10201
|
+
/**
|
|
10202
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10203
|
+
*/
|
|
9728
10204
|
|
|
9729
10205
|
/**
|
|
9730
10206
|
* Metadata of the scraper
|
|
@@ -9749,6 +10225,9 @@ var pdfScraperMetadata = $deepFreeze({
|
|
|
9749
10225
|
* @public exported from `@promptbook/cli`
|
|
9750
10226
|
*/
|
|
9751
10227
|
var _PdfScraperMetadataRegistration = $scrapersMetadataRegister.register(pdfScraperMetadata);
|
|
10228
|
+
/**
|
|
10229
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10230
|
+
*/
|
|
9752
10231
|
|
|
9753
10232
|
/**
|
|
9754
10233
|
* Metadata of the scraper
|
|
@@ -9773,6 +10252,9 @@ var websiteScraperMetadata = $deepFreeze({
|
|
|
9773
10252
|
* @public exported from `@promptbook/cli`
|
|
9774
10253
|
*/
|
|
9775
10254
|
var _WebsiteScraperMetadataRegistration = $scrapersMetadataRegister.register(websiteScraperMetadata);
|
|
10255
|
+
/**
|
|
10256
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10257
|
+
*/
|
|
9776
10258
|
|
|
9777
10259
|
/**
|
|
9778
10260
|
* Behaves like a storage but forgets everything you put in it
|
|
@@ -9855,322 +10337,5 @@ var PrefixStorage = /** @class */ (function () {
|
|
|
9855
10337
|
return PrefixStorage;
|
|
9856
10338
|
}());
|
|
9857
10339
|
|
|
9858
|
-
|
|
9859
|
-
* Format either small or big number
|
|
9860
|
-
*
|
|
9861
|
-
* @private within the repository
|
|
9862
|
-
*/
|
|
9863
|
-
function formatNumber(value) {
|
|
9864
|
-
if (value === 0) {
|
|
9865
|
-
return '0';
|
|
9866
|
-
}
|
|
9867
|
-
for (var exponent = 0; exponent < 15; exponent++) {
|
|
9868
|
-
var factor = Math.pow(10, exponent);
|
|
9869
|
-
var valueRounded = Math.round(value * factor) / factor;
|
|
9870
|
-
if (Math.abs(value - valueRounded) / value <
|
|
9871
|
-
0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
|
|
9872
|
-
return valueRounded.toFixed(exponent);
|
|
9873
|
-
}
|
|
9874
|
-
}
|
|
9875
|
-
return value.toString();
|
|
9876
|
-
}
|
|
9877
|
-
|
|
9878
|
-
/**
|
|
9879
|
-
* Create a markdown table from a 2D array of strings
|
|
9880
|
-
*
|
|
9881
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
9882
|
-
*/
|
|
9883
|
-
function createMarkdownTable(table) {
|
|
9884
|
-
var columnWidths = table.reduce(function (widths, row) {
|
|
9885
|
-
row.forEach(function (subformat, columnIndex) {
|
|
9886
|
-
var cellLength = subformat.length;
|
|
9887
|
-
if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
|
|
9888
|
-
widths[columnIndex] = cellLength;
|
|
9889
|
-
}
|
|
9890
|
-
});
|
|
9891
|
-
return widths;
|
|
9892
|
-
}, []);
|
|
9893
|
-
var header = "| ".concat(table[0]
|
|
9894
|
-
.map(function (subformat, columnIndex) { return subformat.padEnd(columnWidths[columnIndex]); })
|
|
9895
|
-
.join(' | '), " |");
|
|
9896
|
-
var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
|
|
9897
|
-
var rows = table.slice(1).map(function (row) {
|
|
9898
|
-
var paddedRow = row.map(function (subformat, columnIndex) {
|
|
9899
|
-
return subformat.padEnd(columnWidths[columnIndex]);
|
|
9900
|
-
});
|
|
9901
|
-
return "| ".concat(paddedRow.join(' | '), " |");
|
|
9902
|
-
});
|
|
9903
|
-
return __spreadArray([header, separator], __read(rows), false).join('\n');
|
|
9904
|
-
}
|
|
9905
|
-
/**
|
|
9906
|
-
* TODO: [🏛] This can be part of markdown builder
|
|
9907
|
-
*/
|
|
9908
|
-
|
|
9909
|
-
/**
|
|
9910
|
-
* Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
|
|
9911
|
-
*
|
|
9912
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
9913
|
-
*/
|
|
9914
|
-
function createMarkdownChart(options) {
|
|
9915
|
-
var e_1, _a;
|
|
9916
|
-
var nameHeader = options.nameHeader, valueHeader = options.valueHeader, items = options.items, width = options.width, unitName = options.unitName;
|
|
9917
|
-
var from = Math.min.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.from; })), false));
|
|
9918
|
-
var to = Math.max.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.to; })), false));
|
|
9919
|
-
var scale = width / (to - from);
|
|
9920
|
-
var table = [[nameHeader, valueHeader]];
|
|
9921
|
-
try {
|
|
9922
|
-
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
9923
|
-
var item = items_1_1.value;
|
|
9924
|
-
var before = Math.round((item.from - from) * scale);
|
|
9925
|
-
var during = Math.round((item.to - item.from) * scale);
|
|
9926
|
-
var after = width - before - during;
|
|
9927
|
-
table.push([removeEmojis(item.title).trim(), '░'.repeat(before) + '█'.repeat(during) + '░'.repeat(after)]);
|
|
9928
|
-
}
|
|
9929
|
-
}
|
|
9930
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9931
|
-
finally {
|
|
9932
|
-
try {
|
|
9933
|
-
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
9934
|
-
}
|
|
9935
|
-
finally { if (e_1) throw e_1.error; }
|
|
9936
|
-
}
|
|
9937
|
-
var legend = "_Note: Each \u2588 represents ".concat(formatNumber(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(formatNumber(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
|
|
9938
|
-
return createMarkdownTable(table) + '\n\n' + legend;
|
|
9939
|
-
}
|
|
9940
|
-
/**
|
|
9941
|
-
* TODO: Maybe use Mermain Gant Diagrams
|
|
9942
|
-
* @see https://jojozhuang.github.io/tutorial/mermaid-cheat-sheet/
|
|
9943
|
-
*/
|
|
9944
|
-
|
|
9945
|
-
/**
|
|
9946
|
-
* Function escapeMarkdownBlock will escape markdown block if needed
|
|
9947
|
-
* It is useful when you want have block in block
|
|
9948
|
-
*
|
|
9949
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
9950
|
-
*/
|
|
9951
|
-
function escapeMarkdownBlock(value) {
|
|
9952
|
-
return value.replace(/```/g, '\\`\\`\\`');
|
|
9953
|
-
}
|
|
9954
|
-
/**
|
|
9955
|
-
* TODO: [🏛] This can be part of markdown builder
|
|
9956
|
-
*/
|
|
9957
|
-
|
|
9958
|
-
/**
|
|
9959
|
-
* Default options for generating an execution report string
|
|
9960
|
-
*
|
|
9961
|
-
* @public exported from `@promptbook/core`
|
|
9962
|
-
*/
|
|
9963
|
-
var ExecutionReportStringOptionsDefaults = {
|
|
9964
|
-
taxRate: 0,
|
|
9965
|
-
chartsWidth: 36,
|
|
9966
|
-
};
|
|
9967
|
-
|
|
9968
|
-
/**
|
|
9969
|
-
* Count the duration of working time
|
|
9970
|
-
*
|
|
9971
|
-
* @private within the repository
|
|
9972
|
-
*/
|
|
9973
|
-
function countWorkingDuration(items) {
|
|
9974
|
-
var e_1, _a;
|
|
9975
|
-
var steps = Array.from(new Set(items.flatMap(function (item) { return [item.from, item.to]; })));
|
|
9976
|
-
steps.sort(function (a, b) { return a - b; });
|
|
9977
|
-
var intervals = steps.map(function (step, index) { return [step, steps[index + 1] || 0]; }).slice(0, -1);
|
|
9978
|
-
var duration = 0;
|
|
9979
|
-
var _loop_1 = function (interval) {
|
|
9980
|
-
var _b = __read(interval, 2), from = _b[0], to = _b[1];
|
|
9981
|
-
if (items.some(function (item) { return item.from < to && item.to > from; })) {
|
|
9982
|
-
duration += to - from;
|
|
9983
|
-
}
|
|
9984
|
-
};
|
|
9985
|
-
try {
|
|
9986
|
-
for (var intervals_1 = __values(intervals), intervals_1_1 = intervals_1.next(); !intervals_1_1.done; intervals_1_1 = intervals_1.next()) {
|
|
9987
|
-
var interval = intervals_1_1.value;
|
|
9988
|
-
_loop_1(interval);
|
|
9989
|
-
}
|
|
9990
|
-
}
|
|
9991
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9992
|
-
finally {
|
|
9993
|
-
try {
|
|
9994
|
-
if (intervals_1_1 && !intervals_1_1.done && (_a = intervals_1.return)) _a.call(intervals_1);
|
|
9995
|
-
}
|
|
9996
|
-
finally { if (e_1) throw e_1.error; }
|
|
9997
|
-
}
|
|
9998
|
-
return duration;
|
|
9999
|
-
}
|
|
10000
|
-
|
|
10001
|
-
/**
|
|
10002
|
-
* Converts execution report from JSON to string format
|
|
10003
|
-
*
|
|
10004
|
-
* @public exported from `@promptbook/core`
|
|
10005
|
-
*/
|
|
10006
|
-
function executionReportJsonToString(executionReportJson, options) {
|
|
10007
|
-
var e_1, _a;
|
|
10008
|
-
var _b, _c, _d, _e, _f, _g;
|
|
10009
|
-
var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
|
|
10010
|
-
var executionReportString = spaceTrim$1(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
10011
|
-
var headerList = [];
|
|
10012
|
-
if (executionReportJson.pipelineUrl) {
|
|
10013
|
-
headerList.push("PIPELINE URL ".concat(executionReportJson.pipelineUrl));
|
|
10014
|
-
}
|
|
10015
|
-
headerList.push("PROMPTBOOK VERSION ".concat(executionReportJson.promptbookUsedVersion) +
|
|
10016
|
-
(!executionReportJson.promptbookRequestedVersion
|
|
10017
|
-
? ''
|
|
10018
|
-
: " *(requested ".concat(executionReportJson.promptbookRequestedVersion, ")*")));
|
|
10019
|
-
if (executionReportJson.promptExecutions.length !== 0) {
|
|
10020
|
-
// TODO: What if startedAt OR/AND completedAt is not defined?
|
|
10021
|
-
var startedAt = moment(Math.min.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
|
|
10022
|
-
.filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start; })
|
|
10023
|
-
.map(function (promptExecution) { return moment(promptExecution.result.timing.start).valueOf(); })), false)));
|
|
10024
|
-
var completedAt = moment(Math.max.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
|
|
10025
|
-
.filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.complete; })
|
|
10026
|
-
.map(function (promptExecution) { return moment(promptExecution.result.timing.complete).valueOf(); })), false)));
|
|
10027
|
-
var timingItems = executionReportJson.promptExecutions.map(function (promptExecution) {
|
|
10028
|
-
var _a, _b, _c, _d;
|
|
10029
|
-
return ({
|
|
10030
|
-
title: promptExecution.prompt.title,
|
|
10031
|
-
from: moment((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start).valueOf() / 1000,
|
|
10032
|
-
to: moment((_d = (_c = promptExecution.result) === null || _c === void 0 ? void 0 : _c.timing) === null || _d === void 0 ? void 0 : _d.complete).valueOf() / 1000,
|
|
10033
|
-
});
|
|
10034
|
-
});
|
|
10035
|
-
var costItems = executionReportJson.promptExecutions
|
|
10036
|
-
.filter(function (promptExecution) { var _a, _b; return typeof ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) === 'number'; })
|
|
10037
|
-
.map(function (promptExecution) {
|
|
10038
|
-
var _a, _b;
|
|
10039
|
-
return ({
|
|
10040
|
-
title: promptExecution.prompt.title,
|
|
10041
|
-
from: 0,
|
|
10042
|
-
to: (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price.value) || 0) /* <- TODO: look at uncertain numbers */ *
|
|
10043
|
-
(1 + taxRate),
|
|
10044
|
-
});
|
|
10045
|
-
});
|
|
10046
|
-
var duration = moment.duration(completedAt.diff(startedAt));
|
|
10047
|
-
var llmDuration = moment.duration(countWorkingDuration(timingItems) * 1000);
|
|
10048
|
-
var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
|
|
10049
|
-
var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) {
|
|
10050
|
-
return cost + (promptExecution.result.usage.price.value /* <- Look at uncertain number */ || 0);
|
|
10051
|
-
}, 0);
|
|
10052
|
-
headerList.push("STARTED AT ".concat(moment(startedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
10053
|
-
headerList.push("COMPLETED AT ".concat(moment(completedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
10054
|
-
headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
10055
|
-
headerList.push("TOTAL LLM DURATION ".concat(llmDuration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
10056
|
-
headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
|
|
10057
|
-
(executionsWithKnownCost.length === executionReportJson.promptExecutions.length
|
|
10058
|
-
? ''
|
|
10059
|
-
: " *(Some cost is unknown)*") +
|
|
10060
|
-
(taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
|
|
10061
|
-
executionReportString += '\n\n' + headerList.map(function (header) { return "- ".concat(header); }).join('\n');
|
|
10062
|
-
executionReportString +=
|
|
10063
|
-
'\n\n' +
|
|
10064
|
-
'## 🗃 Index' +
|
|
10065
|
-
'\n\n' +
|
|
10066
|
-
executionReportJson.promptExecutions
|
|
10067
|
-
.map(function (promptExecution) {
|
|
10068
|
-
// TODO: Make some better system to convert hedings to links
|
|
10069
|
-
var hash = normalizeToKebabCase(promptExecution.prompt.title);
|
|
10070
|
-
if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
|
|
10071
|
-
hash = '-' + hash;
|
|
10072
|
-
}
|
|
10073
|
-
// TODO: Make working hash link for the template in md + pdf
|
|
10074
|
-
return "- [".concat(promptExecution.prompt.title, "](#").concat(hash, ")");
|
|
10075
|
-
})
|
|
10076
|
-
.join('\n');
|
|
10077
|
-
executionReportString +=
|
|
10078
|
-
'\n\n' +
|
|
10079
|
-
'## ⌚ Time chart' +
|
|
10080
|
-
'\n\n' +
|
|
10081
|
-
createMarkdownChart({
|
|
10082
|
-
nameHeader: 'Template',
|
|
10083
|
-
valueHeader: 'Timeline',
|
|
10084
|
-
items: timingItems,
|
|
10085
|
-
width: chartsWidth,
|
|
10086
|
-
unitName: 'seconds',
|
|
10087
|
-
});
|
|
10088
|
-
executionReportString +=
|
|
10089
|
-
'\n\n' +
|
|
10090
|
-
'## 💸 Cost chart' +
|
|
10091
|
-
'\n\n' +
|
|
10092
|
-
createMarkdownChart({
|
|
10093
|
-
nameHeader: 'Template',
|
|
10094
|
-
valueHeader: 'Cost',
|
|
10095
|
-
items: costItems,
|
|
10096
|
-
width: chartsWidth,
|
|
10097
|
-
unitName: 'USD',
|
|
10098
|
-
});
|
|
10099
|
-
}
|
|
10100
|
-
else {
|
|
10101
|
-
headerList.push("TOTAL COST $0 *(Nothing executed)*");
|
|
10102
|
-
}
|
|
10103
|
-
var _loop_1 = function (promptExecution) {
|
|
10104
|
-
executionReportString += '\n\n\n\n' + "## ".concat(promptExecution.prompt.title);
|
|
10105
|
-
var templateList = [];
|
|
10106
|
-
// TODO: What if startedAt OR/AND completedAt is not defined?
|
|
10107
|
-
var startedAt = moment((_c = (_b = promptExecution.result) === null || _b === void 0 ? void 0 : _b.timing) === null || _c === void 0 ? void 0 : _c.start);
|
|
10108
|
-
var completedAt = moment((_e = (_d = promptExecution.result) === null || _d === void 0 ? void 0 : _d.timing) === null || _e === void 0 ? void 0 : _e.complete);
|
|
10109
|
-
var duration = moment.duration(completedAt.diff(startedAt));
|
|
10110
|
-
// Not need here:
|
|
10111
|
-
// > templateList.push(`STARTED AT ${moment(startedAt).calendar()}`);
|
|
10112
|
-
templateList.push("DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
10113
|
-
if (typeof ((_g = (_f = promptExecution.result) === null || _f === void 0 ? void 0 : _f.usage) === null || _g === void 0 ? void 0 : _g.price) === 'number') {
|
|
10114
|
-
templateList.push("COST $".concat(formatNumber(promptExecution.result.usage.price * (1 + taxRate))) +
|
|
10115
|
-
(taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
|
|
10116
|
-
}
|
|
10117
|
-
else {
|
|
10118
|
-
templateList.push("COST UNKNOWN");
|
|
10119
|
-
}
|
|
10120
|
-
executionReportString += '\n\n' + templateList.map(function (header) { return "- ".concat(header); }).join('\n');
|
|
10121
|
-
/*
|
|
10122
|
-
- MODEL VARIANT ${promptExecution.prompt.modelRequirements.modelVariant}
|
|
10123
|
-
- MODEL NAME \`${promptExecution.result?.model}\` (requested \`${
|
|
10124
|
-
promptExecution.prompt.modelRequirements.modelName
|
|
10125
|
-
|
|
10126
|
-
*/
|
|
10127
|
-
if (just(true)) {
|
|
10128
|
-
executionReportString +=
|
|
10129
|
-
'\n\n\n\n' +
|
|
10130
|
-
spaceTrim$1(function (block) {
|
|
10131
|
-
var _a;
|
|
10132
|
-
return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(((_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.rawPromptContent) || promptExecution.prompt.content)), "\n ```\n\n ");
|
|
10133
|
-
});
|
|
10134
|
-
}
|
|
10135
|
-
if (promptExecution.result && promptExecution.result.content) {
|
|
10136
|
-
executionReportString += '\n\n\n\n' + '### Result' + '\n\n';
|
|
10137
|
-
if (promptExecution.result === undefined) {
|
|
10138
|
-
executionReportString += '*No result*';
|
|
10139
|
-
}
|
|
10140
|
-
else if (typeof promptExecution.result.content === 'string') {
|
|
10141
|
-
executionReportString += spaceTrim$1(function (block) { return "\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
|
|
10142
|
-
}
|
|
10143
|
-
else {
|
|
10144
|
-
executionReportString += embeddingVectorToString(promptExecution.result.content);
|
|
10145
|
-
}
|
|
10146
|
-
}
|
|
10147
|
-
if (promptExecution.error && promptExecution.error.message) {
|
|
10148
|
-
executionReportString +=
|
|
10149
|
-
'\n\n\n\n' +
|
|
10150
|
-
spaceTrim$1(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
|
|
10151
|
-
}
|
|
10152
|
-
};
|
|
10153
|
-
try {
|
|
10154
|
-
for (var _j = __values(executionReportJson.promptExecutions), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
10155
|
-
var promptExecution = _k.value;
|
|
10156
|
-
_loop_1(promptExecution);
|
|
10157
|
-
}
|
|
10158
|
-
}
|
|
10159
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
10160
|
-
finally {
|
|
10161
|
-
try {
|
|
10162
|
-
if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
|
|
10163
|
-
}
|
|
10164
|
-
finally { if (e_1) throw e_1.error; }
|
|
10165
|
-
}
|
|
10166
|
-
executionReportString = prettifyMarkdown(executionReportString);
|
|
10167
|
-
return executionReportString;
|
|
10168
|
-
}
|
|
10169
|
-
/**
|
|
10170
|
-
* TODO: Add mermaid chart for every report
|
|
10171
|
-
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
10172
|
-
* TODO: [🧠] Should be in generated file GENERATOR_WARNING
|
|
10173
|
-
*/
|
|
10174
|
-
|
|
10175
|
-
export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TITLE, ERRORS, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GenericFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NotFoundError, NotYetImplementedError, PROMPTBOOK_ENGINE_VERSION, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SheetsFormfactorDefinition, TemplateTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTemplates, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
|
|
10340
|
+
export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TITLE, ERRORS, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, PROMPTBOOK_ENGINE_VERSION, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
|
|
10176
10341
|
//# sourceMappingURL=index.es.js.map
|