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

Method as_string

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

Read data as a string.

(self)

Source from the content-addressed store, hash-verified

135 return values
136
137 def as_string(self) -> str:
138 """Read data as a string."""
139 if self.data is None and self.path:
140 with open(str(self.path), "r", encoding=self.encoding) as f:
141 return f.read()
142 elif isinstance(self.data, bytes):
143 return self.data.decode(self.encoding)
144 elif isinstance(self.data, str):
145 return self.data
146 else:
147 raise ValueError(f"Unable to get string for blob {self}")
148
149 def as_bytes(self) -> bytes:
150 """Read data as bytes."""

Calls 1

readMethod · 0.45

Tested by 1