-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Model): switch model caused app crash (janhq#1596)
Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]> Co-authored-by: Louis <[email protected]>
- Loading branch information
1 parent
f293e11
commit db987e8
Showing
7 changed files
with
187 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react' | ||
|
||
import { | ||
Badge, | ||
Tooltip, | ||
TooltipArrow, | ||
TooltipContent, | ||
TooltipPortal, | ||
TooltipTrigger, | ||
} from '@janhq/uikit' | ||
import { InfoIcon } from 'lucide-react' | ||
|
||
const NotEnoughRamLabel: React.FC = () => ( | ||
<Badge className="space-x-1 rounded-md" themes="danger"> | ||
<span>Not enough RAM</span> | ||
<Tooltip> | ||
<TooltipTrigger> | ||
<InfoIcon size={16} /> | ||
</TooltipTrigger> | ||
<TooltipPortal> | ||
<TooltipContent side="right" sideOffset={10} className="max-w-[300px]"> | ||
<span> | ||
{`This tag signals insufficient RAM for optimal model | ||
performance. It's dynamic and may change with your system's | ||
RAM availability.`} | ||
</span> | ||
<TooltipArrow /> | ||
</TooltipContent> | ||
</TooltipPortal> | ||
</Tooltip> | ||
</Badge> | ||
) | ||
|
||
export default React.memo(NotEnoughRamLabel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
|
||
import { Badge } from '@janhq/uikit' | ||
|
||
const RecommendedLabel: React.FC = () => ( | ||
<Badge className="space-x-1 rounded-md" themes="success"> | ||
<span>Recommended</span> | ||
</Badge> | ||
) | ||
|
||
export default React.memo(RecommendedLabel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react' | ||
|
||
import { | ||
Badge, | ||
Tooltip, | ||
TooltipArrow, | ||
TooltipContent, | ||
TooltipPortal, | ||
TooltipTrigger, | ||
} from '@janhq/uikit' | ||
import { InfoIcon } from 'lucide-react' | ||
|
||
const SlowOnYourDeviceLabel: React.FC = () => ( | ||
<Badge className="space-x-1 rounded-md" themes="warning"> | ||
<span>Slow on your device</span> | ||
<Tooltip> | ||
<TooltipTrigger> | ||
<InfoIcon size={16} /> | ||
</TooltipTrigger> | ||
<TooltipPortal> | ||
<TooltipContent side="right" sideOffset={10} className="max-w-[300px]"> | ||
<span> | ||
This tag indicates that your current RAM performance may affect | ||
model speed. It can change based on other active apps. To improve, | ||
consider closing unnecessary applications to free up RAM. | ||
</span> | ||
<TooltipArrow /> | ||
</TooltipContent> | ||
</TooltipPortal> | ||
</Tooltip> | ||
</Badge> | ||
) | ||
|
||
export default React.memo(SlowOnYourDeviceLabel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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) |
Oops, something went wrong.