11import { ChatOllamaInput } from '@langchain/ollama'
22import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
33import { 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'
66import { ChatOllama } from './FlowiseChatOllama'
77
88class 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