@promptbook/cli 0.61.0-1 → 0.61.0-10

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 (162) hide show
  1. package/README.md +1 -1
  2. package/esm/index.es.js +417 -150
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/promptbook-collection/index.d.ts +118 -26
  5. package/esm/typings/src/_packages/core.index.d.ts +5 -1
  6. package/esm/typings/src/_packages/types.index.d.ts +5 -3
  7. package/esm/typings/src/_packages/utils.index.d.ts +1 -2
  8. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
  9. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
  10. package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +1 -1
  11. package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +1 -1
  12. package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
  13. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +12 -12
  14. package/esm/typings/src/config.d.ts +4 -0
  15. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +8 -5
  16. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +3 -3
  17. package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
  18. package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
  19. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +2 -2
  20. package/esm/typings/src/errors/VersionMismatch.d.ts +8 -0
  21. package/esm/typings/src/execution/PipelineExecutor.d.ts +5 -5
  22. package/esm/typings/src/execution/PromptResult.d.ts +5 -5
  23. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +3 -3
  24. package/esm/typings/src/execution/UserInterfaceTools.d.ts +5 -5
  25. package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -1
  26. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
  27. package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
  28. package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -1
  29. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -1
  30. package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +1 -1
  31. package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
  32. package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
  33. package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
  34. package/esm/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +7 -0
  35. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +8 -23
  36. package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +7 -14
  37. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  38. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
  39. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
  40. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  41. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +2 -2
  42. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
  43. package/esm/typings/src/personas/preparePersona.d.ts +13 -0
  44. package/esm/typings/src/personas/preparePersona.test.d.ts +1 -0
  45. package/esm/typings/src/prepare/PrepareOptions.d.ts +22 -0
  46. package/esm/typings/src/prepare/preparePipeline.d.ts +15 -0
  47. package/esm/typings/src/prepare/unpreparePipeline.d.ts +8 -0
  48. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
  49. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  50. package/esm/typings/src/types/ModelRequirements.d.ts +2 -1
  51. package/esm/typings/src/types/Parameters.d.ts +1 -0
  52. package/esm/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
  53. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
  54. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
  55. package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +8 -1
  56. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +40 -0
  57. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +27 -2
  58. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +25 -0
  59. package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +2 -0
  60. package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
  61. package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +7 -1
  62. package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
  63. package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
  64. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
  65. package/esm/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
  66. package/esm/typings/src/types/typeAliases.d.ts +27 -13
  67. package/esm/typings/src/utils/FromtoItems.d.ts +3 -3
  68. package/esm/typings/src/utils/currentDate.d.ts +7 -0
  69. package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +2 -2
  70. package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +6 -9
  71. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  72. package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
  73. package/esm/typings/src/utils/organization/TODO.d.ts +4 -0
  74. package/esm/typings/src/utils/organization/TODO_USE.d.ts +11 -0
  75. package/esm/typings/src/utils/organization/___.d.ts +4 -0
  76. package/esm/typings/src/utils/organization/really_any.d.ts +4 -0
  77. package/package.json +2 -2
  78. package/umd/index.umd.js +417 -150
  79. package/umd/index.umd.js.map +1 -1
  80. package/umd/typings/promptbook-collection/index.d.ts +118 -26
  81. package/umd/typings/src/_packages/core.index.d.ts +5 -1
  82. package/umd/typings/src/_packages/types.index.d.ts +5 -3
  83. package/umd/typings/src/_packages/utils.index.d.ts +1 -2
  84. package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
  85. package/umd/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
  86. package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +1 -1
  87. package/umd/typings/src/commands/MODEL/ModelCommand.d.ts +1 -1
  88. package/umd/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
  89. package/umd/typings/src/commands/_common/types/CommandParser.d.ts +12 -12
  90. package/umd/typings/src/config.d.ts +4 -0
  91. package/umd/typings/src/conversion/pipelineStringToJson.d.ts +8 -5
  92. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +3 -3
  93. package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
  94. package/umd/typings/src/conversion/utils/renameParameter.d.ts +3 -3
  95. package/umd/typings/src/conversion/validation/_importPipeline.d.ts +2 -2
  96. package/umd/typings/src/errors/VersionMismatch.d.ts +8 -0
  97. package/umd/typings/src/execution/PipelineExecutor.d.ts +5 -5
  98. package/umd/typings/src/execution/PromptResult.d.ts +5 -5
  99. package/umd/typings/src/execution/ScriptExecutionTools.d.ts +3 -3
  100. package/umd/typings/src/execution/UserInterfaceTools.d.ts +5 -5
  101. package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -1
  102. package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
  103. package/umd/typings/src/execution/utils/forEachAsync.d.ts +1 -1
  104. package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -1
  105. package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -1
  106. package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +1 -1
  107. package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
  108. package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
  109. package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
  110. package/umd/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +7 -0
  111. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +8 -23
  112. package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +7 -14
  113. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  114. package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +2 -2
  115. package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
  116. package/umd/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  117. package/umd/typings/src/llm-providers/openai/openai-models.d.ts +2 -2
  118. package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
  119. package/umd/typings/src/personas/preparePersona.d.ts +13 -0
  120. package/umd/typings/src/personas/preparePersona.test.d.ts +1 -0
  121. package/umd/typings/src/prepare/PrepareOptions.d.ts +22 -0
  122. package/umd/typings/src/prepare/preparePipeline.d.ts +15 -0
  123. package/umd/typings/src/prepare/unpreparePipeline.d.ts +8 -0
  124. package/umd/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
  125. package/umd/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  126. package/umd/typings/src/types/ModelRequirements.d.ts +2 -1
  127. package/umd/typings/src/types/Parameters.d.ts +1 -0
  128. package/umd/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
  129. package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +67 -0
  130. package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +24 -0
  131. package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +8 -1
  132. package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +40 -0
  133. package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +27 -2
  134. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +25 -0
  135. package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +2 -0
  136. package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
  137. package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +7 -1
  138. package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +2 -0
  139. package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +2 -0
  140. package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
  141. package/umd/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
  142. package/umd/typings/src/types/typeAliases.d.ts +27 -13
  143. package/umd/typings/src/utils/FromtoItems.d.ts +3 -3
  144. package/umd/typings/src/utils/currentDate.d.ts +7 -0
  145. package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +2 -2
  146. package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +6 -9
  147. package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  148. package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
  149. package/umd/typings/src/utils/organization/TODO.d.ts +4 -0
  150. package/umd/typings/src/utils/organization/TODO_USE.d.ts +11 -0
  151. package/umd/typings/src/utils/organization/___.d.ts +4 -0
  152. package/umd/typings/src/utils/organization/really_any.d.ts +4 -0
  153. package/esm/typings/src/personas/personaToModelRequirements.d.ts +0 -6
  154. package/esm/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
  155. package/esm/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
  156. package/umd/typings/src/personas/personaToModelRequirements.d.ts +0 -6
  157. package/umd/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
  158. package/umd/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
  159. /package/esm/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
  160. /package/esm/typings/src/utils/{just.d.ts → organization/just.d.ts} +0 -0
  161. /package/umd/typings/src/_packages/{markdown-utils.d.ts → markdown-utils.index.d.ts} +0 -0
  162. /package/umd/typings/src/utils/{just.d.ts → organization/just.d.ts} +0 -0
package/umd/index.umd.js CHANGED
@@ -149,7 +149,7 @@
149
149
  /**
150
150
  * The version of the Promptbook library
151
151
  */
152
- var PROMPTBOOK_VERSION = '0.61.0-0';
152
+ var PROMPTBOOK_VERSION = '0.61.0-9';
153
153
  // TODO: !!!! List here all the versions and annotate + put into script
154
154
 
155
155
  /**
@@ -215,6 +215,10 @@
215
215
  * The maximum number of iterations for a loops which adds characters one by one
216
216
  */
217
217
  var CHARACTER_LOOP_LIMIT = 100000;
218
+ /**
219
+ * The maximum number of (LLM) tasks running in parallel
220
+ */
221
+ var MAX_PARALLEL_COUNT = 5;
218
222
  /**
219
223
  * The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
220
224
  */
@@ -228,7 +232,172 @@
228
232
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
229
233
  ];
230
234
 
231
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-0",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",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledge:[{name:"u",title:"U",content:"E",keywords:["E"],index:[{modelName:"mocked-facked",position:[0.3862088172833116,0.7349284028017404,-0.9438230019966163,-0.9250069104750818,-0.026138914694730175,-0.7268311159817045,-0.07935019253731612,0.6470171268509612,-0.43852570574155214,0.34435062959144824,-0.03450022605546588,-0.5277705379240651,0.00828213142899159,0.15691069644743383,-0.625404064630672,-0.33277847012240613,-0.2936622789266794,0.18401827710902152,0.3055511517178138,0.2943796117307138,0.7709829510346151,-0.4424955841467506,0.6031092188828207,-0.02473045258733153,0.33586695334417804]}],sources:[{title:"Markdown document",href:"#"}]}],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-0",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",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"keywords"}],knowledge:[{name:"s",title:"S",content:"A",keywords:["I"],index:[{modelName:"mocked-facked",position:[0.6409598940537844,-0.599282163088533,-0.7951357406825994,0.5034713531055992,0.9186084716269733,-0.6841151439158257,-0.39762364246107484,-0.7646814627420149,0.9551202443145854,0.36871821752653666,0.27710484531156565,-0.6886362623745139,0.1246419058549284,-0.7957866917804912,-0.4688680561538634,-0.7037555014650994,0.003694510488622793,0.3186841135345695,-0.7081253398806422,0.7052620275090136,-0.9744710956043585,0.6828863755008538,-0.021569809814358187,-0.23961644339743904,-0.5963677915161343]}],sources:[{title:"Markdown document",href:"#"}]}],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-0",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}},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"}],knowledge:[{name:"c",title:"C",content:"A",keywords:["E"],index:[{modelName:"mocked-facked",position:[0.3053077802556703,0.45834476154202175,0.11951317167907494,-0.8925032092763412,-0.041809804577583876,-0.7087885568549193,0.0373992576888198,0.9495631083993494,-0.6050023289380846,0.14919003109680862,-0.3228347383159025,0.3273383195761892,-0.5509884895794359,0.7137115707360451,-0.3455818427015154,-0.7130289858826453,0.6105746565153107,-0.30829913719966573,0.6287711326338274,-0.8588121879147286,-0.583980568533244,-0.23082011458606733,-0.10987445073290791,-0.1129755192200137,0.4046462365369812]}],sources:[{title:"Markdown document",href:"#"}]}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"}];
235
+ /**
236
+ * Function `addUsage` will add multiple usages into one
237
+ *
238
+ * Note: If you provide 0 values, it returns void usage
239
+ */
240
+ function addUsage() {
241
+ var usageItems = [];
242
+ for (var _i = 0; _i < arguments.length; _i++) {
243
+ usageItems[_i] = arguments[_i];
244
+ }
245
+ var initialStructure = {
246
+ price: { value: 0 },
247
+ input: {
248
+ tokensCount: { value: 0 },
249
+ charactersCount: { value: 0 },
250
+ wordsCount: { value: 0 },
251
+ sentencesCount: { value: 0 },
252
+ linesCount: { value: 0 },
253
+ paragraphsCount: { value: 0 },
254
+ pagesCount: { value: 0 },
255
+ },
256
+ output: {
257
+ tokensCount: { value: 0 },
258
+ charactersCount: { value: 0 },
259
+ wordsCount: { value: 0 },
260
+ sentencesCount: { value: 0 },
261
+ linesCount: { value: 0 },
262
+ paragraphsCount: { value: 0 },
263
+ pagesCount: { value: 0 },
264
+ },
265
+ };
266
+ return usageItems.reduce(function (acc, item) {
267
+ var e_1, _a, e_2, _b;
268
+ var _c;
269
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
270
+ try {
271
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
272
+ var key = _e.value;
273
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
274
+ //@ts-ignore
275
+ if (item.input[key]) {
276
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
277
+ //@ts-ignore
278
+ acc.input[key].value += item.input[key].value || 0;
279
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
280
+ //@ts-ignore
281
+ if (item.input[key].isUncertain) {
282
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
283
+ //@ts-ignore
284
+ acc.input[key].isUncertain = true;
285
+ }
286
+ }
287
+ }
288
+ }
289
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
290
+ finally {
291
+ try {
292
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
293
+ }
294
+ finally { if (e_1) throw e_1.error; }
295
+ }
296
+ try {
297
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
298
+ var key = _g.value;
299
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
300
+ //@ts-ignore
301
+ if (item.output[key]) {
302
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
303
+ //@ts-ignore
304
+ acc.output[key].value += item.output[key].value || 0;
305
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
306
+ //@ts-ignore
307
+ if (item.output[key].isUncertain) {
308
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
309
+ //@ts-ignore
310
+ acc.output[key].isUncertain = true;
311
+ }
312
+ }
313
+ }
314
+ }
315
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
316
+ finally {
317
+ try {
318
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
319
+ }
320
+ finally { if (e_2) throw e_2.error; }
321
+ }
322
+ return acc;
323
+ }, initialStructure);
324
+ }
325
+
326
+ /**
327
+ * Async version of Array.forEach
328
+ *
329
+ * @param array - Array to iterate over
330
+ * @param options - Options for the function
331
+ * @param callbackfunction - Function to call for each item
332
+ */
333
+ function forEachAsync(array, options, callbackfunction) {
334
+ return __awaiter(this, void 0, void 0, function () {
335
+ var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
336
+ var e_1, _d;
337
+ return __generator(this, function (_e) {
338
+ switch (_e.label) {
339
+ case 0:
340
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
341
+ index = 0;
342
+ runningTasks = [];
343
+ tasks = [];
344
+ _loop_1 = function (item) {
345
+ var currentIndex, task;
346
+ return __generator(this, function (_f) {
347
+ switch (_f.label) {
348
+ case 0:
349
+ currentIndex = index++;
350
+ task = callbackfunction(item, currentIndex, array);
351
+ tasks.push(task);
352
+ runningTasks.push(task);
353
+ /* not await */ Promise.resolve(task).then(function () {
354
+ runningTasks = runningTasks.filter(function (t) { return t !== task; });
355
+ });
356
+ if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
357
+ return [4 /*yield*/, Promise.race(runningTasks)];
358
+ case 1:
359
+ _f.sent();
360
+ _f.label = 2;
361
+ case 2: return [2 /*return*/];
362
+ }
363
+ });
364
+ };
365
+ _e.label = 1;
366
+ case 1:
367
+ _e.trys.push([1, 6, 7, 8]);
368
+ _b = __values(array), _c = _b.next();
369
+ _e.label = 2;
370
+ case 2:
371
+ if (!!_c.done) return [3 /*break*/, 5];
372
+ item = _c.value;
373
+ return [5 /*yield**/, _loop_1(item)];
374
+ case 3:
375
+ _e.sent();
376
+ _e.label = 4;
377
+ case 4:
378
+ _c = _b.next();
379
+ return [3 /*break*/, 2];
380
+ case 5: return [3 /*break*/, 8];
381
+ case 6:
382
+ e_1_1 = _e.sent();
383
+ e_1 = { error: e_1_1 };
384
+ return [3 /*break*/, 8];
385
+ case 7:
386
+ try {
387
+ if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
388
+ }
389
+ finally { if (e_1) throw e_1.error; }
390
+ return [7 /*endfinally*/];
391
+ case 8: return [4 /*yield*/, Promise.all(tasks)];
392
+ case 9:
393
+ _e.sent();
394
+ return [2 /*return*/];
395
+ }
396
+ });
397
+ });
398
+ }
399
+
400
+ 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"}];
232
401
 
233
402
  /**
234
403
  * Prettify the html code
@@ -1297,6 +1466,14 @@
1297
1466
  * Function normalizes title to name which can be used as identifier
1298
1467
  */
1299
1468
  function titleToName(value) {
1469
+ if (value.startsWith('http://') || value.startsWith('https://')) {
1470
+ // TODO: Maybe check against some list unallowed characters
1471
+ return value;
1472
+ }
1473
+ if (value.startsWith('./') || value.startsWith('../')) {
1474
+ // TODO: Maybe check against some list unallowed characters
1475
+ return value;
1476
+ }
1300
1477
  value = removeEmojis(value);
1301
1478
  value = normalizeToKebabCase(value);
1302
1479
  // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
@@ -1631,97 +1808,6 @@
1631
1808
  return [input];
1632
1809
  }
1633
1810
 
1634
- /**
1635
- * Function `addUsage` will add multiple usages into one
1636
- *
1637
- * Note: If you provide 0 values, it returns void usage
1638
- */
1639
- function addUsage() {
1640
- var usageItems = [];
1641
- for (var _i = 0; _i < arguments.length; _i++) {
1642
- usageItems[_i] = arguments[_i];
1643
- }
1644
- var initialStructure = {
1645
- price: { value: 0 },
1646
- input: {
1647
- tokensCount: { value: 0 },
1648
- charactersCount: { value: 0 },
1649
- wordsCount: { value: 0 },
1650
- sentencesCount: { value: 0 },
1651
- linesCount: { value: 0 },
1652
- paragraphsCount: { value: 0 },
1653
- pagesCount: { value: 0 },
1654
- },
1655
- output: {
1656
- tokensCount: { value: 0 },
1657
- charactersCount: { value: 0 },
1658
- wordsCount: { value: 0 },
1659
- sentencesCount: { value: 0 },
1660
- linesCount: { value: 0 },
1661
- paragraphsCount: { value: 0 },
1662
- pagesCount: { value: 0 },
1663
- },
1664
- };
1665
- return usageItems.reduce(function (acc, item) {
1666
- var e_1, _a, e_2, _b;
1667
- var _c;
1668
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
1669
- try {
1670
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
1671
- var key = _e.value;
1672
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1673
- //@ts-ignore
1674
- if (item.input[key]) {
1675
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1676
- //@ts-ignore
1677
- acc.input[key].value += item.input[key].value || 0;
1678
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1679
- //@ts-ignore
1680
- if (item.input[key].isUncertain) {
1681
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1682
- //@ts-ignore
1683
- acc.input[key].isUncertain = true;
1684
- }
1685
- }
1686
- }
1687
- }
1688
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1689
- finally {
1690
- try {
1691
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1692
- }
1693
- finally { if (e_1) throw e_1.error; }
1694
- }
1695
- try {
1696
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
1697
- var key = _g.value;
1698
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1699
- //@ts-ignore
1700
- if (item.output[key]) {
1701
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1702
- //@ts-ignore
1703
- acc.output[key].value += item.output[key].value || 0;
1704
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1705
- //@ts-ignore
1706
- if (item.output[key].isUncertain) {
1707
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1708
- //@ts-ignore
1709
- acc.output[key].isUncertain = true;
1710
- }
1711
- }
1712
- }
1713
- }
1714
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1715
- finally {
1716
- try {
1717
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
1718
- }
1719
- finally { if (e_2) throw e_2.error; }
1720
- }
1721
- return acc;
1722
- }, initialStructure);
1723
- }
1724
-
1725
1811
  /**
1726
1812
  * Counts number of characters in the text
1727
1813
  */
@@ -1925,8 +2011,6 @@
1925
2011
  var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
1926
2012
  // TODO: !!!!! Implement new commands
1927
2013
  validatePipeline(pipeline);
1928
- // TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
1929
- // TODO: !!!!! Do here personaToModelRequirements
1930
2014
  var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
1931
2015
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1932
2016
  function executeSingleTemplate(currentTemplate) {
@@ -2447,53 +2531,74 @@
2447
2531
  return pipelineExecutor;
2448
2532
  }
2449
2533
  /**
2534
+ * TODO: [🪂] Pass maxParallelCount here
2450
2535
  * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
2451
2536
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
2452
2537
  * Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
2453
2538
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
2454
2539
  */
2455
2540
 
2456
- function prepareKnowledgeFromMarkdown(options) {
2541
+ /**
2542
+ * Just marks a place of place where should be something implemented
2543
+ * No side effects.
2544
+ *
2545
+ * Note: It can be usefull suppressing eslint errors of unused variables
2546
+ *
2547
+ * @param value any values
2548
+ * @returns void
2549
+ */
2550
+ function TODO_USE() {
2551
+ var value = [];
2552
+ for (var _i = 0; _i < arguments.length; _i++) {
2553
+ value[_i] = arguments[_i];
2554
+ }
2555
+ }
2556
+ // TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
2557
+
2558
+ /**
2559
+ * @@@
2560
+ */
2561
+ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
2457
2562
  return __awaiter(this, void 0, void 0, function () {
2458
- var content, llmTools, _a, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _b, prepareTitleExecutor, _c, prepareKeywordsExecutor, _d, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2459
- var _e, _f, _g;
2563
+ var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2564
+ var _f, _g, _h;
2460
2565
  var _this = this;
2461
- return __generator(this, function (_h) {
2462
- switch (_h.label) {
2566
+ return __generator(this, function (_j) {
2567
+ switch (_j.label) {
2463
2568
  case 0:
2464
- content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2569
+ llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
2570
+ TODO_USE(maxParallelCount); // <- [🪂]
2465
2571
  collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
2466
- _b = createPipelineExecutor;
2467
- _e = {};
2468
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
2469
- case 1:
2470
- prepareKnowledgeFromMarkdownExecutor = _b.apply(void 0, [(_e.pipeline = _h.sent(),
2471
- _e.tools = {
2472
- llm: llmTools,
2473
- },
2474
- _e)]);
2475
2572
  _c = createPipelineExecutor;
2476
2573
  _f = {};
2477
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
2478
- case 2:
2479
- prepareTitleExecutor = _c.apply(void 0, [(_f.pipeline = _h.sent(),
2574
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
2575
+ case 1:
2576
+ prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
2480
2577
  _f.tools = {
2481
2578
  llm: llmTools,
2482
2579
  },
2483
2580
  _f)]);
2484
2581
  _d = createPipelineExecutor;
2485
2582
  _g = {};
2486
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
2487
- case 3:
2488
- prepareKeywordsExecutor = _d.apply(void 0, [(_g.pipeline = _h.sent(),
2583
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
2584
+ case 2:
2585
+ prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
2489
2586
  _g.tools = {
2490
2587
  llm: llmTools,
2491
2588
  },
2492
2589
  _g)]);
2590
+ _e = createPipelineExecutor;
2591
+ _h = {};
2592
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
2593
+ case 3:
2594
+ prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
2595
+ _h.tools = {
2596
+ llm: llmTools,
2597
+ },
2598
+ _h)]);
2493
2599
  return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
2494
2600
  case 4:
2495
- result = _h.sent();
2496
- // TODO: [0] !!! Aggeregate usage
2601
+ result = _j.sent();
2497
2602
  assertsExecutionSuccessful(result);
2498
2603
  outputParameters = result.outputParameters;
2499
2604
  knowledgeRaw = outputParameters.knowledge;
@@ -2502,9 +2607,9 @@
2502
2607
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
2503
2608
  }
2504
2609
  return [4 /*yield*/, Promise.all(
2505
- // TODO: !!! Do not send all at once but in chunks
2610
+ // TODO: [🪂] !! Do not send all at once but in chunks
2506
2611
  knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
2507
- var name, title, content, keywords, index, sources, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
2612
+ var name, title, content, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
2508
2613
  return __generator(this, function (_c) {
2509
2614
  switch (_c.label) {
2510
2615
  case 0:
@@ -2513,12 +2618,6 @@
2513
2618
  content = spaceTrim__default["default"](knowledgeTextPiece);
2514
2619
  keywords = [];
2515
2620
  index = [];
2516
- sources = [
2517
- {
2518
- title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
2519
- href: '#' /* <- TODO: !!! Unhardcode */,
2520
- },
2521
- ];
2522
2621
  _c.label = 1;
2523
2622
  case 1:
2524
2623
  _c.trys.push([1, 7, , 8]);
@@ -2553,7 +2652,6 @@
2553
2652
  })];
2554
2653
  case 5:
2555
2654
  embeddingResult = _c.sent();
2556
- // TODO: [0] !!! Aggeregate usage embeddingResult.usage
2557
2655
  index.push({
2558
2656
  modelName: embeddingResult.modelName,
2559
2657
  position: embeddingResult.content,
@@ -2571,20 +2669,186 @@
2571
2669
  content: content,
2572
2670
  keywords: keywords,
2573
2671
  index: index,
2574
- sources: sources,
2672
+ // <- TODO: [☀] sources,
2575
2673
  }];
2576
2674
  }
2577
2675
  });
2578
2676
  }); }))];
2579
2677
  case 5:
2580
- knowledge = _h.sent();
2678
+ knowledge = _j.sent();
2581
2679
  return [2 /*return*/, knowledge];
2582
2680
  }
2583
2681
  });
2584
2682
  });
2585
2683
  }
2586
2684
  /**
2587
- * 11:11
2685
+ * TODO: [🪂] Do it in parallel 11:11
2686
+ * Note: No need to aggregate usage here, it is done by intercepting the llmTools
2687
+ */
2688
+
2689
+ /**
2690
+ * Prepares the knowle
2691
+ *
2692
+ * @see https://github.com/webgptorg/promptbook/discussions/41
2693
+ * @private within the package
2694
+ */
2695
+ function prepareKnowledgePieces(knowledgeSources, options) {
2696
+ return __awaiter(this, void 0, void 0, function () {
2697
+ var _a, maxParallelCount, knowledgePrepared;
2698
+ var _this = this;
2699
+ return __generator(this, function (_b) {
2700
+ switch (_b.label) {
2701
+ case 0:
2702
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
2703
+ knowledgePrepared = [];
2704
+ return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
2705
+ var partialPieces, pieces;
2706
+ return __generator(this, function (_a) {
2707
+ switch (_a.label) {
2708
+ case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
2709
+ options)];
2710
+ case 1:
2711
+ partialPieces = _a.sent();
2712
+ pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
2713
+ {
2714
+ name: knowledgeSource.name,
2715
+ // line, column <- TODO: [☀]
2716
+ // <- TODO: [❎]
2717
+ },
2718
+ ] })); });
2719
+ knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
2720
+ return [2 /*return*/];
2721
+ }
2722
+ });
2723
+ }); })];
2724
+ case 1:
2725
+ _b.sent();
2726
+ return [2 /*return*/, knowledgePrepared];
2727
+ }
2728
+ });
2729
+ });
2730
+ }
2731
+ /*
2732
+ TODO: [🧊] This is how it can look in future
2733
+ > type PrepareKnowledgeKnowledge = {
2734
+ > /**
2735
+ > * Unprepared knowledge
2736
+ > * /
2737
+ > readonly knowledgeSources: Array<KnowledgeSourceJson>;
2738
+ > };
2739
+ >
2740
+ > export async function prepareKnowledgePieces(
2741
+ > knowledge: PrepareKnowledgeKnowledge,
2742
+ > options: PrepareOptions,
2743
+ > ):
2744
+ */
2745
+ /**
2746
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
2747
+ * Put `knowledgePieces` into `PrepareKnowledgeOptions`
2748
+ * TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
2749
+ * TODO: [🧠][❎] Do here propper M:N mapping
2750
+ * [x] One source can make multiple pieces
2751
+ * [ ] One piece can have multiple sources
2752
+ */
2753
+
2754
+ /**
2755
+ * Prepares the persona for the pipeline
2756
+ *
2757
+ * @see https://github.com/webgptorg/promptbook/discussions/22
2758
+ * @private within the package
2759
+ */
2760
+ function preparePersona(personaDescription, options) {
2761
+ return __awaiter(this, void 0, void 0, function () {
2762
+ var llmTools, _a, maxParallelCount, _b, isVerbose;
2763
+ return __generator(this, function (_c) {
2764
+ llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
2765
+ TODO_USE(maxParallelCount); // <- [🪂]
2766
+ TODO_USE(personaDescription); // <- !!!!!
2767
+ TODO_USE(llmTools); // <- !!!!!
2768
+ TODO_USE(isVerbose); // <- !!!!!
2769
+ return [2 /*return*/, {
2770
+ modelVariant: 'CHAT',
2771
+ modelName: 'gpt-4',
2772
+ }];
2773
+ });
2774
+ });
2775
+ }
2776
+ /**
2777
+ * TODO: [🪂] Do it in parallel
2778
+ */
2779
+
2780
+ /**
2781
+ * Simple wrapper `new Date().toISOString()`
2782
+ *
2783
+ * @returns string_date branded type
2784
+ */
2785
+ function $currentDate() {
2786
+ return new Date().toISOString();
2787
+ }
2788
+
2789
+ /**
2790
+ * Prepare pipeline from string (markdown) format to JSON format
2791
+ *
2792
+ * Note: This function does not validate logic of the pipeline
2793
+ * Note: This function acts as part of compilation process
2794
+ */
2795
+ function preparePipeline(pipeline, options) {
2796
+ return __awaiter(this, void 0, void 0, function () {
2797
+ var _a, maxParallelCount,
2798
+ /*
2799
+ <- TODO: [🧠][0] `promptbookVersion` */
2800
+ knowledgeSources /*
2801
+ <- TODO: [🧊] `knowledgePieces` */, personas /*
2802
+ <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
2803
+ var _this = this;
2804
+ return __generator(this, function (_b) {
2805
+ switch (_b.label) {
2806
+ case 0:
2807
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
2808
+ knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
2809
+ currentPreparation = {
2810
+ id: 1,
2811
+ date: $currentDate(),
2812
+ promptbookVersion: PROMPTBOOK_VERSION,
2813
+ modelUsage: addUsage(),
2814
+ };
2815
+ preparations = [
2816
+ // ...preparations
2817
+ // <- TODO: [🧊]
2818
+ currentPreparation,
2819
+ ];
2820
+ preparedPersonas = [];
2821
+ 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 () {
2822
+ var modelRequirements, preparedPersona;
2823
+ return __generator(this, function (_a) {
2824
+ switch (_a.label) {
2825
+ case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
2826
+ case 1:
2827
+ modelRequirements = _a.sent();
2828
+ preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
2829
+ preparedPersonas.push(preparedPersona);
2830
+ return [2 /*return*/];
2831
+ }
2832
+ });
2833
+ }); })];
2834
+ case 1:
2835
+ _b.sent();
2836
+ knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
2837
+ return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
2838
+ case 2:
2839
+ partialknowledgePiecesPrepared = _b.sent();
2840
+ knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
2841
+ // ----- /Knowledge preparation -----
2842
+ return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
2843
+ }
2844
+ });
2845
+ });
2846
+ }
2847
+ /**
2848
+ * TODO: Write tests for `preparePipeline`
2849
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
2850
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
2851
+ * TODO: [💸] Make utilities `interceptLlmTools` and `costLlmTools` to compute cost and DO put this counting logic in `prepareKnowledge` or `preparePersona`
2588
2852
  */
2589
2853
 
2590
2854
  /**
@@ -2771,6 +3035,7 @@
2771
3035
 
2772
3036
  /**
2773
3037
  * Units of text measurement
3038
+ * @see https://github.com/webgptorg/promptbook/discussions/30
2774
3039
  */
2775
3040
  var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
2776
3041
  /**
@@ -3091,9 +3356,10 @@
3091
3356
 
3092
3357
  var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
3093
3358
  /**
3359
+ * TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
3094
3360
  * TODO: Maybe figure out better word than "variant"
3095
3361
  * TODO: Add here more requirement options like max context size, max tokens, etc.
3096
- * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
3362
+ * TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
3097
3363
  */
3098
3364
 
3099
3365
  /**
@@ -4236,14 +4502,14 @@
4236
4502
  */
4237
4503
 
4238
4504
  /**
4239
- * Compile promptbook from string (markdown) format to JSON format synchronously
4505
+ * Compile pipeline from string (markdown) format to JSON format synchronously
4240
4506
  *
4241
- * Note: There are two similar functions:
4507
+ * Note: There are 3 similar functions:
4242
4508
  * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
4243
4509
  * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
4510
+ * - `preparePipeline` - just one step in the compilation process
4244
4511
  *
4245
4512
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
4246
- * @param options - Options and tools for the compilation
4247
4513
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
4248
4514
  * @throws {ParsingError} if the promptbook string is not valid
4249
4515
  *
@@ -4259,7 +4525,10 @@
4259
4525
  description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
4260
4526
  parameters: [],
4261
4527
  promptTemplates: [],
4262
- knowledge: [],
4528
+ knowledgeSources: [],
4529
+ knowledgePieces: [],
4530
+ personas: [],
4531
+ preparations: [],
4263
4532
  };
4264
4533
  // =============================================================
4265
4534
  // Note: 1️⃣ Parsing of the markdown into object
@@ -4527,6 +4796,7 @@
4527
4796
  postprocessing: postprocessing,
4528
4797
  expectations: expectAmount,
4529
4798
  expectFormat: expectFormat,
4799
+ personaName: null,
4530
4800
  modelRequirements: templateModelRequirements,
4531
4801
  contentLanguage: blockType === 'SCRIPT' ? language : undefined,
4532
4802
  content: content,
@@ -4606,11 +4876,12 @@
4606
4876
  */
4607
4877
 
4608
4878
  /**
4609
- * Compile promptbook from string (markdown) format to JSON format
4879
+ * Compile pipeline from string (markdown) format to JSON format
4610
4880
  *
4611
- * Note: There are two similar functions:
4881
+ * Note: There are 3 similar functions:
4612
4882
  * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
4613
4883
  * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
4884
+ * - `preparePipeline` - just one step in the compilation process
4614
4885
  *
4615
4886
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
4616
4887
  * @param options - Options and tools for the compilation
@@ -4621,22 +4892,18 @@
4621
4892
  * Note: This function acts as compilation process
4622
4893
  */
4623
4894
  function pipelineStringToJson(pipelineString, options) {
4624
- if (options === void 0) { options = {}; }
4895
+ if (options === void 0) { options = { llmTools: null }; }
4625
4896
  return __awaiter(this, void 0, void 0, function () {
4626
- var llmTools, pipelineJson, knowledge;
4897
+ var llmTools, pipelineJson;
4627
4898
  return __generator(this, function (_a) {
4628
4899
  switch (_a.label) {
4629
4900
  case 0:
4630
4901
  llmTools = options.llmTools;
4631
4902
  pipelineJson = pipelineStringToJsonSync(pipelineString);
4632
- if (!llmTools) return [3 /*break*/, 2];
4633
- return [4 /*yield*/, prepareKnowledgeFromMarkdown({
4634
- content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
4635
- llmTools: llmTools,
4636
- })];
4903
+ if (!(llmTools !== null)) return [3 /*break*/, 2];
4904
+ return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
4637
4905
  case 1:
4638
- knowledge = _a.sent();
4639
- pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
4906
+ pipelineJson = _a.sent();
4640
4907
  _a.label = 2;
4641
4908
  case 2: return [2 /*return*/, pipelineJson];
4642
4909
  }
@@ -4758,7 +5025,7 @@
4758
5025
  */
4759
5026
  function createCollectionFromDirectory(path$1, options) {
4760
5027
  return __awaiter(this, void 0, void 0, function () {
4761
- var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, collection;
5028
+ var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, collection;
4762
5029
  var _this = this;
4763
5030
  return __generator(this, function (_f) {
4764
5031
  switch (_f.label) {
@@ -4779,7 +5046,7 @@
4779
5046
  colors__default["default"].green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
4780
5047
  // TODO: !! Implement;
4781
5048
  }
4782
- _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashOnError, isCrashOnError = _e === void 0 ? true : _e;
5049
+ _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
4783
5050
  collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
4784
5051
  var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
4785
5052
  var e_1, _a;
@@ -4841,7 +5108,7 @@
4841
5108
  if (isVerbose) {
4842
5109
  console.info("Loading ".concat(fileName.split('\\').join('/')));
4843
5110
  }
4844
- if (!isCrashOnError) {
5111
+ if (!isCrashedOnError) {
4845
5112
  // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
4846
5113
  // But be handled in current try-catch block
4847
5114
  validatePipeline(promptbook);
@@ -4857,7 +5124,7 @@
4857
5124
  throw error_1;
4858
5125
  }
4859
5126
  wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n Error during loading pipeline from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
4860
- if (isCrashOnError) {
5127
+ if (isCrashedOnError) {
4861
5128
  throw new CollectionError(wrappedErrorMessage);
4862
5129
  }
4863
5130
  // TODO: [🟥] Detect browser / node and make it colorfull