77 TooltipTrigger ,
88} from '@/components/ui/tooltip'
99import { isModelSupported } from '@/services/models'
10- import { getJanDataFolderPath , joinPath } from '@janhq/core'
10+ import { getJanDataFolderPath , joinPath , fs } from '@janhq/core'
11+ import { invoke } from '@tauri-apps/api/core'
1112
1213interface ModelSupportStatusProps {
1314 modelId : string | undefined
@@ -31,27 +32,60 @@ export const ModelSupportStatus = ({
3132 async (
3233 id : string ,
3334 ctxSize : number
34- ) : Promise < 'RED' | 'YELLOW' | 'GREEN' > => {
35+ ) : Promise < 'RED' | 'YELLOW' | 'GREEN' | null > => {
3536 try {
36- // Get Jan's data folder path and construct the full model file path
37- // Following the llamacpp extension structure: <Jan's data folder>/llamacpp/models/<modelId>/model.gguf
3837 const janDataFolder = await getJanDataFolderPath ( )
39- const modelFilePath = await joinPath ( [
38+
39+ // First try the standard downloaded model path
40+ const ggufModelPath = await joinPath ( [
4041 janDataFolder ,
4142 'llamacpp' ,
4243 'models' ,
4344 id ,
4445 'model.gguf' ,
4546 ] )
4647
47- return await isModelSupported ( modelFilePath , ctxSize )
48+ // Check if the standard model.gguf file exists
49+ if ( await fs . existsSync ( ggufModelPath ) ) {
50+ return await isModelSupported ( ggufModelPath , ctxSize )
51+ }
52+
53+ // If model.gguf doesn't exist, try reading from model.yml (for imported models)
54+ const modelConfigPath = await joinPath ( [
55+ janDataFolder ,
56+ 'llamacpp' ,
57+ 'models' ,
58+ id ,
59+ 'model.yml' ,
60+ ] )
61+
62+ if ( ! ( await fs . existsSync ( modelConfigPath ) ) ) {
63+ console . error (
64+ `Neither model.gguf nor model.yml found for model: ${ id } `
65+ )
66+ return null
67+ }
68+
69+ // Read the model configuration to get the actual model path
70+ const modelConfig = await invoke < { model_path : string } > ( 'read_yaml' , {
71+ path : `llamacpp/models/${ id } /model.yml` ,
72+ } )
73+
74+ // Handle both absolute and relative paths
75+ const actualModelPath =
76+ modelConfig . model_path . startsWith ( '/' ) ||
77+ modelConfig . model_path . match ( / ^ [ A - Z a - z ] : / )
78+ ? modelConfig . model_path // absolute path, use as-is
79+ : await joinPath ( [ janDataFolder , modelConfig . model_path ] ) // relative path, join with data folder
80+
81+ return await isModelSupported ( actualModelPath , ctxSize )
4882 } catch ( error ) {
4983 console . error (
50- 'Error checking model support with constructed path:' ,
84+ 'Error checking model support with path resolution :' ,
5185 error
5286 )
5387 // If path construction or model support check fails, assume not supported
54- return 'RED'
88+ return null
5589 }
5690 } ,
5791 [ ]
0 commit comments