Bugfix/Prevent sending non image file (#3173)

* bugfix to prevent sending non image file

* fix typo
This commit is contained in:
Henry Heng
2024-09-09 21:02:47 +01:00
committed by GitHub
parent 1e8839e21b
commit 474793486b
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -616,7 +616,7 @@ export const mapChatMessageToBaseMessage = async (chatmessages: any[] = []): Pro
const uploads = JSON.parse(message.fileUploads) const uploads = JSON.parse(message.fileUploads)
const imageContents: MessageContentImageUrl[] = [] const imageContents: MessageContentImageUrl[] = []
for (const upload of uploads) { for (const upload of uploads) {
if (upload.type === 'stored-file') { if (upload.type === 'stored-file' && upload.mime.startsWith('image')) {
const fileData = await getFileFromStorage(upload.name, message.chatflowid, message.chatId) const fileData = await getFileFromStorage(upload.name, message.chatflowid, message.chatId)
// as the image is stored in the server, read the file and convert it to base64 // as the image is stored in the server, read the file and convert it to base64
const bf = 'data:' + upload.mime + ';base64,' + fileData.toString('base64') const bf = 'data:' + upload.mime + ';base64,' + fileData.toString('base64')
@@ -627,7 +627,7 @@ export const mapChatMessageToBaseMessage = async (chatmessages: any[] = []): Pro
url: bf url: bf
} }
}) })
} else if (upload.type === 'url') { } else if (upload.type === 'url' && upload.mime.startsWith('image')) {
imageContents.push({ imageContents.push({
type: 'image_url', type: 'image_url',
image_url: { image_url: {
@@ -203,7 +203,7 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
} }
if (filePaths.length) msg.filePaths = filePaths if (filePaths.length) msg.filePaths = filePaths
if (chatmsg.sourceDocuments) msg.sourceDocuments = chatmsg.sourceDocuments if (chatmsg.sourceDocuments) msg.sourceDocuments = chatmsg.sourceDocuments
if (chatmsg.usedTools) msg.usedTools = Jchatmsg.usedTools if (chatmsg.usedTools) msg.usedTools = chatmsg.usedTools
if (chatmsg.fileAnnotations) msg.fileAnnotations = chatmsg.fileAnnotations if (chatmsg.fileAnnotations) msg.fileAnnotations = chatmsg.fileAnnotations
if (chatmsg.feedback) msg.feedback = chatmsg.feedback?.content if (chatmsg.feedback) msg.feedback = chatmsg.feedback?.content
if (chatmsg.agentReasoning) msg.agentReasoning = chatmsg.agentReasoning if (chatmsg.agentReasoning) msg.agentReasoning = chatmsg.agentReasoning