Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions web-app/src/routes/hub/$modelId.tsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,76 @@
import HeaderPage from '@/containers/HeaderPage'
import {

Check warning on line 2 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

1-2 lines are not covered with tests
createFileRoute,
useParams,
useNavigate,
useSearch,
} from '@tanstack/react-router'
import {

Check warning on line 8 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

8 line is not covered with tests
IconArrowLeft,
IconDownload,
IconClock,
IconFileCode,
} from '@tabler/icons-react'
import { route } from '@/constants/routes'
import { useModelSources } from '@/hooks/useModelSources'
import { extractModelName, extractDescription } from '@/lib/models'
import { RenderMarkdown } from '@/containers/RenderMarkdown'
import { useEffect, useMemo, useCallback, useState } from 'react'
import { useModelProvider } from '@/hooks/useModelProvider'
import { useDownloadStore } from '@/hooks/useDownloadStore'
import {

Check warning on line 21 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

14-21 lines are not covered with tests
CatalogModel,
convertHfRepoToCatalogModel,
fetchHuggingFaceRepo,
pullModel,
} from '@/services/models'
import { Progress } from '@/components/ui/progress'
import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'
import { useGeneralSetting } from '@/hooks/useGeneralSetting'

Check warning on line 30 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

27-30 lines are not covered with tests

type SearchParams = {
repo: string
}

export const Route = createFileRoute('/hub/$modelId')({
component: HubModelDetail,
validateSearch: (search: Record<string, unknown>): SearchParams => ({
repo: search.repo as SearchParams['repo'],
}),
})

Check warning on line 41 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

36-41 lines are not covered with tests

function HubModelDetail() {
const { modelId } = useParams({ from: Route.id })
const navigate = useNavigate()
const { huggingfaceToken } = useGeneralSetting()
const { sources, fetchSources } = useModelSources()

Check warning on line 47 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

43-47 lines are not covered with tests
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const search = useSearch({ from: Route.id as any })
const { getProviderByName } = useModelProvider()
const llamaProvider = getProviderByName('llamacpp')
const { downloads, localDownloadingModels, addLocalDownloadingModel } =
useDownloadStore()
const [repoData, setRepoData] = useState<CatalogModel | undefined>()

Check warning on line 54 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

49-54 lines are not covered with tests

// State for README content
const [readmeContent, setReadmeContent] = useState<string>('')
const [isLoadingReadme, setIsLoadingReadme] = useState(false)

Check warning on line 58 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

57-58 lines are not covered with tests

useEffect(() => {
fetchSources()
}, [fetchSources])

Check warning on line 62 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

60-62 lines are not covered with tests

const fetchRepo = useCallback(async () => {
const repoInfo = await fetchHuggingFaceRepo(search.repo || modelId)
const repoInfo = await fetchHuggingFaceRepo(
search.repo || modelId,
huggingfaceToken
)
if (repoInfo) {
const repoDetail = convertHfRepoToCatalogModel(repoInfo)
setRepoData(repoDetail)
}
}, [modelId, search])
}, [modelId, search, huggingfaceToken])

Check warning on line 73 in web-app/src/routes/hub/$modelId.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

64-73 lines are not covered with tests

useEffect(() => {
fetchRepo()
Expand Down Expand Up @@ -151,7 +156,20 @@
useEffect(() => {
if (modelData?.readme) {
setIsLoadingReadme(true)
// Try fetching without headers first
// There is a weird issue where this HF link will return error when access public repo with auth header
fetch(modelData.readme)
.then((response) => {
if (!response.ok && huggingfaceToken && modelData?.readme) {
// Retry with Authorization header if first fetch failed
return fetch(modelData.readme, {
headers: {
Authorization: `Bearer ${huggingfaceToken}`,
},
})
}
return response
})
.then((response) => response.text())
.then((content) => {
setReadmeContent(content)
Expand All @@ -162,7 +180,7 @@
setIsLoadingReadme(false)
})
}
}, [modelData?.readme])
}, [modelData?.readme, huggingfaceToken])

if (!modelData) {
return (
Expand Down
Loading