mirror of
https://github.com/hwchase17/langchain
synced 2024-11-04 06:00:26 +00:00
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:
parent
c3624b416d
commit
b508fcce65
58
libs/core/langchain_core/sys_info.py
Normal file
58
libs/core/langchain_core/sys_info.py
Normal 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()
|
6
libs/core/tests/unit_tests/test_sys_info.py
Normal file
6
libs/core/tests/unit_tests/test_sys_info.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user