diff --git a/web/screens/HubScreen2/components/DownloadLocalModelModal.tsx b/web/screens/HubScreen2/components/DownloadLocalModelModal.tsx index fef81aac6..dd1a87e26 100644 --- a/web/screens/HubScreen2/components/DownloadLocalModelModal.tsx +++ b/web/screens/HubScreen2/components/DownloadLocalModelModal.tsx @@ -1,4 +1,4 @@ -import { Fragment, useEffect, useState } from 'react' +import { Fragment, useEffect, useState, useCallback } from 'react' import { Modal } from '@janhq/joi' import { useAtom } from 'jotai' @@ -13,6 +13,7 @@ import Tab, { ModelTab } from './Tab' import { localModelModalStageAtom } from '@/helpers/atoms/DownloadLocalModel.atom' const DownloadLocalModelModal: React.FC = () => { + const [availableModels, setAvailableModels] = useState([]) const [{ stage, modelHandle }, setLocalModelModalStage] = useAtom( localModelModalStageAtom ) @@ -31,9 +32,21 @@ const DownloadLocalModelModal: React.FC = () => { }, []) const modelName = modelHandle?.split('/')[1] ?? '' - if (!modelHandle) return null + const isFromCortexHub = modelHandle?.includes('cortexso') ?? false - const isFromCortexHub = modelHandle.includes('cortexso') + const onModelBranchChanged = useCallback( + (models: string[]) => { + const isFromCortexHub = modelHandle?.includes('cortexso') ?? false + if (isFromCortexHub) { + setAvailableModels(models) + } else { + setAvailableModels(modelHandle != null ? [modelHandle] : []) + } + }, + [modelHandle] + ) + + if (!modelHandle) return null return ( { content={ {}} - modelIdVariants={[modelHandle]} isLocalModel={true} + availableModels={availableModels} /> { /> {tab === 'Versions' && (isFromCortexHub ? ( - + ) : ( ))} diff --git a/web/screens/HubScreen2/components/HeaderModal.tsx b/web/screens/HubScreen2/components/HeaderModal.tsx index ec3e7c491..23a45244a 100644 --- a/web/screens/HubScreen2/components/HeaderModal.tsx +++ b/web/screens/HubScreen2/components/HeaderModal.tsx @@ -1,4 +1,4 @@ -import { Fragment, useCallback, useRef, useState } from 'react' +import { Fragment, useCallback, useEffect, useRef, useState } from 'react' import Image from 'next/image' @@ -10,27 +10,60 @@ import { twMerge } from 'tailwind-merge' import DropdownModal from './DropdownModal' type Props = { - modelIdVariants: string[] - modelId: string name: string + modelHandle?: string + availableModels: string[] onActionClick: () => void isLocalModel?: boolean } const HeaderModal: React.FC = ({ - modelIdVariants, - modelId, name, + modelHandle, + availableModels, onActionClick, isLocalModel = false, }) => { - const [selectedVariant, setSelectedVariant] = useState(modelId) + const [options, setOptions] = useState<{ name: string; value: string }[]>([]) + const [selectedVariant, setSelectedVariant] = useState() const textRef = useRef(null) - const options = modelIdVariants.map((variant) => ({ - name: variant, - value: variant, - })) + useEffect(() => { + const isFromCortexHub = modelHandle?.includes('cortexso') ?? false + if (!isLocalModel) { + setOptions( + availableModels.map((variant) => ({ + name: variant, + value: variant, + })) + ) + if (availableModels.length > 0) { + setSelectedVariant(availableModels[0]) + } + return + } + + if (isLocalModel && !isFromCortexHub) { + setOptions([ + { + name: modelHandle ?? '', + value: modelHandle ?? '', + }, + ]) + setSelectedVariant(modelHandle) + return + } + + setOptions( + availableModels.map((variant) => ({ + name: `${name}:${variant}`, + value: `${name}:${variant}`, + })) + ) + if (availableModels.length > 0) { + setSelectedVariant(`${name}:${availableModels[0]}`) + } + }, [availableModels, name, modelHandle, isLocalModel]) const onCopyClicked = useCallback(() => { navigator.clipboard.writeText(textRef.current?.innerText ?? '') @@ -38,6 +71,8 @@ const HeaderModal: React.FC = ({ const title = name.charAt(0).toUpperCase() + name.slice(1) + if (!selectedVariant) return null + return (
{title} diff --git a/web/screens/HubScreen2/components/ListModel.tsx b/web/screens/HubScreen2/components/ListModel.tsx index 1c39751bf..c39df654c 100644 --- a/web/screens/HubScreen2/components/ListModel.tsx +++ b/web/screens/HubScreen2/components/ListModel.tsx @@ -33,14 +33,16 @@ import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom' type Props = { modelHandle: string + onBranchSelected?: (availableSelections: string[]) => void } -const ListModel: React.FC = ({ modelHandle }) => { +const ListModel: React.FC = ({ modelHandle, onBranchSelected }) => { const { data: engineData } = useEngineQuery() + const { data, isLoading } = useHfEngineToBranchesQuery(modelHandle) + const [engineFilter, setEngineFilter] = useState( undefined ) - const { data, isLoading } = useHfEngineToBranchesQuery(modelHandle) const engineSelections: { name: string; value: string }[] = useMemo(() => { if (!data || !engineData) return [] @@ -63,17 +65,26 @@ const ListModel: React.FC = ({ modelHandle }) => { return result }, [data, engineData]) + const modelBranches: CortexHubModel[] = useMemo((): CortexHubModel[] => { + if (!data) return [] + return (data[engineFilter as EngineType] as CortexHubModel[]) ?? [] + }, [data, engineFilter]) + useEffect(() => { if (engineSelections.length === 0) return setEngineFilter(engineSelections[0].value as EngineType) - }, [engineSelections]) + const models = modelBranches.map((m) => m.name) + onBranchSelected?.(models) + }, [engineSelections, modelBranches, onBranchSelected]) - const modelBranches: CortexHubModel[] = [] - if (data) { - const branches = data[engineFilter as EngineType] as CortexHubModel[] - if (!branches || branches.length === 0) return - modelBranches.push(...branches) - } + const onSelectionChanged = useCallback( + (selectionValue: string) => { + setEngineFilter(selectionValue as EngineType) + const models = modelBranches.map((m) => m.name) + onBranchSelected?.(models) + }, + [setEngineFilter, onBranchSelected, modelBranches] + ) if (isLoading) return ( @@ -90,7 +101,7 @@ const ListModel: React.FC = ({ modelHandle }) => { value={engineFilter} className="gap-1.5 whitespace-nowrap px-4 py-2 font-semibold" options={engineSelections} - onValueChange={(value) => setEngineFilter(value as EngineType)} + onValueChange={onSelectionChanged} />
diff --git a/web/screens/HubScreen2/components/SetUpRemoteModelModal.tsx b/web/screens/HubScreen2/components/SetUpRemoteModelModal.tsx index d0dc59f06..5f608f63d 100644 --- a/web/screens/HubScreen2/components/SetUpRemoteModelModal.tsx +++ b/web/screens/HubScreen2/components/SetUpRemoteModelModal.tsx @@ -31,8 +31,7 @@ const SetUpRemoteModelModal: React.FC = () => { { }, []) const onDeleteModelClick = useCallback(() => {}, []) - console.log('namh model', model) const displayStatus = useMemo(() => { if (model.status === 'FAILED') { return 'Failed' diff --git a/web/screens/Settings/ImportingModelModal/index.tsx b/web/screens/Settings/ImportingModelModal/index.tsx index 30f7d7a99..3d168a1ae 100644 --- a/web/screens/Settings/ImportingModelModal/index.tsx +++ b/web/screens/Settings/ImportingModelModal/index.tsx @@ -29,14 +29,6 @@ const ImportingModelModal = () => { const importModels = async () => { for (const model of importingModels) { await downloadModel(model.path) - // const parsedResult = await result?.json() - // if ( - // parsedResult['message'] && - // parsedResult['message'] === 'Download model started successfully.' - // ) { - // // update importingModels - // } - // console.log(`NamH result ${JSON.stringify(parsedResult)}`) } } importModels()