Skip to content

Commit

Permalink
fix up types file
Browse files Browse the repository at this point in the history
  • Loading branch information
Mary Hipp authored and Mary Hipp committed Nov 4, 2024
1 parent ebbde85 commit fb79880
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions invokeai/frontend/web/src/services/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,37 @@ export type AnyModelConfig =
| MainModelConfig
| CLIPVisionDiffusersConfig;

const check_submodel = (submodels: AnyModelConfig['submodels'], check_str: string): boolean => {
/**
* Checks if a list of submodels contains any that match a given variant or type
* @param submodels The list of submodels to check
* @param checkStr The string to check against for variant or type
* @returns A boolean
*/
const checkSubmodel = (submodels: AnyModelConfig['submodels'], checkStr: string): boolean => {
for (const submodel in submodels) {
if (
submodel &&
submodels[submodel] &&
(submodels[submodel].model_type === check_str || submodels[submodel].variant === check_str)
(submodels[submodel].model_type === checkStr || submodels[submodel].variant === checkStr)
) {
return true;
}
}
return false;
};

const check_submodels = (indentifiers: string[], config: AnyModelConfig): boolean => {
return indentifiers.every(
(indentifier) =>
/**
* Checks if a main model config has submodels that match a given variant or type
* @param identifiers A list of strings to check against for variant or type in submodels
* @param config The model config
* @returns A boolean
*/
const checkSubmodels = (identifiers: string[], config: AnyModelConfig): boolean => {
return identifiers.every(
(identifier) =>
config.type === 'main' &&
config.submodels &&
(indentifier in config.submodels || check_submodel(config.submodels, indentifier))
(identifier in config.submodels || checkSubmodel(config.submodels, identifier))
);
};

Expand All @@ -104,22 +116,22 @@ export const isLoRAModelConfig = (config: AnyModelConfig): config is LoRAModelCo
};

export const isVAEModelConfig = (config: AnyModelConfig, excludeSubmodels?: boolean): config is VAEModelConfig => {
return config.type === 'vae' || (!excludeSubmodels && config.type === 'main' && check_submodels(['vae'], config));
return config.type === 'vae' || (!excludeSubmodels && config.type === 'main' && checkSubmodels(['vae'], config));
};

export const isNonFluxVAEModelConfig = (
config: AnyModelConfig,
excludeSubmodels?: boolean
): config is VAEModelConfig => {
return (
(config.type === 'vae' || (!excludeSubmodels && config.type === 'main' && check_submodels(['vae'], config))) &&
(config.type === 'vae' || (!excludeSubmodels && config.type === 'main' && checkSubmodels(['vae'], config))) &&
config.base !== 'flux'
);
};

export const isFluxVAEModelConfig = (config: AnyModelConfig, excludeSubmodels?: boolean): config is VAEModelConfig => {
return (
(config.type === 'vae' || (!excludeSubmodels && config.type === 'main' && check_submodels(['vae'], config))) &&
(config.type === 'vae' || (!excludeSubmodels && config.type === 'main' && checkSubmodels(['vae'], config))) &&
config.base === 'flux'
);
};
Expand All @@ -146,7 +158,7 @@ export const isT5EncoderModelConfig = (
): config is T5EncoderModelConfig | T5EncoderBnbQuantizedLlmInt8bModelConfig => {
return (
config.type === 't5_encoder' ||
(!excludeSubmodels && config.type === 'main' && check_submodels(['t5_encoder'], config))
(!excludeSubmodels && config.type === 'main' && checkSubmodels(['t5_encoder'], config))
);
};

Expand All @@ -156,7 +168,7 @@ export const isCLIPEmbedModelConfig = (
): config is CLIPEmbedModelConfig => {
return (
config.type === 'clip_embed' ||
(!excludeSubmodels && config.type === 'main' && check_submodels(['clip_embed'], config))
(!excludeSubmodels && config.type === 'main' && checkSubmodels(['clip_embed'], config))
);
};

Expand All @@ -166,7 +178,7 @@ export const isCLIPLEmbedModelConfig = (
): config is CLIPLEmbedModelConfig => {
return (
(config.type === 'clip_embed' && config.variant === 'large') ||
(!excludeSubmodels && config.type === 'main' && check_submodels(['clip_embed', 'large'], config))
(!excludeSubmodels && config.type === 'main' && checkSubmodels(['clip_embed', 'large'], config))
);
};

Expand All @@ -176,7 +188,7 @@ export const isCLIPGEmbedModelConfig = (
): config is CLIPGEmbedModelConfig => {
return (
(config.type === 'clip_embed' && config.variant === 'gigantic') ||
(!excludeSubmodels && config.type === 'main' && check_submodels(['clip_embed', 'gigantic'], config))
(!excludeSubmodels && config.type === 'main' && checkSubmodels(['clip_embed', 'gigantic'], config))
);
};

Expand Down

0 comments on commit fb79880

Please sign in to comment.