File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
invokeai/backend/model_manager/configs Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 210
210
]
211
211
212
212
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
+ """
213
219
214
220
215
221
class ModelConfigFactory :
@@ -219,6 +225,12 @@ def from_dict(fields: dict[str, Any]) -> AnyModelConfig:
219
225
model = AnyModelConfigValidator .validate_python (fields )
220
226
return model
221
227
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
+
222
234
@staticmethod
223
235
def build_common_fields (
224
236
mod : ModelOnDisk ,
@@ -320,8 +332,9 @@ def from_model_on_disk(
320
332
# - SD main models can look like a LoRA when they have merged in LoRA weights. Prefer the main model.
321
333
# - SD main models in diffusers format can look like a CLIP Embed; they have a text_encoder folder with
322
334
# 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.
325
338
def sort_key (m : AnyModelConfig ) -> int :
326
339
match m .type :
327
340
case ModelType .Main :
You can’t perform that action at this time.
0 commit comments