jan/web/hooks/useDeleteModel.ts
NamH 52d56a8ae1
refactor: move file to jan root (#598)
* feat: move necessary files to jan root

Signed-off-by: James <james@jan.ai>

* chore: check model dir

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
Co-authored-by: Louis <louis@jan.ai>
2023-11-16 12:09:09 +07:00

29 lines
892 B
TypeScript

import { PluginType } from '@janhq/core'
import { ModelPlugin } from '@janhq/core/lib/plugins'
import { Model } from '@janhq/core/lib/types'
import { toaster } from '@/containers/Toast'
import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'
import { pluginManager } from '@/plugin/PluginManager'
import { join } from 'path'
export default function useDeleteModel() {
const { setDownloadedModels, downloadedModels } = useGetDownloadedModels()
const deleteModel = async (model: Model) => {
const path = join('models', model.productName, model.id)
await pluginManager.get<ModelPlugin>(PluginType.Model)?.deleteModel(path)
// reload models
setDownloadedModels(downloadedModels.filter((e) => e.id !== model.id))
toaster({
title: 'Delete a Model',
description: `Model ${model.id} has been deleted.`,
})
}
return { deleteModel }
}