Skip to content

Commit

Permalink
Merge branch 'main' into Ssstars-patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
0xHieu01 authored Jan 12, 2024
2 parents 3feb148 + a855027 commit 59cfa24
Showing 1 changed file with 86 additions and 5 deletions.
91 changes: 86 additions & 5 deletions web/containers/DropdownListSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@ import {
SelectTrigger,
SelectValue,
Input,
Tooltip,
TooltipContent,
TooltipPortal,
TooltipTrigger,
TooltipArrow,
Badge,
} from '@janhq/uikit'

import { atom, useAtomValue, useSetAtom } from 'jotai'

import { MonitorIcon } from 'lucide-react'
import { MonitorIcon, InfoIcon } from 'lucide-react'

import { twMerge } from 'tailwind-merge'

import { MainViewState } from '@/constants/screens'

import { useActiveModel } from '@/hooks/useActiveModel'

import { useEngineSettings } from '@/hooks/useEngineSettings'

import { useMainViewState } from '@/hooks/useMainViewState'
Expand All @@ -33,6 +41,7 @@ import useRecommendedModel from '@/hooks/useRecommendedModel'

import { toGibibytes } from '@/utils/converter'

import { totalRamAtom, usedRamAtom } from '@/helpers/atoms/SystemBar.atom'
import {
ModelParams,
activeThreadAtom,
Expand All @@ -49,13 +58,16 @@ export default function DropdownListSidebar() {
const threadStates = useAtomValue(threadStatesAtom)
const setSelectedModel = useSetAtom(selectedModelAtom)
const setThreadModelParams = useSetAtom(setThreadModelParamsAtom)
const { activeModel } = useActiveModel()

const [selected, setSelected] = useState<Model | undefined>()
const { setMainViewState } = useMainViewState()
const [openAISettings, setOpenAISettings] = useState<
{ api_key: string } | undefined
>(undefined)
const { readOpenAISettings, saveOpenAISettings } = useEngineSettings()
const totalRam = useAtomValue(totalRamAtom)
const usedRam = useAtomValue(usedRamAtom)

useEffect(() => {
readOpenAISettings().then((settings) => {
Expand Down Expand Up @@ -119,6 +131,71 @@ export default function DropdownListSidebar() {
return null
}

const getLabel = (size: number) => {
const minimumRamModel = size * 1.25
const availableRam = totalRam - usedRam + (activeModel?.metadata.size ?? 0)
if (minimumRamModel > totalRam) {
return (
<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>
)
}
if (minimumRamModel < availableRam) {
return (
<Badge className="space-x-1 rounded-md" themes="success">
<span>Recommended</span>
</Badge>
)
}
if (minimumRamModel < totalRam && minimumRamModel > availableRam) {
return (
<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>
)
}
}

return (
<>
<Select value={selected?.id} onValueChange={onValueSelected}>
Expand All @@ -127,7 +204,7 @@ export default function DropdownListSidebar() {
{downloadedModels.filter((x) => x.id === selected?.id)[0]?.name}
</SelectValue>
</SelectTrigger>
<SelectContent className="right-5 block w-full min-w-[300px] pr-0">
<SelectContent className="right-2 block w-full min-w-[450px] pr-0">
<div className="flex w-full items-center space-x-2 px-4 py-2">
<MonitorIcon size={20} className="text-muted-foreground" />
<span>Local</span>
Expand All @@ -147,9 +224,13 @@ export default function DropdownListSidebar() {
>
<div className="flex w-full justify-between">
<span className="line-clamp-1 block">{x.name}</span>
<span className="font-bold text-muted-foreground">
{toGibibytes(x.metadata.size)}
</span>
<div className="space-x-2">
<span className="font-bold text-muted-foreground">
{toGibibytes(x.metadata.size)}
</span>
{x.engine == InferenceEngine.nitro &&
getLabel(x.metadata.size)}
</div>
</div>
</SelectItem>
))}
Expand Down

0 comments on commit 59cfa24

Please sign in to comment.