fix: app shows wrong performance tag, all say not enough ram on windows
This commit is contained in:
parent
00c68aea74
commit
f7f1e3da74
@ -16,7 +16,6 @@ import {
|
|||||||
import { atom, useAtomValue } from 'jotai'
|
import { atom, useAtomValue } from 'jotai'
|
||||||
|
|
||||||
import { useDownloadState } from '@/hooks/useDownloadState'
|
import { useDownloadState } from '@/hooks/useDownloadState'
|
||||||
import useGetPerformanceTag from '@/hooks/useGetPerformanceTag'
|
|
||||||
|
|
||||||
import { formatDownloadPercentage } from '@/utils/converter'
|
import { formatDownloadPercentage } from '@/utils/converter'
|
||||||
|
|
||||||
@ -30,7 +29,6 @@ export default function ModalCancelDownload({
|
|||||||
isFromList,
|
isFromList,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { modelDownloadStateAtom } = useDownloadState()
|
const { modelDownloadStateAtom } = useDownloadState()
|
||||||
useGetPerformanceTag()
|
|
||||||
const downloadAtom = useMemo(
|
const downloadAtom = useMemo(
|
||||||
() => atom((get) => get(modelDownloadStateAtom)[suitableModel.name]),
|
() => atom((get) => get(modelDownloadStateAtom)[suitableModel.name]),
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
|||||||
@ -1,27 +1,22 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
|
|
||||||
import { ModelVersion } from '@janhq/core/lib/types'
|
import { ModelVersion } from '@janhq/core/lib/types'
|
||||||
import { useAtomValue } from 'jotai'
|
|
||||||
|
|
||||||
import { ModelPerformance, TagType } from '@/constants/tagType'
|
import { ModelPerformance, TagType } from '@/constants/tagType'
|
||||||
|
|
||||||
import { totalRamAtom } from '@/helpers/atoms/SystemBar.atom'
|
|
||||||
|
|
||||||
// Recommendation:
|
// Recommendation:
|
||||||
// `Recommended (green)`: "Max RAM required" is 80% of users max RAM.
|
// `Recommended (green)`: "Max RAM required" is 80% of users max RAM.
|
||||||
// `Slow on your device (yellow)`: Max RAM required is 80-100% of users max RAM
|
// `Slow on your device (yellow)`: Max RAM required is 80-100% of users max RAM
|
||||||
// `Not enough RAM (red)`: User RAM is below "Max RAM required"
|
// `Not enough RAM (red)`: User RAM is below "Max RAM required"
|
||||||
|
|
||||||
export default function useGetPerformanceTag() {
|
export default function useGetPerformanceTag() {
|
||||||
const [performanceTag, setPerformanceTag] = useState<TagType | undefined>()
|
async function getPerformanceForModel(
|
||||||
const totalRam = useAtomValue(totalRamAtom)
|
modelVersion: ModelVersion,
|
||||||
|
totalRam: number
|
||||||
const getPerformanceForModel = async (modelVersion: ModelVersion) => {
|
): Promise<{ title: string; performanceTag: TagType }> {
|
||||||
const requiredRam = modelVersion.maxRamRequired
|
const requiredRam = modelVersion.maxRamRequired
|
||||||
setPerformanceTag(calculateRamPerformance(requiredRam, totalRam))
|
const performanceTag = calculateRamPerformance(requiredRam, totalRam)
|
||||||
}
|
|
||||||
|
|
||||||
let title = ''
|
let title = ''
|
||||||
|
|
||||||
switch (performanceTag) {
|
switch (performanceTag) {
|
||||||
case ModelPerformance.PerformancePositive:
|
case ModelPerformance.PerformancePositive:
|
||||||
title = 'Recommended'
|
title = 'Recommended'
|
||||||
@ -33,8 +28,10 @@ export default function useGetPerformanceTag() {
|
|||||||
title = 'Not enough RAM'
|
title = 'Not enough RAM'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
return { title, performanceTag }
|
||||||
|
}
|
||||||
|
|
||||||
return { performanceTag, title, getPerformanceForModel }
|
return { getPerformanceForModel }
|
||||||
}
|
}
|
||||||
|
|
||||||
const calculateRamPerformance = (
|
const calculateRamPerformance = (
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable react-hooks/exhaustive-deps */
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
import { useCallback, useEffect, useMemo } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
|
|
||||||
import { ModelCatalog, ModelVersion } from '@janhq/core/lib/types'
|
import { ModelCatalog, ModelVersion } from '@janhq/core/lib/types'
|
||||||
import { Badge, Button } from '@janhq/uikit'
|
import { Badge, Button } from '@janhq/uikit'
|
||||||
@ -20,6 +20,8 @@ import { useMainViewState } from '@/hooks/useMainViewState'
|
|||||||
|
|
||||||
import { toGigabytes } from '@/utils/converter'
|
import { toGigabytes } from '@/utils/converter'
|
||||||
|
|
||||||
|
import { totalRamAtom } from '@/helpers/atoms/SystemBar.atom'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
suitableModel: ModelVersion
|
suitableModel: ModelVersion
|
||||||
exploreModel: ModelCatalog
|
exploreModel: ModelCatalog
|
||||||
@ -32,8 +34,12 @@ const ExploreModelItemHeader: React.FC<Props> = ({
|
|||||||
const { downloadModel } = useDownloadModel()
|
const { downloadModel } = useDownloadModel()
|
||||||
const { downloadedModels } = useGetDownloadedModels()
|
const { downloadedModels } = useGetDownloadedModels()
|
||||||
const { modelDownloadStateAtom, downloadStates } = useDownloadState()
|
const { modelDownloadStateAtom, downloadStates } = useDownloadState()
|
||||||
const { performanceTag, title, getPerformanceForModel } =
|
const { getPerformanceForModel } = useGetPerformanceTag()
|
||||||
useGetPerformanceTag()
|
const [title, setTitle] = useState<string>('Recommended')
|
||||||
|
const totalRam = useAtomValue(totalRamAtom)
|
||||||
|
const [performanceTag, setPerformanceTag] = useState<TagType>(
|
||||||
|
ModelPerformance.PerformancePositive
|
||||||
|
)
|
||||||
const downloadAtom = useMemo(
|
const downloadAtom = useMemo(
|
||||||
() => atom((get) => get(modelDownloadStateAtom)[suitableModel.name]),
|
() => atom((get) => get(modelDownloadStateAtom)[suitableModel.name]),
|
||||||
[suitableModel.name]
|
[suitableModel.name]
|
||||||
@ -41,9 +47,20 @@ const ExploreModelItemHeader: React.FC<Props> = ({
|
|||||||
const downloadState = useAtomValue(downloadAtom)
|
const downloadState = useAtomValue(downloadAtom)
|
||||||
const { setMainViewState } = useMainViewState()
|
const { setMainViewState } = useMainViewState()
|
||||||
|
|
||||||
|
const calculatePerformance = useCallback(
|
||||||
|
(suitableModel: ModelVersion) => async () => {
|
||||||
|
const { title, performanceTag } = await getPerformanceForModel(
|
||||||
|
suitableModel,
|
||||||
|
totalRam
|
||||||
|
)
|
||||||
|
setPerformanceTag(performanceTag)
|
||||||
|
setTitle(title)
|
||||||
|
},
|
||||||
|
[totalRam]
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getPerformanceForModel(suitableModel)
|
calculatePerformance(suitableModel)
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [suitableModel])
|
}, [suitableModel])
|
||||||
|
|
||||||
const onDownloadClick = useCallback(() => {
|
const onDownloadClick = useCallback(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user