* 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>
98 lines
3.1 KiB
TypeScript
98 lines
3.1 KiB
TypeScript
import { Fragment } from 'react'
|
|
|
|
import {
|
|
Progress,
|
|
Modal,
|
|
ModalContent,
|
|
Button,
|
|
ModalHeader,
|
|
ModalTitle,
|
|
ModalTrigger,
|
|
} from '@janhq/uikit'
|
|
|
|
import { useAtomValue } from 'jotai'
|
|
|
|
import useDownloadModel from '@/hooks/useDownloadModel'
|
|
import { modelDownloadStateAtom } from '@/hooks/useDownloadState'
|
|
|
|
import { formatDownloadPercentage } from '@/utils/converter'
|
|
|
|
import { getDownloadingModelAtom } from '@/helpers/atoms/Model.atom'
|
|
|
|
export default function DownloadingState() {
|
|
const downloadStates = useAtomValue(modelDownloadStateAtom)
|
|
const downloadingModels = useAtomValue(getDownloadingModelAtom)
|
|
const { abortModelDownload } = useDownloadModel()
|
|
|
|
const totalCurrentProgress = Object.values(downloadStates)
|
|
.map((a) => a.size.transferred + a.size.transferred)
|
|
.reduce((partialSum, a) => partialSum + a, 0)
|
|
|
|
const totalSize = Object.values(downloadStates)
|
|
.map((a) => a.size.total + a.size.total)
|
|
.reduce((partialSum, a) => partialSum + a, 0)
|
|
|
|
const totalPercentage = ((totalCurrentProgress / totalSize) * 100).toFixed(2)
|
|
|
|
return (
|
|
<Fragment>
|
|
{Object.values(downloadStates)?.length > 0 && (
|
|
<Modal>
|
|
<ModalTrigger asChild>
|
|
<div className="relative block">
|
|
<Button size="sm" themes="outline">
|
|
<span>
|
|
{Object.values(downloadStates).length} Downloading model
|
|
</span>
|
|
</Button>
|
|
<span
|
|
className="absolute left-0 h-full rounded-md rounded-l-md bg-primary/20"
|
|
style={{
|
|
width: `${totalPercentage}%`,
|
|
}}
|
|
/>
|
|
</div>
|
|
</ModalTrigger>
|
|
<ModalContent>
|
|
<ModalHeader>
|
|
<ModalTitle>Downloading model</ModalTitle>
|
|
</ModalHeader>
|
|
{Object.values(downloadStates).map((item, i) => (
|
|
<div className="pt-2" key={i}>
|
|
<Progress
|
|
className="mb-2 h-2"
|
|
value={
|
|
formatDownloadPercentage(item?.percent, {
|
|
hidePercentage: true,
|
|
}) as number
|
|
}
|
|
/>
|
|
<div className="flex items-center justify-between gap-x-2">
|
|
<div className="flex gap-x-2">
|
|
<p className="line-clamp-1">{item?.modelId}</p>
|
|
<span>{formatDownloadPercentage(item?.percent)}</span>
|
|
</div>
|
|
<Button
|
|
themes="outline"
|
|
size="sm"
|
|
onClick={() => {
|
|
if (item?.modelId) {
|
|
const model = downloadingModels.find(
|
|
(model) => model.id === item.modelId
|
|
)
|
|
if (model) abortModelDownload(model)
|
|
}
|
|
}}
|
|
>
|
|
Cancel
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</ModalContent>
|
|
</Modal>
|
|
)}
|
|
</Fragment>
|
|
)
|
|
}
|