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

Indent fix, test fix and python version expansion #186

Merged
merged 4 commits into from
May 3, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/python-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
python-version: [3.11]
python-version: [3.7,3.8,3.9,3.10,3.11,3.12]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions agentops/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# agentops/__init__.py
from os import environ
from typing import Optional, List
from typing import Optional, List, Union

from .client import Client
from .config import Configuration
Expand Down Expand Up @@ -86,7 +86,7 @@ def start_session(tags: Optional[List[str]] = None, config: Optional[Configurati
return Client().start_session(tags, config, inherited_session_id)


def record(event: Event | ErrorEvent):
def record(event: Union[Event, ErrorEvent]):
"""
Record an event with the AgentOps service.

Expand Down
4 changes: 3 additions & 1 deletion agentops/agent.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Union

from .log_config import logger
from uuid import uuid4
from agentops import Client
from inspect import isclass, isfunction


def track_agent(name: str | None = None):
def track_agent(name: Union[str, None] = None):
def decorator(obj):
if name:
obj.agent_ops_agent_name = name
Expand Down
5 changes: 2 additions & 3 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .worker import Worker
from .host_env import get_host_env
from uuid import uuid4
from typing import Optional, List
from typing import Optional, List, Union
import traceback
from .log_config import logger, set_logging_level_info
from decimal import Decimal
Expand Down Expand Up @@ -114,7 +114,6 @@ def add_tags(self, tags: List[str]):
self._session.tags = tags

if self._session is not None and self._worker is not None:
self._session.tags = self._tags
self._worker.update_session(self._session)

def set_tags(self, tags: List[str]):
Expand All @@ -130,7 +129,7 @@ def set_tags(self, tags: List[str]):
self._session.tags = tags
self._worker.update_session(self._session)

def record(self, event: Event | ErrorEvent):
def record(self, event: Union[Event, ErrorEvent]):
"""
Record an event with the AgentOps service.

Expand Down
18 changes: 9 additions & 9 deletions agentops/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from dataclasses import asdict, dataclass, field
from typing import Any, Dict, List, Optional, Sequence
from typing import Any, Dict, List, Optional, Sequence, Union
from .helpers import get_ISO_time, check_call_stack_for_agent_id
from .enums import EventType, Models
from uuid import UUID, uuid4
Expand Down Expand Up @@ -38,8 +38,8 @@ class Event:
"""

event_type: str # EventType.ENUM.value
params: Optional[str | Dict[str, Any]] = None
returns: Optional[str | Dict[str, Any]] = None
params: Optional[Union[str, Dict[str, Any]]] = None
returns: Optional[Union[str, Dict[str, Any]]] = None
init_timestamp: Optional[str] = field(default_factory=get_ISO_time)
end_timestamp: str = field(default_factory=get_ISO_time)
agent_id: Optional[UUID] = field(default_factory=check_call_stack_for_agent_id)
Expand All @@ -60,7 +60,7 @@ class ActionEvent(Event):
event_type: str = EventType.ACTION.value
# TODO: Should not be optional, but non-default argument 'agent_id' follows default argument error
action_type: Optional[str] = None
logs: Optional[str | Sequence[Any]] = None
logs: Optional[Union[str, Sequence[Any]]] = None
screenshot: Optional[str] = None

# May be needed if we keep Optional for agent_id
Expand All @@ -86,11 +86,11 @@ class LLMEvent(Event):

event_type: str = EventType.LLM.value
thread_id: Optional[UUID] = None
prompt: Optional[str | List] = None
prompt: Optional[Union[str, List]] = None
prompt_tokens: Optional[int] = None
completion: str | object = None
completion: Union[str, object] = None
completion_tokens: Optional[int] = None
model: Optional[Models | str] = None
model: Optional[Union[Models, str]] = None


@dataclass
Expand All @@ -104,7 +104,7 @@ class ToolEvent(Event):
"""
event_type: str = EventType.TOOL.value
name: Optional[str] = None
logs: Optional[str | dict] = None
logs: Optional[Union[str, dict]] = None

# Does not inherit from Event because error will (optionally) be linked to an ActionEvent, LLMEvent, etc that will have the details

Expand All @@ -129,7 +129,7 @@ class ErrorEvent():
exception: Optional[BaseException] = None
error_type: Optional[str] = None
code: Optional[str] = None
details: Optional[str | Dict[str, str]] = None
details: Optional[Union[str, Dict[str, str]]] = None
logs: Optional[str] = field(default_factory=traceback.format_exc)
timestamp: str = field(default_factory=get_ISO_time)

Expand Down
4 changes: 3 additions & 1 deletion agentops/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from datetime import datetime
import json
import inspect
from typing import Union

from .log_config import logger
from uuid import UUID
import os
Expand Down Expand Up @@ -76,7 +78,7 @@ def remove_none_values(value):
return json.dumps(cleaned_obj, default=default)


def check_call_stack_for_agent_id() -> UUID | None:
def check_call_stack_for_agent_id() -> Union[UUID, None]:
for frame_info in inspect.stack():
# Look through the call stack for the class that called the LLM
local_vars = frame_info.frame.f_locals
Expand Down
2 changes: 0 additions & 2 deletions agentops/llm_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ def handle_stream_chunk(chunk):
kwargs_str = pprint.pformat(kwargs)
chunk = pprint.pformat(chunk)
logger.warning(
"🖇 AgentOps: Unable to parse a chunk for LLM call %s - skipping upload to AgentOps",
kwargs)
f"🖇 AgentOps: Unable to parse a chunk for LLM call. Skipping upload to AgentOps\n"
f"chunk:\n {chunk}\n"
f"kwargs:\n {kwargs_str}\n"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ authors = [
]
description = "Python SDK for developing AI agent evals and observability"
readme = "README.md"
requires-python = ">=3.10"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py310,py311,py312
envlist = py37,py38,py39,py310,py311,py312

[testenv]
deps =
Expand Down
Loading