in src/sagemaker_huggingface_inference_toolkit/handler_service.py [0:0]
def function_extra_arg(self, default_func, func):
"""Helper to call the handler function which covers 2 cases:
1. the handle function takes context
2. the handle function does not take context
"""
default_params = signature(default_func).parameters
func_params = signature(func).parameters
if "self" in default_params:
num_default_func_input = len(default_params) - 1
else:
num_default_func_input = len(default_params)
num_func_input = len(func_params)
if num_default_func_input == num_func_input:
# function takes context
extra_args = [self.context]
elif num_default_func_input == num_func_input + 1:
# function does not take context
extra_args = []
else:
raise TypeError(
"{} definition takes {} or {} arguments but {} were given.".format(
func.__name__, num_default_func_input - 1, num_default_func_input, num_func_input
)
)
return extra_args