From b8cf3ccd7d1b946de8ea8f3506bbb04d48475bff Mon Sep 17 00:00:00 2001 From: tstadel <60758086+tstadel@users.noreply.github.com> Date: Wed, 25 Dec 2024 12:33:06 +0100 Subject: [PATCH] fix: truncate ByteStream string representation --- haystack/dataclasses/byte_stream.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/haystack/dataclasses/byte_stream.py b/haystack/dataclasses/byte_stream.py index 72a2648199..9dca4d9697 100644 --- a/haystack/dataclasses/byte_stream.py +++ b/haystack/dataclasses/byte_stream.py @@ -63,3 +63,10 @@ def to_string(self, encoding: str = "utf-8") -> str: :raises: UnicodeDecodeError: If the ByteStream data cannot be decoded with the specified encoding. """ return self.data.decode(encoding) + + def __str__(self) -> str: + """ + Returns a string representation of the ByteStream, truncating the data to 1KB. + """ + truncated = self.data[:1021] + b"..." if len(self.data) > 1024 else self.data + return f"ByteStream(data={truncated!r}, mime_type={self.mime_type!r}, meta={self.meta!r})"