Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Add Multi Modal Capabilities to Flowise #1419

Merged
merged 76 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
c96572e
GPT Vision - OpenAIVisionChain
vinodkiran Nov 25, 2023
73f7046
GPT Vision: Initial implementation of the OpenAI Vision API
vinodkiran Dec 6, 2023
dc265eb
Merge branch 'main' into FEATURE/Vision
vinodkiran Dec 6, 2023
b492153
GPT Vision: Storing filenames only in chat message
vinodkiran Dec 7, 2023
68fbe0e
GPT Vision: Vision Chain Node update along with addition of chatid fo…
vinodkiran Dec 7, 2023
3257582
GPT Vision: Converting vision into Multi Modal. Base Changes.
vinodkiran Dec 8, 2023
1b308a8
making the chain multi-modal. now we accept audio and image uploads a…
vinodkiran Dec 9, 2023
1bd1fd5
MultiModal: Minor adjustments to layout and categorization of node
vinodkiran Dec 13, 2023
c609c63
MultiModal: start integration of audio input (live recording) for Mul…
vinodkiran Dec 13, 2023
826de70
MultiModal: addition of live recording...
vinodkiran Dec 15, 2023
60800db
Merge branch 'main' into FEATURE/Vision
vinodkiran Dec 15, 2023
c6ae3be
Merge branch 'main' into FEATURE/Vision
vinodkiran Dec 20, 2023
d3ce6f8
Merge branch 'main' into FEATURE/Vision
vinodkiran Dec 21, 2023
7f15494
Merge branch 'main' into FEATURE/Vision
HenryHengZJ Jan 8, 2024
f57daea
Merge branch 'main' into FEATURE/Vision
HenryHengZJ Jan 15, 2024
398a31f
UI touchup
HenryHengZJ Jan 17, 2024
8a14a52
GPT Vision: Renaming to OpenAIMultiModalChain and merging the functio…
vinodkiran Jan 18, 2024
1883111
GPT Vision: Fix for error when only speech input is sent.
vinodkiran Jan 18, 2024
9222aaf
GPT Vision: Updated behaviour to submit voice recording directly with…
vinodkiran Jan 18, 2024
f87d849
GPT Vision: lint fixes
vinodkiran Jan 18, 2024
e774bd3
GPT Vision: Added multi model capabilities to ChatOpenAI and Conversa…
vinodkiran Jan 19, 2024
7e5d8e7
Fix image uploads appear on top of chat messages. Now image uploads w…
0xi4o Jan 22, 2024
59643b6
Fix the flickering issue when dragging files over the chat window
0xi4o Jan 22, 2024
7d0ae52
Fix chat popup styles and remove console statements
0xi4o Jan 22, 2024
f384ad9
Update audio recording ui in internal chat
0xi4o Jan 22, 2024
318686e
Fix issue where audio recording is not sent on stopping recording
0xi4o Jan 23, 2024
3ce22d0
MultiModal : Adding functionality to base OpenAI Chat Model
vinodkiran Jan 24, 2024
d61e3d5
SpeechToText: Adding SpeechToText at the Chatflow level.
vinodkiran Jan 27, 2024
517c2f2
Fix error message when audio recording is not available
0xi4o Jan 30, 2024
1d12208
Fix auto scroll on audio messages
0xi4o Jan 30, 2024
4604594
SpeechToText: Adding SpeechToText at the Chatflow level.
vinodkiran Jan 31, 2024
e81927e
SpeechToText: Adding SpeechToText at the Chatflow level.
vinodkiran Jan 31, 2024
5c8f48c
Multimodal: Image Uploads.
vinodkiran Feb 1, 2024
aa5d141
Multimodal: deleting uploads on delete of all chatmessages
vinodkiran Feb 1, 2024
eab8c19
Multimodal: deleting uploads on delete of all chatmessages or chatflow
vinodkiran Feb 1, 2024
9cd0362
Merge branch 'main' into FEATURE/Vision
HenryHengZJ Feb 2, 2024
a219efc
Rename MultiModalUtils.ts to multiModalUtils.ts
HenryHengZJ Feb 2, 2024
c5bd4d4
address configuration fix and add BLOB_STORAGE_PATH env variable
HenryHengZJ Feb 2, 2024
a4131dc
add fixes for chaining
HenryHengZJ Feb 2, 2024
041bfea
add more params
HenryHengZJ Feb 2, 2024
c504f91
Multimodal: guard to check for nodeData before image message insertion.
vinodkiran Feb 2, 2024
8c494cf
Fix UI issues - chat window height, image & audio styling, and image …
0xi4o Feb 6, 2024
9072e69
Return uploads config in public chatbot config endpoint
0xi4o Feb 12, 2024
0a54db7
Update how uploads config is sent
0xi4o Feb 12, 2024
11219c6
Fix audio recording not sending when recording stops
0xi4o Feb 13, 2024
2056703
Check if uploads are enabled/changed on chatflow save and update chat…
0xi4o Feb 14, 2024
56b2186
Send uploads config if available, even when chatbot config is not ava…
0xi4o Feb 14, 2024
dcb1ad1
Merge branch 'main' into FEATURE/Vision
HenryHengZJ Feb 14, 2024
86da67f
add missing human text when image presents
HenryHengZJ Feb 14, 2024
44c1f54
Showing image/audio files in the View Messages Dialog
vinodkiran Feb 14, 2024
a71c5a1
fix for concurrent requests for media handling
vinodkiran Feb 14, 2024
85809a9
fix for concurrency
HenryHengZJ Feb 14, 2024
6acc921
ViewMessages->Export Messages. Add Fullpath of the image/audio file.
vinodkiran Feb 14, 2024
9c874bb
Concurrency fixes - correcting wrong id
vinodkiran Feb 15, 2024
52ffa17
Multimodal Fixes...removing all static methods/variables.
vinodkiran Feb 15, 2024
10fc1bf
Multimodal Fixes for cyclic (circular) dependencies during langsmith …
vinodkiran Feb 16, 2024
81c07dc
Update UI of speech to text dialog
0xi4o Feb 19, 2024
5aa991a
Update how uploads are shown in view messages dialog
0xi4o Feb 19, 2024
46c4701
Merge branch 'main' into FEATURE/Vision
HenryHengZJ Feb 19, 2024
d313dc6
Show transcribed audio inputs as message along with audio clip in int…
0xi4o Feb 19, 2024
8bad360
Remove status indicator in speech to text configuration
0xi4o Feb 19, 2024
b31e871
reverting all image upload logic to individual chains/agents
vinodkiran Feb 19, 2024
97a376d
Fix local state sync issue, STT auth issue, and add none option for s…
0xi4o Feb 20, 2024
51c2a93
Merge remote-tracking branch 'origin/FEATURE/Vision' into FEATURE/Vision
vinodkiran Feb 20, 2024
0bc8559
Merge branch 'main' into FEATURE/Vision
vinodkiran Feb 20, 2024
4cee518
image uploads for mrkl agent
vinodkiran Feb 20, 2024
d172802
Merge branch 'main' into feature/Vision
HenryHengZJ Feb 21, 2024
a48edcd
touchup fixes
HenryHengZJ Feb 21, 2024
4071fe5
add default none option
HenryHengZJ Feb 21, 2024
35d3b93
Merge branch 'main' into feature/Vision
HenryHengZJ Feb 21, 2024
e86550a
update marketplace templates
HenryHengZJ Feb 22, 2024
7e84268
Add content-disposition package for handling content disposition resp…
0xi4o Feb 23, 2024
e55975e
Revert useEffect in async dropdown and input components
0xi4o Feb 23, 2024
b884e93
fix speech to text dialog credential, fix url changed when clicked se…
HenryHengZJ Feb 24, 2024
bca7e82
Merge branch 'main' into FEATURE/Vision
HenryHengZJ Feb 26, 2024
68ac61c
fix speech to dialog state
HenryHengZJ Feb 26, 2024
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
1 change: 1 addition & 0 deletions CONTRIBUTING-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Flowise 支持不同的环境变量来配置您的实例。您可以在 `package
| FLOWISE_PASSWORD | 登录密码 | 字符串 | |
| FLOWISE_FILE_SIZE_LIMIT | 上传文件大小限制 | 字符串 | 50mb |
| DEBUG | 打印组件的日志 | 布尔值 | |
| BLOB_STORAGE_PATH | 存储位置 | 字符串 | `your-home-dir/.flowise/storage` |
| LOG_PATH | 存储日志文件的位置 | 字符串 | `your-path/Flowise/logs` |
| LOG_LEVEL | 日志的不同级别 | 枚举字符串: `error`, `info`, `verbose`, `debug` | `info` |
| APIKEY_PATH | 存储 API 密钥的位置 | 字符串 | `your-path/Flowise/packages/server` |
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Flowise support different environment variables to configure your instance. You
| FLOWISE_PASSWORD | Password to login | String | |
| FLOWISE_FILE_SIZE_LIMIT | Upload File Size Limit | String | 50mb |
| DEBUG | Print logs from components | Boolean | |
| BLOB_STORAGE_PATH | Location where uploaded files are stored | String | `your-home-dir/.flowise/storage` |
| LOG_PATH | Location where log files are stored | String | `your-path/Flowise/logs` |
| LOG_LEVEL | Different levels of logs | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
| APIKEY_PATH | Location where api keys are saved | String | `your-path/Flowise/packages/server` |
Expand Down
1 change: 1 addition & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ DATABASE_PATH=/root/.flowise
APIKEY_PATH=/root/.flowise
SECRETKEY_PATH=/root/.flowise
LOG_PATH=/root/.flowise/logs
BLOB_STORAGE_PATH=/root/.flowise/storage

# CORS_ORIGINS="*"
# IFRAME_ORIGINS="*"
Expand Down
1 change: 1 addition & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ If you like to persist your data (flows, logs, apikeys, credentials), set these
- APIKEY_PATH=/root/.flowise
- LOG_PATH=/root/.flowise/logs
- SECRETKEY_PATH=/root/.flowise
- BLOB_STORAGE_PATH=/root/.flowise/storage

Flowise also support different environment variables to configure your instance. Read [more](https://docs.flowiseai.com/environment-variables)
1 change: 1 addition & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ services:
- FLOWISE_SECRETKEY_OVERWRITE=${FLOWISE_SECRETKEY_OVERWRITE}
- LOG_LEVEL=${LOG_LEVEL}
- LOG_PATH=${LOG_PATH}
- BLOB_STORAGE_PATH=${BLOB_STORAGE_PATH}
- DISABLE_FLOWISE_TELEMETRY=${DISABLE_FLOWISE_TELEMETRY}
ports:
- '${PORT}:${PORT}'
Expand Down
23 changes: 23 additions & 0 deletions packages/components/credentials/AssemblyAI.credential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { INodeParams, INodeCredential } from '../src/Interface'

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

constructor() {
this.label = 'AssemblyAI API'
this.name = 'assemblyAIApi'
this.version = 1.0
this.inputs = [
{
label: 'AssemblyAI Api Key',
name: 'assemblyAIApiKey',
type: 'password'
}
]
}
}

module.exports = { credClass: AssemblyAIApi }
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { BaseChatModel } from '@langchain/core/language_models/chat_models'
import { AIMessage, BaseMessage, HumanMessage } from '@langchain/core/messages'
import { ChainValues } from '@langchain/core/utils/types'
import { AgentStep } from '@langchain/core/agents'
import { renderTemplate } from '@langchain/core/prompts'
import { renderTemplate, MessagesPlaceholder } from '@langchain/core/prompts'
import { RunnableSequence } from '@langchain/core/runnables'
import { ChatConversationalAgent } from 'langchain/agents'
import { getBaseClasses } from '../../../src/utils'
import { ConsoleCallbackHandler, CustomChainHandler, additionalCallbacks } from '../../../src/handler'
import { FlowiseMemory, ICommonObject, IMessage, INode, INodeData, INodeParams } from '../../../src/Interface'
import { AgentExecutor } from '../../../src/agents'
import { ChatOpenAI } from '../../chatmodels/ChatOpenAI/FlowiseChatOpenAI'
import { addImagesToMessages } from '../../../src/multiModalUtils'

const DEFAULT_PREFIX = `Assistant is a large language model trained by OpenAI.

Expand Down Expand Up @@ -81,12 +83,19 @@ class ConversationalAgent_Agents implements INode {
}

async init(nodeData: INodeData, input: string, options: ICommonObject): Promise<any> {
return prepareAgent(nodeData, { sessionId: this.sessionId, chatId: options.chatId, input }, options.chatHistory)
return prepareAgent(nodeData, options, { sessionId: this.sessionId, chatId: options.chatId, input }, options.chatHistory)
}

async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
const memory = nodeData.inputs?.memory as FlowiseMemory
const executor = await prepareAgent(nodeData, { sessionId: this.sessionId, chatId: options.chatId, input }, options.chatHistory)

const executor = await prepareAgent(
nodeData,
options,
{ sessionId: this.sessionId, chatId: options.chatId, input },
options.chatHistory
)
// injectAgentExecutorNodeData(executor, nodeData, options)

const loggerHandler = new ConsoleCallbackHandler(options.logger)
const callbacks = await additionalCallbacks(nodeData, options)
Expand Down Expand Up @@ -120,6 +129,7 @@ class ConversationalAgent_Agents implements INode {

const prepareAgent = async (
nodeData: INodeData,
options: ICommonObject,
flowObj: { sessionId?: string; chatId?: string; input?: string },
chatHistory: IMessage[] = []
) => {
Expand All @@ -131,11 +141,6 @@ const prepareAgent = async (
const memoryKey = memory.memoryKey ? memory.memoryKey : 'chat_history'
const inputKey = memory.inputKey ? memory.inputKey : 'input'

/** Bind a stop token to the model */
const modelWithStop = model.bind({
stop: ['\nObservation']
})

const outputParser = ChatConversationalAgent.getDefaultOutputParser({
llm: model,
toolNames: tools.map((tool) => tool.name)
Expand All @@ -146,6 +151,41 @@ const prepareAgent = async (
outputParser
})

if (model instanceof ChatOpenAI) {
let humanImageMessages: HumanMessage[] = []
const messageContent = addImagesToMessages(nodeData, options, model.multiModalOption)

if (messageContent?.length) {
// Change model to gpt-4-vision
model.modelName = 'gpt-4-vision-preview'

// Change default max token to higher when using gpt-4-vision
model.maxTokens = 1024

for (const msg of messageContent) {
humanImageMessages.push(new HumanMessage({ content: [msg] }))
}

// Pop the `agent_scratchpad` MessagePlaceHolder
let messagePlaceholder = prompt.promptMessages.pop() as MessagesPlaceholder

// Add the HumanMessage for images
prompt.promptMessages.push(...humanImageMessages)

// Add the `agent_scratchpad` MessagePlaceHolder back
prompt.promptMessages.push(messagePlaceholder)
} else {
// revert to previous values if image upload is empty
model.modelName = model.configuredModel
model.maxTokens = model.configuredMaxToken
}
}

/** Bind a stop token to the model */
const modelWithStop = model.bind({
stop: ['\nObservation']
})

const runnableAgent = RunnableSequence.from([
{
[inputKey]: (i: { input: string; steps: AgentStep[] }) => i.input,
Expand All @@ -166,7 +206,7 @@ const prepareAgent = async (
sessionId: flowObj?.sessionId,
chatId: flowObj?.chatId,
input: flowObj?.input,
verbose: process.env.DEBUG === 'true' ? true : false
verbose: process.env.DEBUG === 'true'
})

return executor
Expand Down
32 changes: 29 additions & 3 deletions packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { additionalCallbacks } from '../../../src/handler'
import { FlowiseMemory, ICommonObject, IMessage, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { createReactAgent } from '../../../src/agents'
import { ChatOpenAI } from '../../chatmodels/ChatOpenAI/FlowiseChatOpenAI'
import { HumanMessage } from '@langchain/core/messages'
import { addImagesToMessages } from '../../../src/multiModalUtils'
import { ChatPromptTemplate, HumanMessagePromptTemplate } from 'langchain/prompts'

class MRKLAgentChat_Agents implements INode {
label: string
Expand Down Expand Up @@ -61,19 +65,41 @@ class MRKLAgentChat_Agents implements INode {
let tools = nodeData.inputs?.tools as Tool[]
tools = flatten(tools)

const promptWithChat = await pull<PromptTemplate>('hwchase17/react-chat')
const prompt = await pull<PromptTemplate>('hwchase17/react-chat')
let chatPromptTemplate = undefined

if (model instanceof ChatOpenAI) {
const messageContent = addImagesToMessages(nodeData, options, model.multiModalOption)

if (messageContent?.length) {
// Change model to gpt-4-vision
model.modelName = 'gpt-4-vision-preview'

// Change default max token to higher when using gpt-4-vision
model.maxTokens = 1024

const oldTemplate = prompt.template as string
chatPromptTemplate = ChatPromptTemplate.fromMessages([HumanMessagePromptTemplate.fromTemplate(oldTemplate)])
chatPromptTemplate.promptMessages.push(new HumanMessage({ content: messageContent }))
} else {
// revert to previous values if image upload is empty
model.modelName = model.configuredModel
model.maxTokens = model.configuredMaxToken
}
}

const agent = await createReactAgent({
llm: model,
tools,
prompt: promptWithChat
prompt: chatPromptTemplate ?? prompt
})

const executor = new AgentExecutor({
agent,
tools,
verbose: process.env.DEBUG === 'true' ? true : false
verbose: process.env.DEBUG === 'true'
})
// injectLcAgentExecutorNodeData(executor, nodeData, options)

const callbacks = await additionalCallbacks(nodeData, options)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { ConversationChain } from 'langchain/chains'
import { ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate } from '@langchain/core/prompts'
import { BaseChatModel } from '@langchain/core/language_models/chat_models'
import { RunnableSequence } from '@langchain/core/runnables'
import { StringOutputParser } from '@langchain/core/output_parsers'
import { HumanMessage } from '@langchain/core/messages'
import { ConsoleCallbackHandler as LCConsoleCallbackHandler } from '@langchain/core/tracers/console'
import { ConversationChain } from 'langchain/chains'
import { FlowiseMemory, ICommonObject, IMessage, INode, INodeData, INodeParams } from '../../../src/Interface'
import { ConsoleCallbackHandler, CustomChainHandler, additionalCallbacks } from '../../../src/handler'
import { getBaseClasses, handleEscapeCharacters } from '../../../src/utils'
import { checkInputs, Moderation, streamResponse } from '../../moderation/Moderation'
import { formatResponse } from '../../outputparsers/OutputParserHelpers'
import { addImagesToMessages } from '../../../src/multiModalUtils'
import { ChatOpenAI } from '../../chatmodels/ChatOpenAI/FlowiseChatOpenAI'
import { FlowiseMemory, ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { ConsoleCallbackHandler, CustomChainHandler, additionalCallbacks } from '../../../src/handler'
import { getBaseClasses, handleEscapeCharacters } from '../../../src/utils'

let systemMessage = `The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.`
const inputKey = 'input'
Expand Down Expand Up @@ -86,12 +88,14 @@ class ConversationChain_Chains implements INode {
}

async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const chain = prepareChain(nodeData, this.sessionId, options.chatHistory)
const chain = prepareChain(nodeData, options, this.sessionId)
return chain
}

async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string | object> {
const memory = nodeData.inputs?.memory

const chain = prepareChain(nodeData, options, this.sessionId)
const moderations = nodeData.inputs?.inputModeration as Moderation[]

if (moderations && moderations.length > 0) {
Expand All @@ -105,8 +109,6 @@ class ConversationChain_Chains implements INode {
}
}

const chain = prepareChain(nodeData, this.sessionId, options.chatHistory)

const loggerHandler = new ConsoleCallbackHandler(options.logger)
const additionalCallback = await additionalCallbacks(nodeData, options)

Expand Down Expand Up @@ -143,20 +145,18 @@ class ConversationChain_Chains implements INode {
}
}

const prepareChatPrompt = (nodeData: INodeData) => {
const prepareChatPrompt = (nodeData: INodeData, humanImageMessages: HumanMessage[]) => {
const memory = nodeData.inputs?.memory as FlowiseMemory
const prompt = nodeData.inputs?.systemMessagePrompt as string
const chatPromptTemplate = nodeData.inputs?.chatPromptTemplate as ChatPromptTemplate

if (chatPromptTemplate && chatPromptTemplate.promptMessages.length) {
const sysPrompt = chatPromptTemplate.promptMessages[0]
const humanPrompt = chatPromptTemplate.promptMessages[chatPromptTemplate.promptMessages.length - 1]
const chatPrompt = ChatPromptTemplate.fromMessages([
sysPrompt,
new MessagesPlaceholder(memory.memoryKey ?? 'chat_history'),
humanPrompt
])
const messages = [sysPrompt, new MessagesPlaceholder(memory.memoryKey ?? 'chat_history'), humanPrompt]
if (humanImageMessages.length) messages.push(...humanImageMessages)

const chatPrompt = ChatPromptTemplate.fromMessages(messages)
if ((chatPromptTemplate as any).promptValues) {
// @ts-ignore
chatPrompt.promptValues = (chatPromptTemplate as any).promptValues
Expand All @@ -165,21 +165,46 @@ const prepareChatPrompt = (nodeData: INodeData) => {
return chatPrompt
}

const chatPrompt = ChatPromptTemplate.fromMessages([
const messages = [
SystemMessagePromptTemplate.fromTemplate(prompt ? prompt : systemMessage),
new MessagesPlaceholder(memory.memoryKey ?? 'chat_history'),
HumanMessagePromptTemplate.fromTemplate(`{${inputKey}}`)
])
]
if (humanImageMessages.length) messages.push(...(humanImageMessages as any[]))

const chatPrompt = ChatPromptTemplate.fromMessages(messages)

return chatPrompt
}

const prepareChain = (nodeData: INodeData, sessionId?: string, chatHistory: IMessage[] = []) => {
const model = nodeData.inputs?.model as BaseChatModel
const prepareChain = (nodeData: INodeData, options: ICommonObject, sessionId?: string) => {
const chatHistory = options.chatHistory
let model = nodeData.inputs?.model as ChatOpenAI
const memory = nodeData.inputs?.memory as FlowiseMemory
const memoryKey = memory.memoryKey ?? 'chat_history'

const chatPrompt = prepareChatPrompt(nodeData)
let humanImageMessages: HumanMessage[] = []
if (model instanceof ChatOpenAI) {
const messageContent = addImagesToMessages(nodeData, options, model.multiModalOption)

if (messageContent?.length) {
// Change model to gpt-4-vision
model.modelName = 'gpt-4-vision-preview'

// Change default max token to higher when using gpt-4-vision
model.maxTokens = 1024

for (const msg of messageContent) {
humanImageMessages.push(new HumanMessage({ content: [msg] }))
}
} else {
// revert to previous values if image upload is empty
model.modelName = model.configuredModel
model.maxTokens = model.configuredMaxToken
}
}

const chatPrompt = prepareChatPrompt(nodeData, humanImageMessages)
let promptVariables = {}
const promptValuesRaw = (chatPrompt as any).promptValues
if (promptValuesRaw) {
Expand All @@ -203,7 +228,7 @@ const prepareChain = (nodeData: INodeData, sessionId?: string, chatHistory: IMes
},
...promptVariables
},
chatPrompt,
prepareChatPrompt(nodeData, humanImageMessages),
model,
new StringOutputParser()
])
Expand Down
Loading
Loading