@@ -46,7 +46,7 @@ def create_score_definition(
46
46
description : str = "" ,
47
47
server_name : str = "cas-shared-default" ,
48
48
library_name : str = "Public" ,
49
- model_version : str = "latest" ,
49
+ model_version : Union [ str , dict ] = "latest" ,
50
50
):
51
51
"""Creates the score definition service.
52
52
@@ -69,7 +69,7 @@ def create_score_definition(
69
69
library_name: str, optional
70
70
The library within the CAS server the table exists in. Defaults to "Public".
71
71
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" .
73
73
74
74
Returns
75
75
-------
@@ -116,7 +116,7 @@ def create_score_definition(
116
116
table = cls ._cas_management .get_table (table_name , library_name , server_name )
117
117
if not table and not table_file :
118
118
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."
120
120
)
121
121
elif not table and table_file :
122
122
cls ._cas_management .upload_file (
@@ -129,29 +129,8 @@ def create_score_definition(
129
129
)
130
130
# Checks if the inputted table exists, and if not, uploads a file to create a new table
131
131
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
155
134
156
135
save_score_def = {
157
136
"name" : model_name , # used to be score_def_name
@@ -185,3 +164,38 @@ def create_score_definition(
185
164
"/definitions" , data = json .dumps (save_score_def ), headers = headers_score_def
186
165
)
187
166
# 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