@@ -28,7 +28,13 @@ class ModelManagement(Service):
2828 # TODO: set ds2MultiType
2929 @classmethod
3030 def publish_model (
31- cls , model , destination , name = None , force = False , reload_model_table = False
31+ cls ,
32+ model ,
33+ destination ,
34+ model_version = "latest" ,
35+ name = None ,
36+ force = False ,
37+ reload_model_table = False ,
3238 ):
3339 """
3440
@@ -38,6 +44,8 @@ def publish_model(
3844 The name or id of the model, or a dictionary representation of the model.
3945 destination : str
4046 Name of destination to publish the model to.
47+ model_version_id : str or dict, optional
48+ Provide the id, name, or dictionary representation of the version to publish. Defaults to 'latest'.
4149 name : str, optional
4250 Provide a custom name for the published model. Defaults to None.
4351 force : bool, optional
@@ -68,6 +76,18 @@ def publish_model(
6876
6977 # TODO: Verify allowed formats by destination type.
7078 # As of 19w04 MAS throws HTTP 500 if name is in invalid format.
79+ if model_version != "latest" :
80+ if isinstance (model_version , dict ) and "modelVersionName" in model_version :
81+ model_version_name = model_version ["modelVersionName" ]
82+ elif isinstance (model_version , str ) and cls .is_uuid (model_version ):
83+ model_version_name = mr .get_model_or_version (model , model_version )[
84+ "modelVersionName"
85+ ]
86+ else :
87+ model_version_name = model_version
88+ else :
89+ model_version_name = ""
90+
7191 model_name = name or "{}_{}" .format (
7292 model_obj ["name" ].replace (" " , "" ), model_obj ["id" ]
7393 ).replace ("-" , "" )
@@ -79,6 +99,7 @@ def publish_model(
7999 {
80100 "modelName" : mp ._publish_name (model_name ),
81101 "sourceUri" : model_uri .get ("uri" ),
102+ "modelVersionID" : model_version_name ,
82103 "publishLevel" : "model" ,
83104 }
84105 ],
@@ -104,6 +125,7 @@ def create_performance_definition(
104125 table_prefix ,
105126 project = None ,
106127 models = None ,
128+ modelVersions = None ,
107129 library_name = "Public" ,
108130 name = None ,
109131 description = None ,
@@ -136,6 +158,9 @@ def create_performance_definition(
136158 The name or id of the model(s), or a dictionary representation of the model(s). For
137159 multiple models, input a list of model names, or a list of dictionaries. If no models are specified, all
138160 models in the project specified will be used. Defaults to None.
161+ modelVersions: str, list, optional
162+ The name of the model version(s) for models used in the performance definition. If no model versions
163+ are specified, all models will use the latest version. Defaults to None.
139164 library_name : str
140165 The library containing the input data, default is 'Public'.
141166 name : str, optional
@@ -239,10 +264,37 @@ def create_performance_definition(
239264 "property set." % project .name
240265 )
241266
267+ if not modelVersions :
268+ updated_models = [model .id for model in models ]
269+ else :
270+ updated_models = []
271+ if not isinstance (modelVersions , list ):
272+ modelVersions = [modelVersions ]
273+
274+ if len (models ) < len (modelVersions ):
275+ raise ValueError (
276+ "There are too many versions for the amount of models specified."
277+ )
278+
279+ modelVersions = modelVersions + ["" ] * (len (models ) - len (modelVersions ))
280+ for model , modelVersionName in zip (models , modelVersions ):
281+ print (model .name )
282+ if (
283+ isinstance (modelVersionName , dict )
284+ and "modelVersionName" in modelVersionName
285+ ):
286+ modelVersionName = modelVersionName ["modelVersionName" ]
287+ elif (
288+ isinstance (modelVersionName , dict )
289+ and "modelVersionName" not in modelVersionName
290+ ):
291+ raise ValueError ("Model version is not recognized." )
292+ updated_models .append (model .id + ":" + modelVersionName )
293+
242294 request = {
243295 "projectId" : project .id ,
244296 "name" : name or project .name + " Performance" ,
245- "modelIds" : [model . id for model in models ],
297+ "modelIds" : [model for model in updated_models ],
246298 "championMonitored" : monitor_champion ,
247299 "challengerMonitored" : monitor_challenger ,
248300 "maxBins" : max_bins ,
0 commit comments