Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat: remotely fetch Jan latest model during the onboarding
Vanalite00978535ed30
diff --git a/web-app/src/constants/models.ts b/web-app/src/constants/models.tsindex b43cdd9da..e087d1329 100644--- a/web-app/src/constants/models.ts+++ b/web-app/src/constants/models.ts@@ -2,7 +2,6 @@* Model-related constants*/-export const NEW_JAN_MODEL_HF_REPO = 'janhq/Jan-v3-4B-base-instruct-GGUF'export const JAN_CODE_HF_REPO = 'janhq/Jan-Code-4b-Gguf'export const DEFAULT_MODEL_QUANTIZATIONS = ['iq4_xs', 'q4_k_m']diff --git a/web-app/src/containers/PromptJanModel.tsx b/web-app/src/containers/PromptJanModel.tsxindex 8fb32d843..653091b10 100644--- a/web-app/src/containers/PromptJanModel.tsx+++ b/web-app/src/containers/PromptJanModel.tsx@@ -5,10 +5,7 @@ import { useDownloadStore } from '@/hooks/useDownloadStore'import { useGeneralSetting } from '@/hooks/useGeneralSetting'import { useEffect, useState, useMemo, useCallback, useRef } from 'react'import type { CatalogModel } from '@/services/models/types'-import {- NEW_JAN_MODEL_HF_REPO,- SETUP_SCREEN_QUANTIZATIONS,-} from '@/constants/models'+import { SETUP_SCREEN_QUANTIZATIONS } from '@/constants/models'export function PromptJanModel() {@@ -27,22 +24,17 @@ export function PromptJanModel() {fetchAttempted.current = truetry {- const repo = await serviceHub- .models()- .fetchHuggingFaceRepo(NEW_JAN_MODEL_HF_REPO, huggingfaceToken)-- if (repo) {- const catalogModel = serviceHub- .models()- .convertHfRepoToCatalogModel(repo)- setJanNewModel(catalogModel)+ const model = await serviceHub.models().fetchLatestJanModel()++ if (model) {+ setJanNewModel(model)}} catch (error) {- console.error('Error fetching Jan Model:', error)+ console.error('Error fetching latest Jan model:', error)} finally {setIsLoading(false)}- }, [serviceHub, huggingfaceToken])+ }, [serviceHub])useEffect(() => {fetchJanModel()@@ -98,7 +90,7 @@ export function PromptJanModel() {<div className="flex items-center gap-2"><img src="/images/jan-logo.png" alt="Jan" className="size-5" /><h2 className="font-medium">- Jan v3 Model+ {janNewModel?.display_name ?? janNewModel?.model_name ?? 'Jan Model'}{defaultVariant && (<span className="text-muted-foreground">{' '}@@ -108,7 +100,7 @@ export function PromptJanModel() {</h2></div><p className="mt-2 text-sm text-muted-foreground">- Get started with Jan v3, our recommended local AI model optimized for your device.+ Get started with {janNewModel?.display_name ?? 'Jan'}, our recommended local AI model optimized for your device.</p><div className="mt-4 flex justify-end space-x-2"><Buttondiff --git a/web-app/src/containers/SetupScreen.tsx b/web-app/src/containers/SetupScreen.tsxindex 61efd7788..fbab3e6ab 100644--- a/web-app/src/containers/SetupScreen.tsx+++ b/web-app/src/containers/SetupScreen.tsx@@ -8,10 +8,7 @@ import { useServiceHub } from '@/hooks/useServiceHub'import { useEffect, useMemo, useCallback, useState, useRef } from 'react'import { AppEvent, events } from '@janhq/core'import type { CatalogModel } from '@/services/models/types'-import {- NEW_JAN_MODEL_HF_REPO,- SETUP_SCREEN_QUANTIZATIONS,-} from '@/constants/models'+import { SETUP_SCREEN_QUANTIZATIONS } from '@/constants/models'import { toast } from 'sonner'import { Button } from '@/components/ui/button'import { IconEye, IconSquareCheck } from '@tabler/icons-react'@@ -105,23 +102,18 @@ function SetupScreen() {const fetchJanModel = useCallback(async () => {setMetadataFetchFailed(false)try {- const repo = await serviceHub- .models()- .fetchHuggingFaceRepo(NEW_JAN_MODEL_HF_REPO, huggingfaceToken)+ const model = await serviceHub.models().fetchLatestJanModel()- if (repo) {- const catalogModel = serviceHub- .models()- .convertHfRepoToCatalogModel(repo)- setJanNewModel(catalogModel)+ if (model) {+ setJanNewModel(model)} else {setMetadataFetchFailed(true)}} catch (error) {- console.error('Error fetching Jan Model V2:', error)+ console.error('Error fetching latest Jan model:', error)setMetadataFetchFailed(true)}- }, [serviceHub, huggingfaceToken])+ }, [serviceHub])// Check model support for variants when janNewModel is availableuseEffect(() => {@@ -459,7 +451,7 @@ function SetupScreen() {<div className="flex flex-col w-full h-full justify-center"><div className="flex flex-1 items-center justify-between"><h1 className="font-semibold text-sm mb-1">- <span>Jan v3</span> <span className='text-xs text-muted-foreground'>· {defaultVariant?.file_size}</span>+ <span>{janNewModel?.display_name ?? janNewModel?.model_name ?? 'Jan Model'}</span> <span className='text-xs text-muted-foreground'>· {defaultVariant?.file_size}</span></h1>{(isDownloading) && (<div className="flex items-center gap-1.5 text-xs text-muted-foreground">diff --git a/web-app/src/services/models/default.ts b/web-app/src/services/models/default.tsindex 8d50fdc6d..702e31255 100644--- a/web-app/src/services/models/default.ts+++ b/web-app/src/services/models/default.ts@@ -60,6 +60,25 @@ export class DefaultModelsService implements ModelsService {}}+ async fetchLatestJanModel(): Promise<CatalogModel | null> {+ try {+ const response = await fetch(LATEST_JAN_MODEL_URL)++ if (!response.ok) {+ console.error(+ `Failed to fetch latest Jan model: ${response.status} ${response.statusText}`+ )+ return null+ }++ const model: CatalogModel = await response.json()+ return model+ } catch (error) {+ console.error('Error fetching latest Jan model:', error)+ return null+ }+ }+async fetchHuggingFaceRepo(repoId: string,hfToken?: stringdiff --git a/web-app/src/services/models/types.ts b/web-app/src/services/models/types.tsindex fe14934d8..6384b708d 100644--- a/web-app/src/services/models/types.ts+++ b/web-app/src/services/models/types.ts@@ -27,6 +27,7 @@ export interface SafetensorsFile {export interface CatalogModel {model_name: string+ display_name?: stringdescription: stringlibrary_name?: stringdeveloper?: string@@ -105,6 +106,7 @@ export interface ModelsService {getModel(modelId: string): Promise<modelInfo | undefined>fetchModels(): Promise<modelInfo[]>fetchModelCatalog(): Promise<ModelCatalog>+ fetchLatestJanModel(): Promise<CatalogModel | null>fetchHuggingFaceRepo(repoId: string,hfToken?: stringdiff --git a/web-app/src/types/global.d.ts b/web-app/src/types/global.d.tsindex c94104fb1..1994516d9 100644--- a/web-app/src/types/global.d.ts+++ b/web-app/src/types/global.d.ts@@ -20,6 +20,7 @@ declare global {declare const POSTHOG_KEY: stringdeclare const POSTHOG_HOST: stringdeclare const MODEL_CATALOG_URL: string+ declare const LATEST_JAN_MODEL_URL: stringdeclare const AUTO_UPDATER_DISABLED: booleandeclare const UPDATE_CHECK_INTERVAL_MS: numberdeclare const GA_MEASUREMENT_ID: stringdiff --git a/web-app/vite.config.ts b/web-app/vite.config.tsindex e220f3568..1e2ff21fe 100644--- a/web-app/vite.config.ts+++ b/web-app/vite.config.ts@@ -96,6 +96,9 @@ export default defineConfig(({ mode }) => {MODEL_CATALOG_URL: JSON.stringify('https://raw.githubusercontent.com/janhq/model-catalog/main/model_catalog_v2.json'),+ LATEST_JAN_MODEL_URL: JSON.stringify(+ 'https://raw.githubusercontent.com/janhq/model-catalog/main/latest_jan_model.json'+ ),AUTO_UPDATER_DISABLED: JSON.stringify(env.AUTO_UPDATER_DISABLED === 'true'),