feat: Restore Delete Model Functionality

This commit is contained in:
blessedcoolant 2023-07-12 16:39:07 +12:00
parent afb46564e8
commit 5a6ad99d4e
3 changed files with 27 additions and 1 deletions

View File

@ -593,6 +593,7 @@ class ModelManager(object):
rmtree(str(model_path)) rmtree(str(model_path))
else: else:
model_path.unlink() model_path.unlink()
self.commit()
# LS: tested # LS: tested
def add_model( def add_model(

View File

@ -8,6 +8,7 @@ import IAIAlertDialog from 'common/components/IAIAlertDialog';
import IAIIconButton from 'common/components/IAIIconButton'; import IAIIconButton from 'common/components/IAIIconButton';
import { setOpenModel } from 'features/system/store/systemSlice'; import { setOpenModel } from 'features/system/store/systemSlice';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useDeleteMainModelsMutation } from 'services/api/endpoints/models';
type ModelListItemProps = { type ModelListItemProps = {
modelKey: string; modelKey: string;
@ -24,6 +25,8 @@ export default function ModelListItem(props: ModelListItemProps) {
(state: RootState) => state.system.openModel (state: RootState) => state.system.openModel
); );
const [deleteMainModel] = useDeleteMainModelsMutation();
const { t } = useTranslation(); const { t } = useTranslation();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -35,7 +38,11 @@ export default function ModelListItem(props: ModelListItemProps) {
}; };
const handleModelDelete = () => { const handleModelDelete = () => {
dispatch(deleteModel(modelKey)); const [base_model, _, model_name] = modelKey.split('/');
deleteMainModel({
base_model: base_model,
model_name: model_name,
});
dispatch(setOpenModel(null)); dispatch(setOpenModel(null));
}; };

View File

@ -39,6 +39,11 @@ type UpdateMainModelQuery = {
body: MainModelConfig; body: MainModelConfig;
}; };
type DeleteMainModelQuery = {
base_model: BaseModelType;
model_name: string;
};
const mainModelsAdapter = createEntityAdapter<MainModelConfigEntity>({ const mainModelsAdapter = createEntityAdapter<MainModelConfigEntity>({
sortComparer: (a, b) => a.name.localeCompare(b.name), sortComparer: (a, b) => a.name.localeCompare(b.name),
}); });
@ -121,6 +126,18 @@ export const modelsApi = api.injectEndpoints({
}, },
invalidatesTags: ['MainModel'], invalidatesTags: ['MainModel'],
}), }),
deleteMainModels: build.mutation<
EntityState<MainModelConfigEntity>,
DeleteMainModelQuery
>({
query: ({ base_model, model_name }) => {
return {
url: `models/${base_model}/main/${model_name}`,
method: 'DELETE',
};
},
invalidatesTags: ['MainModel'],
}),
getLoRAModels: build.query<EntityState<LoRAModelConfigEntity>, void>({ getLoRAModels: build.query<EntityState<LoRAModelConfigEntity>, void>({
query: () => ({ url: 'models/', params: { model_type: 'lora' } }), query: () => ({ url: 'models/', params: { model_type: 'lora' } }),
providesTags: (result, error, arg) => { providesTags: (result, error, arg) => {
@ -265,4 +282,5 @@ export const {
useGetTextualInversionModelsQuery, useGetTextualInversionModelsQuery,
useGetVaeModelsQuery, useGetVaeModelsQuery,
useUpdateMainModelsMutation, useUpdateMainModelsMutation,
useDeleteMainModelsMutation,
} = modelsApi; } = modelsApi;