Skip to content

Commit 836990b

Browse files
committed
chore: update fn check mmproj file
1 parent 4141910 commit 836990b

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

extensions/llamacpp-extension/src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,22 @@ export default class llamacpp_extension extends AIEngine {
17291729
*/
17301730
async checkMmprojExists(modelId: string): Promise<boolean> {
17311731
try {
1732+
const modelConfigPath = await joinPath([
1733+
await this.getProviderPath(),
1734+
'models',
1735+
modelId,
1736+
'model.yml',
1737+
])
1738+
1739+
const modelConfig = await invoke<ModelConfig>('read_yaml', {
1740+
path: modelConfigPath,
1741+
})
1742+
1743+
// If mmproj_path is not defined in YAML, return false
1744+
if (modelConfig.mmproj_path) {
1745+
return true
1746+
}
1747+
17321748
const mmprojPath = await joinPath([
17331749
await this.getProviderPath(),
17341750
'models',

web-app/src/containers/dialogs/ImportVisionModelDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
type ImportVisionModelDialogProps = {
2323
provider: ModelProvider
2424
trigger?: React.ReactNode
25-
onSuccess?: () => void
25+
onSuccess?: (importedModelName?: string) => void
2626
}
2727

2828
export const ImportVisionModelDialog = ({
@@ -114,7 +114,7 @@ export const ImportVisionModelDialog = ({
114114
// Reset form and close dialog
115115
resetForm()
116116
setOpen(false)
117-
onSuccess?.()
117+
onSuccess?.(modelName)
118118
} catch (error) {
119119
console.error('Import model error:', error)
120120
toast.error('Failed to import model', {

web-app/src/routes/settings/providers/$providerName.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,45 @@ function ProviderDetail() {
9090
!setting.controller_props.value)
9191
)
9292

93-
const handleModelImportSuccess = async () => {
93+
const handleModelImportSuccess = async (importedModelName?: string) => {
9494
// Refresh the provider to update the models list
9595
await serviceHub.providers().getProviders().then(setProviders)
96+
97+
// If a model was imported and it might have vision capabilities, check and update
98+
if (importedModelName && providerName === 'llamacpp') {
99+
try {
100+
const mmprojExists = await serviceHub.models().checkMmprojExists(importedModelName)
101+
if (mmprojExists) {
102+
// Get the updated provider after refresh
103+
const { getProviderByName, updateProvider: updateProviderState } = useModelProvider.getState()
104+
const llamacppProvider = getProviderByName('llamacpp')
105+
106+
if (llamacppProvider) {
107+
const modelIndex = llamacppProvider.models.findIndex(
108+
(m: Model) => m.id === importedModelName
109+
)
110+
if (modelIndex !== -1) {
111+
const model = llamacppProvider.models[modelIndex]
112+
const capabilities = model.capabilities || []
113+
114+
// Add 'vision' capability if not already present
115+
if (!capabilities.includes('vision')) {
116+
const updatedModels = [...llamacppProvider.models]
117+
updatedModels[modelIndex] = {
118+
...model,
119+
capabilities: [...capabilities, 'vision'],
120+
}
121+
122+
updateProviderState('llamacpp', { models: updatedModels })
123+
console.log(`Vision capability added to model after provider refresh: ${importedModelName}`)
124+
}
125+
}
126+
}
127+
}
128+
} catch (error) {
129+
console.error('Error checking mmproj existence after import:', error)
130+
}
131+
}
96132
}
97133

98134
useEffect(() => {

0 commit comments

Comments
 (0)