* feat: Support multiple model binaries * fix: Update downloadModel with multiple binaries handler * feat: Add 3 models with multiple binaries * chore: fix model download * fix: model file lookup & model path * chore: add .prettierrc * chore: refactor docs * chore: bump model version * fix(capybara): add filename * fix(codeninja): add file name + llama model path * fix(default): add llama model path * fix(deepseek coder): add filename * fix(deepseek 33B): add filename * fix(dolphin mixtral): add filename * fix(llama2-chat): add filename * fix(llama2-70B): add filename * fix(mistral 7b): add filename + model path * fix(bakllava): correct size model * fix(llava-7b): correct size model * fix(llava-13b): correct size model * fix(mixtral-8x7b): add file name + modelpath * fix(noramaid-7b): add file name + modelpath * fix(openchat-7b): add file name + modelpath * fix(openhermes-7b): add file name + modelpath * fix(phi2-3b): add file name + modelpath * fix(phind): add file name + modelpath * fix(solarslerp): add file name + modelpath * fix(starling): add file name + modelpath * fix(stealth): add file name + modelpath * fix(tinyllama): add file name + modelpath * fix(trinity): add file name + modelpath * fix(tulu): add file name + modelpath * fix(wizardcoder): add file name + modelpath * fix(yi): add file name + modelpath * update from source -> sources Signed-off-by: James <james@jan.ai> --------- Signed-off-by: James <james@jan.ai> Co-authored-by: hiro <vuonghoainam.work@gmail.com> Co-authored-by: hahuyhoang411 <hahuyhoanghhh41@gmail.com> Co-authored-by: James <james@jan.ai>
80 lines
1.8 KiB
TypeScript
80 lines
1.8 KiB
TypeScript
import { useContext } from 'react'
|
|
|
|
import {
|
|
Model,
|
|
ExtensionTypeEnum,
|
|
ModelExtension,
|
|
abortDownload,
|
|
joinPath,
|
|
ModelArtifact,
|
|
} from '@janhq/core'
|
|
|
|
import { useSetAtom } from 'jotai'
|
|
|
|
import { FeatureToggleContext } from '@/context/FeatureToggle'
|
|
|
|
import { modelBinFileName } from '@/utils/model'
|
|
|
|
import { useDownloadState } from './useDownloadState'
|
|
|
|
import { extensionManager } from '@/extension/ExtensionManager'
|
|
import { addNewDownloadingModelAtom } from '@/helpers/atoms/Model.atom'
|
|
|
|
export default function useDownloadModel() {
|
|
const { ignoreSSL, proxy } = useContext(FeatureToggleContext)
|
|
const { setDownloadState } = useDownloadState()
|
|
const addNewDownloadingModel = useSetAtom(addNewDownloadingModelAtom)
|
|
|
|
const downloadModel = async (model: Model) => {
|
|
const childrenDownloadProgress: DownloadState[] = []
|
|
model.sources.forEach((source: ModelArtifact) => {
|
|
childrenDownloadProgress.push({
|
|
modelId: source.filename,
|
|
time: {
|
|
elapsed: 0,
|
|
remaining: 0,
|
|
},
|
|
speed: 0,
|
|
percent: 0,
|
|
size: {
|
|
total: 0,
|
|
transferred: 0,
|
|
},
|
|
})
|
|
})
|
|
|
|
// set an initial download state
|
|
setDownloadState({
|
|
modelId: model.id,
|
|
time: {
|
|
elapsed: 0,
|
|
remaining: 0,
|
|
},
|
|
speed: 0,
|
|
percent: 0,
|
|
size: {
|
|
total: 0,
|
|
transferred: 0,
|
|
},
|
|
children: childrenDownloadProgress,
|
|
})
|
|
|
|
addNewDownloadingModel(model)
|
|
|
|
await extensionManager
|
|
.get<ModelExtension>(ExtensionTypeEnum.Model)
|
|
?.downloadModel(model, { ignoreSSL, proxy })
|
|
}
|
|
|
|
const abortModelDownload = async (model: Model) => {
|
|
await abortDownload(
|
|
await joinPath(['models', model.id, modelBinFileName(model)])
|
|
)
|
|
}
|
|
|
|
return {
|
|
downloadModel,
|
|
abortModelDownload,
|
|
}
|
|
}
|