Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize Client.llm_tracker on all codepaths. #257

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__(
os.environ.get("AGENTOPS_ENV_DATA_OPT_OUT", "False").lower() == "true"
)

self.llm_tracker = None
self.config = None

try:
Expand Down
3 changes: 2 additions & 1 deletion agentops/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def singleton(class_):
instances = {}

def getinstance(*args, **kwargs):
if class_ not in instances:
allow_multiple_instances = kwargs.pop("allow_multiple_instances", False)
if allow_multiple_instances or class_ not in instances:
instances[class_] = class_(*args, **kwargs)
return instances[class_]

Expand Down
13 changes: 12 additions & 1 deletion tests/test_teardown.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ class TestSessions:
def setup_method(self):
self.api_key = "random_api_key"
self.event_type = "test_event_type"
self.client = Client(self.api_key)
self.client = Client(self.api_key, allow_multiple_instances=False)

def test_exit(self):
# Tests should not hang.
...

def test_can_stop_with_no_instrumentation(self):
non_instrumented = Client(self.api_key, instrument_llm_calls=False,
allow_multiple_instances=True)
assert non_instrumented.llm_tracker is None
non_instrumented.stop_instrumenting()

def test_initializes_llm_tracker_when_enabled(self):
instrumented = Client(self.api_key, instrument_llm_calls=True,
allow_multiple_instances=True)
assert instrumented.llm_tracker is not None
Loading