CustomPersister Class — langchain Architecture
Architecture documentation for the CustomPersister class in conftest.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD d3622376_b455_b9cd_a885_7c3b3f1e4e0a["CustomPersister"] 4159e649_0289_4167_86d9_2e12affd22da["conftest.py"] d3622376_b455_b9cd_a885_7c3b3f1e4e0a -->|defined in| 4159e649_0289_4167_86d9_2e12affd22da a2cc7573_d2be_e845_b5cb_67b28e1b0650["load_cassette()"] d3622376_b455_b9cd_a885_7c3b3f1e4e0a -->|method| a2cc7573_d2be_e845_b5cb_67b28e1b0650 de88a9e5_dccf_72cf_df50_8697713f14f8["save_cassette()"] d3622376_b455_b9cd_a885_7c3b3f1e4e0a -->|method| de88a9e5_dccf_72cf_df50_8697713f14f8
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/conftest.py lines 55–89
class CustomPersister:
"""A custom persister for VCR that uses the `CustomSerializer`."""
@classmethod
def load_cassette(
cls,
cassette_path: str | PathLike[str],
serializer: CustomSerializer,
) -> tuple[list[Any], list[Any]]:
"""Load a cassette from a file."""
# If cassette path is already Path this is a no-op
cassette_path = Path(cassette_path)
if not cassette_path.is_file():
msg = f"Cassette file {cassette_path} does not exist."
raise CassetteNotFoundError(msg)
with cassette_path.open(mode="rb") as f:
data = f.read()
deser = serializer.deserialize(data)
return deser["requests"], deser["responses"]
@staticmethod
def save_cassette(
cassette_path: str | PathLike[str],
cassette_dict: dict[str, Any],
serializer: CustomSerializer,
) -> None:
"""Save a cassette to a file."""
data = serializer.serialize(cassette_dict)
# if cassette path is already Path this is no operation
cassette_path = Path(cassette_path)
cassette_folder = cassette_path.parent
if not cassette_folder.exists():
cassette_folder.mkdir(parents=True)
with cassette_path.open("wb") as f:
f.write(data)
Source
Frequently Asked Questions
What is the CustomPersister class?
CustomPersister is a class in the langchain codebase, defined in libs/standard-tests/langchain_tests/conftest.py.
Where is CustomPersister defined?
CustomPersister is defined in libs/standard-tests/langchain_tests/conftest.py at line 55.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free