chore: add facades refactor: core module export refactor: inference plugin - deprecate function registering (#537) * refactor: revamp inference plugin as class - deprecate function registering * refactor: monitoring plugin - deprecate service registering (#538) refactor: revamp inference plugin as class - deprecate function registering chore: update import refactor: plugin revamp - model management chore: update build steps and remove experimental plugins refactor: remove pluggable electron chore: add sorting for conversations chore: build plugins for testing chore: consistent plugin directory name chore: docs chore: fix CI chore: update conversation prefix
26 lines
902 B
TypeScript
26 lines
902 B
TypeScript
import { useState } from 'react'
|
|
import { useAtomValue } from 'jotai'
|
|
import { totalRamAtom } from '@helpers/atoms/SystemBar.atom'
|
|
import { ModelVersion } from '@janhq/core/lib/types'
|
|
|
|
export default function useGetMostSuitableModelVersion() {
|
|
const [suitableModel, setSuitableModel] = useState<ModelVersion | undefined>()
|
|
const totalRam = useAtomValue(totalRamAtom)
|
|
|
|
const getMostSuitableModelVersion = async (modelVersions: ModelVersion[]) => {
|
|
// find the model version with the highest required RAM that is still below the user's RAM by 80%
|
|
const modelVersion = modelVersions.reduce((prev, current) => {
|
|
if (current.maxRamRequired > prev.maxRamRequired) {
|
|
if (current.maxRamRequired < totalRam * 0.8) {
|
|
return current
|
|
}
|
|
}
|
|
return prev
|
|
})
|
|
|
|
setSuitableModel(modelVersion)
|
|
}
|
|
|
|
return { suitableModel, getMostSuitableModelVersion }
|
|
}
|