NamH ec9b5bf682
fix: update new api from cortex to support 0.5.0 (#3221)
* fix: update new api from cortex to support 0.5.0

Signed-off-by: James <namnh0122@gmail.com>

* fix stop button for streaming

Signed-off-by: James <namnh0122@gmail.com>

* fix stop inference for nonstreaming

Signed-off-by: James <namnh0122@gmail.com>

* chore: remove umami prevent tracking call to vercel

Signed-off-by: James <namnh0122@gmail.com>

* add warning modal when running more than 2 model concurrently

Signed-off-by: James <namnh0122@gmail.com>

* fix: skip summarize if abort

Signed-off-by: James <namnh0122@gmail.com>

* 0.5.0-3

* add inference error popup

Signed-off-by: James <namnh0122@gmail.com>

* add back import local model

Signed-off-by: James <namnh0122@gmail.com>

* fix: max token issue (#3225)

Signed-off-by: James <namnh0122@gmail.com>

* format status

Signed-off-by: James <namnh0122@gmail.com>

* fix migration missing instructions

Signed-off-by: James <namnh0122@gmail.com>

* fix: wait for cortex process overlay should be on top (#3224)

* fix: wait for cortex process overlay should be on top

* chore: update cortex.js

* Cortex 0.5.0-5

* add import model to my model screen

Signed-off-by: James <namnh0122@gmail.com>

* fix: should migrate symlink models (#3226)

* fix import on windows (#3229)

Signed-off-by: James <namnh0122@gmail.com>

* fix yarn lint

Signed-off-by: James <namnh0122@gmail.com>

* fix: clean up port before start jan (#3232)

Signed-off-by: James <namnh0122@gmail.com>

---------

Signed-off-by: James <namnh0122@gmail.com>
Co-authored-by: Van Pham <64197333+Van-QA@users.noreply.github.com>
Co-authored-by: Louis <louis@jan.ai>
2024-08-02 09:37:04 +07:00

119 lines
3.5 KiB
TypeScript

import { useCallback } from 'react'
import { ImportingModel, SelectFileOption } from '@janhq/core'
import { Button, Modal } from '@janhq/joi'
import { useSetAtom, useAtomValue } from 'jotai'
import { snackbar } from '@/containers/Toast'
import {
setImportModelStageAtom,
getImportModelStageAtom,
} from '@/hooks/useImportModel'
import { importingModelsAtom } from '@/helpers/atoms/Model.atom'
const ChooseWhatToImportModal = () => {
const setImportModelStage = useSetAtom(setImportModelStageAtom)
const setImportingModels = useSetAtom(importingModelsAtom)
const importModelStage = useAtomValue(getImportModelStageAtom)
const onImportFileClick = useCallback(async () => {
const options: SelectFileOption = {
title: 'Select model files',
buttonLabel: 'Select',
allowMultiple: true,
filters: [
{ name: 'GGUF Files', extensions: ['gguf'] },
{ name: 'All Files', extensions: ['*'] },
],
}
const filePaths: string[] = await window.core?.api?.selectFiles(options)
if (!filePaths || filePaths.length === 0) return
const importingModels: ImportingModel[] = filePaths
.filter((path) => path.endsWith('.gguf'))
.map((path) => {
const normalizedPath = isWindows ? path.replace(/\\/g, '/') : path
return {
importId: normalizedPath,
modelId: undefined,
name: normalizedPath.replace('.gguf', ''),
description: '',
path: path,
tags: [],
size: 0,
status: 'PREPARING',
format: 'gguf',
}
})
if (importingModels.length < 1) {
snackbar({
description: `Only files with .gguf extension can be imported.`,
type: 'error',
})
return
}
setImportingModels(importingModels)
setImportModelStage('MODEL_SELECTED')
}, [setImportingModels, setImportModelStage])
const onImportFolderClick = useCallback(async () => {
const options: SelectFileOption = {
title: 'Select model folders',
buttonLabel: 'Select',
allowMultiple: true,
selectDirectory: true,
}
const filePaths: string[] = await window.core?.api?.selectFiles(options)
if (!filePaths || filePaths.length === 0) return
console.log('filePaths folder', filePaths)
const importingModels: ImportingModel[] = filePaths
.filter((path) => path.endsWith('.gguf'))
.map((path) => {
const normalizedPath = isWindows ? path.replace(/\\/g, '/') : path
return {
importId: normalizedPath,
modelId: undefined,
name: normalizedPath.replace('.gguf', ''),
description: '',
path: path,
tags: [],
size: 0,
status: 'PREPARING',
format: 'gguf',
}
})
if (importingModels.length < 1) {
snackbar({
description: `Only files with .gguf extension can be imported.`,
type: 'error',
})
return
}
setImportingModels(importingModels)
setImportModelStage('MODEL_SELECTED')
}, [setImportingModels, setImportModelStage])
return (
<Modal
title="Choose what to import"
open={importModelStage === 'CHOOSE_WHAT_TO_IMPORT'}
onOpenChange={() => setImportModelStage('SELECTING_MODEL')}
content={
<div>
<div className="mt-2 flex flex-col space-y-3">
<Button onClick={onImportFileClick}>Import file (GGUF)</Button>
<Button onClick={onImportFolderClick}>Import Folder</Button>
</div>
</div>
}
/>
)
}
export default ChooseWhatToImportModal