4
4
# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
5
5
# SPDX-License-Identifier: Apache-2.0
6
6
7
+ import sys
7
8
from sasctl .core import is_uuid , get , post , get_link , _build_crud_funcs , current_session
8
9
9
10
@@ -52,6 +53,18 @@ def get_model_link(model, rel, refresh=False):
52
53
53
54
54
55
def get_astore (model ):
56
+ """Get the ASTORE for a model registered int he model repository.
57
+
58
+ Parameters
59
+ ----------
60
+ model : str or dict
61
+ The name or id of the model, or a dictionary representation of the model.
62
+
63
+ Returns
64
+ ----------
65
+ binary?
66
+
67
+ """
55
68
# TODO: Download binary object?
56
69
57
70
link = get_model_link (model , 'analyticStore' , refresh = True )
@@ -61,7 +74,7 @@ def get_astore(model):
61
74
62
75
63
76
def get_score_code (model ):
64
- """The score code for a model registered in the model repository.
77
+ """Get the score code for a model registered in the model repository.
65
78
66
79
Parameters
67
80
----------
@@ -83,7 +96,7 @@ def get_score_code(model):
83
96
84
97
85
98
def get_model_contents (model ):
86
- """The additional files and data associated with the model.
99
+ """Retrieve the additional files and data associated with the model.
87
100
88
101
Parameters
89
102
----------
@@ -106,47 +119,61 @@ def get_model_contents(model):
106
119
def create_model (model , project , description = None , modeler = None , function = None , algorithm = None , tool = None ,
107
120
is_champion = False ,
108
121
properties = {}, ** kwargs ):
109
- """
122
+ """Creates a model into a project or folder.
110
123
111
124
Parameters
112
125
----------
113
- model
114
- project
126
+ model : str or dict
127
+ The name or id of the model, or a dictionary representation of the model.
128
+ project : str or dict
129
+ The name or id of the model project, or a dictionary representation of the model project.
115
130
description : str, optional
131
+ The description of the model.
116
132
modeler : str, optional
117
133
Name of the user that created the model. Current user name will be used if unspecified.
134
+ function : str, optional
135
+ The function of the model, valid values include: analytical, classification, cluster, forecasting, prediction, Text analytics, transformation.
136
+ algorithm : str, optional
137
+ The name of the model algorithm.
138
+ tool : str, optional
139
+ The name of the model tool, can be 'Python 2' or 'Python 3'.
140
+ scoreCodeType : str, optional
141
+ The score code type for the model.
142
+ trainTable : str, optional
143
+ The train data table.
144
+ classificationEventProbabilityVariableName : str, optional
145
+ The name of the event probability variable.
146
+ classificationTargetEventValue : str, optional
147
+ The target event value.
148
+ champion : bool, optional
149
+ Indicates whether the project has champion model or not.
150
+ role : str, optional
151
+ The role of the model, valid values include: plain, champion, challenger.
152
+ location : str, optional,
153
+ The location of this model.
154
+ targetVariable : str, optional
155
+ The name of the target variable.
156
+ suggestedChampion : bool
157
+ Indicates the model was suggested as the champion at import time.
158
+ retrainable : bool
159
+ Indicates whether the model can be retrained or not.
160
+ immutable : bool
161
+ Indicates whether the model can be changed or not.
162
+ modelVersionName : str, optional
163
+ The display name for the model version.
164
+ properties : array_like, optional (custom properties)
165
+ Custom model properties that can be set: name, value, type
166
+
167
+ inputVariables : array_like, optional
168
+ Model input variables. By default, these are the same as the model project.
169
+ outputVariables : array_like, optional
170
+ Model output variables. By default, these are the same as the model project.
118
171
119
- function
120
- algorithm
121
- tool
122
- modeler
123
- scoreCodeType
124
- trainTable
125
- classificationEventProbabilityVariableName
126
- classificationTargetEventValue
127
- champion (T/F)
128
- role
129
- location
130
- targetVariable
131
- projectId, projectName, projectVersionId, projectVersionName???
132
- suggestedChampion (T/F)
133
- retrainable
134
- immutable
135
- modelVersionName
136
- properties (custom properties)
137
- name
138
- value
139
- type
140
- inputVariables
141
- -
142
- outputVariables
143
- -
144
-
145
- properties
146
- kwargs
147
172
148
173
Returns
149
174
-------
175
+ str
176
+ The model schema returned in JSON format.
150
177
151
178
"""
152
179
@@ -177,6 +204,27 @@ def create_model(model, project, description=None, modeler=None, function=None,
177
204
178
205
179
206
def add_model_content (model , file , name = None , role = None ):
207
+ """Add additional files to the model.
208
+
209
+ Parameters
210
+ ----------
211
+ model : str or dict
212
+ The name or id of the model, or a dictionary representation of the model.
213
+ file : str or bytes
214
+ A file related to the model, such as the model code.
215
+ name : str
216
+ Name of the file related to the model.
217
+ role : str
218
+ Role of the model file, such as 'Python pickle'.
219
+
220
+
221
+ Returns
222
+ -------
223
+ str
224
+ The model content schema.
225
+
226
+ """
227
+
180
228
if is_uuid (model ):
181
229
id = model
182
230
elif isinstance (model , dict ) and 'id' in model :
@@ -211,6 +259,22 @@ def default_repository():
211
259
212
260
213
261
def create_project (project , repository , ** kwargs ):
262
+ """Create a model project in the given model repository.
263
+
264
+ Parameters
265
+ ----------
266
+ project : str or dict
267
+ The name or id of the model project, or a dictionary representation of the project.
268
+ repository : str or dict
269
+ The name or id of the model repository, or a dictionary representation of the repository.
270
+
271
+ Returns
272
+ -------
273
+ RestObj
274
+
275
+ """
276
+
277
+
214
278
if isinstance (project , str ):
215
279
project = {'name' : project }
216
280
@@ -226,6 +290,25 @@ def create_project(project, repository, **kwargs):
226
290
def import_model_from_zip (name , project , file , description = None , version = 'latest' ):
227
291
# TODO: Allow import into folder if no project is given
228
292
# TODO: Create new version if model already exists
293
+ """Import a model and contents as a ZIP file into a model project.
294
+
295
+ Parameters
296
+ ----------
297
+ name : str or dict
298
+ The name of the model.
299
+ project : str or dict
300
+ The name or id of the model project, or a dictionary representation of the project.
301
+ description : str
302
+ The description of the model.
303
+ file : byte
304
+ The ZIP file containing the model and contents.
305
+
306
+ Returns
307
+ -------
308
+ ResponseObj
309
+ The API response after importing the model.
310
+
311
+ """
229
312
project = get_project (project )
230
313
231
314
if project is None :
@@ -244,5 +327,3 @@ def import_model_from_zip(name, project, file, description=None, version='latest
244
327
headers = {'Content-Type' : 'application/octet-stream' })
245
328
246
329
return r
247
-
248
-
0 commit comments