You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unable to get an endpoint with PILImage without Content-Type:multipart/form-data with new Service decorator
To reproduce
I already have working code with bentoml 1.1.11, runners, yolo/pytorch model.
I'm trying to migrate to new decorators @bentoml.service and @bentoml.api to use concurrency feature introduced.
Bentoml version tested: [1.2.9, 1.2.10].
All examples running with bentoml serve -p 8000 service.py:Service.
My working code with 1.1.11 and 1.2.10 with Runner/Runnable looks like
Now, I'm trying to migrate to new decorators and my code looks like
fromsrc.ServiceimportServicefromPIL.ImageimportImageasPILImage@bentoml.service()classService:
# this class is a sustitute of MyRunnable class. my_new_service=bentoml.depends(Service)
@bentoml.api(route="/v1/debug" )asyncdefdebug(
self,
image: PILImage=Field(description="Image to be processed")
):
return {"width": image.width, "height": image.height}
Now my curl for this code (extracted from swagger) is
The code is working, but I don't want to change the endpoint call from Content-Type: image/jpeg to Content-Type: multipart/form-data.
I tried this:
# This is the using the same Image() that `@svc.api(input=Image()` old decorator uses
from bentoml.io import Image
from PIL.Image import Image as PILImage
from src.Service import Service
@bentoml.service()
class Service:
# this class is a sustitute of MyRunnable class.
my_new_service = bentoml.depends(Service)
@bentoml.api(
input_spec=Image(),
route="/v1/debug"
)
async def debug(
self,
image: PILImage = Field(description="Image to be processed")
):
return {"width": image.width, "height": image.height}
With the following errors:
File "/.../service.py", line 34, in <module>
class Service:
File "/.../service.py", line 37, in Service
@bentoml.api(
^^^^^^^^^^^^
File "/.../_bentoml_sdk/decorators.py", line 101, in wrapper
return APIMethod(func, **params)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "<attrs generated init _bentoml_sdk.method.APIMethod>", line 13, in __init__
File "/.../_bentoml_sdk/method.py", line 36, in _io_descriptor_converter
raise ValueError(f"{it} must be a class type")
ValueError: Image must be a class type
I already tried this:
# This is the using the Annotated example in documentation
from typing import Annotated
from bentoml.validators import ContentType
from PIL.Image import Image as PILImage
from src.Service import Service
@bentoml.service()
class Service:
# this class is a sustitute of MyRunnable class.
my_new_service = bentoml.depends(Service)
@bentoml.api(
route="/v1/debug"
)
async def debug(
self,
image: Annotated[PILImage, ContentType('image/jpeg')]
):
return {"width": image.width, "height": image.height}
This code is working too but the same mentioned problem, changed Content-Type to multipart.
I'm not sure if it is a bug or not. It's possible just I was missing something.
The motivation to upgrade to new decorators is the use of concurrency feature introduced.
Is there any way to use with old Runners way?
I really appreciated some help there.
Thanks in advance,
Adrián.
Expected behavior
Using PILImage or bentoml.io.Image in the same way and with the same endpoint result.
Environment
bentoml: 1.2.9 and 1.2.10
python: 3.11.8
platform: Macos Sonoma 14.4.1. M1 PRO cpu.
The text was updated successfully, but these errors were encountered:
Describe the bug
Unable to get an endpoint with
PILImage
withoutContent-Type:multipart/form-data
with new Service decoratorTo reproduce
I already have working code with bentoml 1.1.11, runners, yolo/pytorch model.
I'm trying to migrate to new decorators
@bentoml.service
and@bentoml.api
to use concurrency feature introduced.Bentoml version tested: [1.2.9, 1.2.10].
All examples running with
bentoml serve -p 8000 service.py:Service
.My working code with 1.1.11 and 1.2.10 with Runner/Runnable looks like
An example curl to before code is
Now, I'm trying to migrate to new decorators and my code looks like
Now my curl for this code (extracted from swagger) is
The code is working, but I don't want to change the endpoint call from
Content-Type: image/jpeg
toContent-Type: multipart/form-data
.I tried this:
With the following errors:
I already tried this:
This code is working too but the same mentioned problem, changed Content-Type to multipart.
I'm not sure if it is a bug or not. It's possible just I was missing something.
The motivation to upgrade to new decorators is the use of concurrency feature introduced.
Is there any way to use with old Runners way?
I really appreciated some help there.
Thanks in advance,
Adrián.
Expected behavior
Using PILImage or bentoml.io.Image in the same way and with the same endpoint result.
Environment
bentoml: 1.2.9 and 1.2.10
python: 3.11.8
platform: Macos Sonoma 14.4.1. M1 PRO cpu.
The text was updated successfully, but these errors were encountered: