@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/esm/index.es.js CHANGED
@@ -146,7 +146,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
146
146
  /**
147
147
  * The version of the Promptbook library
148
148
  */
149
- var PROMPTBOOK_VERSION = '0.61.0-0';
149
+ var PROMPTBOOK_VERSION = '0.61.0-9';
150
150
  // TODO: !!!! List here all the versions and annotate + put into script
151
151
 
152
152
  /**
@@ -212,6 +212,10 @@ var LOOP_LIMIT = 1000;
212
212
  * The maximum number of iterations for a loops which adds characters one by one
213
213
  */
214
214
  var CHARACTER_LOOP_LIMIT = 100000;
215
+ /**
216
+ * The maximum number of (LLM) tasks running in parallel
217
+ */
218
+ var MAX_PARALLEL_COUNT = 5;
215
219
  /**
216
220
  * The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
217
221
  */
@@ -225,7 +229,172 @@ var RESERVED_PARAMETER_NAMES = [
225
229
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
226
230
  ];
227
231
 
228
- 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"}];
232
+ /**
233
+ * Function `addUsage` will add multiple usages into one
234
+ *
235
+ * Note: If you provide 0 values, it returns void usage
236
+ */
237
+ function addUsage() {
238
+ var usageItems = [];
239
+ for (var _i = 0; _i < arguments.length; _i++) {
240
+ usageItems[_i] = arguments[_i];
241
+ }
242
+ var initialStructure = {
243
+ price: { value: 0 },
244
+ input: {
245
+ tokensCount: { value: 0 },
246
+ charactersCount: { value: 0 },
247
+ wordsCount: { value: 0 },
248
+ sentencesCount: { value: 0 },
249
+ linesCount: { value: 0 },
250
+ paragraphsCount: { value: 0 },
251
+ pagesCount: { value: 0 },
252
+ },
253
+ output: {
254
+ tokensCount: { value: 0 },
255
+ charactersCount: { value: 0 },
256
+ wordsCount: { value: 0 },
257
+ sentencesCount: { value: 0 },
258
+ linesCount: { value: 0 },
259
+ paragraphsCount: { value: 0 },
260
+ pagesCount: { value: 0 },
261
+ },
262
+ };
263
+ return usageItems.reduce(function (acc, item) {
264
+ var e_1, _a, e_2, _b;
265
+ var _c;
266
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
267
+ try {
268
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
269
+ var key = _e.value;
270
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
271
+ //@ts-ignore
272
+ if (item.input[key]) {
273
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
274
+ //@ts-ignore
275
+ acc.input[key].value += item.input[key].value || 0;
276
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
277
+ //@ts-ignore
278
+ if (item.input[key].isUncertain) {
279
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
280
+ //@ts-ignore
281
+ acc.input[key].isUncertain = true;
282
+ }
283
+ }
284
+ }
285
+ }
286
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
287
+ finally {
288
+ try {
289
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
290
+ }
291
+ finally { if (e_1) throw e_1.error; }
292
+ }
293
+ try {
294
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
295
+ var key = _g.value;
296
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
297
+ //@ts-ignore
298
+ if (item.output[key]) {
299
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
300
+ //@ts-ignore
301
+ acc.output[key].value += item.output[key].value || 0;
302
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
303
+ //@ts-ignore
304
+ if (item.output[key].isUncertain) {
305
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
306
+ //@ts-ignore
307
+ acc.output[key].isUncertain = true;
308
+ }
309
+ }
310
+ }
311
+ }
312
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
313
+ finally {
314
+ try {
315
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
316
+ }
317
+ finally { if (e_2) throw e_2.error; }
318
+ }
319
+ return acc;
320
+ }, initialStructure);
321
+ }
322
+
323
+ /**
324
+ * Async version of Array.forEach
325
+ *
326
+ * @param array - Array to iterate over
327
+ * @param options - Options for the function
328
+ * @param callbackfunction - Function to call for each item
329
+ */
330
+ function forEachAsync(array, options, callbackfunction) {
331
+ return __awaiter(this, void 0, void 0, function () {
332
+ var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
333
+ var e_1, _d;
334
+ return __generator(this, function (_e) {
335
+ switch (_e.label) {
336
+ case 0:
337
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
338
+ index = 0;
339
+ runningTasks = [];
340
+ tasks = [];
341
+ _loop_1 = function (item) {
342
+ var currentIndex, task;
343
+ return __generator(this, function (_f) {
344
+ switch (_f.label) {
345
+ case 0:
346
+ currentIndex = index++;
347
+ task = callbackfunction(item, currentIndex, array);
348
+ tasks.push(task);
349
+ runningTasks.push(task);
350
+ /* not await */ Promise.resolve(task).then(function () {
351
+ runningTasks = runningTasks.filter(function (t) { return t !== task; });
352
+ });
353
+ if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
354
+ return [4 /*yield*/, Promise.race(runningTasks)];
355
+ case 1:
356
+ _f.sent();
357
+ _f.label = 2;
358
+ case 2: return [2 /*return*/];
359
+ }
360
+ });
361
+ };
362
+ _e.label = 1;
363
+ case 1:
364
+ _e.trys.push([1, 6, 7, 8]);
365
+ _b = __values(array), _c = _b.next();
366
+ _e.label = 2;
367
+ case 2:
368
+ if (!!_c.done) return [3 /*break*/, 5];
369
+ item = _c.value;
370
+ return [5 /*yield**/, _loop_1(item)];
371
+ case 3:
372
+ _e.sent();
373
+ _e.label = 4;
374
+ case 4:
375
+ _c = _b.next();
376
+ return [3 /*break*/, 2];
377
+ case 5: return [3 /*break*/, 8];
378
+ case 6:
379
+ e_1_1 = _e.sent();
380
+ e_1 = { error: e_1_1 };
381
+ return [3 /*break*/, 8];
382
+ case 7:
383
+ try {
384
+ if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
385
+ }
386
+ finally { if (e_1) throw e_1.error; }
387
+ return [7 /*endfinally*/];
388
+ case 8: return [4 /*yield*/, Promise.all(tasks)];
389
+ case 9:
390
+ _e.sent();
391
+ return [2 /*return*/];
392
+ }
393
+ });
394
+ });
395
+ }
396
+
397
+ 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"}];
229
398
 
230
399
  /**
231
400
  * Prettify the html code
@@ -1294,6 +1463,14 @@ function removeEmojis(text) {
1294
1463
  * Function normalizes title to name which can be used as identifier
1295
1464
  */
1296
1465
  function titleToName(value) {
1466
+ if (value.startsWith('http://') || value.startsWith('https://')) {
1467
+ // TODO: Maybe check against some list unallowed characters
1468
+ return value;
1469
+ }
1470
+ if (value.startsWith('./') || value.startsWith('../')) {
1471
+ // TODO: Maybe check against some list unallowed characters
1472
+ return value;
1473
+ }
1297
1474
  value = removeEmojis(value);
1298
1475
  value = normalizeToKebabCase(value);
1299
1476
  // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
@@ -1628,97 +1805,6 @@ function arrayableToArray(input) {
1628
1805
  return [input];
1629
1806
  }
1630
1807
 
1631
- /**
1632
- * Function `addUsage` will add multiple usages into one
1633
- *
1634
- * Note: If you provide 0 values, it returns void usage
1635
- */
1636
- function addUsage() {
1637
- var usageItems = [];
1638
- for (var _i = 0; _i < arguments.length; _i++) {
1639
- usageItems[_i] = arguments[_i];
1640
- }
1641
- var initialStructure = {
1642
- price: { value: 0 },
1643
- input: {
1644
- tokensCount: { value: 0 },
1645
- charactersCount: { value: 0 },
1646
- wordsCount: { value: 0 },
1647
- sentencesCount: { value: 0 },
1648
- linesCount: { value: 0 },
1649
- paragraphsCount: { value: 0 },
1650
- pagesCount: { value: 0 },
1651
- },
1652
- output: {
1653
- tokensCount: { value: 0 },
1654
- charactersCount: { value: 0 },
1655
- wordsCount: { value: 0 },
1656
- sentencesCount: { value: 0 },
1657
- linesCount: { value: 0 },
1658
- paragraphsCount: { value: 0 },
1659
- pagesCount: { value: 0 },
1660
- },
1661
- };
1662
- return usageItems.reduce(function (acc, item) {
1663
- var e_1, _a, e_2, _b;
1664
- var _c;
1665
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
1666
- try {
1667
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
1668
- var key = _e.value;
1669
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1670
- //@ts-ignore
1671
- if (item.input[key]) {
1672
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1673
- //@ts-ignore
1674
- acc.input[key].value += item.input[key].value || 0;
1675
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1676
- //@ts-ignore
1677
- if (item.input[key].isUncertain) {
1678
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1679
- //@ts-ignore
1680
- acc.input[key].isUncertain = true;
1681
- }
1682
- }
1683
- }
1684
- }
1685
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1686
- finally {
1687
- try {
1688
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1689
- }
1690
- finally { if (e_1) throw e_1.error; }
1691
- }
1692
- try {
1693
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
1694
- var key = _g.value;
1695
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1696
- //@ts-ignore
1697
- if (item.output[key]) {
1698
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1699
- //@ts-ignore
1700
- acc.output[key].value += item.output[key].value || 0;
1701
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1702
- //@ts-ignore
1703
- if (item.output[key].isUncertain) {
1704
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1705
- //@ts-ignore
1706
- acc.output[key].isUncertain = true;
1707
- }
1708
- }
1709
- }
1710
- }
1711
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1712
- finally {
1713
- try {
1714
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
1715
- }
1716
- finally { if (e_2) throw e_2.error; }
1717
- }
1718
- return acc;
1719
- }, initialStructure);
1720
- }
1721
-
1722
1808
  /**
1723
1809
  * Counts number of characters in the text
1724
1810
  */
@@ -1922,8 +2008,6 @@ function createPipelineExecutor(options) {
1922
2008
  var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
1923
2009
  // TODO: !!!!! Implement new commands
1924
2010
  validatePipeline(pipeline);
1925
- // TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
1926
- // TODO: !!!!! Do here personaToModelRequirements
1927
2011
  var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
1928
2012
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1929
2013
  function executeSingleTemplate(currentTemplate) {
@@ -2444,53 +2528,74 @@ function createPipelineExecutor(options) {
2444
2528
  return pipelineExecutor;
2445
2529
  }
2446
2530
  /**
2531
+ * TODO: [🪂] Pass maxParallelCount here
2447
2532
  * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
2448
2533
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
2449
2534
  * Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
2450
2535
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
2451
2536
  */
2452
2537
 
2453
- function prepareKnowledgeFromMarkdown(options) {
2538
+ /**
2539
+ * Just marks a place of place where should be something implemented
2540
+ * No side effects.
2541
+ *
2542
+ * Note: It can be usefull suppressing eslint errors of unused variables
2543
+ *
2544
+ * @param value any values
2545
+ * @returns void
2546
+ */
2547
+ function TODO_USE() {
2548
+ var value = [];
2549
+ for (var _i = 0; _i < arguments.length; _i++) {
2550
+ value[_i] = arguments[_i];
2551
+ }
2552
+ }
2553
+ // TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
2554
+
2555
+ /**
2556
+ * @@@
2557
+ */
2558
+ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
2454
2559
  return __awaiter(this, void 0, void 0, function () {
2455
- var content, llmTools, _a, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _b, prepareTitleExecutor, _c, prepareKeywordsExecutor, _d, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2456
- var _e, _f, _g;
2560
+ var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2561
+ var _f, _g, _h;
2457
2562
  var _this = this;
2458
- return __generator(this, function (_h) {
2459
- switch (_h.label) {
2563
+ return __generator(this, function (_j) {
2564
+ switch (_j.label) {
2460
2565
  case 0:
2461
- content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2566
+ llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
2567
+ TODO_USE(maxParallelCount); // <- [🪂]
2462
2568
  collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
2463
- _b = createPipelineExecutor;
2464
- _e = {};
2465
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
2466
- case 1:
2467
- prepareKnowledgeFromMarkdownExecutor = _b.apply(void 0, [(_e.pipeline = _h.sent(),
2468
- _e.tools = {
2469
- llm: llmTools,
2470
- },
2471
- _e)]);
2472
2569
  _c = createPipelineExecutor;
2473
2570
  _f = {};
2474
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
2475
- case 2:
2476
- prepareTitleExecutor = _c.apply(void 0, [(_f.pipeline = _h.sent(),
2571
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
2572
+ case 1:
2573
+ prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
2477
2574
  _f.tools = {
2478
2575
  llm: llmTools,
2479
2576
  },
2480
2577
  _f)]);
2481
2578
  _d = createPipelineExecutor;
2482
2579
  _g = {};
2483
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
2484
- case 3:
2485
- prepareKeywordsExecutor = _d.apply(void 0, [(_g.pipeline = _h.sent(),
2580
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
2581
+ case 2:
2582
+ prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
2486
2583
  _g.tools = {
2487
2584
  llm: llmTools,
2488
2585
  },
2489
2586
  _g)]);
2587
+ _e = createPipelineExecutor;
2588
+ _h = {};
2589
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
2590
+ case 3:
2591
+ prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
2592
+ _h.tools = {
2593
+ llm: llmTools,
2594
+ },
2595
+ _h)]);
2490
2596
  return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
2491
2597
  case 4:
2492
- result = _h.sent();
2493
- // TODO: [0] !!! Aggeregate usage
2598
+ result = _j.sent();
2494
2599
  assertsExecutionSuccessful(result);
2495
2600
  outputParameters = result.outputParameters;
2496
2601
  knowledgeRaw = outputParameters.knowledge;
@@ -2499,9 +2604,9 @@ function prepareKnowledgeFromMarkdown(options) {
2499
2604
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
2500
2605
  }
2501
2606
  return [4 /*yield*/, Promise.all(
2502
- // TODO: !!! Do not send all at once but in chunks
2607
+ // TODO: [🪂] !! Do not send all at once but in chunks
2503
2608
  knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
2504
- var name, title, content, keywords, index, sources, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
2609
+ var name, title, content, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
2505
2610
  return __generator(this, function (_c) {
2506
2611
  switch (_c.label) {
2507
2612
  case 0:
@@ -2510,12 +2615,6 @@ function prepareKnowledgeFromMarkdown(options) {
2510
2615
  content = spaceTrim(knowledgeTextPiece);
2511
2616
  keywords = [];
2512
2617
  index = [];
2513
- sources = [
2514
- {
2515
- title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
2516
- href: '#' /* <- TODO: !!! Unhardcode */,
2517
- },
2518
- ];
2519
2618
  _c.label = 1;
2520
2619
  case 1:
2521
2620
  _c.trys.push([1, 7, , 8]);
@@ -2550,7 +2649,6 @@ function prepareKnowledgeFromMarkdown(options) {
2550
2649
  })];
2551
2650
  case 5:
2552
2651
  embeddingResult = _c.sent();
2553
- // TODO: [0] !!! Aggeregate usage embeddingResult.usage
2554
2652
  index.push({
2555
2653
  modelName: embeddingResult.modelName,
2556
2654
  position: embeddingResult.content,
@@ -2568,20 +2666,186 @@ function prepareKnowledgeFromMarkdown(options) {
2568
2666
  content: content,
2569
2667
  keywords: keywords,
2570
2668
  index: index,
2571
- sources: sources,
2669
+ // <- TODO: [☀] sources,
2572
2670
  }];
2573
2671
  }
2574
2672
  });
2575
2673
  }); }))];
2576
2674
  case 5:
2577
- knowledge = _h.sent();
2675
+ knowledge = _j.sent();
2578
2676
  return [2 /*return*/, knowledge];
2579
2677
  }
2580
2678
  });
2581
2679
  });
2582
2680
  }
2583
2681
  /**
2584
- * 11:11
2682
+ * TODO: [🪂] Do it in parallel 11:11
2683
+ * Note: No need to aggregate usage here, it is done by intercepting the llmTools
2684
+ */
2685
+
2686
+ /**
2687
+ * Prepares the knowle
2688
+ *
2689
+ * @see https://github.com/webgptorg/promptbook/discussions/41
2690
+ * @private within the package
2691
+ */
2692
+ function prepareKnowledgePieces(knowledgeSources, options) {
2693
+ return __awaiter(this, void 0, void 0, function () {
2694
+ var _a, maxParallelCount, knowledgePrepared;
2695
+ var _this = this;
2696
+ return __generator(this, function (_b) {
2697
+ switch (_b.label) {
2698
+ case 0:
2699
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
2700
+ knowledgePrepared = [];
2701
+ return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
2702
+ var partialPieces, pieces;
2703
+ return __generator(this, function (_a) {
2704
+ switch (_a.label) {
2705
+ case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
2706
+ options)];
2707
+ case 1:
2708
+ partialPieces = _a.sent();
2709
+ pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
2710
+ {
2711
+ name: knowledgeSource.name,
2712
+ // line, column <- TODO: [☀]
2713
+ // <- TODO: [❎]
2714
+ },
2715
+ ] })); });
2716
+ knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
2717
+ return [2 /*return*/];
2718
+ }
2719
+ });
2720
+ }); })];
2721
+ case 1:
2722
+ _b.sent();
2723
+ return [2 /*return*/, knowledgePrepared];
2724
+ }
2725
+ });
2726
+ });
2727
+ }
2728
+ /*
2729
+ TODO: [🧊] This is how it can look in future
2730
+ > type PrepareKnowledgeKnowledge = {
2731
+ > /**
2732
+ > * Unprepared knowledge
2733
+ > * /
2734
+ > readonly knowledgeSources: Array<KnowledgeSourceJson>;
2735
+ > };
2736
+ >
2737
+ > export async function prepareKnowledgePieces(
2738
+ > knowledge: PrepareKnowledgeKnowledge,
2739
+ > options: PrepareOptions,
2740
+ > ):
2741
+ */
2742
+ /**
2743
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
2744
+ * Put `knowledgePieces` into `PrepareKnowledgeOptions`
2745
+ * TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
2746
+ * TODO: [🧠][❎] Do here propper M:N mapping
2747
+ * [x] One source can make multiple pieces
2748
+ * [ ] One piece can have multiple sources
2749
+ */
2750
+
2751
+ /**
2752
+ * Prepares the persona for the pipeline
2753
+ *
2754
+ * @see https://github.com/webgptorg/promptbook/discussions/22
2755
+ * @private within the package
2756
+ */
2757
+ function preparePersona(personaDescription, options) {
2758
+ return __awaiter(this, void 0, void 0, function () {
2759
+ var llmTools, _a, maxParallelCount, _b, isVerbose;
2760
+ return __generator(this, function (_c) {
2761
+ llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
2762
+ TODO_USE(maxParallelCount); // <- [🪂]
2763
+ TODO_USE(personaDescription); // <- !!!!!
2764
+ TODO_USE(llmTools); // <- !!!!!
2765
+ TODO_USE(isVerbose); // <- !!!!!
2766
+ return [2 /*return*/, {
2767
+ modelVariant: 'CHAT',
2768
+ modelName: 'gpt-4',
2769
+ }];
2770
+ });
2771
+ });
2772
+ }
2773
+ /**
2774
+ * TODO: [🪂] Do it in parallel
2775
+ */
2776
+
2777
+ /**
2778
+ * Simple wrapper `new Date().toISOString()`
2779
+ *
2780
+ * @returns string_date branded type
2781
+ */
2782
+ function $currentDate() {
2783
+ return new Date().toISOString();
2784
+ }
2785
+
2786
+ /**
2787
+ * Prepare pipeline from string (markdown) format to JSON format
2788
+ *
2789
+ * Note: This function does not validate logic of the pipeline
2790
+ * Note: This function acts as part of compilation process
2791
+ */
2792
+ function preparePipeline(pipeline, options) {
2793
+ return __awaiter(this, void 0, void 0, function () {
2794
+ var _a, maxParallelCount,
2795
+ /*
2796
+ <- TODO: [🧠][0] `promptbookVersion` */
2797
+ knowledgeSources /*
2798
+ <- TODO: [🧊] `knowledgePieces` */, personas /*
2799
+ <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
2800
+ var _this = this;
2801
+ return __generator(this, function (_b) {
2802
+ switch (_b.label) {
2803
+ case 0:
2804
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
2805
+ knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
2806
+ currentPreparation = {
2807
+ id: 1,
2808
+ date: $currentDate(),
2809
+ promptbookVersion: PROMPTBOOK_VERSION,
2810
+ modelUsage: addUsage(),
2811
+ };
2812
+ preparations = [
2813
+ // ...preparations
2814
+ // <- TODO: [🧊]
2815
+ currentPreparation,
2816
+ ];
2817
+ preparedPersonas = [];
2818
+ 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 () {
2819
+ var modelRequirements, preparedPersona;
2820
+ return __generator(this, function (_a) {
2821
+ switch (_a.label) {
2822
+ case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
2823
+ case 1:
2824
+ modelRequirements = _a.sent();
2825
+ preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
2826
+ preparedPersonas.push(preparedPersona);
2827
+ return [2 /*return*/];
2828
+ }
2829
+ });
2830
+ }); })];
2831
+ case 1:
2832
+ _b.sent();
2833
+ knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
2834
+ return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
2835
+ case 2:
2836
+ partialknowledgePiecesPrepared = _b.sent();
2837
+ knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
2838
+ // ----- /Knowledge preparation -----
2839
+ return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
2840
+ }
2841
+ });
2842
+ });
2843
+ }
2844
+ /**
2845
+ * TODO: Write tests for `preparePipeline`
2846
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
2847
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
2848
+ * TODO: [💸] Make utilities `interceptLlmTools` and `costLlmTools` to compute cost and DO put this counting logic in `prepareKnowledge` or `preparePersona`
2585
2849
  */
2586
2850
 
2587
2851
  /**
@@ -2768,6 +3032,7 @@ var blockCommandParser = {
2768
3032
 
2769
3033
  /**
2770
3034
  * Units of text measurement
3035
+ * @see https://github.com/webgptorg/promptbook/discussions/30
2771
3036
  */
2772
3037
  var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
2773
3038
  /**
@@ -3088,9 +3353,10 @@ var knowledgeCommandParser = {
3088
3353
 
3089
3354
  var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
3090
3355
  /**
3356
+ * TODO: !!!!! Add and use systemMessage, temprerature, top_k, top_p, presencePenalty, frequencyPenalty, bestOf, n, logitBias, logitBiasType, stop, ... to ModelRequirements
3091
3357
  * TODO: Maybe figure out better word than "variant"
3092
3358
  * TODO: Add here more requirement options like max context size, max tokens, etc.
3093
- * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
3359
+ * TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
3094
3360
  */
3095
3361
 
3096
3362
  /**
@@ -4233,14 +4499,14 @@ function extractParametersFromPromptTemplate(promptTemplate) {
4233
4499
  */
4234
4500
 
4235
4501
  /**
4236
- * Compile promptbook from string (markdown) format to JSON format synchronously
4502
+ * Compile pipeline from string (markdown) format to JSON format synchronously
4237
4503
  *
4238
- * Note: There are two similar functions:
4504
+ * Note: There are 3 similar functions:
4239
4505
  * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
4240
4506
  * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
4507
+ * - `preparePipeline` - just one step in the compilation process
4241
4508
  *
4242
4509
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
4243
- * @param options - Options and tools for the compilation
4244
4510
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
4245
4511
  * @throws {ParsingError} if the promptbook string is not valid
4246
4512
  *
@@ -4256,7 +4522,10 @@ function pipelineStringToJsonSync(pipelineString) {
4256
4522
  description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
4257
4523
  parameters: [],
4258
4524
  promptTemplates: [],
4259
- knowledge: [],
4525
+ knowledgeSources: [],
4526
+ knowledgePieces: [],
4527
+ personas: [],
4528
+ preparations: [],
4260
4529
  };
4261
4530
  // =============================================================
4262
4531
  // Note: 1️⃣ Parsing of the markdown into object
@@ -4524,6 +4793,7 @@ function pipelineStringToJsonSync(pipelineString) {
4524
4793
  postprocessing: postprocessing,
4525
4794
  expectations: expectAmount,
4526
4795
  expectFormat: expectFormat,
4796
+ personaName: null,
4527
4797
  modelRequirements: templateModelRequirements,
4528
4798
  contentLanguage: blockType === 'SCRIPT' ? language : undefined,
4529
4799
  content: content,
@@ -4603,11 +4873,12 @@ function pipelineStringToJsonSync(pipelineString) {
4603
4873
  */
4604
4874
 
4605
4875
  /**
4606
- * Compile promptbook from string (markdown) format to JSON format
4876
+ * Compile pipeline from string (markdown) format to JSON format
4607
4877
  *
4608
- * Note: There are two similar functions:
4878
+ * Note: There are 3 similar functions:
4609
4879
  * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
4610
4880
  * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
4881
+ * - `preparePipeline` - just one step in the compilation process
4611
4882
  *
4612
4883
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
4613
4884
  * @param options - Options and tools for the compilation
@@ -4618,22 +4889,18 @@ function pipelineStringToJsonSync(pipelineString) {
4618
4889
  * Note: This function acts as compilation process
4619
4890
  */
4620
4891
  function pipelineStringToJson(pipelineString, options) {
4621
- if (options === void 0) { options = {}; }
4892
+ if (options === void 0) { options = { llmTools: null }; }
4622
4893
  return __awaiter(this, void 0, void 0, function () {
4623
- var llmTools, pipelineJson, knowledge;
4894
+ var llmTools, pipelineJson;
4624
4895
  return __generator(this, function (_a) {
4625
4896
  switch (_a.label) {
4626
4897
  case 0:
4627
4898
  llmTools = options.llmTools;
4628
4899
  pipelineJson = pipelineStringToJsonSync(pipelineString);
4629
- if (!llmTools) return [3 /*break*/, 2];
4630
- return [4 /*yield*/, prepareKnowledgeFromMarkdown({
4631
- content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
4632
- llmTools: llmTools,
4633
- })];
4900
+ if (!(llmTools !== null)) return [3 /*break*/, 2];
4901
+ return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
4634
4902
  case 1:
4635
- knowledge = _a.sent();
4636
- pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
4903
+ pipelineJson = _a.sent();
4637
4904
  _a.label = 2;
4638
4905
  case 2: return [2 /*return*/, pipelineJson];
4639
4906
  }
@@ -4755,7 +5022,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
4755
5022
  */
4756
5023
  function createCollectionFromDirectory(path, options) {
4757
5024
  return __awaiter(this, void 0, void 0, function () {
4758
- var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, collection;
5025
+ var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, collection;
4759
5026
  var _this = this;
4760
5027
  return __generator(this, function (_f) {
4761
5028
  switch (_f.label) {
@@ -4776,7 +5043,7 @@ function createCollectionFromDirectory(path, options) {
4776
5043
  colors.green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
4777
5044
  // TODO: !! Implement;
4778
5045
  }
4779
- _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;
5046
+ _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;
4780
5047
  collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
4781
5048
  var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
4782
5049
  var e_1, _a;
@@ -4838,7 +5105,7 @@ function createCollectionFromDirectory(path, options) {
4838
5105
  if (isVerbose) {
4839
5106
  console.info("Loading ".concat(fileName.split('\\').join('/')));
4840
5107
  }
4841
- if (!isCrashOnError) {
5108
+ if (!isCrashedOnError) {
4842
5109
  // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
4843
5110
  // But be handled in current try-catch block
4844
5111
  validatePipeline(promptbook);
@@ -4854,7 +5121,7 @@ function createCollectionFromDirectory(path, options) {
4854
5121
  throw error_1;
4855
5122
  }
4856
5123
  wrappedErrorMessage = spaceTrim(function (block) { return "\n Error during loading pipeline from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
4857
- if (isCrashOnError) {
5124
+ if (isCrashedOnError) {
4858
5125
  throw new CollectionError(wrappedErrorMessage);
4859
5126
  }
4860
5127
  // TODO: [🟥] Detect browser / node and make it colorfull