@promptbook/cli 0.62.0-0 → 0.62.0

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 (35) hide show
  1. package/esm/index.es.js +70 -50
  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/execution/createPipelineExecutor.d.ts +1 -1
  5. package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +3 -0
  6. package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -1
  7. package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -1
  8. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +6 -0
  9. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -2
  10. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
  11. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +3 -0
  12. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +1 -0
  13. package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.test.d.ts +1 -0
  14. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +2 -1
  15. package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +3 -0
  16. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
  17. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
  18. package/package.json +2 -2
  19. package/umd/index.umd.js +92 -54
  20. package/umd/index.umd.js.map +1 -1
  21. package/umd/typings/promptbook-collection/index.d.ts +3 -3
  22. package/umd/typings/src/execution/createPipelineExecutor.d.ts +1 -1
  23. package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +3 -0
  24. package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -1
  25. package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -1
  26. package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +6 -0
  27. package/umd/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -2
  28. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
  29. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +3 -0
  30. package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +1 -0
  31. package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.test.d.ts +1 -0
  32. package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +2 -1
  33. package/umd/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +3 -0
  34. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
  35. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
package/esm/index.es.js CHANGED
@@ -8,6 +8,7 @@ import { format } from 'prettier';
8
8
  import parserHtml from 'prettier/parser-html';
9
9
  import hexEncoder from 'crypto-js/enc-hex';
10
10
  import sha256 from 'crypto-js/sha256';
11
+ import * as dotenv from 'dotenv';
11
12
  import Anthropic from '@anthropic-ai/sdk';
12
13
  import OpenAI from 'openai';
13
14
  import glob from 'glob-promise';
@@ -150,7 +151,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
150
151
  /**
151
152
  * The version of the Promptbook library
152
153
  */
153
- var PROMPTBOOK_VERSION = '0.61.0';
154
+ var PROMPTBOOK_VERSION = '0.62.0-1';
154
155
  // TODO: !!!! List here all the versions and annotate + put into script
155
156
 
156
157
  /**
@@ -748,7 +749,7 @@ function forEachAsync(array, options, callbackfunction) {
748
749
  });
749
750
  }
750
751
 
751
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.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.61.0",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",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",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",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",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",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",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"}];
752
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.62.0-1",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-1",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-1",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-1",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-1",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-1",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-1",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-1",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"}];
752
753
 
753
754
  /**
754
755
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -3252,7 +3253,7 @@ function createPipelineExecutor(options) {
3252
3253
  }
3253
3254
  /**
3254
3255
  * TODO: Use isVerbose here (not only pass to `preparePipeline`)
3255
- * TODO: [🧠] Use here `countTotalUsage` and put preparation and prepared pipiline to report
3256
+ * TODO: [🧠][🌳] Use here `countTotalUsage` and put preparation and prepared pipiline to report
3256
3257
  * TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
3257
3258
  * TODO: [♈] Probbably move expectations from templates to parameters
3258
3259
  * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
@@ -3482,7 +3483,8 @@ function countTotalUsage(llmTools) {
3482
3483
  listModels: function () {
3483
3484
  return /* not await */ llmTools.listModels();
3484
3485
  },
3485
- get totalUsage() {
3486
+ getTotalUsage: function () {
3487
+ // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
3486
3488
  return totalUsage;
3487
3489
  },
3488
3490
  };
@@ -3680,7 +3682,7 @@ function preparePipeline(pipeline, options) {
3680
3682
  id: 1,
3681
3683
  // TODO: [🍥]> date: $currentDate(),
3682
3684
  promptbookVersion: PROMPTBOOK_VERSION,
3683
- modelUsage: ZERO_USAGE,
3685
+ usage: ZERO_USAGE,
3684
3686
  };
3685
3687
  preparations = [
3686
3688
  // ...preparations
@@ -3729,7 +3731,7 @@ function preparePipeline(pipeline, options) {
3729
3731
  promptTemplatesPrepared = (_c.sent()).promptTemplatesPrepared;
3730
3732
  // ----- /Templates preparation -----
3731
3733
  // Note: Count total usage
3732
- currentPreparation.modelUsage = llmToolsWithUsage.totalUsage;
3734
+ currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
3733
3735
  return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3734
3736
  }
3735
3737
  });
@@ -6197,7 +6199,7 @@ var FilesStorage = /** @class */ (function () {
6197
6199
  switch (_a.label) {
6198
6200
  case 0:
6199
6201
  filename = this.getFilenameForKey(key);
6200
- fileContent = JSON.stringify(value, null, 4);
6202
+ fileContent = stringifyPipelineJson(value);
6201
6203
  return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
6202
6204
  case 1:
6203
6205
  _a.sent(); // <- [0]
@@ -6264,7 +6266,7 @@ function computeUsageCounts(content) {
6264
6266
  * @private utility for initializating UncertainNumber
6265
6267
  */
6266
6268
  function uncertainNumber(value) {
6267
- if (value === null || value === undefined || Number.isNaN(NaN)) {
6269
+ if (value === null || value === undefined || Number.isNaN(value)) {
6268
6270
  return { value: 0, isUncertain: true };
6269
6271
  }
6270
6272
  return { value: value };
@@ -6578,6 +6580,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6578
6580
  * TODO: Maybe Create some common util for callChatModel and callCompletionModel
6579
6581
  * TODO: Maybe make custom OpenaiError
6580
6582
  * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
6583
+ * TODO: [🍜] Auto use anonymous server in browser
6581
6584
  */
6582
6585
 
6583
6586
  /**
@@ -7271,6 +7274,8 @@ var OpenAiExecutionTools = /** @class */ (function () {
7271
7274
  *
7272
7275
  * Note: This function is not cached, every call creates new instance of `LlmExecutionTools`
7273
7276
  *
7277
+ * @@@ .env
7278
+ *
7274
7279
  * It looks for environment variables:
7275
7280
  * - `process.env.OPENAI_API_KEY`
7276
7281
  * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
@@ -7283,6 +7288,7 @@ function createLlmToolsFromEnv(options) {
7283
7288
  throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
7284
7289
  }
7285
7290
  var _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
7291
+ dotenv.config();
7286
7292
  var llmTools = [];
7287
7293
  if (typeof process.env.OPENAI_API_KEY === 'string') {
7288
7294
  llmTools.push(new OpenAiExecutionTools({
@@ -7307,6 +7313,7 @@ function createLlmToolsFromEnv(options) {
7307
7313
  }
7308
7314
  }
7309
7315
  /**
7316
+ * TODO: [🍜] Use `createLlmToolsFromConfiguration`
7310
7317
  * TODO: [🔼] !!! Export via `@promptbook/node`
7311
7318
  * TODO: @@@ write discussion about this - wizzard
7312
7319
  * TODO: Add Azure
@@ -7390,9 +7397,9 @@ function $currentDate() {
7390
7397
  function cacheLlmTools(llmTools, options) {
7391
7398
  var _this = this;
7392
7399
  if (options === void 0) { options = {}; }
7393
- var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a;
7400
+ var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a, _b = options.isReloaded, isReloaded = _b === void 0 ? false : _b;
7394
7401
  var proxyTools = __assign(__assign({}, llmTools), {
7395
- // <- TODO: !!!!!! Is this working?
7402
+ // <- Note: [🥫]
7396
7403
  get title() {
7397
7404
  // TODO: [🧠] Maybe put here some suffix
7398
7405
  return llmTools.title;
@@ -7405,47 +7412,54 @@ function cacheLlmTools(llmTools, options) {
7405
7412
  return /* not await */ llmTools.listModels();
7406
7413
  } });
7407
7414
  var callCommonModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
7408
- var key, cacheItem, promptResult, _a;
7409
- return __generator(this, function (_b) {
7410
- switch (_b.label) {
7415
+ var key, cacheItem, _a, promptResult, _b;
7416
+ return __generator(this, function (_c) {
7417
+ switch (_c.label) {
7411
7418
  case 0:
7412
7419
  key = titleToName(prompt.title.substring(0, MAX_FILENAME_LENGTH - 10) +
7413
7420
  '-' +
7414
7421
  sha256(hexEncoder.parse(JSON.stringify(prompt.parameters))).toString( /* hex */));
7422
+ if (!!isReloaded) return [3 /*break*/, 2];
7415
7423
  return [4 /*yield*/, storage.getItem(key)];
7416
7424
  case 1:
7417
- cacheItem = _b.sent();
7425
+ _a = _c.sent();
7426
+ return [3 /*break*/, 3];
7427
+ case 2:
7428
+ _a = null;
7429
+ _c.label = 3;
7430
+ case 3:
7431
+ cacheItem = _a;
7418
7432
  if (cacheItem) {
7419
7433
  return [2 /*return*/, cacheItem.promptResult];
7420
7434
  }
7421
- _a = prompt.modelRequirements.modelVariant;
7422
- switch (_a) {
7423
- case 'CHAT': return [3 /*break*/, 2];
7424
- case 'COMPLETION': return [3 /*break*/, 4];
7425
- case 'EMBEDDING': return [3 /*break*/, 6];
7435
+ _b = prompt.modelRequirements.modelVariant;
7436
+ switch (_b) {
7437
+ case 'CHAT': return [3 /*break*/, 4];
7438
+ case 'COMPLETION': return [3 /*break*/, 6];
7439
+ case 'EMBEDDING': return [3 /*break*/, 8];
7426
7440
  }
7427
- return [3 /*break*/, 8];
7428
- case 2: return [4 /*yield*/, llmTools.callChatModel(prompt)];
7429
- case 3:
7430
- promptResult = _b.sent();
7431
- return [3 /*break*/, 9];
7432
- case 4: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
7441
+ return [3 /*break*/, 10];
7442
+ case 4: return [4 /*yield*/, llmTools.callChatModel(prompt)];
7433
7443
  case 5:
7434
- promptResult = _b.sent();
7435
- return [3 /*break*/, 9];
7436
- case 6: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
7444
+ promptResult = _c.sent();
7445
+ return [3 /*break*/, 11];
7446
+ case 6: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
7437
7447
  case 7:
7438
- promptResult = _b.sent();
7439
- return [3 /*break*/, 9];
7440
- case 8: throw new PipelineExecutionError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
7441
- case 9: return [4 /*yield*/, storage.setItem(key, {
7448
+ promptResult = _c.sent();
7449
+ return [3 /*break*/, 11];
7450
+ case 8: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
7451
+ case 9:
7452
+ promptResult = _c.sent();
7453
+ return [3 /*break*/, 11];
7454
+ case 10: throw new PipelineExecutionError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
7455
+ case 11: return [4 /*yield*/, storage.setItem(key, {
7442
7456
  date: $currentDate(),
7443
7457
  promptbookVersion: PROMPTBOOK_VERSION,
7444
7458
  prompt: prompt,
7445
7459
  promptResult: promptResult,
7446
7460
  })];
7447
- case 10:
7448
- _b.sent();
7461
+ case 12:
7462
+ _c.sent();
7449
7463
  return [2 /*return*/, promptResult];
7450
7464
  }
7451
7465
  });
@@ -7488,14 +7502,16 @@ function cacheLlmTools(llmTools, options) {
7488
7502
  *
7489
7503
  * @private within the repository - for CLI utils
7490
7504
  */
7491
- function getLlmToolsForCli() {
7505
+ function getLlmToolsForCli(options) {
7492
7506
  if (!isRunningInNode()) {
7493
7507
  throw new EnvironmentMismatchError('Function `getLlmToolsForTestingAndScriptsAndPlayground` works only in Node.js environment');
7494
7508
  }
7509
+ var _a = (options !== null && options !== void 0 ? options : {}).isCacheReloaded, isCacheReloaded = _a === void 0 ? false : _a;
7495
7510
  return cacheLlmTools(countTotalUsage(
7496
7511
  // <- Note: for example here we don`t want the [🌯]
7497
7512
  createLlmToolsFromEnv()), {
7498
7513
  storage: new FilesStorage({ cacheFolderPath: join(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
7514
+ isReloaded: isCacheReloaded,
7499
7515
  });
7500
7516
  }
7501
7517
  /**
@@ -7510,24 +7526,26 @@ function getLlmToolsForCli() {
7510
7526
  */
7511
7527
  function initializeMakeCommand(program) {
7512
7528
  var _this = this;
7513
- var helloCommand = program.command('make');
7514
- helloCommand.description(spaceTrim("\n Makes a new pipeline collection in given folder\n "));
7515
- helloCommand.argument('<path>', 'Path to promptbook directory');
7516
- helloCommand.option('--project-name', "Name of the project for whom collection is", 'Project');
7517
- helloCommand.option('-f, --format <format>', spaceTrim("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
7518
- helloCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
7519
- helloCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
7520
- helloCommand.option('--verbose', "Is verbose", false);
7521
- helloCommand.option('-o, --out-file <path>', spaceTrim("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), PIPELINE_COLLECTION_BASE_FILENAME);
7522
- helloCommand.action(function (path, _a) {
7523
- var projectName = _a.projectName, format = _a.format, validation = _a.validation, verbose = _a.verbose, outFile = _a.outFile;
7529
+ var makeCommand = program.command('make');
7530
+ makeCommand.description(spaceTrim("\n Makes a new pipeline collection in given folder\n "));
7531
+ makeCommand.argument('<path>', 'Path to promptbook directory');
7532
+ makeCommand.option('--project-name', "Name of the project for whom collection is", 'Project');
7533
+ makeCommand.option('-f, --format <format>', spaceTrim("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
7534
+ makeCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
7535
+ makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
7536
+ makeCommand.option('--reload-cache', "Use LLM models even if cached ", false);
7537
+ makeCommand.option('--verbose', "Is verbose", false);
7538
+ makeCommand.option('-o, --out-file <path>', spaceTrim("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), PIPELINE_COLLECTION_BASE_FILENAME);
7539
+ makeCommand.action(function (path, _a) {
7540
+ var projectName = _a.projectName, format = _a.format, validation = _a.validation, reloadCache = _a.reloadCache, verbose = _a.verbose, outFile = _a.outFile;
7524
7541
  return __awaiter(_this, void 0, void 0, function () {
7525
- var isVerbose, formats, validations, llmTools, collection, validations_1, validations_1_1, validation_1, _b, _c, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, saveFile;
7542
+ var isCacheReloaded, isVerbose, formats, validations, llmTools, collection, validations_1, validations_1_1, validation_1, _b, _c, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, saveFile;
7526
7543
  var e_2, _d, e_1, _e;
7527
7544
  var _this = this;
7528
7545
  return __generator(this, function (_f) {
7529
7546
  switch (_f.label) {
7530
7547
  case 0:
7548
+ isCacheReloaded = reloadCache;
7531
7549
  isVerbose = verbose;
7532
7550
  formats = (format || '')
7533
7551
  .split(',')
@@ -7541,11 +7559,14 @@ function initializeMakeCommand(program) {
7541
7559
  console.error(colors.red("You can use only one format when saving to a file"));
7542
7560
  process.exit(1);
7543
7561
  }
7544
- llmTools = getLlmToolsForCli();
7562
+ llmTools = getLlmToolsForCli({
7563
+ isCacheReloaded: isCacheReloaded,
7564
+ });
7545
7565
  return [4 /*yield*/, createCollectionFromDirectory(path, {
7546
7566
  llmTools: llmTools,
7547
7567
  isVerbose: isVerbose,
7548
7568
  isRecursive: true,
7569
+ // <- TODO: [🍖] isCacheReloaded
7549
7570
  })];
7550
7571
  case 1:
7551
7572
  collection = _f.sent();
@@ -7652,9 +7673,8 @@ function initializeMakeCommand(program) {
7652
7673
  _f.label = 23;
7653
7674
  case 23:
7654
7675
  if (isVerbose) {
7655
- // TODO: !!!!!! Test that this works
7656
7676
  console.info(colors.green("Collection builded"));
7657
- console.info(colors.cyan(usageToHuman(llmTools.totalUsage)));
7677
+ console.info(colors.cyan(usageToHuman(llmTools.getTotalUsage())));
7658
7678
  }
7659
7679
  process.exit(0);
7660
7680
  return [2 /*return*/];