Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix: resolve downloaded model toggle bug by handling developer prefix (#7648)
James Dam32e9b21b8a14
diff --git a/web-app/src/containers/DownloadButton.tsx b/web-app/src/containers/DownloadButton.tsxindex be8e7191e..ab1fecd73 100644--- a/web-app/src/containers/DownloadButton.tsx+++ b/web-app/src/containers/DownloadButton.tsx@@ -47,6 +47,16 @@ export function DownloadButtonPlaceholder({const modelId = quant?.model_id || model.model_name+ // Get the actual downloaded model ID (with or without developer prefix)+ const downloadedModelId = useMemo(() => {+ const foundModel = llamaProvider?.models.find(+ (m: { id: string }) =>+ m.id === modelId ||+ m.id === `${model.developer}/${sanitizeModelId(modelId)}`+ )+ return foundModel?.id || modelId+ }, [llamaProvider, modelId, model.developer])+const downloadProcesses = useMemo(() =>Object.values(downloads).map((download) => ({@@ -138,7 +148,7 @@ export function DownloadButtonPlaceholder({<Buttonvariant="default"size="sm"- onClick={() => handleUseModel(modelId)}+ onClick={() => handleUseModel(downloadedModelId)}data-test-id={`hub-model-${modelId}`}>{t('hub:newChat')}diff --git a/web-app/src/containers/MlxModelDownloadAction.tsx b/web-app/src/containers/MlxModelDownloadAction.tsxindex 7963f76fb..7370ee290 100644--- a/web-app/src/containers/MlxModelDownloadAction.tsx+++ b/web-app/src/containers/MlxModelDownloadAction.tsx@@ -53,14 +53,27 @@ export const MlxModelDownloadAction = memo(({ model }: { model: CatalogModel })const downloadProgress =downloadProcesses.find((e) => e.id === modelId)?.progress || 0+ // Get the actual downloaded model ID (with or without developer prefix)+ const downloadedModelId = useMemo(() => {+ const mlxProvider = useModelProvider.getState().getProviderByName('mlx')+ const foundModel = mlxProvider?.models.find(+ (m: { id: string }) =>+ m.id === modelId ||+ m.id === `${model.developer}/${modelId}`+ )+ return foundModel?.id || modelId+ }, [modelId, model.developer])+// Check if MLX model is already downloadeduseEffect(() => {const mlxProvider = useModelProvider.getState().getProviderByName('mlx')const downloaded = mlxProvider?.models.some(- (m: { id: string }) => m.id === modelId+ (m: { id: string }) =>+ m.id === modelId ||+ m.id === `${model.developer}/${modelId}`)setDownloaded(!!downloaded)- }, [modelId])+ }, [modelId, model.developer])// Listen for download successuseEffect(() => {@@ -87,12 +100,12 @@ export const MlxModelDownloadAction = memo(({ model }: { model: CatalogModel })params: {},search: {threadModel: {- id: modelId,+ id: downloadedModelId,provider: 'mlx',},},})- }, [navigate, modelId])+ }, [navigate, downloadedModelId])const handleDownloadMlxModel = useCallback(async () => {addLocalDownloadingModel(modelId)diff --git a/web-app/src/routes/hub/index.tsx b/web-app/src/routes/hub/index.tsxindex 59584bacd..14342ea30 100644--- a/web-app/src/routes/hub/index.tsx+++ b/web-app/src/routes/hub/index.tsx@@ -3,7 +3,7 @@ import { useVirtualizer } from '@tanstack/react-virtual'import { createFileRoute, useNavigate } from '@tanstack/react-router'import { route } from '@/constants/routes'import { useModelSources } from '@/hooks/useModelSources'-import { cn } from '@/lib/utils'+import { cn, sanitizeModelId } from '@/lib/utils'import {useState,useMemo,@@ -172,15 +172,25 @@ function HubContent() {?.map((model) => ({...model,quants: model.quants?.filter((variant) => {- // Check both llamacpp and mlx providers+ // Check both direct match and with developer prefix (like DownloadButton does)const isLlamaCppDownloaded = useModelProvider.getState().getProviderByName('llamacpp')- ?.models.some((m: { id: string }) => m.id === variant.model_id)+ ?.models.some(+ (m: { id: string }) =>+ m.id === variant.model_id ||+ m.id === `${model.developer}/${sanitizeModelId(variant.model_id)}`+ )+const isMlxDownloaded = useModelProvider.getState().getProviderByName('mlx')- ?.models.some((m: { id: string }) => m.id === variant.model_id)+ ?.models.some(+ (m: { id: string }) =>+ m.id === variant.model_id ||+ m.id === `${model.developer}/${sanitizeModelId(variant.model_id)}`+ )+return isLlamaCppDownloaded || isMlxDownloaded}),}))