Hello! I set up an simple image service with "@ser...
# ask-for-help
c
Hello! I set up an simple image service with "@service" and "@api" decorators. Is there a possibility during bentoml serve, to get the current bento tag of the service? i want to store a result.json file and also but the service tag in it 🙂
c
Yes
Copy code
import bentoml
from bentoml import server_context

@bentoml.service()
class Demo:
    def __init__(self) -> None:
        ..

    @bentoml.api
    def predict(self, query: str="hello") -> str:
        if server_context.bento_name:
            print("## ", server_context.bento_name)
        if server_context.bento_version:
            print("## ", server_context.bento_version)
        ...
✅ 1
when serving locally from a project directory, bento_version will be None when serving a built Bento or from a container, this code should give you the bento_version Tag is just:
{bento_name}:{bento_version}
c
thank you very much for the quick response! :)