|
| 1 | +#!/usr/bin/env python |
| 2 | +# encoding: utf-8 |
| 3 | +# |
| 4 | +# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. |
| 5 | +# SPDX-License-Identifier: Apache-2.0 |
| 6 | + |
| 7 | +import pickle |
| 8 | +from datetime import datetime |
| 9 | + |
| 10 | +from sasctl import register_model, Session |
| 11 | + |
| 12 | + |
| 13 | +s = Session('hostname', 'username', 'password') |
| 14 | + |
| 15 | +# The register_model task will attempt to extract the necessary metadata from the provided ASTORE file or Python model. |
| 16 | +# However, if this doesn't work for your model or you need to specify different metadata, you can provide it as a |
| 17 | +# dictionary instead. For a full list of parameters that can be specified see the documentation here: |
| 18 | +# https://developer.sas.com/apis/rest/DecisionManagement/#schemamodel |
| 19 | +model_info = { |
| 20 | + 'name': 'Custom Model', |
| 21 | + 'description': 'This model is for demonstration purposes only.', |
| 22 | + 'scoreCodeType': 'Python', |
| 23 | + 'algorithm': 'Other' |
| 24 | +} |
| 25 | + |
| 26 | +# To include the contents of the model itself, simply provide the information for each file in a list. |
| 27 | +files = [ |
| 28 | + |
| 29 | + # Files can be added to the model by specifying a name of the file and its contents |
| 30 | + dict(name='greetings.txt', file='Hello World!'), |
| 31 | + |
| 32 | + # You can also specify file-like object to be included. Here we upload this Python file itself to the model. |
| 33 | + # In addition, the optional `role` parameter can be used to assign a File Role to the file in Model Manager. |
| 34 | + dict(name=__file__, file=open(__file__), role='Score code'), |
| 35 | + |
| 36 | + # The files also need not be simple text. Here we create a simple Python datetime object, pickle it, and then |
| 37 | + # include the binary file with the model. |
| 38 | + dict(name='datetime.pkl', file=pickle.dumps(datetime.now())) |
| 39 | +] |
| 40 | + |
| 41 | +model = register_model(model_info, name=model_info['name'], project='Examples', files=files, force=True) |
0 commit comments