Exemple #1
0
    def _init_artifacts(self, artifacts):
        if len(self._artifacts_spec) > 0:
            if artifacts is None:
                if self._bento_archive_path:
                    artifacts = ArtifactCollection.load(
                        self._bento_archive_path,
                        self.__class__._artifacts_spec)
                else:
                    raise BentoMLException(
                        "Must provide required artifacts before instantiating a "
                        "custom BentoService class")

            if isinstance(artifacts, ArtifactCollection):
                self._artifacts = artifacts
            else:
                self._artifacts = ArtifactCollection()
                for artifact in artifacts:
                    self._artifacts[artifact.name] = artifact
        else:
            self._artifacts = ArtifactCollection()
Exemple #2
0
    def __init__(self):
        self._bento_service_version = self.__class__._bento_service_bundle_version
        self._packed_artifacts = ArtifactCollection()
        self.name = self.__class__.name()

        if self._bento_service_bundle_path:
            # load artifacts from saved BentoService bundle
            self._load_artifacts(self._bento_service_bundle_path)

        self._config_service_apis()
        self._init_env()
Exemple #3
0
    def pack(cls, *args, **kwargs):
        if args and isinstance(args[0], ArtifactCollection):
            return cls(args[0])

        artifacts = ArtifactCollection()

        for artifact_spec in cls._artifacts_spec:
            if artifact_spec.name in kwargs:
                artifact_instance = artifact_spec.pack(kwargs[artifact_spec.name])
                artifacts.add(artifact_instance)

        return cls(artifacts)
Exemple #4
0
    def __init__(self):
        from bentoml.artifact import ArtifactCollection

        self._bento_service_version = self.__class__._bento_service_bundle_version
        self._packed_artifacts = ArtifactCollection()

        if self._bento_service_bundle_path:
            # load artifacts from saved BentoService bundle
            self._load_artifacts(self._bento_service_bundle_path)

        self._config_inference_apis()
        self._config_environments()
Exemple #5
0
    def __init__(self, artifacts=None, env=None):
        if artifacts is None:
            if self._bento_archive_path:
                artifacts = ArtifactCollection.load(self._bento_archive_path,
                                                    self.__class__._artifacts_spec)
            else:
                raise BentoMLException("Must provide artifacts or set cls._bento_archive_path"
                                       "before instantiating a BentoService class")

        # TODO: validate artifacts arg matches self.__class__._artifacts_spec definition
        if isinstance(artifacts, ArtifactCollection):
            self._artifacts = artifacts
        else:
            self._artifacts = ArtifactCollection()
            for artifact in artifacts:
                self._artifacts[artifact.name] = artifact

        self._init_env(env)
        self._config_service_apis()
        self.name = self.__class__.name()
Exemple #6
0
    def __init__(self, artifacts, env=None):
        # TODO: validate artifacts arg matches self.__class__._artifacts_spec definition

        if isinstance(artifacts, ArtifactCollection):
            self._artifacts = artifacts
        else:
            self._artifacts = ArtifactCollection()
            for artifact in artifacts:
                self._artifacts[artifact.name] = artifact

        if env is None:
            # By default use BentoServiceEnv defined on class via @env decorator
            env = self.__class__._env

        if isinstance(env, dict):
            self._env = BentoServiceEnv.fromDict(env)
        else:
            self._env = env

        self._config_service_apis()
        self.name = self.__class__.name()