[docs]defload_config(config:Union[ConfigT,FilePath,str,dict],config_type:Type[ConfigT])->ConfigT:"""Generic config loader, either accepting a path to a json file, a json string, a dict or passing through a valid config object."""ifisinstance(config,(str,Path)):# if we have a str / path, we need to check whether it is a file or a json stringifPath(config).is_file():# if we have a valid file pointer, we load itwithopen(config,"r")asf:config=json.load(f)else:# since the str is not a file path, we assume it is json and try to load ittry:config=json.loads(config)exceptjson.JSONDecodeErrorase:# if we failed, we raise an error notifying the user of possibilitiesraiseConfigurationError(f"The config '{config:.100}' is neither an existing file path, nor a "f"valid json document.")fromereturnconfig_type.model_validate(config)