@promptbook/core 0.61.0-10 → 0.61.0-12

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 (207) hide show
  1. package/esm/index.es.js +398 -252
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/promptbook-collection/index.d.ts +83 -2
  4. package/esm/typings/src/_packages/core.index.d.ts +2 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +2 -2
  6. package/esm/typings/src/_packages/utils.index.d.ts +3 -1
  7. package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -0
  8. package/esm/typings/src/cli/cli-commands/make.d.ts +3 -0
  9. package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -0
  10. package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
  11. package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
  12. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  13. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
  14. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
  15. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +4 -1
  16. package/esm/typings/src/config.d.ts +4 -0
  17. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
  18. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -0
  19. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -0
  20. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +6 -0
  21. package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
  22. package/{umd/typings/src/errors/VersionMismatch.d.ts → esm/typings/src/errors/VersionMismatchError.d.ts} +1 -1
  23. package/esm/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
  24. package/esm/typings/src/execution/LlmExecutionTools.d.ts +3 -1
  25. package/esm/typings/src/execution/PipelineExecutor.d.ts +4 -3
  26. package/esm/typings/src/execution/PromptResult.d.ts +12 -0
  27. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +4 -2
  28. package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -0
  29. package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -0
  30. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -0
  31. package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +1 -0
  32. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
  33. package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
  34. package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
  35. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -0
  36. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
  37. package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -0
  38. package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +22 -0
  39. package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
  40. package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
  41. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
  42. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
  43. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
  44. package/esm/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
  45. package/esm/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
  46. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
  47. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  48. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
  49. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -0
  50. package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
  51. package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
  52. package/esm/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
  53. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  54. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  55. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
  56. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -0
  57. package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
  58. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
  59. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
  60. package/esm/typings/src/personas/preparePersona.d.ts +4 -2
  61. package/esm/typings/src/prepare/preparePipeline.d.ts +3 -1
  62. package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
  63. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
  64. package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
  65. package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
  66. package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
  67. package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
  68. package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
  69. package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
  70. package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
  71. package/esm/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
  72. package/esm/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
  73. package/esm/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
  74. package/esm/typings/src/types/ModelRequirements.d.ts +21 -1
  75. package/esm/typings/src/types/Parameters.d.ts +0 -1
  76. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -2
  77. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -5
  78. package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +1 -0
  79. package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
  80. package/esm/typings/src/types/PipelineString.d.ts +1 -1
  81. package/esm/typings/src/types/Prompt.d.ts +5 -2
  82. package/esm/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
  83. package/esm/typings/src/types/typeAliases.d.ts +35 -1
  84. package/esm/typings/src/utils/emojis.d.ts +2 -2
  85. package/esm/typings/src/utils/formatNumber.d.ts +1 -1
  86. package/esm/typings/src/utils/isRunningInWhatever.d.ts +3 -0
  87. package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
  88. package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
  89. package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
  90. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
  91. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +7 -0
  92. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  93. package/esm/typings/src/utils/organization/TODO.d.ts +2 -0
  94. package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -0
  95. package/esm/typings/src/utils/organization/___.d.ts +2 -0
  96. package/esm/typings/src/utils/organization/just.d.ts +1 -0
  97. package/esm/typings/src/utils/organization/keepImported.d.ts +12 -0
  98. package/esm/typings/src/utils/organization/notUsing.d.ts +12 -0
  99. package/esm/typings/src/utils/organization/really_any.d.ts +2 -0
  100. package/esm/typings/src/utils/random/randomSeed.d.ts +7 -0
  101. package/esm/typings/src/version.d.ts +3 -0
  102. package/package.json +1 -1
  103. package/umd/index.umd.js +398 -252
  104. package/umd/index.umd.js.map +1 -1
  105. package/umd/typings/promptbook-collection/index.d.ts +83 -2
  106. package/umd/typings/src/_packages/core.index.d.ts +2 -2
  107. package/umd/typings/src/_packages/types.index.d.ts +2 -2
  108. package/umd/typings/src/_packages/utils.index.d.ts +3 -1
  109. package/umd/typings/src/cli/cli-commands/hello.d.ts +3 -0
  110. package/umd/typings/src/cli/cli-commands/make.d.ts +3 -0
  111. package/umd/typings/src/cli/cli-commands/prettify.d.ts +3 -0
  112. package/umd/typings/src/cli/promptbookCli.d.ts +1 -0
  113. package/umd/typings/src/collection/PipelineCollection.d.ts +1 -1
  114. package/umd/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  115. package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
  116. package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
  117. package/umd/typings/src/commands/_common/types/CommandParser.d.ts +4 -1
  118. package/umd/typings/src/config.d.ts +4 -0
  119. package/umd/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
  120. package/umd/typings/src/conversion/pipelineStringToJson.d.ts +1 -0
  121. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -0
  122. package/umd/typings/src/conversion/validation/validatePipeline.d.ts +6 -0
  123. package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
  124. package/{esm/typings/src/errors/VersionMismatch.d.ts → umd/typings/src/errors/VersionMismatchError.d.ts} +1 -1
  125. package/umd/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
  126. package/umd/typings/src/execution/LlmExecutionTools.d.ts +3 -1
  127. package/umd/typings/src/execution/PipelineExecutor.d.ts +4 -3
  128. package/umd/typings/src/execution/PromptResult.d.ts +12 -0
  129. package/umd/typings/src/execution/ScriptExecutionTools.d.ts +4 -2
  130. package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -0
  131. package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -0
  132. package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -0
  133. package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +1 -0
  134. package/umd/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
  135. package/umd/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
  136. package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
  137. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -0
  138. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
  139. package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -0
  140. package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +22 -0
  141. package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
  142. package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
  143. package/umd/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
  144. package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
  145. package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
  146. package/umd/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
  147. package/umd/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
  148. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
  149. package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  150. package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
  151. package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -0
  152. package/umd/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
  153. package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
  154. package/umd/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
  155. package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  156. package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  157. package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
  158. package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -0
  159. package/umd/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
  160. package/umd/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
  161. package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
  162. package/umd/typings/src/personas/preparePersona.d.ts +4 -2
  163. package/umd/typings/src/prepare/preparePipeline.d.ts +3 -1
  164. package/umd/typings/src/prepare/unpreparePipeline.d.ts +1 -0
  165. package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
  166. package/umd/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
  167. package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
  168. package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
  169. package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
  170. package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
  171. package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
  172. package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
  173. package/umd/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
  174. package/umd/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
  175. package/umd/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
  176. package/umd/typings/src/types/ModelRequirements.d.ts +21 -1
  177. package/umd/typings/src/types/Parameters.d.ts +0 -1
  178. package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -2
  179. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -5
  180. package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +1 -0
  181. package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
  182. package/umd/typings/src/types/PipelineString.d.ts +1 -1
  183. package/umd/typings/src/types/Prompt.d.ts +5 -2
  184. package/umd/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
  185. package/umd/typings/src/types/typeAliases.d.ts +35 -1
  186. package/umd/typings/src/utils/emojis.d.ts +2 -2
  187. package/umd/typings/src/utils/formatNumber.d.ts +1 -1
  188. package/umd/typings/src/utils/isRunningInWhatever.d.ts +3 -0
  189. package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
  190. package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
  191. package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
  192. package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
  193. package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +7 -0
  194. package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  195. package/umd/typings/src/utils/organization/TODO.d.ts +2 -0
  196. package/umd/typings/src/utils/organization/TODO_USE.d.ts +1 -0
  197. package/umd/typings/src/utils/organization/___.d.ts +2 -0
  198. package/umd/typings/src/utils/organization/just.d.ts +1 -0
  199. package/umd/typings/src/utils/organization/keepImported.d.ts +12 -0
  200. package/umd/typings/src/utils/organization/notUsing.d.ts +12 -0
  201. package/umd/typings/src/utils/organization/really_any.d.ts +2 -0
  202. package/umd/typings/src/utils/random/randomSeed.d.ts +7 -0
  203. package/umd/typings/src/version.d.ts +3 -0
  204. package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
  205. package/esm/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +0 -7
  206. package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
  207. package/umd/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +0 -7
package/esm/index.es.js CHANGED
@@ -385,7 +385,7 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
385
385
  return parameterString;
386
386
  }
387
387
  /**
388
- * TODO: !!!!! Implement new features and commands into `promptTemplateParameterJsonToString`
388
+ * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
389
389
  * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
390
390
  * TODO: Escape all
391
391
  */
@@ -406,6 +406,10 @@ var RESERVED_PARAMETER_NAMES = [
406
406
  // <- TODO: Add more like 'date', 'modelName',...
407
407
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
408
408
  ];
409
+ /*
410
+ TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
411
+ */
412
+ // [🟡][🟢][🔵][⚪]
409
413
 
410
414
  /**
411
415
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -779,6 +783,12 @@ function validatePipeline(pipeline) {
779
783
  * > * - ...
780
784
  * > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
781
785
  */
786
+ /**
787
+ * TODO: [🧠][🐣] !!!! Validate that all samples match expectations
788
+ * TODO: [🧠][🐣] !!!! Validate that knowledge is valid (non-void)
789
+ * TODO: [🧠] !!! Validationg not only logic itself but imports around - files and websites and rerefenced pipelines exists
790
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
791
+ */
782
792
 
783
793
  /**
784
794
  * This error indicates that promptbook not found in the collection
@@ -819,7 +829,7 @@ var SimplePipelineCollection = /** @class */ (function () {
819
829
  /**
820
830
  * Constructs a pipeline collection from promptbooks
821
831
  *
822
- * @param promptbooks !!!
832
+ * @param promptbooks @@@
823
833
  *
824
834
  * @private Use instead `createCollectionFromJson`
825
835
  * Note: During the construction logic of all promptbooks are validated
@@ -1288,7 +1298,7 @@ function forEachAsync(array, options, callbackfunction) {
1288
1298
  });
1289
1299
  }
1290
1300
 
1291
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-9",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"],blockType:"PROMPT_TEMPLATE",personaName:null,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"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,date:"2024-07-29T00:04:31.966Z",promptbookVersion:"0.61.0-9",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-9",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"],blockType:"PROMPT_TEMPLATE",personaName:null,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"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,date:"2024-07-29T00:04:31.970Z",promptbookVersion:"0.61.0-9",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-9",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",expectations:{words:{min:1,max:8}},personaName:null,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}",resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,date:"2024-07-29T00:04:31.976Z",promptbookVersion:"0.61.0-9",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"}];
1301
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-11",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"],blockType:"PROMPT_TEMPLATE",personaName:null,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"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",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-11",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"],blockType:"PROMPT_TEMPLATE",personaName:null,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"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",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-11",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",expectations:{words:{min:1,max:8}},personaName:null,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}",resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",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-11",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:[{name:"make-model-requirements",title:"Make modelRequirements",dependentParameterNames:["availableModelNames","personaDescription"],blockType:"PROMPT_TEMPLATE",expectFormat:"JSON",personaName:null,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}",resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",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"}];
1292
1302
 
1293
1303
  var defaultDiacriticsRemovalMap = [
1294
1304
  {
@@ -1844,7 +1854,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
1844
1854
  };
1845
1855
  /**
1846
1856
  * List all available models that can be used
1847
- * This liost is a combination of all available models from all execution tools
1857
+ * This lists is a combination of all available models from all execution tools
1848
1858
  */
1849
1859
  MultipleLlmExecutionTools.prototype.listModels = function () {
1850
1860
  return __awaiter(this, void 0, void 0, function () {
@@ -1890,6 +1900,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
1890
1900
  }());
1891
1901
  /**
1892
1902
  * TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
1903
+ * TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
1904
+ * Look how `countTotalUsage` (and `cacheLlmTools`) implements it
1893
1905
  */
1894
1906
 
1895
1907
  /**
@@ -1960,8 +1972,11 @@ function arrayableToArray(input) {
1960
1972
  /**
1961
1973
  * The version of the Promptbook library
1962
1974
  */
1963
- var PROMPTBOOK_VERSION = '0.61.0-9';
1975
+ var PROMPTBOOK_VERSION = '0.61.0-11';
1964
1976
  // TODO: !!!! List here all the versions and annotate + put into script
1977
+ /**
1978
+ * TODO: [🔼] !!! Export via `@promptbook/code`
1979
+ */
1965
1980
 
1966
1981
  /**
1967
1982
  * Counts number of characters in the text
@@ -2164,7 +2179,6 @@ function createPipelineExecutor(options) {
2164
2179
  var _this = this;
2165
2180
  var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
2166
2181
  var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
2167
- // TODO: !!!!! Implement new commands
2168
2182
  validatePipeline(pipeline);
2169
2183
  var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
2170
2184
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
@@ -2240,7 +2254,10 @@ function createPipelineExecutor(options) {
2240
2254
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2241
2255
  parameters: parametersToPass,
2242
2256
  content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
2257
+ // <- TODO: !!!!! Apply {context} and knowledges
2258
+ // <- TODO: !!!!! Apply samples
2243
2259
  modelRequirements: currentTemplate.modelRequirements,
2260
+ // <- TODO: !!!!! Apply persona
2244
2261
  expectations: currentTemplate.expectations,
2245
2262
  expectFormat: currentTemplate.expectFormat,
2246
2263
  postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
@@ -2687,10 +2704,12 @@ function createPipelineExecutor(options) {
2687
2704
  }
2688
2705
  /**
2689
2706
  * TODO: [🪂] Pass maxParallelCount here
2707
+ * TODO: [♈] Probbably move expectations from templates to parameters
2690
2708
  * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
2691
2709
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
2692
2710
  * Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
2693
2711
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
2712
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
2694
2713
  */
2695
2714
 
2696
2715
  /**
@@ -2701,6 +2720,7 @@ function createPipelineExecutor(options) {
2701
2720
  *
2702
2721
  * @param value any values
2703
2722
  * @returns void
2723
+ * @private within the repository
2704
2724
  */
2705
2725
  function TODO_USE() {
2706
2726
  var value = [];
@@ -2708,7 +2728,6 @@ function TODO_USE() {
2708
2728
  value[_i] = arguments[_i];
2709
2729
  }
2710
2730
  }
2711
- // TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
2712
2731
 
2713
2732
  /**
2714
2733
  * @@@
@@ -2837,6 +2856,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
2837
2856
  });
2838
2857
  }
2839
2858
  /**
2859
+ * TODO: [🔼] !!! Export via `@promptbook/markdown`
2840
2860
  * TODO: [🪂] Do it in parallel 11:11
2841
2861
  * Note: No need to aggregate usage here, it is done by intercepting the llmTools
2842
2862
  */
@@ -2845,7 +2865,6 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
2845
2865
  * Prepares the knowle
2846
2866
  *
2847
2867
  * @see https://github.com/webgptorg/promptbook/discussions/41
2848
- * @private within the package
2849
2868
  */
2850
2869
  function prepareKnowledgePieces(knowledgeSources, options) {
2851
2870
  return __awaiter(this, void 0, void 0, function () {
@@ -2860,7 +2879,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
2860
2879
  var partialPieces, pieces;
2861
2880
  return __generator(this, function (_a) {
2862
2881
  switch (_a.label) {
2863
- case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
2882
+ case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!!!! Unhardcode markdown, detect which type it is
2864
2883
  options)];
2865
2884
  case 1:
2866
2885
  partialPieces = _a.sent();
@@ -2898,6 +2917,7 @@ TODO: [🧊] This is how it can look in future
2898
2917
  > ):
2899
2918
  */
2900
2919
  /**
2920
+ * TODO: [🔼] !!! Export via `@promptbook/core`
2901
2921
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
2902
2922
  * Put `knowledgePieces` into `PrepareKnowledgeOptions`
2903
2923
  * TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
@@ -2910,36 +2930,65 @@ TODO: [🧊] This is how it can look in future
2910
2930
  * Prepares the persona for the pipeline
2911
2931
  *
2912
2932
  * @see https://github.com/webgptorg/promptbook/discussions/22
2913
- * @private within the package
2914
2933
  */
2915
2934
  function preparePersona(personaDescription, options) {
2916
2935
  return __awaiter(this, void 0, void 0, function () {
2917
- var llmTools, _a, maxParallelCount, _b, isVerbose;
2918
- return __generator(this, function (_c) {
2919
- llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
2920
- TODO_USE(maxParallelCount); // <- [🪂]
2921
- TODO_USE(personaDescription); // <- !!!!!
2922
- TODO_USE(llmTools); // <- !!!!!
2923
- TODO_USE(isVerbose); // <- !!!!!
2924
- return [2 /*return*/, {
2925
- modelVariant: 'CHAT',
2926
- modelName: 'gpt-4',
2927
- }];
2936
+ var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
2937
+ var _c;
2938
+ return __generator(this, function (_d) {
2939
+ switch (_d.label) {
2940
+ case 0:
2941
+ llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2942
+ collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
2943
+ _b = createPipelineExecutor;
2944
+ _c = {};
2945
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
2946
+ case 1:
2947
+ preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
2948
+ _c.tools = {
2949
+ llm: llmTools,
2950
+ },
2951
+ _c)]);
2952
+ return [4 /*yield*/, llmTools.listModels()];
2953
+ case 2:
2954
+ availableModels = _d.sent();
2955
+ availableModelNames = availableModels
2956
+ .filter(function (_a) {
2957
+ var modelVariant = _a.modelVariant;
2958
+ return modelVariant === 'CHAT';
2959
+ })
2960
+ .map(function (_a) {
2961
+ var modelName = _a.modelName;
2962
+ return modelName;
2963
+ })
2964
+ .join(',');
2965
+ return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
2966
+ case 3:
2967
+ result = _d.sent();
2968
+ assertsExecutionSuccessful(result);
2969
+ outputParameters = result.outputParameters;
2970
+ modelRequirementsRaw = outputParameters.modelRequirements;
2971
+ modelRequirements = JSON.parse(modelRequirementsRaw);
2972
+ if (isVerbose) {
2973
+ console.info("PERSONA ".concat(personaDescription), modelRequirements);
2974
+ }
2975
+ modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
2976
+ return [2 /*return*/, {
2977
+ modelVariant: 'CHAT',
2978
+ modelName: modelName,
2979
+ systemMessage: systemMessage,
2980
+ temperature: temperature,
2981
+ }];
2982
+ }
2928
2983
  });
2929
2984
  });
2930
2985
  }
2931
2986
  /**
2932
- * TODO: [🪂] Do it in parallel
2933
- */
2934
-
2935
- /**
2936
- * Simple wrapper `new Date().toISOString()`
2937
- *
2938
- * @returns string_date branded type
2987
+ * TODO: [🔼] !!! Export via `@promptbook/core`
2988
+ * TODO: [🏢] !! Check validity of `modelName` in pipeline
2989
+ * TODO: [🏢] !! Check validity of `systemMessage` in pipeline
2990
+ * TODO: [🏢] !! Check validity of `temperature` in pipeline
2939
2991
  */
2940
- function $currentDate() {
2941
- return new Date().toISOString();
2942
- }
2943
2992
 
2944
2993
  /**
2945
2994
  * Prepare pipeline from string (markdown) format to JSON format
@@ -2963,7 +3012,7 @@ function preparePipeline(pipeline, options) {
2963
3012
  knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
2964
3013
  currentPreparation = {
2965
3014
  id: 1,
2966
- date: $currentDate(),
3015
+ // TODO: [🍥]> date: $currentDate(),
2967
3016
  promptbookVersion: PROMPTBOOK_VERSION,
2968
3017
  modelUsage: addUsage(),
2969
3018
  };
@@ -2972,8 +3021,8 @@ function preparePipeline(pipeline, options) {
2972
3021
  // <- TODO: [🧊]
2973
3022
  currentPreparation,
2974
3023
  ];
2975
- preparedPersonas = [];
2976
- return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona) { return __awaiter(_this, void 0, void 0, function () {
3024
+ preparedPersonas = new Array(personas.length);
3025
+ return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
2977
3026
  var modelRequirements, preparedPersona;
2978
3027
  return __generator(this, function (_a) {
2979
3028
  switch (_a.label) {
@@ -2981,7 +3030,7 @@ function preparePipeline(pipeline, options) {
2981
3030
  case 1:
2982
3031
  modelRequirements = _a.sent();
2983
3032
  preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
2984
- preparedPersonas.push(preparedPersona);
3033
+ preparedPersonas[index] = preparedPersona;
2985
3034
  return [2 /*return*/];
2986
3035
  }
2987
3036
  });
@@ -3000,11 +3049,186 @@ function preparePipeline(pipeline, options) {
3000
3049
  });
3001
3050
  }
3002
3051
  /**
3052
+ * TODO: [🔼] !!! Export via `@promptbook/core`
3003
3053
  * TODO: Write tests for `preparePipeline`
3004
3054
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3005
3055
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3006
- * TODO: [💸] Make utilities `interceptLlmTools` and `costLlmTools` to compute cost and DO put this counting logic in `prepareKnowledge` or `preparePersona`
3056
+ * TODO: [🎐] !!!! Use here countTotalUsage
3057
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3058
+ */
3059
+
3060
+ /**
3061
+ * Tests if given string is valid URL.
3062
+ *
3063
+ * Note: This does not check if the file exists only if the path is valid
3064
+ */
3065
+ function isValidFilePath(filePath) {
3066
+ if (typeof filePath !== 'string') {
3067
+ return false;
3068
+ }
3069
+ var filePathSlashes = filePath.split('\\').join('/');
3070
+ // Absolute Unix path: /hello.txt
3071
+ if (/^(\/)/i.test(filePathSlashes)) {
3072
+ return true;
3073
+ }
3074
+ // Absolute Windows path: /hello.txt
3075
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
3076
+ return true;
3077
+ }
3078
+ // Relative path: ./hello.txt
3079
+ if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
3080
+ return true;
3081
+ }
3082
+ return false;
3083
+ }
3084
+
3085
+ /**
3086
+ * Parses the knowledge command
3087
+ *
3088
+ * @see ./KNOWLEDGE-README.md for more details
3089
+ * @private within the commands folder
3090
+ */
3091
+ var knowledgeCommandParser = {
3092
+ /**
3093
+ * Name of the command
3094
+ */
3095
+ name: 'KNOWLEDGE',
3096
+ /**
3097
+ * BOILERPLATE command can be used in:
3098
+ */
3099
+ usagePlaces: ['PIPELINE_HEAD'],
3100
+ /**
3101
+ * Description of the KNOWLEDGE command
3102
+ */
3103
+ description: "Tells promptbook which external knowledge to use",
3104
+ /**
3105
+ * Link to discussion
3106
+ */
3107
+ discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
3108
+ /**
3109
+ * Example usages of the KNOWLEDGE command
3110
+ */
3111
+ examples: [
3112
+ 'KNOWLEDGE https://www.pavolhejny.com/',
3113
+ 'KNOWLEDGE ./hejny-cv.txt',
3114
+ 'KNOWLEDGE ./hejny-cv.md',
3115
+ 'KNOWLEDGE ./hejny-cv.pdf',
3116
+ 'KNOWLEDGE ./hejny-cv.docx',
3117
+ ],
3118
+ /**
3119
+ * Parses the KNOWLEDGE command
3120
+ */
3121
+ parse: function (input) {
3122
+ var args = input.args;
3123
+ var source = args[0];
3124
+ if (source === undefined) {
3125
+ throw new ParsingError("Source is not defined");
3126
+ }
3127
+ if (source.startsWith('http://')) {
3128
+ throw new ParsingError("Source is not secure");
3129
+ }
3130
+ if (!(isValidFilePath(source) || isValidUrl(source))) {
3131
+ throw new ParsingError("Source not valid");
3132
+ }
3133
+ if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
3134
+ throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
3135
+ }
3136
+ return {
3137
+ type: 'KNOWLEDGE',
3138
+ source: source,
3139
+ };
3140
+ },
3141
+ /**
3142
+ * Note: Prototype of [🍧] (remove this comment after full implementation)
3143
+ */
3144
+ applyToPipelineJson: function (pipelineJson, personaCommand) {
3145
+ var source = personaCommand.source;
3146
+ var name = titleToName(source);
3147
+ pipelineJson.knowledgeSources.push({
3148
+ name: name,
3149
+ source: source,
3150
+ });
3151
+ },
3152
+ };
3153
+
3154
+ /**
3155
+ * Parses the persona command
3156
+ *
3157
+ * @see ./PERSONA-README.md for more details
3158
+ * @private within the commands folder
3007
3159
  */
3160
+ var personaCommandParser = {
3161
+ /**
3162
+ * Name of the command
3163
+ */
3164
+ name: 'PERSONA',
3165
+ /**
3166
+ * Aliases for the PERSONA command
3167
+ */
3168
+ aliasNames: ['PERSON'],
3169
+ /**
3170
+ * PERSONA command can be used in:
3171
+ */
3172
+ usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
3173
+ /**
3174
+ * Description of the PERSONA command
3175
+ */
3176
+ description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
3177
+ /**
3178
+ * Link to discussion
3179
+ */
3180
+ discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
3181
+ /**
3182
+ * Example usages of the PERSONA command
3183
+ */
3184
+ examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
3185
+ /**
3186
+ * Parses the PERSONA command
3187
+ */
3188
+ parse: function (input) {
3189
+ var rawArgs = input.rawArgs;
3190
+ var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
3191
+ var personaName = (personaNameRaw || '').trim();
3192
+ if (personaName === '') {
3193
+ throw new ParsingError("You must set name for the persona");
3194
+ }
3195
+ var personaDescription = (personaDescriptionRaw || '').trim();
3196
+ if (personaDescription === '') {
3197
+ personaDescription = null;
3198
+ }
3199
+ return {
3200
+ type: 'PERSONA',
3201
+ personaName: personaName,
3202
+ personaDescription: personaDescription,
3203
+ };
3204
+ },
3205
+ /**
3206
+ * Note: Prototype of [🍧] (remove this comment after full implementation)
3207
+ */
3208
+ applyToPipelineJson: function (pipelineJson, personaCommand) {
3209
+ var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
3210
+ var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
3211
+ if (persona === undefined) {
3212
+ pipelineJson.personas.push({
3213
+ name: personaName,
3214
+ description: personaDescription || '',
3215
+ });
3216
+ return;
3217
+ }
3218
+ if (persona.description === personaDescription) {
3219
+ return;
3220
+ }
3221
+ if (personaDescription === null) {
3222
+ return;
3223
+ }
3224
+ if (persona.description === '') {
3225
+ persona.description = personaDescription;
3226
+ return;
3227
+ }
3228
+ console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
3229
+ persona.description += spaceTrim('\n\n' + personaDescription);
3230
+ },
3231
+ };
3008
3232
 
3009
3233
  /**
3010
3234
  * Removes Markdown formatting tags from a string.
@@ -3144,7 +3368,7 @@ var blockCommandParser = {
3144
3368
  'Knowledge BLOCK',
3145
3369
  // 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
3146
3370
  //---
3147
- /* TODO: !!!! Not implemented block types will be in examples in future -> */
3371
+ /* Note: Not implemented block types will be in examples in future -> */
3148
3372
  'Instrument BLOCK',
3149
3373
  // 'Instrument', // <- Note: [⛱]
3150
3374
  'Action BLOCK',
@@ -3160,13 +3384,12 @@ var blockCommandParser = {
3160
3384
  normalized = normalized.split('EXAMPLE').join('SAMPLE');
3161
3385
  var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
3162
3386
  if (blockTypes.length !== 1) {
3163
- // console.log('!!!', { blockType });
3164
3387
  throw new ParsingError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
3165
3388
  }
3166
- // TODO: !!!! Not supported yet
3389
+ var blockType = blockTypes[0];
3167
3390
  return {
3168
3391
  type: 'BLOCK',
3169
- blockType: blockTypes[0],
3392
+ blockType: blockType,
3170
3393
  };
3171
3394
  },
3172
3395
  };
@@ -3409,92 +3632,12 @@ var jokerCommandParser = {
3409
3632
  },
3410
3633
  };
3411
3634
 
3412
- /**
3413
- * Tests if given string is valid URL.
3414
- *
3415
- * Note: This does not check if the file exists only if the path is valid
3416
- */
3417
- function isValidFilePath(filePath) {
3418
- if (typeof filePath !== 'string') {
3419
- return false;
3420
- }
3421
- var filePathSlashes = filePath.split('\\').join('/');
3422
- // Absolute Unix path: /hello.txt
3423
- if (/^(\/)/i.test(filePathSlashes)) {
3424
- return true;
3425
- }
3426
- // Absolute Windows path: /hello.txt
3427
- if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
3428
- return true;
3429
- }
3430
- // Relative path: ./hello.txt
3431
- if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
3432
- return true;
3433
- }
3434
- return false;
3435
- }
3436
-
3437
- /**
3438
- * Parses the knowledge command
3439
- *
3440
- * @see ./KNOWLEDGE-README.md for more details
3441
- * @private within the commands folder
3442
- */
3443
- var knowledgeCommandParser = {
3444
- /**
3445
- * Name of the command
3446
- */
3447
- name: 'KNOWLEDGE',
3448
- /**
3449
- * BOILERPLATE command can be used in:
3450
- */
3451
- usagePlaces: ['PIPELINE_HEAD'],
3452
- /**
3453
- * Description of the KNOWLEDGE command
3454
- */
3455
- description: "Tells promptbook which external knowledge to use",
3456
- /**
3457
- * Link to discussion
3458
- */
3459
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
3460
- /**
3461
- * Example usages of the KNOWLEDGE command
3462
- */
3463
- examples: [
3464
- 'KNOWLEDGE https://www.pavolhejny.com/',
3465
- 'KNOWLEDGE ./hejny-cv.txt',
3466
- 'KNOWLEDGE ./hejny-cv.md',
3467
- 'KNOWLEDGE ./hejny-cv.pdf',
3468
- 'KNOWLEDGE ./hejny-cv.docx',
3469
- ],
3470
- /**
3471
- * Parses the KNOWLEDGE command
3472
- */
3473
- parse: function (input) {
3474
- var args = input.args;
3475
- var source = args[0];
3476
- if (source === undefined) {
3477
- throw new ParsingError("Source is not defined");
3478
- }
3479
- if (source.startsWith('http://')) {
3480
- throw new ParsingError("Source is not secure");
3481
- }
3482
- if (!(isValidFilePath(source) || isValidUrl(source))) {
3483
- throw new ParsingError("Source not valid");
3484
- }
3485
- if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
3486
- throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
3487
- }
3488
- return {
3489
- type: 'KNOWLEDGE',
3490
- source: source,
3491
- };
3492
- },
3493
- };
3494
-
3495
3635
  var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
3496
3636
  /**
3497
- * TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
3637
+ * TODO: [🧠][🈁] `seed` should maybe be somewhere else (not in `ModelRequirements`) (simmilar that `user` identification is not here)
3638
+ * TODO: [🧠][💱] Add more model options: `stop_token`, `logit_bias`, `logprobs` (`top_logprobs`), `top_k`, `top_p`, `presence_penalty`, `frequency_penalty`, `bestOf`, `logitBias`, `logitBiasType`,...
3639
+ * [💱] Probbably keep using just `temperature` in Promptbook (not `top_k` and `top_p`)
3640
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3498
3641
  * TODO: Maybe figure out better word than "variant"
3499
3642
  * TODO: Add here more requirement options like max context size, max tokens, etc.
3500
3643
  * TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
@@ -3636,59 +3779,6 @@ var parameterCommandParser = {
3636
3779
  },
3637
3780
  };
3638
3781
 
3639
- /**
3640
- * Parses the persona command
3641
- *
3642
- * @see ./PERSONA-README.md for more details
3643
- * @private within the commands folder
3644
- */
3645
- var personaCommandParser = {
3646
- /**
3647
- * Name of the command
3648
- */
3649
- name: 'PERSONA',
3650
- /**
3651
- * Aliases for the PERSONA command
3652
- */
3653
- aliasNames: ['PERSON'],
3654
- /**
3655
- * PERSONA command can be used in:
3656
- */
3657
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
3658
- /**
3659
- * Description of the PERSONA command
3660
- */
3661
- description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
3662
- /**
3663
- * Link to discussion
3664
- */
3665
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
3666
- /**
3667
- * Example usages of the PERSONA command
3668
- */
3669
- examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
3670
- /**
3671
- * Parses the PERSONA command
3672
- */
3673
- parse: function (input) {
3674
- var rawArgs = input.rawArgs;
3675
- var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
3676
- var personaName = (personaNameRaw || '').trim();
3677
- if (personaName === '') {
3678
- throw new ParsingError("You must set name for the persona");
3679
- }
3680
- var personaDescription = (personaDescriptionRaw || '').trim();
3681
- if (personaDescription === '') {
3682
- personaDescription = null;
3683
- }
3684
- return {
3685
- type: 'PERSONA',
3686
- personaName: personaName,
3687
- personaDescription: personaDescription,
3688
- };
3689
- },
3690
- };
3691
-
3692
3782
  function isValidJavascriptName(javascriptName) {
3693
3783
  if (typeof javascriptName !== 'string') {
3694
3784
  return false;
@@ -3875,22 +3965,6 @@ var urlCommandParser = {
3875
3965
  },
3876
3966
  };
3877
3967
 
3878
- /**
3879
- * Returns the same value that is passed as argument.
3880
- * No side effects.
3881
- *
3882
- * Note: It can be usefull for leveling indentation
3883
- *
3884
- * @param value any values
3885
- * @returns the same values
3886
- */
3887
- function just(value) {
3888
- if (value === undefined) {
3889
- return undefined;
3890
- }
3891
- return value;
3892
- }
3893
-
3894
3968
  /**
3895
3969
  * Parses the action command
3896
3970
  *
@@ -3922,7 +3996,8 @@ var actionCommandParser = {
3922
3996
  * Parses the ACTION command
3923
3997
  */
3924
3998
  parse: function (input) {
3925
- input.args;
3999
+ var args = input.args;
4000
+ TODO_USE(args);
3926
4001
  return {
3927
4002
  type: 'ACTION',
3928
4003
  };
@@ -3960,7 +4035,8 @@ var instrumentCommandParser = {
3960
4035
  * Parses the INSTRUMENT command
3961
4036
  */
3962
4037
  parse: function (input) {
3963
- input.args;
4038
+ var args = input.args;
4039
+ TODO_USE(args);
3964
4040
  return {
3965
4041
  type: 'INSTRUMENT',
3966
4042
  };
@@ -4018,6 +4094,7 @@ var boilerplateCommandParser = {
4018
4094
  };
4019
4095
  /**
4020
4096
  * TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
4097
+ * Note: [⚪] This should never be in any released package
4021
4098
  */
4022
4099
 
4023
4100
  /**
@@ -4036,7 +4113,7 @@ var COMMANDS = [
4036
4113
  actionCommandParser,
4037
4114
  instrumentCommandParser,
4038
4115
  personaCommandParser,
4039
- boilerplateCommandParser, // <- TODO: !!!! Only in development, remove in production
4116
+ boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
4040
4117
  ];
4041
4118
 
4042
4119
  /**
@@ -4122,7 +4199,7 @@ function parseCommand(raw, usagePlace) {
4122
4199
  }));
4123
4200
  }
4124
4201
  /**
4125
- * !!!
4202
+ * @@@
4126
4203
  */
4127
4204
  function getSupportedCommandsMessage() {
4128
4205
  return COMMANDS.flatMap(function (_a) {
@@ -4133,7 +4210,7 @@ function getSupportedCommandsMessage() {
4133
4210
  }).join('\n');
4134
4211
  }
4135
4212
  /**
4136
- * !!!
4213
+ * @@@
4137
4214
  */
4138
4215
  function parseCommandVariant(input) {
4139
4216
  var e_1, _a;
@@ -4142,7 +4219,6 @@ function parseCommandVariant(input) {
4142
4219
  var _loop_1 = function (commandParser) {
4143
4220
  var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
4144
4221
  var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
4145
- // console.log('!!!', { commandName, names });
4146
4222
  if (names.includes(commandName)) {
4147
4223
  try {
4148
4224
  return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
@@ -4252,25 +4328,42 @@ function extractAllBlocksFromMarkdown(markdown) {
4252
4328
  var e_1, _a;
4253
4329
  var codeBlocks = [];
4254
4330
  var lines = markdown.split('\n');
4331
+ // Note: [0] Ensure that the last block notated by gt > will be closed
4332
+ lines.push('');
4255
4333
  var currentCodeBlock = null;
4256
4334
  try {
4257
4335
  for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
4258
4336
  var line = lines_1_1.value;
4337
+ if (line.startsWith('> ') || line === '>') {
4338
+ if (currentCodeBlock === null) {
4339
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
4340
+ } /* not else */
4341
+ if (currentCodeBlock.blockNotation === '>') {
4342
+ if (currentCodeBlock.content !== '') {
4343
+ currentCodeBlock.content += '\n';
4344
+ }
4345
+ currentCodeBlock.content += line.slice(2);
4346
+ }
4347
+ }
4348
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
4349
+ codeBlocks.push(currentCodeBlock);
4350
+ currentCodeBlock = null;
4351
+ }
4352
+ /* not else */
4259
4353
  if (line.startsWith('```')) {
4260
4354
  var language = line.slice(3).trim() || null;
4261
4355
  if (currentCodeBlock === null) {
4262
- currentCodeBlock = { language: language, content: '' };
4356
+ currentCodeBlock = { blockNotation: '```', language: language, content: '' };
4263
4357
  }
4264
4358
  else {
4265
4359
  if (language !== null) {
4266
- // [🌻]
4267
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
4360
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
4268
4361
  }
4269
4362
  codeBlocks.push(currentCodeBlock);
4270
4363
  currentCodeBlock = null;
4271
4364
  }
4272
4365
  }
4273
- else if (currentCodeBlock !== null) {
4366
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
4274
4367
  if (currentCodeBlock.content !== '') {
4275
4368
  currentCodeBlock.content += '\n';
4276
4369
  }
@@ -4286,11 +4379,13 @@ function extractAllBlocksFromMarkdown(markdown) {
4286
4379
  finally { if (e_1) throw e_1.error; }
4287
4380
  }
4288
4381
  if (currentCodeBlock !== null) {
4289
- // [🌻]
4290
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
4382
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
4291
4383
  }
4292
4384
  return codeBlocks;
4293
4385
  }
4386
+ /**
4387
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
4388
+ */
4294
4389
 
4295
4390
  /**
4296
4391
  * Extracts exactly ONE code block from markdown.
@@ -4308,13 +4403,12 @@ function extractAllBlocksFromMarkdown(markdown) {
4308
4403
  function extractOneBlockFromMarkdown(markdown) {
4309
4404
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
4310
4405
  if (codeBlocks.length !== 1) {
4311
- // TODO: Report more specific place where the error happened
4312
- throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
4406
+ throw new ParsingError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
4313
4407
  }
4314
4408
  return codeBlocks[0];
4315
4409
  }
4316
4410
  /***
4317
- * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
4411
+ * TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
4318
4412
  */
4319
4413
 
4320
4414
  /**
@@ -4324,13 +4418,13 @@ function parseMarkdownSection(value) {
4324
4418
  var _a, _b;
4325
4419
  var lines = value.split('\n');
4326
4420
  if (!lines[0].startsWith('#')) {
4327
- throw new Error('Markdown section must start with heading');
4421
+ throw new ParsingError('Markdown section must start with heading');
4328
4422
  }
4329
4423
  var title = lines[0].replace(/^#+\s*/, '');
4330
4424
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
4331
4425
  var content = spaceTrim(lines.slice(1).join('\n'));
4332
4426
  if (level < 1 || level > 6) {
4333
- throw new Error('Markdown section must have heading level between 1 and 6');
4427
+ throw new ParsingError('Markdown section must have heading level between 1 and 6');
4334
4428
  }
4335
4429
  return { title: title, level: level, content: content };
4336
4430
  }
@@ -4712,7 +4806,7 @@ function pipelineStringToJsonSync(pipelineString) {
4712
4806
  existingParameter.description &&
4713
4807
  existingParameter.description !== parameterDescription &&
4714
4808
  parameterDescription) {
4715
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
4809
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
4716
4810
  }
4717
4811
  if (existingParameter) {
4718
4812
  if (parameterDescription) {
@@ -4731,11 +4825,12 @@ function pipelineStringToJsonSync(pipelineString) {
4731
4825
  // =============================================================
4732
4826
  // Note: 3️⃣ Process pipeline head
4733
4827
  pipelineJson.title = pipelineHead.title;
4734
- // TODO: [1] DRY description
4828
+ // TODO: [🎾][1] DRY description
4735
4829
  var description = pipelineHead.content;
4736
- // Note: Remove codeblocks - TODO: Maybe put this into util (exported from `@promptbool/utils`)
4830
+ // Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
4737
4831
  description = description.split(/^```.*^```/gms).join('');
4738
- //Note: Remove lists and return statement - TODO: Maybe put this into util (exported from `@promptbool/utils`)
4832
+ description = description.split(/^>.*$/gm).join('');
4833
+ //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
4739
4834
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
4740
4835
  description = spaceTrim$1(description);
4741
4836
  if (description === '') {
@@ -4763,7 +4858,7 @@ function pipelineStringToJsonSync(pipelineString) {
4763
4858
  pipelineJson.pipelineUrl = command.pipelineUrl.href;
4764
4859
  break;
4765
4860
  case 'KNOWLEDGE':
4766
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
4861
+ knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
4767
4862
  break;
4768
4863
  case 'ACTION':
4769
4864
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
@@ -4772,7 +4867,8 @@ function pipelineStringToJsonSync(pipelineString) {
4772
4867
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4773
4868
  break;
4774
4869
  case 'PERSONA':
4775
- console.error(new NotYetImplementedError('Personas are not implemented yet'));
4870
+ personaCommandParser.applyToPipelineJson(pipelineJson, command);
4871
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
4776
4872
  break;
4777
4873
  case 'BOILERPLATE':
4778
4874
  throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
@@ -4801,7 +4897,27 @@ function pipelineStringToJsonSync(pipelineString) {
4801
4897
  var postprocessing = [];
4802
4898
  var expectAmount = {};
4803
4899
  var expectFormat = undefined;
4804
- var isBlockTypeChanged = false;
4900
+ var isBlockTypeSet = false;
4901
+ var lastLine = section.content.split('\n').pop();
4902
+ var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
4903
+ var resultingParameterName = null;
4904
+ if (resultingParameterNameMatch &&
4905
+ resultingParameterNameMatch.groups !== undefined &&
4906
+ resultingParameterNameMatch.groups.resultingParamName !== undefined) {
4907
+ resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
4908
+ }
4909
+ var expectResultingParameterName = function () {
4910
+ if (resultingParameterName !== null) {
4911
+ return resultingParameterName;
4912
+ }
4913
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
4914
+ // TODO: Show code of invalid sections each time + DRY
4915
+ section.content
4916
+ .split('\n')
4917
+ .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
4918
+ .join('\n')), "\n "); }));
4919
+ };
4920
+ var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
4805
4921
  try {
4806
4922
  for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
4807
4923
  var listItem = listItems_2_1.value;
@@ -4809,15 +4925,24 @@ function pipelineStringToJsonSync(pipelineString) {
4809
4925
  switch (command.type) {
4810
4926
  // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
4811
4927
  case 'BLOCK':
4812
- if (isBlockTypeChanged) {
4928
+ if (isBlockTypeSet) {
4813
4929
  throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
4814
4930
  }
4815
4931
  if (command.blockType === 'SAMPLE') {
4816
- console.error(new NotYetImplementedError('Block type SAMPLE is not implemented yet'));
4932
+ expectResultingParameterName();
4933
+ var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
4934
+ if (parameter === undefined) {
4935
+ throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
4936
+ }
4937
+ parameter.sampleValues = parameter.sampleValues || [];
4938
+ parameter.sampleValues.push(content);
4817
4939
  return "continue-templates";
4818
4940
  }
4819
4941
  if (command.blockType === 'KNOWLEDGE') {
4820
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
4942
+ knowledgeCommandParser.applyToPipelineJson(pipelineJson, {
4943
+ type: 'KNOWLEDGE',
4944
+ source: content, // <- TODO: [🐝] !!!! Work with KNOWLEDGE which not referring to the source file/wweb, but its content itself
4945
+ });
4821
4946
  return "continue-templates";
4822
4947
  }
4823
4948
  if (command.blockType === 'ACTION') {
@@ -4828,8 +4953,9 @@ function pipelineStringToJsonSync(pipelineString) {
4828
4953
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4829
4954
  return "continue-templates";
4830
4955
  }
4956
+ expectResultingParameterName();
4831
4957
  blockType = command.blockType;
4832
- isBlockTypeChanged = true;
4958
+ isBlockTypeSet = true;
4833
4959
  break;
4834
4960
  case 'EXPECT_AMOUNT':
4835
4961
  // eslint-disable-next-line no-case-declarations
@@ -4869,16 +4995,20 @@ function pipelineStringToJsonSync(pipelineString) {
4869
4995
  postprocessing.push(command.functionName);
4870
4996
  break;
4871
4997
  case 'KNOWLEDGE':
4872
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
4998
+ // TODO: [👙] The knowledge is maybe relevant for just this template
4999
+ knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
4873
5000
  break;
4874
5001
  case 'ACTION':
5002
+ // TODO: [👙] The action is maybe relevant for just this template
4875
5003
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
4876
5004
  break;
4877
5005
  case 'INSTRUMENT':
5006
+ // TODO: [👙] The instrument is maybe relevant for just this template
4878
5007
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4879
5008
  break;
4880
5009
  case 'PERSONA':
4881
- console.error(new NotYetImplementedError('Personas are not implemented yet'));
5010
+ personaCommandParser.applyToPipelineJson(pipelineJson, command);
5011
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
4882
5012
  break;
4883
5013
  case 'BOILERPLATE':
4884
5014
  console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
@@ -4896,7 +5026,6 @@ function pipelineStringToJsonSync(pipelineString) {
4896
5026
  }
4897
5027
  finally { if (e_3) throw e_3.error; }
4898
5028
  }
4899
- var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
4900
5029
  if (blockType === 'SCRIPT') {
4901
5030
  if (!language) {
4902
5031
  throw new ParsingError('You must specify the language of the script in the prompt template');
@@ -4905,22 +5034,12 @@ function pipelineStringToJsonSync(pipelineString) {
4905
5034
  throw new ParsingError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
4906
5035
  }
4907
5036
  }
4908
- var lastLine = section.content.split('\n').pop();
4909
- var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
4910
- if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
4911
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Each section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
4912
- // TODO: Show code of invalid sections each time + DRY
4913
- section.content
4914
- .split('\n')
4915
- .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
4916
- .join('\n')), "\n "); }));
4917
- }
4918
- var resultingParameterName = match.groups.resultingParamName;
4919
- // TODO: [1] DRY description
5037
+ // TODO: [🎾][1] DRY description
4920
5038
  var description_1 = section.content;
4921
- // Note: Remove codeblocks
5039
+ // Note: Remove codeblocks - TODO: [🎾]
4922
5040
  description_1 = description_1.split(/^```.*^```/gms).join('');
4923
- //Note: Remove lists and return statement
5041
+ description_1 = description_1.split(/^>.*$/gm).join('');
5042
+ //Note: Remove lists and return statement - TODO: [🎾]
4924
5043
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
4925
5044
  description_1 = spaceTrim$1(description_1);
4926
5045
  if (description_1 === '') {
@@ -4954,13 +5073,13 @@ function pipelineStringToJsonSync(pipelineString) {
4954
5073
  modelRequirements: templateModelRequirements,
4955
5074
  contentLanguage: blockType === 'SCRIPT' ? language : undefined,
4956
5075
  content: content,
4957
- resultingParameterName: resultingParameterName,
5076
+ resultingParameterName: expectResultingParameterName( /* <- Note: This is once more redundant */),
4958
5077
  };
4959
5078
  if (blockType !== 'PROMPT_TEMPLATE') {
4960
5079
  delete template.modelRequirements;
4961
5080
  }
4962
5081
  // TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
4963
- pipelineJson.promptTemplates.push(template /* <- !!! */);
5082
+ pipelineJson.promptTemplates.push(template);
4964
5083
  };
4965
5084
  try {
4966
5085
  // =============================================================
@@ -5027,6 +5146,8 @@ function pipelineStringToJsonSync(pipelineString) {
5027
5146
  * TODO: Use spaceTrim more effectively
5028
5147
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
5029
5148
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
5149
+ * TODO: [♈] Probbably move expectations from templates to parameters
5150
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
5030
5151
  */
5031
5152
 
5032
5153
  /**
@@ -5066,12 +5187,13 @@ function pipelineStringToJson(pipelineString, options) {
5066
5187
  }
5067
5188
  /**
5068
5189
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
5190
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
5069
5191
  */
5070
5192
 
5071
5193
  /**
5072
5194
  * Add or modify an auto-generated section in a markdown file
5073
5195
  *
5074
- * @private within the package
5196
+ * @private within the repository
5075
5197
  */
5076
5198
  function addAutoGeneratedSection(content, options) {
5077
5199
  var sectionName = options.sectionName, sectionContent = options.sectionContent;
@@ -5083,7 +5205,10 @@ function addAutoGeneratedSection(content, options) {
5083
5205
  }
5084
5206
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
5085
5207
  if (!placeForSection) {
5086
- throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
5208
+ throw new ParsingError(
5209
+ // <- [🧠] Maybe something better than `ParsingError`
5210
+ "No place where to put the section <!--".concat(sectionName, "-->"));
5211
+ // <- [🚞]
5087
5212
  }
5088
5213
  var _a = __read(placeForSection, 1), heading = _a[0];
5089
5214
  return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
@@ -5257,15 +5382,15 @@ var CollectionError = /** @class */ (function (_super) {
5257
5382
  /**
5258
5383
  * This error type indicates that the version of the pipeline is not matching the expected version
5259
5384
  */
5260
- var VersionMismatch = /** @class */ (function (_super) {
5261
- __extends(VersionMismatch, _super);
5262
- function VersionMismatch(message, expectedVersion) {
5385
+ var VersionMismatchError = /** @class */ (function (_super) {
5386
+ __extends(VersionMismatchError, _super);
5387
+ function VersionMismatchError(message, expectedVersion) {
5263
5388
  var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n This error indicates that there is error with compatibility\n\n Expected version:\n ").concat(expectedVersion, "\n\n Current version:\n ").concat(PROMPTBOOK_VERSION, "\n\n "); })) || this;
5264
5389
  _this.name = 'UnexpectedError';
5265
- Object.setPrototypeOf(_this, VersionMismatch.prototype);
5390
+ Object.setPrototypeOf(_this, VersionMismatchError.prototype);
5266
5391
  return _this;
5267
5392
  }
5268
- return VersionMismatch;
5393
+ return VersionMismatchError;
5269
5394
  }(Error));
5270
5395
 
5271
5396
  /**
@@ -5355,6 +5480,9 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
5355
5480
  };
5356
5481
  return SimplePromptInterfaceTools;
5357
5482
  }());
5483
+ /**
5484
+ * Note: [🔵] This code should never be published outside of `@promptbook/browser`
5485
+ */
5358
5486
 
5359
5487
  /**
5360
5488
  * Unprepare just strips the preparation data of the pipeline
@@ -5366,6 +5494,7 @@ function unpreparePipeline(pipeline) {
5366
5494
  return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
5367
5495
  }
5368
5496
  /**
5497
+ * TODO: [🔼] !!! Export via `@promptbook/core`
5369
5498
  * TODO: Write tests for `preparePipeline`
5370
5499
  */
5371
5500
 
@@ -5380,7 +5509,7 @@ var ExecutionReportStringOptionsDefaults = {
5380
5509
  /**
5381
5510
  * Format either small or big number
5382
5511
  *
5383
- * @private within the package
5512
+ * @private within the repository
5384
5513
  */
5385
5514
  function formatNumber(value) {
5386
5515
  if (value === 0) {
@@ -5400,7 +5529,7 @@ function formatNumber(value) {
5400
5529
  /**
5401
5530
  * Create a markdown table from a 2D array of strings
5402
5531
  *
5403
- * @private within the package
5532
+ * @private within the repository
5404
5533
  */
5405
5534
  function createMarkdownTable(table) {
5406
5535
  var columnWidths = table.reduce(function (widths, row) {
@@ -5428,7 +5557,7 @@ function createMarkdownTable(table) {
5428
5557
  /**
5429
5558
  * Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
5430
5559
  *
5431
- * @private within the package
5560
+ * @private within the repository
5432
5561
  */
5433
5562
  function createMarkdownChart(options) {
5434
5563
  var e_1, _a;
@@ -5469,6 +5598,23 @@ function escapeMarkdownBlock(value) {
5469
5598
  return value.replace(/```/g, '\\`\\`\\`');
5470
5599
  }
5471
5600
 
5601
+ /**
5602
+ * Returns the same value that is passed as argument.
5603
+ * No side effects.
5604
+ *
5605
+ * Note: It can be usefull for leveling indentation
5606
+ *
5607
+ * @param value any values
5608
+ * @returns the same values
5609
+ * @private within the repository
5610
+ */
5611
+ function just(value) {
5612
+ if (value === undefined) {
5613
+ return undefined;
5614
+ }
5615
+ return value;
5616
+ }
5617
+
5472
5618
  /**
5473
5619
  * The thresholds for the relative time in the `moment` NPM package.
5474
5620
  *
@@ -5481,7 +5627,7 @@ var MOMENT_ARG_THRESHOLDS = {
5481
5627
  /**
5482
5628
  * Count the duration of working time
5483
5629
  *
5484
- * @private within the package
5630
+ * @private within the repository
5485
5631
  */
5486
5632
  function countWorkingDuration(items) {
5487
5633
  var e_1, _a;
@@ -5679,5 +5825,5 @@ function executionReportJsonToString(executionReportJson, options) {
5679
5825
  * TODO: [🧠] Allow to filter out some parts of the report by options
5680
5826
  */
5681
5827
 
5682
- export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatch, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, preparePipeline, prettifyPipelineString, unpreparePipeline, usageToWorktime, validatePipeline };
5828
+ export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatchError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, preparePipeline, prettifyPipelineString, unpreparePipeline, usageToWorktime, validatePipeline };
5683
5829
  //# sourceMappingURL=index.es.js.map