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