Skip to content

Commit 220a6d6

Browse files
committed
Update GuanrdrailSequence save_to_file()
1 parent a107dd2 commit 220a6d6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ads/llm/chain.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ def _save_to_file(self, chain_dict, filename, overwrite=False):
192192
)
193193

194194
file_ext = pathlib.Path(expanded_path).suffix.lower()
195+
if file_ext not in [".yaml", ".json"]:
196+
raise ValueError(
197+
f"{self.__class__.__name__} can only be saved as yaml or json format."
198+
)
195199
with open(expanded_path, "w", encoding="utf-8") as f:
196200
if file_ext == ".yaml":
197201
yaml.safe_dump(chain_dict, f, default_flow_style=False)
198202
elif file_ext == ".json":
199203
json.dump(chain_dict, f)
200-
else:
201-
raise ValueError(
202-
f"{self.__class__.__name__} can only be saved as yaml or json format."
203-
)
204204

205205
def save(self, filename: str = None, overwrite: bool = False) -> dict:
206206
"""Serialize the sequence to a dictionary.

0 commit comments

Comments
 (0)