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: Blob.from_data mimetype is lost #5395

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion langchain/document_loaders/blob_loaders/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def from_data(
Returns:
Blob instance
"""
return cls(data=data, mime_type=mime_type, encoding=encoding, path=path)
return cls(data=data, mimetype=mime_type, encoding=encoding, path=path)

def __repr__(self) -> str:
"""Define the blob representation."""
Expand Down
23 changes: 23 additions & 0 deletions tests/unit_tests/document_loaders/blob_loaders/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ def test_blob_from_str_path() -> None:
assert bytes_io.read() == content


def test_blob_from_str_data() -> None:
"""Test reading blob from a file path."""
content = b"Hello, World!"
blob = Blob.from_data(content)
assert blob.encoding == "utf-8" # Default encoding
assert blob.path is None
assert blob.mimetype is None
assert blob.source is None
assert blob.data == b"Hello, World!"
assert blob.as_bytes() == content
assert blob.as_string() == "Hello, World!"
with blob.as_bytes_io() as bytes_io:
assert bytes_io.read() == content


def test_blob_mimetype_from_str_data() -> None:
"""Test reading blob from a file path."""
content = b"Hello, World!"
mimetype = "text/html"
blob = Blob.from_data(content, mime_type=mimetype)
assert blob.mimetype == mimetype


@pytest.mark.parametrize(
"path, mime_type, guess_type, expected_mime_type",
[
Expand Down