Save the LLM. Args: file_path: Path to file to save the LLM to. Example: .. code-block:: python llm.save(file_path="path/llm.yaml")
(self, file_path: Union[Path, str])
| 1185 | return starter_dict |
| 1186 | |
| 1187 | def save(self, file_path: Union[Path, str]) -> None: |
| 1188 | """Save the LLM. |
| 1189 | |
| 1190 | Args: |
| 1191 | file_path: Path to file to save the LLM to. |
| 1192 | |
| 1193 | Example: |
| 1194 | .. code-block:: python |
| 1195 | |
| 1196 | llm.save(file_path="path/llm.yaml") |
| 1197 | """ |
| 1198 | # Convert file to Path object. |
| 1199 | if isinstance(file_path, str): |
| 1200 | save_path = Path(file_path) |
| 1201 | else: |
| 1202 | save_path = file_path |
| 1203 | |
| 1204 | directory_path = save_path.parent |
| 1205 | directory_path.mkdir(parents=True, exist_ok=True) |
| 1206 | |
| 1207 | # Fetch dictionary to save |
| 1208 | prompt_dict = self.dict() |
| 1209 | |
| 1210 | if save_path.suffix == ".json": |
| 1211 | with open(file_path, "w") as f: |
| 1212 | json.dump(prompt_dict, f, indent=4) |
| 1213 | elif save_path.suffix.endswith((".yaml", ".yml")): |
| 1214 | with open(file_path, "w") as f: |
| 1215 | yaml.dump(prompt_dict, f, default_flow_style=False) |
| 1216 | else: |
| 1217 | raise ValueError(f"{save_path} must be json or yaml") |
| 1218 | |
| 1219 | |
| 1220 | class LLM(BaseLLM): |