@promptbook/core 0.61.0 → 0.62.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/esm/index.es.js +139 -17
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/promptbook-collection/index.d.ts +3 -3
  4. package/esm/typings/src/_packages/core.index.d.ts +2 -1
  5. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +2 -1
  6. package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -0
  7. package/esm/typings/src/execution/utils/usageToHuman.d.ts +15 -0
  8. package/esm/typings/src/execution/utils/usageToHuman.test.d.ts +1 -0
  9. package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +4 -0
  10. package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +12 -2
  11. package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +12 -2
  12. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +7 -1
  13. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +7 -4
  14. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +15 -0
  15. package/{umd/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts → esm/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts} +5 -2
  16. package/esm/typings/src/llm-providers/_common/utils/{count-total-cost/limitTotalCost.d.ts → count-total-usage/limitTotalUsage.d.ts} +8 -5
  17. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
  18. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +3 -0
  19. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +1 -0
  20. package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +3 -0
  21. package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.test.d.ts +1 -0
  22. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +2 -1
  23. package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +3 -0
  24. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
  25. package/esm/typings/src/prepare/preparePipeline.d.ts +0 -1
  26. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
  27. package/package.json +2 -2
  28. package/umd/index.umd.js +139 -16
  29. package/umd/index.umd.js.map +1 -1
  30. package/umd/typings/promptbook-collection/index.d.ts +3 -3
  31. package/umd/typings/src/_packages/core.index.d.ts +2 -1
  32. package/umd/typings/src/conversion/pipelineJsonToString.d.ts +2 -1
  33. package/umd/typings/src/execution/createPipelineExecutor.d.ts +1 -0
  34. package/umd/typings/src/execution/utils/usageToHuman.d.ts +15 -0
  35. package/umd/typings/src/execution/utils/usageToHuman.test.d.ts +1 -0
  36. package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +4 -0
  37. package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +12 -2
  38. package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +12 -2
  39. package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +7 -1
  40. package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +7 -4
  41. package/umd/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +15 -0
  42. package/{esm/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts → umd/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts} +5 -2
  43. package/umd/typings/src/llm-providers/_common/utils/{count-total-cost/limitTotalCost.d.ts → count-total-usage/limitTotalUsage.d.ts} +8 -5
  44. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
  45. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +3 -0
  46. package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +1 -0
  47. package/umd/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +3 -0
  48. package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.test.d.ts +1 -0
  49. package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +2 -1
  50. package/umd/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +3 -0
  51. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
  52. package/umd/typings/src/prepare/preparePipeline.d.ts +0 -1
  53. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
  54. package/esm/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +0 -11
  55. package/umd/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +0 -11
package/esm/index.es.js CHANGED
@@ -387,7 +387,8 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
387
387
  /**
388
388
  * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
389
389
  * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
390
- * TODO: Escape all
390
+ * TODO: [🏛] Maybe make some markdown builder
391
+ * TODO: [🏛] Escape all
391
392
  */
392
393
 
393
394
  /**
@@ -1517,7 +1518,7 @@ function forEachAsync(array, options, callbackfunction) {
1517
1518
  });
1518
1519
  }
1519
1520
 
1520
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-30",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",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-30",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",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-30",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-30",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1521
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.62.0-0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0-0",usage:{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.62.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0-0",usage:{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.62.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0-0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.62.0-0",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0-0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1521
1522
 
1522
1523
  var defaultDiacriticsRemovalMap = [
1523
1524
  {
@@ -2287,6 +2288,9 @@ function joinLlmExecutionTools() {
2287
2288
  }
2288
2289
  return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
2289
2290
  }
2291
+ /**
2292
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2293
+ */
2290
2294
 
2291
2295
  /**
2292
2296
  * Determine if the pipeline is fully prepared
@@ -2522,7 +2526,7 @@ function union() {
2522
2526
  /**
2523
2527
  * The version of the Promptbook library
2524
2528
  */
2525
- var PROMPTBOOK_VERSION = '0.61.0-30';
2529
+ var PROMPTBOOK_VERSION = '0.62.0-0';
2526
2530
  // TODO: !!!! List here all the versions and annotate + put into script
2527
2531
 
2528
2532
  /**
@@ -3436,6 +3440,7 @@ function createPipelineExecutor(options) {
3436
3440
  }
3437
3441
  /**
3438
3442
  * TODO: Use isVerbose here (not only pass to `preparePipeline`)
3443
+ * TODO: [🧠] Use here `countTotalUsage` and put preparation and prepared pipiline to report
3439
3444
  * TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
3440
3445
  * TODO: [♈] Probbably move expectations from templates to parameters
3441
3446
  * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
@@ -3644,6 +3649,86 @@ TODO: [🧊] This is how it can look in future
3644
3649
  * [ ] One piece can have multiple sources
3645
3650
  */
3646
3651
 
3652
+ /**
3653
+ * Intercepts LLM tools and counts total usage of the tools
3654
+ *
3655
+ * @param llmTools LLM tools to be intercepted with usage counting
3656
+ * @returns LLM tools with same functionality with added total cost counting
3657
+ */
3658
+ function countTotalUsage(llmTools) {
3659
+ var _this = this;
3660
+ var totalUsage = ZERO_USAGE;
3661
+ var proxyTools = {
3662
+ get title() {
3663
+ // TODO: [🧠] Maybe put here some suffix
3664
+ return llmTools.title;
3665
+ },
3666
+ get description() {
3667
+ // TODO: [🧠] Maybe put here some suffix
3668
+ return llmTools.description;
3669
+ },
3670
+ listModels: function () {
3671
+ return /* not await */ llmTools.listModels();
3672
+ },
3673
+ getTotalUsage: function () {
3674
+ // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
3675
+ return totalUsage;
3676
+ },
3677
+ };
3678
+ if (llmTools.callChatModel !== undefined) {
3679
+ proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
3680
+ var promptResult;
3681
+ return __generator(this, function (_a) {
3682
+ switch (_a.label) {
3683
+ case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
3684
+ case 1:
3685
+ promptResult = _a.sent();
3686
+ totalUsage = addUsage(totalUsage, promptResult.usage);
3687
+ return [2 /*return*/, promptResult];
3688
+ }
3689
+ });
3690
+ }); };
3691
+ }
3692
+ if (llmTools.callCompletionModel !== undefined) {
3693
+ proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
3694
+ var promptResult;
3695
+ return __generator(this, function (_a) {
3696
+ switch (_a.label) {
3697
+ case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
3698
+ case 1:
3699
+ promptResult = _a.sent();
3700
+ totalUsage = addUsage(totalUsage, promptResult.usage);
3701
+ return [2 /*return*/, promptResult];
3702
+ }
3703
+ });
3704
+ }); };
3705
+ }
3706
+ if (llmTools.callEmbeddingModel !== undefined) {
3707
+ proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
3708
+ var promptResult;
3709
+ return __generator(this, function (_a) {
3710
+ switch (_a.label) {
3711
+ case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
3712
+ case 1:
3713
+ promptResult = _a.sent();
3714
+ totalUsage = addUsage(totalUsage, promptResult.usage);
3715
+ return [2 /*return*/, promptResult];
3716
+ }
3717
+ });
3718
+ }); };
3719
+ }
3720
+ // <- Note: [🤖]
3721
+ return proxyTools;
3722
+ }
3723
+ /**
3724
+ * TODO: [🔼] !!! Export via `@promptbookcore/`
3725
+ * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
3726
+ * TODO: [🧠] Is there some meaningfull way how to test this util
3727
+ * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
3728
+ * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
3729
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
3730
+ */
3731
+
3647
3732
  /**
3648
3733
  * Prepares the persona for the pipeline
3649
3734
  *
@@ -3767,23 +3852,24 @@ function prepareTemplates(pipeline, options) {
3767
3852
  */
3768
3853
  function preparePipeline(pipeline, options) {
3769
3854
  return __awaiter(this, void 0, void 0, function () {
3770
- var _a, maxParallelCount, parameters, promptTemplates,
3855
+ var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
3771
3856
  /*
3772
3857
  <- TODO: [🧠][0] `promptbookVersion` */
3773
3858
  knowledgeSources /*
3774
3859
  <- TODO: [🧊] `knowledgePieces` */, personas /*
3775
- <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
3860
+ <- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
3776
3861
  var _this = this;
3777
- return __generator(this, function (_b) {
3778
- switch (_b.label) {
3862
+ return __generator(this, function (_c) {
3863
+ switch (_c.label) {
3779
3864
  case 0:
3780
- _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3865
+ llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
3781
3866
  parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3867
+ llmToolsWithUsage = countTotalUsage(llmTools);
3782
3868
  currentPreparation = {
3783
3869
  id: 1,
3784
3870
  // TODO: [🍥]> date: $currentDate(),
3785
3871
  promptbookVersion: PROMPTBOOK_VERSION,
3786
- modelUsage: ZERO_USAGE,
3872
+ usage: ZERO_USAGE,
3787
3873
  };
3788
3874
  preparations = [
3789
3875
  // ...preparations
@@ -3795,7 +3881,11 @@ function preparePipeline(pipeline, options) {
3795
3881
  var modelRequirements, preparedPersona;
3796
3882
  return __generator(this, function (_a) {
3797
3883
  switch (_a.label) {
3798
- case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
3884
+ case 0: return [4 /*yield*/, preparePersona(persona.description, {
3885
+ llmTools: llmToolsWithUsage,
3886
+ maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
3887
+ isVerbose: isVerbose,
3888
+ })];
3799
3889
  case 1:
3800
3890
  modelRequirements = _a.sent();
3801
3891
  preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
@@ -3805,20 +3895,30 @@ function preparePipeline(pipeline, options) {
3805
3895
  });
3806
3896
  }); })];
3807
3897
  case 1:
3808
- _b.sent();
3898
+ _c.sent();
3809
3899
  knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3810
- return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
3900
+ return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, {
3901
+ llmTools: llmToolsWithUsage,
3902
+ maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
3903
+ isVerbose: isVerbose,
3904
+ })];
3811
3905
  case 2:
3812
- partialknowledgePiecesPrepared = _b.sent();
3906
+ partialknowledgePiecesPrepared = _c.sent();
3813
3907
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3814
3908
  return [4 /*yield*/, prepareTemplates({
3815
3909
  parameters: parameters,
3816
3910
  promptTemplates: promptTemplates,
3817
3911
  knowledgePiecesCount: knowledgePiecesPrepared.length,
3818
- }, options)];
3912
+ }, {
3913
+ llmTools: llmToolsWithUsage,
3914
+ maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
3915
+ isVerbose: isVerbose,
3916
+ })];
3819
3917
  case 3:
3820
- promptTemplatesPrepared = (_b.sent()).promptTemplatesPrepared;
3918
+ promptTemplatesPrepared = (_c.sent()).promptTemplatesPrepared;
3821
3919
  // ----- /Templates preparation -----
3920
+ // Note: Count total usage
3921
+ currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
3822
3922
  return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3823
3923
  }
3824
3924
  });
@@ -3829,7 +3929,6 @@ function preparePipeline(pipeline, options) {
3829
3929
  * TODO: Write tests for `preparePipeline`
3830
3930
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3831
3931
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3832
- * TODO: [🎐] !!!!! Use here countTotalUsage
3833
3932
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3834
3933
  */
3835
3934
 
@@ -6029,6 +6128,29 @@ function usageToWorktime(usage) {
6029
6128
  return uncertainNumber;
6030
6129
  }
6031
6130
 
6131
+ /**
6132
+ * Function `usageToHuman` will take usage and convert it to human readable report
6133
+ */
6134
+ function usageToHuman(usage) {
6135
+ var report = 'Usage:';
6136
+ var uncertainNumberToHuman = function (_a) {
6137
+ var value = _a.value, isUncertain = _a.isUncertain;
6138
+ return "".concat(isUncertain ? 'approximately ' : '').concat(Math.round(value * 100) / 100);
6139
+ };
6140
+ report += '\n' + "- Cost ".concat(uncertainNumberToHuman(usage.price), " USD");
6141
+ report += '\n' + "- Saved ".concat(uncertainNumberToHuman(usageToWorktime(usage)), " hours of human time");
6142
+ return spaceTrim(report);
6143
+ }
6144
+ /**
6145
+ * TODO: Use "$1" not "1 USD"
6146
+ * TODO: Use markdown formatting like "Cost approximately **$1**"
6147
+ * TODO: Report in minutes, seconds, days NOT 0.1 hours
6148
+ * TODO: [🧠] Maybe make from `uncertainNumberToHuman` separate exported utility
6149
+ * TODO: When negligible usage, report "Negligible" or just don't report it
6150
+ * TODO: [🧠] Maybe use "~" instead of "approximately"
6151
+ * TODO: [🏛] Maybe make some markdown builder
6152
+ */
6153
+
6032
6154
  /**
6033
6155
  * Delagates the user interaction to a async callback function
6034
6156
  * You need to provide your own implementation of this callback function and its bind to UI.
@@ -6407,5 +6529,5 @@ function executionReportJsonToString(executionReportJson, options) {
6407
6529
  * TODO: [🧠] Allow to filter out some parts of the report by options
6408
6530
  */
6409
6531
 
6410
- export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatchError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, preparePipeline, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToWorktime, validatePipeline };
6532
+ export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatchError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, preparePipeline, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
6411
6533
  //# sourceMappingURL=index.es.js.map