44
55from pathlib import Path
66import json
7- from typing import Union , Optional
7+ from typing import Dict , Union , Optional
88
99from ..core import current_session , delete , get , sasctl_command , RestObj
1010from .cas_management import CASManagement
@@ -41,12 +41,13 @@ def create_score_definition(
4141 score_def_name : str ,
4242 model : Union [str , dict ],
4343 table_name : str ,
44- use_cas_gateway : Optional [bool ] = False ,
44+ use_cas_gateway : Optional [bool ] = True ,
4545 table_file : Union [str , Path ] = None ,
4646 description : str = "" ,
4747 server_name : str = "cas-shared-default" ,
4848 library_name : str = "Public" ,
4949 model_version : Union [str , dict ] = "latest" ,
50+ input_mapping : Optional [Dict ] = None
5051 ):
5152 """Creates the score definition service.
5253
@@ -70,6 +71,8 @@ def create_score_definition(
7071 The library within the CAS server the table exists in. Defaults to "Public".
7172 model_version: str, optional
7273 The user-chosen version of the model. Deafaults to "latest".
74+ input_mapping: list, optional
75+ A list of dictionaries mapping variables from the data table to the variables in the model if they are different. Defaults to None.
7376
7477 Returns
7578 -------
@@ -101,11 +104,18 @@ def create_score_definition(
101104 try :
102105 inputMapping = []
103106 for input_item in model .get ("inputVariables" ):
104- var = {
105- "mappingValue" : input_item ["name" ],
106- "mappingType" : "datasource" ,
107- "variableName" : input_item ["name" ],
108- }
107+ if input_mapping and input_item ["name" ] in input_mapping :
108+ var = {
109+ "mappingValue" : input_mapping [input_item ["name" ]],
110+ "mappingType" : "datasource" ,
111+ "variableName" : input_item ["name" ],
112+ }
113+ else :
114+ var = {
115+ "mappingValue" : input_item ["name" ],
116+ "mappingType" : "datasource" ,
117+ "variableName" : input_item ["name" ],
118+ }
109119 inputMapping .append (var )
110120
111121 except :
@@ -133,7 +143,7 @@ def create_score_definition(
133143 # Checks if the model version is valid and how to find the name
134144
135145 save_score_def = {
136- "name" : model_name , # used to be score_def_name
146+ "name" : score_def_name , # used to be score_def_name
137147 "description" : description ,
138148 "objectDescriptor" : {
139149 "uri" : object_uri ,
0 commit comments