core(minor): Add a way to print out system information for debugging purposes. (#15718)

To use: 

```bash
python -m langchain_core.sys_info
```
This commit is contained in:
Eugene Yurtsev 2024-01-08 15:20:18 -05:00 committed by GitHub
parent c3624b416d
commit b508fcce65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,58 @@
"""Print information about the system and langchain packages for debugging purposes."""
from typing import Sequence
def print_sys_info(*, additional_pkgs: Sequence[str] = tuple()) -> None:
"""Print information about the environment for debugging purposes."""
import platform
import sys
from importlib import metadata, util
packages = [
"langchain_core",
"langchain",
"langchain_community",
"langserve",
] + list(additional_pkgs)
system_info = {
"OS": platform.system(),
"OS Version": platform.version(),
"Python Version": sys.version,
}
print()
print("System Information")
print("------------------")
print("> OS: ", system_info["OS"])
print("> OS Version: ", system_info["OS Version"])
print("> Python Version: ", system_info["Python Version"])
# Print out only langchain packages
print()
print("Package Information")
print("-------------------")
for pkg in packages:
try:
found_package = util.find_spec(pkg)
except Exception:
found_package = None
if found_package is None:
print(f"> {pkg}: Not Found")
continue
# Package version
try:
package_version = metadata.version(pkg)
except Exception:
package_version = None
# Print package with version
if package_version is not None:
print(f"> {pkg}: {package_version}")
else:
print(f"> {pkg}: Found")
if __name__ == "__main__":
print_sys_info()

View File

@ -0,0 +1,6 @@
from langchain_core.sys_info import print_sys_info
def test_print_sys_info() -> None:
"""Super simple test to that no exceptions are triggered when calling code."""
print_sys_info()