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> {
|
async checkMmprojExists(modelId: string): Promise<boolean> {
|
||||||
try {
|
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([
|
const mmprojPath = await joinPath([
|
||||||
await this.getProviderPath(),
|
await this.getProviderPath(),
|
||||||
'models',
|
'models',
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import {
|
|||||||
type ImportVisionModelDialogProps = {
|
type ImportVisionModelDialogProps = {
|
||||||
provider: ModelProvider
|
provider: ModelProvider
|
||||||
trigger?: React.ReactNode
|
trigger?: React.ReactNode
|
||||||
onSuccess?: () => void
|
onSuccess?: (importedModelName?: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ImportVisionModelDialog = ({
|
export const ImportVisionModelDialog = ({
|
||||||
@ -114,7 +114,7 @@ export const ImportVisionModelDialog = ({
|
|||||||
// Reset form and close dialog
|
// Reset form and close dialog
|
||||||
resetForm()
|
resetForm()
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
onSuccess?.()
|
onSuccess?.(modelName)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Import model error:', error)
|
console.error('Import model error:', error)
|
||||||
toast.error('Failed to import model', {
|
toast.error('Failed to import model', {
|
||||||
|
|||||||
@ -90,9 +90,45 @@ function ProviderDetail() {
|
|||||||
!setting.controller_props.value)
|
!setting.controller_props.value)
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleModelImportSuccess = async () => {
|
const handleModelImportSuccess = async (importedModelName?: string) => {
|
||||||
// Refresh the provider to update the models list
|
// Refresh the provider to update the models list
|
||||||
await serviceHub.providers().getProviders().then(setProviders)
|
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(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user