@promptbook/core 0.35.0 → 0.36.1

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.
Files changed (112) hide show
  1. package/README.md +1 -1
  2. package/esm/index.es.js +126 -123
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/core.index.d.ts +8 -8
  5. package/esm/typings/_packages/remote-server.index.d.ts +2 -2
  6. package/esm/typings/_packages/types.index.d.ts +8 -8
  7. package/esm/typings/classes/PromptbookLibrary.d.ts +61 -0
  8. package/esm/typings/conversion/_importPromptbook.d.ts +12 -0
  9. package/esm/typings/conversion/promptbookStringToJson.d.ts +13 -0
  10. package/esm/typings/conversion/validatePromptbookJson.d.ts +26 -0
  11. package/{umd/typings/execution/PtpExecutor.d.ts → esm/typings/execution/PromptbookExecutor.d.ts} +5 -5
  12. package/esm/typings/execution/assertsExecutionSuccessful.d.ts +2 -2
  13. package/esm/typings/execution/createPromptbookExecutor.d.ts +40 -0
  14. package/esm/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +1 -1
  15. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +1 -1
  16. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +1 -1
  17. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
  18. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Error.d.ts → Promptbook_Server_Error.d.ts} +1 -1
  19. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Progress.d.ts → Promptbook_Server_Progress.d.ts} +1 -1
  20. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Request.d.ts → Promptbook_Server_Request.d.ts} +2 -2
  21. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Response.d.ts → Promptbook_Server_Response.d.ts} +2 -2
  22. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +3 -3
  23. package/{umd/typings/execution/plugins/natural-execution-tools/remote/runRemoteServer.d.ts → esm/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts} +2 -2
  24. package/esm/typings/types/Command.d.ts +12 -12
  25. package/esm/typings/types/Parameters.d.ts +3 -3
  26. package/esm/typings/types/Prompt.d.ts +5 -5
  27. package/{umd/typings/types/PromptTemplatePipelineJson → esm/typings/types/PromptbookJson}/PromptTemplateJson.d.ts +4 -4
  28. package/esm/typings/types/{PromptTemplatePipelineJson → PromptbookJson}/PromptTemplateParameterJson.d.ts +2 -2
  29. package/{umd/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts → esm/typings/types/PromptbookJson/PromptbookJson.d.ts} +11 -15
  30. package/esm/typings/types/PromptbookString.d.ts +12 -0
  31. package/esm/typings/types/TaskProgress.d.ts +1 -1
  32. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +10 -10
  33. package/esm/typings/types/typeAliases.d.ts +4 -4
  34. package/esm/typings/utils/expectation-counters/countCharacters.d.ts +1 -1
  35. package/esm/typings/utils/expectation-counters/countLines.d.ts +1 -1
  36. package/esm/typings/utils/expectation-counters/countPages.d.ts +1 -1
  37. package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +1 -1
  38. package/esm/typings/utils/expectation-counters/countSentences.d.ts +1 -1
  39. package/esm/typings/utils/expectation-counters/countWords.d.ts +1 -1
  40. package/esm/typings/utils/expectation-counters/index.d.ts +1 -1
  41. package/esm/typings/utils/isRunningInWhatever.d.ts +12 -0
  42. package/esm/typings/utils/markdown/addAutoGeneratedSection.d.ts +10 -0
  43. package/esm/typings/utils/markdown/createMarkdownChart.d.ts +4 -0
  44. package/esm/typings/version.d.ts +1 -1
  45. package/package.json +1 -1
  46. package/umd/index.umd.js +130 -127
  47. package/umd/index.umd.js.map +1 -1
  48. package/umd/typings/_packages/core.index.d.ts +8 -8
  49. package/umd/typings/_packages/remote-server.index.d.ts +2 -2
  50. package/umd/typings/_packages/types.index.d.ts +8 -8
  51. package/umd/typings/classes/PromptbookLibrary.d.ts +61 -0
  52. package/umd/typings/conversion/_importPromptbook.d.ts +12 -0
  53. package/umd/typings/conversion/promptbookStringToJson.d.ts +13 -0
  54. package/umd/typings/conversion/validatePromptbookJson.d.ts +26 -0
  55. package/umd/typings/conversion/validatePromptbookJson.test.d.ts +1 -0
  56. package/{esm/typings/execution/PtpExecutor.d.ts → umd/typings/execution/PromptbookExecutor.d.ts} +5 -5
  57. package/umd/typings/execution/assertsExecutionSuccessful.d.ts +2 -2
  58. package/umd/typings/execution/createPromptbookExecutor.d.ts +40 -0
  59. package/umd/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +1 -1
  60. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +1 -1
  61. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +1 -1
  62. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
  63. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Error.d.ts → Promptbook_Server_Error.d.ts} +1 -1
  64. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Progress.d.ts → Promptbook_Server_Progress.d.ts} +1 -1
  65. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Request.d.ts → Promptbook_Server_Request.d.ts} +2 -2
  66. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Response.d.ts → Promptbook_Server_Response.d.ts} +2 -2
  67. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +3 -3
  68. package/{esm/typings/execution/plugins/natural-execution-tools/remote/runRemoteServer.d.ts → umd/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts} +2 -2
  69. package/umd/typings/types/Command.d.ts +12 -12
  70. package/umd/typings/types/Parameters.d.ts +3 -3
  71. package/umd/typings/types/Prompt.d.ts +5 -5
  72. package/{esm/typings/types/PromptTemplatePipelineJson → umd/typings/types/PromptbookJson}/PromptTemplateJson.d.ts +4 -4
  73. package/umd/typings/types/{PromptTemplatePipelineJson → PromptbookJson}/PromptTemplateParameterJson.d.ts +2 -2
  74. package/{esm/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts → umd/typings/types/PromptbookJson/PromptbookJson.d.ts} +11 -15
  75. package/umd/typings/types/PromptbookString.d.ts +12 -0
  76. package/umd/typings/types/TaskProgress.d.ts +1 -1
  77. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +10 -10
  78. package/umd/typings/types/typeAliases.d.ts +4 -4
  79. package/umd/typings/utils/expectation-counters/countCharacters.d.ts +1 -1
  80. package/umd/typings/utils/expectation-counters/countLines.d.ts +1 -1
  81. package/umd/typings/utils/expectation-counters/countPages.d.ts +1 -1
  82. package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +1 -1
  83. package/umd/typings/utils/expectation-counters/countSentences.d.ts +1 -1
  84. package/umd/typings/utils/expectation-counters/countWords.d.ts +1 -1
  85. package/umd/typings/utils/expectation-counters/index.d.ts +1 -1
  86. package/umd/typings/utils/isRunningInWhatever.d.ts +12 -0
  87. package/umd/typings/utils/markdown/addAutoGeneratedSection.d.ts +10 -0
  88. package/umd/typings/utils/markdown/addAutoGeneratedSection.test.d.ts +1 -0
  89. package/umd/typings/utils/markdown/createMarkdownChart.d.ts +4 -0
  90. package/umd/typings/version.d.ts +1 -1
  91. package/esm/typings/classes/PromptTemplatePipelineLibrary.d.ts +0 -71
  92. package/esm/typings/config.d.ts +0 -12
  93. package/esm/typings/conversion/_importPtp.d.ts +0 -12
  94. package/esm/typings/conversion/promptTemplatePipelineStringToJson.d.ts +0 -13
  95. package/esm/typings/conversion/validatePromptTemplatePipelineJson.d.ts +0 -26
  96. package/esm/typings/execution/createPtpExecutor.d.ts +0 -40
  97. package/esm/typings/types/PromptTemplatePipelineString.d.ts +0 -16
  98. package/umd/typings/classes/PromptTemplatePipelineLibrary.d.ts +0 -71
  99. package/umd/typings/config.d.ts +0 -12
  100. package/umd/typings/conversion/_importPtp.d.ts +0 -12
  101. package/umd/typings/conversion/promptTemplatePipelineStringToJson.d.ts +0 -13
  102. package/umd/typings/conversion/validatePromptTemplatePipelineJson.d.ts +0 -26
  103. package/umd/typings/execution/createPtpExecutor.d.ts +0 -40
  104. package/umd/typings/types/PromptTemplatePipelineString.d.ts +0 -16
  105. /package/esm/typings/conversion/{promptTemplatePipelineStringToJson-syntaxErrors.test.d.ts → promptbookStringToJson-syntaxErrors.test.d.ts} +0 -0
  106. /package/esm/typings/conversion/{promptTemplatePipelineStringToJson.test.d.ts → promptbookStringToJson.test.d.ts} +0 -0
  107. /package/esm/typings/conversion/{validatePromptTemplatePipelineJson-logicErrors.test.d.ts → validatePromptbookJson-logicErrors.test.d.ts} +0 -0
  108. /package/esm/typings/conversion/{validatePromptTemplatePipelineJson.test.d.ts → validatePromptbookJson.test.d.ts} +0 -0
  109. /package/{umd/typings/conversion/promptTemplatePipelineStringToJson-syntaxErrors.test.d.ts → esm/typings/utils/markdown/addAutoGeneratedSection.test.d.ts} +0 -0
  110. /package/umd/typings/conversion/{promptTemplatePipelineStringToJson.test.d.ts → promptbookStringToJson-syntaxErrors.test.d.ts} +0 -0
  111. /package/umd/typings/conversion/{validatePromptTemplatePipelineJson-logicErrors.test.d.ts → promptbookStringToJson.test.d.ts} +0 -0
  112. /package/umd/typings/conversion/{validatePromptTemplatePipelineJson.test.d.ts → validatePromptbookJson-logicErrors.test.d.ts} +0 -0
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # 📖 Prompt template pipelines
1
+ # 📖 Promptbook
2
2
 
3
3
  Library to supercharge your use of large language models
4
4
 
package/esm/index.es.js CHANGED
@@ -120,21 +120,6 @@ function __spreadArray(to, from, pack) {
120
120
  return to.concat(ar || Array.prototype.slice.call(from));
121
121
  }
122
122
 
123
- /**
124
- * Default model requirements for the pipeline
125
- *
126
- * Note: As default, we use the chat model gpt-3.5-turbo. For most tasks, this is the best model with most intuitive usage.
127
- * GPT-4 is overkill for most tasks so keeping it as opt-in option.
128
- */
129
- var DEFAULT_MODEL_REQUIREMENTS = {
130
- modelVariant: 'CHAT',
131
- modelName: 'gpt-3.5-turbo',
132
- };
133
- /**
134
- * TODO: !!! Different default model for different model variant
135
- * TODO: [🧠] What should be the default model?
136
- */
137
-
138
123
  /**
139
124
  * Supported script languages
140
125
  */
@@ -435,6 +420,11 @@ function removeContentComments(content) {
435
420
  return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
436
421
  }
437
422
 
423
+ /**
424
+ * The version of the Promptbook library
425
+ */
426
+ var PROMPTBOOK_VERSION = '0.36.0';
427
+
438
428
  /**
439
429
  * Execution type describes the way how the block is executed
440
430
  *
@@ -552,36 +542,39 @@ function parseCommand(listItem) {
552
542
  .map(function (part) { return part.trim(); })
553
543
  .filter(function (item) { return item !== ''; })
554
544
  .filter(function (item) { return !/^PTBK$/i.test(item); })
545
+ .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
555
546
  .map(removeMarkdownFormatting);
556
547
  if (type.startsWith('URL') ||
557
548
  type.startsWith('PTBK_URL') ||
558
549
  type.startsWith('PTBKURL') ||
550
+ type.startsWith('PROMPTBOOK_URL') ||
551
+ type.startsWith('PROMPTBOOKURL') ||
559
552
  type.startsWith('HTTPS')) {
560
553
  if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
561
- throw new Error(spaceTrim("\n Invalid PTBK_URL command:\n\n - ".concat(listItem, "\n ")));
554
+ throw new Error(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
562
555
  }
563
- var ptbkUrlString = listItemParts.pop();
564
- var ptbkUrl = new URL(ptbkUrlString);
565
- if (ptbkUrl.protocol !== 'https:') {
566
- throw new Error(spaceTrim("\n Invalid PTBK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
556
+ var promptbookUrlString = listItemParts.pop();
557
+ var promptbookUrl = new URL(promptbookUrlString);
558
+ if (promptbookUrl.protocol !== 'https:') {
559
+ throw new Error(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
567
560
  }
568
- if (ptbkUrl.hash !== '') {
569
- throw new Error(spaceTrim("\n Invalid PTBK_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 ")));
561
+ if (promptbookUrl.hash !== '') {
562
+ throw new Error(spaceTrim("\n Invalid PROMPTBOOK_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 ")));
570
563
  }
571
564
  return {
572
- type: 'PTBK_URL',
573
- ptbkUrl: ptbkUrl,
565
+ type: 'PROMPTBOOK_URL',
566
+ promptbookUrl: promptbookUrl,
574
567
  };
575
568
  }
576
- else if (type.startsWith('PTBK_VERSION')) {
569
+ else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
577
570
  if (listItemParts.length !== 2) {
578
- throw new Error(spaceTrim("\n Invalid PTBK_VERSION command:\n\n - ".concat(listItem, "\n ")));
571
+ throw new Error(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
579
572
  }
580
- var ptbkVersion = listItemParts.pop();
573
+ var promptbookVersion = listItemParts.pop();
581
574
  // TODO: Validate version
582
575
  return {
583
- type: 'PTBK_VERSION',
584
- ptbkVersion: ptbkVersion,
576
+ type: 'PROMPTBOOK_VERSION',
577
+ promptbookVersion: promptbookVersion,
585
578
  };
586
579
  }
587
580
  else if (type.startsWith('EXECUTE') ||
@@ -626,7 +619,7 @@ function parseCommand(listItem) {
626
619
  };
627
620
  }
628
621
  else {
629
- throw new Error(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT CHAT\n - MODEL NAME gpt-4\n "); }));
622
+ throw new Error(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
630
623
  }
631
624
  }
632
625
  else if (type.startsWith('PARAM') ||
@@ -752,41 +745,36 @@ function parseCommand(listItem) {
752
745
  }
753
746
  }
754
747
  else {
755
- throw new Error(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - Execute\n - Model\n - Parameter\n - INPUT PARAMETER\n - OUTPUT PARAMETER\n - PTBK VERSION\n ")));
748
+ throw new Error(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - Execute\n - Model\n - Parameter\n - INPUT PARAMETER\n - OUTPUT PARAMETER\n - PROMPTBOOK VERSION\n ")));
756
749
  }
757
750
  }
758
751
 
759
752
  /**
760
- * The version of the Promptbook library
761
- */
762
- var PTBK_VERSION = '0.34.1';
763
-
764
- /**
765
- * Parse prompt template pipeline from string format to JSON format
753
+ * Parse promptbook from string format to JSON format
766
754
  *
767
755
  * Note: This function does not validate logic of the pipeline only the syntax
768
756
  */
769
- function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
757
+ function promptbookStringToJson(promptbookString) {
770
758
  var e_1, _a, e_2, _b;
771
- var ptbJson = {
759
+ var promptbookJson = {
772
760
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
773
761
  title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
774
- ptbkUrl: undefined /* <- Note: Putting here placeholder to keep `ptbkUrl` on top at final JSON */,
775
- ptbkVersion: PTBK_VERSION,
762
+ promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
763
+ promptbookVersion: PROMPTBOOK_VERSION,
776
764
  description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
777
765
  parameters: [],
778
766
  promptTemplates: [],
779
767
  };
780
768
  // =============================================================
781
- // Note: 1️⃣ Normalization of the PTP string
782
- promptTemplatePipelineString = removeContentComments(promptTemplatePipelineString);
783
- promptTemplatePipelineString = promptTemplatePipelineString.replaceAll(/`\{(?<paramName>[a-z0-9_]+)\}`/gi, '{$<paramName>}');
784
- promptTemplatePipelineString = promptTemplatePipelineString.replaceAll(/`->\s+\{(?<paramName>[a-z0-9_]+)\}`/gi, '-> {$<paramName>}');
769
+ // Note: 1️⃣ Normalization of the PROMPTBOOK string
770
+ promptbookString = removeContentComments(promptbookString);
771
+ promptbookString = promptbookString.replaceAll(/`\{(?<paramName>[a-z0-9_]+)\}`/gi, '{$<paramName>}');
772
+ promptbookString = promptbookString.replaceAll(/`->\s+\{(?<paramName>[a-z0-9_]+)\}`/gi, '-> {$<paramName>}');
785
773
  // =============================================================
786
774
  ///Note: 2️⃣ Function for adding parameters
787
775
  var addParam = function (parameterCommand) {
788
776
  var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInputParameter = parameterCommand.isInputParameter;
789
- var existingParameter = ptbJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
777
+ var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
790
778
  if (existingParameter &&
791
779
  existingParameter.description &&
792
780
  existingParameter.description !== parameterDescription &&
@@ -799,7 +787,7 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
799
787
  }
800
788
  }
801
789
  else {
802
- ptbJson.parameters.push({
790
+ promptbookJson.parameters.push({
803
791
  name: parameterName,
804
792
  description: parameterDescription || undefined,
805
793
  isInput: isInputParameter,
@@ -808,12 +796,12 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
808
796
  };
809
797
  // =============================================================
810
798
  // Note: 3️⃣ Parse the dynamic part - the template pipeline
811
- var markdownStructure = markdownToMarkdownStructure(promptTemplatePipelineString);
799
+ var markdownStructure = markdownToMarkdownStructure(promptbookString);
812
800
  var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
813
801
  if (markdownStructureDeepness !== 2) {
814
802
  throw new Error(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
815
803
  }
816
- ptbJson.title = markdownStructure.title;
804
+ promptbookJson.title = markdownStructure.title;
817
805
  // TODO: [1] DRY description
818
806
  var description = markdownStructure.content;
819
807
  // Note: Remove codeblocks
@@ -824,29 +812,28 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
824
812
  if (description === '') {
825
813
  description = undefined;
826
814
  }
827
- ptbJson.description = description;
828
- var defaultModelRequirements = __assign({}, DEFAULT_MODEL_REQUIREMENTS);
815
+ promptbookJson.description = description;
816
+ var defaultModelRequirements = {};
829
817
  var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
830
818
  try {
831
819
  for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
832
820
  var listItem = listItems_1_1.value;
833
821
  var command = parseCommand(listItem);
834
822
  switch (command.type) {
835
- case 'PTBK_URL':
836
- ptbJson.ptbkUrl = command.ptbkUrl.href;
823
+ case 'PROMPTBOOK_URL':
824
+ promptbookJson.promptbookUrl = command.promptbookUrl.href;
837
825
  break;
838
- case 'PTBK_VERSION':
839
- ptbJson.ptbkVersion = command.ptbkVersion;
826
+ case 'PROMPTBOOK_VERSION':
827
+ promptbookJson.promptbookVersion = command.promptbookVersion;
840
828
  break;
841
829
  case 'MODEL':
842
- // @ts-expect-error [🤸‍♂️] No idea why this occurs after adding maxTokens into modelRequirements
843
830
  defaultModelRequirements[command.key] = command.value;
844
831
  break;
845
832
  case 'PARAMETER':
846
833
  addParam(command);
847
834
  break;
848
835
  default:
849
- throw new Error("Command ".concat(command.type, " is not allowed in the head of the prompt template pipeline ONLY at the prompt template block"));
836
+ throw new Error("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
850
837
  }
851
838
  }
852
839
  }
@@ -886,7 +873,6 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
886
873
  isExecutionTypeChanged = true;
887
874
  break;
888
875
  case 'MODEL':
889
- // @ts-expect-error [🤸‍♂️] No idea why this occurs after adding maxTokens into modelRequirements
890
876
  templateModelRequirements[command.key] = command.value;
891
877
  break;
892
878
  case 'PARAMETER':
@@ -920,7 +906,7 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
920
906
  expectFormat = command.format;
921
907
  break;
922
908
  default:
923
- throw new Error("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the prompt template pipeline"));
909
+ throw new Error("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
924
910
  }
925
911
  }
926
912
  }
@@ -999,7 +985,7 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
999
985
  }
1000
986
  }
1001
987
  dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
1002
- ptbJson.promptTemplates.push({
988
+ promptbookJson.promptTemplates.push({
1003
989
  name: normalizeTo_PascalCase(section.title),
1004
990
  title: section.title,
1005
991
  description: description_1,
@@ -1029,7 +1015,7 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
1029
1015
  finally { if (e_2) throw e_2.error; }
1030
1016
  }
1031
1017
  // =============================================================
1032
- return ptbJson;
1018
+ return promptbookJson;
1033
1019
  }
1034
1020
  /**
1035
1021
  * TODO: Report here line/column of error
@@ -1038,7 +1024,7 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
1038
1024
  */
1039
1025
 
1040
1026
  /**
1041
- * Validates PromptTemplatePipelineJson if it is logically valid.
1027
+ * Validates PromptbookJson if it is logically valid.
1042
1028
  *
1043
1029
  * It checks:
1044
1030
  * - if it has correct parameters dependency
@@ -1047,12 +1033,12 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
1047
1033
  * - if it is valid json
1048
1034
  * - if it is meaningful
1049
1035
  *
1050
- * @param ptp valid or invalid PromptTemplatePipelineJson
1036
+ * @param promptbook valid or invalid PromptbookJson
1051
1037
  * @throws {Error} if invalid
1052
1038
  */
1053
- function validatePromptTemplatePipelineJson(ptp) {
1039
+ function validatePromptbookJson(promptbook) {
1054
1040
  var e_1, _a, e_2, _b, e_3, _c;
1055
- var definedParameters = new Set(ptp.parameters.filter(function (_a) {
1041
+ var definedParameters = new Set(promptbook.parameters.filter(function (_a) {
1056
1042
  var isInput = _a.isInput;
1057
1043
  return isInput;
1058
1044
  }).map(function (_a) {
@@ -1061,11 +1047,16 @@ function validatePromptTemplatePipelineJson(ptp) {
1061
1047
  }));
1062
1048
  try {
1063
1049
  // Note: Check each template individually
1064
- for (var _d = __values(ptp.promptTemplates), _e = _d.next(); !_e.done; _e = _d.next()) {
1050
+ for (var _d = __values(promptbook.promptTemplates), _e = _d.next(); !_e.done; _e = _d.next()) {
1065
1051
  var template = _e.value;
1066
1052
  if (definedParameters.has(template.resultingParameterName)) {
1067
1053
  throw new Error("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
1068
1054
  }
1055
+ if (template.executionType === 'PROMPT_TEMPLATE' &&
1056
+ (template.modelRequirements.modelVariant === undefined ||
1057
+ template.modelRequirements.modelName === undefined)) {
1058
+ throw new Error(spaceTrim("\n\n You must specify MODEL VARIANT and MODEL NAME in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
1059
+ }
1069
1060
  if (template.jokers && template.jokers.length > 0) {
1070
1061
  if (!template.expectFormat &&
1071
1062
  !template.expectAmount /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
@@ -1121,14 +1112,16 @@ function validatePromptTemplatePipelineJson(ptp) {
1121
1112
  finally { if (e_1) throw e_1.error; }
1122
1113
  }
1123
1114
  // Note: Detect circular dependencies
1124
- var resovedParameters = ptp.parameters.filter(function (_a) {
1115
+ var resovedParameters = promptbook.parameters
1116
+ .filter(function (_a) {
1125
1117
  var isInput = _a.isInput;
1126
1118
  return isInput;
1127
- }).map(function (_a) {
1119
+ })
1120
+ .map(function (_a) {
1128
1121
  var name = _a.name;
1129
1122
  return name;
1130
1123
  });
1131
- var unresovedTemplates = __spreadArray([], __read(ptp.promptTemplates), false);
1124
+ var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
1132
1125
  var _loop_1 = function () {
1133
1126
  var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
1134
1127
  return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
@@ -1154,15 +1147,15 @@ function validatePromptTemplatePipelineJson(ptp) {
1154
1147
  }
1155
1148
  }
1156
1149
  /**
1157
- * TODO: [🧠] Work with ptbkVersion
1150
+ * TODO: [🧠] Work with promptbookVersion
1158
1151
  * TODO: Use here some json-schema, Zod or something similar and change it to:
1159
1152
  * > /**
1160
- * > * Validates PromptTemplatePipelineJson if it is logically valid.
1153
+ * > * Validates PromptbookJson if it is logically valid.
1161
1154
  * > *
1162
1155
  * > * It checks:
1163
1156
  * > * - it has a valid structure
1164
1157
  * > * - ...
1165
- * > ex port function validatePromptTemplatePipelineJson(ptp: unknown): asserts ptp is PromptTemplatePipelineJson {
1158
+ * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
1166
1159
  */
1167
1160
 
1168
1161
  /**
@@ -1319,16 +1312,16 @@ var ExpectError = /** @class */ (function (_super) {
1319
1312
  */
1320
1313
 
1321
1314
  /**
1322
- * Creates executor function from prompt template pipeline and execution tools.
1315
+ * Creates executor function from promptbook and execution tools.
1323
1316
  *
1324
1317
  * Note: Consider using getExecutor method of the library instead of using this function
1325
1318
  */
1326
- function createPtpExecutor(options) {
1319
+ function createPromptbookExecutor(options) {
1327
1320
  var _this = this;
1328
- var ptp = options.ptp, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
1321
+ var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
1329
1322
  var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
1330
- validatePromptTemplatePipelineJson(ptp);
1331
- var ptpExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1323
+ validatePromptbookJson(promptbook);
1324
+ var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1332
1325
  function executeSingleTemplate(currentTemplate) {
1333
1326
  return __awaiter(this, void 0, void 0, function () {
1334
1327
  var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_1_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_2_1, e_3_1, _j, _k, _l, unit, _m, max, min, amount, error_4;
@@ -1336,9 +1329,9 @@ function createPtpExecutor(options) {
1336
1329
  return __generator(this, function (_t) {
1337
1330
  switch (_t.label) {
1338
1331
  case 0:
1339
- name = "ptp-executor-frame-".concat(currentTemplate.name);
1332
+ name = "promptbook-executor-frame-".concat(currentTemplate.name);
1340
1333
  title = currentTemplate.title;
1341
- priority = ptp.promptTemplates.length - ptp.promptTemplates.indexOf(currentTemplate);
1334
+ priority = promptbook.promptTemplates.length - promptbook.promptTemplates.indexOf(currentTemplate);
1342
1335
  if (!onProgress) return [3 /*break*/, 2];
1343
1336
  return [4 /*yield*/, onProgress({
1344
1337
  name: name,
@@ -1395,9 +1388,9 @@ function createPtpExecutor(options) {
1395
1388
  case 6:
1396
1389
  prompt = {
1397
1390
  title: currentTemplate.title,
1398
- ptbkUrl: "".concat(ptp.ptbkUrl
1399
- ? ptp.ptbkUrl
1400
- : 'anonymous' /* <- [🧠] !!! How to deal with anonymous PTPs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
1391
+ promptbookUrl: "".concat(promptbook.promptbookUrl
1392
+ ? promptbook.promptbookUrl
1393
+ : 'anonymous' /* <- [🧠][🈴] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
1401
1394
  parameters: parametersToPass,
1402
1395
  content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
1403
1396
  modelRequirements: currentTemplate.modelRequirements,
@@ -1654,7 +1647,7 @@ function createPtpExecutor(options) {
1654
1647
  parameterValue: resultString,
1655
1648
  });
1656
1649
  }
1657
- parametersToPass = __assign(__assign({}, parametersToPass), (_s = {}, _s[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because PromptTemplatePipeline checks logic consistency during construction */, _s));
1650
+ parametersToPass = __assign(__assign({}, parametersToPass), (_s = {}, _s[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _s));
1658
1651
  return [2 /*return*/];
1659
1652
  }
1660
1653
  });
@@ -1666,17 +1659,17 @@ function createPtpExecutor(options) {
1666
1659
  case 0:
1667
1660
  parametersToPass = inputParameters;
1668
1661
  executionReport = {
1669
- ptbkUrl: ptp.ptbkUrl,
1670
- title: ptp.title,
1671
- ptbkUsedVersion: PTBK_VERSION,
1672
- ptbkRequestedVersion: ptp.ptbkVersion,
1673
- description: ptp.description,
1662
+ promptbookUrl: promptbook.promptbookUrl,
1663
+ title: promptbook.title,
1664
+ promptbookUsedVersion: PROMPTBOOK_VERSION,
1665
+ promptbookRequestedVersion: promptbook.promptbookVersion,
1666
+ description: promptbook.description,
1674
1667
  promptExecutions: [],
1675
1668
  };
1676
1669
  _a.label = 1;
1677
1670
  case 1:
1678
1671
  _a.trys.push([1, 6, , 7]);
1679
- resovedParameters_1 = ptp.parameters
1672
+ resovedParameters_1 = promptbook.parameters
1680
1673
  .filter(function (_a) {
1681
1674
  var isInput = _a.isInput;
1682
1675
  return isInput;
@@ -1685,7 +1678,7 @@ function createPtpExecutor(options) {
1685
1678
  var name = _a.name;
1686
1679
  return name;
1687
1680
  });
1688
- unresovedTemplates = __spreadArray([], __read(ptp.promptTemplates), false);
1681
+ unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
1689
1682
  resolving_1 = [];
1690
1683
  _loop_1 = function () {
1691
1684
  var currentTemplate, work_1;
@@ -1749,50 +1742,50 @@ function createPtpExecutor(options) {
1749
1742
  }
1750
1743
  });
1751
1744
  }); };
1752
- return ptpExecutor;
1745
+ return promptbookExecutor;
1753
1746
  }
1754
1747
  /**
1755
1748
  * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
1756
1749
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
1757
- * Note: CreatePtpExecutorOptions are just connected to PtpExecutor so do not extract to types folder
1750
+ * Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
1758
1751
  */
1759
1752
 
1760
1753
  /**
1761
- * Library of prompt template pipelines that groups together prompt template pipelines for an application. This is a very thin wrapper around the Array / Set of prompt template pipelines.
1754
+ * Library of promptbooks that groups together promptbooks for an application. This is a very thin wrapper around the Array / Set of promptbooks.
1762
1755
  *
1763
- * Prompt Template Pipeline library is a useful helper in execution, it can be shared between execution and consumer parts of the app and make common knowledge about prompt template pipelines.
1756
+ * Promptbook library is a useful helper in execution, it can be shared between execution and consumer parts of the app and make common knowledge about promptbooks.
1764
1757
  *
1765
- * It allows to create executor functions from prompt template pipelines in the library.
1758
+ * It allows to create executor functions from promptbooks in the library.
1766
1759
  *
1767
1760
  * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline-library
1768
1761
  */
1769
- var PromptTemplatePipelineLibrary = /** @class */ (function () {
1770
- function PromptTemplatePipelineLibrary(options) {
1762
+ var PromptbookLibrary = /** @class */ (function () {
1763
+ function PromptbookLibrary(options) {
1771
1764
  this.options = options;
1772
1765
  }
1773
1766
  /**
1774
- * Constructs PromptTemplatePipeline from any sources
1767
+ * Constructs Promptbook from any sources
1775
1768
  *
1776
1769
  * Note: During the construction syntax and logic of all sources are validated
1777
1770
  * Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
1778
1771
  *
1779
- * @param ptbkSources contents of .ptbk.md or .ptbk.json files
1772
+ * @param promptbookSources contents of .ptbk.md or .ptbk.json files
1780
1773
  * @param settings settings for creating executor functions
1781
- * @returns PromptTemplatePipelineLibrary
1774
+ * @returns PromptbookLibrary
1782
1775
  */
1783
- PromptTemplatePipelineLibrary.fromSources = function (ptbkSources, settings) {
1776
+ PromptbookLibrary.fromSources = function (promptbookSources, settings) {
1784
1777
  var e_1, _a;
1785
1778
  var library = {};
1786
1779
  try {
1787
- for (var _b = __values(Object.entries(ptbkSources)), _c = _b.next(); !_c.done; _c = _b.next()) {
1780
+ for (var _b = __values(Object.entries(promptbookSources)), _c = _b.next(); !_c.done; _c = _b.next()) {
1788
1781
  var _d = __read(_c.value, 2), name_1 = _d[0], source = _d[1];
1789
1782
  if (typeof source === 'string') {
1790
1783
  // Note: When directly creating from string, no need to validate the source
1791
1784
  // The validation is performed always before execution
1792
- library[name_1] = promptTemplatePipelineStringToJson(source);
1785
+ library[name_1] = promptbookStringToJson(source);
1793
1786
  }
1794
1787
  else {
1795
- validatePromptTemplatePipelineJson(source);
1788
+ validatePromptbookJson(source);
1796
1789
  library[name_1] = source;
1797
1790
  }
1798
1791
  }
@@ -1804,43 +1797,53 @@ var PromptTemplatePipelineLibrary = /** @class */ (function () {
1804
1797
  }
1805
1798
  finally { if (e_1) throw e_1.error; }
1806
1799
  }
1807
- return new PromptTemplatePipelineLibrary({ library: library, settings: settings });
1800
+ return new PromptbookLibrary({ library: library, settings: settings });
1808
1801
  };
1802
+ Object.defineProperty(PromptbookLibrary.prototype, "promptbookNames", {
1803
+ /**
1804
+ * Gets all promptbooks in the library
1805
+ */
1806
+ get: function () {
1807
+ return Object.keys(this.options.library);
1808
+ },
1809
+ enumerable: false,
1810
+ configurable: true
1811
+ });
1809
1812
  /**
1810
- * Gets prompt template pipeline by name
1813
+ * Gets promptbook by name
1811
1814
  */
1812
- PromptTemplatePipelineLibrary.prototype.getPtp = function (name) {
1813
- var promptTemplatePipeline = this.options.library[name];
1814
- if (!promptTemplatePipeline) {
1815
- throw new Error("Prompt template pipeline with name \"".concat(name, "\" not found"));
1815
+ PromptbookLibrary.prototype.getPromptbookByName = function (name) {
1816
+ var promptbook = this.options.library[name];
1817
+ if (!promptbook) {
1818
+ throw new Error("Promptbook with name \"".concat(name, "\" not found"));
1816
1819
  }
1817
- return promptTemplatePipeline;
1820
+ return promptbook;
1818
1821
  };
1819
1822
  /**
1820
1823
  * Checks whether prompt is in the library
1821
1824
  */
1822
- PromptTemplatePipelineLibrary.prototype.isPromptInLibrary = function (prompt) {
1825
+ PromptbookLibrary.prototype.isPromptInLibrary = function (prompt) {
1823
1826
  return true;
1824
1827
  };
1825
1828
  /**
1826
- * Gets executor function for given prompt template pipeline
1829
+ * Gets executor function for given promptbook
1827
1830
  */
1828
- PromptTemplatePipelineLibrary.prototype.createExecutor = function (name, tools) {
1829
- var ptp = this.getPtp(name);
1830
- return createPtpExecutor({ ptp: ptp, tools: tools, settings: this.options.settings });
1831
+ PromptbookLibrary.prototype.createExecutor = function (name, tools) {
1832
+ var promptbook = this.getPromptbookByName(name);
1833
+ return createPromptbookExecutor({ promptbook: promptbook, tools: tools, settings: this.options.settings });
1831
1834
  };
1832
- return PromptTemplatePipelineLibrary;
1835
+ return PromptbookLibrary;
1833
1836
  }());
1834
1837
  /**
1835
- * TODO: !!! This should be renamed to Promptbook
1836
- * TODO: !! [👐][🧠] Split of PromptTemplatePipeline,PromptTemplatePipelineLibrary between interface and class
1837
- * TODO: !! [👐] Make promptTemplatePipelines private WHEN split between interface and class
1838
+ * TODO: [🈴] Identify promptbooks by url `promptbookUrls` + `getPromptbookByUrl`
1839
+ * TODO: !! [👐][🧠] Split of Promptbook,PromptbookLibrary between interface and class
1840
+ * TODO: !! [👐] Make promptbooks private WHEN split between interface and class
1838
1841
  * TODO: [🧠] Maybe isPromptInLibrary should be separate utility function
1839
1842
  * TODO: [🧠] Maybe createExecutor should be separate utility function
1840
1843
  * TODO: Static method fromDirectory
1841
1844
  * TODO: [🤜] Add generic type for entry and result parameters
1842
- * TODO: [🧠] Is it better to ptbkLibrary.executePtp('writeXyz',{...}) OR ptbkLibrary.createExecutor('writeXyz')({...}) OR createExecutor(ptbkLibrary.getPtp('writeXyz'))
1843
- * TODO: [🧠] Formarly (before commit 62229afce7668a5b85077cc18becf798b583bf8d) there were two classes PromptTemplatePipelineLibrary+PtpLibraryExecutor (maybe it was better?)
1845
+ * TODO: [🧠] Is it better to promptbookLibrary.executePromptbook('writeXyz',{...}) OR promptbookLibrary.createExecutor('writeXyz')({...}) OR createExecutor(promptbookLibrary.getPromptbook('writeXyz'))
1846
+ * TODO: [🧠] Formarly (before commit 62229afce7668a5b85077cc18becf798b583bf8d) there were two classes PromptbookLibrary+PromptbookLibraryExecutor (maybe it was better?)
1844
1847
  * TODO: [🧠] Is it better to pass tools into getExecutor or into constructor
1845
1848
  * Maybe it is not a good idea to cache executors when they are can be created with different tools
1846
1849
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
@@ -1987,5 +1990,5 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
1987
1990
  return SimplePromptInterfaceTools;
1988
1991
  }());
1989
1992
 
1990
- export { CallbackInterfaceTools, ExecutionTypes, MockedEchoNaturalExecutionTools, PTBK_VERSION, PromptTemplatePipelineLibrary, SimplePromptInterfaceTools, createPtpExecutor, promptTemplatePipelineStringToJson, validatePromptTemplatePipelineJson };
1993
+ export { CallbackInterfaceTools, ExecutionTypes, MockedEchoNaturalExecutionTools, PROMPTBOOK_VERSION, PromptbookLibrary, SimplePromptInterfaceTools, createPromptbookExecutor, promptbookStringToJson, validatePromptbookJson };
1991
1994
  //# sourceMappingURL=index.es.js.map