diff --git a/examples/quickstart/service.py b/examples/quickstart/service.py index 27e64cdf6e4..fb55253c715 100644 --- a/examples/quickstart/service.py +++ b/examples/quickstart/service.py @@ -5,14 +5,14 @@ from bentoml.validators import Shape -@bentoml.service(resources={"cpu": "200m", "memory": "512Mi"}) +@bentoml.service(name="preprocessing", resources={"cpu": "200m", "memory": "512Mi"}) class Preprocessing: @bentoml.api def preprocess(self, input_series: np.ndarray) -> np.ndarray: return input_series -@bentoml.service(name="iris_classifier", resources={"cpu": "200m", "memory": "512Mi"}) +@bentoml.service(resources={"cpu": "200m", "memory": "512Mi"}) class IrisClassifier: iris_model = bentoml.models.get("iris_sklearn:latest") preprocessing = bentoml.depends(Preprocessing) diff --git a/src/_bentoml_sdk/service/factory.py b/src/_bentoml_sdk/service/factory.py index 40cd3cd5383..14a4747cfe2 100644 --- a/src/_bentoml_sdk/service/factory.py +++ b/src/_bentoml_sdk/service/factory.py @@ -19,7 +19,6 @@ from bentoml._internal.configuration.containers import BentoMLContainer from bentoml._internal.context import ServiceContext from bentoml._internal.models import Model -from bentoml._internal.tag import validate_tag_str from bentoml._internal.utils import dict_filter_none from bentoml.exceptions import BentoMLException @@ -159,8 +158,7 @@ def schema(self) -> dict[str, t.Any]: @property def name(self) -> str: - name = self.config.get("name") or self.inner.__name__.lower() - validate_tag_str(name) + name = self.config.get("name") or self.inner.__name__ return name @property diff --git a/src/bentoml/_internal/bento/bento.py b/src/bentoml/_internal/bento/bento.py index feff4277f16..8194ed6aefd 100644 --- a/src/bentoml/_internal/bento/bento.py +++ b/src/bentoml/_internal/bento/bento.py @@ -33,6 +33,7 @@ from ..store import Store from ..store import StoreItem from ..tag import Tag +from ..tag import to_snake_case from ..types import PathType from ..utils import bentoml_cattr from ..utils import copy_file_to_fs_folder @@ -204,7 +205,18 @@ def create( # Apply default build options build_config = build_config.with_defaults() - bento_name = build_config.name if build_config.name is not None else svc.name + if isinstance(svc, Service): + # for < 1.2 + bento_name = ( + build_config.name if build_config.name is not None else svc.name + ) + else: + # for >= 1.2 + bento_name = ( + build_config.name + if build_config.name is not None + else to_snake_case(svc.name) + ) tag = Tag(bento_name, version) if version is None: tag = tag.make_new_version() @@ -293,6 +305,7 @@ def create( BentoInfo( tag=tag, service=svc, # type: ignore # attrs converters do not typecheck + entry_service=svc.name, labels=build_config.labels, models=[ BentoModelInfo.from_bento_model( @@ -581,7 +594,9 @@ class BentoInfo: models: t.List[BentoModelInfo] = attr.field(factory=list) runners: t.List[BentoRunnerInfo] = attr.field(factory=list) # for BentoML 1.2+ SDK + entry_service: str = attr.field(factory=str) services: t.List[BentoServiceInfo] = attr.field(factory=list) + apis: t.List[BentoApiInfo] = attr.field(factory=list) docker: DockerOptions = attr.field(factory=lambda: DockerOptions().with_defaults()) python: PythonOptions = attr.field(factory=lambda: PythonOptions().with_defaults()) diff --git a/src/bentoml/_internal/cloud/bentocloud.py b/src/bentoml/_internal/cloud/bentocloud.py index a4ea4fe8159..04472d98a34 100644 --- a/src/bentoml/_internal/cloud/bentocloud.py +++ b/src/bentoml/_internal/cloud/bentocloud.py @@ -159,6 +159,7 @@ def push_model(model: Model) -> None: ] manifest = BentoManifestSchema( name=info.name, + entry_service=info.entry_service, service=info.service, bentoml_version=info.bentoml_version, apis=apis, diff --git a/src/bentoml/_internal/cloud/schemas/modelschemas.py b/src/bentoml/_internal/cloud/schemas/modelschemas.py index 3a3e9852436..79d28d7c15f 100644 --- a/src/bentoml/_internal/cloud/schemas/modelschemas.py +++ b/src/bentoml/_internal/cloud/schemas/modelschemas.py @@ -74,6 +74,7 @@ class BentoRunnerSchema: @attr.define class BentoManifestSchema: service: str + entry_service: str bentoml_version: str size_bytes: int name: t.Optional[str] = attr.field(default=None) diff --git a/src/bentoml/_internal/cloud/yatai.py b/src/bentoml/_internal/cloud/yatai.py index 05f0b75df5e..efd47ed233f 100644 --- a/src/bentoml/_internal/cloud/yatai.py +++ b/src/bentoml/_internal/cloud/yatai.py @@ -153,6 +153,7 @@ def push_model(model: Model) -> None: ] manifest = BentoManifestSchema( name=info.name, + entry_service=info.entry_service, service=info.service, bentoml_version=info.bentoml_version, apis=apis, diff --git a/src/bentoml/_internal/tag.py b/src/bentoml/_internal/tag.py index 4494eafa2a9..5188a1e81bc 100644 --- a/src/bentoml/_internal/tag.py +++ b/src/bentoml/_internal/tag.py @@ -21,6 +21,11 @@ tag_regex = re.compile(f"^{tag_fmt}$") +def to_snake_case(name: str) -> str: + snake_case = re.sub(r"(?