diff --git a/packages/@n8n/nodes-langchain/credentials/AzureOpenAiApi.credentials.ts b/packages/@n8n/nodes-langchain/credentials/AzureOpenAiApi.credentials.ts index 28608524c8..1dbc62b4ed 100644 --- a/packages/@n8n/nodes-langchain/credentials/AzureOpenAiApi.credentials.ts +++ b/packages/@n8n/nodes-langchain/credentials/AzureOpenAiApi.credentials.ts @@ -30,6 +30,13 @@ export class AzureOpenAiApi implements ICredentialType { required: true, default: '2023-07-01-preview', }, + { + displayName: 'Endpoint', + name: 'endpoint', + type: 'string', + default: undefined, + placeholder: 'https://westeurope.api.cognitive.microsoft.com', + }, ]; authenticate: IAuthenticateGeneric = { diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts index 8c178543fc..bf101292f2 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts @@ -128,6 +128,7 @@ export class EmbeddingsAzureOpenAi implements INodeType { apiKey: string; resourceName: string; apiVersion: string; + endpoint?: string; }>('azureOpenAiApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; @@ -144,9 +145,15 @@ export class EmbeddingsAzureOpenAi implements INodeType { const embeddings = new OpenAIEmbeddings({ azureOpenAIApiDeploymentName: modelName, - azureOpenAIApiInstanceName: credentials.resourceName, + // instance name only needed to set base url + azureOpenAIApiInstanceName: !credentials.endpoint ? credentials.resourceName : undefined, azureOpenAIApiKey: credentials.apiKey, azureOpenAIApiVersion: credentials.apiVersion, + // azureOpenAIEndpoint and configuration.baseURL are both ignored here + // only setting azureOpenAIBasePath worked + azureOpenAIBasePath: credentials.endpoint + ? `${credentials.endpoint}/openai/deployments` + : undefined, ...options, }); diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts index ffa7f4d58f..e2292abc77 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts @@ -168,6 +168,7 @@ export class LmChatAzureOpenAi implements INodeType { apiKey: string; resourceName: string; apiVersion: string; + endpoint?: string; }>('azureOpenAiApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; @@ -184,9 +185,11 @@ export class LmChatAzureOpenAi implements INodeType { const model = new ChatOpenAI({ azureOpenAIApiDeploymentName: modelName, - azureOpenAIApiInstanceName: credentials.resourceName, + // instance name only needed to set base url + azureOpenAIApiInstanceName: !credentials.endpoint ? credentials.resourceName : undefined, azureOpenAIApiKey: credentials.apiKey, azureOpenAIApiVersion: credentials.apiVersion, + azureOpenAIEndpoint: credentials.endpoint, ...options, timeout: options.timeout ?? 60000, maxRetries: options.maxRetries ?? 2,