fix: compatibility imported model
This commit is contained in:
parent
39e8d3b80c
commit
f6e4d55f5e
@ -7,7 +7,8 @@ import {
|
|||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from '@/components/ui/tooltip'
|
} from '@/components/ui/tooltip'
|
||||||
import { isModelSupported } from '@/services/models'
|
import { isModelSupported } from '@/services/models'
|
||||||
import { getJanDataFolderPath, joinPath } from '@janhq/core'
|
import { getJanDataFolderPath, joinPath, fs } from '@janhq/core'
|
||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
|
||||||
interface ModelSupportStatusProps {
|
interface ModelSupportStatusProps {
|
||||||
modelId: string | undefined
|
modelId: string | undefined
|
||||||
@ -31,12 +32,12 @@ export const ModelSupportStatus = ({
|
|||||||
async (
|
async (
|
||||||
id: string,
|
id: string,
|
||||||
ctxSize: number
|
ctxSize: number
|
||||||
): Promise<'RED' | 'YELLOW' | 'GREEN'> => {
|
): Promise<'RED' | 'YELLOW' | 'GREEN' | null> => {
|
||||||
try {
|
try {
|
||||||
// Get Jan's data folder path and construct the full model file path
|
|
||||||
// Following the llamacpp extension structure: <Jan's data folder>/llamacpp/models/<modelId>/model.gguf
|
|
||||||
const janDataFolder = await getJanDataFolderPath()
|
const janDataFolder = await getJanDataFolderPath()
|
||||||
const modelFilePath = await joinPath([
|
|
||||||
|
// First try the standard downloaded model path
|
||||||
|
const ggufModelPath = await joinPath([
|
||||||
janDataFolder,
|
janDataFolder,
|
||||||
'llamacpp',
|
'llamacpp',
|
||||||
'models',
|
'models',
|
||||||
@ -44,14 +45,47 @@ export const ModelSupportStatus = ({
|
|||||||
'model.gguf',
|
'model.gguf',
|
||||||
])
|
])
|
||||||
|
|
||||||
return await isModelSupported(modelFilePath, ctxSize)
|
// Check if the standard model.gguf file exists
|
||||||
|
if (await fs.existsSync(ggufModelPath)) {
|
||||||
|
return await isModelSupported(ggufModelPath, ctxSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If model.gguf doesn't exist, try reading from model.yml (for imported models)
|
||||||
|
const modelConfigPath = await joinPath([
|
||||||
|
janDataFolder,
|
||||||
|
'llamacpp',
|
||||||
|
'models',
|
||||||
|
id,
|
||||||
|
'model.yml',
|
||||||
|
])
|
||||||
|
|
||||||
|
if (!(await fs.existsSync(modelConfigPath))) {
|
||||||
|
console.error(
|
||||||
|
`Neither model.gguf nor model.yml found for model: ${id}`
|
||||||
|
)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the model configuration to get the actual model path
|
||||||
|
const modelConfig = await invoke<{ model_path: string }>('read_yaml', {
|
||||||
|
path: `llamacpp/models/${id}/model.yml`,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Handle both absolute and relative paths
|
||||||
|
const actualModelPath =
|
||||||
|
modelConfig.model_path.startsWith('/') ||
|
||||||
|
modelConfig.model_path.match(/^[A-Za-z]:/)
|
||||||
|
? modelConfig.model_path // absolute path, use as-is
|
||||||
|
: await joinPath([janDataFolder, modelConfig.model_path]) // relative path, join with data folder
|
||||||
|
|
||||||
|
return await isModelSupported(actualModelPath, ctxSize)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
'Error checking model support with constructed path:',
|
'Error checking model support with path resolution:',
|
||||||
error
|
error
|
||||||
)
|
)
|
||||||
// If path construction or model support check fails, assume not supported
|
// If path construction or model support check fails, assume not supported
|
||||||
return 'RED'
|
return null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user