Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect the content type config for file output #4570

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/_bentoml_sdk/io_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def mime_type(cls) -> str:
return "audio/*"
elif format == "video":
return "video/*"
return "*/*"
return "application/octet-stream"
return "application/json"

@classmethod
Expand Down Expand Up @@ -178,9 +178,7 @@ def content_stream() -> t.Generator[str | bytes, None, None]:
else:
if is_file_type(type(obj)) and isinstance(serde, JSONSerde):
if isinstance(obj, pathlib.PurePath):
media_type = (
mimetypes.guess_type(obj)[0] or "application/octet-stream"
)
media_type = mimetypes.guess_type(obj)[0] or cls.mime_type()
should_inline = media_type.startswith("image")
content_disposition_type = (
"inline" if should_inline else "attachment"
Expand Down Expand Up @@ -310,7 +308,9 @@ def from_output(cls, func: t.Callable[..., t.Any]) -> type[IODescriptor]:


def ensure_io_descriptor(output_type: type) -> type[IODescriptor]:
if inspect.isclass(output_type) and issubclass(output_type, BaseModel):
from pydantic._internal._utils import lenient_issubclass

if inspect.isclass(output_type) and lenient_issubclass(output_type, BaseModel):
if not issubclass(output_type, IODescriptor):
return t.cast(
t.Type[IODescriptor],
Expand Down
Loading