Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix: regression - model download

Louis4ba51d33d8d3
diff --git a/web-app/src/containers/DownloadButton.tsx b/web-app/src/containers/DownloadButton.tsx
index 5be6bcf77..b4cc07bfe 100644
--- a/web-app/src/containers/DownloadButton.tsx
+++ b/web-app/src/containers/DownloadButton.tsx
@@ -10,9 +10,6 @@ import { cn, sanitizeModelId } from '@/lib/utils'
import { CatalogModel } from '@/services/models/types'
import { DownloadEvent, DownloadState, events } from '@janhq/core'
import { useCallback, useEffect, useMemo, useState } from 'react'
-import { toast } from 'sonner'
-import { route } from '@/constants/routes'
-import { useNavigate } from '@tanstack/react-router'
import { useShallow } from 'zustand/shallow'
import { DEFAULT_MODEL_QUANTIZATIONS } from '@/constants/models'
@@ -40,7 +37,6 @@ export function DownloadButtonPlaceholder({
const serviceHub = useServiceHub()
const huggingfaceToken = useGeneralSetting((state) => state.huggingfaceToken)
const [isDownloaded, setDownloaded] = useState<boolean>(false)
- const navigate = useNavigate()
const quant =
model.quants.find((e) =>
@@ -112,69 +108,6 @@ export function DownloadButtonPlaceholder({
const isRecommended = isRecommendedModel(model.model_name)
const handleDownload = async () => {
- // Preflight check for gated repos/artifacts
- const preflight = await serviceHub
- .models()
- .preflightArtifactAccess(modelUrl, huggingfaceToken)
-
- if (!preflight.ok) {
- const repoPage = `https://huggingface.co/${model.model_name}`
-
- if (preflight.reason === 'AUTH_REQUIRED') {
- toast.error('Hugging Face token required', {
- description:
- 'This model requires a Hugging Face access token. Add your token in Settings and retry.',
- action: {
- label: 'Open Settings',
- onClick: () => navigate({ to: route.settings.general }),
- },
- })
- return
- }
-
- if (preflight.reason === 'LICENSE_NOT_ACCEPTED') {
- toast.error('Accept model license on Hugging Face', {
- description:
- 'You must accept the model’s license on its Hugging Face page before downloading.',
- action: {
- label: 'Open model page',
- onClick: () => window.open(repoPage, '_blank'),
- },
- })
- return
- }
-
- if (preflight.reason === 'RATE_LIMITED') {
- toast.error('Rate limited by Hugging Face', {
- description:
- 'You have been rate-limited. Adding a token can increase rate limits. Please try again later.',
- action: {
- label: 'Open Settings',
- onClick: () => navigate({ to: route.settings.general }),
- },
- })
- return
- }
-
- if (preflight.reason === 'NOT_FOUND') {
- toast.error('File not found', {
- description:
- 'The requested artifact was not found in the repository. Try another quant or check the model page.',
- action: {
- label: 'Open model page',
- onClick: () => window.open(repoPage, '_blank'),
- },
- })
- return
- }
-
- toast.error('Model download error', {
- description:
- 'We could not start the download. Check your network or try again later.',
- })
- return
- }
-
// Immediately set local downloading state and start download
addLocalDownloadingModel(modelId)
const mmprojPath = (
diff --git a/web-app/src/containers/ModelDownloadAction.tsx b/web-app/src/containers/ModelDownloadAction.tsx
index e32fd642d..e975621dd 100644
--- a/web-app/src/containers/ModelDownloadAction.tsx
+++ b/web-app/src/containers/ModelDownloadAction.tsx
@@ -10,7 +10,6 @@ import { CatalogModel } from '@/services/models/types'
import { IconDownload } from '@tabler/icons-react'
import { useNavigate } from '@tanstack/react-router'
import { useCallback, useMemo } from 'react'
-import { toast } from 'sonner'
export const ModelDownloadAction = ({
variant,
@@ -56,76 +55,6 @@ export const ModelDownloadAction = ({
)
const handleDownloadModel = useCallback(async () => {
- const preflight = await serviceHub
- .models()
- .preflightArtifactAccess(variant.path, huggingfaceToken)
-
- const repoPage = `https://huggingface.co/${model.model_name}`
-
- if (!preflight.ok) {
- if (preflight.reason === 'AUTH_REQUIRED') {
- toast.error('Hugging Face token required', {
- description:
- 'This model requires a Hugging Face access token. Add your token in Settings and retry.',
- action: {
- label: 'Open Settings',
- onClick: () =>
- navigate({
- to: route.settings.general,
- params: {},
- }),
- },
- })
- return
- }
-
- if (preflight.reason === 'LICENSE_NOT_ACCEPTED') {
- toast.error('Accept model license on Hugging Face', {
- description:
- 'You must accept the model’s license on its Hugging Face page before downloading.',
- action: {
- label: 'Open model page',
- onClick: () => window.open(repoPage, '_blank'),
- },
- })
- return
- }
-
- if (preflight.reason === 'RATE_LIMITED') {
- toast.error('Rate limited by Hugging Face', {
- description:
- 'You have been rate-limited. Adding a token can increase rate limits. Please try again later.',
- action: {
- label: 'Open Settings',
- onClick: () =>
- navigate({
- to: route.settings.general,
- params: {},
- }),
- },
- })
- return
- }
-
- if (preflight.reason === 'NOT_FOUND') {
- toast.error('Model file not found', {
- description:
- 'The requested model could not be found. Please verify the model URL',
- action: {
- label: 'Open model page',
- onClick: () => window.open(repoPage, '_blank'),
- },
- })
- return
- }
-
- toast.error('Unable to start download', {
- description:
- 'Jan encountered an issue. Please check your connection and try again.',
- })
- return
- }
-
addLocalDownloadingModel(variant.model_id)
serviceHub
.models()
diff --git a/web-app/src/services/models/default.ts b/web-app/src/services/models/default.ts
index 65aabc152..11d167a3a 100644
--- a/web-app/src/services/models/default.ts
+++ b/web-app/src/services/models/default.ts
@@ -24,7 +24,6 @@ import type {
ModelValidationResult,
ModelPlan,
} from './types'
-import { PreflightResult } from './types'
// TODO: Replace this with the actual provider later
const defaultProvider = 'llamacpp'
@@ -106,37 +105,6 @@ export class DefaultModelsService implements ModelsService {
}
}
- async preflightArtifactAccess(
- url: string,
- hfToken?: string
- ): Promise<PreflightResult> {
- try {
- const resp = await fetch(url, {
- method: 'HEAD',
- headers: hfToken
- ? {
- Authorization: `Bearer ${hfToken}`,
- }
- : {},
- })
-
- if (resp.ok) {
- return { ok: true, status: resp.status }
- }
-
- const status = resp.status
- if (status === 401) return { ok: false, status, reason: 'AUTH_REQUIRED' }
- if (status === 403)
- return { ok: false, status, reason: 'LICENSE_NOT_ACCEPTED' }
- if (status === 404) return { ok: false, status, reason: 'NOT_FOUND' }
- if (status === 429) return { ok: false, status, reason: 'RATE_LIMITED' }
- return { ok: false, status, reason: 'UNKNOWN' }
- } catch (e) {
- console.warn('Preflight artifact access failed:', e)
- return { ok: false, reason: 'NETWORK' }
- }
- }
-
convertHfRepoToCatalogModel(repo: HuggingFaceRepo): CatalogModel {
// Format file size helper
const formatFileSize = (size?: number) => {
diff --git a/web-app/src/services/models/types.ts b/web-app/src/services/models/types.ts
index 8aef92db4..6a1b0504e 100644
--- a/web-app/src/services/models/types.ts
+++ b/web-app/src/services/models/types.ts
@@ -98,12 +98,6 @@ export type PreflightReason =
| 'NETWORK'
| 'UNKNOWN'
-export interface PreflightResult {
- ok: boolean
- status?: number
- reason?: PreflightReason
-}
-
export interface ModelsService {
getModel(modelId: string): Promise<modelInfo | undefined>
fetchModels(): Promise<modelInfo[]>
@@ -113,10 +107,6 @@ export interface ModelsService {
hfToken?: string
): Promise<HuggingFaceRepo | null>
convertHfRepoToCatalogModel(repo: HuggingFaceRepo): CatalogModel
- preflightArtifactAccess(
- url: string,
- hfToken?: string
- ): Promise<PreflightResult>
updateModel(modelId: string, model: Partial<CoreModel>): Promise<void>
pullModel(
id: string,