@@ -5,7 +5,7 @@ import * as path from 'path'
5
5
import { JSDOM } from 'jsdom'
6
6
import { z } from 'zod'
7
7
import { DataSource } from 'typeorm'
8
- import { ICommonObject , IDatabaseEntity , IDocument , IMessage , INodeData , IVariable , MessageContentImageUrl } from './Interface'
8
+ import { ICommonObject , IDatabaseEntity , IFileUpload , IMessage , INodeData , IVariable , MessageContentImageUrl } from './Interface'
9
9
import { AES , enc } from 'crypto-js'
10
10
import { omit } from 'lodash'
11
11
import { AIMessage , HumanMessage , BaseMessage } from '@langchain/core/messages'
@@ -718,10 +718,10 @@ export const mapChatMessageToBaseMessage = async (chatmessages: any[] = []): Pro
718
718
// example: [{"type":"stored-file","name":"0_DiXc4ZklSTo3M8J4.jpg","mime":"image/jpeg"}]
719
719
try {
720
720
let messageWithFileUploads = ''
721
- const uploads = JSON . parse ( message . fileUploads )
721
+ const uploads : IFileUpload [ ] = JSON . parse ( message . fileUploads )
722
722
const imageContents : MessageContentImageUrl [ ] = [ ]
723
723
for ( const upload of uploads ) {
724
- if ( upload . type === 'stored-file' && upload . mime . startsWith ( 'image' ) ) {
724
+ if ( upload . type === 'stored-file' && upload . mime . startsWith ( 'image/ ' ) ) {
725
725
const fileData = await getFileFromStorage ( upload . name , message . chatflowid , message . chatId )
726
726
// as the image is stored in the server, read the file and convert it to base64
727
727
const bf = 'data:' + upload . mime + ';base64,' + fileData . toString ( 'base64' )
@@ -732,7 +732,7 @@ export const mapChatMessageToBaseMessage = async (chatmessages: any[] = []): Pro
732
732
url : bf
733
733
}
734
734
} )
735
- } else if ( upload . type === 'url' && upload . mime . startsWith ( 'image' ) ) {
735
+ } else if ( upload . type === 'url' && upload . mime . startsWith ( 'image' ) && upload . data ) {
736
736
imageContents . push ( {
737
737
type : 'image_url' ,
738
738
image_url : {
@@ -748,14 +748,15 @@ export const mapChatMessageToBaseMessage = async (chatmessages: any[] = []): Pro
748
748
chatflowid : message . chatflowid ,
749
749
chatId : message . chatId
750
750
}
751
+ let fileInputFieldFromMimeType = 'txtFile'
752
+ fileInputFieldFromMimeType = mapMimeTypeToInputField ( upload . mime )
751
753
const nodeData = {
752
754
inputs : {
753
- txtFile : `FILE-STORAGE::${ JSON . stringify ( [ upload . name ] ) } `
755
+ [ fileInputFieldFromMimeType ] : `FILE-STORAGE::${ JSON . stringify ( [ upload . name ] ) } `
754
756
}
755
757
}
756
- const documents : IDocument [ ] = await fileLoaderNodeInstance . init ( nodeData , '' , options )
757
- const pageContents = documents . map ( ( doc ) => doc . pageContent ) . join ( '\n' )
758
- messageWithFileUploads += `<doc name='${ upload . name } '>${ pageContents } </doc>\n\n`
758
+ const documents : string = await fileLoaderNodeInstance . init ( nodeData , '' , options )
759
+ messageWithFileUploads += `<doc name='${ upload . name } '>${ documents } </doc>\n\n`
759
760
}
760
761
}
761
762
const messageContent = messageWithFileUploads ? `${ messageWithFileUploads } \n\n${ message . content } ` : message . content
0 commit comments