Hi all, My team using both fastapi and bentoml. W...
# ask-for-help
l
Hi all, My team using both fastapi and bentoml. We have a unify documentation logic on fastapi based on docs_url and openapi_url. Using a mount asgi app how to use the documentation of fastapi instead of bentoml ? I mean getting bentoml api routes into our fastapi documentation.
j
Hey Lucas, In BentoML 1.2, all classes with the
@bentoml.service
decorator have an
openapi_spec
parameter. You can use
openapi_spec.asdict
to extract the OpenAPI schema from your service as a dictionary. Then, you can pass this to the FastAPI app's
app.openapi_schema
.
For example, import bentoml @bentoml.service( resources={"cpu": "2"}, traffic={"timeout": 10}, ) @bentoml.mount_asgi_app(app, path="/v1") class Api: def __init__(self) -> None: self.model = None @bentoml.api def summarize(self, text: str) -> str: return dict(self) openapi_schema = Api.openapi_spec.asdict() app.openapi_schema = openapi_schema
l
Thank you !