import { Fragment } from 'react' import { InferenceEngine } from '@janhq/core' import { CommandModal, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Badge, } from '@janhq/uikit' import { useAtom, useAtomValue } from 'jotai' import { DatabaseIcon, CpuIcon } from 'lucide-react' import { showSelectModelModalAtom } from '@/containers/Providers/KeyListener' import { MainViewState } from '@/constants/screens' import { useActiveModel } from '@/hooks/useActiveModel' import { useMainViewState } from '@/hooks/useMainViewState' import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom' import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom' export default function CommandListDownloadedModel() { const { setMainViewState } = useMainViewState() const downloadedModels = useAtomValue(downloadedModelsAtom) const { activeModel, startModel, stopModel } = useActiveModel() const [serverEnabled] = useAtom(serverEnabledAtom) const [showSelectModelModal, setShowSelectModelModal] = useAtom( showSelectModelModalAtom ) const onModelActionClick = (modelId: string) => { if (activeModel && activeModel.id === modelId) { stopModel() } else { startModel(modelId) } } const isNotDownloadedModel = downloadedModels.length === 0 if (isNotDownloadedModel || serverEnabled) return null return ( No Model found. {!isNotDownloadedModel && ( {downloadedModels .filter((model) => model.engine === InferenceEngine.nitro) .map((model) => ( { onModelActionClick(model.id) setShowSelectModelModal(false) }} >
{model.id} {activeModel && activeModel.id === model.id && ( Active )}
))}
)} { setMainViewState(MainViewState.Hub) setShowSelectModelModal(false) }} > Explore The Hub
) }