NamH db987e88f9
fix(Model): switch model caused app crash (#1596)
Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
Co-authored-by: Louis <louis@jan.ai>
2024-01-17 09:33:40 +07:00

44 lines
1.1 KiB
TypeScript

import React from 'react'
import { useAtomValue } from 'jotai'
import { useActiveModel } from '@/hooks/useActiveModel'
import NotEnoughRamLabel from './NotEnoughRamLabel'
import RecommendedLabel from './RecommendedLabel'
import SlowOnYourDeviceLabel from './SlowOnYourDeviceLabel'
import { totalRamAtom, usedRamAtom } from '@/helpers/atoms/SystemBar.atom'
type Props = {
size: number
}
const ModelLabel: React.FC<Props> = ({ size }) => {
const { activeModel } = useActiveModel()
const totalRam = useAtomValue(totalRamAtom)
const usedRam = useAtomValue(usedRamAtom)
const getLabel = (size: number) => {
const minimumRamModel = size * 1.25
const availableRam = totalRam - usedRam + (activeModel?.metadata.size ?? 0)
if (minimumRamModel > totalRam) {
return <NotEnoughRamLabel />
}
if (minimumRamModel < availableRam) {
return <RecommendedLabel />
}
if (minimumRamModel < totalRam && minimumRamModel > availableRam) {
return <SlowOnYourDeviceLabel />
}
return null
}
return getLabel(size)
}
export default React.memo(ModelLabel)