Hello - I encountered a possible bug or am I doing...
# ask-for-help
b
Hello - I encountered a possible bug or am I doing something wrong? I can't make BentoML return multiple PILImages in a List. Here is the minimal code (using bentoml 1.2.18):
Copy code
import bentoml
from PIL.Image import Image as PILImage
from typing import List


@bentoml.service(
    workers=1,
    traffic={"timeout": 300},
)
class TestService:
    name = "TestService"

    @bentoml.api(route="/test_image_list_output")
    async def test_image_list_output(self, input_image: PILImage) -> List[PILImage]:
        return_images = [input_image]
        return return_images
When using swagger and attach any image it should return a list including that image but instead it throws:
Copy code
2024-06-19T21:32:12+0200 [ERROR] [entry_service:TestService:1] Exception on /test_image_list_output [POST] (trace=ae56b5cd2a525e62bb3d1300dabf5574,span=8a242a8848ca2649,sampled=0,service.name=TestService)
Traceback (most recent call last):
  File "/home/user/miniconda3/envs/sd/lib/python3.10/site-packages/_bentoml_impl/server/app.py", line 421, in api_endpoint_wrapper
    resp = await self.api_endpoint(name, request)
  File "/home/user/miniconda3/envs/sd/lib/python3.10/site-packages/_bentoml_impl/server/app.py", line 516, in api_endpoint
    response = await method.output_spec.to_http_response(output, serde)
  File "/home/user/miniconda3/envs/sd/lib/python3.10/site-packages/_bentoml_sdk/io_models.py", line 259, in to_http_response
    payload = serde.serialize_model(ins)
  File "/home/user/miniconda3/envs/sd/lib/python3.10/site-packages/_bentoml_impl/serde.py", line 150, in serialize_model
    model.model_dump_json(
  File "/home/user/miniconda3/envs/sd/lib/python3.10/site-packages/pydantic/main.py", line 398, in model_dump_json
    return self.__pydantic_serializer__.to_json(
pydantic_core._pydantic_core.PydanticSerializationError: Error serializing to JSON: invalid utf-8 sequence of 1 bytes from index 0
2024-06-19T21:32:12+0200 [INFO] [entry_service:TestService:1] 127.0.0.1:46398 (scheme=http,method=POST,path=/test_image_list_output,type=multipart/form-data; boundary=----WebKitFormBoundarykpr3msdOUVATwiu9,length=140777) (status=500,type=application/json,length=74) 14.692ms (trace=ae56b5cd2a525e62bb3d1300dabf5574,span=8a242a8848ca2649,sampled=0,service.name=TestService)
Am I doing something wrong or is there a workaround? This is really stopping me right now 😕 Thank you!
c
@Frost Ming could you help take a look?
f
Sorry, multipart output(list of binaries) is not supported yet. will update the docs to be correct
🥲 2
b
Thank you for that information. :)
c
One workaround is to use a custom encoding to return multiple image files (e.g. base64)
@Frost Ming is returning multiple binaries on our roadmap? Is it possible for user use the Response object to do this?
f
Is it possible for user use the Response object to do this
Yes, users can return a
starlette.Response
from the API method directly
b
Thanks - that works fine in the mean time!