* fix: reduce the number of api call Signed-off-by: James <james@jan.ai> * fix: download progress Signed-off-by: James <james@jan.ai> * chore: save blob * fix: server boot up * fix: download state not updating Signed-off-by: James <james@jan.ai> * fix: copy assets * Add Dockerfile CPU for Jan Server and Jan Web * Add Dockerfile GPU for Jan Server and Jan Web * feat: S3 adapter * Update check find count from ./pre-install and correct copy:asserts command * server add bundleDependencies @janhq/core * server add bundleDependencies @janhq/core * fix: update success/failed download state (#1945) * fix: update success/failed download state Signed-off-by: James <james@jan.ai> * fix: download model progress and state handling for both Desktop and Web --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> Co-authored-by: Louis <louis@jan.ai> * chore: refactor * fix: load models empty first time open * Add Docker compose * fix: assistants onUpdate --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> Co-authored-by: Hien To <tominhhien97@gmail.com> Co-authored-by: NamH <NamNh0122@gmail.com>
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { atom } from 'jotai'
|
|
|
|
import { toaster } from '@/containers/Toast'
|
|
|
|
import {
|
|
configuredModelsAtom,
|
|
downloadedModelsAtom,
|
|
removeDownloadingModelAtom,
|
|
} from '@/helpers/atoms/Model.atom'
|
|
|
|
// download states
|
|
export const modelDownloadStateAtom = atom<Record<string, DownloadState>>({})
|
|
|
|
/**
|
|
* Used to set the download state for a particular model.
|
|
*/
|
|
export const setDownloadStateAtom = atom(
|
|
null,
|
|
(get, set, state: DownloadState) => {
|
|
const currentState = { ...get(modelDownloadStateAtom) }
|
|
|
|
if (state.downloadState === 'end') {
|
|
// download successfully
|
|
delete currentState[state.modelId]
|
|
set(removeDownloadingModelAtom, state.modelId)
|
|
const model = get(configuredModelsAtom).find(
|
|
(e) => e.id === state.modelId
|
|
)
|
|
if (model) set(downloadedModelsAtom, (prev) => [...prev, model])
|
|
toaster({
|
|
title: 'Download Completed',
|
|
description: `Download ${state.modelId} completed`,
|
|
type: 'success',
|
|
})
|
|
} else if (state.downloadState === 'error') {
|
|
// download error
|
|
delete currentState[state.modelId]
|
|
set(removeDownloadingModelAtom, state.modelId)
|
|
if (state.error === 'aborted') {
|
|
toaster({
|
|
title: 'Cancel Download',
|
|
description: `Model ${state.modelId} download cancelled`,
|
|
type: 'warning',
|
|
})
|
|
} else {
|
|
let error = state.error
|
|
if (state.error?.includes('certificate')) {
|
|
error +=
|
|
'. To fix enable "Ignore SSL Certificates" in Advanced settings.'
|
|
}
|
|
toaster({
|
|
title: 'Download Failed',
|
|
description: `Model ${state.modelId} download failed: ${error}`,
|
|
type: 'error',
|
|
})
|
|
}
|
|
} else {
|
|
// download in progress
|
|
currentState[state.modelId] = state
|
|
}
|
|
|
|
set(modelDownloadStateAtom, currentState)
|
|
}
|
|
)
|