@@ -11,15 +11,19 @@ def __init__(self, apply_func, load_func=None, client=None, manifest_path="model
11
11
"""
12
12
Creates the adk object
13
13
:param apply_func: A required function that can have an arity of 1-2, depending on if loading occurs
14
- :param load_func: An optional supplier function used if load time events are required, has an arity of 0.
15
- :param client: A Algorithmia Client instance that might be user defined, and is used for interacting with a model manifest file; if defined.
14
+ :param load_func: An optional supplier function used if load time events are required, if a model manifest is provided;
15
+ the function may have a single `manifest` parameter to interact with the model manifest, otherwise must have no parameters.
16
+ :param client: A Algorithmia Client instance that might be user defined,
17
+ and is used for interacting with a model manifest file; if defined.
16
18
:param manifest_path: A development / testing facing variable used to set the name and path
17
19
"""
18
20
self .FIFO_PATH = "/tmp/algoout"
19
21
apply_args , _ , _ , _ , _ , _ , _ = inspect .getfullargspec (apply_func )
22
+ self .apply_arity = len (apply_args )
20
23
if load_func :
21
24
load_args , _ , _ , _ , _ , _ , _ = inspect .getfullargspec (load_func )
22
- if len (load_args ) > 2 :
25
+ self .load_arity = len (load_args )
26
+ if self .load_arity > 2 :
23
27
raise Exception ("load function may either have no parameters, or one parameter providing the manifest "
24
28
"state." )
25
29
self .load_func = load_func
@@ -35,9 +39,10 @@ def __init__(self, apply_func, load_func=None, client=None, manifest_path="model
35
39
36
40
def load (self ):
37
41
try :
38
- if self .load_func and self . manifest .available ():
42
+ if self .manifest .available ():
39
43
self .manifest .initialize ()
40
- self .load_result = self .load_func (self .manifest )
44
+ if self .load_func and self .load_arity == 1 :
45
+ self .load_result = self .load_func (self .manifest )
41
46
elif self .load_func :
42
47
self .load_result = self .load_func ()
43
48
except Exception as e :
@@ -51,7 +56,7 @@ def load(self):
51
56
52
57
def apply (self , payload ):
53
58
try :
54
- if self .load_result :
59
+ if self .load_result and self . apply_arity == 2 :
55
60
apply_result = self .apply_func (payload , self .load_result )
56
61
else :
57
62
apply_result = self .apply_func (payload )
0 commit comments