From dba3cb095751a7f675fffd033ab803c34e58db02 Mon Sep 17 00:00:00 2001 From: Howard Gil Date: Wed, 15 May 2024 13:52:09 -0700 Subject: [PATCH 1/4] Added stuff to host_env --- agentops/__init__.py | 9 +++-- agentops/host_env.py | 81 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 9 deletions(-) diff --git a/agentops/__init__.py b/agentops/__init__.py index 02324a41..f2b30bea 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -2,11 +2,8 @@ from typing import Optional, List, Union from .client import Client from .config import Configuration -from .event import Event, ActionEvent, LLMEvent, ToolEvent, ErrorEvent -from .enums import Models -from .decorators import record_function -from .agent import track_agent -from .log_config import set_logging_level_info, set_logging_level_critial +from .event import Event, ErrorEvent +from .log_config import set_logging_level_info try: from .langchain_callback_handler import LangchainCallbackHandler, AsyncLangchainCallbackHandler except ModuleNotFoundError: @@ -47,6 +44,7 @@ def init(api_key: Optional[str] = None, Attributes: """ set_logging_level_info() + c = Client(api_key=api_key, parent_key=parent_key, endpoint=endpoint, @@ -131,6 +129,7 @@ def set_parent_key(parent_key): """ Client().set_parent_key(parent_key) + def stop_instrumenting(): Client().stop_instrumenting() diff --git a/agentops/host_env.py b/agentops/host_env.py index 4eff0c89..edad6957 100644 --- a/agentops/host_env.py +++ b/agentops/host_env.py @@ -2,6 +2,9 @@ import psutil import socket from .helpers import get_agentops_version +import importlib.metadata +import os +import sys def get_sdk_details(): @@ -9,6 +12,68 @@ def get_sdk_details(): return { "AgentOps SDK Version": get_agentops_version(), "Python Version": platform.python_version(), + "System Packages": get_sys_packages() + } + except: + return {} + + +def get_python_details(): + try: + return { + "Python Version": platform.python_version() + } + except: + return {} + + +def get_agentops_details(): + try: + return { + "AgentOps SDK Version": get_agentops_version() + } + except: + return {} + + +def get_sys_packages(): + sys_packages = {} + for module in sys.modules: + try: + version = importlib.metadata.version(module) + sys_packages[module] = version + except importlib.metadata.PackageNotFoundError: + # Skip built-in modules and those without package metadata + continue + + return sys_packages + + +def get_installed_packages(): + + try: + return { + # TODO: test + # TODO: add to opt out + "Installed Packages": {dist.metadata['Name']: dist.version for dist in importlib.metadata.distributions()} + } + except: + return {} + + +def get_current_directory(): + try: + return { + "Project Working Directory": os.getcwd() + } + except: + return {} + + +def get_virtual_env(): + try: + return { + "Virtual Environment": os.environ.get('VIRTUAL_ENV', None) } except: return {} @@ -51,7 +116,6 @@ def get_ram_details(): return {} - def get_disk_details(): partitions = psutil.disk_partitions() disk_info = {} @@ -70,14 +134,23 @@ def get_disk_details(): def get_host_env(opt_out: bool = False): if opt_out: return { - "SDK": get_sdk_details(), - "OS": get_os_details() + "AgentOps SDK": get_agentops_details(), + "Python": get_python_details(), + "OS": get_os_details(), + "System Packages": get_sys_packages(), + "Project Working Directory": get_current_directory(), + "Virtual Environment": get_virtual_env() } else: return { - "SDK": get_sdk_details(), + "AgentOps SDK": get_agentops_details(), + "Python": get_python_details(), "OS": get_os_details(), "CPU": get_cpu_details(), "RAM": get_ram_details(), "Disk": get_disk_details(), + "System Packages": get_sys_packages(), + "Installed Packages": get_installed_packages(), + "Project Working Directory": get_current_directory(), + "Virtual Environment": get_virtual_env() } From 802b8045843d31d6798a6cbe423869562fba2c62 Mon Sep 17 00:00:00 2001 From: Howard Gil Date: Wed, 15 May 2024 14:13:41 -0700 Subject: [PATCH 2/4] Undo last reset --- agentops/host_env.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/agentops/host_env.py b/agentops/host_env.py index edad6957..13d27943 100644 --- a/agentops/host_env.py +++ b/agentops/host_env.py @@ -134,22 +134,18 @@ def get_disk_details(): def get_host_env(opt_out: bool = False): if opt_out: return { - "AgentOps SDK": get_agentops_details(), - "Python": get_python_details(), + "SDK": get_sdk_details(), "OS": get_os_details(), - "System Packages": get_sys_packages(), "Project Working Directory": get_current_directory(), "Virtual Environment": get_virtual_env() } else: return { - "AgentOps SDK": get_agentops_details(), - "Python": get_python_details(), + "SDK": get_sdk_details(), "OS": get_os_details(), "CPU": get_cpu_details(), "RAM": get_ram_details(), "Disk": get_disk_details(), - "System Packages": get_sys_packages(), "Installed Packages": get_installed_packages(), "Project Working Directory": get_current_directory(), "Virtual Environment": get_virtual_env() From cb248d56decb66ee755be90e18ad19c2685b52bf Mon Sep 17 00:00:00 2001 From: Howard Gil Date: Wed, 15 May 2024 14:14:53 -0700 Subject: [PATCH 3/4] Put back critical stuff --- agentops/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/agentops/__init__.py b/agentops/__init__.py index f2b30bea..38597c8a 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -2,8 +2,11 @@ from typing import Optional, List, Union from .client import Client from .config import Configuration -from .event import Event, ErrorEvent -from .log_config import set_logging_level_info +from .event import Event, ActionEvent, LLMEvent, ToolEvent, ErrorEvent +from .enums import Models +from .decorators import record_function +from .agent import track_agent +from .log_config import set_logging_level_info, set_logging_level_critial try: from .langchain_callback_handler import LangchainCallbackHandler, AsyncLangchainCallbackHandler except ModuleNotFoundError: From b9cba4546611202e9fec6a575927cf69153b9c0c Mon Sep 17 00:00:00 2001 From: Howard Gil Date: Wed, 15 May 2024 15:39:31 -0700 Subject: [PATCH 4/4] undoing whitespace change --- agentops/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/agentops/__init__.py b/agentops/__init__.py index 38597c8a..02324a41 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -47,7 +47,6 @@ def init(api_key: Optional[str] = None, Attributes: """ set_logging_level_info() - c = Client(api_key=api_key, parent_key=parent_key, endpoint=endpoint, @@ -132,7 +131,6 @@ def set_parent_key(parent_key): """ Client().set_parent_key(parent_key) - def stop_instrumenting(): Client().stop_instrumenting()