@promptbook/cli 0.61.0-18 → 0.61.0-19

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/umd/index.umd.js CHANGED
@@ -154,7 +154,7 @@
154
154
  /**
155
155
  * The version of the Promptbook library
156
156
  */
157
- var PROMPTBOOK_VERSION = '0.61.0-17';
157
+ var PROMPTBOOK_VERSION = '0.61.0-18';
158
158
  // TODO: !!!! List here all the versions and annotate + put into script
159
159
 
160
160
  /**
@@ -304,200 +304,6 @@
304
304
  * TODO: [🔼] Export all to core
305
305
  */
306
306
 
307
- /**
308
- * @@@
309
- */
310
- function deepClone(objectValue) {
311
- return JSON.parse(JSON.stringify(objectValue));
312
- /*
313
- TODO: [🧠] Is there a better implementation?
314
- > const propertyNames = Object.getOwnPropertyNames(objectValue);
315
- > for (const propertyName of propertyNames) {
316
- > const value = (objectValue as really_any)[propertyName];
317
- > if (value && typeof value === 'object') {
318
- > deepClone(value);
319
- > }
320
- > }
321
- > return Object.assign({}, objectValue);
322
- */
323
- }
324
- /**
325
- * TODO: [🔼] Export from `@promptbook/utils`
326
- * TODO: [🧠] Is there a way how to meaningfully test this utility
327
- */
328
-
329
- /**
330
- * @@@
331
- *
332
- * TODO: [🔼] Export with addUsage
333
- */
334
- var ZERO_USAGE = deepFreeze({
335
- price: { value: 0 },
336
- input: {
337
- tokensCount: { value: 0 },
338
- charactersCount: { value: 0 },
339
- wordsCount: { value: 0 },
340
- sentencesCount: { value: 0 },
341
- linesCount: { value: 0 },
342
- paragraphsCount: { value: 0 },
343
- pagesCount: { value: 0 },
344
- },
345
- output: {
346
- tokensCount: { value: 0 },
347
- charactersCount: { value: 0 },
348
- wordsCount: { value: 0 },
349
- sentencesCount: { value: 0 },
350
- linesCount: { value: 0 },
351
- paragraphsCount: { value: 0 },
352
- pagesCount: { value: 0 },
353
- },
354
- });
355
- /**
356
- * Function `addUsage` will add multiple usages into one
357
- *
358
- * Note: If you provide 0 values, it returns ZERO_USAGE
359
- */
360
- function addUsage() {
361
- var usageItems = [];
362
- for (var _i = 0; _i < arguments.length; _i++) {
363
- usageItems[_i] = arguments[_i];
364
- }
365
- return usageItems.reduce(function (acc, item) {
366
- var e_1, _a, e_2, _b;
367
- var _c;
368
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
369
- try {
370
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
371
- var key = _e.value;
372
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
373
- //@ts-ignore
374
- if (item.input[key]) {
375
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
376
- //@ts-ignore
377
- acc.input[key].value += item.input[key].value || 0;
378
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
379
- //@ts-ignore
380
- if (item.input[key].isUncertain) {
381
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
382
- //@ts-ignore
383
- acc.input[key].isUncertain = true;
384
- }
385
- }
386
- }
387
- }
388
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
389
- finally {
390
- try {
391
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
392
- }
393
- finally { if (e_1) throw e_1.error; }
394
- }
395
- try {
396
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
397
- var key = _g.value;
398
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
399
- //@ts-ignore
400
- if (item.output[key]) {
401
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
402
- //@ts-ignore
403
- acc.output[key].value += item.output[key].value || 0;
404
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
405
- //@ts-ignore
406
- if (item.output[key].isUncertain) {
407
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
408
- //@ts-ignore
409
- acc.output[key].isUncertain = true;
410
- }
411
- }
412
- }
413
- }
414
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
415
- finally {
416
- try {
417
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
418
- }
419
- finally { if (e_2) throw e_2.error; }
420
- }
421
- return acc;
422
- }, deepClone(ZERO_USAGE));
423
- }
424
-
425
- /**
426
- * Async version of Array.forEach
427
- *
428
- * @param array - Array to iterate over
429
- * @param options - Options for the function
430
- * @param callbackfunction - Function to call for each item
431
- */
432
- function forEachAsync(array, options, callbackfunction) {
433
- return __awaiter(this, void 0, void 0, function () {
434
- var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
435
- var e_1, _d;
436
- return __generator(this, function (_e) {
437
- switch (_e.label) {
438
- case 0:
439
- _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
440
- index = 0;
441
- runningTasks = [];
442
- tasks = [];
443
- _loop_1 = function (item) {
444
- var currentIndex, task;
445
- return __generator(this, function (_f) {
446
- switch (_f.label) {
447
- case 0:
448
- currentIndex = index++;
449
- task = callbackfunction(item, currentIndex, array);
450
- tasks.push(task);
451
- runningTasks.push(task);
452
- /* not await */ Promise.resolve(task).then(function () {
453
- runningTasks = runningTasks.filter(function (t) { return t !== task; });
454
- });
455
- if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
456
- return [4 /*yield*/, Promise.race(runningTasks)];
457
- case 1:
458
- _f.sent();
459
- _f.label = 2;
460
- case 2: return [2 /*return*/];
461
- }
462
- });
463
- };
464
- _e.label = 1;
465
- case 1:
466
- _e.trys.push([1, 6, 7, 8]);
467
- _b = __values(array), _c = _b.next();
468
- _e.label = 2;
469
- case 2:
470
- if (!!_c.done) return [3 /*break*/, 5];
471
- item = _c.value;
472
- return [5 /*yield**/, _loop_1(item)];
473
- case 3:
474
- _e.sent();
475
- _e.label = 4;
476
- case 4:
477
- _c = _b.next();
478
- return [3 /*break*/, 2];
479
- case 5: return [3 /*break*/, 8];
480
- case 6:
481
- e_1_1 = _e.sent();
482
- e_1 = { error: e_1_1 };
483
- return [3 /*break*/, 8];
484
- case 7:
485
- try {
486
- if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
487
- }
488
- finally { if (e_1) throw e_1.error; }
489
- return [7 /*endfinally*/];
490
- case 8: return [4 /*yield*/, Promise.all(tasks)];
491
- case 9:
492
- _e.sent();
493
- return [2 /*return*/];
494
- }
495
- });
496
- });
497
- }
498
-
499
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-17",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",dependentParameterNames:["content"],resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-17",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-17",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-17",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-17",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-17",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-17",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-17",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
500
-
501
307
  /**
502
308
  * Prettify the html code
503
309
  *
@@ -714,32 +520,226 @@
714
520
  pipelineString += '\n\n';
715
521
  pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
716
522
  }
717
- }
718
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
719
- finally {
720
- try {
721
- if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
523
+ }
524
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
525
+ finally {
526
+ try {
527
+ if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
528
+ }
529
+ finally { if (e_3) throw e_3.error; }
530
+ }
531
+ return pipelineString;
532
+ }
533
+ /**
534
+ * @private internal util of pipelineJsonToString
535
+ */
536
+ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
537
+ var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
538
+ var parameterString = "{".concat(name, "}");
539
+ if (description) {
540
+ parameterString = "".concat(parameterString, " ").concat(description);
541
+ }
542
+ return parameterString;
543
+ }
544
+ /**
545
+ * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
546
+ * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
547
+ * TODO: Escape all
548
+ */
549
+
550
+ /**
551
+ * @@@
552
+ */
553
+ function deepClone(objectValue) {
554
+ return JSON.parse(JSON.stringify(objectValue));
555
+ /*
556
+ TODO: [🧠] Is there a better implementation?
557
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
558
+ > for (const propertyName of propertyNames) {
559
+ > const value = (objectValue as really_any)[propertyName];
560
+ > if (value && typeof value === 'object') {
561
+ > deepClone(value);
562
+ > }
563
+ > }
564
+ > return Object.assign({}, objectValue);
565
+ */
566
+ }
567
+ /**
568
+ * TODO: [🔼] Export from `@promptbook/utils`
569
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
570
+ */
571
+
572
+ /**
573
+ * @@@
574
+ *
575
+ * TODO: [🔼] Export with addUsage
576
+ */
577
+ var ZERO_USAGE = deepFreeze({
578
+ price: { value: 0 },
579
+ input: {
580
+ tokensCount: { value: 0 },
581
+ charactersCount: { value: 0 },
582
+ wordsCount: { value: 0 },
583
+ sentencesCount: { value: 0 },
584
+ linesCount: { value: 0 },
585
+ paragraphsCount: { value: 0 },
586
+ pagesCount: { value: 0 },
587
+ },
588
+ output: {
589
+ tokensCount: { value: 0 },
590
+ charactersCount: { value: 0 },
591
+ wordsCount: { value: 0 },
592
+ sentencesCount: { value: 0 },
593
+ linesCount: { value: 0 },
594
+ paragraphsCount: { value: 0 },
595
+ pagesCount: { value: 0 },
596
+ },
597
+ });
598
+ /**
599
+ * Function `addUsage` will add multiple usages into one
600
+ *
601
+ * Note: If you provide 0 values, it returns ZERO_USAGE
602
+ */
603
+ function addUsage() {
604
+ var usageItems = [];
605
+ for (var _i = 0; _i < arguments.length; _i++) {
606
+ usageItems[_i] = arguments[_i];
607
+ }
608
+ return usageItems.reduce(function (acc, item) {
609
+ var e_1, _a, e_2, _b;
610
+ var _c;
611
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
612
+ try {
613
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
614
+ var key = _e.value;
615
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
616
+ //@ts-ignore
617
+ if (item.input[key]) {
618
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
619
+ //@ts-ignore
620
+ acc.input[key].value += item.input[key].value || 0;
621
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
622
+ //@ts-ignore
623
+ if (item.input[key].isUncertain) {
624
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
625
+ //@ts-ignore
626
+ acc.input[key].isUncertain = true;
627
+ }
628
+ }
629
+ }
630
+ }
631
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
632
+ finally {
633
+ try {
634
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
635
+ }
636
+ finally { if (e_1) throw e_1.error; }
637
+ }
638
+ try {
639
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
640
+ var key = _g.value;
641
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
642
+ //@ts-ignore
643
+ if (item.output[key]) {
644
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
645
+ //@ts-ignore
646
+ acc.output[key].value += item.output[key].value || 0;
647
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
648
+ //@ts-ignore
649
+ if (item.output[key].isUncertain) {
650
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
651
+ //@ts-ignore
652
+ acc.output[key].isUncertain = true;
653
+ }
654
+ }
655
+ }
656
+ }
657
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
658
+ finally {
659
+ try {
660
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
661
+ }
662
+ finally { if (e_2) throw e_2.error; }
722
663
  }
723
- finally { if (e_3) throw e_3.error; }
724
- }
725
- return pipelineString;
664
+ return acc;
665
+ }, deepClone(ZERO_USAGE));
726
666
  }
667
+
727
668
  /**
728
- * @private internal util of pipelineJsonToString
669
+ * Async version of Array.forEach
670
+ *
671
+ * @param array - Array to iterate over
672
+ * @param options - Options for the function
673
+ * @param callbackfunction - Function to call for each item
729
674
  */
730
- function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
731
- var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
732
- var parameterString = "{".concat(name, "}");
733
- if (description) {
734
- parameterString = "".concat(parameterString, " ").concat(description);
735
- }
736
- return parameterString;
675
+ function forEachAsync(array, options, callbackfunction) {
676
+ return __awaiter(this, void 0, void 0, function () {
677
+ var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
678
+ var e_1, _d;
679
+ return __generator(this, function (_e) {
680
+ switch (_e.label) {
681
+ case 0:
682
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
683
+ index = 0;
684
+ runningTasks = [];
685
+ tasks = [];
686
+ _loop_1 = function (item) {
687
+ var currentIndex, task;
688
+ return __generator(this, function (_f) {
689
+ switch (_f.label) {
690
+ case 0:
691
+ currentIndex = index++;
692
+ task = callbackfunction(item, currentIndex, array);
693
+ tasks.push(task);
694
+ runningTasks.push(task);
695
+ /* not await */ Promise.resolve(task).then(function () {
696
+ runningTasks = runningTasks.filter(function (t) { return t !== task; });
697
+ });
698
+ if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
699
+ return [4 /*yield*/, Promise.race(runningTasks)];
700
+ case 1:
701
+ _f.sent();
702
+ _f.label = 2;
703
+ case 2: return [2 /*return*/];
704
+ }
705
+ });
706
+ };
707
+ _e.label = 1;
708
+ case 1:
709
+ _e.trys.push([1, 6, 7, 8]);
710
+ _b = __values(array), _c = _b.next();
711
+ _e.label = 2;
712
+ case 2:
713
+ if (!!_c.done) return [3 /*break*/, 5];
714
+ item = _c.value;
715
+ return [5 /*yield**/, _loop_1(item)];
716
+ case 3:
717
+ _e.sent();
718
+ _e.label = 4;
719
+ case 4:
720
+ _c = _b.next();
721
+ return [3 /*break*/, 2];
722
+ case 5: return [3 /*break*/, 8];
723
+ case 6:
724
+ e_1_1 = _e.sent();
725
+ e_1 = { error: e_1_1 };
726
+ return [3 /*break*/, 8];
727
+ case 7:
728
+ try {
729
+ if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
730
+ }
731
+ finally { if (e_1) throw e_1.error; }
732
+ return [7 /*endfinally*/];
733
+ case 8: return [4 /*yield*/, Promise.all(tasks)];
734
+ case 9:
735
+ _e.sent();
736
+ return [2 /*return*/];
737
+ }
738
+ });
739
+ });
737
740
  }
738
- /**
739
- * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
740
- * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
741
- * TODO: Escape all
742
- */
741
+
742
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-18",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",dependentParameterNames:["content"],resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-18",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-18",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-18",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-18",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-18",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-18",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-18",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
743
743
 
744
744
  /**
745
745
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -1212,17 +1212,23 @@
1212
1212
  try {
1213
1213
  for (var pipelines_1 = __values(pipelines), pipelines_1_1 = pipelines_1.next(); !pipelines_1_1.done; pipelines_1_1 = pipelines_1.next()) {
1214
1214
  var pipeline = pipelines_1_1.value;
1215
+ // TODO: [👠] DRY
1215
1216
  if (pipeline.pipelineUrl === undefined) {
1216
1217
  throw new ReferenceError$1(spaceTrim.spaceTrim("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
1217
1218
  }
1219
+ // Note: [🐨]
1218
1220
  validatePipeline(pipeline);
1221
+ // TODO: [🦄] DRY
1219
1222
  // Note: [🦄]
1220
- if (this.collection.has(pipeline.pipelineUrl) &&
1223
+ if (
1224
+ // TODO: [🐽]
1225
+ this.collection.has(pipeline.pipelineUrl) &&
1221
1226
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
1222
1227
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1223
1228
  var existing = this.collection.get(pipeline.pipelineUrl);
1224
1229
  throw new ReferenceError$1(spaceTrim.spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
1225
1230
  }
1231
+ // Note: [🧠] Overwrite existing pipeline with the same URL
1226
1232
  this.collection.set(pipeline.pipelineUrl, pipeline);
1227
1233
  }
1228
1234
  }
@@ -1662,39 +1668,6 @@
1662
1668
  * TODO: [🧠] Can this return type be better typed than void
1663
1669
  */
1664
1670
 
1665
- /**
1666
- * Create difference set of two sets.
1667
- *
1668
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
1669
- */
1670
- function difference(a, b, isEqual) {
1671
- var e_1, _a;
1672
- if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
1673
- var diff = new Set();
1674
- var _loop_1 = function (itemA) {
1675
- if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
1676
- diff.add(itemA);
1677
- }
1678
- };
1679
- try {
1680
- for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
1681
- var itemA = _c.value;
1682
- _loop_1(itemA);
1683
- }
1684
- }
1685
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1686
- finally {
1687
- try {
1688
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1689
- }
1690
- finally { if (e_1) throw e_1.error; }
1691
- }
1692
- return diff;
1693
- }
1694
- /**
1695
- * TODO: [🧠][💯] Maybe also implement symmetricDifference
1696
- */
1697
-
1698
1671
  /**
1699
1672
  * Parses the template and returns the list of all parameter names
1700
1673
  *
@@ -1828,46 +1801,6 @@
1828
1801
  * TODO: [🔣] If script require contentLanguage
1829
1802
  */
1830
1803
 
1831
- /**
1832
- * Creates a new set with all elements that are present in either set
1833
- *
1834
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
1835
- */
1836
- function union() {
1837
- var e_1, _a, e_2, _b;
1838
- var sets = [];
1839
- for (var _i = 0; _i < arguments.length; _i++) {
1840
- sets[_i] = arguments[_i];
1841
- }
1842
- var union = new Set();
1843
- try {
1844
- for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
1845
- var set = sets_1_1.value;
1846
- try {
1847
- for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
1848
- var item = _d.value;
1849
- union.add(item);
1850
- }
1851
- }
1852
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1853
- finally {
1854
- try {
1855
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1856
- }
1857
- finally { if (e_2) throw e_2.error; }
1858
- }
1859
- }
1860
- }
1861
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1862
- finally {
1863
- try {
1864
- if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
1865
- }
1866
- finally { if (e_1) throw e_1.error; }
1867
- }
1868
- return union;
1869
- }
1870
-
1871
1804
  /**
1872
1805
  * This error occurs when some expectation is not met in the execution of the pipeline
1873
1806
  *
@@ -2273,6 +2206,79 @@
2273
2206
  return replacedTemplate;
2274
2207
  }
2275
2208
 
2209
+ /**
2210
+ * Create difference set of two sets.
2211
+ *
2212
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2213
+ */
2214
+ function difference(a, b, isEqual) {
2215
+ var e_1, _a;
2216
+ if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
2217
+ var diff = new Set();
2218
+ var _loop_1 = function (itemA) {
2219
+ if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
2220
+ diff.add(itemA);
2221
+ }
2222
+ };
2223
+ try {
2224
+ for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
2225
+ var itemA = _c.value;
2226
+ _loop_1(itemA);
2227
+ }
2228
+ }
2229
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2230
+ finally {
2231
+ try {
2232
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2233
+ }
2234
+ finally { if (e_1) throw e_1.error; }
2235
+ }
2236
+ return diff;
2237
+ }
2238
+ /**
2239
+ * TODO: [🧠][💯] Maybe also implement symmetricDifference
2240
+ */
2241
+
2242
+ /**
2243
+ * Creates a new set with all elements that are present in either set
2244
+ *
2245
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2246
+ */
2247
+ function union() {
2248
+ var e_1, _a, e_2, _b;
2249
+ var sets = [];
2250
+ for (var _i = 0; _i < arguments.length; _i++) {
2251
+ sets[_i] = arguments[_i];
2252
+ }
2253
+ var union = new Set();
2254
+ try {
2255
+ for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
2256
+ var set = sets_1_1.value;
2257
+ try {
2258
+ for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
2259
+ var item = _d.value;
2260
+ union.add(item);
2261
+ }
2262
+ }
2263
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2264
+ finally {
2265
+ try {
2266
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2267
+ }
2268
+ finally { if (e_2) throw e_2.error; }
2269
+ }
2270
+ }
2271
+ }
2272
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2273
+ finally {
2274
+ try {
2275
+ if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
2276
+ }
2277
+ finally { if (e_1) throw e_1.error; }
2278
+ }
2279
+ return union;
2280
+ }
2281
+
2276
2282
  /**
2277
2283
  * Counts number of characters in the text
2278
2284
  */
@@ -2400,7 +2406,7 @@
2400
2406
  pipeline = rawPipeline;
2401
2407
  }
2402
2408
  else {
2403
- console.warn(spaceTrim.spaceTrim("\n Pipeline is not prepared\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "));
2409
+ console.warn(spaceTrim.spaceTrim("\n Pipeline ".concat(rawPipeline.pipelineUrl || rawPipeline.sourceFile || rawPipeline.title, " is not prepared\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
2404
2410
  }
2405
2411
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2406
2412
  function getContextForTemplate(// <- TODO: [🧠][🥜]
@@ -5512,7 +5518,7 @@
5512
5518
  }
5513
5519
  _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
5514
5520
  collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
5515
- var fileNames, pipelines, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
5521
+ var fileNames, collection, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
5516
5522
  var e_1, _a;
5517
5523
  return __generator(this, function (_b) {
5518
5524
  switch (_b.label) {
@@ -5534,9 +5540,9 @@
5534
5540
  }
5535
5541
  return 0;
5536
5542
  });
5537
- pipelines = [];
5543
+ collection = new Map();
5538
5544
  _loop_1 = function (fileName) {
5539
- var sourceFile, pipeline, pipelineString, _c, _d, error_1, wrappedErrorMessage;
5545
+ var sourceFile, pipeline, pipelineString, _c, _d, existing, error_1, wrappedErrorMessage;
5540
5546
  return __generator(this, function (_e) {
5541
5547
  switch (_e.label) {
5542
5548
  case 0:
@@ -5572,7 +5578,8 @@
5572
5578
  case 7:
5573
5579
  // ---
5574
5580
  if (pipeline !== null) {
5575
- if (!pipeline.pipelineUrl) {
5581
+ // TODO: [👠] DRY
5582
+ if (pipeline.pipelineUrl === undefined) {
5576
5583
  if (isVerbose) {
5577
5584
  console.info(colors__default["default"].red("Can not load pipeline from ".concat(fileName
5578
5585
  .split('\\')
@@ -5580,16 +5587,30 @@
5580
5587
  }
5581
5588
  }
5582
5589
  else {
5583
- if (!isCrashedOnError) {
5584
- // Note: Validate pipeline to check if it is logically correct to not crash on invalid pipelines
5585
- // But be handled in current try-catch block
5586
- validatePipeline(pipeline);
5590
+ // Note: [🐨] Pipeline is checked multiple times
5591
+ // TODO: Maybe once is enough BUT be sure to check it - better to check it multiple times than not at all
5592
+ validatePipeline(pipeline);
5593
+ if (
5594
+ // TODO: [🐽] comparePipelines(pipeline1,pipeline2): 'IDENTICAL' |'IDENTICAL_UNPREPARED' | 'IDENTICAL_INTERFACE' | 'DIFFERENT'
5595
+ !collection.has(pipeline.pipelineUrl)) {
5596
+ if (isVerbose) {
5597
+ console.info(colors__default["default"].gray("Loaded pipeline ".concat(fileName.split('\\').join('/'), "\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060")));
5598
+ }
5599
+ // Note: [🦄] Pipeline with same url uniqueness will be double-checked automatically in SimplePipelineCollection
5600
+ collection.set(pipeline.pipelineUrl, pipeline);
5587
5601
  }
5588
- if (isVerbose) {
5589
- console.info(colors__default["default"].green("Loading ".concat(fileName.split('\\').join('/'))));
5602
+ else if (pipelineJsonToString(unpreparePipeline(pipeline)) ===
5603
+ pipelineJsonToString(unpreparePipeline(collection.get(pipeline.pipelineUrl)))) {
5604
+ if (isVerbose) {
5605
+ console.info(colors__default["default"].gray("Skipped pipeline ".concat(fileName
5606
+ .split('\\')
5607
+ .join('/'), " \u2013\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060 identical pipeline in the collection")));
5608
+ }
5609
+ }
5610
+ else {
5611
+ existing = collection.get(pipeline.pipelineUrl);
5612
+ throw new ReferenceError(spaceTrim__default["default"]("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
5590
5613
  }
5591
- // Note: [🦄] Pipeline with same url uniqueness will be checked automatically in SimplePipelineCollection
5592
- pipelines.push(pipeline);
5593
5614
  }
5594
5615
  }
5595
5616
  return [3 /*break*/, 9];
@@ -5598,7 +5619,7 @@
5598
5619
  if (!(error_1 instanceof Error)) {
5599
5620
  throw error_1;
5600
5621
  }
5601
- wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n Error during loading pipeline from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
5622
+ wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
5602
5623
  if (isCrashedOnError) {
5603
5624
  throw new CollectionError(wrappedErrorMessage);
5604
5625
  }
@@ -5635,7 +5656,7 @@
5635
5656
  }
5636
5657
  finally { if (e_1) throw e_1.error; }
5637
5658
  return [7 /*endfinally*/];
5638
- case 9: return [2 /*return*/, pipelines];
5659
+ case 9: return [2 /*return*/, Array.from(collection.values())];
5639
5660
  }
5640
5661
  });
5641
5662
  }); });