Rajiv Abraham
05/16/2025, 1:06 AM@bentoml.service
class Summarization:
def __init__(self, context) -> None:
self.context = context # <=====================
self.model = ... model ...
pass
@bentoml.api
def summarize(self, text: str = EXAMPLE_INPUT) -> str:
logger = self.context.logger() # <===== logger is just an example. It could be a logger which is different depending on local, prod
logger.info("In Summarize")
return self.model.predict()
The idea is construct common object like monitoring, logging, feature stores through this context object and to pass it to the Summarization ServiceFrost Ming
05/16/2025, 2:14 AMSummarization.context, (Note, self.__class__.context doesn’t work, since they are different object. Summarization != self.__class__ or type(self))Frost Ming
05/16/2025, 2:16 AM.state which is a dictionary to store arbitrary global statesRajiv Abraham
05/16/2025, 8:19 PM