Dsnnaveen Kumar
07/22/2024, 8:46 AMsvc = bentoml.Service("iris_classifier", runners=[iris_clf_runner])
@svc.api(
input=NumpyNdarray.from_sample(np.array([4.9, 3.0, 1.4, 0.2], dtype=np.double)),
output=Text(),
)
async def classify(features: np.ndarray) -> str:
with bentoml.monitor("iris_classifier_prediction") as mon:
mon.log(features[0], name="sepal length", role="feature", data_type="numerical")
mon.log(features[1], name="sepal width", role="feature", data_type="numerical")
mon.log(features[2], name="petal length", role="feature", data_type="numerical")
mon.log(features[3], name="petal width", role="feature", data_type="numerical")
results = await iris_clf_runner.predict.async_run([features])
result = results[0]
category = CLASS_NAMES[result]
mon.log(category, name="pred", role="prediction", data_type="categorical")
return category
in this service we are using "classify" function to monitor the function
how can i write multple api's here like in below
@bentoml.service(
resources={"cpu": "2"},
traffic={"timeout": 10},
)
class IrisClassifier:
bento_model = bentoml.models.get("iris:latest")
def __init__(self):
self.model = bentoml.mlflow.load_model(self.bento_model)
@bentoml.api
def predict(self, input_data: np.ndarray) -> np.ndarray:
rv = self.model.predict(input_data)
return np.asarray(rv)
@bentoml.api
def classify(self, input_data: np.ndarray) -> np.ndarray:
rv = self.model.predict(input_data)
return np.asarray(rv)