Skip to content

Commit af81d87

Browse files
wggcchHenryHengZJ
andauthored
feat: allow image uploads for ChatLitellm (#5697)
* feat(ChatLitellm.ts): update the LiteLLM Chat Node to support Image Uploads, like AzureOpenAI or OpenAI https://docs.flowiseai.com/using-flowise/uploads https://docs.flowiseai.com/using-flowise/uploads docs can be adjusted for this ChatLiteLLM node * Update ChatLitellm.ts --------- Co-authored-by: Henry Heng <henryheng@flowiseai.com>
1 parent 8bb0564 commit af81d87

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

packages/components/nodes/chatmodels/ChatLitellm/ChatLitellm.ts

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { OpenAIChatInput, ChatOpenAI } from '@langchain/openai'
1+
import { OpenAIChatInput, ChatOpenAI as LangchainChatOpenAI } from '@langchain/openai'
22
import { BaseCache } from '@langchain/core/caches'
33
import { BaseLLMParams } from '@langchain/core/language_models/llms'
4-
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
4+
import { ICommonObject, IMultiModalOption, INode, INodeData, INodeParams } from '../../../src/Interface'
55
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
6+
import { ChatOpenAI } from '../ChatOpenAI/FlowiseChatOpenAI'
67

78
class ChatLitellm_ChatModels implements INode {
89
label: string
@@ -19,12 +20,12 @@ class ChatLitellm_ChatModels implements INode {
1920
constructor() {
2021
this.label = 'ChatLitellm'
2122
this.name = 'chatLitellm'
22-
this.version = 1.0
23+
this.version = 2.0
2324
this.type = 'ChatLitellm'
2425
this.icon = 'litellm.jpg'
2526
this.category = 'Chat Models'
2627
this.description = 'Connect to a Litellm server using OpenAI-compatible API'
27-
this.baseClasses = [this.type, 'BaseChatModel', ...getBaseClasses(ChatOpenAI)]
28+
this.baseClasses = [this.type, 'BaseChatModel', ...getBaseClasses(LangchainChatOpenAI)]
2829
this.credential = {
2930
label: 'Connect Credential',
3031
name: 'credential',
@@ -90,6 +91,40 @@ class ChatLitellm_ChatModels implements INode {
9091
step: 1,
9192
optional: true,
9293
additionalParams: true
94+
},
95+
{
96+
label: 'Allow Image Uploads',
97+
name: 'allowImageUploads',
98+
type: 'boolean',
99+
description:
100+
'Allow image input. Image uploads need a model marked supports_vision=true in LiteLLM. Refer to the <a href="https://docs.flowiseai.com/using-flowise/uploads#image" target="_blank">docs</a> for more details.',
101+
default: false,
102+
optional: true
103+
},
104+
{
105+
label: 'Image Resolution',
106+
description: 'This parameter controls the resolution in which the model views the image.',
107+
name: 'imageResolution',
108+
type: 'options',
109+
options: [
110+
{
111+
label: 'Low',
112+
name: 'low'
113+
},
114+
{
115+
label: 'High',
116+
name: 'high'
117+
},
118+
{
119+
label: 'Auto',
120+
name: 'auto'
121+
}
122+
],
123+
default: 'low',
124+
optional: false,
125+
show: {
126+
allowImageUploads: true
127+
}
93128
}
94129
]
95130
}
@@ -103,6 +138,8 @@ class ChatLitellm_ChatModels implements INode {
103138
const maxTokens = nodeData.inputs?.maxTokens as string
104139
const topP = nodeData.inputs?.topP as string
105140
const timeout = nodeData.inputs?.timeout as string
141+
const allowImageUploads = nodeData.inputs?.allowImageUploads as boolean
142+
const imageResolution = nodeData.inputs?.imageResolution as string
106143

107144
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
108145
const apiKey = getCredentialParam('litellmApiKey', credentialData, nodeData)
@@ -129,7 +166,15 @@ class ChatLitellm_ChatModels implements INode {
129166
obj.apiKey = apiKey
130167
}
131168

132-
const model = new ChatOpenAI(obj)
169+
const multiModalOption: IMultiModalOption = {
170+
image: {
171+
allowImageUploads: allowImageUploads ?? false,
172+
imageResolution
173+
}
174+
}
175+
176+
const model = new ChatOpenAI(nodeData.id, obj)
177+
model.setMultiModalOption(multiModalOption)
133178

134179
return model
135180
}

0 commit comments

Comments
 (0)