(
nodeData: INodeData,
options: ICommonObject,
multiModalOption?: IMultiModalOption
)
| 2 | import { getFileFromStorage } from './storageUtils' |
| 3 | |
| 4 | export const addImagesToMessages = async ( |
| 5 | nodeData: INodeData, |
| 6 | options: ICommonObject, |
| 7 | multiModalOption?: IMultiModalOption |
| 8 | ): Promise<MessageContentImageUrl[]> => { |
| 9 | const imageContent: MessageContentImageUrl[] = [] |
| 10 | let model = nodeData.inputs?.model |
| 11 | |
| 12 | if (llmSupportsVision(model) && multiModalOption) { |
| 13 | // Image Uploaded |
| 14 | if (multiModalOption.image && multiModalOption.image.allowImageUploads && options?.uploads && options?.uploads.length > 0) { |
| 15 | const imageUploads = getImageUploads(options.uploads) |
| 16 | for (const upload of imageUploads) { |
| 17 | let bf = upload.data |
| 18 | if (upload.type == 'stored-file') { |
| 19 | const contents = await getFileFromStorage(upload.name, options.orgId, options.chatflowid, options.chatId) |
| 20 | // as the image is stored in the server, read the file and convert it to base64 |
| 21 | bf = 'data:' + upload.mime + ';base64,' + contents.toString('base64') |
| 22 | |
| 23 | imageContent.push({ |
| 24 | type: 'image_url', |
| 25 | image_url: { |
| 26 | url: bf |
| 27 | } |
| 28 | }) |
| 29 | } else if (upload.type == 'url' && bf) { |
| 30 | imageContent.push({ |
| 31 | type: 'image_url', |
| 32 | image_url: { |
| 33 | url: bf |
| 34 | } |
| 35 | }) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | return imageContent |
| 41 | } |
| 42 | |
| 43 | export const getAudioUploads = (uploads: IFileUpload[]) => { |
| 44 | return uploads.filter((upload: IFileUpload) => upload.mime.startsWith('audio/')) |
no test coverage detected