Skip to content

Commit 76e4487

Browse files
docs(mm): update docsstrings in factory.py
1 parent cffffd0 commit 76e4487

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

invokeai/backend/model_manager/configs/factory.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@
210210
]
211211

212212
AnyModelConfigValidator = TypeAdapter[AnyModelConfig](AnyModelConfig)
213+
"""Pydantic TypeAdapter for the AnyModelConfig union, used for parsing and validation.
214+
215+
If you need to parse/validate a dict or JSON into an AnyModelConfig, you should probably use
216+
ModelConfigFactory.from_dict or ModelConfigFactory.from_json instead as they may implement
217+
additional logic in the future.
218+
"""
213219

214220

215221
class ModelConfigFactory:
@@ -219,6 +225,12 @@ def from_dict(fields: dict[str, Any]) -> AnyModelConfig:
219225
model = AnyModelConfigValidator.validate_python(fields)
220226
return model
221227

228+
@staticmethod
229+
def from_json(json: str | bytes | bytearray) -> AnyModelConfig:
230+
"""Return the appropriate config object from json."""
231+
model = AnyModelConfigValidator.validate_json(json)
232+
return model
233+
222234
@staticmethod
223235
def build_common_fields(
224236
mod: ModelOnDisk,
@@ -320,8 +332,9 @@ def from_model_on_disk(
320332
# - SD main models can look like a LoRA when they have merged in LoRA weights. Prefer the main model.
321333
# - SD main models in diffusers format can look like a CLIP Embed; they have a text_encoder folder with
322334
# a config.json file. Prefer the main model.
323-
324-
# Sort the matching according to known special cases.
335+
#
336+
# Given the above cases, we can prioritize the matches by type. If we find more cases, we may need a more
337+
# sophisticated approach.
325338
def sort_key(m: AnyModelConfig) -> int:
326339
match m.type:
327340
case ModelType.Main:

0 commit comments

Comments
 (0)