Skip to content

Commit

Permalink
Merge pull request #3997 from janhq/fix/model-import-name
Browse files Browse the repository at this point in the history
fix: remove cuda toolkit error message and bring back incremental model import
  • Loading branch information
louis-jan authored Nov 12, 2024
2 parents 4e91c80 + 3f6fb15 commit 20c467e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 48 deletions.
2 changes: 1 addition & 1 deletion web/hooks/useDropModelBinaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down
22 changes: 18 additions & 4 deletions web/hooks/useImportModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
baseName,

Check warning on line 12 in web/hooks/useImportModel.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'baseName' is defined but never used

Check warning on line 12 in web/hooks/useImportModel.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'baseName' is defined but never used

Check warning on line 12 in web/hooks/useImportModel.ts

View workflow job for this annotation

GitHub Actions / test-on-windows (mcafee)

'baseName' is defined but never used

Check warning on line 12 in web/hooks/useImportModel.ts

View workflow job for this annotation

GitHub Actions / test-on-windows (default-windows-security)

'baseName' is defined but never used

Check warning on line 12 in web/hooks/useImportModel.ts

View workflow job for this annotation

GitHub Actions / test-on-windows (bit-defender)

'baseName' is defined but never used

Check warning on line 12 in web/hooks/useImportModel.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'baseName' is defined but never used

Check warning on line 12 in web/hooks/useImportModel.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'baseName' is defined but never used

Check warning on line 12 in web/hooks/useImportModel.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'baseName' is defined but never used

Check warning on line 12 in web/hooks/useImportModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'baseName' is defined but never used
} from '@janhq/core'

import { atom, useSetAtom } from 'jotai'
import { atom, useAtomValue, useSetAtom } from 'jotai'

import { v4 as uuidv4 } from 'uuid'

Expand All @@ -23,6 +23,7 @@ import { FilePathWithSize } from '@/utils/file'
import { extensionManager } from '@/extension'
import {
addDownloadingModelAtom,
downloadedModelsAtom,
importingModelsAtom,
removeDownloadingModelAtom,
} from '@/helpers/atoms/Model.atom'
Expand Down Expand Up @@ -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
Expand All @@ -78,7 +92,7 @@ const useImportModel = () => {
}
})
},
[addDownloadingModel, removeDownloadingModel]
[addDownloadingModel, incrementalModelName, removeDownloadingModel]
)

const updateModelInfo = useCallback(
Expand All @@ -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: [],
Expand Down
43 changes: 0 additions & 43 deletions web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,49 +64,6 @@ const LoadModelError = () => {
to continue using it.
</p>
)
} else if (
settings &&
settings.run_mode === 'gpu' &&
!settings.vulkan &&
(!settings.nvidia_driver?.exist || !settings.cuda?.exist)
) {
return (
<>
{!settings?.cuda.exist ? (
<p>
The CUDA toolkit may be unavailable. Please use the{' '}
<span
className="cursor-pointer font-medium text-[hsla(var(--app-link))]"
onClick={() => {
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
</span>{' '}
setting to proceed with the download / installation process.
</p>
) : (
<div>
Problem with Nvidia drivers. Please follow the{' '}
<a
className="font-medium text-[hsla(var(--app-link))]"
href="https://www.nvidia.com/Download/index.aspx"
target="_blank"
>
Nvidia Drivers guideline
</a>{' '}
to access installation instructions and ensure proper functioning
of the application.
</div>
)}
</>
)
} else {
return (
<div>
Expand Down

0 comments on commit 20c467e

Please sign in to comment.