Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/components/credentials/Ollama.credential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { INodeParams, INodeCredential } from '../src/Interface'

class OllamaApi implements INodeCredential {
label: string
name: string
description: string
version: number
inputs: INodeParams[]

constructor() {
this.label = 'Ollama API'
this.name = 'ollamaApi'
this.version = 1.0
this.inputs = [
{
label: 'Ollama Api Key',
name: 'ollamaApiKey',
type: 'password'
}
]
}
}

module.exports = { credClass: OllamaApi }
21 changes: 18 additions & 3 deletions packages/components/nodes/chatmodels/ChatOllama/ChatOllama.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChatOllamaInput } from '@langchain/ollama'
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
import { BaseCache } from '@langchain/core/caches'
import { IMultiModalOption, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { ICommonObject, IMultiModalOption, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { ChatOllama } from './FlowiseChatOllama'

class ChatOllama_ChatModels implements INode {
Expand All @@ -26,6 +26,13 @@ class ChatOllama_ChatModels implements INode {
this.category = 'Chat Models'
this.description = 'Chat completion using open-source LLM on Ollama'
this.baseClasses = [this.type, ...getBaseClasses(ChatOllama)]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['ollamaApi'],
optional: true
}
this.inputs = [
{
label: 'Cache',
Expand Down Expand Up @@ -214,7 +221,7 @@ class ChatOllama_ChatModels implements INode {
]
}

async init(nodeData: INodeData): Promise<any> {
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const temperature = nodeData.inputs?.temperature as string
const baseUrl = nodeData.inputs?.baseUrl as string
const modelName = nodeData.inputs?.modelName as string
Expand Down Expand Up @@ -264,6 +271,14 @@ class ChatOllama_ChatModels implements INode {
}
}

const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const ollamaApiKey = getCredentialParam('ollamaApiKey', credentialData, nodeData)
if (ollamaApiKey) {
obj.headers = new Headers({
Authorization: `Bearer ${ollamaApiKey}`
})
}

const model = new ChatOllama(nodeData.id, obj)
model.setMultiModalOption(multiModalOption)
return model
Expand Down