mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-19 13:26:32 -04:00
1c81883d42
This PR targets the `API Reference` documentation.
- Several classes and functions missed `docstrings`. These docstrings
were created.
- In several places this
```
except ImportError:
raise ValueError(
```
was replaced to
```
except ImportError:
raise ImportError(
```
27 lines
753 B
Python
27 lines
753 B
Python
import json
|
|
from typing import Any, Dict
|
|
|
|
from langchain.load.serializable import Serializable, to_json_not_implemented
|
|
|
|
|
|
def default(obj: Any) -> Any:
|
|
"""Return a default value for a Serializable object or
|
|
a SerializedNotImplemented object."""
|
|
if isinstance(obj, Serializable):
|
|
return obj.to_json()
|
|
else:
|
|
return to_json_not_implemented(obj)
|
|
|
|
|
|
def dumps(obj: Any, *, pretty: bool = False) -> str:
|
|
"""Return a json string representation of an object."""
|
|
if pretty:
|
|
return json.dumps(obj, default=default, indent=2)
|
|
else:
|
|
return json.dumps(obj, default=default)
|
|
|
|
|
|
def dumpd(obj: Any) -> Dict[str, Any]:
|
|
"""Return a json dict representation of an object."""
|
|
return json.loads(dumps(obj))
|