@n8n/n8n-nodes-langchain 1.91.1 → 1.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/credentials/AnthropicApi.credentials.js +8 -1
- package/dist/credentials/AnthropicApi.credentials.js.map +1 -1
- package/dist/credentials/AzureEntraCognitiveServicesOAuth2Api.credentials.js +150 -0
- package/dist/credentials/AzureEntraCognitiveServicesOAuth2Api.credentials.js.map +1 -0
- package/dist/known/credentials.json +10 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/description.js +23 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/description.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/execute.js +28 -13
- package/dist/nodes/agents/Agent/agents/ToolsAgent/execute.js.map +1 -1
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js +39 -21
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js.map +1 -1
- package/dist/nodes/chains/ChainLLM/methods/config.js +24 -0
- package/dist/nodes/chains/ChainLLM/methods/config.js.map +1 -1
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js +55 -15
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.js +54 -11
- package/dist/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.js.map +1 -1
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js +66 -24
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js.map +1 -1
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js +86 -27
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js.map +1 -1
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js +81 -47
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js.map +1 -1
- package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js +5 -1
- package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js.map +1 -1
- package/dist/nodes/llms/LMChatAnthropic/methods/searchModels.js +3 -1
- package/dist/nodes/llms/LMChatAnthropic/methods/searchModels.js.map +1 -1
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js +63 -123
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js.map +1 -1
- package/dist/nodes/llms/LmChatAzureOpenAi/credentials/N8nOAuth2TokenCredential.js +61 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/credentials/N8nOAuth2TokenCredential.js.map +1 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/credentials/api-key.js +53 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/credentials/api-key.js.map +1 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/credentials/oauth2.js +54 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/credentials/oauth2.js.map +1 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/properties.js +155 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/properties.js.map +1 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/types.js +42 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/types.js.map +1 -0
- package/dist/types/credentials.json +2 -1
- package/dist/types/nodes.json +8 -8
- package/package.json +10 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\n\nimport { ChatAnthropic } from '@langchain/anthropic';\nimport type { LLMResult } from '@langchain/core/outputs';\nimport {\n\tNodeConnectionTypes,\n\ttype INodePropertyOptions,\n\ttype INodeProperties,\n\ttype ISupplyDataFunctions,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { searchModels } from './methods/searchModels';\nimport { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler';\nimport { N8nLlmTracing } from '../N8nLlmTracing';\n\nconst modelField: INodeProperties = {\n\tdisplayName: 'Model',\n\tname: 'model',\n\ttype: 'options',\n\t// eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items\n\toptions: [\n\t\t{\n\t\t\tname: 'Claude 3.5 Sonnet(20241022)',\n\t\t\tvalue: 'claude-3-5-sonnet-20241022',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Opus(20240229)',\n\t\t\tvalue: 'claude-3-opus-20240229',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3.5 Sonnet(20240620)',\n\t\t\tvalue: 'claude-3-5-sonnet-20240620',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Sonnet(20240229)',\n\t\t\tvalue: 'claude-3-sonnet-20240229',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3.5 Haiku(20241022)',\n\t\t\tvalue: 'claude-3-5-haiku-20241022',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Haiku(20240307)',\n\t\t\tvalue: 'claude-3-haiku-20240307',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude 2',\n\t\t\tvalue: 'claude-2',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude 2.1',\n\t\t\tvalue: 'claude-2.1',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude Instant 1.2',\n\t\t\tvalue: 'claude-instant-1.2',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude Instant 1',\n\t\t\tvalue: 'claude-instant-1',\n\t\t},\n\t],\n\tdescription:\n\t\t'The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.',\n\tdefault: 'claude-2',\n};\n\nconst MIN_THINKING_BUDGET = 1024;\nconst DEFAULT_MAX_TOKENS = 4096;\nexport class LmChatAnthropic implements INodeType {\n\tmethods = {\n\t\tlistSearch: {\n\t\t\tsearchModels,\n\t\t},\n\t};\n\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Anthropic Chat Model',\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-name-miscased\n\t\tname: 'lmChatAnthropic',\n\t\ticon: 'file:anthropic.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdefaultVersion: 1.3,\n\t\tdescription: 'Language Model Anthropic',\n\t\tdefaults: {\n\t\t\tname: 'Anthropic Chat Model',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Language Models', 'Root Nodes'],\n\t\t\t\t'Language Models': ['Chat Models (Recommended)'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatanthropic/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\talias: ['claude', 'sonnet', 'opus'],\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiLanguageModel],\n\t\toutputNames: ['Model'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'anthropicApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiChain]),\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdefault: 'claude-3-sonnet-20240229',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdefault: 'claude-3-5-sonnet-20240620',\n\t\t\t\toptions: (modelField.options ?? []).filter(\n\t\t\t\t\t(o): o is INodePropertyOptions => 'name' in o && !o.name.toString().startsWith('LEGACY'),\n\t\t\t\t),\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tname: 'model',\n\t\t\t\ttype: 'resourceLocator',\n\t\t\t\tdefault: {\n\t\t\t\t\tmode: 'list',\n\t\t\t\t\tvalue: 'claude-3-7-sonnet-20250219',\n\t\t\t\t\tcachedResultName: 'Claude 3.7 Sonnet',\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t\tmodes: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'From List',\n\t\t\t\t\t\tname: 'list',\n\t\t\t\t\t\ttype: 'list',\n\t\t\t\t\t\tplaceholder: 'Select a model...',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\tsearchListMethod: 'searchModels',\n\t\t\t\t\t\t\tsearchable: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'ID',\n\t\t\t\t\t\tname: 'id',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tplaceholder: 'Claude Sonnet',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdescription:\n\t\t\t\t\t'The model. Choose from the list, or specify an ID. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.3 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Maximum Number of Tokens',\n\t\t\t\t\t\tname: 'maxTokensToSample',\n\t\t\t\t\t\tdefault: DEFAULT_MAX_TOKENS,\n\t\t\t\t\t\tdescription: 'The maximum number of tokens to generate in the completion',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Sampling Temperature',\n\t\t\t\t\t\tname: 'temperature',\n\t\t\t\t\t\tdefault: 0.7,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Top K',\n\t\t\t\t\t\tname: 'topK',\n\t\t\t\t\t\tdefault: -1,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: -1, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Used to remove \"long tail\" low probability responses. Defaults to -1, which disables it.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Top P',\n\t\t\t\t\t\tname: 'topP',\n\t\t\t\t\t\tdefault: 1,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Enable Thinking',\n\t\t\t\t\t\tname: 'thinking',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\tdescription: 'Whether to enable thinking mode for the model',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Thinking Budget (Tokens)',\n\t\t\t\t\t\tname: 'thinkingBudget',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdefault: MIN_THINKING_BUDGET,\n\t\t\t\t\t\tdescription: 'The maximum number of tokens to use for thinking',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('anthropicApi');\n\n\t\tconst version = this.getNode().typeVersion;\n\t\tconst modelName =\n\t\t\tversion >= 1.3\n\t\t\t\t? (this.getNodeParameter('model.value', itemIndex) as string)\n\t\t\t\t: (this.getNodeParameter('model', itemIndex) as string);\n\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\tmaxTokensToSample?: number;\n\t\t\ttemperature: number;\n\t\t\ttopK?: number;\n\t\t\ttopP?: number;\n\t\t\tthinking?: boolean;\n\t\t\tthinkingBudget?: number;\n\t\t};\n\t\tlet invocationKwargs = {};\n\n\t\tconst tokensUsageParser = (llmOutput: LLMResult['llmOutput']) => {\n\t\t\tconst usage = (llmOutput?.usage as { input_tokens: number; output_tokens: number }) ?? {\n\t\t\t\tinput_tokens: 0,\n\t\t\t\toutput_tokens: 0,\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tcompletionTokens: usage.output_tokens,\n\t\t\t\tpromptTokens: usage.input_tokens,\n\t\t\t\ttotalTokens: usage.input_tokens + usage.output_tokens,\n\t\t\t};\n\t\t};\n\n\t\tif (options.thinking) {\n\t\t\tinvocationKwargs = {\n\t\t\t\tthinking: {\n\t\t\t\t\ttype: 'enabled',\n\t\t\t\t\t// If thinking is enabled, we need to set a budget.\n\t\t\t\t\t// We fallback to 1024 as that is the minimum\n\t\t\t\t\tbudget_tokens: options.thinkingBudget ?? MIN_THINKING_BUDGET,\n\t\t\t\t},\n\t\t\t\t// The default Langchain max_tokens is -1 (no limit) but Anthropic requires a number\n\t\t\t\t// higher than budget_tokens\n\t\t\t\tmax_tokens: options.maxTokensToSample ?? DEFAULT_MAX_TOKENS,\n\t\t\t\t// These need to be unset when thinking is enabled.\n\t\t\t\t// Because the invocationKwargs will override the model options\n\t\t\t\t// we can pass options to the model and then override them here\n\t\t\t\ttop_k: undefined,\n\t\t\t\ttop_p: undefined,\n\t\t\t\ttemperature: undefined,\n\t\t\t};\n\t\t}\n\n\t\tconst model = new ChatAnthropic({\n\t\t\tanthropicApiKey: credentials.apiKey as string,\n\t\t\tmodelName,\n\t\t\tmaxTokens: options.maxTokensToSample,\n\t\t\ttemperature: options.temperature,\n\t\t\ttopK: options.topK,\n\t\t\ttopP: options.topP,\n\t\t\tcallbacks: [new N8nLlmTracing(this, { tokensUsageParser })],\n\t\t\tonFailedAttempt: makeN8nLlmFailedAttemptHandler(this),\n\t\t\tinvocationKwargs,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: model,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAA8B;AAE9B,0BAQO;AAEP,0BAA6C;AAE7C,0BAA6B;AAC7B,wCAA+C;AAC/C,2BAA8B;AAE9B,MAAM,aAA8B;AAAA,EACnC,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA;AAAA,EAEN,SAAS;AAAA,IACR;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EACA,aACC;AAAA,EACD,SAAS;AACV;AAEA,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AACpB,MAAM,gBAAqC;AAAA,EAA3C;AACN,mBAAU;AAAA,MACT,YAAY;AAAA,QACX;AAAA,MACD;AAAA,IACD;AAEA,uBAAoC;AAAA,MACnC,aAAa;AAAA;AAAA,MAE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A,aAAO;AAAA,QACN,kBAAkB,MAAM;AAAA,QACxB,cAAc,MAAM;AAAA,QACpB,aAAa,MAAM,eAAe,MAAM;AAAA,MACzC;AAAA,IACD;AAEA,QAAI,QAAQ,UAAU;AACrB,yBAAmB;AAAA,QAClB,UAAU;AAAA,UACT,MAAM;AAAA;AAAA;AAAA,UAGN,eAAe,QAAQ,kBAAkB;AAAA,QAC1C;AAAA;AAAA;AAAA,QAGA,YAAY,QAAQ,qBAAqB;AAAA;AAAA;AAAA;AAAA,QAIzC,OAAO;AAAA,QACP,OAAO;AAAA,QACP,aAAa;AAAA,MACd;AAAA,IACD;AAEA,UAAM,QAAQ,IAAI,+BAAc;AAAA,MAC/B,iBAAiB,YAAY;AAAA,MAC7B;AAAA,MACA,WAAW,QAAQ;AAAA,MACnB,aAAa,QAAQ;AAAA,MACrB,MAAM,QAAQ;AAAA,MACd,MAAM,QAAQ;AAAA,MACd,WAAW,CAAC,IAAI,mCAAc,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAAA,MAC1D,qBAAiB,kEAA+B,IAAI;AAAA,MACpD;AAAA,IACD,CAAC;AAED,WAAO;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\n\nimport { ChatAnthropic } from '@langchain/anthropic';\nimport type { LLMResult } from '@langchain/core/outputs';\nimport {\n\tNodeConnectionTypes,\n\ttype INodePropertyOptions,\n\ttype INodeProperties,\n\ttype ISupplyDataFunctions,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { searchModels } from './methods/searchModels';\nimport { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler';\nimport { N8nLlmTracing } from '../N8nLlmTracing';\n\nconst modelField: INodeProperties = {\n\tdisplayName: 'Model',\n\tname: 'model',\n\ttype: 'options',\n\t// eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items\n\toptions: [\n\t\t{\n\t\t\tname: 'Claude 3.5 Sonnet(20241022)',\n\t\t\tvalue: 'claude-3-5-sonnet-20241022',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Opus(20240229)',\n\t\t\tvalue: 'claude-3-opus-20240229',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3.5 Sonnet(20240620)',\n\t\t\tvalue: 'claude-3-5-sonnet-20240620',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Sonnet(20240229)',\n\t\t\tvalue: 'claude-3-sonnet-20240229',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3.5 Haiku(20241022)',\n\t\t\tvalue: 'claude-3-5-haiku-20241022',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Haiku(20240307)',\n\t\t\tvalue: 'claude-3-haiku-20240307',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude 2',\n\t\t\tvalue: 'claude-2',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude 2.1',\n\t\t\tvalue: 'claude-2.1',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude Instant 1.2',\n\t\t\tvalue: 'claude-instant-1.2',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude Instant 1',\n\t\t\tvalue: 'claude-instant-1',\n\t\t},\n\t],\n\tdescription:\n\t\t'The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.',\n\tdefault: 'claude-2',\n};\n\nconst MIN_THINKING_BUDGET = 1024;\nconst DEFAULT_MAX_TOKENS = 4096;\nexport class LmChatAnthropic implements INodeType {\n\tmethods = {\n\t\tlistSearch: {\n\t\t\tsearchModels,\n\t\t},\n\t};\n\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Anthropic Chat Model',\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-name-miscased\n\t\tname: 'lmChatAnthropic',\n\t\ticon: 'file:anthropic.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdefaultVersion: 1.3,\n\t\tdescription: 'Language Model Anthropic',\n\t\tdefaults: {\n\t\t\tname: 'Anthropic Chat Model',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Language Models', 'Root Nodes'],\n\t\t\t\t'Language Models': ['Chat Models (Recommended)'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatanthropic/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\talias: ['claude', 'sonnet', 'opus'],\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiLanguageModel],\n\t\toutputNames: ['Model'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'anthropicApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiChain]),\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdefault: 'claude-3-sonnet-20240229',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdefault: 'claude-3-5-sonnet-20240620',\n\t\t\t\toptions: (modelField.options ?? []).filter(\n\t\t\t\t\t(o): o is INodePropertyOptions => 'name' in o && !o.name.toString().startsWith('LEGACY'),\n\t\t\t\t),\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tname: 'model',\n\t\t\t\ttype: 'resourceLocator',\n\t\t\t\tdefault: {\n\t\t\t\t\tmode: 'list',\n\t\t\t\t\tvalue: 'claude-3-7-sonnet-20250219',\n\t\t\t\t\tcachedResultName: 'Claude 3.7 Sonnet',\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t\tmodes: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'From List',\n\t\t\t\t\t\tname: 'list',\n\t\t\t\t\t\ttype: 'list',\n\t\t\t\t\t\tplaceholder: 'Select a model...',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\tsearchListMethod: 'searchModels',\n\t\t\t\t\t\t\tsearchable: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'ID',\n\t\t\t\t\t\tname: 'id',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tplaceholder: 'Claude Sonnet',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdescription:\n\t\t\t\t\t'The model. Choose from the list, or specify an ID. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.3 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Maximum Number of Tokens',\n\t\t\t\t\t\tname: 'maxTokensToSample',\n\t\t\t\t\t\tdefault: DEFAULT_MAX_TOKENS,\n\t\t\t\t\t\tdescription: 'The maximum number of tokens to generate in the completion',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Sampling Temperature',\n\t\t\t\t\t\tname: 'temperature',\n\t\t\t\t\t\tdefault: 0.7,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Top K',\n\t\t\t\t\t\tname: 'topK',\n\t\t\t\t\t\tdefault: -1,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: -1, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Used to remove \"long tail\" low probability responses. Defaults to -1, which disables it.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Top P',\n\t\t\t\t\t\tname: 'topP',\n\t\t\t\t\t\tdefault: 1,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Enable Thinking',\n\t\t\t\t\t\tname: 'thinking',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\tdescription: 'Whether to enable thinking mode for the model',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Thinking Budget (Tokens)',\n\t\t\t\t\t\tname: 'thinkingBudget',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdefault: MIN_THINKING_BUDGET,\n\t\t\t\t\t\tdescription: 'The maximum number of tokens to use for thinking',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<{ url?: string; apiKey?: string }>(\n\t\t\t'anthropicApi',\n\t\t);\n\t\tconst baseURL = credentials.url ?? 'https://api.anthropic.com';\n\t\tconst version = this.getNode().typeVersion;\n\t\tconst modelName =\n\t\t\tversion >= 1.3\n\t\t\t\t? (this.getNodeParameter('model.value', itemIndex) as string)\n\t\t\t\t: (this.getNodeParameter('model', itemIndex) as string);\n\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\tmaxTokensToSample?: number;\n\t\t\ttemperature: number;\n\t\t\ttopK?: number;\n\t\t\ttopP?: number;\n\t\t\tthinking?: boolean;\n\t\t\tthinkingBudget?: number;\n\t\t};\n\t\tlet invocationKwargs = {};\n\n\t\tconst tokensUsageParser = (llmOutput: LLMResult['llmOutput']) => {\n\t\t\tconst usage = (llmOutput?.usage as { input_tokens: number; output_tokens: number }) ?? {\n\t\t\t\tinput_tokens: 0,\n\t\t\t\toutput_tokens: 0,\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tcompletionTokens: usage.output_tokens,\n\t\t\t\tpromptTokens: usage.input_tokens,\n\t\t\t\ttotalTokens: usage.input_tokens + usage.output_tokens,\n\t\t\t};\n\t\t};\n\n\t\tif (options.thinking) {\n\t\t\tinvocationKwargs = {\n\t\t\t\tthinking: {\n\t\t\t\t\ttype: 'enabled',\n\t\t\t\t\t// If thinking is enabled, we need to set a budget.\n\t\t\t\t\t// We fallback to 1024 as that is the minimum\n\t\t\t\t\tbudget_tokens: options.thinkingBudget ?? MIN_THINKING_BUDGET,\n\t\t\t\t},\n\t\t\t\t// The default Langchain max_tokens is -1 (no limit) but Anthropic requires a number\n\t\t\t\t// higher than budget_tokens\n\t\t\t\tmax_tokens: options.maxTokensToSample ?? DEFAULT_MAX_TOKENS,\n\t\t\t\t// These need to be unset when thinking is enabled.\n\t\t\t\t// Because the invocationKwargs will override the model options\n\t\t\t\t// we can pass options to the model and then override them here\n\t\t\t\ttop_k: undefined,\n\t\t\t\ttop_p: undefined,\n\t\t\t\ttemperature: undefined,\n\t\t\t};\n\t\t}\n\n\t\tconst model = new ChatAnthropic({\n\t\t\tanthropicApiKey: credentials.apiKey,\n\t\t\tmodelName,\n\t\t\tanthropicApiUrl: baseURL,\n\t\t\tmaxTokens: options.maxTokensToSample,\n\t\t\ttemperature: options.temperature,\n\t\t\ttopK: options.topK,\n\t\t\ttopP: options.topP,\n\t\t\tcallbacks: [new N8nLlmTracing(this, { tokensUsageParser })],\n\t\t\tonFailedAttempt: makeN8nLlmFailedAttemptHandler(this),\n\t\t\tinvocationKwargs,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: model,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAA8B;AAE9B,0BAQO;AAEP,0BAA6C;AAE7C,0BAA6B;AAC7B,wCAA+C;AAC/C,2BAA8B;AAE9B,MAAM,aAA8B;AAAA,EACnC,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA;AAAA,EAEN,SAAS;AAAA,IACR;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EACA,aACC;AAAA,EACD,SAAS;AACV;AAEA,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AACpB,MAAM,gBAAqC;AAAA,EAA3C;AACN,mBAAU;AAAA,MACT,YAAY;AAAA,QACX;AAAA,MACD;AAAA,IACD;AAEA,uBAAoC;AAAA,MACnC,aAAa;AAA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D;AAAA,QACtF,cAAc;AAAA,QACd,eAAe;AAAA,MAChB;AACA,aAAO;AAAA,QACN,kBAAkB,MAAM;AAAA,QACxB,cAAc,MAAM;AAAA,QACpB,aAAa,MAAM,eAAe,MAAM;AAAA,MACzC;AAAA,IACD;AAEA,QAAI,QAAQ,UAAU;AACrB,yBAAmB;AAAA,QAClB,UAAU;AAAA,UACT,MAAM;AAAA;AAAA;AAAA,UAGN,eAAe,QAAQ,kBAAkB;AAAA,QAC1C;AAAA;AAAA;AAAA,QAGA,YAAY,QAAQ,qBAAqB;AAAA;AAAA;AAAA;AAAA,QAIzC,OAAO;AAAA,QACP,OAAO;AAAA,QACP,aAAa;AAAA,MACd;AAAA,IACD;AAEA,UAAM,QAAQ,IAAI,+BAAc;AAAA,MAC/B,iBAAiB,YAAY;AAAA,MAC7B;AAAA,MACA,iBAAiB;AAAA,MACjB,WAAW,QAAQ;AAAA,MACnB,aAAa,QAAQ;AAAA,MACrB,MAAM,QAAQ;AAAA,MACd,MAAM,QAAQ;AAAA,MACd,WAAW,CAAC,IAAI,mCAAc,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAAA,MAC1D,qBAAiB,kEAA+B,IAAI;AAAA,MACpD;AAAA,IACD,CAAC;AAED,WAAO;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
|
|
@@ -22,8 +22,10 @@ __export(searchModels_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(searchModels_exports);
|
|
24
24
|
async function searchModels(filter) {
|
|
25
|
+
const credentials = await this.getCredentials("anthropicApi");
|
|
26
|
+
const baseURL = credentials.url ?? "https://api.anthropic.com";
|
|
25
27
|
const response = await this.helpers.httpRequestWithAuthentication.call(this, "anthropicApi", {
|
|
26
|
-
url:
|
|
28
|
+
url: `${baseURL}/v1/models`,
|
|
27
29
|
headers: {
|
|
28
30
|
"anthropic-version": "2023-06-01"
|
|
29
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../nodes/llms/LMChatAnthropic/methods/searchModels.ts"],"sourcesContent":["import type {\n\tILoadOptionsFunctions,\n\tINodeListSearchItems,\n\tINodeListSearchResult,\n} from 'n8n-workflow';\n\nexport interface AnthropicModel {\n\tid: string;\n\tdisplay_name: string;\n\ttype: string;\n\tcreated_at: string;\n}\n\nexport async function searchModels(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\tconst response = (await this.helpers.httpRequestWithAuthentication.call(this, 'anthropicApi', {\n\t\turl:
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/llms/LMChatAnthropic/methods/searchModels.ts"],"sourcesContent":["import type {\n\tILoadOptionsFunctions,\n\tINodeListSearchItems,\n\tINodeListSearchResult,\n} from 'n8n-workflow';\n\nexport interface AnthropicModel {\n\tid: string;\n\tdisplay_name: string;\n\ttype: string;\n\tcreated_at: string;\n}\n\nexport async function searchModels(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\tconst credentials = await this.getCredentials<{ url?: string }>('anthropicApi');\n\n\tconst baseURL = credentials.url ?? 'https://api.anthropic.com';\n\tconst response = (await this.helpers.httpRequestWithAuthentication.call(this, 'anthropicApi', {\n\t\turl: `${baseURL}/v1/models`,\n\t\theaders: {\n\t\t\t'anthropic-version': '2023-06-01',\n\t\t},\n\t})) as { data: AnthropicModel[] };\n\n\tconst models = response.data || [];\n\tlet results: INodeListSearchItems[] = [];\n\n\tif (filter) {\n\t\tfor (const model of models) {\n\t\t\tif (model.id.toLowerCase().includes(filter.toLowerCase())) {\n\t\t\t\tresults.push({\n\t\t\t\t\tname: model.display_name,\n\t\t\t\t\tvalue: model.id,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t} else {\n\t\tresults = models.map((model) => ({\n\t\t\tname: model.display_name,\n\t\t\tvalue: model.id,\n\t\t}));\n\t}\n\n\t// Sort models with more recent ones first (claude-3 before claude-2)\n\tresults = results.sort((a, b) => {\n\t\tconst modelA = models.find((m) => m.id === a.value);\n\t\tconst modelB = models.find((m) => m.id === b.value);\n\n\t\tif (!modelA || !modelB) return 0;\n\n\t\t// Sort by created_at date, most recent first\n\t\tconst dateA = new Date(modelA.created_at);\n\t\tconst dateB = new Date(modelB.created_at);\n\t\treturn dateB.getTime() - dateA.getTime();\n\t});\n\n\treturn {\n\t\tresults,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,eAAsB,aAErB,QACiC;AACjC,QAAM,cAAc,MAAM,KAAK,eAAiC,cAAc;AAE9E,QAAM,UAAU,YAAY,OAAO;AACnC,QAAM,WAAY,MAAM,KAAK,QAAQ,8BAA8B,KAAK,MAAM,gBAAgB;AAAA,IAC7F,KAAK,GAAG,OAAO;AAAA,IACf,SAAS;AAAA,MACR,qBAAqB;AAAA,IACtB;AAAA,EACD,CAAC;AAED,QAAM,SAAS,SAAS,QAAQ,CAAC;AACjC,MAAI,UAAkC,CAAC;AAEvC,MAAI,QAAQ;AACX,eAAW,SAAS,QAAQ;AAC3B,UAAI,MAAM,GAAG,YAAY,EAAE,SAAS,OAAO,YAAY,CAAC,GAAG;AAC1D,gBAAQ,KAAK;AAAA,UACZ,MAAM,MAAM;AAAA,UACZ,OAAO,MAAM;AAAA,QACd,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD,OAAO;AACN,cAAU,OAAO,IAAI,CAAC,WAAW;AAAA,MAChC,MAAM,MAAM;AAAA,MACZ,OAAO,MAAM;AAAA,IACd,EAAE;AAAA,EACH;AAGA,YAAU,QAAQ,KAAK,CAAC,GAAG,MAAM;AAChC,UAAM,SAAS,OAAO,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK;AAClD,UAAM,SAAS,OAAO,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK;AAElD,QAAI,CAAC,UAAU,CAAC,OAAQ,QAAO;AAG/B,UAAM,QAAQ,IAAI,KAAK,OAAO,UAAU;AACxC,UAAM,QAAQ,IAAI,KAAK,OAAO,UAAU;AACxC,WAAO,MAAM,QAAQ,IAAI,MAAM,QAAQ;AAAA,EACxC,CAAC;AAED,SAAO;AAAA,IACN;AAAA,EACD;AACD;","names":[]}
|
|
@@ -23,7 +23,10 @@ __export(LmChatAzureOpenAi_node_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(LmChatAzureOpenAi_node_exports);
|
|
24
24
|
var import_openai = require("@langchain/openai");
|
|
25
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
26
|
-
var
|
|
26
|
+
var import_api_key = require("./credentials/api-key");
|
|
27
|
+
var import_oauth2 = require("./credentials/oauth2");
|
|
28
|
+
var import_properties = require("./properties");
|
|
29
|
+
var import_types = require("./types");
|
|
27
30
|
var import_n8nLlmFailedAttemptHandler = require("../n8nLlmFailedAttemptHandler");
|
|
28
31
|
var import_N8nLlmTracing = require("../N8nLlmTracing");
|
|
29
32
|
class LmChatAzureOpenAi {
|
|
@@ -61,139 +64,76 @@ class LmChatAzureOpenAi {
|
|
|
61
64
|
credentials: [
|
|
62
65
|
{
|
|
63
66
|
name: "azureOpenAiApi",
|
|
64
|
-
required: true
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
properties: [
|
|
68
|
-
(0, import_sharedFields.getConnectionHintNoticeField)([import_n8n_workflow.NodeConnectionTypes.AiChain, import_n8n_workflow.NodeConnectionTypes.AiAgent]),
|
|
69
|
-
{
|
|
70
|
-
displayName: 'If using JSON response format, you must include word "json" in the prompt in your chain or agent. Also, make sure to select latest models released post November 2023.',
|
|
71
|
-
name: "notice",
|
|
72
|
-
type: "notice",
|
|
73
|
-
default: "",
|
|
67
|
+
required: true,
|
|
74
68
|
displayOptions: {
|
|
75
69
|
show: {
|
|
76
|
-
|
|
70
|
+
authentication: [import_types.AuthenticationType.ApiKey]
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
},
|
|
80
74
|
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
displayName: "Options",
|
|
89
|
-
name: "options",
|
|
90
|
-
placeholder: "Add Option",
|
|
91
|
-
description: "Additional options to add",
|
|
92
|
-
type: "collection",
|
|
93
|
-
default: {},
|
|
94
|
-
options: [
|
|
95
|
-
{
|
|
96
|
-
displayName: "Frequency Penalty",
|
|
97
|
-
name: "frequencyPenalty",
|
|
98
|
-
default: 0,
|
|
99
|
-
typeOptions: { maxValue: 2, minValue: -2, numberPrecision: 1 },
|
|
100
|
-
description: "Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim",
|
|
101
|
-
type: "number"
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
displayName: "Maximum Number of Tokens",
|
|
105
|
-
name: "maxTokens",
|
|
106
|
-
default: -1,
|
|
107
|
-
description: "The maximum number of tokens to generate in the completion. Most models have a context length of 2048 tokens (except for the newest models, which support 32,768).",
|
|
108
|
-
type: "number",
|
|
109
|
-
typeOptions: {
|
|
110
|
-
maxValue: 32768
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
displayName: "Response Format",
|
|
115
|
-
name: "responseFormat",
|
|
116
|
-
default: "text",
|
|
117
|
-
type: "options",
|
|
118
|
-
options: [
|
|
119
|
-
{
|
|
120
|
-
name: "Text",
|
|
121
|
-
value: "text",
|
|
122
|
-
description: "Regular text response"
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: "JSON",
|
|
126
|
-
value: "json_object",
|
|
127
|
-
description: "Enables JSON mode, which should guarantee the message the model generates is valid JSON"
|
|
128
|
-
}
|
|
129
|
-
]
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
displayName: "Presence Penalty",
|
|
133
|
-
name: "presencePenalty",
|
|
134
|
-
default: 0,
|
|
135
|
-
typeOptions: { maxValue: 2, minValue: -2, numberPrecision: 1 },
|
|
136
|
-
description: "Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics",
|
|
137
|
-
type: "number"
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
displayName: "Sampling Temperature",
|
|
141
|
-
name: "temperature",
|
|
142
|
-
default: 0.7,
|
|
143
|
-
typeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },
|
|
144
|
-
description: "Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.",
|
|
145
|
-
type: "number"
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
displayName: "Timeout",
|
|
149
|
-
name: "timeout",
|
|
150
|
-
default: 6e4,
|
|
151
|
-
description: "Maximum amount of time a request is allowed to take in milliseconds",
|
|
152
|
-
type: "number"
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
displayName: "Max Retries",
|
|
156
|
-
name: "maxRetries",
|
|
157
|
-
default: 2,
|
|
158
|
-
description: "Maximum number of retries to attempt",
|
|
159
|
-
type: "number"
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
displayName: "Top P",
|
|
163
|
-
name: "topP",
|
|
164
|
-
default: 1,
|
|
165
|
-
typeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },
|
|
166
|
-
description: "Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.",
|
|
167
|
-
type: "number"
|
|
75
|
+
name: "azureEntraCognitiveServicesOAuth2Api",
|
|
76
|
+
required: true,
|
|
77
|
+
displayOptions: {
|
|
78
|
+
show: {
|
|
79
|
+
authentication: [import_types.AuthenticationType.EntraOAuth2]
|
|
168
80
|
}
|
|
169
|
-
|
|
81
|
+
}
|
|
170
82
|
}
|
|
171
|
-
]
|
|
83
|
+
],
|
|
84
|
+
properties: import_properties.properties
|
|
172
85
|
};
|
|
173
86
|
}
|
|
174
87
|
async supplyData(itemIndex) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
88
|
+
try {
|
|
89
|
+
const authenticationMethod = this.getNodeParameter(
|
|
90
|
+
"authentication",
|
|
91
|
+
itemIndex
|
|
92
|
+
);
|
|
93
|
+
const modelName = this.getNodeParameter("model", itemIndex);
|
|
94
|
+
const options = this.getNodeParameter("options", itemIndex, {});
|
|
95
|
+
let modelConfig;
|
|
96
|
+
switch (authenticationMethod) {
|
|
97
|
+
case import_types.AuthenticationType.ApiKey:
|
|
98
|
+
modelConfig = await import_api_key.setupApiKeyAuthentication.call(this, "azureOpenAiApi");
|
|
99
|
+
break;
|
|
100
|
+
case import_types.AuthenticationType.EntraOAuth2:
|
|
101
|
+
modelConfig = await import_oauth2.setupOAuth2Authentication.call(
|
|
102
|
+
this,
|
|
103
|
+
"azureEntraCognitiveServicesOAuth2Api"
|
|
104
|
+
);
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
throw new import_n8n_workflow.NodeOperationError(this.getNode(), "Invalid authentication method");
|
|
108
|
+
}
|
|
109
|
+
this.logger.info(`Instantiating AzureChatOpenAI model with deployment: ${modelName}`);
|
|
110
|
+
const model = new import_openai.AzureChatOpenAI({
|
|
111
|
+
azureOpenAIApiDeploymentName: modelName,
|
|
112
|
+
...modelConfig,
|
|
113
|
+
...options,
|
|
114
|
+
timeout: options.timeout ?? 6e4,
|
|
115
|
+
maxRetries: options.maxRetries ?? 2,
|
|
116
|
+
callbacks: [new import_N8nLlmTracing.N8nLlmTracing(this)],
|
|
117
|
+
modelKwargs: options.responseFormat ? {
|
|
118
|
+
response_format: { type: options.responseFormat }
|
|
119
|
+
} : void 0,
|
|
120
|
+
onFailedAttempt: (0, import_n8nLlmFailedAttemptHandler.makeN8nLlmFailedAttemptHandler)(this)
|
|
121
|
+
});
|
|
122
|
+
this.logger.info(`Azure OpenAI client initialized for deployment: ${modelName}`);
|
|
123
|
+
return {
|
|
124
|
+
response: model
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
this.logger.error(`Error in LmChatAzureOpenAi.supplyData: ${error.message}`, error);
|
|
128
|
+
if (error instanceof import_n8n_workflow.NodeOperationError) {
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
throw new import_n8n_workflow.NodeOperationError(
|
|
132
|
+
this.getNode(),
|
|
133
|
+
`Failed to initialize Azure OpenAI client: ${error.message}`,
|
|
134
|
+
error
|
|
135
|
+
);
|
|
136
|
+
}
|
|
197
137
|
}
|
|
198
138
|
}
|
|
199
139
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport { AzureChatOpenAI } from '@langchain/openai';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler';\nimport { N8nLlmTracing } from '../N8nLlmTracing';\n\nexport class LmChatAzureOpenAi implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Azure OpenAI Chat Model',\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-name-miscased\n\t\tname: 'lmChatAzureOpenAi',\n\t\ticon: 'file:azure.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'For advanced usage with an AI chain',\n\t\tdefaults: {\n\t\t\tname: 'Azure OpenAI Chat Model',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Language Models', 'Root Nodes'],\n\t\t\t\t'Language Models': ['Chat Models (Recommended)'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatazureopenai/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiLanguageModel],\n\t\toutputNames: ['Model'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'azureOpenAiApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t'If using JSON response format, you must include word \"json\" in the prompt in your chain or agent. Also, make sure to select latest models released post November 2023.',\n\t\t\t\tname: 'notice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/options.responseFormat': ['json_object'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Model (Deployment) Name',\n\t\t\t\tname: 'model',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'The name of the model(deployment) to use',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Frequency Penalty',\n\t\t\t\t\t\tname: 'frequencyPenalty',\n\t\t\t\t\t\tdefault: 0,\n\t\t\t\t\t\ttypeOptions: { maxValue: 2, minValue: -2, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim\",\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Maximum Number of Tokens',\n\t\t\t\t\t\tname: 'maxTokens',\n\t\t\t\t\t\tdefault: -1,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'The maximum number of tokens to generate in the completion. Most models have a context length of 2048 tokens (except for the newest models, which support 32,768).',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\tmaxValue: 32768,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Response Format',\n\t\t\t\t\t\tname: 'responseFormat',\n\t\t\t\t\t\tdefault: 'text',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Text',\n\t\t\t\t\t\t\t\tvalue: 'text',\n\t\t\t\t\t\t\t\tdescription: 'Regular text response',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'JSON',\n\t\t\t\t\t\t\t\tvalue: 'json_object',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'Enables JSON mode, which should guarantee the message the model generates is valid JSON',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Presence Penalty',\n\t\t\t\t\t\tname: 'presencePenalty',\n\t\t\t\t\t\tdefault: 0,\n\t\t\t\t\t\ttypeOptions: { maxValue: 2, minValue: -2, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics\",\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Sampling Temperature',\n\t\t\t\t\t\tname: 'temperature',\n\t\t\t\t\t\tdefault: 0.7,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Timeout',\n\t\t\t\t\t\tname: 'timeout',\n\t\t\t\t\t\tdefault: 60000,\n\t\t\t\t\t\tdescription: 'Maximum amount of time a request is allowed to take in milliseconds',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Max Retries',\n\t\t\t\t\t\tname: 'maxRetries',\n\t\t\t\t\t\tdefault: 2,\n\t\t\t\t\t\tdescription: 'Maximum number of retries to attempt',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Top P',\n\t\t\t\t\t\tname: 'topP',\n\t\t\t\t\t\tdefault: 1,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<{\n\t\t\tapiKey: string;\n\t\t\tresourceName: string;\n\t\t\tapiVersion: string;\n\t\t\tendpoint?: string;\n\t\t}>('azureOpenAiApi');\n\n\t\tconst modelName = this.getNodeParameter('model', itemIndex) as string;\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\tfrequencyPenalty?: number;\n\t\t\tmaxTokens?: number;\n\t\t\tmaxRetries: number;\n\t\t\ttimeout: number;\n\t\t\tpresencePenalty?: number;\n\t\t\ttemperature?: number;\n\t\t\ttopP?: number;\n\t\t\tresponseFormat?: 'text' | 'json_object';\n\t\t};\n\n\t\tconst model = new AzureChatOpenAI({\n\t\t\tazureOpenAIApiDeploymentName: modelName,\n\t\t\t// instance name only needed to set base url\n\t\t\tazureOpenAIApiInstanceName: !credentials.endpoint ? credentials.resourceName : undefined,\n\t\t\tazureOpenAIApiKey: credentials.apiKey,\n\t\t\tazureOpenAIApiVersion: credentials.apiVersion,\n\t\t\tazureOpenAIEndpoint: credentials.endpoint,\n\t\t\t...options,\n\t\t\ttimeout: options.timeout ?? 60000,\n\t\t\tmaxRetries: options.maxRetries ?? 2,\n\t\t\tcallbacks: [new N8nLlmTracing(this)],\n\t\t\tmodelKwargs: options.responseFormat\n\t\t\t\t? {\n\t\t\t\t\t\tresponse_format: { type: options.responseFormat },\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\t\tonFailedAttempt: makeN8nLlmFailedAttemptHandler(this),\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: model,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAgC;AAChC,0BAMO;A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AAE;AAAA,cAC5D,aACC;AAAA,cACD,MAAM;AAAA,YACP;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,cAAc,MAAM,KAAK,eAK5B,gBAAgB;AAEnB,UAAM,YAAY,KAAK,iBAAiB,SAAS,SAAS;AAC1D,UAAM,UAAU,KAAK,iBAAiB,WAAW,WAAW,CAAC,CAAC;AAW9D,UAAM,QAAQ,IAAI,8BAAgB;AAAA,MACjC,8BAA8B;AAAA;AAAA,MAE9B,4BAA4B,CAAC,YAAY,WAAW,YAAY,eAAe;AAAA,MAC/E,mBAAmB,YAAY;AAAA,MAC/B,uBAAuB,YAAY;AAAA,MACnC,qBAAqB,YAAY;AAAA,MACjC,GAAG;AAAA,MACH,SAAS,QAAQ,WAAW;AAAA,MAC5B,YAAY,QAAQ,cAAc;AAAA,MAClC,WAAW,CAAC,IAAI,mCAAc,IAAI,CAAC;AAAA,MACnC,aAAa,QAAQ,iBAClB;AAAA,QACA,iBAAiB,EAAE,MAAM,QAAQ,eAAe;AAAA,MACjD,IACC;AAAA,MACH,qBAAiB,kEAA+B,IAAI;AAAA,IACrD,CAAC;AAED,WAAO;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-execute-block-wrong-error-thrown */\n/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport { AzureChatOpenAI } from '@langchain/openai';\nimport {\n\tNodeOperationError,\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { setupApiKeyAuthentication } from './credentials/api-key';\nimport { setupOAuth2Authentication } from './credentials/oauth2';\nimport { properties } from './properties';\nimport { AuthenticationType } from './types';\nimport type {\n\tAzureOpenAIApiKeyModelConfig,\n\tAzureOpenAIOAuth2ModelConfig,\n\tAzureOpenAIOptions,\n} from './types';\nimport { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler';\nimport { N8nLlmTracing } from '../N8nLlmTracing';\n\nexport class LmChatAzureOpenAi implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Azure OpenAI Chat Model',\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-name-miscased\n\t\tname: 'lmChatAzureOpenAi',\n\t\ticon: 'file:azure.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'For advanced usage with an AI chain',\n\t\tdefaults: {\n\t\t\tname: 'Azure OpenAI Chat Model',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Language Models', 'Root Nodes'],\n\t\t\t\t'Language Models': ['Chat Models (Recommended)'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatazureopenai/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiLanguageModel],\n\t\toutputNames: ['Model'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'azureOpenAiApi',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: [AuthenticationType.ApiKey],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'azureEntraCognitiveServicesOAuth2Api',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: [AuthenticationType.EntraOAuth2],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tproperties,\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\ttry {\n\t\t\tconst authenticationMethod = this.getNodeParameter(\n\t\t\t\t'authentication',\n\t\t\t\titemIndex,\n\t\t\t) as AuthenticationType;\n\t\t\tconst modelName = this.getNodeParameter('model', itemIndex) as string;\n\t\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as AzureOpenAIOptions;\n\n\t\t\t// Set up Authentication based on selection and get configuration\n\t\t\tlet modelConfig: AzureOpenAIApiKeyModelConfig | AzureOpenAIOAuth2ModelConfig;\n\t\t\tswitch (authenticationMethod) {\n\t\t\t\tcase AuthenticationType.ApiKey:\n\t\t\t\t\tmodelConfig = await setupApiKeyAuthentication.call(this, 'azureOpenAiApi');\n\t\t\t\t\tbreak;\n\t\t\t\tcase AuthenticationType.EntraOAuth2:\n\t\t\t\t\tmodelConfig = await setupOAuth2Authentication.call(\n\t\t\t\t\t\tthis,\n\t\t\t\t\t\t'azureEntraCognitiveServicesOAuth2Api',\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), 'Invalid authentication method');\n\t\t\t}\n\n\t\t\tthis.logger.info(`Instantiating AzureChatOpenAI model with deployment: ${modelName}`);\n\n\t\t\t// Create and return the model\n\t\t\tconst model = new AzureChatOpenAI({\n\t\t\t\tazureOpenAIApiDeploymentName: modelName,\n\t\t\t\t...modelConfig,\n\t\t\t\t...options,\n\t\t\t\ttimeout: options.timeout ?? 60000,\n\t\t\t\tmaxRetries: options.maxRetries ?? 2,\n\t\t\t\tcallbacks: [new N8nLlmTracing(this)],\n\t\t\t\tmodelKwargs: options.responseFormat\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tresponse_format: { type: options.responseFormat },\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t\tonFailedAttempt: makeN8nLlmFailedAttemptHandler(this),\n\t\t\t});\n\n\t\t\tthis.logger.info(`Azure OpenAI client initialized for deployment: ${modelName}`);\n\n\t\t\treturn {\n\t\t\t\tresponse: model,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis.logger.error(`Error in LmChatAzureOpenAi.supplyData: ${error.message}`, error);\n\n\t\t\t// Re-throw NodeOperationError directly, wrap others\n\t\t\tif (error instanceof NodeOperationError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t`Failed to initialize Azure OpenAI client: ${error.message}`,\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAgC;AAChC,0BAOO;AAEP,qBAA0C;AAC1C,oBAA0C;AAC1C,wBAA2B;AAC3B,mBAAmC;AAMnC,wCAA+C;AAC/C,2BAA8B;AAEvB,MAAM,kBAAuC;AAAA,EAA7C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA;AAAA,MAEb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,mBAAmB,YAAY;AAAA,UACpC,mBAAmB,CAAC,2BAA2B;AAAA,QAChD;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA;AAAA,MAE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AA,UACA,iBAAiB,EAAE,MAAM,QAAQ,eAAe;AAAA,QACjD,IACC;AAAA,QACH,qBAAiB,kEAA+B,IAAI;AAAA,MACrD,CAAC;AAED,WAAK,OAAO,KAAK,mDAAmD,SAAS,EAAE;AAE/E,aAAO;AAAA,QACN,UAAU;AAAA,MACX;AAAA,IACD,SAAS,OAAO;AACf,WAAK,OAAO,MAAM,0CAA0C,MAAM,OAAO,IAAI,KAAK;AAGlF,UAAI,iBAAiB,wCAAoB;AACxC,cAAM;AAAA,MACP;AAEA,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb,6CAA6C,MAAM,OAAO;AAAA,QAC1D;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var N8nOAuth2TokenCredential_exports = {};
|
|
20
|
+
__export(N8nOAuth2TokenCredential_exports, {
|
|
21
|
+
N8nOAuth2TokenCredential: () => N8nOAuth2TokenCredential
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(N8nOAuth2TokenCredential_exports);
|
|
24
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
25
|
+
class N8nOAuth2TokenCredential {
|
|
26
|
+
constructor(node, credential) {
|
|
27
|
+
this.node = node;
|
|
28
|
+
this.credential = credential;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets an access token from OAuth credential
|
|
32
|
+
*/
|
|
33
|
+
async getToken() {
|
|
34
|
+
try {
|
|
35
|
+
if (!this.credential?.oauthTokenData?.access_token) {
|
|
36
|
+
throw new import_n8n_workflow.NodeOperationError(this.node, "Failed to retrieve access token");
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
token: this.credential.oauthTokenData.access_token,
|
|
40
|
+
expiresOnTimestamp: this.credential.oauthTokenData.expires_on
|
|
41
|
+
};
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw new import_n8n_workflow.NodeOperationError(this.node, "Failed to retrieve OAuth2 access token", error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the deployment details from the credential
|
|
48
|
+
*/
|
|
49
|
+
async getDeploymentDetails() {
|
|
50
|
+
return {
|
|
51
|
+
apiVersion: this.credential.apiVersion,
|
|
52
|
+
endpoint: this.credential.endpoint,
|
|
53
|
+
resourceName: this.credential.resourceName
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
N8nOAuth2TokenCredential
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=N8nOAuth2TokenCredential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/llms/LmChatAzureOpenAi/credentials/N8nOAuth2TokenCredential.ts"],"sourcesContent":["import type { TokenCredential, AccessToken } from '@azure/identity';\nimport type { INode } from 'n8n-workflow';\nimport { NodeOperationError } from 'n8n-workflow';\n\nimport type { AzureEntraCognitiveServicesOAuth2ApiCredential } from '../types';\n/**\n * Adapts n8n's credential retrieval into the TokenCredential interface expected by @azure/identity\n */\nexport class N8nOAuth2TokenCredential implements TokenCredential {\n\tconstructor(\n\t\tprivate node: INode,\n\t\tprivate credential: AzureEntraCognitiveServicesOAuth2ApiCredential,\n\t) {}\n\n\t/**\n\t * Gets an access token from OAuth credential\n\t */\n\tasync getToken(): Promise<AccessToken | null> {\n\t\ttry {\n\t\t\tif (!this.credential?.oauthTokenData?.access_token) {\n\t\t\t\tthrow new NodeOperationError(this.node, 'Failed to retrieve access token');\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ttoken: this.credential.oauthTokenData.access_token,\n\t\t\t\texpiresOnTimestamp: this.credential.oauthTokenData.expires_on,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\t// Re-throw with better error message\n\t\t\tthrow new NodeOperationError(this.node, 'Failed to retrieve OAuth2 access token', error);\n\t\t}\n\t}\n\n\t/**\n\t * Gets the deployment details from the credential\n\t */\n\tasync getDeploymentDetails() {\n\t\treturn {\n\t\t\tapiVersion: this.credential.apiVersion,\n\t\t\tendpoint: this.credential.endpoint,\n\t\t\tresourceName: this.credential.resourceName,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAmC;AAM5B,MAAM,yBAAoD;AAAA,EAChE,YACS,MACA,YACP;AAFO;AACA;AAAA,EACN;AAAA;AAAA;AAAA;AAAA,EAKH,MAAM,WAAwC;AAC7C,QAAI;AACH,UAAI,CAAC,KAAK,YAAY,gBAAgB,cAAc;AACnD,cAAM,IAAI,uCAAmB,KAAK,MAAM,iCAAiC;AAAA,MAC1E;AAEA,aAAO;AAAA,QACN,OAAO,KAAK,WAAW,eAAe;AAAA,QACtC,oBAAoB,KAAK,WAAW,eAAe;AAAA,MACpD;AAAA,IACD,SAAS,OAAO;AAEf,YAAM,IAAI,uCAAmB,KAAK,MAAM,0CAA0C,KAAK;AAAA,IACxF;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,uBAAuB;AAC5B,WAAO;AAAA,MACN,YAAY,KAAK,WAAW;AAAA,MAC5B,UAAU,KAAK,WAAW;AAAA,MAC1B,cAAc,KAAK,WAAW;AAAA,IAC/B;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var api_key_exports = {};
|
|
20
|
+
__export(api_key_exports, {
|
|
21
|
+
setupApiKeyAuthentication: () => setupApiKeyAuthentication
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(api_key_exports);
|
|
24
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
25
|
+
async function setupApiKeyAuthentication(credentialName) {
|
|
26
|
+
try {
|
|
27
|
+
const configCredentials = await this.getCredentials(credentialName);
|
|
28
|
+
if (!configCredentials.apiKey) {
|
|
29
|
+
throw new import_n8n_workflow.NodeOperationError(
|
|
30
|
+
this.getNode(),
|
|
31
|
+
"API Key is missing in the selected Azure OpenAI API credential. Please configure the API Key or choose Entra ID authentication."
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
this.logger.info("Using API Key authentication for Azure OpenAI.");
|
|
35
|
+
return {
|
|
36
|
+
azureOpenAIApiKey: configCredentials.apiKey,
|
|
37
|
+
azureOpenAIApiInstanceName: configCredentials.resourceName,
|
|
38
|
+
azureOpenAIApiVersion: configCredentials.apiVersion,
|
|
39
|
+
azureOpenAIEndpoint: configCredentials.endpoint
|
|
40
|
+
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error instanceof import_n8n_workflow.OperationalError) {
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
this.logger.error(`Error setting up API Key authentication: ${error.message}`, error);
|
|
46
|
+
throw new import_n8n_workflow.NodeOperationError(this.getNode(), "Failed to retrieve API Key", error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
setupApiKeyAuthentication
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=api-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/llms/LmChatAzureOpenAi/credentials/api-key.ts"],"sourcesContent":["import { NodeOperationError, OperationalError, type ISupplyDataFunctions } from 'n8n-workflow';\n\nimport type { AzureOpenAIApiKeyModelConfig } from '../types';\n\n/**\n * Handles API Key authentication setup for Azure OpenAI\n */\nexport async function setupApiKeyAuthentication(\n\tthis: ISupplyDataFunctions,\n\tcredentialName: string,\n): Promise<AzureOpenAIApiKeyModelConfig> {\n\ttry {\n\t\t// Get Azure OpenAI Config (Endpoint, Version, etc.)\n\t\tconst configCredentials = await this.getCredentials<{\n\t\t\tapiKey?: string;\n\t\t\tresourceName: string;\n\t\t\tapiVersion: string;\n\t\t\tendpoint?: string;\n\t\t}>(credentialName);\n\n\t\tif (!configCredentials.apiKey) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'API Key is missing in the selected Azure OpenAI API credential. Please configure the API Key or choose Entra ID authentication.',\n\t\t\t);\n\t\t}\n\n\t\tthis.logger.info('Using API Key authentication for Azure OpenAI.');\n\n\t\treturn {\n\t\t\tazureOpenAIApiKey: configCredentials.apiKey,\n\t\t\tazureOpenAIApiInstanceName: configCredentials.resourceName,\n\t\t\tazureOpenAIApiVersion: configCredentials.apiVersion,\n\t\t\tazureOpenAIEndpoint: configCredentials.endpoint,\n\t\t};\n\t} catch (error) {\n\t\tif (error instanceof OperationalError) {\n\t\t\tthrow error;\n\t\t}\n\n\t\tthis.logger.error(`Error setting up API Key authentication: ${error.message}`, error);\n\n\t\tthrow new NodeOperationError(this.getNode(), 'Failed to retrieve API Key', error);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAgF;AAOhF,eAAsB,0BAErB,gBACwC;AACxC,MAAI;AAEH,UAAM,oBAAoB,MAAM,KAAK,eAKlC,cAAc;AAEjB,QAAI,CAAC,kBAAkB,QAAQ;AAC9B,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,MACD;AAAA,IACD;AAEA,SAAK,OAAO,KAAK,gDAAgD;AAEjE,WAAO;AAAA,MACN,mBAAmB,kBAAkB;AAAA,MACrC,4BAA4B,kBAAkB;AAAA,MAC9C,uBAAuB,kBAAkB;AAAA,MACzC,qBAAqB,kBAAkB;AAAA,IACxC;AAAA,EACD,SAAS,OAAO;AACf,QAAI,iBAAiB,sCAAkB;AACtC,YAAM;AAAA,IACP;AAEA,SAAK,OAAO,MAAM,4CAA4C,MAAM,OAAO,IAAI,KAAK;AAEpF,UAAM,IAAI,uCAAmB,KAAK,QAAQ,GAAG,8BAA8B,KAAK;AAAA,EACjF;AACD;","names":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var oauth2_exports = {};
|
|
20
|
+
__export(oauth2_exports, {
|
|
21
|
+
setupOAuth2Authentication: () => setupOAuth2Authentication
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(oauth2_exports);
|
|
24
|
+
var import_identity = require("@azure/identity");
|
|
25
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
26
|
+
var import_N8nOAuth2TokenCredential = require("./N8nOAuth2TokenCredential");
|
|
27
|
+
const AZURE_OPENAI_SCOPE = "https://cognitiveservices.azure.com/.default";
|
|
28
|
+
async function setupOAuth2Authentication(credentialName) {
|
|
29
|
+
try {
|
|
30
|
+
const credential = await this.getCredentials(credentialName);
|
|
31
|
+
const entraTokenCredential = new import_N8nOAuth2TokenCredential.N8nOAuth2TokenCredential(this.getNode(), credential);
|
|
32
|
+
const deploymentDetails = await entraTokenCredential.getDeploymentDetails();
|
|
33
|
+
const azureADTokenProvider = (0, import_identity.getBearerTokenProvider)(entraTokenCredential, AZURE_OPENAI_SCOPE);
|
|
34
|
+
this.logger.debug("Successfully created Azure AD Token Provider.");
|
|
35
|
+
return {
|
|
36
|
+
azureADTokenProvider,
|
|
37
|
+
azureOpenAIApiInstanceName: deploymentDetails.resourceName,
|
|
38
|
+
azureOpenAIApiVersion: deploymentDetails.apiVersion,
|
|
39
|
+
azureOpenAIEndpoint: deploymentDetails.endpoint
|
|
40
|
+
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
this.logger.error(`Error setting up Entra ID authentication: ${error.message}`, error);
|
|
43
|
+
throw new import_n8n_workflow.NodeOperationError(
|
|
44
|
+
this.getNode(),
|
|
45
|
+
`Error setting up Entra ID authentication: ${error.message}`,
|
|
46
|
+
error
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
setupOAuth2Authentication
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=oauth2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/llms/LmChatAzureOpenAi/credentials/oauth2.ts"],"sourcesContent":["import { getBearerTokenProvider } from '@azure/identity';\nimport { NodeOperationError, type ISupplyDataFunctions } from 'n8n-workflow';\n\nimport { N8nOAuth2TokenCredential } from './N8nOAuth2TokenCredential';\nimport type {\n\tAzureEntraCognitiveServicesOAuth2ApiCredential,\n\tAzureOpenAIOAuth2ModelConfig,\n} from '../types';\n\nconst AZURE_OPENAI_SCOPE = 'https://cognitiveservices.azure.com/.default';\n/**\n * Creates Entra ID (OAuth2) authentication for Azure OpenAI\n */\nexport async function setupOAuth2Authentication(\n\tthis: ISupplyDataFunctions,\n\tcredentialName: string,\n): Promise<AzureOpenAIOAuth2ModelConfig> {\n\ttry {\n\t\tconst credential =\n\t\t\tawait this.getCredentials<AzureEntraCognitiveServicesOAuth2ApiCredential>(credentialName);\n\t\t// Create a TokenCredential\n\t\tconst entraTokenCredential = new N8nOAuth2TokenCredential(this.getNode(), credential);\n\t\tconst deploymentDetails = await entraTokenCredential.getDeploymentDetails();\n\n\t\t// Use getBearerTokenProvider to create the function LangChain expects\n\t\t// Pass the required scope for Azure Cognitive Services\n\t\tconst azureADTokenProvider = getBearerTokenProvider(entraTokenCredential, AZURE_OPENAI_SCOPE);\n\n\t\tthis.logger.debug('Successfully created Azure AD Token Provider.');\n\n\t\treturn {\n\t\t\tazureADTokenProvider,\n\t\t\tazureOpenAIApiInstanceName: deploymentDetails.resourceName,\n\t\t\tazureOpenAIApiVersion: deploymentDetails.apiVersion,\n\t\t\tazureOpenAIEndpoint: deploymentDetails.endpoint,\n\t\t};\n\t} catch (error) {\n\t\tthis.logger.error(`Error setting up Entra ID authentication: ${error.message}`, error);\n\n\t\tthrow new NodeOperationError(\n\t\t\tthis.getNode(),\n\t\t\t`Error setting up Entra ID authentication: ${error.message}`,\n\t\t\terror,\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuC;AACvC,0BAA8D;AAE9D,sCAAyC;AAMzC,MAAM,qBAAqB;AAI3B,eAAsB,0BAErB,gBACwC;AACxC,MAAI;AACH,UAAM,aACL,MAAM,KAAK,eAA+D,cAAc;AAEzF,UAAM,uBAAuB,IAAI,yDAAyB,KAAK,QAAQ,GAAG,UAAU;AACpF,UAAM,oBAAoB,MAAM,qBAAqB,qBAAqB;AAI1E,UAAM,2BAAuB,wCAAuB,sBAAsB,kBAAkB;AAE5F,SAAK,OAAO,MAAM,+CAA+C;AAEjE,WAAO;AAAA,MACN;AAAA,MACA,4BAA4B,kBAAkB;AAAA,MAC9C,uBAAuB,kBAAkB;AAAA,MACzC,qBAAqB,kBAAkB;AAAA,IACxC;AAAA,EACD,SAAS,OAAO;AACf,SAAK,OAAO,MAAM,6CAA6C,MAAM,OAAO,IAAI,KAAK;AAErF,UAAM,IAAI;AAAA,MACT,KAAK,QAAQ;AAAA,MACb,6CAA6C,MAAM,OAAO;AAAA,MAC1D;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|