chore: update fn check mmproj file
This commit is contained in:
parent
4141910ee2
commit
836990b7d9
@ -1729,6 +1729,22 @@ export default class llamacpp_extension extends AIEngine {
|
||||
*/
|
||||
async checkMmprojExists(modelId: string): Promise<boolean> {
|
||||
try {
|
||||
const modelConfigPath = await joinPath([
|
||||
await this.getProviderPath(),
|
||||
'models',
|
||||
modelId,
|
||||
'model.yml',
|
||||
])
|
||||
|
||||
const modelConfig = await invoke<ModelConfig>('read_yaml', {
|
||||
path: modelConfigPath,
|
||||
})
|
||||
|
||||
// If mmproj_path is not defined in YAML, return false
|
||||
if (modelConfig.mmproj_path) {
|
||||
return true
|
||||
}
|
||||
|
||||
const mmprojPath = await joinPath([
|
||||
await this.getProviderPath(),
|
||||
'models',
|
||||
|
||||
@ -22,7 +22,7 @@ import {
|
||||
type ImportVisionModelDialogProps = {
|
||||
provider: ModelProvider
|
||||
trigger?: React.ReactNode
|
||||
onSuccess?: () => void
|
||||
onSuccess?: (importedModelName?: string) => void
|
||||
}
|
||||
|
||||
export const ImportVisionModelDialog = ({
|
||||
@ -114,7 +114,7 @@ export const ImportVisionModelDialog = ({
|
||||
// Reset form and close dialog
|
||||
resetForm()
|
||||
setOpen(false)
|
||||
onSuccess?.()
|
||||
onSuccess?.(modelName)
|
||||
} catch (error) {
|
||||
console.error('Import model error:', error)
|
||||
toast.error('Failed to import model', {
|
||||
|
||||
@ -90,9 +90,45 @@ function ProviderDetail() {
|
||||
!setting.controller_props.value)
|
||||
)
|
||||
|
||||
const handleModelImportSuccess = async () => {
|
||||
const handleModelImportSuccess = async (importedModelName?: string) => {
|
||||
// Refresh the provider to update the models list
|
||||
await serviceHub.providers().getProviders().then(setProviders)
|
||||
|
||||
// If a model was imported and it might have vision capabilities, check and update
|
||||
if (importedModelName && providerName === 'llamacpp') {
|
||||
try {
|
||||
const mmprojExists = await serviceHub.models().checkMmprojExists(importedModelName)
|
||||
if (mmprojExists) {
|
||||
// Get the updated provider after refresh
|
||||
const { getProviderByName, updateProvider: updateProviderState } = useModelProvider.getState()
|
||||
const llamacppProvider = getProviderByName('llamacpp')
|
||||
|
||||
if (llamacppProvider) {
|
||||
const modelIndex = llamacppProvider.models.findIndex(
|
||||
(m: Model) => m.id === importedModelName
|
||||
)
|
||||
if (modelIndex !== -1) {
|
||||
const model = llamacppProvider.models[modelIndex]
|
||||
const capabilities = model.capabilities || []
|
||||
|
||||
// Add 'vision' capability if not already present
|
||||
if (!capabilities.includes('vision')) {
|
||||
const updatedModels = [...llamacppProvider.models]
|
||||
updatedModels[modelIndex] = {
|
||||
...model,
|
||||
capabilities: [...capabilities, 'vision'],
|
||||
}
|
||||
|
||||
updateProviderState('llamacpp', { models: updatedModels })
|
||||
console.log(`Vision capability added to model after provider refresh: ${importedModelName}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking mmproj existence after import:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user