diff --git a/packages/@n8n/nodes-langchain/credentials/OllamaApi.credentials.ts b/packages/@n8n/nodes-langchain/credentials/OllamaApi.credentials.ts index acfbbcd3f9..3d030753c8 100644 --- a/packages/@n8n/nodes-langchain/credentials/OllamaApi.credentials.ts +++ b/packages/@n8n/nodes-langchain/credentials/OllamaApi.credentials.ts @@ -1,4 +1,9 @@ -import type { ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow'; +import type { + ICredentialTestRequest, + ICredentialType, + INodeProperties, + IAuthenticateGeneric, +} from 'n8n-workflow'; export class OllamaApi implements ICredentialType { name = 'ollamaApi'; @@ -15,12 +20,30 @@ export class OllamaApi implements ICredentialType { type: 'string', default: 'http://localhost:11434', }, + { + displayName: 'API Key', + hint: 'When using Ollama behind a proxy with authentication (such as Open WebUI), provide the Bearer token/API key here. This is not required for the default Ollama installation', + name: 'apiKey', + type: 'string', + typeOptions: { password: true }, + default: '', + required: false, + }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '=Bearer {{$credentials.apiKey}}', + }, + }, + }; + test: ICredentialTestRequest = { request: { baseURL: '={{ $credentials.baseUrl }}', - url: '/', + url: '/api/tags', method: 'GET', }, }; diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts index 86a2a9174f..3fb174181f 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts @@ -49,10 +49,16 @@ export class EmbeddingsOllama implements INodeType { this.logger.debug('Supply data for embeddings Ollama'); const modelName = this.getNodeParameter('model', itemIndex) as string; const credentials = await this.getCredentials('ollamaApi'); + const headers = credentials.apiKey + ? { + Authorization: `Bearer ${credentials.apiKey as string}`, + } + : undefined; const embeddings = new OllamaEmbeddings({ baseUrl: credentials.baseUrl as string, model: modelName, + headers, }); return { diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts index 23734a75cd..026da50349 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts @@ -58,6 +58,11 @@ export class LmChatOllama implements INodeType { const modelName = this.getNodeParameter('model', itemIndex) as string; const options = this.getNodeParameter('options', itemIndex, {}) as ChatOllamaInput; + const headers = credentials.apiKey + ? { + Authorization: `Bearer ${credentials.apiKey as string}`, + } + : undefined; const model = new ChatOllama({ ...options, @@ -66,6 +71,7 @@ export class LmChatOllama implements INodeType { format: options.format === 'default' ? undefined : options.format, callbacks: [new N8nLlmTracing(this)], onFailedAttempt: makeN8nLlmFailedAttemptHandler(this), + headers, }); return { diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts index 6dbad1aaaa..540c0c0cab 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts @@ -57,6 +57,11 @@ export class LmOllama implements INodeType { const modelName = this.getNodeParameter('model', itemIndex) as string; const options = this.getNodeParameter('options', itemIndex, {}) as object; + const headers = credentials.apiKey + ? { + Authorization: `Bearer ${credentials.apiKey as string}`, + } + : undefined; const model = new Ollama({ baseUrl: credentials.baseUrl as string, @@ -64,6 +69,7 @@ export class LmOllama implements INodeType { ...options, callbacks: [new N8nLlmTracing(this)], onFailedAttempt: makeN8nLlmFailedAttemptHandler(this), + headers, }); return {