99
1010from adk .io import create_exception , format_data , format_response
1111from adk .modeldata import ModelData
12+ from adk .mlops import MLOps
1213
1314
1415class ADK (object ):
@@ -21,6 +22,7 @@ def __init__(self, apply_func, load_func=None, client=None):
2122 :param client: A Algorithmia Client instance that might be user defined,
2223 and is used for interacting with a model manifest file; if defined.
2324 """
25+ self .mlops = None
2426 self .FIFO_PATH = "/tmp/algoout"
2527
2628 if client :
@@ -43,10 +45,8 @@ def __init__(self, apply_func, load_func=None, client=None):
4345 self .load_result = None
4446 self .loading_exception = None
4547 self .manifest_path = "model_manifest.json"
46- self .model_data = self .init_manifest (self .manifest_path )
47-
48- def init_manifest (self , path ):
49- return ModelData (self .client , path )
48+ self .mlops_path = "mlops.json"
49+ self .model_data = ModelData (self .client , self .manifest_path )
5050
5151 def load (self ):
5252 try :
@@ -95,25 +95,18 @@ def write_to_pipe(self, payload, pprint=print):
9595 def process_local (self , local_payload , pprint ):
9696 result = self .apply (local_payload )
9797 self .write_to_pipe (result , pprint = pprint )
98-
99- def mlops_initialize (self ):
100- os .environ ["MLOPS_SPOOLER_TYPE" ] = "FILESYSTEM"
101- os .environ ["MLOPS_FILESYSTEM_DIRECTORY" ] = self .mlops_spool_dir
102- with open (f'{ agents_dir } /conf/mlops.agent.conf.yaml' ) as f :
103- documents = yaml .load (f , Loader = yaml .FullLoader )
104- documents ['mlopsUrl' ] = DATAROBOT_ENDPOINT
105- documents ['apiToken' ] = DATAROBOT_API_TOKEN
106- with open (f'{ agents_dir } /conf/mlops.agent.conf.yaml' , 'w' ) as f :
107- yaml .dump (documents , f )
108- subprocess .call (f'{ agents_dir } /bin/start-agent.sh' )
109- check = subprocess .Popen ([f'{ agents_dir } /bin/status-agent.sh' ], stdout = subprocess .PIPE )
110- check .terminate ()
111-
112-
98+
99+ def mlops_init (self ):
100+ mlops_token = os .environ .get ("DATAROBOT_MLOPS_API_TOKEN" , None )
101+ if mlops_token :
102+ self .mlops = MLOps (mlops_token , self .mlops_path )
103+ self .mlops .init ()
104+ else :
105+ raise Exception ("'DATAROBOT_MLOPS_API_TOKEN' was not found, please set to use mlops." )
113106
114107 def init (self , local_payload = None , pprint = print , mlops = False ):
115108 if mlops and not self .is_local :
116- self .mlops_initialize ()
109+ self .mlops_init ()
117110 self .load ()
118111 if self .is_local and local_payload is not None :
119112 if self .loading_exception :
0 commit comments