Skip to content

Commit

Permalink
fix: truncate ByteStream string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
tstadel committed Dec 25, 2024
1 parent 3ea128c commit b8cf3cc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions haystack/dataclasses/byte_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})"

0 comments on commit b8cf3cc

Please sign in to comment.