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

Method save

libs/core/langchain_core/language_models/llms.py:1187–1217  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

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
1220class LLM(BaseLLM):

Callers 1

Calls 2

dictMethod · 0.95
dumpMethod · 0.80

Tested by 1