From 02013639a4eb728aa2045218f850f79fdeaf525a Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Tue, 5 Mar 2024 13:39:08 +0700 Subject: [PATCH] fix: drag and drop support image format when model has vision_model attribute (#2237) --- web/screens/Chat/ChatInput/index.tsx | 8 +++---- web/screens/Chat/index.tsx | 33 +++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/web/screens/Chat/ChatInput/index.tsx b/web/screens/Chat/ChatInput/index.tsx index 052720d6c..a7985a59c 100644 --- a/web/screens/Chat/ChatInput/index.tsx +++ b/web/screens/Chat/ChatInput/index.tsx @@ -165,8 +165,7 @@ const ChatInput: React.FC = () => { if ( fileUpload.length > 0 || (activeThread?.assistants[0].tools && - !activeThread?.assistants[0].tools[0]?.enabled && - !activeThread?.assistants[0].model.settings.vision_model) + !activeThread?.assistants[0].tools[0]?.enabled) ) { e.stopPropagation() } else { @@ -178,8 +177,7 @@ const ChatInput: React.FC = () => { {fileUpload.length > 0 || (activeThread?.assistants[0].tools && - !activeThread?.assistants[0].tools[0]?.enabled && - !activeThread?.assistants[0].model.settings.vision_model && ( + !activeThread?.assistants[0].tools[0]?.enabled && ( {fileUpload.length !== 0 && ( @@ -205,7 +203,7 @@ const ChatInput: React.FC = () => { {showAttacmentMenus && (
  • { const isGeneratingResponse = useAtomValue(isGeneratingResponseAtom) + const acceptedFormat: Accept = activeThread?.assistants[0].model.settings + .vision_model + ? { + 'application/pdf': ['.pdf'], + 'image/jpeg': ['.jpeg'], + 'image/png': ['.png'], + 'image/jpg': ['.jpg'], + } + : { + 'application/pdf': ['.pdf'], + } + const { getRootProps, isDragReject } = useDropzone({ noClick: true, multiple: false, - accept: { - 'application/pdf': ['.pdf'], - }, + accept: acceptedFormat, onDragOver: (e) => { // Retrieval file drag and drop is experimental feature @@ -164,10 +174,21 @@ const ChatScreen: React.FC = () => {
    {isDragReject - ? 'Currently, we only support 1 attachment at the same time with PDF format' + ? `Currently, we only support 1 attachment at the same time with ${ + activeThread?.assistants[0].model.settings + .vision_model + ? 'PDF, JPEG, JPG, PNG' + : 'PDF' + } format` : 'Drop file here'}
    - {!isDragReject &&

    (PDF)

    } + {!isDragReject && ( +

    + {activeThread?.assistants[0].model.settings.vision_model + ? 'PDF, JPEG, JPG, PNG' + : 'PDF'} +

    + )}