MCPcopy
hub / github.com/langchain-ai/langchain / as_bytes

Method as_bytes

libs/core/langchain_core/documents/base.py:149–159  ·  view source on GitHub ↗

Read data as bytes.

(self)

Source from the content-addressed store, hash-verified

147 raise ValueError(f"Unable to get string for blob {self}")
148
149 def as_bytes(self) -> bytes:
150 """Read data as bytes."""
151 if isinstance(self.data, bytes):
152 return self.data
153 elif isinstance(self.data, str):
154 return self.data.encode(self.encoding)
155 elif self.data is None and self.path:
156 with open(str(self.path), "rb") as f:
157 return f.read()
158 else:
159 raise ValueError(f"Unable to get bytes for blob {self}")
160
161 @contextlib.contextmanager
162 def as_bytes_io(self) -> Generator[Union[BytesIO, BufferedReader], None, None]:

Calls 2

encodeMethod · 0.45
readMethod · 0.45

Tested by 1