-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: some bugs for import model (janhq#2181)
* fix: some bugs for import model Signed-off-by: James <[email protected]> Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]>
- Loading branch information
Showing
14 changed files
with
212 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ export type ImportingModel = { | |
status: ImportingModelStatus | ||
format: string | ||
percentage?: number | ||
error?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useCallback } from 'react' | ||
|
||
import { ImportingModel } from '@janhq/core' | ||
import { useSetAtom } from 'jotai' | ||
|
||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
import { snackbar } from '@/containers/Toast' | ||
|
||
import { getFileInfoFromFile } from '@/utils/file' | ||
|
||
import { setImportModelStageAtom } from './useImportModel' | ||
|
||
import { importingModelsAtom } from '@/helpers/atoms/Model.atom' | ||
|
||
export default function useDropModelBinaries() { | ||
const setImportingModels = useSetAtom(importingModelsAtom) | ||
const setImportModelStage = useSetAtom(setImportModelStageAtom) | ||
|
||
const onDropModels = useCallback( | ||
async (acceptedFiles: File[]) => { | ||
const files = await getFileInfoFromFile(acceptedFiles) | ||
|
||
const unsupportedFiles = files.filter( | ||
(file) => !file.path.endsWith('.gguf') | ||
) | ||
const supportedFiles = files.filter((file) => file.path.endsWith('.gguf')) | ||
|
||
const importingModels: ImportingModel[] = supportedFiles.map((file) => ({ | ||
importId: uuidv4(), | ||
modelId: undefined, | ||
name: file.name.replace('.gguf', ''), | ||
description: '', | ||
path: file.path, | ||
tags: [], | ||
size: file.size, | ||
status: 'PREPARING', | ||
format: 'gguf', | ||
})) | ||
if (unsupportedFiles.length > 0) { | ||
snackbar({ | ||
description: `File has to be a .gguf file`, | ||
type: 'error', | ||
}) | ||
} | ||
if (importingModels.length === 0) return | ||
|
||
setImportingModels(importingModels) | ||
setImportModelStage('MODEL_SELECTED') | ||
}, | ||
[setImportModelStage, setImportingModels] | ||
) | ||
|
||
return { onDropModels } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.