From 407926b8dc78daf5ae86d6292cf8e5e2f06c322f Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 7 Oct 2025 15:02:18 +1100 Subject: [PATCH] docs(mm): update docsstrings in factory.py --- .../backend/model_manager/configs/factory.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/invokeai/backend/model_manager/configs/factory.py b/invokeai/backend/model_manager/configs/factory.py index 6ab16cd5f6..39f588f232 100644 --- a/invokeai/backend/model_manager/configs/factory.py +++ b/invokeai/backend/model_manager/configs/factory.py @@ -210,6 +210,12 @@ AnyModelConfig = Annotated[ ] AnyModelConfigValidator = TypeAdapter[AnyModelConfig](AnyModelConfig) +"""Pydantic TypeAdapter for the AnyModelConfig union, used for parsing and validation. + +If you need to parse/validate a dict or JSON into an AnyModelConfig, you should probably use +ModelConfigFactory.from_dict or ModelConfigFactory.from_json instead as they may implement +additional logic in the future. +""" class ModelConfigFactory: @@ -219,6 +225,12 @@ class ModelConfigFactory: model = AnyModelConfigValidator.validate_python(fields) return model + @staticmethod + def from_json(json: str | bytes | bytearray) -> AnyModelConfig: + """Return the appropriate config object from json.""" + model = AnyModelConfigValidator.validate_json(json) + return model + @staticmethod def build_common_fields( mod: ModelOnDisk, @@ -320,8 +332,9 @@ class ModelConfigFactory: # - SD main models can look like a LoRA when they have merged in LoRA weights. Prefer the main model. # - SD main models in diffusers format can look like a CLIP Embed; they have a text_encoder folder with # a config.json file. Prefer the main model. - - # Sort the matching according to known special cases. + # + # Given the above cases, we can prioritize the matches by type. If we find more cases, we may need a more + # sophisticated approach. def sort_key(m: AnyModelConfig) -> int: match m.type: case ModelType.Main: