@promptbook/node 0.66.0-1 → 0.66.0-5

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 (45) hide show
  1. package/esm/index.es.js +85 -45
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +8 -2
  5. package/esm/typings/src/_packages/openai.index.d.ts +4 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +10 -2
  7. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
  8. package/esm/typings/src/config.d.ts +0 -7
  9. package/esm/typings/src/execution/AvailableModel.d.ts +20 -0
  10. package/esm/typings/src/execution/LlmExecutionTools.d.ts +1 -19
  11. package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +10 -0
  12. package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -1
  13. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +1 -1
  14. package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts +1 -1
  15. package/esm/typings/src/llm-providers/_common/$llmToolsMetadataRegister.d.ts +10 -0
  16. package/esm/typings/src/llm-providers/_common/$llmToolsRegister.d.ts +10 -0
  17. package/esm/typings/src/llm-providers/_common/LlmToolsConfiguration.d.ts +7 -13
  18. package/esm/typings/src/llm-providers/_common/LlmToolsMetadata.d.ts +27 -0
  19. package/esm/typings/src/llm-providers/_common/LlmToolsOptions.d.ts +7 -0
  20. package/esm/typings/src/llm-providers/_common/config.d.ts +4 -0
  21. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -2
  22. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  23. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +1 -1
  24. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.test.d.ts +1 -1
  25. package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +7 -2
  26. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +8 -0
  27. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +11 -0
  28. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +2 -2
  29. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  30. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  31. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +1 -1
  32. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -3
  33. package/esm/typings/src/llm-providers/openai/{computeOpenaiUsage.d.ts → computeOpenAiUsage.d.ts} +2 -2
  34. package/esm/typings/src/llm-providers/openai/{computeOpenaiUsage.test.d.ts → computeOpenAiUsage.test.d.ts} +1 -1
  35. package/esm/typings/src/llm-providers/openai/createOpenAiExecutionTools.d.ts +15 -0
  36. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  37. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +8 -0
  38. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +11 -0
  39. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  40. package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +2 -2
  41. package/esm/typings/src/personas/preparePersona.test.d.ts +1 -1
  42. package/esm/typings/src/utils/Register.d.ts +22 -0
  43. package/package.json +2 -2
  44. package/umd/index.umd.js +85 -45
  45. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -17,7 +17,7 @@ import OpenAI from 'openai';
17
17
  /**
18
18
  * The version of the Promptbook library
19
19
  */
20
- var PROMPTBOOK_VERSION = '0.66.0-0';
20
+ var PROMPTBOOK_VERSION = '0.66.0-4';
21
21
  // TODO: !!!! List here all the versions and annotate + put into script
22
22
 
23
23
  /*! *****************************************************************************
@@ -696,7 +696,7 @@ function forEachAsync(array, options, callbackfunction) {
696
696
  });
697
697
  }
698
698
 
699
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.66.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.66.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.66.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:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
699
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.0-4",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:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.66.0-4",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:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.66.0-4",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:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.66.0-4",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:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
700
700
 
701
701
  /**
702
702
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -6286,6 +6286,38 @@ var EnvironmentMismatchError = /** @class */ (function (_super) {
6286
6286
  return EnvironmentMismatchError;
6287
6287
  }(Error));
6288
6288
 
6289
+ /**
6290
+ * Register is @@@
6291
+ *
6292
+ * @private internal utility, exported are only signleton instances of this class
6293
+ */
6294
+ var Register = /** @class */ (function () {
6295
+ function Register(storage) {
6296
+ this.storage = storage;
6297
+ }
6298
+ Register.prototype.list = function () {
6299
+ // <- TODO: ReadonlyDeep<Array<TRegistered>>
6300
+ return this.storage;
6301
+ };
6302
+ Register.prototype.register = function (registered) {
6303
+ // !!!!!! <- TODO: What to return here
6304
+ // TODO: !!!!!! Compare if same is not already registered
6305
+ this.storage.push(registered);
6306
+ };
6307
+ return Register;
6308
+ }());
6309
+
6310
+ /**
6311
+ * @@@
6312
+ *
6313
+ * Note: `$` is used to indicate that this interacts with the global scope
6314
+ * @singleton Only one instance of each register is created per build, but thare can be more @@@
6315
+ * @public exported from `@promptbook/core`
6316
+ */
6317
+ var $llmToolsMetadataRegister = new Register([
6318
+ // TODO: !!!!!! Take from global scope
6319
+ ]);
6320
+
6289
6321
  /**
6290
6322
  * @@@
6291
6323
  *
@@ -6303,28 +6335,10 @@ function createLlmToolsFromConfigurationFromEnv() {
6303
6335
  throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
6304
6336
  }
6305
6337
  dotenv.config();
6306
- var llmToolsConfiguration = [];
6307
- if (typeof process.env.OPENAI_API_KEY === 'string') {
6308
- llmToolsConfiguration.push({
6309
- title: 'OpenAI (from env)',
6310
- packageName: '@promptbook/openai',
6311
- className: 'OpenAiExecutionTools',
6312
- options: {
6313
- apiKey: process.env.OPENAI_API_KEY,
6314
- },
6315
- });
6316
- }
6317
- if (typeof process.env.ANTHROPIC_CLAUDE_API_KEY === 'string') {
6318
- llmToolsConfiguration.push({
6319
- title: 'Claude (from env)',
6320
- packageName: '@promptbook/antrhopic-claude',
6321
- className: 'AnthropicClaudeExecutionTools',
6322
- options: {
6323
- apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
6324
- },
6325
- });
6326
- }
6327
- // <- Note: [🦑] Add here new LLM provider
6338
+ var llmToolsConfiguration = $llmToolsMetadataRegister
6339
+ .list()
6340
+ .map(function (metadata) { return metadata.createConfigurationFromEnv(process.env); })
6341
+ .filter(function (configuration) { return configuration !== null; });
6328
6342
  return llmToolsConfiguration;
6329
6343
  }
6330
6344
  /**
@@ -6650,7 +6664,7 @@ resultContent, rawResponse) {
6650
6664
  };
6651
6665
  }
6652
6666
  /**
6653
- * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
6667
+ * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
6654
6668
  */
6655
6669
 
6656
6670
  /**
@@ -6873,7 +6887,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6873
6887
  * TODO: [🍆] JSON mode
6874
6888
  * TODO: [🧠] Maybe handle errors via transformAnthropicError (like transformAzureError)
6875
6889
  * TODO: Maybe Create some common util for callChatModel and callCompletionModel
6876
- * TODO: Maybe make custom OpenaiError
6890
+ * TODO: Maybe make custom OpenAiError
6877
6891
  * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
6878
6892
  * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
6879
6893
  * TODO: [📅] Maybe instead of `RemoteLlmExecutionToolsOptions` use `proxyWithAnonymousRemoteServer` (if implemented)
@@ -6884,7 +6898,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6884
6898
  *
6885
6899
  * @public exported from `@promptbook/anthropic-claude`
6886
6900
  */
6887
- function createAnthropicClaudeExecutionTools(options) {
6901
+ var createAnthropicClaudeExecutionTools = Object.assign(function (options) {
6888
6902
  if (options.isProxied) {
6889
6903
  return new RemoteLlmExecutionTools(__assign(__assign({}, options), { isAnonymous: true, llmToolsConfiguration: [
6890
6904
  {
@@ -6895,14 +6909,17 @@ function createAnthropicClaudeExecutionTools(options) {
6895
6909
  },
6896
6910
  ], models: ANTHROPIC_CLAUDE_MODELS }));
6897
6911
  }
6898
- return new AnthropicClaudeExecutionTools(
6899
- // <- TODO: [🧱] Implement in a functional (not new Class) way
6900
- options);
6901
- }
6912
+ return new AnthropicClaudeExecutionTools(options);
6913
+ }, {
6914
+ packageName: '@promptbook/anthropic-claude',
6915
+ className: 'AnthropicClaudeExecutionTools',
6916
+ });
6902
6917
  /**
6903
6918
  * TODO: [🧠] !!!! Make anonymous this with all LLM providers
6904
- * TODO: [🧠] !!!! Maybe change all `new AnthropicClaudeExecutionTools` -> `createAnthropicClaudeExecutionTools` in manual
6919
+ * TODO: [🧠][🧱] !!!! Maybe change all `new AnthropicClaudeExecutionTools` -> `createAnthropicClaudeExecutionTools` in manual
6905
6920
  * TODO: [🧠] Maybe auto-detect usage in browser and determine default value of `isProxied`
6921
+ * TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
6922
+ * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
6906
6923
  */
6907
6924
 
6908
6925
  /**
@@ -7504,7 +7521,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
7504
7521
  }());
7505
7522
  /**
7506
7523
  * TODO: Maybe Create some common util for callChatModel and callCompletionModel
7507
- * TODO: Maybe make custom AzureOpenaiError
7524
+ * TODO: Maybe make custom AzureOpenAiError
7508
7525
  * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
7509
7526
  * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
7510
7527
  */
@@ -7518,7 +7535,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
7518
7535
  * @throws {PipelineExecutionError} If the usage is not defined in the response from OpenAI
7519
7536
  * @private internal utility of `OpenAiExecutionTools`
7520
7537
  */
7521
- function computeOpenaiUsage(promptContent, // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
7538
+ function computeOpenAiUsage(promptContent, // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
7522
7539
  resultContent, rawResponse) {
7523
7540
  var _a, _b;
7524
7541
  if (rawResponse.usage === undefined) {
@@ -7544,11 +7561,11 @@ resultContent, rawResponse) {
7544
7561
  };
7545
7562
  }
7546
7563
  /**
7547
- * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
7564
+ * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
7548
7565
  */
7549
7566
 
7550
7567
  /**
7551
- * Execution Tools for calling OpenAI API.
7568
+ * Execution Tools for calling OpenAI API
7552
7569
  *
7553
7570
  * @public exported from `@promptbook/openai`
7554
7571
  */
@@ -7647,7 +7664,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
7647
7664
  resultContent = rawResponse.choices[0].message.content;
7648
7665
  // eslint-disable-next-line prefer-const
7649
7666
  complete = getCurrentIsoDate();
7650
- usage = computeOpenaiUsage(content, resultContent || '', rawResponse);
7667
+ usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
7651
7668
  if (resultContent === null) {
7652
7669
  throw new PipelineExecutionError('No response message from OpenAI');
7653
7670
  }
@@ -7716,7 +7733,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
7716
7733
  resultContent = rawResponse.choices[0].text;
7717
7734
  // eslint-disable-next-line prefer-const
7718
7735
  complete = getCurrentIsoDate();
7719
- usage = computeOpenaiUsage(content, resultContent || '', rawResponse);
7736
+ usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
7720
7737
  return [2 /*return*/, {
7721
7738
  content: resultContent,
7722
7739
  modelName: rawResponse.model || modelName,
@@ -7773,7 +7790,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
7773
7790
  resultContent = rawResponse.data[0].embedding;
7774
7791
  // eslint-disable-next-line prefer-const
7775
7792
  complete = getCurrentIsoDate();
7776
- usage = computeOpenaiUsage(content, '', rawResponse);
7793
+ usage = computeOpenAiUsage(content, '', rawResponse);
7777
7794
  return [2 /*return*/, {
7778
7795
  content: resultContent,
7779
7796
  modelName: rawResponse.model || modelName,
@@ -7847,18 +7864,37 @@ var OpenAiExecutionTools = /** @class */ (function () {
7847
7864
  /**
7848
7865
  * TODO: [🧠][🧙‍♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
7849
7866
  * TODO: Maybe Create some common util for callChatModel and callCompletionModel
7850
- * TODO: Maybe make custom OpenaiError
7867
+ * TODO: Maybe make custom OpenAiError
7851
7868
  * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
7852
7869
  * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
7853
7870
  */
7854
7871
 
7855
7872
  /**
7873
+ * Execution Tools for calling OpenAI API
7874
+ *
7875
+ * @public exported from `@promptbook/openai`
7876
+ */
7877
+ var createOpenAiExecutionTools = Object.assign(function (options) {
7878
+ // TODO: !!!!!! If browser, auto add `dangerouslyAllowBrowser`
7879
+ return new OpenAiExecutionTools(options);
7880
+ }, {
7881
+ packageName: '@promptbook/openai',
7882
+ className: 'OpenAiExecutionTools',
7883
+ });
7884
+ /**
7885
+ * TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
7886
+ * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
7887
+ */
7888
+
7889
+ /**
7890
+ * @@@
7891
+ *
7892
+ * TODO: !!!!!! Remove EXECUTION_TOOLS_CLASSES and use $llmToolsRegister instead
7893
+ *
7856
7894
  * @private internal type for `createLlmToolsFromConfiguration`
7857
7895
  */
7858
7896
  var EXECUTION_TOOLS_CLASSES = {
7859
- createOpenAiExecutionTools: function (options) {
7860
- return new OpenAiExecutionTools(__assign(__assign({}, options), { dangerouslyAllowBrowser: true /* <- TODO: [🧠] !!! Some mechanism for auto-detection of browser, maybe hide in `OpenAiExecutionTools` */ }));
7861
- },
7897
+ createOpenAiExecutionTools: createOpenAiExecutionTools,
7862
7898
  createAnthropicClaudeExecutionTools: createAnthropicClaudeExecutionTools,
7863
7899
  createAzureOpenAiExecutionTools: function (options) {
7864
7900
  return new AzureOpenAiExecutionTools(
@@ -7884,7 +7920,11 @@ function createLlmToolsFromConfiguration(configuration, options) {
7884
7920
  if (options === void 0) { options = {}; }
7885
7921
  var _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
7886
7922
  var llmTools = configuration.map(function (llmConfiguration) {
7887
- return EXECUTION_TOOLS_CLASSES["create".concat(llmConfiguration.className)](__assign({ isVerbose: isVerbose }, llmConfiguration.options));
7923
+ var constructor = EXECUTION_TOOLS_CLASSES["create".concat(llmConfiguration.className)];
7924
+ if (!constructor) {
7925
+ throw new Error(spaceTrim(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "`\n\n\n @@@\n\n Available constructors are:\n ").concat(block('@@@'), "\n\n\n "); }));
7926
+ }
7927
+ return constructor(__assign({ isVerbose: isVerbose }, llmConfiguration.options));
7888
7928
  });
7889
7929
  return joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(llmTools), false));
7890
7930
  }
@@ -7919,7 +7959,7 @@ function createLlmToolsFromEnv(options) {
7919
7959
  var configuration = createLlmToolsFromConfigurationFromEnv();
7920
7960
  if (configuration.length === 0) {
7921
7961
  // TODO: [🥃]
7922
- throw new Error(spaceTrim("\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n "));
7962
+ throw new Error(spaceTrim("\n No LLM tools found in the environment\n\n !!!!!!!@@@@You have maybe forgotten to two things:\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n "));
7923
7963
  }
7924
7964
  return createLlmToolsFromConfiguration(configuration, options);
7925
7965
  }