Björn Werner
06/19/2024, 7:35 PMimport 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:
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!Chaoyu
06/19/2024, 9:58 PMFrost Ming
06/20/2024, 12:53 AMBjörn Werner
06/20/2024, 5:20 PMChaoyu
06/20/2024, 7:09 PMChaoyu
06/20/2024, 7:10 PMFrost Ming
06/21/2024, 12:36 AMIs it possible for user use the Response object to do thisYes, users can return a
starlette.Response from the API method directlyBjörn Werner
06/21/2024, 4:31 PM