mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 23:01:09 +03:00
Multimodal: Image Uploads.
This commit is contained in:
@@ -9,6 +9,7 @@ import { FlowiseMemory, ICommonObject, IMessage, INode, INodeData, INodeParams }
|
|||||||
import { AgentExecutor } from '../../../src/agents'
|
import { AgentExecutor } from '../../../src/agents'
|
||||||
import { ChatConversationalAgent } from 'langchain/agents'
|
import { ChatConversationalAgent } from 'langchain/agents'
|
||||||
import { renderTemplate } from '@langchain/core/prompts'
|
import { renderTemplate } from '@langchain/core/prompts'
|
||||||
|
import { injectChainNodeData } from '../../../src/MultiModalUtils'
|
||||||
|
|
||||||
const DEFAULT_PREFIX = `Assistant is a large language model trained by OpenAI.
|
const DEFAULT_PREFIX = `Assistant is a large language model trained by OpenAI.
|
||||||
|
|
||||||
@@ -84,6 +85,8 @@ class ConversationalAgent_Agents implements INode {
|
|||||||
|
|
||||||
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
||||||
const memory = nodeData.inputs?.memory as FlowiseMemory
|
const memory = nodeData.inputs?.memory as FlowiseMemory
|
||||||
|
injectChainNodeData(nodeData, options)
|
||||||
|
|
||||||
const executor = await prepareAgent(nodeData, { sessionId: this.sessionId, chatId: options.chatId, input }, options.chatHistory)
|
const executor = await prepareAgent(nodeData, { sessionId: this.sessionId, chatId: options.chatId, input }, options.chatHistory)
|
||||||
|
|
||||||
const loggerHandler = new ConsoleCallbackHandler(options.logger)
|
const loggerHandler = new ConsoleCallbackHandler(options.logger)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Tool } from 'langchain/tools'
|
|||||||
import { BaseLanguageModel } from 'langchain/base_language'
|
import { BaseLanguageModel } from 'langchain/base_language'
|
||||||
import { flatten } from 'lodash'
|
import { flatten } from 'lodash'
|
||||||
import { additionalCallbacks } from '../../../src/handler'
|
import { additionalCallbacks } from '../../../src/handler'
|
||||||
|
import { injectChainNodeData } from '../../../src/MultiModalUtils'
|
||||||
|
|
||||||
class MRKLAgentChat_Agents implements INode {
|
class MRKLAgentChat_Agents implements INode {
|
||||||
label: string
|
label: string
|
||||||
@@ -54,6 +55,7 @@ class MRKLAgentChat_Agents implements INode {
|
|||||||
|
|
||||||
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
||||||
const executor = nodeData.instance as AgentExecutor
|
const executor = nodeData.instance as AgentExecutor
|
||||||
|
injectChainNodeData(nodeData, options)
|
||||||
|
|
||||||
const callbacks = await additionalCallbacks(nodeData, options)
|
const callbacks = await additionalCallbacks(nodeData, options)
|
||||||
|
|
||||||
|
|||||||
@@ -475,7 +475,8 @@ export class App {
|
|||||||
})
|
})
|
||||||
if (!chatflow) return res.status(404).send(`Chatflow ${req.params.id} not found`)
|
if (!chatflow) return res.status(404).send(`Chatflow ${req.params.id} not found`)
|
||||||
|
|
||||||
const uploadAllowedCategoryNodes = ['Chat Models']
|
const uploadAllowedNodes = ['llmChain', 'conversationChain', 'mrklAgentChat', 'conversationalAgent']
|
||||||
|
const uploadProcessingNodes = ['chatOpenAI']
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const flowObj = JSON.parse(chatflow.flowData)
|
const flowObj = JSON.parse(chatflow.flowData)
|
||||||
@@ -494,26 +495,27 @@ export class App {
|
|||||||
|
|
||||||
let allowImageUploads = false
|
let allowImageUploads = false
|
||||||
flowObj.nodes.forEach((node: IReactFlowNode) => {
|
flowObj.nodes.forEach((node: IReactFlowNode) => {
|
||||||
if (uploadAllowedCategoryNodes.indexOf(node.data.category) > -1) {
|
if (uploadProcessingNodes.indexOf(node.data.name) > -1) {
|
||||||
logger.debug(`[server]: Found Eligible Node ${node.data.type}, Allowing Uploads.`)
|
logger.debug(`[server]: Found Eligible Node ${node.data.type}, Allowing Uploads.`)
|
||||||
|
|
||||||
// there could be multiple components allowing uploads, so we check if it's already added
|
// there could be multiple components allowing uploads, so we check if it's already added
|
||||||
// TODO: for now the maxUploadSize is hardcoded to 5MB, we need to add it to the node properties
|
// TODO: for now the maxUploadSize is hardcoded to 5MB, we need to add it to the node properties
|
||||||
node.data.inputParams.map((param: INodeParams) => {
|
node.data.inputParams.map((param: INodeParams) => {
|
||||||
if (param.name === 'allowImageUploads' && node.data.inputs?.['allowImageUploads'] && !allowImageUploads) {
|
if (param.name === 'allowImageUploads' && node.data.inputs?.['allowImageUploads']) {
|
||||||
allowances.push({
|
allowances.push({
|
||||||
fileTypes: 'image/gif;image/jpeg;image/png;image/webp;'.split(';'),
|
fileTypes: 'image/gif;image/jpeg;image/png;image/webp;'.split(';'),
|
||||||
maxUploadSize: 5
|
maxUploadSize: 5
|
||||||
})
|
})
|
||||||
allowImageUploads = true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else if (uploadAllowedNodes.indexOf(node.data.name) > -1 && !allowImageUploads) {
|
||||||
|
allowImageUploads = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
allowSpeechToText: allowSpeechToText,
|
allowSpeechToText: allowSpeechToText,
|
||||||
isUploadAllowed: allowances.length > 0,
|
isUploadAllowed: allowImageUploads,
|
||||||
uploadFileSizeAndTypes: allowances
|
uploadFileSizeAndTypes: allowances
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user