Skip to content

Commit

Permalink
chore(sdk): able to specify service name (#4377)
Browse files Browse the repository at this point in the history
  • Loading branch information
bojiang authored Jan 3, 2024
1 parent 66f7a9a commit bb61f88
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/quickstart/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def preprocess(self, input_series: np.ndarray) -> np.ndarray:
return input_series


@bentoml.service(resources={"cpu": "200m", "memory": "512Mi"})
@bentoml.service(name="iris_classifier", resources={"cpu": "200m", "memory": "512Mi"})
class IrisClassifier:
iris_model = bentoml.models.get("iris_clf:latest")
preprocessing = bentoml.depends(Preprocessing)
Expand Down
2 changes: 1 addition & 1 deletion src/_bentoml_impl/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def __call__(self, is_main: bool = False) -> Starlette:

@property
def name(self) -> str:
return self.service.inner.__name__
return self.service.name

@property
def middlewares(self) -> list[Middleware]:
Expand Down
1 change: 1 addition & 0 deletions src/_bentoml_sdk/service/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class LoggingSchema(TypedDict, total=False):


class ServiceConfig(TypedDict, total=False):
name: str
traffic: TrafficSchema
backlog: Annotated[int, Ge(64)]
max_runner_connections: Posint
Expand Down
2 changes: 2 additions & 0 deletions src/_bentoml_sdk/service/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def schema(self) -> dict[str, t.Any]:

@property
def name(self) -> str:
if name := self.config.get("name"):
return name
return self.inner.__name__.lower()

@property
Expand Down
1 change: 1 addition & 0 deletions src/bentoml/_internal/configuration/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
},
}
_SERVICE_CONFIG = {
s.Optional("name", default=None): s.Or(str, None),
s.Optional("batching"): {
s.Optional("enabled"): bool,
s.Optional("max_batch_size"): s.And(int, ensure_larger_than_zero),
Expand Down

0 comments on commit bb61f88

Please sign in to comment.