mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): control adapter models select disable if incompatible
This commit is contained in:
committed by
Kent Keirsey
parent
61c10a7ca8
commit
799ef0e7c1
@ -11,13 +11,14 @@ import { useControlAdapterModelEntities } from 'features/controlAdapters/hooks/u
|
|||||||
import { useControlAdapterType } from 'features/controlAdapters/hooks/useControlAdapterType';
|
import { useControlAdapterType } from 'features/controlAdapters/hooks/useControlAdapterType';
|
||||||
import { controlAdapterModelChanged } from 'features/controlAdapters/store/controlAdaptersSlice';
|
import { controlAdapterModelChanged } from 'features/controlAdapters/store/controlAdaptersSlice';
|
||||||
import { pick } from 'lodash-es';
|
import { pick } from 'lodash-es';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import type {
|
import type {
|
||||||
ControlNetModelConfigEntity,
|
ControlNetModelConfigEntity,
|
||||||
IPAdapterModelConfigEntity,
|
IPAdapterModelConfigEntity,
|
||||||
T2IAdapterModelConfigEntity,
|
T2IAdapterModelConfigEntity,
|
||||||
} from 'services/api/endpoints/models';
|
} from 'services/api/endpoints/models';
|
||||||
|
import type { AnyModelConfig } from 'services/api/types';
|
||||||
|
|
||||||
type ParamControlAdapterModelProps = {
|
type ParamControlAdapterModelProps = {
|
||||||
id: string;
|
id: string;
|
||||||
@ -33,7 +34,9 @@ const ParamControlAdapterModel = ({ id }: ParamControlAdapterModelProps) => {
|
|||||||
const controlAdapterType = useControlAdapterType(id);
|
const controlAdapterType = useControlAdapterType(id);
|
||||||
const model = useControlAdapterModel(id);
|
const model = useControlAdapterModel(id);
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
const currentBaseModel = useAppSelector(
|
||||||
|
(state) => state.generation.model?.base_model
|
||||||
|
);
|
||||||
const { mainModel } = useAppSelector(selector);
|
const { mainModel } = useAppSelector(selector);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@ -60,14 +63,29 @@ const ParamControlAdapterModel = ({ id }: ParamControlAdapterModelProps) => {
|
|||||||
[dispatch, id]
|
[dispatch, id]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const selectedModel = useMemo(
|
||||||
|
() =>
|
||||||
|
model && controlAdapterType
|
||||||
|
? { ...model, model_type: controlAdapterType }
|
||||||
|
: null,
|
||||||
|
[controlAdapterType, model]
|
||||||
|
);
|
||||||
|
|
||||||
|
const getIsDisabled = useCallback(
|
||||||
|
(model: AnyModelConfig): boolean => {
|
||||||
|
const isCompatible = currentBaseModel === model.base_model;
|
||||||
|
const hasMainModel = Boolean(currentBaseModel);
|
||||||
|
return !hasMainModel || !isCompatible;
|
||||||
|
},
|
||||||
|
[currentBaseModel]
|
||||||
|
);
|
||||||
|
|
||||||
const { options, value, onChange, noOptionsMessage } =
|
const { options, value, onChange, noOptionsMessage } =
|
||||||
useGroupedModelInvSelect({
|
useGroupedModelInvSelect({
|
||||||
modelEntities: models,
|
modelEntities: models,
|
||||||
onChange: _onChange,
|
onChange: _onChange,
|
||||||
selectedModel:
|
selectedModel,
|
||||||
model && controlAdapterType
|
getIsDisabled,
|
||||||
? { ...model, model_type: controlAdapterType }
|
|
||||||
: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -21,13 +21,14 @@ export const EmbeddingSelect = memo(
|
|||||||
(state) => state.generation.model?.base_model
|
(state) => state.generation.model?.base_model
|
||||||
);
|
);
|
||||||
|
|
||||||
const getIsDisabled = (
|
const getIsDisabled = useCallback(
|
||||||
embedding: TextualInversionModelConfigEntity
|
(embedding: TextualInversionModelConfigEntity): boolean => {
|
||||||
): boolean => {
|
const isCompatible = currentBaseModel === embedding.base_model;
|
||||||
const isCompatible = currentBaseModel === embedding.base_model;
|
const hasMainModel = Boolean(currentBaseModel);
|
||||||
const hasMainModel = Boolean(currentBaseModel);
|
return !hasMainModel || !isCompatible;
|
||||||
return !hasMainModel || !isCompatible;
|
},
|
||||||
};
|
[currentBaseModel]
|
||||||
|
);
|
||||||
const { data, isLoading } = useGetTextualInversionModelsQuery();
|
const { data, isLoading } = useGetTextualInversionModelsQuery();
|
||||||
|
|
||||||
const _onChange = useCallback(
|
const _onChange = useCallback(
|
||||||
|
Reference in New Issue
Block a user