chore: update validation logic
This commit is contained in:
parent
f2594134c7
commit
94dc298181
@ -59,24 +59,24 @@ export const ImportVisionModelDialog = ({
|
|||||||
try {
|
try {
|
||||||
console.log(`Reading GGUF metadata for ${fileType}:`, filePath)
|
console.log(`Reading GGUF metadata for ${fileType}:`, filePath)
|
||||||
|
|
||||||
// Try to use the validateGgufFile method if available
|
// Handle validation differently for model files vs mmproj files
|
||||||
if (typeof serviceHub.models().validateGgufFile === 'function') {
|
if (fileType === 'model') {
|
||||||
const result = await serviceHub.models().validateGgufFile(filePath)
|
// For model files, use the standard validateGgufFile method
|
||||||
|
if (typeof serviceHub.models().validateGgufFile === 'function') {
|
||||||
|
const result = await serviceHub.models().validateGgufFile(filePath)
|
||||||
|
|
||||||
if (result.metadata) {
|
if (result.metadata) {
|
||||||
// Log full metadata for debugging
|
// Log full metadata for debugging
|
||||||
console.log(
|
console.log(
|
||||||
`Full GGUF metadata for ${fileType}:`,
|
`Full GGUF metadata for ${fileType}:`,
|
||||||
JSON.stringify(result.metadata, null, 2)
|
JSON.stringify(result.metadata, null, 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check architecture from metadata
|
// Check architecture from metadata
|
||||||
const architecture =
|
const architecture =
|
||||||
result.metadata.metadata?.['general.architecture']
|
result.metadata.metadata?.['general.architecture']
|
||||||
console.log(`${fileType} architecture:`, architecture)
|
console.log(`${fileType} architecture:`, architecture)
|
||||||
|
|
||||||
// Validate based on file type
|
|
||||||
if (fileType === 'model') {
|
|
||||||
// Model files should NOT be clip
|
// Model files should NOT be clip
|
||||||
if (architecture === 'clip') {
|
if (architecture === 'clip') {
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
@ -92,33 +92,15 @@ export const ImportVisionModelDialog = ({
|
|||||||
architecture
|
architecture
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
// MMProj files MUST be clip
|
|
||||||
if (architecture !== 'clip') {
|
if (!result.isValid) {
|
||||||
const errorMessage = `This MMProj file has "${architecture}" architecture but should have "clip" architecture. MMProj files must be CLIP models for vision processing.`
|
setValidationError(result.error || 'Model validation failed')
|
||||||
setMmprojValidationError(errorMessage)
|
console.error('Model validation failed:', result.error)
|
||||||
console.error(
|
|
||||||
'Non-CLIP architecture detected in mmproj file:',
|
|
||||||
architecture
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
'MMProj validation passed. Architecture:',
|
|
||||||
architecture
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.isValid && fileType === 'model') {
|
|
||||||
setValidationError(result.error || 'Model validation failed')
|
|
||||||
console.error('Model validation failed:', result.error)
|
|
||||||
} else if (!result.isValid && fileType === 'mmproj') {
|
|
||||||
setMmprojValidationError(result.error || 'MMProj validation failed')
|
|
||||||
console.error('MMProj validation failed:', result.error)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Fallback: Try to call the Tauri plugin directly if available
|
// For mmproj files, we need to manually validate since validateGgufFile rejects CLIP models
|
||||||
try {
|
try {
|
||||||
// Import the readGgufMetadata function directly from Tauri
|
// Import the readGgufMetadata function directly from Tauri
|
||||||
const { invoke } = await import('@tauri-apps/api/core')
|
const { invoke } = await import('@tauri-apps/api/core')
|
||||||
@ -138,47 +120,26 @@ export const ImportVisionModelDialog = ({
|
|||||||
).metadata?.['general.architecture']
|
).metadata?.['general.architecture']
|
||||||
console.log(`${fileType} architecture:`, architecture)
|
console.log(`${fileType} architecture:`, architecture)
|
||||||
|
|
||||||
if (fileType === 'model') {
|
// MMProj files MUST be clip
|
||||||
// Model files should NOT be clip
|
if (architecture !== 'clip') {
|
||||||
if (architecture === 'clip') {
|
const errorMessage = `This MMProj file has "${architecture}" architecture but should have "clip" architecture. MMProj files must be CLIP models for vision processing.`
|
||||||
const errorMessage =
|
setMmprojValidationError(errorMessage)
|
||||||
'This model has CLIP architecture and cannot be imported as a text generation model. CLIP models are designed for vision tasks and require different handling.'
|
console.error(
|
||||||
setValidationError(errorMessage)
|
'Non-CLIP architecture detected in mmproj file:',
|
||||||
console.error(
|
architecture
|
||||||
'CLIP architecture detected in model file:',
|
)
|
||||||
architecture
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
'Model validation passed. Architecture:',
|
|
||||||
architecture
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// MMProj files MUST be clip
|
console.log(
|
||||||
if (architecture !== 'clip') {
|
'MMProj validation passed. Architecture:',
|
||||||
const errorMessage = `This MMProj file has "${architecture}" architecture but should have "clip" architecture. MMProj files must be CLIP models for vision processing.`
|
architecture
|
||||||
setMmprojValidationError(errorMessage)
|
)
|
||||||
console.error(
|
|
||||||
'Non-CLIP architecture detected in mmproj file:',
|
|
||||||
architecture
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
'MMProj validation passed. Architecture:',
|
|
||||||
architecture
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (tauriError) {
|
} catch (directError) {
|
||||||
console.warn(
|
console.error('Failed to validate mmproj file directly:', directError)
|
||||||
`Tauri validation fallback failed for ${fileType}:`,
|
const errorMessage = `Failed to read MMProj metadata: ${
|
||||||
tauriError
|
directError instanceof Error ? directError.message : 'Unknown error'
|
||||||
)
|
}`
|
||||||
// Final fallback: just warn and allow
|
setMmprojValidationError(errorMessage)
|
||||||
console.log(
|
|
||||||
`${fileType} validation skipped - validation service not available`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user