From 60607dfb7a32c7c2e753c4d78faf9fddb08fe3e7 Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Mon, 5 Aug 2024 13:59:09 -0700 Subject: [PATCH] speed up version check (#334) --- agentops/__init__.py | 4 +++- agentops/helpers.py | 22 ++++++++++++++-------- tests/core_manual_tests/canary.py | 25 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 tests/core_manual_tests/canary.py diff --git a/agentops/__init__.py b/agentops/__init__.py index 5798c366..9397d6b3 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -8,6 +8,7 @@ from .helpers import check_agentops_update from .log_config import logger from .session import Session +import threading try: from .partners.langchain_callback_handler import ( @@ -62,7 +63,8 @@ def init( Attributes: """ Client().unsuppress_logs() - check_agentops_update() + t = threading.Thread(target=check_agentops_update) + t.start() if Client().is_initialized: return logger.warning( diff --git a/agentops/helpers.py b/agentops/helpers.py index bd95e868..9e7e873a 100644 --- a/agentops/helpers.py +++ b/agentops/helpers.py @@ -4,6 +4,8 @@ import json import inspect from typing import Union +import requests +from importlib.metadata import version, PackageNotFoundError from .log_config import logger from uuid import UUID @@ -150,15 +152,19 @@ def get_agentops_version(): def check_agentops_update(): - result = subprocess.run( - ["pip", "list", "--outdated"], capture_output=True, text=True - ) - lines = result.stdout.splitlines()[2:] # Skip the header lines - for line in lines: - parts = line.split() - if len(parts) > 0 and parts[0] == "agentops": + response = requests.get("https://pypi.org/pypi/agentops/json") + + if response.status_code == 200: + latest_version = response.json()["info"]["version"] + + try: + current_version = version("agentops") + except PackageNotFoundError: + return None + + if not latest_version == current_version: logger.warning( - f" WARNING: {parts[0]} is out of date. Please update with the command: 'pip install --upgrade agentops'" + f" WARNING: agentops is out of date. Please update with the command: 'pip install --upgrade agentops'" ) diff --git a/tests/core_manual_tests/canary.py b/tests/core_manual_tests/canary.py new file mode 100644 index 00000000..325cb840 --- /dev/null +++ b/tests/core_manual_tests/canary.py @@ -0,0 +1,25 @@ +import agentops +from openai import OpenAI +from dotenv import load_dotenv +from agentops import ActionEvent + +load_dotenv() +agentops.init() +openai = OpenAI() + +messages = [{"role": "user", "content": "Hello"}] + +# option 1: use session.patch +response = openai.chat.completions.create( + model="gpt-3.5-turbo", + messages=messages, + temperature=0.5, +) + +agentops.record(ActionEvent(action_type="test event")) + +agentops.end_session(end_state="Success") + +### +# Used to verify that one session is created with one LLM event +###