@promptbook/core 0.65.0-1 → 0.65.0-2

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.
package/umd/index.umd.js CHANGED
@@ -1,22 +1,44 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('moment')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'moment'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.moment));
5
- })(this, (function (exports, spaceTrim, prettier, parserHtml, hexEncoder, sha256, moment) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('dotenv'), require('@anthropic-ai/sdk'), require('colors'), require('@azure/openai'), require('openai'), require('moment')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'dotenv', '@anthropic-ai/sdk', 'colors', '@azure/openai', 'openai', 'moment'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.dotenv, global.Anthropic, global.colors, global.openai, global.OpenAI, global.moment));
5
+ })(this, (function (exports, spaceTrim, prettier, parserHtml, hexEncoder, sha256, dotenv, Anthropic, colors, openai, OpenAI, moment) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
9
27
  var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
10
28
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
11
29
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
12
30
  var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
31
+ var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
32
+ var Anthropic__default = /*#__PURE__*/_interopDefaultLegacy(Anthropic);
33
+ var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
34
+ var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
13
35
  var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
14
36
 
15
37
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
16
38
  /**
17
39
  * The version of the Promptbook library
18
40
  */
19
- var PROMPTBOOK_VERSION = '0.65.0-0';
41
+ var PROMPTBOOK_VERSION = '0.65.0-1';
20
42
  // TODO: !!!! List here all the versions and annotate + put into script
21
43
 
22
44
  /*! *****************************************************************************
@@ -1631,7 +1653,7 @@
1631
1653
  });
1632
1654
  }
1633
1655
 
1634
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.65.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.65.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.65.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.65.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"}];
1656
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.65.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.65.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.65.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.65.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:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1635
1657
 
1636
1658
  var defaultDiacriticsRemovalMap = [
1637
1659
  {
@@ -6479,6 +6501,1335 @@
6479
6501
  return CallbackInterfaceTools;
6480
6502
  }());
6481
6503
 
6504
+ /**
6505
+ * Helper of usage compute
6506
+ *
6507
+ * @param content the content of prompt or response
6508
+ * @returns part of PromptResultUsageCounts
6509
+ *
6510
+ * @private internal utility of LlmExecutionTools
6511
+ */
6512
+ function computeUsageCounts(content) {
6513
+ return {
6514
+ charactersCount: { value: countCharacters(content) },
6515
+ wordsCount: { value: countWords(content) },
6516
+ sentencesCount: { value: countSentences(content) },
6517
+ linesCount: { value: countLines(content) },
6518
+ paragraphsCount: { value: countParagraphs(content) },
6519
+ pagesCount: { value: countPages(content) },
6520
+ };
6521
+ }
6522
+
6523
+ /**
6524
+ * Make UncertainNumber
6525
+ *
6526
+ * @param value
6527
+ *
6528
+ * @private utility for initializating UncertainNumber
6529
+ */
6530
+ function uncertainNumber(value) {
6531
+ if (value === null || value === undefined || Number.isNaN(value)) {
6532
+ return { value: 0, isUncertain: true };
6533
+ }
6534
+ return { value: value };
6535
+ }
6536
+
6537
+ /**
6538
+ * Get current date in ISO 8601 format
6539
+ *
6540
+ * @private internal utility
6541
+ */
6542
+ function getCurrentIsoDate() {
6543
+ return new Date().toISOString();
6544
+ }
6545
+
6546
+ /**
6547
+ * Function computeUsage will create price per one token based on the string value found on openai page
6548
+ *
6549
+ * @private within the repository, used only as internal helper for `OPENAI_MODELS`
6550
+ */
6551
+ function computeUsage(value) {
6552
+ var _a = __read(value.split(' / '), 2), price = _a[0], tokens = _a[1];
6553
+ return parseFloat(price.replace('$', '')) / parseFloat(tokens.replace('M tokens', '')) / 1000000;
6554
+ }
6555
+
6556
+ /**
6557
+ * List of available Anthropic Claude models with pricing
6558
+ *
6559
+ * Note: Done at 2024-05-25
6560
+ *
6561
+ * @see https://docs.anthropic.com/en/docs/models-overview
6562
+ * @public exported from `@promptbook/anthropic-claude`
6563
+ */
6564
+ var ANTHROPIC_CLAUDE_MODELS = [
6565
+ {
6566
+ modelVariant: 'CHAT',
6567
+ modelTitle: 'Claude 3 Opus',
6568
+ modelName: 'claude-3-opus-20240229',
6569
+ pricing: {
6570
+ prompt: computeUsage("$15.00 / 1M tokens"),
6571
+ output: computeUsage("$75.00 / 1M tokens"),
6572
+ },
6573
+ },
6574
+ {
6575
+ modelVariant: 'CHAT',
6576
+ modelTitle: 'Claude 3 Sonnet',
6577
+ modelName: 'claude-3-sonnet-20240229',
6578
+ pricing: {
6579
+ prompt: computeUsage("$3.00 / 1M tokens"),
6580
+ output: computeUsage("$15.00 / 1M tokens"),
6581
+ },
6582
+ },
6583
+ {
6584
+ modelVariant: 'CHAT',
6585
+ modelTitle: 'Claude 3 Haiku',
6586
+ modelName: ' claude-3-haiku-20240307',
6587
+ pricing: {
6588
+ prompt: computeUsage("$0.25 / 1M tokens"),
6589
+ output: computeUsage("$1.25 / 1M tokens"),
6590
+ },
6591
+ },
6592
+ {
6593
+ modelVariant: 'CHAT',
6594
+ modelTitle: 'Claude 2.1',
6595
+ modelName: 'claude-2.1',
6596
+ pricing: {
6597
+ prompt: computeUsage("$8.00 / 1M tokens"),
6598
+ output: computeUsage("$24.00 / 1M tokens"),
6599
+ },
6600
+ },
6601
+ {
6602
+ modelVariant: 'CHAT',
6603
+ modelTitle: 'Claude 2',
6604
+ modelName: 'claude-2.0',
6605
+ pricing: {
6606
+ prompt: computeUsage("$8.00 / 1M tokens"),
6607
+ output: computeUsage("$24.00 / 1M tokens"),
6608
+ },
6609
+ },
6610
+ {
6611
+ modelVariant: 'CHAT',
6612
+ modelTitle: ' Claude Instant 1.2',
6613
+ modelName: 'claude-instant-1.2',
6614
+ pricing: {
6615
+ prompt: computeUsage("$0.80 / 1M tokens"),
6616
+ output: computeUsage("$2.40 / 1M tokens"),
6617
+ },
6618
+ },
6619
+ // TODO: !!! Claude 1 and 2 has also completion versions - ask Hoagy
6620
+ ];
6621
+ /**
6622
+ * Note: [🤖] Add models of new variant
6623
+ * TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
6624
+ * TODO: [🧠] Some mechanism to propagate unsureness
6625
+ * TODO: [🧠][👮‍♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
6626
+ * TODO: [🕚] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
6627
+ */
6628
+
6629
+ /**
6630
+ * Execution Tools for calling Anthropic Claude API.
6631
+ *
6632
+ * @public exported from `@promptbook/anthropic-claude`
6633
+ */
6634
+ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6635
+ /**
6636
+ * Creates Anthropic Claude Execution Tools.
6637
+ *
6638
+ * @param options which are relevant are directly passed to the Anthropic Claude client
6639
+ */
6640
+ function AnthropicClaudeExecutionTools(options) {
6641
+ if (options === void 0) { options = {}; }
6642
+ this.options = options;
6643
+ // Note: Passing only Anthropic Claude relevant options to Anthropic constructor
6644
+ var anthropicOptions = __assign({}, options);
6645
+ delete anthropicOptions.isVerbose;
6646
+ this.client = new Anthropic__default["default"](anthropicOptions);
6647
+ }
6648
+ Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
6649
+ get: function () {
6650
+ return 'Anthropic Claude';
6651
+ },
6652
+ enumerable: false,
6653
+ configurable: true
6654
+ });
6655
+ Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "description", {
6656
+ get: function () {
6657
+ return 'Use all models provided by Anthropic Claude';
6658
+ },
6659
+ enumerable: false,
6660
+ configurable: true
6661
+ });
6662
+ /**
6663
+ * Calls Anthropic Claude API to use a chat model.
6664
+ */
6665
+ AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
6666
+ return __awaiter(this, void 0, void 0, function () {
6667
+ var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
6668
+ return __generator(this, function (_a) {
6669
+ switch (_a.label) {
6670
+ case 0:
6671
+ if (this.options.isVerbose) {
6672
+ console.info('💬 Anthropic Claude callChatModel call');
6673
+ }
6674
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
6675
+ // TODO: [☂] Use here more modelRequirements
6676
+ if (modelRequirements.modelVariant !== 'CHAT') {
6677
+ throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
6678
+ }
6679
+ modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6680
+ rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
6681
+ rawRequest = {
6682
+ model: modelRequirements.modelName || this.getDefaultChatModel().modelName,
6683
+ max_tokens: modelRequirements.maxTokens || 4096,
6684
+ // <- TODO: [🌾] Make some global max cap for maxTokens
6685
+ temperature: modelRequirements.temperature,
6686
+ system: modelRequirements.systemMessage,
6687
+ // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
6688
+ // <- Note: [🧆]
6689
+ messages: [
6690
+ {
6691
+ role: 'user',
6692
+ content: rawPromptContent,
6693
+ },
6694
+ ],
6695
+ // TODO: Is here some equivalent of user identification?> user: this.options.user,
6696
+ };
6697
+ start = getCurrentIsoDate();
6698
+ if (this.options.isVerbose) {
6699
+ console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
6700
+ }
6701
+ return [4 /*yield*/, this.client.messages.create(rawRequest)];
6702
+ case 1:
6703
+ rawResponse = _a.sent();
6704
+ if (this.options.isVerbose) {
6705
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
6706
+ }
6707
+ if (!rawResponse.content[0]) {
6708
+ throw new PipelineExecutionError('No content from Anthropic Claude');
6709
+ }
6710
+ if (rawResponse.content.length > 1) {
6711
+ throw new PipelineExecutionError('More than one content blocks from Anthropic Claude');
6712
+ }
6713
+ resultContent = rawResponse.content[0].text;
6714
+ // eslint-disable-next-line prefer-const
6715
+ complete = getCurrentIsoDate();
6716
+ usage = {
6717
+ price: { value: 0, isUncertain: true } /* <- TODO: [🐞] Compute usage */,
6718
+ input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(prompt.content)),
6719
+ output: __assign({ tokensCount: uncertainNumber(rawResponse.usage.output_tokens) }, computeUsageCounts(prompt.content)),
6720
+ };
6721
+ return [2 /*return*/, {
6722
+ content: resultContent,
6723
+ modelName: rawResponse.model,
6724
+ timing: {
6725
+ start: start,
6726
+ complete: complete,
6727
+ },
6728
+ usage: usage,
6729
+ rawPromptContent: rawPromptContent,
6730
+ rawRequest: rawRequest,
6731
+ rawResponse: rawResponse,
6732
+ // <- [🗯]
6733
+ }];
6734
+ }
6735
+ });
6736
+ });
6737
+ };
6738
+ /*
6739
+ TODO: [👏]
6740
+ public async callCompletionModel(
6741
+ prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>,
6742
+ ): Promise<PromptCompletionResult> {
6743
+
6744
+ if (this.options.isVerbose) {
6745
+ console.info('🖋 Anthropic Claude callCompletionModel call');
6746
+ }
6747
+
6748
+ const { content, parameters, modelRequirements } = prompt;
6749
+
6750
+ // TODO: [☂] Use here more modelRequirements
6751
+ if (modelRequirements.modelVariant !== 'COMPLETION') {
6752
+ throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
6753
+ }
6754
+
6755
+ const modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6756
+ const modelSettings = {
6757
+ model: modelName,
6758
+ max_tokens: modelRequirements.maxTokens || 2000, // <- Note: 2000 is for lagacy reasons
6759
+ // <- TODO: [🌾] Make some global max cap for maxTokens
6760
+ // <- TODO: Use here `systemMessage`, `temperature` and `seed`
6761
+ };
6762
+
6763
+ const rawRequest: xxxx.Completions.CompletionCreateParamsNonStreaming = {
6764
+ ...modelSettings,
6765
+ prompt: rawPromptContent,
6766
+ user: this.options.user,
6767
+ };
6768
+ const start: string_date_iso8601 = getCurrentIsoDate();
6769
+ let complete: string_date_iso8601;
6770
+
6771
+ if (this.options.isVerbose) {
6772
+ console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
6773
+ }
6774
+ const rawResponse = await this.client.completions.create(rawRequest);
6775
+ if (this.options.isVerbose) {
6776
+ console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
6777
+ }
6778
+
6779
+ if (!rawResponse.choices[0]) {
6780
+ throw new PipelineExecutionError('No choises from Anthropic Claude');
6781
+ }
6782
+
6783
+ if (rawResponse.choices.length > 1) {
6784
+ // TODO: This should be maybe only warning
6785
+ throw new PipelineExecutionError('More than one choise from Anthropic Claude');
6786
+ }
6787
+
6788
+ const resultContent = rawResponse.choices[0].text;
6789
+ // eslint-disable-next-line prefer-const
6790
+ complete = getCurrentIsoDate();
6791
+ const usage = { price: 'UNKNOWN', inputTokens: 0, outputTokens: 0 /* <- TODO: [🐞] Compute usage * / } satisfies PromptResultUsage;
6792
+
6793
+
6794
+
6795
+ return {
6796
+ content: resultContent,
6797
+ modelName: rawResponse.model || model,
6798
+ timing: {
6799
+ start,
6800
+ complete,
6801
+ },
6802
+ usage,
6803
+ rawResponse,
6804
+ // <- [🗯]
6805
+ };
6806
+ }
6807
+ */
6808
+ // <- Note: [🤖] callXxxModel
6809
+ /**
6810
+ * Get the model that should be used as default
6811
+ */
6812
+ AnthropicClaudeExecutionTools.prototype.getDefaultModel = function (defaultModelName) {
6813
+ var model = ANTHROPIC_CLAUDE_MODELS.find(function (_a) {
6814
+ var modelName = _a.modelName;
6815
+ return modelName.startsWith(defaultModelName);
6816
+ });
6817
+ if (model === undefined) {
6818
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) {
6819
+ return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(ANTHROPIC_CLAUDE_MODELS.map(function (_a) {
6820
+ var modelName = _a.modelName;
6821
+ return "- \"".concat(modelName, "\"");
6822
+ }).join('\n')), "\n\n ");
6823
+ }));
6824
+ }
6825
+ return model;
6826
+ };
6827
+ /**
6828
+ * Default model for chat variant.
6829
+ */
6830
+ AnthropicClaudeExecutionTools.prototype.getDefaultChatModel = function () {
6831
+ return this.getDefaultModel('claude-3-opus');
6832
+ };
6833
+ // <- Note: [🤖] getDefaultXxxModel
6834
+ /**
6835
+ * List all available Anthropic Claude models that can be used
6836
+ */
6837
+ AnthropicClaudeExecutionTools.prototype.listModels = function () {
6838
+ return ANTHROPIC_CLAUDE_MODELS;
6839
+ };
6840
+ return AnthropicClaudeExecutionTools;
6841
+ }());
6842
+ /**
6843
+ * TODO: [🍆] JSON mode
6844
+ * TODO: [🧠] Maybe handle errors via transformAnthropicError (like transformAzureError)
6845
+ * TODO: Maybe Create some common util for callChatModel and callCompletionModel
6846
+ * TODO: Maybe make custom OpenaiError
6847
+ * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
6848
+ * TODO: [🍜] Auto use anonymous server in browser
6849
+ * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
6850
+ */
6851
+
6852
+ /**
6853
+ * List of available OpenAI models with pricing
6854
+ *
6855
+ * Note: Done at 2024-05-20
6856
+ *
6857
+ * @see https://platform.openai.com/docs/models/
6858
+ * @see https://openai.com/api/pricing/
6859
+ * @public exported from `@promptbook/openai`
6860
+ */
6861
+ var OPENAI_MODELS = [
6862
+ /*/
6863
+ {
6864
+ modelTitle: 'dall-e-3',
6865
+ modelName: 'dall-e-3',
6866
+ },
6867
+ /**/
6868
+ /*/
6869
+ {
6870
+ modelTitle: 'whisper-1',
6871
+ modelName: 'whisper-1',
6872
+ },
6873
+ /**/
6874
+ /**/
6875
+ {
6876
+ modelVariant: 'COMPLETION',
6877
+ modelTitle: 'davinci-002',
6878
+ modelName: 'davinci-002',
6879
+ pricing: {
6880
+ prompt: computeUsage("$2.00 / 1M tokens"),
6881
+ output: computeUsage("$2.00 / 1M tokens"), // <- not sure
6882
+ },
6883
+ },
6884
+ /**/
6885
+ /*/
6886
+ {
6887
+ modelTitle: 'dall-e-2',
6888
+ modelName: 'dall-e-2',
6889
+ },
6890
+ /**/
6891
+ /**/
6892
+ {
6893
+ modelVariant: 'CHAT',
6894
+ modelTitle: 'gpt-3.5-turbo-16k',
6895
+ modelName: 'gpt-3.5-turbo-16k',
6896
+ pricing: {
6897
+ prompt: computeUsage("$3.00 / 1M tokens"),
6898
+ output: computeUsage("$4.00 / 1M tokens"),
6899
+ },
6900
+ },
6901
+ /**/
6902
+ /*/
6903
+ {
6904
+ modelTitle: 'tts-1-hd-1106',
6905
+ modelName: 'tts-1-hd-1106',
6906
+ },
6907
+ /**/
6908
+ /*/
6909
+ {
6910
+ modelTitle: 'tts-1-hd',
6911
+ modelName: 'tts-1-hd',
6912
+ },
6913
+ /**/
6914
+ /**/
6915
+ {
6916
+ modelVariant: 'CHAT',
6917
+ modelTitle: 'gpt-4',
6918
+ modelName: 'gpt-4',
6919
+ pricing: {
6920
+ prompt: computeUsage("$30.00 / 1M tokens"),
6921
+ output: computeUsage("$60.00 / 1M tokens"),
6922
+ },
6923
+ },
6924
+ /**/
6925
+ /**/
6926
+ {
6927
+ modelVariant: 'CHAT',
6928
+ modelTitle: 'gpt-4-32k',
6929
+ modelName: 'gpt-4-32k',
6930
+ pricing: {
6931
+ prompt: computeUsage("$60.00 / 1M tokens"),
6932
+ output: computeUsage("$120.00 / 1M tokens"),
6933
+ },
6934
+ },
6935
+ /**/
6936
+ /*/
6937
+ {
6938
+ modelVariant: 'CHAT',
6939
+ modelTitle: 'gpt-4-0613',
6940
+ modelName: 'gpt-4-0613',
6941
+ pricing: {
6942
+ prompt: computeUsage(` / 1M tokens`),
6943
+ output: computeUsage(` / 1M tokens`),
6944
+ },
6945
+ },
6946
+ /**/
6947
+ /**/
6948
+ {
6949
+ modelVariant: 'CHAT',
6950
+ modelTitle: 'gpt-4-turbo-2024-04-09',
6951
+ modelName: 'gpt-4-turbo-2024-04-09',
6952
+ pricing: {
6953
+ prompt: computeUsage("$10.00 / 1M tokens"),
6954
+ output: computeUsage("$30.00 / 1M tokens"),
6955
+ },
6956
+ },
6957
+ /**/
6958
+ /**/
6959
+ {
6960
+ modelVariant: 'CHAT',
6961
+ modelTitle: 'gpt-3.5-turbo-1106',
6962
+ modelName: 'gpt-3.5-turbo-1106',
6963
+ pricing: {
6964
+ prompt: computeUsage("$1.00 / 1M tokens"),
6965
+ output: computeUsage("$2.00 / 1M tokens"),
6966
+ },
6967
+ },
6968
+ /**/
6969
+ /**/
6970
+ {
6971
+ modelVariant: 'CHAT',
6972
+ modelTitle: 'gpt-4-turbo',
6973
+ modelName: 'gpt-4-turbo',
6974
+ pricing: {
6975
+ prompt: computeUsage("$10.00 / 1M tokens"),
6976
+ output: computeUsage("$30.00 / 1M tokens"),
6977
+ },
6978
+ },
6979
+ /**/
6980
+ /**/
6981
+ {
6982
+ modelVariant: 'COMPLETION',
6983
+ modelTitle: 'gpt-3.5-turbo-instruct-0914',
6984
+ modelName: 'gpt-3.5-turbo-instruct-0914',
6985
+ pricing: {
6986
+ prompt: computeUsage("$1.50 / 1M tokens"),
6987
+ output: computeUsage("$2.00 / 1M tokens"), // <- For gpt-3.5-turbo-instruct
6988
+ },
6989
+ },
6990
+ /**/
6991
+ /**/
6992
+ {
6993
+ modelVariant: 'COMPLETION',
6994
+ modelTitle: 'gpt-3.5-turbo-instruct',
6995
+ modelName: 'gpt-3.5-turbo-instruct',
6996
+ pricing: {
6997
+ prompt: computeUsage("$1.50 / 1M tokens"),
6998
+ output: computeUsage("$2.00 / 1M tokens"),
6999
+ },
7000
+ },
7001
+ /**/
7002
+ /*/
7003
+ {
7004
+ modelTitle: 'tts-1',
7005
+ modelName: 'tts-1',
7006
+ },
7007
+ /**/
7008
+ /**/
7009
+ {
7010
+ modelVariant: 'CHAT',
7011
+ modelTitle: 'gpt-3.5-turbo',
7012
+ modelName: 'gpt-3.5-turbo',
7013
+ pricing: {
7014
+ prompt: computeUsage("$3.00 / 1M tokens"),
7015
+ output: computeUsage("$6.00 / 1M tokens"), // <- Not sure, refer to gpt-3.5-turbo in Fine-tuning models
7016
+ },
7017
+ },
7018
+ /**/
7019
+ /**/
7020
+ {
7021
+ modelVariant: 'CHAT',
7022
+ modelTitle: 'gpt-3.5-turbo-0301',
7023
+ modelName: 'gpt-3.5-turbo-0301',
7024
+ pricing: {
7025
+ prompt: computeUsage("$1.50 / 1M tokens"),
7026
+ output: computeUsage("$2.00 / 1M tokens"),
7027
+ },
7028
+ },
7029
+ /**/
7030
+ /**/
7031
+ {
7032
+ modelVariant: 'COMPLETION',
7033
+ modelTitle: 'babbage-002',
7034
+ modelName: 'babbage-002',
7035
+ pricing: {
7036
+ prompt: computeUsage("$0.40 / 1M tokens"),
7037
+ output: computeUsage("$0.40 / 1M tokens"), // <- Not sure
7038
+ },
7039
+ },
7040
+ /**/
7041
+ /**/
7042
+ {
7043
+ modelVariant: 'CHAT',
7044
+ modelTitle: 'gpt-4-1106-preview',
7045
+ modelName: 'gpt-4-1106-preview',
7046
+ pricing: {
7047
+ prompt: computeUsage("$10.00 / 1M tokens"),
7048
+ output: computeUsage("$30.00 / 1M tokens"),
7049
+ },
7050
+ },
7051
+ /**/
7052
+ /**/
7053
+ {
7054
+ modelVariant: 'CHAT',
7055
+ modelTitle: 'gpt-4-0125-preview',
7056
+ modelName: 'gpt-4-0125-preview',
7057
+ pricing: {
7058
+ prompt: computeUsage("$10.00 / 1M tokens"),
7059
+ output: computeUsage("$30.00 / 1M tokens"),
7060
+ },
7061
+ },
7062
+ /**/
7063
+ /*/
7064
+ {
7065
+ modelTitle: 'tts-1-1106',
7066
+ modelName: 'tts-1-1106',
7067
+ },
7068
+ /**/
7069
+ /**/
7070
+ {
7071
+ modelVariant: 'CHAT',
7072
+ modelTitle: 'gpt-3.5-turbo-0125',
7073
+ modelName: 'gpt-3.5-turbo-0125',
7074
+ pricing: {
7075
+ prompt: computeUsage("$0.50 / 1M tokens"),
7076
+ output: computeUsage("$1.50 / 1M tokens"),
7077
+ },
7078
+ },
7079
+ /**/
7080
+ /**/
7081
+ {
7082
+ modelVariant: 'CHAT',
7083
+ modelTitle: 'gpt-4-turbo-preview',
7084
+ modelName: 'gpt-4-turbo-preview',
7085
+ pricing: {
7086
+ prompt: computeUsage("$10.00 / 1M tokens"),
7087
+ output: computeUsage("$30.00 / 1M tokens"), // <- Not sure, just for gpt-4-turbo
7088
+ },
7089
+ },
7090
+ /**/
7091
+ /**/
7092
+ {
7093
+ modelVariant: 'EMBEDDING',
7094
+ modelTitle: 'text-embedding-3-large',
7095
+ modelName: 'text-embedding-3-large',
7096
+ pricing: {
7097
+ prompt: computeUsage("$0.13 / 1M tokens"),
7098
+ // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
7099
+ output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
7100
+ },
7101
+ },
7102
+ /**/
7103
+ /**/
7104
+ {
7105
+ modelVariant: 'EMBEDDING',
7106
+ modelTitle: 'text-embedding-3-small',
7107
+ modelName: 'text-embedding-3-small',
7108
+ pricing: {
7109
+ prompt: computeUsage("$0.02 / 1M tokens"),
7110
+ // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
7111
+ output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
7112
+ },
7113
+ },
7114
+ /**/
7115
+ /**/
7116
+ {
7117
+ modelVariant: 'CHAT',
7118
+ modelTitle: 'gpt-3.5-turbo-0613',
7119
+ modelName: 'gpt-3.5-turbo-0613',
7120
+ pricing: {
7121
+ prompt: computeUsage("$1.50 / 1M tokens"),
7122
+ output: computeUsage("$2.00 / 1M tokens"),
7123
+ },
7124
+ },
7125
+ /**/
7126
+ /**/
7127
+ {
7128
+ modelVariant: 'EMBEDDING',
7129
+ modelTitle: 'text-embedding-ada-002',
7130
+ modelName: 'text-embedding-ada-002',
7131
+ pricing: {
7132
+ prompt: computeUsage("$0.1 / 1M tokens"),
7133
+ // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
7134
+ output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
7135
+ },
7136
+ },
7137
+ /**/
7138
+ /*/
7139
+ {
7140
+ modelVariant: 'CHAT',
7141
+ modelTitle: 'gpt-4-1106-vision-preview',
7142
+ modelName: 'gpt-4-1106-vision-preview',
7143
+ },
7144
+ /**/
7145
+ /*/
7146
+ {
7147
+ modelVariant: 'CHAT',
7148
+ modelTitle: 'gpt-4-vision-preview',
7149
+ modelName: 'gpt-4-vision-preview',
7150
+ pricing: {
7151
+ prompt: computeUsage(`$10.00 / 1M tokens`),
7152
+ output: computeUsage(`$30.00 / 1M tokens`),
7153
+ },
7154
+ },
7155
+ /**/
7156
+ /**/
7157
+ {
7158
+ modelVariant: 'CHAT',
7159
+ modelTitle: 'gpt-4o-2024-05-13',
7160
+ modelName: 'gpt-4o-2024-05-13',
7161
+ pricing: {
7162
+ prompt: computeUsage("$5.00 / 1M tokens"),
7163
+ output: computeUsage("$15.00 / 1M tokens"),
7164
+ },
7165
+ },
7166
+ /**/
7167
+ /**/
7168
+ {
7169
+ modelVariant: 'CHAT',
7170
+ modelTitle: 'gpt-4o',
7171
+ modelName: 'gpt-4o',
7172
+ pricing: {
7173
+ prompt: computeUsage("$5.00 / 1M tokens"),
7174
+ output: computeUsage("$15.00 / 1M tokens"),
7175
+ },
7176
+ },
7177
+ /**/
7178
+ /**/
7179
+ {
7180
+ modelVariant: 'CHAT',
7181
+ modelTitle: 'gpt-3.5-turbo-16k-0613',
7182
+ modelName: 'gpt-3.5-turbo-16k-0613',
7183
+ pricing: {
7184
+ prompt: computeUsage("$3.00 / 1M tokens"),
7185
+ output: computeUsage("$4.00 / 1M tokens"),
7186
+ },
7187
+ },
7188
+ /**/
7189
+ ];
7190
+ /**
7191
+ * Note: [🤖] Add models of new variant
7192
+ * TODO: [🧠] Some mechanism to propagate unsureness
7193
+ * TODO: [🕚][👮‍♀️] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
7194
+ * TODO: [🧠][👮‍♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
7195
+ * @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
7196
+ * @see https://openai.com/api/pricing/
7197
+ * @see /other/playground/playground.ts
7198
+ * TODO: [🍓] Make better
7199
+ * TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
7200
+ * TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
7201
+ */
7202
+
7203
+ /**
7204
+ * Execution Tools for calling Azure OpenAI API.
7205
+ *
7206
+ * @public exported from `@promptbook/azure-openai`
7207
+ */
7208
+ var AzureOpenAiExecutionTools = /** @class */ (function () {
7209
+ /**
7210
+ * Creates OpenAI Execution Tools.
7211
+ *
7212
+ * @param options which are relevant are directly passed to the OpenAI client
7213
+ */
7214
+ function AzureOpenAiExecutionTools(options) {
7215
+ this.options = options;
7216
+ this.client = new openai.OpenAIClient("https://".concat(options.resourceName, ".openai.azure.com/"), new openai.AzureKeyCredential(options.apiKey));
7217
+ }
7218
+ Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
7219
+ get: function () {
7220
+ return 'Azure OpenAI';
7221
+ },
7222
+ enumerable: false,
7223
+ configurable: true
7224
+ });
7225
+ Object.defineProperty(AzureOpenAiExecutionTools.prototype, "description", {
7226
+ get: function () {
7227
+ return 'Use all models trained by OpenAI provided by Azure';
7228
+ },
7229
+ enumerable: false,
7230
+ configurable: true
7231
+ });
7232
+ /**
7233
+ * Calls OpenAI API to use a chat model.
7234
+ */
7235
+ AzureOpenAiExecutionTools.prototype.callChatModel = function (prompt) {
7236
+ var _a, _b;
7237
+ return __awaiter(this, void 0, void 0, function () {
7238
+ var content, parameters, modelRequirements, modelName, modelSettings, rawPromptContent, messages, start, complete, rawRequest, rawResponse, resultContent, usage, error_1;
7239
+ var _c;
7240
+ return __generator(this, function (_d) {
7241
+ switch (_d.label) {
7242
+ case 0:
7243
+ if (this.options.isVerbose) {
7244
+ console.info('💬 OpenAI callChatModel call');
7245
+ }
7246
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
7247
+ // TODO: [☂] Use here more modelRequirements
7248
+ if (modelRequirements.modelVariant !== 'CHAT') {
7249
+ throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
7250
+ }
7251
+ _d.label = 1;
7252
+ case 1:
7253
+ _d.trys.push([1, 3, , 4]);
7254
+ modelName = prompt.modelRequirements.modelName || this.options.deploymentName;
7255
+ modelSettings = {
7256
+ maxTokens: modelRequirements.maxTokens,
7257
+ // <- TODO: [🌾] Make some global max cap for maxTokens
7258
+ temperature: modelRequirements.temperature,
7259
+ user: this.options.user,
7260
+ // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
7261
+ // <- Note: [🧆]
7262
+ };
7263
+ rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
7264
+ messages = __spreadArray(__spreadArray([], __read((modelRequirements.systemMessage === undefined
7265
+ ? []
7266
+ : [
7267
+ {
7268
+ role: 'system',
7269
+ content: modelRequirements.systemMessage,
7270
+ },
7271
+ ])), false), [
7272
+ {
7273
+ role: 'user',
7274
+ content: rawPromptContent,
7275
+ },
7276
+ ], false);
7277
+ start = getCurrentIsoDate();
7278
+ complete = void 0;
7279
+ if (this.options.isVerbose) {
7280
+ console.info(colors__default["default"].bgWhite('messages'), JSON.stringify(messages, null, 4));
7281
+ }
7282
+ rawRequest = [modelName, messages, modelSettings];
7283
+ return [4 /*yield*/, (_c = this.client).getChatCompletions.apply(_c, __spreadArray([], __read(rawRequest), false))];
7284
+ case 2:
7285
+ rawResponse = _d.sent();
7286
+ if (this.options.isVerbose) {
7287
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
7288
+ }
7289
+ if (!rawResponse.choices[0]) {
7290
+ throw new PipelineExecutionError('No choises from Azure OpenAI');
7291
+ }
7292
+ if (rawResponse.choices.length > 1) {
7293
+ // TODO: This should be maybe only warning
7294
+ throw new PipelineExecutionError('More than one choise from Azure OpenAI');
7295
+ }
7296
+ if (!rawResponse.choices[0].message || !rawResponse.choices[0].message.content) {
7297
+ throw new PipelineExecutionError('Empty response from Azure OpenAI');
7298
+ }
7299
+ resultContent = rawResponse.choices[0].message.content;
7300
+ // eslint-disable-next-line prefer-const
7301
+ complete = getCurrentIsoDate();
7302
+ usage = {
7303
+ price: uncertainNumber() /* <- TODO: [🐞] Compute usage */,
7304
+ input: __assign({ tokensCount: uncertainNumber((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.promptTokens) }, computeUsageCounts(prompt.content)),
7305
+ output: __assign({ tokensCount: uncertainNumber((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completionTokens) }, computeUsageCounts(prompt.content)),
7306
+ };
7307
+ return [2 /*return*/, {
7308
+ content: resultContent,
7309
+ modelName: modelName,
7310
+ timing: {
7311
+ start: start,
7312
+ complete: complete,
7313
+ },
7314
+ usage: usage,
7315
+ rawPromptContent: rawPromptContent,
7316
+ rawRequest: rawRequest,
7317
+ rawResponse: rawResponse,
7318
+ // <- [🗯]
7319
+ }];
7320
+ case 3:
7321
+ error_1 = _d.sent();
7322
+ throw this.transformAzureError(error_1);
7323
+ case 4: return [2 /*return*/];
7324
+ }
7325
+ });
7326
+ });
7327
+ };
7328
+ /**
7329
+ * Calls Azure OpenAI API to use a complete model.
7330
+ */
7331
+ AzureOpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
7332
+ var _a, _b;
7333
+ return __awaiter(this, void 0, void 0, function () {
7334
+ var content, parameters, modelRequirements, modelName, modelSettings, start, complete, rawPromptContent, rawRequest, rawResponse, resultContent, usage, error_2;
7335
+ var _c;
7336
+ return __generator(this, function (_d) {
7337
+ switch (_d.label) {
7338
+ case 0:
7339
+ if (this.options.isVerbose) {
7340
+ console.info('🖋 OpenAI callCompletionModel call');
7341
+ }
7342
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
7343
+ // TODO: [☂] Use here more modelRequirements
7344
+ if (modelRequirements.modelVariant !== 'COMPLETION') {
7345
+ throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
7346
+ }
7347
+ _d.label = 1;
7348
+ case 1:
7349
+ _d.trys.push([1, 3, , 4]);
7350
+ modelName = prompt.modelRequirements.modelName || this.options.deploymentName;
7351
+ modelSettings = {
7352
+ maxTokens: modelRequirements.maxTokens || 2000,
7353
+ // <- TODO: [🌾] Make some global max cap for maxTokens
7354
+ temperature: modelRequirements.temperature,
7355
+ user: this.options.user,
7356
+ // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
7357
+ // <- Note: [🧆]
7358
+ };
7359
+ start = getCurrentIsoDate();
7360
+ complete = void 0;
7361
+ if (this.options.isVerbose) {
7362
+ console.info(colors__default["default"].bgWhite('content'), JSON.stringify(content, null, 4));
7363
+ console.info(colors__default["default"].bgWhite('parameters'), JSON.stringify(parameters, null, 4));
7364
+ }
7365
+ rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
7366
+ rawRequest = [
7367
+ modelName,
7368
+ [rawPromptContent],
7369
+ modelSettings,
7370
+ ];
7371
+ return [4 /*yield*/, (_c = this.client).getCompletions.apply(_c, __spreadArray([], __read(rawRequest), false))];
7372
+ case 2:
7373
+ rawResponse = _d.sent();
7374
+ if (this.options.isVerbose) {
7375
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
7376
+ }
7377
+ if (!rawResponse.choices[0]) {
7378
+ throw new PipelineExecutionError('No choises from OpenAI');
7379
+ }
7380
+ if (rawResponse.choices.length > 1) {
7381
+ // TODO: This should be maybe only warning
7382
+ throw new PipelineExecutionError('More than one choise from OpenAI');
7383
+ }
7384
+ resultContent = rawResponse.choices[0].text;
7385
+ // eslint-disable-next-line prefer-const
7386
+ complete = getCurrentIsoDate();
7387
+ usage = {
7388
+ price: uncertainNumber() /* <- TODO: [🐞] Compute usage */,
7389
+ input: __assign({ tokensCount: uncertainNumber((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.promptTokens) }, computeUsageCounts(prompt.content)),
7390
+ output: __assign({ tokensCount: uncertainNumber((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completionTokens) }, computeUsageCounts(prompt.content)),
7391
+ };
7392
+ return [2 /*return*/, {
7393
+ content: resultContent,
7394
+ modelName: modelName,
7395
+ timing: {
7396
+ start: start,
7397
+ complete: complete,
7398
+ },
7399
+ usage: usage,
7400
+ rawPromptContent: rawPromptContent,
7401
+ rawRequest: rawRequest,
7402
+ rawResponse: rawResponse,
7403
+ // <- [🗯]
7404
+ }];
7405
+ case 3:
7406
+ error_2 = _d.sent();
7407
+ throw this.transformAzureError(error_2);
7408
+ case 4: return [2 /*return*/];
7409
+ }
7410
+ });
7411
+ });
7412
+ };
7413
+ // <- Note: [🤖] callXxxModel
7414
+ /**
7415
+ * Changes Azure error (which is not propper Error but object) to propper Error
7416
+ */
7417
+ AzureOpenAiExecutionTools.prototype.transformAzureError = function (azureError) {
7418
+ if (typeof azureError !== 'object' || azureError === null) {
7419
+ return new PipelineExecutionError("Unknown Azure OpenAI error");
7420
+ }
7421
+ var code = azureError.code, message = azureError.message;
7422
+ return new PipelineExecutionError("".concat(code, ": ").concat(message));
7423
+ };
7424
+ /**
7425
+ * List all available Azure OpenAI models that can be used
7426
+ */
7427
+ AzureOpenAiExecutionTools.prototype.listModels = function () {
7428
+ return __awaiter(this, void 0, void 0, function () {
7429
+ return __generator(this, function (_a) {
7430
+ // TODO: !!! Do here some filtering which models are really available as deployment
7431
+ // @see https://management.azure.com/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.CognitiveServices/accounts/accountName/deployments?api-version=2023-05-01
7432
+ return [2 /*return*/, OPENAI_MODELS.map(function (_a) {
7433
+ var modelTitle = _a.modelTitle, modelName = _a.modelName, modelVariant = _a.modelVariant;
7434
+ return ({
7435
+ modelTitle: "Azure ".concat(modelTitle),
7436
+ modelName: modelName,
7437
+ modelVariant: modelVariant,
7438
+ });
7439
+ })];
7440
+ });
7441
+ });
7442
+ };
7443
+ return AzureOpenAiExecutionTools;
7444
+ }());
7445
+ /**
7446
+ * TODO: Maybe Create some common util for callChatModel and callCompletionModel
7447
+ * TODO: Maybe make custom AzureOpenaiError
7448
+ * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
7449
+ * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
7450
+ */
7451
+
7452
+ /**
7453
+ * Computes the usage of the OpenAI API based on the response from OpenAI
7454
+ *
7455
+ * @param promptContent The content of the prompt
7456
+ * @param resultContent The content of the result (for embedding prompts or failed prompts pass empty string)
7457
+ * @param rawResponse The raw response from OpenAI API
7458
+ * @throws {PipelineExecutionError} If the usage is not defined in the response from OpenAI
7459
+ * @private internal utility of `OpenAiExecutionTools`
7460
+ */
7461
+ function computeOpenaiUsage(promptContent, // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
7462
+ resultContent, rawResponse) {
7463
+ var _a, _b;
7464
+ if (rawResponse.usage === undefined) {
7465
+ throw new PipelineExecutionError('The usage is not defined in the response from OpenAI');
7466
+ }
7467
+ if (((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.prompt_tokens) === undefined) {
7468
+ throw new PipelineExecutionError('In OpenAI response `usage.prompt_tokens` not defined');
7469
+ }
7470
+ var inputTokens = rawResponse.usage.prompt_tokens;
7471
+ var outputTokens = ((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completion_tokens) || 0;
7472
+ var modelInfo = OPENAI_MODELS.find(function (model) { return model.modelName === rawResponse.model; });
7473
+ var price;
7474
+ if (modelInfo === undefined || modelInfo.pricing === undefined) {
7475
+ price = uncertainNumber();
7476
+ }
7477
+ else {
7478
+ price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output);
7479
+ }
7480
+ return {
7481
+ price: price,
7482
+ input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.prompt_tokens) }, computeUsageCounts(promptContent)),
7483
+ output: __assign({ tokensCount: uncertainNumber(outputTokens) }, computeUsageCounts(resultContent)),
7484
+ };
7485
+ }
7486
+
7487
+ /**
7488
+ * Execution Tools for calling OpenAI API.
7489
+ *
7490
+ * @public exported from `@promptbook/openai`
7491
+ */
7492
+ var OpenAiExecutionTools = /** @class */ (function () {
7493
+ /**
7494
+ * Creates OpenAI Execution Tools.
7495
+ *
7496
+ * @param options which are relevant are directly passed to the OpenAI client
7497
+ */
7498
+ function OpenAiExecutionTools(options) {
7499
+ if (options === void 0) { options = {}; }
7500
+ this.options = options;
7501
+ // Note: Passing only OpenAI relevant options to OpenAI constructor
7502
+ var openAiOptions = __assign({}, options);
7503
+ delete openAiOptions.isVerbose;
7504
+ delete openAiOptions.user;
7505
+ this.client = new OpenAI__default["default"](__assign({}, openAiOptions));
7506
+ }
7507
+ Object.defineProperty(OpenAiExecutionTools.prototype, "title", {
7508
+ get: function () {
7509
+ return 'OpenAI';
7510
+ },
7511
+ enumerable: false,
7512
+ configurable: true
7513
+ });
7514
+ Object.defineProperty(OpenAiExecutionTools.prototype, "description", {
7515
+ get: function () {
7516
+ return 'Use all models provided by OpenAI';
7517
+ },
7518
+ enumerable: false,
7519
+ configurable: true
7520
+ });
7521
+ /**
7522
+ * Calls OpenAI API to use a chat model.
7523
+ */
7524
+ OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
7525
+ return __awaiter(this, void 0, void 0, function () {
7526
+ var content, parameters, modelRequirements, expectFormat, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
7527
+ return __generator(this, function (_a) {
7528
+ switch (_a.label) {
7529
+ case 0:
7530
+ if (this.options.isVerbose) {
7531
+ console.info('💬 OpenAI callChatModel call', { prompt: prompt });
7532
+ }
7533
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements, expectFormat = prompt.expectFormat;
7534
+ // TODO: [☂] Use here more modelRequirements
7535
+ if (modelRequirements.modelVariant !== 'CHAT') {
7536
+ throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
7537
+ }
7538
+ modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
7539
+ modelSettings = {
7540
+ model: modelName,
7541
+ max_tokens: modelRequirements.maxTokens,
7542
+ // <- TODO: [🌾] Make some global max cap for maxTokens
7543
+ temperature: modelRequirements.temperature,
7544
+ // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
7545
+ // <- Note: [🧆]
7546
+ };
7547
+ if (expectFormat === 'JSON') {
7548
+ modelSettings.response_format = {
7549
+ type: 'json_object',
7550
+ };
7551
+ }
7552
+ rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
7553
+ rawRequest = __assign(__assign({}, modelSettings), { messages: __spreadArray(__spreadArray([], __read((modelRequirements.systemMessage === undefined
7554
+ ? []
7555
+ : [
7556
+ {
7557
+ role: 'system',
7558
+ content: modelRequirements.systemMessage,
7559
+ },
7560
+ ])), false), [
7561
+ {
7562
+ role: 'user',
7563
+ content: rawPromptContent,
7564
+ },
7565
+ ], false), user: this.options.user });
7566
+ start = getCurrentIsoDate();
7567
+ if (this.options.isVerbose) {
7568
+ console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
7569
+ }
7570
+ return [4 /*yield*/, this.client.chat.completions.create(rawRequest)];
7571
+ case 1:
7572
+ rawResponse = _a.sent();
7573
+ if (this.options.isVerbose) {
7574
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
7575
+ }
7576
+ if (!rawResponse.choices[0]) {
7577
+ throw new PipelineExecutionError('No choises from OpenAI');
7578
+ }
7579
+ if (rawResponse.choices.length > 1) {
7580
+ // TODO: This should be maybe only warning
7581
+ throw new PipelineExecutionError('More than one choise from OpenAI');
7582
+ }
7583
+ resultContent = rawResponse.choices[0].message.content;
7584
+ // eslint-disable-next-line prefer-const
7585
+ complete = getCurrentIsoDate();
7586
+ usage = computeOpenaiUsage(content, resultContent || '', rawResponse);
7587
+ if (resultContent === null) {
7588
+ throw new PipelineExecutionError('No response message from OpenAI');
7589
+ }
7590
+ return [2 /*return*/, {
7591
+ content: resultContent,
7592
+ modelName: rawResponse.model || modelName,
7593
+ timing: {
7594
+ start: start,
7595
+ complete: complete,
7596
+ },
7597
+ usage: usage,
7598
+ rawPromptContent: rawPromptContent,
7599
+ rawRequest: rawRequest,
7600
+ rawResponse: rawResponse,
7601
+ // <- [🗯]
7602
+ }];
7603
+ }
7604
+ });
7605
+ });
7606
+ };
7607
+ /**
7608
+ * Calls OpenAI API to use a complete model.
7609
+ */
7610
+ OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
7611
+ return __awaiter(this, void 0, void 0, function () {
7612
+ var content, parameters, modelRequirements, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
7613
+ return __generator(this, function (_a) {
7614
+ switch (_a.label) {
7615
+ case 0:
7616
+ if (this.options.isVerbose) {
7617
+ console.info('🖋 OpenAI callCompletionModel call', { prompt: prompt });
7618
+ }
7619
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
7620
+ // TODO: [☂] Use here more modelRequirements
7621
+ if (modelRequirements.modelVariant !== 'COMPLETION') {
7622
+ throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
7623
+ }
7624
+ modelName = modelRequirements.modelName || this.getDefaultCompletionModel().modelName;
7625
+ modelSettings = {
7626
+ model: modelName,
7627
+ max_tokens: modelRequirements.maxTokens || 2000,
7628
+ // <- TODO: [🌾] Make some global max cap for maxTokens
7629
+ temperature: modelRequirements.temperature,
7630
+ // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
7631
+ // <- Note: [🧆]
7632
+ };
7633
+ rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
7634
+ rawRequest = __assign(__assign({}, modelSettings), { prompt: rawPromptContent, user: this.options.user });
7635
+ start = getCurrentIsoDate();
7636
+ if (this.options.isVerbose) {
7637
+ console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
7638
+ }
7639
+ return [4 /*yield*/, this.client.completions.create(rawRequest)];
7640
+ case 1:
7641
+ rawResponse = _a.sent();
7642
+ if (this.options.isVerbose) {
7643
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
7644
+ }
7645
+ if (!rawResponse.choices[0]) {
7646
+ throw new PipelineExecutionError('No choises from OpenAI');
7647
+ }
7648
+ if (rawResponse.choices.length > 1) {
7649
+ // TODO: This should be maybe only warning
7650
+ throw new PipelineExecutionError('More than one choise from OpenAI');
7651
+ }
7652
+ resultContent = rawResponse.choices[0].text;
7653
+ // eslint-disable-next-line prefer-const
7654
+ complete = getCurrentIsoDate();
7655
+ usage = computeOpenaiUsage(content, resultContent || '', rawResponse);
7656
+ return [2 /*return*/, {
7657
+ content: resultContent,
7658
+ modelName: rawResponse.model || modelName,
7659
+ timing: {
7660
+ start: start,
7661
+ complete: complete,
7662
+ },
7663
+ usage: usage,
7664
+ rawPromptContent: rawPromptContent,
7665
+ rawRequest: rawRequest,
7666
+ rawResponse: rawResponse,
7667
+ // <- [🗯]
7668
+ }];
7669
+ }
7670
+ });
7671
+ });
7672
+ };
7673
+ /**
7674
+ * Calls OpenAI API to use a embedding model
7675
+ */
7676
+ OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
7677
+ return __awaiter(this, void 0, void 0, function () {
7678
+ var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
7679
+ return __generator(this, function (_a) {
7680
+ switch (_a.label) {
7681
+ case 0:
7682
+ if (this.options.isVerbose) {
7683
+ console.info('🖋 OpenAI embedding call', { prompt: prompt });
7684
+ }
7685
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
7686
+ // TODO: [☂] Use here more modelRequirements
7687
+ if (modelRequirements.modelVariant !== 'EMBEDDING') {
7688
+ throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
7689
+ }
7690
+ modelName = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
7691
+ rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
7692
+ rawRequest = {
7693
+ input: rawPromptContent,
7694
+ model: modelName,
7695
+ };
7696
+ start = getCurrentIsoDate();
7697
+ if (this.options.isVerbose) {
7698
+ console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
7699
+ }
7700
+ return [4 /*yield*/, this.client.embeddings.create(rawRequest)];
7701
+ case 1:
7702
+ rawResponse = _a.sent();
7703
+ if (this.options.isVerbose) {
7704
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
7705
+ }
7706
+ if (rawResponse.data.length !== 1) {
7707
+ throw new PipelineExecutionError("Expected exactly 1 data item in response, got ".concat(rawResponse.data.length));
7708
+ }
7709
+ resultContent = rawResponse.data[0].embedding;
7710
+ // eslint-disable-next-line prefer-const
7711
+ complete = getCurrentIsoDate();
7712
+ usage = computeOpenaiUsage(content, '', rawResponse);
7713
+ return [2 /*return*/, {
7714
+ content: resultContent,
7715
+ modelName: rawResponse.model || modelName,
7716
+ timing: {
7717
+ start: start,
7718
+ complete: complete,
7719
+ },
7720
+ usage: usage,
7721
+ rawPromptContent: rawPromptContent,
7722
+ rawRequest: rawRequest,
7723
+ rawResponse: rawResponse,
7724
+ // <- [🗯]
7725
+ }];
7726
+ }
7727
+ });
7728
+ });
7729
+ };
7730
+ // <- Note: [🤖] callXxxModel
7731
+ /**
7732
+ * Get the model that should be used as default
7733
+ */
7734
+ OpenAiExecutionTools.prototype.getDefaultModel = function (defaultModelName) {
7735
+ var model = OPENAI_MODELS.find(function (_a) {
7736
+ var modelName = _a.modelName;
7737
+ return modelName === defaultModelName;
7738
+ });
7739
+ if (model === undefined) {
7740
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) {
7741
+ return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(OPENAI_MODELS.map(function (_a) {
7742
+ var modelName = _a.modelName;
7743
+ return "- \"".concat(modelName, "\"");
7744
+ }).join('\n')), "\n\n ");
7745
+ }));
7746
+ }
7747
+ return model;
7748
+ };
7749
+ /**
7750
+ * Default model for chat variant.
7751
+ */
7752
+ OpenAiExecutionTools.prototype.getDefaultChatModel = function () {
7753
+ return this.getDefaultModel('gpt-4o');
7754
+ };
7755
+ /**
7756
+ * Default model for completion variant.
7757
+ */
7758
+ OpenAiExecutionTools.prototype.getDefaultCompletionModel = function () {
7759
+ return this.getDefaultModel('gpt-3.5-turbo-instruct');
7760
+ };
7761
+ /**
7762
+ * Default model for completion variant.
7763
+ */
7764
+ OpenAiExecutionTools.prototype.getDefaultEmbeddingModel = function () {
7765
+ return this.getDefaultModel('text-embedding-3-large');
7766
+ };
7767
+ // <- Note: [🤖] getDefaultXxxModel
7768
+ /**
7769
+ * List all available OpenAI models that can be used
7770
+ */
7771
+ OpenAiExecutionTools.prototype.listModels = function () {
7772
+ /*
7773
+ Note: Dynamic lising of the models
7774
+ const models = await this.openai.models.list({});
7775
+
7776
+ console.log({ models });
7777
+ console.log(models.data);
7778
+ */
7779
+ return OPENAI_MODELS;
7780
+ };
7781
+ return OpenAiExecutionTools;
7782
+ }());
7783
+ /**
7784
+ * TODO: [🧠][🧙‍♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
7785
+ * TODO: Maybe Create some common util for callChatModel and callCompletionModel
7786
+ * TODO: Maybe make custom OpenaiError
7787
+ * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
7788
+ * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
7789
+ */
7790
+
7791
+ /**
7792
+ * @private internal type for `createLlmToolsFromConfiguration`
7793
+ */
7794
+ var EXECUTION_TOOLS_CLASSES = {
7795
+ getOpenAiExecutionTools: function (options) {
7796
+ return new OpenAiExecutionTools(__assign(__assign({}, options), { dangerouslyAllowBrowser: true /* <- TODO: [🧠] !!! Some mechanism for auto-detection of browser, maybe hide in `OpenAiExecutionTools` */ }));
7797
+ },
7798
+ getAnthropicClaudeExecutionTools: function (options) { return new AnthropicClaudeExecutionTools(options); },
7799
+ getAzureOpenAiExecutionTools: function (options) { return new AzureOpenAiExecutionTools(options); },
7800
+ // <- Note: [🦑] Add here new LLM provider
7801
+ };
7802
+ /**
7803
+ * TODO: [🧠] Better file name than `config.ts` + maybe move to two separate files
7804
+ * TODO: [🧠][🎌] Adding this should be responsibility of each provider package NOT this one central place
7805
+ */
7806
+
7807
+ /**
7808
+ * @@@
7809
+ *
7810
+ * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
7811
+ *
7812
+ * @returns @@@
7813
+ * @public exported from `@promptbook/core`
7814
+ */
7815
+ function createLlmToolsFromConfiguration(configuration, options) {
7816
+ if (options === void 0) { options = {}; }
7817
+ var _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
7818
+ dotenv__namespace.config();
7819
+ var llmTools = configuration.map(function (llmConfiguration) {
7820
+ return EXECUTION_TOOLS_CLASSES["get".concat(llmConfiguration.className)](__assign({ isVerbose: isVerbose }, llmConfiguration.options));
7821
+ });
7822
+ return joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(llmTools), false));
7823
+ }
7824
+ /**
7825
+ * TODO: [🎌] Togethere with `createLlmToolsFromConfiguration` + 'EXECUTION_TOOLS_CLASSES' gets to `@promptbook/core` ALL model providers, make this more efficient
7826
+ * TODO: [🧠][🎌] Dynamically install required providers
7827
+ * TODO: @@@ write discussion about this - wizzard
7828
+ * TODO: [🧠][🍛] Which name is better `createLlmToolsFromConfig` or `createLlmToolsFromConfiguration`?
7829
+ * TODO: [🧠] Is there some meaningfull way how to test this util
7830
+ * TODO: This should be maybe not under `_common` but under `utils`
7831
+ */
7832
+
6482
7833
  /**
6483
7834
  * Stores
6484
7835
  *
@@ -7089,6 +8440,7 @@
7089
8440
  exports.createCollectionFromJson = createCollectionFromJson;
7090
8441
  exports.createCollectionFromPromise = createCollectionFromPromise;
7091
8442
  exports.createCollectionFromUrl = createCollectionFromUrl;
8443
+ exports.createLlmToolsFromConfiguration = createLlmToolsFromConfiguration;
7092
8444
  exports.createPipelineExecutor = createPipelineExecutor;
7093
8445
  exports.createSubcollection = createSubcollection;
7094
8446
  exports.embeddingVectorToString = embeddingVectorToString;