From 3f6fb1561b78b034b63fa83241e332e5f6394823 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 12 Nov 2024 12:10:26 +0700 Subject: [PATCH] fix: remove cuda toolkit error message and bring back incremental model import --- web/hooks/useDropModelBinaries.ts | 2 +- web/hooks/useImportModel.ts | 22 ++++++++-- .../LoadModelError/index.tsx | 43 ------------------- 3 files changed, 19 insertions(+), 48 deletions(-) diff --git a/web/hooks/useDropModelBinaries.ts b/web/hooks/useDropModelBinaries.ts index d87e96627e..7c87355f79 100644 --- a/web/hooks/useDropModelBinaries.ts +++ b/web/hooks/useDropModelBinaries.ts @@ -29,7 +29,7 @@ export default function useDropModelBinaries() { const importingModels: ImportingModel[] = supportedFiles.map((file) => ({ importId: uuidv4(), modelId: undefined, - name: file.name.replace('.gguf', ''), + name: file.name.replace(/ /g, '').replace('.gguf', ''), description: '', path: file.path, tags: [], diff --git a/web/hooks/useImportModel.ts b/web/hooks/useImportModel.ts index a2b1f09cb0..c49ddb9645 100644 --- a/web/hooks/useImportModel.ts +++ b/web/hooks/useImportModel.ts @@ -12,7 +12,7 @@ import { baseName, } from '@janhq/core' -import { atom, useSetAtom } from 'jotai' +import { atom, useAtomValue, useSetAtom } from 'jotai' import { v4 as uuidv4 } from 'uuid' @@ -23,6 +23,7 @@ import { FilePathWithSize } from '@/utils/file' import { extensionManager } from '@/extension' import { addDownloadingModelAtom, + downloadedModelsAtom, importingModelsAtom, removeDownloadingModelAtom, } from '@/helpers/atoms/Model.atom' @@ -58,11 +59,24 @@ const useImportModel = () => { const setImportingModels = useSetAtom(importingModelsAtom) const addDownloadingModel = useSetAtom(addDownloadingModelAtom) const removeDownloadingModel = useSetAtom(removeDownloadingModelAtom) + const downloadedModels = useAtomValue(downloadedModelsAtom) + + const incrementalModelName = useCallback( + (name: string, startIndex: number = 0): string => { + const newModelName = startIndex ? `${name}-${startIndex}` : name + if (downloadedModels.some((model) => model.id === newModelName)) { + return incrementalModelName(name, startIndex + 1) + } else { + return newModelName + } + }, + [downloadedModels] + ) const importModels = useCallback( (models: ImportingModel[], optionType: OptionType) => { models.map(async (model) => { - const modelId = model.modelId ?? (await baseName(model.path)) + const modelId = model.modelId ?? incrementalModelName(model.name) if (modelId) { addDownloadingModel(modelId) extensionManager @@ -78,7 +92,7 @@ const useImportModel = () => { } }) }, - [addDownloadingModel, removeDownloadingModel] + [addDownloadingModel, incrementalModelName, removeDownloadingModel] ) const updateModelInfo = useCallback( @@ -100,7 +114,7 @@ const useImportModel = () => { ({ path, name, size }: FilePathWithSize) => ({ importId: uuidv4(), modelId: undefined, - name: name.replace('.gguf', ''), + name: name.replace(/ /g, '').replace('.gguf', ''), description: '', path: path, tags: [], diff --git a/web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx b/web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx index 19a1f628c2..0420b7d51d 100644 --- a/web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx @@ -64,49 +64,6 @@ const LoadModelError = () => { to continue using it.

) - } else if ( - settings && - settings.run_mode === 'gpu' && - !settings.vulkan && - (!settings.nvidia_driver?.exist || !settings.cuda?.exist) - ) { - return ( - <> - {!settings?.cuda.exist ? ( -

- The CUDA toolkit may be unavailable. Please use the{' '} - { - setMainState(MainViewState.Settings) - if (activeThread?.assistants[0]?.model.engine) { - const engine = EngineManager.instance().get( - activeThread.assistants[0].model.engine - ) - engine?.name && setSelectedSettingScreen(engine.name) - } - }} - > - Install Additional Dependencies - {' '} - setting to proceed with the download / installation process. -

- ) : ( -
- Problem with Nvidia drivers. Please follow the{' '} - - Nvidia Drivers guideline - {' '} - to access installation instructions and ensure proper functioning - of the application. -
- )} - - ) } else { return (