From 1435cd316284b163744680ca100bcd29ab93ca55 Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Mon, 19 May 2025 12:35:18 +0700 Subject: [PATCH] chore: add functional use button when download complete --- web-app/src/containers/DownloadManegement.tsx | 4 +- web-app/src/routes/hub.tsx | 109 ++++++++++++++---- web-app/src/routes/index.tsx | 20 +++- 3 files changed, 103 insertions(+), 30 deletions(-) diff --git a/web-app/src/containers/DownloadManegement.tsx b/web-app/src/containers/DownloadManegement.tsx index 5a04d2c86..4a347464a 100644 --- a/web-app/src/containers/DownloadManegement.tsx +++ b/web-app/src/containers/DownloadManegement.tsx @@ -125,7 +125,7 @@ export function DownloadManagement() {
- {overallProgress.toFixed(2)}% + {Math.round(overallProgress * 100)}%
@@ -175,7 +175,7 @@ export function DownloadManagement() { />

{`${renderGB(download.current)} / ${renderGB(download.total)}`}{' '} - GB ({download.progress.toFixed(2)}%) + GB ({Math.round(download.progress * 100)}%)

))} diff --git a/web-app/src/routes/hub.tsx b/web-app/src/routes/hub.tsx index f99bf988f..af6819ce0 100644 --- a/web-app/src/routes/hub.tsx +++ b/web-app/src/routes/hub.tsx @@ -1,9 +1,10 @@ -import { createFileRoute, Link } from '@tanstack/react-router' +import { createFileRoute, Link, useNavigate } from '@tanstack/react-router' import { route } from '@/constants/routes' import { useModelSources } from '@/hooks/useModelSources' import { cn, fuzzySearch, toGigabytes } from '@/lib/utils' -import { useState, useMemo, useEffect, ChangeEvent } from 'react' +import { useState, useMemo, useEffect, ChangeEvent, useCallback } from 'react' import { Button } from '@/components/ui/button' +import { useModelProvider } from '@/hooks/useModelProvider' import { Card, CardItem } from '@/containers/Card' import { RenderMarkdown } from '@/containers/RenderMarkdown' import { extractModelName, extractDescription } from '@/lib/models' @@ -19,6 +20,15 @@ import { downloadModel } from '@/services/models' import { useDownloadStore } from '@/hooks/useDownloadStore' import { Progress } from '@/components/ui/progress' +type ModelProps = { + model: { + id: string + models: { + id: string + }[] + } +} + // eslint-disable-next-line @typescript-eslint/no-explicit-any export const Route = createFileRoute(route.hub as any)({ component: Hub, @@ -93,14 +103,26 @@ function Hub() { [downloads] ) - interface ModelProps { - model: { - id: string - models: { - id: string - }[] - } - } + const { getProviderByName } = useModelProvider() + const llamaProvider = getProviderByName('llama.cpp') + + const navigate = useNavigate() + + const handleUseModel = useCallback( + (modelId: string) => { + navigate({ + to: route.home, + params: {}, + search: { + model: { + id: modelId, + provider: 'llama.cpp', + }, + }, + }) + }, + [navigate] + ) const DownloadButtonPlaceholder = useMemo(() => { return ({ model }: ModelProps) => { @@ -108,6 +130,9 @@ function Hub() { const isDownloading = downloadProcesses.some((e) => e.id === modelId) const downloadProgress = downloadProcesses.find((e) => e.id === modelId)?.progress || 0 + const isDownloaded = llamaProvider?.models.some( + (m: { id: string }) => m.id === modelId + ) return ( <> @@ -118,13 +143,19 @@ function Hub() { {Math.round(downloadProgress * 100)}% + ) : isDownloaded ? ( + ) : ( - + )} ) } - }, [downloadProcesses]) + }, [downloadProcesses, llamaProvider?.models, handleUseModel]) return (
@@ -282,20 +313,50 @@ function Hub() { downloadProcesses.find( (e) => e.id === variant.id )?.progress || 0 + const isDownloaded = + llamaProvider?.models.some( + (m: { id: string }) => + m.id === variant.id + ) - return isDownloading ? ( - <> -
- - - {Math.round(downloadProgress * 100)} - % - + if (isDownloading) { + return ( + <> +
+ + + {Math.round( + downloadProgress * 100 + )} + % + +
+ + ) + } + + if (isDownloaded) { + return ( +
+
- - ) : ( + ) + } + + return (
): SearchParams => ({ + model: search.model as SearchParams['model'], + }), }) function Index() { const { t } = useTranslation() const { providers } = useModelProvider() + const search = useSearch({ from: route.home as any }) + const selectedModel = search.model // Conditional to check if there are any valid providers // required min 1 api_key or 1 model in llama.cpp @@ -31,7 +43,7 @@ function Index() { return (
- +