@promptbook/core 0.60.0-3 → 0.60.0-5
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 +3 -5
- package/esm/index.es.js +488 -485
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +9 -9
- package/esm/typings/src/_packages/node.index.d.ts +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +3 -3
- package/{umd/typings/src/library → esm/typings/src/collection}/PipelineCollection.d.ts +4 -4
- package/{umd/typings/src/library → esm/typings/src/collection}/SimplePipelineCollection.d.ts +5 -5
- package/{umd/typings/src/library/libraryToJson.d.ts → esm/typings/src/collection/collectionToJson.d.ts} +2 -2
- package/esm/typings/src/{library → collection}/constructors/createCollectionFromDirectory.d.ts +3 -3
- package/esm/typings/src/{library → collection}/constructors/createCollectionFromJson.d.ts +1 -1
- package/{umd/typings/src/library → esm/typings/src/collection}/constructors/createCollectionFromPromise.d.ts +1 -1
- package/esm/typings/src/{library → collection}/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createSubcollection.d.ts +12 -0
- package/esm/typings/src/config.d.ts +2 -2
- package/esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts +1 -1
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +1 -1
- package/esm/typings/src/errors/CollectionError.d.ts +1 -1
- package/esm/typings/src/errors/ExecutionError.d.ts +1 -1
- package/esm/typings/src/errors/NotFoundError.d.ts +1 -1
- package/esm/typings/src/execution/EmbeddingVector.d.ts +1 -1
- package/esm/typings/src/execution/{PromptbookExecutor.d.ts → PipelineExecutor.d.ts} +3 -3
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/{umd/typings/src/execution/createPromptbookExecutor.d.ts → esm/typings/src/execution/createPipelineExecutor.d.ts} +13 -13
- package/esm/typings/src/execution/utils/replaceParameters.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/joker.test.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/mocked-chat.test.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/mocked-completion.test.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +4 -4
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/types/Command.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +6 -6
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineString.d.ts +1 -1
- package/esm/typings/src/types/Prompt.d.ts +4 -4
- package/esm/typings/src/types/TaskProgress.d.ts +1 -1
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -3
- package/esm/typings/src/types/execution-report/config.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +2 -2
- package/esm/typings/src/utils/emojis.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +489 -486
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +1 -1
- package/umd/typings/src/_packages/core.index.d.ts +9 -9
- package/umd/typings/src/_packages/node.index.d.ts +1 -1
- package/umd/typings/src/_packages/types.index.d.ts +3 -3
- package/{esm/typings/src/library → umd/typings/src/collection}/PipelineCollection.d.ts +4 -4
- package/{esm/typings/src/library → umd/typings/src/collection}/SimplePipelineCollection.d.ts +5 -5
- package/{esm/typings/src/library/libraryToJson.d.ts → umd/typings/src/collection/collectionToJson.d.ts} +2 -2
- package/umd/typings/src/{library → collection}/constructors/createCollectionFromDirectory.d.ts +3 -3
- package/umd/typings/src/{library → collection}/constructors/createCollectionFromJson.d.ts +1 -1
- package/{esm/typings/src/library → umd/typings/src/collection}/constructors/createCollectionFromPromise.d.ts +1 -1
- package/umd/typings/src/{library → collection}/constructors/createCollectionFromUrl.d.ts +1 -1
- package/umd/typings/src/collection/constructors/createSubcollection.d.ts +12 -0
- package/umd/typings/src/config.d.ts +2 -2
- package/umd/typings/src/conversion/prettify/prettifyPipelineString.d.ts +1 -1
- package/umd/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +1 -1
- package/umd/typings/src/errors/CollectionError.d.ts +1 -1
- package/umd/typings/src/errors/ExecutionError.d.ts +1 -1
- package/umd/typings/src/errors/NotFoundError.d.ts +1 -1
- package/umd/typings/src/execution/EmbeddingVector.d.ts +1 -1
- package/umd/typings/src/execution/{PromptbookExecutor.d.ts → PipelineExecutor.d.ts} +3 -3
- package/umd/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/{esm/typings/src/execution/createPromptbookExecutor.d.ts → umd/typings/src/execution/createPipelineExecutor.d.ts} +13 -13
- package/umd/typings/src/execution/utils/replaceParameters.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/joker.test.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/mocked-chat.test.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/mocked-completion.test.d.ts +1 -1
- package/umd/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +4 -4
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/umd/typings/src/types/Command.d.ts +2 -2
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +6 -6
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/umd/typings/src/types/PipelineString.d.ts +1 -1
- package/umd/typings/src/types/Prompt.d.ts +4 -4
- package/umd/typings/src/types/TaskProgress.d.ts +1 -1
- package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -3
- package/umd/typings/src/types/execution-report/config.d.ts +1 -1
- package/umd/typings/src/types/typeAliases.d.ts +2 -2
- package/umd/typings/src/utils/emojis.d.ts +1 -1
- package/esm/typings/src/library/constructors/createSubcollection.d.ts +0 -12
- package/umd/typings/src/library/constructors/createSubcollection.d.ts +0 -12
- /package/esm/typings/src/{library/constructors/createCollectionFromDirectory.test.d.ts → collection/collectionToJson.test.d.ts} +0 -0
- /package/{umd/typings/src/library → esm/typings/src/collection}/constructors/createCollectionFromDirectory.test.d.ts +0 -0
- /package/esm/typings/src/{library → collection}/constructors/createCollectionFromJson.test.d.ts +0 -0
- /package/esm/typings/src/{library → collection}/constructors/createCollectionFromPromise.test.d.ts +0 -0
- /package/esm/typings/src/{library → collection}/constructors/justTestFsImport.d.ts +0 -0
- /package/{esm/typings/src/library/libraryToJson.test.d.ts → umd/typings/src/collection/collectionToJson.test.d.ts} +0 -0
- /package/umd/typings/src/{library/constructors/createCollectionFromJson.test.d.ts → collection/constructors/createCollectionFromDirectory.test.d.ts} +0 -0
- /package/umd/typings/src/{library/constructors/createCollectionFromPromise.test.d.ts → collection/constructors/createCollectionFromJson.test.d.ts} +0 -0
- /package/umd/typings/src/{library/libraryToJson.test.d.ts → collection/constructors/createCollectionFromPromise.test.d.ts} +0 -0
- /package/umd/typings/src/{library → collection}/constructors/justTestFsImport.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -122,6 +122,28 @@ function __spreadArray(to, from, pack) {
|
|
|
122
122
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Converts PipelineCollection to serialized JSON
|
|
127
|
+
*
|
|
128
|
+
* Note: Functions `collectionToJson` and `createCollectionFromJson` are complementary
|
|
129
|
+
*/
|
|
130
|
+
function collectionToJson(collection) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
var pipelineUrls, promptbooks;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
switch (_a.label) {
|
|
135
|
+
case 0: return [4 /*yield*/, collection.listPipelines()];
|
|
136
|
+
case 1:
|
|
137
|
+
pipelineUrls = _a.sent();
|
|
138
|
+
return [4 /*yield*/, Promise.all(pipelineUrls.map(function (url) { return collection.getPipelineByUrl(url); }))];
|
|
139
|
+
case 2:
|
|
140
|
+
promptbooks = _a.sent();
|
|
141
|
+
return [2 /*return*/, promptbooks];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
125
147
|
/**
|
|
126
148
|
* Prettify the html code
|
|
127
149
|
*
|
|
@@ -170,7 +192,7 @@ function capitalize(word) {
|
|
|
170
192
|
*/
|
|
171
193
|
function pipelineJsonToString(pipelineJson) {
|
|
172
194
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
173
|
-
var title = pipelineJson.title,
|
|
195
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, promptTemplates = pipelineJson.promptTemplates;
|
|
174
196
|
var pipelineString = "# ".concat(title);
|
|
175
197
|
if (description) {
|
|
176
198
|
pipelineString += '\n\n';
|
|
@@ -178,8 +200,8 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
178
200
|
}
|
|
179
201
|
// TODO:> const commands: Array<Command>
|
|
180
202
|
var commands = [];
|
|
181
|
-
if (
|
|
182
|
-
commands.push("
|
|
203
|
+
if (pipelineUrl) {
|
|
204
|
+
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
183
205
|
}
|
|
184
206
|
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
185
207
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
@@ -361,47 +383,6 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
361
383
|
* TODO: Escape all
|
|
362
384
|
*/
|
|
363
385
|
|
|
364
|
-
var PipelineCollection = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.60.0-2",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",resultingParameterName:"keywords"}],knowledge:[]},{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.60.0-2",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",resultingParameterName:"knowledge"}],knowledge:[]}];
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* This error indicates errors during the execution of the promptbook
|
|
368
|
-
*/
|
|
369
|
-
var ExecutionError = /** @class */ (function (_super) {
|
|
370
|
-
__extends(ExecutionError, _super);
|
|
371
|
-
function ExecutionError(message) {
|
|
372
|
-
var _this = _super.call(this, message) || this;
|
|
373
|
-
_this.name = 'ExecutionError';
|
|
374
|
-
Object.setPrototypeOf(_this, ExecutionError.prototype);
|
|
375
|
-
return _this;
|
|
376
|
-
}
|
|
377
|
-
return ExecutionError;
|
|
378
|
-
}(Error));
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Asserts that the execution of a promptnook is successful
|
|
382
|
-
*
|
|
383
|
-
* @param executionResult - The partial result of the promptnook execution
|
|
384
|
-
* @throws {ExecutionError} If the execution is not successful or if multiple errors occurred
|
|
385
|
-
*/
|
|
386
|
-
function assertsExecutionSuccessful(executionResult) {
|
|
387
|
-
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
388
|
-
if (isSuccessful === true) {
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
if (errors.length === 0) {
|
|
392
|
-
throw new ExecutionError("Promptnook Execution failed because of unknown reason");
|
|
393
|
-
}
|
|
394
|
-
else if (errors.length === 1) {
|
|
395
|
-
throw errors[0];
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
throw new ExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* TODO: [🧠] Can this return type be better typed than void
|
|
403
|
-
*/
|
|
404
|
-
|
|
405
386
|
/**
|
|
406
387
|
* The maximum number of iterations for a loops
|
|
407
388
|
*/
|
|
@@ -441,7 +422,7 @@ var SyntaxError = /** @class */ (function (_super) {
|
|
|
441
422
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
442
423
|
__extends(UnexpectedError, _super);
|
|
443
424
|
function UnexpectedError(message) {
|
|
444
|
-
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the
|
|
425
|
+
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
445
426
|
_this.name = 'UnexpectedError';
|
|
446
427
|
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
447
428
|
return _this;
|
|
@@ -491,10 +472,10 @@ function isValidUrl(url) {
|
|
|
491
472
|
function validatePipeline(pipeline) {
|
|
492
473
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
493
474
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
494
|
-
if (pipeline.
|
|
495
|
-
if (!isValidUrl(pipeline.
|
|
475
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
476
|
+
if (!isValidUrl(pipeline.pipelineUrl)) {
|
|
496
477
|
// TODO: This should be maybe the syntax error detected during parsing
|
|
497
|
-
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.
|
|
478
|
+
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\""));
|
|
498
479
|
}
|
|
499
480
|
}
|
|
500
481
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
@@ -660,6 +641,369 @@ function validatePipeline(pipeline) {
|
|
|
660
641
|
* > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
|
|
661
642
|
*/
|
|
662
643
|
|
|
644
|
+
/**
|
|
645
|
+
* This error indicates that promptbook not found in the collection
|
|
646
|
+
*/
|
|
647
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
648
|
+
__extends(NotFoundError, _super);
|
|
649
|
+
function NotFoundError(message) {
|
|
650
|
+
var _this = _super.call(this, message) || this;
|
|
651
|
+
_this.name = 'NotFoundError';
|
|
652
|
+
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
653
|
+
return _this;
|
|
654
|
+
}
|
|
655
|
+
return NotFoundError;
|
|
656
|
+
}(Error));
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* This error indicates errors in referencing promptbooks between each other
|
|
660
|
+
*/
|
|
661
|
+
var ReferenceError$1 = /** @class */ (function (_super) {
|
|
662
|
+
__extends(ReferenceError, _super);
|
|
663
|
+
function ReferenceError(message) {
|
|
664
|
+
var _this = _super.call(this, message) || this;
|
|
665
|
+
_this.name = 'ReferenceError';
|
|
666
|
+
Object.setPrototypeOf(_this, ReferenceError.prototype);
|
|
667
|
+
return _this;
|
|
668
|
+
}
|
|
669
|
+
return ReferenceError;
|
|
670
|
+
}(Error));
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Library of promptbooks that groups together promptbooks for an application.
|
|
674
|
+
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
675
|
+
*
|
|
676
|
+
* @private use `createCollectionFromJson` instead
|
|
677
|
+
* @see https://github.com/webgptorg/promptbook#promptbook-collection
|
|
678
|
+
*/
|
|
679
|
+
var SimplePipelineCollection = /** @class */ (function () {
|
|
680
|
+
/**
|
|
681
|
+
* Constructs a pipeline collection from promptbooks
|
|
682
|
+
*
|
|
683
|
+
* @param promptbooks !!!
|
|
684
|
+
*
|
|
685
|
+
* @private Use instead `createCollectionFromJson`
|
|
686
|
+
* Note: During the construction logic of all promptbooks are validated
|
|
687
|
+
* Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
|
|
688
|
+
*/
|
|
689
|
+
function SimplePipelineCollection() {
|
|
690
|
+
var e_1, _a;
|
|
691
|
+
var promptbooks = [];
|
|
692
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
693
|
+
promptbooks[_i] = arguments[_i];
|
|
694
|
+
}
|
|
695
|
+
this.collection = new Map();
|
|
696
|
+
try {
|
|
697
|
+
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
698
|
+
var promptbook = promptbooks_1_1.value;
|
|
699
|
+
if (promptbook.pipelineUrl === undefined) {
|
|
700
|
+
throw new ReferenceError$1(spaceTrim$1("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the pipeline collection\n\n ")));
|
|
701
|
+
}
|
|
702
|
+
validatePipeline(promptbook);
|
|
703
|
+
// Note: [🦄]
|
|
704
|
+
if (this.collection.has(promptbook.pipelineUrl) &&
|
|
705
|
+
pipelineJsonToString(promptbook) !== pipelineJsonToString(this.collection.get(promptbook.pipelineUrl))) {
|
|
706
|
+
throw new ReferenceError$1(spaceTrim$1("\n Promptbook with URL \"".concat(promptbook.pipelineUrl, "\" is already in the collection\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
|
|
707
|
+
}
|
|
708
|
+
this.collection.set(promptbook.pipelineUrl, promptbook);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
712
|
+
finally {
|
|
713
|
+
try {
|
|
714
|
+
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
715
|
+
}
|
|
716
|
+
finally { if (e_1) throw e_1.error; }
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Gets all promptbooks in the collection
|
|
721
|
+
*/
|
|
722
|
+
SimplePipelineCollection.prototype.listPipelines = function () {
|
|
723
|
+
return Array.from(this.collection.keys());
|
|
724
|
+
};
|
|
725
|
+
/**
|
|
726
|
+
* Gets promptbook by its URL
|
|
727
|
+
*
|
|
728
|
+
* Note: This is not a direct fetching from the URL, but a lookup in the collection
|
|
729
|
+
*/
|
|
730
|
+
SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
|
|
731
|
+
var _this = this;
|
|
732
|
+
var promptbook = this.collection.get(url);
|
|
733
|
+
if (!promptbook) {
|
|
734
|
+
if (this.listPipelines().length === 0) {
|
|
735
|
+
throw new NotFoundError(spaceTrim$1("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
736
|
+
}
|
|
737
|
+
throw new NotFoundError(spaceTrim$1(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPipelines()
|
|
738
|
+
.map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
|
|
739
|
+
.join('\n')), "\n\n "); }));
|
|
740
|
+
}
|
|
741
|
+
return promptbook;
|
|
742
|
+
};
|
|
743
|
+
/**
|
|
744
|
+
* Checks whether given prompt was defined in any promptbook in the collection
|
|
745
|
+
*/
|
|
746
|
+
SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
|
|
747
|
+
return true;
|
|
748
|
+
};
|
|
749
|
+
return SimplePipelineCollection;
|
|
750
|
+
}());
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Creates PipelineCollection from array of PipelineJson or PipelineString
|
|
754
|
+
*
|
|
755
|
+
* Note: Functions `collectionToJson` and `createCollectionFromJson` are complementary
|
|
756
|
+
* Note: During the construction syntax and logic of all sources are validated
|
|
757
|
+
*
|
|
758
|
+
* @param promptbookSources
|
|
759
|
+
* @returns PipelineCollection
|
|
760
|
+
*/
|
|
761
|
+
function createCollectionFromJson() {
|
|
762
|
+
var promptbooks = [];
|
|
763
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
764
|
+
promptbooks[_i] = arguments[_i];
|
|
765
|
+
}
|
|
766
|
+
return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Constructs Promptbook from async sources
|
|
771
|
+
* It can be one of the following:
|
|
772
|
+
* - Promise of array of PipelineJson or PipelineString
|
|
773
|
+
* - Factory function that returns Promise of array of PipelineJson or PipelineString
|
|
774
|
+
*
|
|
775
|
+
* Note: This is useful as internal tool for other constructor functions like
|
|
776
|
+
* `createCollectionFromUrl` or `createCollectionFromDirectory`
|
|
777
|
+
* Consider using those functions instead of this one
|
|
778
|
+
*
|
|
779
|
+
* Note: The function does NOT return promise it returns the collection directly which waits for the sources to be resolved
|
|
780
|
+
* when error occurs in given promise or factory function, it is thrown during `listPipelines` or `getPipelineByUrl` call
|
|
781
|
+
*
|
|
782
|
+
* Note: Consider using `createCollectionFromDirectory` or `createCollectionFromUrl`
|
|
783
|
+
*
|
|
784
|
+
* @param promptbookSourcesPromiseOrFactory
|
|
785
|
+
* @returns PipelineCollection
|
|
786
|
+
* @deprecated Do not use, it will became internal tool for other constructor functions
|
|
787
|
+
*/
|
|
788
|
+
function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
789
|
+
var collection;
|
|
790
|
+
function forSources() {
|
|
791
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
792
|
+
var promptbookSources;
|
|
793
|
+
return __generator(this, function (_a) {
|
|
794
|
+
switch (_a.label) {
|
|
795
|
+
case 0:
|
|
796
|
+
if (typeof promptbookSourcesPromiseOrFactory === 'function') {
|
|
797
|
+
// Note: Calling factory function only once despite multiple calls to resolveSources
|
|
798
|
+
promptbookSourcesPromiseOrFactory = promptbookSourcesPromiseOrFactory();
|
|
799
|
+
}
|
|
800
|
+
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
801
|
+
case 1:
|
|
802
|
+
promptbookSources = _a.sent();
|
|
803
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false));
|
|
804
|
+
return [2 /*return*/];
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
function listPipelines() {
|
|
810
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
811
|
+
return __generator(this, function (_a) {
|
|
812
|
+
switch (_a.label) {
|
|
813
|
+
case 0: return [4 /*yield*/, forSources()];
|
|
814
|
+
case 1:
|
|
815
|
+
_a.sent();
|
|
816
|
+
return [2 /*return*/, /* not await */ collection.listPipelines()];
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
function getPipelineByUrl(url) {
|
|
822
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
823
|
+
return __generator(this, function (_a) {
|
|
824
|
+
switch (_a.label) {
|
|
825
|
+
case 0: return [4 /*yield*/, forSources()];
|
|
826
|
+
case 1:
|
|
827
|
+
_a.sent();
|
|
828
|
+
return [2 /*return*/, /* not await */ collection.getPipelineByUrl(url)];
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
function isResponsibleForPrompt(prompt) {
|
|
834
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
835
|
+
return __generator(this, function (_a) {
|
|
836
|
+
switch (_a.label) {
|
|
837
|
+
case 0: return [4 /*yield*/, forSources()];
|
|
838
|
+
case 1:
|
|
839
|
+
_a.sent();
|
|
840
|
+
return [2 /*return*/, /* not await */ collection.isResponsibleForPrompt(prompt)];
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
return {
|
|
846
|
+
listPipelines: listPipelines,
|
|
847
|
+
getPipelineByUrl: getPipelineByUrl,
|
|
848
|
+
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Constructs Promptbook from remote Promptbase URL
|
|
854
|
+
|
|
855
|
+
* @returns PipelineCollection
|
|
856
|
+
*/
|
|
857
|
+
function createCollectionFromUrl(url, options) {
|
|
858
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
859
|
+
var _a, _b, isVerbose, _c, isLazyLoaded, collection;
|
|
860
|
+
var _this = this;
|
|
861
|
+
return __generator(this, function (_d) {
|
|
862
|
+
switch (_d.label) {
|
|
863
|
+
case 0:
|
|
864
|
+
_a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
|
|
865
|
+
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
866
|
+
return __generator(this, function (_a) {
|
|
867
|
+
if (isVerbose) {
|
|
868
|
+
console.info("Creating pipeline collection from url ".concat(url.toString()));
|
|
869
|
+
}
|
|
870
|
+
throw new Error('Not implemented yet');
|
|
871
|
+
});
|
|
872
|
+
}); });
|
|
873
|
+
if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
|
|
874
|
+
return [4 /*yield*/, collection.listPipelines()];
|
|
875
|
+
case 1:
|
|
876
|
+
_d.sent();
|
|
877
|
+
_d.label = 2;
|
|
878
|
+
case 2: return [2 /*return*/, collection];
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
885
|
+
*/
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Creates PipelineCollection as a subset of another PipelineCollection
|
|
889
|
+
*
|
|
890
|
+
* Note: You can use any type of collection as a parent collection - local, remote, etc.
|
|
891
|
+
* Note: This is just a thin wrapper / proxy around the parent collection
|
|
892
|
+
*
|
|
893
|
+
* @param promptbookSources
|
|
894
|
+
* @returns PipelineCollection
|
|
895
|
+
*/
|
|
896
|
+
function createSubcollection(collection, predicate) {
|
|
897
|
+
function listPipelines() {
|
|
898
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
899
|
+
var promptbooks;
|
|
900
|
+
return __generator(this, function (_a) {
|
|
901
|
+
switch (_a.label) {
|
|
902
|
+
case 0: return [4 /*yield*/, collection.listPipelines()];
|
|
903
|
+
case 1:
|
|
904
|
+
promptbooks = _a.sent();
|
|
905
|
+
promptbooks = promptbooks.filter(predicate);
|
|
906
|
+
return [2 /*return*/, promptbooks];
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
function getPipelineByUrl(url) {
|
|
912
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
913
|
+
var _a, pipeline;
|
|
914
|
+
var _this = this;
|
|
915
|
+
return __generator(this, function (_b) {
|
|
916
|
+
switch (_b.label) {
|
|
917
|
+
case 0:
|
|
918
|
+
if (!!predicate(url)) return [3 /*break*/, 2];
|
|
919
|
+
_a = NotFoundError.bind;
|
|
920
|
+
return [4 /*yield*/, spaceTrim$1(function (block) { return __awaiter(_this, void 0, void 0, function () {
|
|
921
|
+
var _a, _b, _c, _d, _e, _f;
|
|
922
|
+
return __generator(this, function (_g) {
|
|
923
|
+
switch (_g.label) {
|
|
924
|
+
case 0:
|
|
925
|
+
_c = (_b = "\n Promptbook with url \"".concat(url, "\" not found or not accessible\n\n Available promptbooks:\n ")).concat;
|
|
926
|
+
_d = block;
|
|
927
|
+
return [4 /*yield*/, listPipelines()];
|
|
928
|
+
case 1:
|
|
929
|
+
_e = (_a = _c.apply(_b, [_d.apply(void 0, [(_g.sent()).map(function (pipelineUrl) { return "- ".concat(pipelineUrl); }).join('\n')]), "\n\n All available promptbooks in parent collection:\n "])).concat;
|
|
930
|
+
_f = block;
|
|
931
|
+
return [4 /*yield*/, collection.listPipelines()];
|
|
932
|
+
case 2: return [2 /*return*/, _e.apply(_a, [_f.apply(void 0, [(_g.sent()).map(function (pipelineUrl) { return "- ".concat(pipelineUrl); }).join('\n')]), "\n\n "])];
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
}); })];
|
|
936
|
+
case 1: throw new (_a.apply(NotFoundError, [void 0, _b.sent()]))();
|
|
937
|
+
case 2: return [4 /*yield*/, collection.getPipelineByUrl(url)];
|
|
938
|
+
case 3:
|
|
939
|
+
pipeline = _b.sent();
|
|
940
|
+
return [2 /*return*/, pipeline];
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
function isResponsibleForPrompt(prompt) {
|
|
946
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
947
|
+
var isResponsible;
|
|
948
|
+
return __generator(this, function (_a) {
|
|
949
|
+
switch (_a.label) {
|
|
950
|
+
case 0: return [4 /*yield*/, collection.isResponsibleForPrompt(prompt)];
|
|
951
|
+
case 1:
|
|
952
|
+
isResponsible = _a.sent();
|
|
953
|
+
// TODO: !! Only if responsible, check if predicate is true
|
|
954
|
+
return [2 /*return*/, isResponsible];
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
return {
|
|
960
|
+
listPipelines: listPipelines,
|
|
961
|
+
getPipelineByUrl: getPipelineByUrl,
|
|
962
|
+
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
var PipelineCollection = [{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.60.0-4",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",resultingParameterName:"keywords"}],knowledge:[]},{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.60.0-4",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",resultingParameterName:"knowledge"}],knowledge:[]}];
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* This error indicates errors during the execution of the pipeline
|
|
970
|
+
*/
|
|
971
|
+
var ExecutionError = /** @class */ (function (_super) {
|
|
972
|
+
__extends(ExecutionError, _super);
|
|
973
|
+
function ExecutionError(message) {
|
|
974
|
+
var _this = _super.call(this, message) || this;
|
|
975
|
+
_this.name = 'ExecutionError';
|
|
976
|
+
Object.setPrototypeOf(_this, ExecutionError.prototype);
|
|
977
|
+
return _this;
|
|
978
|
+
}
|
|
979
|
+
return ExecutionError;
|
|
980
|
+
}(Error));
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Asserts that the execution of a promptnook is successful
|
|
984
|
+
*
|
|
985
|
+
* @param executionResult - The partial result of the promptnook execution
|
|
986
|
+
* @throws {ExecutionError} If the execution is not successful or if multiple errors occurred
|
|
987
|
+
*/
|
|
988
|
+
function assertsExecutionSuccessful(executionResult) {
|
|
989
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
990
|
+
if (isSuccessful === true) {
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
if (errors.length === 0) {
|
|
994
|
+
throw new ExecutionError("Promptnook Execution failed because of unknown reason");
|
|
995
|
+
}
|
|
996
|
+
else if (errors.length === 1) {
|
|
997
|
+
throw errors[0];
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
throw new ExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* TODO: [🧠] Can this return type be better typed than void
|
|
1005
|
+
*/
|
|
1006
|
+
|
|
663
1007
|
/**
|
|
664
1008
|
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
665
1009
|
*
|
|
@@ -699,7 +1043,7 @@ function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
|
699
1043
|
/**
|
|
700
1044
|
* The version of the Promptbook library
|
|
701
1045
|
*/
|
|
702
|
-
var PROMPTBOOK_VERSION = '0.60.0-
|
|
1046
|
+
var PROMPTBOOK_VERSION = '0.60.0-4';
|
|
703
1047
|
|
|
704
1048
|
/**
|
|
705
1049
|
* Function `addUsage` will add multiple usages into one
|
|
@@ -1199,7 +1543,7 @@ var TemplateError = /** @class */ (function (_super) {
|
|
|
1199
1543
|
* @returns the template with replaced parameters
|
|
1200
1544
|
* @throws {TemplateError} if parameter is not defined, not closed, or not opened
|
|
1201
1545
|
*
|
|
1202
|
-
* @private within the
|
|
1546
|
+
* @private within the createPipelineExecutor
|
|
1203
1547
|
*/
|
|
1204
1548
|
function replaceParameters(template, parameters) {
|
|
1205
1549
|
var replacedTemplate = template;
|
|
@@ -1252,17 +1596,17 @@ function replaceParameters(template, parameters) {
|
|
|
1252
1596
|
}
|
|
1253
1597
|
|
|
1254
1598
|
/**
|
|
1255
|
-
* Creates executor function from
|
|
1599
|
+
* Creates executor function from pipeline and execution tools.
|
|
1256
1600
|
*
|
|
1257
1601
|
* @returns The executor function
|
|
1258
|
-
* @throws {PipelineLogicError} on logical error in the
|
|
1602
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
1259
1603
|
*/
|
|
1260
|
-
function
|
|
1604
|
+
function createPipelineExecutor(options) {
|
|
1261
1605
|
var _this = this;
|
|
1262
|
-
var
|
|
1606
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1263
1607
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1264
|
-
validatePipeline(
|
|
1265
|
-
var
|
|
1608
|
+
validatePipeline(pipeline);
|
|
1609
|
+
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1266
1610
|
function executeSingleTemplate(currentTemplate) {
|
|
1267
1611
|
return __awaiter(this, void 0, void 0, function () {
|
|
1268
1612
|
var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, error_4;
|
|
@@ -1271,9 +1615,9 @@ function createPromptbookExecutor(options) {
|
|
|
1271
1615
|
return __generator(this, function (_o) {
|
|
1272
1616
|
switch (_o.label) {
|
|
1273
1617
|
case 0:
|
|
1274
|
-
name = "
|
|
1618
|
+
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
1275
1619
|
title = currentTemplate.title;
|
|
1276
|
-
priority =
|
|
1620
|
+
priority = pipeline.promptTemplates.length - pipeline.promptTemplates.indexOf(currentTemplate);
|
|
1277
1621
|
if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
1278
1622
|
return [4 /*yield*/, onProgress({
|
|
1279
1623
|
name: name,
|
|
@@ -1330,9 +1674,9 @@ function createPromptbookExecutor(options) {
|
|
|
1330
1674
|
case 6:
|
|
1331
1675
|
prompt = {
|
|
1332
1676
|
title: currentTemplate.title,
|
|
1333
|
-
|
|
1334
|
-
?
|
|
1335
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous
|
|
1677
|
+
pipelineUrl: "".concat(pipeline.pipelineUrl
|
|
1678
|
+
? pipeline.pipelineUrl
|
|
1679
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
1336
1680
|
parameters: parametersToPass,
|
|
1337
1681
|
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
1338
1682
|
modelRequirements: currentTemplate.modelRequirements,
|
|
@@ -1609,7 +1953,7 @@ function createPromptbookExecutor(options) {
|
|
|
1609
1953
|
// TODO: [🧠] Maybe put other executionTypes into report
|
|
1610
1954
|
executionReport.promptExecutions.push({
|
|
1611
1955
|
prompt: {
|
|
1612
|
-
title: currentTemplate.title /* <- Note: If title in
|
|
1956
|
+
title: currentTemplate.title /* <- Note: If title in pipeline contains emojis, pass it innto report */,
|
|
1613
1957
|
content: prompt.content,
|
|
1614
1958
|
modelRequirements: prompt.modelRequirements,
|
|
1615
1959
|
expectations: prompt.expectations,
|
|
@@ -1645,7 +1989,7 @@ function createPromptbookExecutor(options) {
|
|
|
1645
1989
|
// <- [3]
|
|
1646
1990
|
});
|
|
1647
1991
|
}
|
|
1648
|
-
parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because
|
|
1992
|
+
parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _m));
|
|
1649
1993
|
return [2 /*return*/];
|
|
1650
1994
|
}
|
|
1651
1995
|
});
|
|
@@ -1658,17 +2002,17 @@ function createPromptbookExecutor(options) {
|
|
|
1658
2002
|
case 0:
|
|
1659
2003
|
parametersToPass = inputParameters;
|
|
1660
2004
|
executionReport = {
|
|
1661
|
-
|
|
1662
|
-
title:
|
|
2005
|
+
pipelineUrl: pipeline.pipelineUrl,
|
|
2006
|
+
title: pipeline.title,
|
|
1663
2007
|
promptbookUsedVersion: PROMPTBOOK_VERSION,
|
|
1664
|
-
promptbookRequestedVersion:
|
|
1665
|
-
description:
|
|
2008
|
+
promptbookRequestedVersion: pipeline.promptbookVersion,
|
|
2009
|
+
description: pipeline.description,
|
|
1666
2010
|
promptExecutions: [],
|
|
1667
2011
|
};
|
|
1668
2012
|
_d.label = 1;
|
|
1669
2013
|
case 1:
|
|
1670
2014
|
_d.trys.push([1, 6, , 7]);
|
|
1671
|
-
resovedParameters_1 =
|
|
2015
|
+
resovedParameters_1 = pipeline.parameters
|
|
1672
2016
|
.filter(function (_a) {
|
|
1673
2017
|
var isInput = _a.isInput;
|
|
1674
2018
|
return isInput;
|
|
@@ -1677,7 +2021,7 @@ function createPromptbookExecutor(options) {
|
|
|
1677
2021
|
var name = _a.name;
|
|
1678
2022
|
return name;
|
|
1679
2023
|
});
|
|
1680
|
-
unresovedTemplates = __spreadArray([], __read(
|
|
2024
|
+
unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
1681
2025
|
resolving_1 = [];
|
|
1682
2026
|
loopLimit = LOOP_LIMIT;
|
|
1683
2027
|
_loop_1 = function () {
|
|
@@ -1686,7 +2030,7 @@ function createPromptbookExecutor(options) {
|
|
|
1686
2030
|
switch (_e.label) {
|
|
1687
2031
|
case 0:
|
|
1688
2032
|
if (loopLimit-- < 0) {
|
|
1689
|
-
throw new UnexpectedError('Loop limit reached during resolving parameters
|
|
2033
|
+
throw new UnexpectedError('Loop limit reached during resolving parameters pipeline execution');
|
|
1690
2034
|
}
|
|
1691
2035
|
currentTemplate = unresovedTemplates.find(function (template) {
|
|
1692
2036
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
@@ -1735,177 +2079,52 @@ function createPromptbookExecutor(options) {
|
|
|
1735
2079
|
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1736
2080
|
})), false));
|
|
1737
2081
|
return [2 /*return*/, {
|
|
1738
|
-
isSuccessful: false,
|
|
1739
|
-
errors: [error_1],
|
|
1740
|
-
usage: usage_1,
|
|
1741
|
-
executionReport: executionReport,
|
|
1742
|
-
outputParameters: parametersToPass,
|
|
1743
|
-
}];
|
|
1744
|
-
case 7:
|
|
1745
|
-
try {
|
|
1746
|
-
// Note: Filter ONLY output parameters
|
|
1747
|
-
for (_a = __values(
|
|
1748
|
-
parameter = _b.value;
|
|
1749
|
-
if (parameter.isOutput) {
|
|
1750
|
-
continue;
|
|
1751
|
-
}
|
|
1752
|
-
delete parametersToPass[parameter.name];
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1756
|
-
finally {
|
|
1757
|
-
try {
|
|
1758
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1759
|
-
}
|
|
1760
|
-
finally { if (e_1) throw e_1.error; }
|
|
1761
|
-
}
|
|
1762
|
-
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1763
|
-
var result = _a.result;
|
|
1764
|
-
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1765
|
-
})), false));
|
|
1766
|
-
return [2 /*return*/, {
|
|
1767
|
-
isSuccessful: true,
|
|
1768
|
-
errors: [],
|
|
1769
|
-
usage: usage,
|
|
1770
|
-
executionReport: executionReport,
|
|
1771
|
-
outputParameters: parametersToPass,
|
|
1772
|
-
}];
|
|
1773
|
-
}
|
|
1774
|
-
});
|
|
1775
|
-
}); };
|
|
1776
|
-
return promptbookExecutor;
|
|
1777
|
-
}
|
|
1778
|
-
/**
|
|
1779
|
-
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
1780
|
-
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
1781
|
-
* Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
|
|
1782
|
-
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
1783
|
-
*/
|
|
1784
|
-
|
|
1785
|
-
/**
|
|
1786
|
-
* This error indicates that promptbook not found in the library
|
|
1787
|
-
*/
|
|
1788
|
-
var NotFoundError = /** @class */ (function (_super) {
|
|
1789
|
-
__extends(NotFoundError, _super);
|
|
1790
|
-
function NotFoundError(message) {
|
|
1791
|
-
var _this = _super.call(this, message) || this;
|
|
1792
|
-
_this.name = 'NotFoundError';
|
|
1793
|
-
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
1794
|
-
return _this;
|
|
1795
|
-
}
|
|
1796
|
-
return NotFoundError;
|
|
1797
|
-
}(Error));
|
|
1798
|
-
|
|
1799
|
-
/**
|
|
1800
|
-
* This error indicates errors in referencing promptbooks between each other
|
|
1801
|
-
*/
|
|
1802
|
-
var ReferenceError$1 = /** @class */ (function (_super) {
|
|
1803
|
-
__extends(ReferenceError, _super);
|
|
1804
|
-
function ReferenceError(message) {
|
|
1805
|
-
var _this = _super.call(this, message) || this;
|
|
1806
|
-
_this.name = 'ReferenceError';
|
|
1807
|
-
Object.setPrototypeOf(_this, ReferenceError.prototype);
|
|
1808
|
-
return _this;
|
|
1809
|
-
}
|
|
1810
|
-
return ReferenceError;
|
|
1811
|
-
}(Error));
|
|
1812
|
-
|
|
1813
|
-
/**
|
|
1814
|
-
* Library of promptbooks that groups together promptbooks for an application.
|
|
1815
|
-
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
1816
|
-
*
|
|
1817
|
-
* @private use `createCollectionFromJson` instead
|
|
1818
|
-
* @see https://github.com/webgptorg/promptbook#promptbook-collection
|
|
1819
|
-
*/
|
|
1820
|
-
var SimplePipelineCollection = /** @class */ (function () {
|
|
1821
|
-
/**
|
|
1822
|
-
* Constructs a promptbook library from promptbooks
|
|
1823
|
-
*
|
|
1824
|
-
* @param promptbooks !!!
|
|
1825
|
-
*
|
|
1826
|
-
* @private Use instead `createCollectionFromJson`
|
|
1827
|
-
* Note: During the construction logic of all promptbooks are validated
|
|
1828
|
-
* Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
|
|
1829
|
-
*/
|
|
1830
|
-
function SimplePipelineCollection() {
|
|
1831
|
-
var e_1, _a;
|
|
1832
|
-
var promptbooks = [];
|
|
1833
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1834
|
-
promptbooks[_i] = arguments[_i];
|
|
1835
|
-
}
|
|
1836
|
-
this.library = new Map();
|
|
1837
|
-
try {
|
|
1838
|
-
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
1839
|
-
var promptbook = promptbooks_1_1.value;
|
|
1840
|
-
if (promptbook.promptbookUrl === undefined) {
|
|
1841
|
-
throw new ReferenceError$1(spaceTrim$1("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
|
|
1842
|
-
}
|
|
1843
|
-
validatePipeline(promptbook);
|
|
1844
|
-
// Note: [🦄]
|
|
1845
|
-
if (this.library.has(promptbook.promptbookUrl) &&
|
|
1846
|
-
pipelineJsonToString(promptbook) !== pipelineJsonToString(this.library.get(promptbook.promptbookUrl))) {
|
|
1847
|
-
throw new ReferenceError$1(spaceTrim$1("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
|
|
1848
|
-
}
|
|
1849
|
-
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1853
|
-
finally {
|
|
1854
|
-
try {
|
|
1855
|
-
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
1856
|
-
}
|
|
1857
|
-
finally { if (e_1) throw e_1.error; }
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
/**
|
|
1861
|
-
* Gets all promptbooks in the library
|
|
1862
|
-
*/
|
|
1863
|
-
SimplePipelineCollection.prototype.listPipelines = function () {
|
|
1864
|
-
return Array.from(this.library.keys());
|
|
1865
|
-
};
|
|
1866
|
-
/**
|
|
1867
|
-
* Gets promptbook by its URL
|
|
1868
|
-
*
|
|
1869
|
-
* Note: This is not a direct fetching from the URL, but a lookup in the library
|
|
1870
|
-
*/
|
|
1871
|
-
SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
|
|
1872
|
-
var _this = this;
|
|
1873
|
-
var promptbook = this.library.get(url);
|
|
1874
|
-
if (!promptbook) {
|
|
1875
|
-
if (this.listPipelines().length === 0) {
|
|
1876
|
-
throw new NotFoundError(spaceTrim$1("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
2082
|
+
isSuccessful: false,
|
|
2083
|
+
errors: [error_1],
|
|
2084
|
+
usage: usage_1,
|
|
2085
|
+
executionReport: executionReport,
|
|
2086
|
+
outputParameters: parametersToPass,
|
|
2087
|
+
}];
|
|
2088
|
+
case 7:
|
|
2089
|
+
try {
|
|
2090
|
+
// Note: Filter ONLY output parameters
|
|
2091
|
+
for (_a = __values(pipeline.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
2092
|
+
parameter = _b.value;
|
|
2093
|
+
if (parameter.isOutput) {
|
|
2094
|
+
continue;
|
|
2095
|
+
}
|
|
2096
|
+
delete parametersToPass[parameter.name];
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2100
|
+
finally {
|
|
2101
|
+
try {
|
|
2102
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2103
|
+
}
|
|
2104
|
+
finally { if (e_1) throw e_1.error; }
|
|
2105
|
+
}
|
|
2106
|
+
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
2107
|
+
var result = _a.result;
|
|
2108
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
2109
|
+
})), false));
|
|
2110
|
+
return [2 /*return*/, {
|
|
2111
|
+
isSuccessful: true,
|
|
2112
|
+
errors: [],
|
|
2113
|
+
usage: usage,
|
|
2114
|
+
executionReport: executionReport,
|
|
2115
|
+
outputParameters: parametersToPass,
|
|
2116
|
+
}];
|
|
1877
2117
|
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
return promptbook;
|
|
1883
|
-
};
|
|
1884
|
-
/**
|
|
1885
|
-
* Checks whether given prompt was defined in any promptbook in the library
|
|
1886
|
-
*/
|
|
1887
|
-
SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
|
|
1888
|
-
return true;
|
|
1889
|
-
};
|
|
1890
|
-
return SimplePipelineCollection;
|
|
1891
|
-
}());
|
|
1892
|
-
|
|
2118
|
+
});
|
|
2119
|
+
}); };
|
|
2120
|
+
return pipelineExecutor;
|
|
2121
|
+
}
|
|
1893
2122
|
/**
|
|
1894
|
-
*
|
|
1895
|
-
*
|
|
1896
|
-
* Note:
|
|
1897
|
-
*
|
|
1898
|
-
*
|
|
1899
|
-
* @param promptbookSources
|
|
1900
|
-
* @returns PipelineCollection
|
|
2123
|
+
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2124
|
+
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2125
|
+
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2126
|
+
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
1901
2127
|
*/
|
|
1902
|
-
function createCollectionFromJson() {
|
|
1903
|
-
var promptbooks = [];
|
|
1904
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1905
|
-
promptbooks[_i] = arguments[_i];
|
|
1906
|
-
}
|
|
1907
|
-
return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
1908
|
-
}
|
|
1909
2128
|
|
|
1910
2129
|
/* tslint:disable */
|
|
1911
2130
|
function normalizeToKebabCase(sentence) {
|
|
@@ -1964,18 +2183,18 @@ function normalizeToKebabCase(sentence) {
|
|
|
1964
2183
|
|
|
1965
2184
|
function prepareKnowledgeFromMarkdown(options) {
|
|
1966
2185
|
return __awaiter(this, void 0, void 0, function () {
|
|
1967
|
-
var content, llmTools, _a, isVerbose,
|
|
2186
|
+
var content, llmTools, _a, isVerbose, collection, prepareKnowledgeFromMarkdownPromptbook, prepareKnowledgeFromMarkdownExecutor, prepareKeywordsPromptbook, prepareKeywordsExecutor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
1968
2187
|
var _this = this;
|
|
1969
2188
|
return __generator(this, function (_b) {
|
|
1970
2189
|
switch (_b.label) {
|
|
1971
2190
|
case 0:
|
|
1972
2191
|
content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
1973
|
-
|
|
1974
|
-
return [4 /*yield*/,
|
|
2192
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2193
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
1975
2194
|
case 1:
|
|
1976
2195
|
prepareKnowledgeFromMarkdownPromptbook = _b.sent();
|
|
1977
|
-
prepareKnowledgeFromMarkdownExecutor =
|
|
1978
|
-
|
|
2196
|
+
prepareKnowledgeFromMarkdownExecutor = createPipelineExecutor({
|
|
2197
|
+
pipeline: prepareKnowledgeFromMarkdownPromptbook,
|
|
1979
2198
|
tools: {
|
|
1980
2199
|
llm: llmTools,
|
|
1981
2200
|
script: [
|
|
@@ -1983,11 +2202,11 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
1983
2202
|
],
|
|
1984
2203
|
},
|
|
1985
2204
|
});
|
|
1986
|
-
return [4 /*yield*/,
|
|
2205
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-keywords.ptbk.md')];
|
|
1987
2206
|
case 2:
|
|
1988
2207
|
prepareKeywordsPromptbook = _b.sent();
|
|
1989
|
-
prepareKeywordsExecutor =
|
|
1990
|
-
|
|
2208
|
+
prepareKeywordsExecutor = createPipelineExecutor({
|
|
2209
|
+
pipeline: prepareKeywordsPromptbook,
|
|
1991
2210
|
tools: {
|
|
1992
2211
|
llm: llmTools,
|
|
1993
2212
|
script: [
|
|
@@ -2681,28 +2900,31 @@ function parseCommand(listItem) {
|
|
|
2681
2900
|
.map(function (part) { return part.trim(); })
|
|
2682
2901
|
.filter(function (item) { return item !== ''; })
|
|
2683
2902
|
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
2903
|
+
.filter(function (item) { return !/^PIPELINE$/i.test(item); })
|
|
2684
2904
|
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
2685
2905
|
.map(removeMarkdownFormatting);
|
|
2686
2906
|
if (type.startsWith('URL') ||
|
|
2687
2907
|
type.startsWith('PTBK_URL') ||
|
|
2688
2908
|
type.startsWith('PTBKURL') ||
|
|
2909
|
+
type.startsWith('PIPELINE_URL') ||
|
|
2910
|
+
type.startsWith('PIPELINEURL') ||
|
|
2689
2911
|
type.startsWith('PROMPTBOOK_URL') ||
|
|
2690
2912
|
type.startsWith('PROMPTBOOKURL') ||
|
|
2691
2913
|
type.startsWith('HTTPS')) {
|
|
2692
2914
|
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
2693
|
-
throw new SyntaxError(spaceTrim$1("\n Invalid
|
|
2915
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PIPELINE_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
2694
2916
|
}
|
|
2695
|
-
var
|
|
2696
|
-
var
|
|
2697
|
-
if (
|
|
2698
|
-
throw new SyntaxError(spaceTrim$1("\n Invalid
|
|
2917
|
+
var pipelineUrlString = listItemParts.pop();
|
|
2918
|
+
var pipelineUrl = new URL(pipelineUrlString);
|
|
2919
|
+
if (pipelineUrl.protocol !== 'https:') {
|
|
2920
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PIPELINE_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
2699
2921
|
}
|
|
2700
|
-
if (
|
|
2701
|
-
throw new SyntaxError(spaceTrim$1("\n Invalid
|
|
2922
|
+
if (pipelineUrl.hash !== '') {
|
|
2923
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PIPELINE_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
|
|
2702
2924
|
}
|
|
2703
2925
|
return {
|
|
2704
|
-
type: '
|
|
2705
|
-
|
|
2926
|
+
type: 'PIPELINE_URL',
|
|
2927
|
+
pipelineUrl: pipelineUrl,
|
|
2706
2928
|
};
|
|
2707
2929
|
}
|
|
2708
2930
|
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
@@ -2894,7 +3116,7 @@ function parseCommand(listItem) {
|
|
|
2894
3116
|
*/
|
|
2895
3117
|
}
|
|
2896
3118
|
else {
|
|
2897
|
-
throw new SyntaxError(spaceTrim$1("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n -
|
|
3119
|
+
throw new SyntaxError(spaceTrim$1("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PIPELINE_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
|
|
2898
3120
|
}
|
|
2899
3121
|
}
|
|
2900
3122
|
|
|
@@ -2943,7 +3165,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
2943
3165
|
var pipelineJson = {
|
|
2944
3166
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2945
3167
|
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
2946
|
-
|
|
3168
|
+
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
2947
3169
|
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2948
3170
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
2949
3171
|
parameters: [],
|
|
@@ -3006,8 +3228,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
3006
3228
|
var listItem = listItems_1_1.value;
|
|
3007
3229
|
var command = parseCommand(listItem);
|
|
3008
3230
|
switch (command.type) {
|
|
3009
|
-
case '
|
|
3010
|
-
pipelineJson.
|
|
3231
|
+
case 'PIPELINE_URL':
|
|
3232
|
+
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
3011
3233
|
break;
|
|
3012
3234
|
case 'PROMPTBOOK_VERSION':
|
|
3013
3235
|
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
@@ -3362,7 +3584,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
3362
3584
|
return promptbookMermaid;
|
|
3363
3585
|
}
|
|
3364
3586
|
/**
|
|
3365
|
-
* TODO: Maybe use some Mermaid
|
|
3587
|
+
* TODO: Maybe use some Mermaid package instead of string templating
|
|
3366
3588
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
3367
3589
|
*/
|
|
3368
3590
|
|
|
@@ -3401,12 +3623,12 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
3401
3623
|
});
|
|
3402
3624
|
}
|
|
3403
3625
|
/**
|
|
3404
|
-
* TODO: Maybe use some Mermaid
|
|
3626
|
+
* TODO: Maybe use some Mermaid package instead of string templating
|
|
3405
3627
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
3406
3628
|
*/
|
|
3407
3629
|
|
|
3408
3630
|
/**
|
|
3409
|
-
* This error indicates that the
|
|
3631
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
3410
3632
|
*/
|
|
3411
3633
|
var CollectionError = /** @class */ (function (_super) {
|
|
3412
3634
|
__extends(CollectionError, _super);
|
|
@@ -3507,225 +3729,6 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
|
3507
3729
|
return SimplePromptInterfaceTools;
|
|
3508
3730
|
}());
|
|
3509
3731
|
|
|
3510
|
-
/**
|
|
3511
|
-
* Constructs Promptbook from async sources
|
|
3512
|
-
* It can be one of the following:
|
|
3513
|
-
* - Promise of array of PipelineJson or PipelineString
|
|
3514
|
-
* - Factory function that returns Promise of array of PipelineJson or PipelineString
|
|
3515
|
-
*
|
|
3516
|
-
* Note: This is useful as internal tool for other constructor functions like
|
|
3517
|
-
* `createCollectionFromUrl` or `createCollectionFromDirectory`
|
|
3518
|
-
* Consider using those functions instead of this one
|
|
3519
|
-
*
|
|
3520
|
-
* Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
|
|
3521
|
-
* when error occurs in given promise or factory function, it is thrown during `listPipelines` or `getPipelineByUrl` call
|
|
3522
|
-
*
|
|
3523
|
-
* Note: Consider using `createCollectionFromDirectory` or `createCollectionFromUrl`
|
|
3524
|
-
*
|
|
3525
|
-
* @param promptbookSourcesPromiseOrFactory
|
|
3526
|
-
* @returns PipelineCollection
|
|
3527
|
-
* @deprecated Do not use, it will became internal tool for other constructor functions
|
|
3528
|
-
*/
|
|
3529
|
-
function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
3530
|
-
var library;
|
|
3531
|
-
function forSources() {
|
|
3532
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3533
|
-
var promptbookSources;
|
|
3534
|
-
return __generator(this, function (_a) {
|
|
3535
|
-
switch (_a.label) {
|
|
3536
|
-
case 0:
|
|
3537
|
-
if (typeof promptbookSourcesPromiseOrFactory === 'function') {
|
|
3538
|
-
// Note: Calling factory function only once despite multiple calls to resolveSources
|
|
3539
|
-
promptbookSourcesPromiseOrFactory = promptbookSourcesPromiseOrFactory();
|
|
3540
|
-
}
|
|
3541
|
-
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
3542
|
-
case 1:
|
|
3543
|
-
promptbookSources = _a.sent();
|
|
3544
|
-
library = createCollectionFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false));
|
|
3545
|
-
return [2 /*return*/];
|
|
3546
|
-
}
|
|
3547
|
-
});
|
|
3548
|
-
});
|
|
3549
|
-
}
|
|
3550
|
-
function listPipelines() {
|
|
3551
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3552
|
-
return __generator(this, function (_a) {
|
|
3553
|
-
switch (_a.label) {
|
|
3554
|
-
case 0: return [4 /*yield*/, forSources()];
|
|
3555
|
-
case 1:
|
|
3556
|
-
_a.sent();
|
|
3557
|
-
return [2 /*return*/, /* not await */ library.listPipelines()];
|
|
3558
|
-
}
|
|
3559
|
-
});
|
|
3560
|
-
});
|
|
3561
|
-
}
|
|
3562
|
-
function getPipelineByUrl(url) {
|
|
3563
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3564
|
-
return __generator(this, function (_a) {
|
|
3565
|
-
switch (_a.label) {
|
|
3566
|
-
case 0: return [4 /*yield*/, forSources()];
|
|
3567
|
-
case 1:
|
|
3568
|
-
_a.sent();
|
|
3569
|
-
return [2 /*return*/, /* not await */ library.getPipelineByUrl(url)];
|
|
3570
|
-
}
|
|
3571
|
-
});
|
|
3572
|
-
});
|
|
3573
|
-
}
|
|
3574
|
-
function isResponsibleForPrompt(prompt) {
|
|
3575
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3576
|
-
return __generator(this, function (_a) {
|
|
3577
|
-
switch (_a.label) {
|
|
3578
|
-
case 0: return [4 /*yield*/, forSources()];
|
|
3579
|
-
case 1:
|
|
3580
|
-
_a.sent();
|
|
3581
|
-
return [2 /*return*/, /* not await */ library.isResponsibleForPrompt(prompt)];
|
|
3582
|
-
}
|
|
3583
|
-
});
|
|
3584
|
-
});
|
|
3585
|
-
}
|
|
3586
|
-
return {
|
|
3587
|
-
listPipelines: listPipelines,
|
|
3588
|
-
getPipelineByUrl: getPipelineByUrl,
|
|
3589
|
-
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3590
|
-
};
|
|
3591
|
-
}
|
|
3592
|
-
|
|
3593
|
-
/**
|
|
3594
|
-
* Constructs Promptbook from remote Promptbase URL
|
|
3595
|
-
|
|
3596
|
-
* @returns PipelineCollection
|
|
3597
|
-
*/
|
|
3598
|
-
function createCollectionFromUrl(url, options) {
|
|
3599
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3600
|
-
var _a, _b, isVerbose, _c, isLazyLoaded, library;
|
|
3601
|
-
var _this = this;
|
|
3602
|
-
return __generator(this, function (_d) {
|
|
3603
|
-
switch (_d.label) {
|
|
3604
|
-
case 0:
|
|
3605
|
-
_a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
|
|
3606
|
-
library = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3607
|
-
return __generator(this, function (_a) {
|
|
3608
|
-
if (isVerbose) {
|
|
3609
|
-
console.info("Creating promptbook library from url ".concat(url.toString()));
|
|
3610
|
-
}
|
|
3611
|
-
throw new Error('Not implemented yet');
|
|
3612
|
-
});
|
|
3613
|
-
}); });
|
|
3614
|
-
if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
|
|
3615
|
-
return [4 /*yield*/, library.listPipelines()];
|
|
3616
|
-
case 1:
|
|
3617
|
-
_d.sent();
|
|
3618
|
-
_d.label = 2;
|
|
3619
|
-
case 2: return [2 /*return*/, library];
|
|
3620
|
-
}
|
|
3621
|
-
});
|
|
3622
|
-
});
|
|
3623
|
-
}
|
|
3624
|
-
/**
|
|
3625
|
-
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3626
|
-
*/
|
|
3627
|
-
|
|
3628
|
-
/**
|
|
3629
|
-
* Creates PipelineCollection as a subset of another PipelineCollection
|
|
3630
|
-
*
|
|
3631
|
-
* Note: You can use any type of library as a parent library - local, remote, etc.
|
|
3632
|
-
* Note: This is just a thin wrapper / proxy around the parent library
|
|
3633
|
-
*
|
|
3634
|
-
* @param promptbookSources
|
|
3635
|
-
* @returns PipelineCollection
|
|
3636
|
-
*/
|
|
3637
|
-
function createSubcollection(library, predicate) {
|
|
3638
|
-
function listPipelines() {
|
|
3639
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3640
|
-
var promptbooks;
|
|
3641
|
-
return __generator(this, function (_a) {
|
|
3642
|
-
switch (_a.label) {
|
|
3643
|
-
case 0: return [4 /*yield*/, library.listPipelines()];
|
|
3644
|
-
case 1:
|
|
3645
|
-
promptbooks = _a.sent();
|
|
3646
|
-
promptbooks = promptbooks.filter(predicate);
|
|
3647
|
-
return [2 /*return*/, promptbooks];
|
|
3648
|
-
}
|
|
3649
|
-
});
|
|
3650
|
-
});
|
|
3651
|
-
}
|
|
3652
|
-
function getPipelineByUrl(url) {
|
|
3653
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3654
|
-
var _a, promptbook;
|
|
3655
|
-
var _this = this;
|
|
3656
|
-
return __generator(this, function (_b) {
|
|
3657
|
-
switch (_b.label) {
|
|
3658
|
-
case 0:
|
|
3659
|
-
if (!!predicate(url)) return [3 /*break*/, 2];
|
|
3660
|
-
_a = NotFoundError.bind;
|
|
3661
|
-
return [4 /*yield*/, spaceTrim$1(function (block) { return __awaiter(_this, void 0, void 0, function () {
|
|
3662
|
-
var _a, _b, _c, _d, _e, _f;
|
|
3663
|
-
return __generator(this, function (_g) {
|
|
3664
|
-
switch (_g.label) {
|
|
3665
|
-
case 0:
|
|
3666
|
-
_c = (_b = "\n Promptbook with url \"".concat(url, "\" not found or not accessible\n\n Available promptbooks:\n ")).concat;
|
|
3667
|
-
_d = block;
|
|
3668
|
-
return [4 /*yield*/, listPipelines()];
|
|
3669
|
-
case 1:
|
|
3670
|
-
_e = (_a = _c.apply(_b, [_d.apply(void 0, [(_g.sent()).map(function (promptbookUrl) { return "- ".concat(promptbookUrl); }).join('\n')]), "\n\n All available promptbooks in parent library:\n "])).concat;
|
|
3671
|
-
_f = block;
|
|
3672
|
-
return [4 /*yield*/, library.listPipelines()];
|
|
3673
|
-
case 2: return [2 /*return*/, _e.apply(_a, [_f.apply(void 0, [(_g.sent()).map(function (promptbookUrl) { return "- ".concat(promptbookUrl); }).join('\n')]), "\n\n "])];
|
|
3674
|
-
}
|
|
3675
|
-
});
|
|
3676
|
-
}); })];
|
|
3677
|
-
case 1: throw new (_a.apply(NotFoundError, [void 0, _b.sent()]))();
|
|
3678
|
-
case 2: return [4 /*yield*/, library.getPipelineByUrl(url)];
|
|
3679
|
-
case 3:
|
|
3680
|
-
promptbook = _b.sent();
|
|
3681
|
-
return [2 /*return*/, promptbook];
|
|
3682
|
-
}
|
|
3683
|
-
});
|
|
3684
|
-
});
|
|
3685
|
-
}
|
|
3686
|
-
function isResponsibleForPrompt(prompt) {
|
|
3687
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3688
|
-
var isResponsible;
|
|
3689
|
-
return __generator(this, function (_a) {
|
|
3690
|
-
switch (_a.label) {
|
|
3691
|
-
case 0: return [4 /*yield*/, library.isResponsibleForPrompt(prompt)];
|
|
3692
|
-
case 1:
|
|
3693
|
-
isResponsible = _a.sent();
|
|
3694
|
-
// TODO: !! Only if responsible, check if predicate is true
|
|
3695
|
-
return [2 /*return*/, isResponsible];
|
|
3696
|
-
}
|
|
3697
|
-
});
|
|
3698
|
-
});
|
|
3699
|
-
}
|
|
3700
|
-
return {
|
|
3701
|
-
listPipelines: listPipelines,
|
|
3702
|
-
getPipelineByUrl: getPipelineByUrl,
|
|
3703
|
-
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3704
|
-
};
|
|
3705
|
-
}
|
|
3706
|
-
|
|
3707
|
-
/**
|
|
3708
|
-
* Converts PipelineCollection to serialized JSON
|
|
3709
|
-
*
|
|
3710
|
-
* Note: Functions `libraryToJson` and `createCollectionFromJson` are complementary
|
|
3711
|
-
*/
|
|
3712
|
-
function libraryToJson(library) {
|
|
3713
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3714
|
-
var promptbookUrls, promptbooks;
|
|
3715
|
-
return __generator(this, function (_a) {
|
|
3716
|
-
switch (_a.label) {
|
|
3717
|
-
case 0: return [4 /*yield*/, library.listPipelines()];
|
|
3718
|
-
case 1:
|
|
3719
|
-
promptbookUrls = _a.sent();
|
|
3720
|
-
return [4 /*yield*/, Promise.all(promptbookUrls.map(function (url) { return library.getPipelineByUrl(url); }))];
|
|
3721
|
-
case 2:
|
|
3722
|
-
promptbooks = _a.sent();
|
|
3723
|
-
return [2 /*return*/, promptbooks];
|
|
3724
|
-
}
|
|
3725
|
-
});
|
|
3726
|
-
});
|
|
3727
|
-
}
|
|
3728
|
-
|
|
3729
3732
|
/**
|
|
3730
3733
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
3731
3734
|
*
|
|
@@ -3958,7 +3961,7 @@ function escapeMarkdownBlock(value) {
|
|
|
3958
3961
|
}
|
|
3959
3962
|
|
|
3960
3963
|
/**
|
|
3961
|
-
* The thresholds for the relative time in the `moment`
|
|
3964
|
+
* The thresholds for the relative time in the `moment` NPM package.
|
|
3962
3965
|
*
|
|
3963
3966
|
* @see https://momentjscom.readthedocs.io/en/latest/moment/07-customization/13-relative-time-threshold/
|
|
3964
3967
|
*/
|
|
@@ -4008,8 +4011,8 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
4008
4011
|
var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
|
|
4009
4012
|
var executionReportString = spaceTrim$1(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
4010
4013
|
var headerList = [];
|
|
4011
|
-
if (executionReportJson.
|
|
4012
|
-
headerList.push("
|
|
4014
|
+
if (executionReportJson.pipelineUrl) {
|
|
4015
|
+
headerList.push("PIPELINE URL ".concat(executionReportJson.pipelineUrl));
|
|
4013
4016
|
}
|
|
4014
4017
|
headerList.push("PROMPTBOOK VERSION ".concat(executionReportJson.promptbookUsedVersion) +
|
|
4015
4018
|
(!executionReportJson.promptbookRequestedVersion
|
|
@@ -4160,5 +4163,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
4160
4163
|
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
4161
4164
|
*/
|
|
4162
4165
|
|
|
4163
|
-
export { CallbackInterfaceTools, CollectionError, ExecutionError, ExecutionReportStringOptionsDefaults, ExecutionTypes, ExpectError, MultipleLlmExecutionTools, NotFoundError, PROMPTBOOK_VERSION, PipelineLogicError, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, SyntaxError, TemplateError, UnexpectedError, addUsage, assertsExecutionSuccessful, checkExpectations, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl,
|
|
4166
|
+
export { CallbackInterfaceTools, CollectionError, ExecutionError, ExecutionReportStringOptionsDefaults, ExecutionTypes, ExpectError, MultipleLlmExecutionTools, NotFoundError, PROMPTBOOK_VERSION, PipelineLogicError, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, SyntaxError, TemplateError, UnexpectedError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection as createSublibrary, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prettifyPipelineString, usageToWorktime, validatePipeline };
|
|
4164
4167
|
//# sourceMappingURL=index.es.js.map
|