From 02013639a4eb728aa2045218f850f79fdeaf525a Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Tue, 5 Mar 2024 13:39:08 +0700 Subject: [PATCH 1/2] 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'} +

    + )}
From 8ecd93661d94667316afed4635bf1f5a1f2d792d Mon Sep 17 00:00:00 2001 From: NamH Date: Tue, 5 Mar 2024 14:03:39 +0700 Subject: [PATCH 2/2] fix: replaced user path from app log (#2238) Signed-off-by: James Co-authored-by: James --- web/hooks/useLogs.tsx | 45 +++++++++++++++++++++++++++---------------- web/hooks/usePath.ts | 21 +++++++------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/web/hooks/useLogs.tsx b/web/hooks/useLogs.tsx index fc591405f..91620d6c3 100644 --- a/web/hooks/useLogs.tsx +++ b/web/hooks/useLogs.tsx @@ -1,26 +1,37 @@ -import { - fs, - joinPath, - openFileExplorer, - getJanDataFolderPath, -} from '@janhq/core' +import { useCallback } from 'react' + +import { fs, joinPath, openFileExplorer } from '@janhq/core' +import { useAtomValue } from 'jotai' + +import { janDataFolderPathAtom } from '@/helpers/atoms/AppConfig.atom' export const useLogs = () => { - const getLogs = async (file: string) => { - const path = await joinPath(['file://logs', `${file}.log`]) - if (!(await fs.existsSync(path))) return {} - const logs = await fs.readFileSync(path, 'utf-8') + const janDataFolderPath = useAtomValue(janDataFolderPathAtom) - return logs - } - const openServerLog = async () => { - const janDataFolderPath = await getJanDataFolderPath() + const getLogs = useCallback( + async (file: string) => { + const path = await joinPath(['file://logs', `${file}.log`]) + if (!(await fs.existsSync(path))) return '' + const logs = await fs.readFileSync(path, 'utf-8') + + const sanitizedLogs = logs.replace( + new RegExp(`${janDataFolderPath}\\/`, 'g'), + 'jan-data-folder/' + ) + + return sanitizedLogs + }, + [janDataFolderPath] + ) + + const openServerLog = useCallback(async () => { const fullPath = await joinPath([janDataFolderPath, 'logs', 'server.log']) return openFileExplorer(fullPath) - } + }, [janDataFolderPath]) - const clearServerLog = async () => { + const clearServerLog = useCallback(async () => { await fs.writeFileSync(await joinPath(['file://logs', 'server.log']), '') - } + }, []) + return { getLogs, openServerLog, clearServerLog } } diff --git a/web/hooks/usePath.ts b/web/hooks/usePath.ts index 545cfb6ee..ed784a5c5 100644 --- a/web/hooks/usePath.ts +++ b/web/hooks/usePath.ts @@ -1,16 +1,13 @@ -import { - openFileExplorer, - joinPath, - getJanDataFolderPath, - baseName, -} from '@janhq/core' +import { openFileExplorer, joinPath, baseName } from '@janhq/core' import { useAtomValue } from 'jotai' import { selectedModelAtom } from '@/containers/DropdownListSidebar' +import { janDataFolderPathAtom } from '@/helpers/atoms/AppConfig.atom' import { activeThreadAtom } from '@/helpers/atoms/Thread.atom' export const usePath = () => { + const janDataFolderPath = useAtomValue(janDataFolderPathAtom) const activeThread = useAtomValue(activeThreadAtom) const selectedModel = useAtomValue(selectedModelAtom) @@ -18,7 +15,6 @@ export const usePath = () => { // TODO: this logic should be refactored. if (type !== 'Model' && !activeThread) return - const userSpace = await getJanDataFolderPath() let filePath = undefined const assistantId = activeThread?.assistants[0]?.assistant_id switch (type) { @@ -40,7 +36,7 @@ export const usePath = () => { } if (!filePath) return - const fullPath = await joinPath([userSpace, filePath]) + const fullPath = await joinPath([janDataFolderPath, filePath]) openFileExplorer(fullPath) } @@ -48,7 +44,6 @@ export const usePath = () => { // TODO: this logic should be refactored. if (type !== 'Model' && !activeThread) return - const userSpace = await getJanDataFolderPath() let filePath = undefined const assistantId = activeThread?.assistants[0]?.assistant_id switch (type) { @@ -74,31 +69,29 @@ export const usePath = () => { } if (!filePath) return - const fullPath = await joinPath([userSpace, filePath]) + const fullPath = await joinPath([janDataFolderPath, filePath]) openFileExplorer(fullPath) } const onViewFile = async (id: string) => { if (!activeThread) return - const userSpace = await getJanDataFolderPath() let filePath = undefined id = await baseName(id) filePath = await joinPath(['threads', `${activeThread.id}/files`, `${id}`]) if (!filePath) return - const fullPath = await joinPath([userSpace, filePath]) + const fullPath = await joinPath([janDataFolderPath, filePath]) openFileExplorer(fullPath) } const onViewFileContainer = async () => { if (!activeThread) return - const userSpace = await getJanDataFolderPath() let filePath = undefined filePath = await joinPath(['threads', `${activeThread.id}/files`]) if (!filePath) return - const fullPath = await joinPath([userSpace, filePath]) + const fullPath = await joinPath([janDataFolderPath, filePath]) openFileExplorer(fullPath) }