Skip to content

Commit 9befae6

Browse files
authored
Feature/Ollama Cloud (#5655)
add api key for ollama cloud
1 parent 83036b1 commit 9befae6

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class OllamaApi implements INodeCredential {
4+
label: string
5+
name: string
6+
description: string
7+
version: number
8+
inputs: INodeParams[]
9+
10+
constructor() {
11+
this.label = 'Ollama API'
12+
this.name = 'ollamaApi'
13+
this.version = 1.0
14+
this.inputs = [
15+
{
16+
label: 'Ollama Api Key',
17+
name: 'ollamaApiKey',
18+
type: 'password'
19+
}
20+
]
21+
}
22+
}
23+
24+
module.exports = { credClass: OllamaApi }

packages/components/nodes/chatmodels/ChatOllama/ChatOllama.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ChatOllamaInput } from '@langchain/ollama'
22
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
33
import { BaseCache } from '@langchain/core/caches'
4-
import { IMultiModalOption, INode, INodeData, INodeParams } from '../../../src/Interface'
5-
import { getBaseClasses } from '../../../src/utils'
4+
import { ICommonObject, IMultiModalOption, INode, INodeData, INodeParams } from '../../../src/Interface'
5+
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
66
import { ChatOllama } from './FlowiseChatOllama'
77

88
class ChatOllama_ChatModels implements INode {
@@ -26,6 +26,13 @@ class ChatOllama_ChatModels implements INode {
2626
this.category = 'Chat Models'
2727
this.description = 'Chat completion using open-source LLM on Ollama'
2828
this.baseClasses = [this.type, ...getBaseClasses(ChatOllama)]
29+
this.credential = {
30+
label: 'Connect Credential',
31+
name: 'credential',
32+
type: 'credential',
33+
credentialNames: ['ollamaApi'],
34+
optional: true
35+
}
2936
this.inputs = [
3037
{
3138
label: 'Cache',
@@ -214,7 +221,7 @@ class ChatOllama_ChatModels implements INode {
214221
]
215222
}
216223

217-
async init(nodeData: INodeData): Promise<any> {
224+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
218225
const temperature = nodeData.inputs?.temperature as string
219226
const baseUrl = nodeData.inputs?.baseUrl as string
220227
const modelName = nodeData.inputs?.modelName as string
@@ -264,6 +271,14 @@ class ChatOllama_ChatModels implements INode {
264271
}
265272
}
266273

274+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
275+
const ollamaApiKey = getCredentialParam('ollamaApiKey', credentialData, nodeData)
276+
if (ollamaApiKey) {
277+
obj.headers = new Headers({
278+
Authorization: `Bearer ${ollamaApiKey}`
279+
})
280+
}
281+
267282
const model = new ChatOllama(nodeData.id, obj)
268283
model.setMultiModalOption(multiModalOption)
269284
return model

0 commit comments

Comments
 (0)