Skip to content

Commit

Permalink
speed up version check
Browse files Browse the repository at this point in the history
  • Loading branch information
bboynton97 committed Aug 5, 2024
1 parent 49a748b commit 3bd5511
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
4 changes: 3 additions & 1 deletion agentops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 14 additions & 8 deletions agentops/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'"
)


Expand Down
25 changes: 25 additions & 0 deletions tests/core_manual_tests/canary.py
Original file line number Diff line number Diff line change
@@ -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
###

0 comments on commit 3bd5511

Please sign in to comment.