Louis 83f090826e
feat: Jan Hub Revamp (#4491)
* feat: model hub revamp UI

* chore: model description - consistent markdown css

* chore: add model versions dropdown

* chore: integrate APIs - model sources

* chore: update model display name

* chore: lint fix

* chore: page transition animation

* feat: model search dropdown - deeplink

* chore: bump cortex version

* chore: add remote model sources

* chore: model download state

* chore: fix model metadata label

* chore: polish model detail page markdown

* test: fix test cases

* chore: initialize default Hub model sources

* chore: fix model stats

* chore: clean up click outside and inside hooks

* feat: change hub banner

* chore: lint fix

* chore: fix css long model id
2025-01-28 22:23:25 +07:00

57 lines
1.4 KiB
TypeScript

import React from 'react'
import { useAtomValue } from 'jotai'
import { useActiveModel } from '@/hooks/useActiveModel'
import { useSettings } from '@/hooks/useSettings'
import NotEnoughMemoryLabel from './NotEnoughMemoryLabel'
import SlowOnYourDeviceLabel from './SlowOnYourDeviceLabel'
import {
availableVramAtom,
totalRamAtom,
usedRamAtom,
} from '@/helpers/atoms/SystemBar.atom'
type Props = {
size?: number
compact?: boolean
}
const ModelLabel = ({ size, compact }: Props) => {
const { activeModel } = useActiveModel()
const totalRam = useAtomValue(totalRamAtom)
const usedRam = useAtomValue(usedRamAtom)
const availableVram = useAtomValue(availableVramAtom)
const { settings } = useSettings()
const getLabel = (size: number) => {
const minimumRamModel = size * 1.25
const availableRam =
settings?.run_mode === 'gpu'
? availableVram * 1000000 // MB to bytes
: totalRam - usedRam + (activeModel?.metadata?.size ?? 0)
if (minimumRamModel > totalRam) {
return (
<NotEnoughMemoryLabel
unit={settings?.run_mode === 'gpu' ? 'VRAM' : 'RAM'}
compact={compact}
/>
)
}
if (minimumRamModel < totalRam && minimumRamModel > availableRam) {
return <SlowOnYourDeviceLabel compact={compact} />
}
return null
}
return getLabel(size ?? 0)
}
export default React.memo(ModelLabel)