|
|
|
@ -610,8 +610,6 @@ class Chain(RunnableSerializable[Dict[str, Any], Dict[str, Any]], ABC):
|
|
|
|
|
chain.dict(exclude_unset=True)
|
|
|
|
|
# -> {"_type": "foo", "verbose": False, ...}
|
|
|
|
|
"""
|
|
|
|
|
if self.memory is not None:
|
|
|
|
|
raise ValueError("Saving of memory is not yet supported.")
|
|
|
|
|
_dict = super().dict(**kwargs)
|
|
|
|
|
try:
|
|
|
|
|
_dict["_type"] = self._chain_type
|
|
|
|
@ -633,6 +631,14 @@ class Chain(RunnableSerializable[Dict[str, Any], Dict[str, Any]], ABC):
|
|
|
|
|
|
|
|
|
|
chain.save(file_path="path/chain.yaml")
|
|
|
|
|
"""
|
|
|
|
|
if self.memory is not None:
|
|
|
|
|
raise ValueError("Saving of memory is not yet supported.")
|
|
|
|
|
|
|
|
|
|
# Fetch dictionary to save
|
|
|
|
|
chain_dict = self.dict()
|
|
|
|
|
if "_type" not in chain_dict:
|
|
|
|
|
raise NotImplementedError(f"Chain {self} does not support saving.")
|
|
|
|
|
|
|
|
|
|
# Convert file to Path object.
|
|
|
|
|
if isinstance(file_path, str):
|
|
|
|
|
save_path = Path(file_path)
|
|
|
|
@ -642,11 +648,6 @@ class Chain(RunnableSerializable[Dict[str, Any], Dict[str, Any]], ABC):
|
|
|
|
|
directory_path = save_path.parent
|
|
|
|
|
directory_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
# Fetch dictionary to save
|
|
|
|
|
chain_dict = self.dict()
|
|
|
|
|
if "_type" not in chain_dict:
|
|
|
|
|
raise NotImplementedError(f"Chain {self} does not support saving.")
|
|
|
|
|
|
|
|
|
|
if save_path.suffix == ".json":
|
|
|
|
|
with open(file_path, "w") as f:
|
|
|
|
|
json.dump(chain_dict, f, indent=4)
|
|
|
|
|