44# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
55# SPDX-License-Identifier: Apache-2.0
66
7+ import sys
78from sasctl .core import is_uuid , get , post , get_link , _build_crud_funcs , current_session
89
910
@@ -52,6 +53,18 @@ def get_model_link(model, rel, refresh=False):
5253
5354
5455def 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+ """
5568 # TODO: Download binary object?
5669
5770 link = get_model_link (model , 'analyticStore' , refresh = True )
@@ -61,7 +74,7 @@ def get_astore(model):
6174
6275
6376def 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.
6578
6679 Parameters
6780 ----------
@@ -83,7 +96,7 @@ def get_score_code(model):
8396
8497
8598def 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.
87100
88101 Parameters
89102 ----------
@@ -106,47 +119,61 @@ def get_model_contents(model):
106119def create_model (model , project , description = None , modeler = None , function = None , algorithm = None , tool = None ,
107120 is_champion = False ,
108121 properties = {}, ** kwargs ):
109- """
122+ """Creates a model into a project or folder.
110123
111124 Parameters
112125 ----------
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.
115130 description : str, optional
131+ The description of the model.
116132 modeler : str, optional
117133 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.
118171
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
147172
148173 Returns
149174 -------
175+ str
176+ The model schema returned in JSON format.
150177
151178 """
152179
@@ -177,6 +204,27 @@ def create_model(model, project, description=None, modeler=None, function=None,
177204
178205
179206def 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+
180228 if is_uuid (model ):
181229 id = model
182230 elif isinstance (model , dict ) and 'id' in model :
@@ -211,6 +259,22 @@ def default_repository():
211259
212260
213261def 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+
214278 if isinstance (project , str ):
215279 project = {'name' : project }
216280
@@ -226,6 +290,25 @@ def create_project(project, repository, **kwargs):
226290def import_model_from_zip (name , project , file , description = None , version = 'latest' ):
227291 # TODO: Allow import into folder if no project is given
228292 # 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+ """
229312 project = get_project (project )
230313
231314 if project is None :
@@ -244,5 +327,3 @@ def import_model_from_zip(name, project, file, description=None, version='latest
244327 headers = {'Content-Type' : 'application/octet-stream' })
245328
246329 return r
247-
248-
0 commit comments