@@ -46,7 +46,7 @@ def create_score_definition(
4646 description : str = "" ,
4747 server_name : str = "cas-shared-default" ,
4848 library_name : str = "Public" ,
49- model_version : str = "latest" ,
49+ model_version : Union [ str , dict ] = "latest" ,
5050 ):
5151 """Creates the score definition service.
5252
@@ -69,7 +69,7 @@ def create_score_definition(
6969 library_name: str, optional
7070 The library within the CAS server the table exists in. Defaults to "Public".
7171 model_version: str, optional
72- The user-chosen version of the model with the specified model version name. Defaults to latest version .
72+ The user-chosen version of the model. Deafaults to " latest" .
7373
7474 Returns
7575 -------
@@ -116,7 +116,7 @@ def create_score_definition(
116116 table = cls ._cas_management .get_table (table_name , library_name , server_name )
117117 if not table and not table_file :
118118 raise HTTPError (
119- "This table may not exist in CAS. Please include the `table_file` argument in the function call if it doesn't exist ."
119+ "This table may not exist in CAS. Please include the `table_file` argument."
120120 )
121121 elif not table and table_file :
122122 cls ._cas_management .upload_file (
@@ -129,29 +129,8 @@ def create_score_definition(
129129 )
130130 # Checks if the inputted table exists, and if not, uploads a file to create a new table
131131
132- if model_version != "latest" :
133-
134- if isinstance (model_version , dict ) and "modelVersionName" in model_version :
135- model_version = model_version ["modelVersionName" ]
136- elif (
137- isinstance (model_version , dict )
138- and "modelVersionName" not in model_version
139- ):
140- raise ValueError (
141- "Model version cannot be found. Please check the inputted model version."
142- )
143- elif isinstance (model_version , str ) and cls .is_uuid (model_version ):
144- print ("hello" )
145- model_version = cls ._model_repository .get_model_or_version (
146- model_id , model_version
147- )["modelVersionName" ]
148- else :
149- model_version = model_version
150-
151- object_uri = f"/modelManagement/models/{ model_id } /versions/@{ model_version } "
152-
153- else :
154- object_uri = f"/modelManagement/models/{ model_id } "
132+ object_uri , model_version = cls .check_model_version (model_id , model_version )
133+ # Checks if the model version is valid and how to find the name
155134
156135 save_score_def = {
157136 "name" : model_name , # used to be score_def_name
@@ -185,3 +164,38 @@ def create_score_definition(
185164 "/definitions" , data = json .dumps (save_score_def ), headers = headers_score_def
186165 )
187166 # The response information of the score definition can be seen as a JSON as well as a RestOBJ
167+
168+ @classmethod
169+ def check_model_version (cls , model_id : str , model_version : Union [str , dict ]):
170+ """Checks if the model version is valid.
171+
172+ Parameters
173+ ----------
174+ model_version : str or dict
175+ The model version to check.
176+
177+ Returns
178+ -------
179+ String tuple
180+ """
181+ if model_version != "latest" :
182+
183+ if isinstance (model_version , dict ) and "modelVersionName" in model_version :
184+ model_version = model_version ["modelVersionName" ]
185+ elif (
186+ isinstance (model_version , dict )
187+ and "modelVersionName" not in model_version
188+ ):
189+ raise ValueError ("Model version cannot be found." )
190+ elif isinstance (model_version , str ) and cls .is_uuid (model_version ):
191+ print ("hello" )
192+ model_version = cls ._model_repository .get_model_or_version (
193+ model_id , model_version
194+ )["modelVersionName" ]
195+
196+ object_uri = f"/modelManagement/models/{ model_id } /versions/@{ model_version } "
197+
198+ else :
199+ object_uri = f"/modelManagement/models/{ model_id } "
200+
201+ return object_uri , model_version
0 commit comments