Exemplo n.º 1
0
    def class_impl(self, project_dir):
        """Can only raise UserException/CortexException exceptions"""
        if self.type in [
                TensorFlowPredictorType, TensorFlowNeuronPredictorType
        ]:
            target_class_name = "TensorFlowPredictor"
            validations = TENSORFLOW_CLASS_VALIDATION
        elif self.type == PythonPredictorType:
            target_class_name = "PythonPredictor"
            validations = PYTHON_CLASS_VALIDATION
        else:
            raise CortexException(f"invalid predictor type: {self.type}")

        try:
            predictor_class = self._get_class_impl(
                "cortex_predictor", os.path.join(project_dir, self.path),
                target_class_name)
        except Exception as e:
            e.wrap("error in " + self.path)
            raise

        try:
            validate_class_impl(predictor_class, validations)
            validate_predictor_with_grpc(predictor_class, self.api_spec)
            if self.type == PythonPredictorType:
                validate_python_predictor_with_models(predictor_class,
                                                      self.api_spec)
        except Exception as e:
            e.wrap("error in " + self.path)
            raise
        return predictor_class
Exemplo n.º 2
0
    def _get_impl(self, project_dir: str):
        if self.type in [
                TensorFlowPredictorType, TensorFlowNeuronPredictorType
        ]:
            target_class_name = "TensorFlowPredictor"
            validations = ASYNC_TENSORFLOW_PREDICTOR_VALIDATION
        elif self.type == PythonPredictorType:
            target_class_name = "PythonPredictor"
            validations = ASYNC_PYTHON_PREDICTOR_VALIDATION
        else:
            raise CortexException(f"invalid predictor type: {self.type}")

        try:
            impl = self._read_impl("cortex_async_predictor",
                                   os.path.join(project_dir, self.path),
                                   target_class_name)
        except CortexException as e:
            e.wrap("error in " + self.path)
            raise

        try:
            validate_class_impl(impl, validations)
        except CortexException as e:
            e.wrap("error in " + self.path)
            raise

        return impl
Exemplo n.º 3
0
 def _validate_impl(impl):
     if inspect.isclass(impl):
         validate_class_impl(impl, TASK_CLASS_VALIDATION)
     else:
         callable_fn = impl
         argspec = inspect.getfullargspec(callable_fn)
         if not (len(argspec.args) == 1 and argspec.args[0] == "config"):
             raise UserException(
                 f'callable function must have the "config" parameter in its signature',
             )
Exemplo n.º 4
0
 def _validate_impl(impl):
     validate_class_impl(impl, TASK_CLASS_VALIDATION)
Exemplo n.º 5
0
 def _validate_impl(impl):
     return validate_class_impl(impl, ASYNC_PYTHON_PREDICTOR_VALIDATION)