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

Adding serialization functionality and multion examples #236

Merged
merged 26 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
15 changes: 13 additions & 2 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from .config import Configuration, ConfigurationError
from .llm_tracker import LlmTracker
from termcolor import colored
from typing import Tuple


@singleton
Expand Down Expand Up @@ -75,7 +76,7 @@ def __init__(
tags: Optional[List[str]] = None,
override: Optional[bool] = None, # Deprecated
instrument_llm_calls=True,
auto_start_session=True,
auto_start_session=False,
bboynton97 marked this conversation as resolved.
Show resolved Hide resolved
inherited_session_id: Optional[str] = None,
skip_auto_end_session: Optional[bool] = False,
):
Expand Down Expand Up @@ -133,7 +134,7 @@ def __init__(

def _check_for_partner_frameworks(
self, instrument_llm_calls, auto_start_session
) -> tuple[bool, bool]:
) -> Tuple[bool, bool]:
partner_frameworks = get_partner_frameworks()
for framework in partner_frameworks.keys():
if framework in sys.modules:
Expand Down Expand Up @@ -260,6 +261,10 @@ def _record_event_sync(self, func, event_name, *args, **kwargs):
returns = list(returns)

event.returns = returns

if hasattr(returns, "screenshot"):
event.screenshot = returns.screenshot

event.end_timestamp = get_ISO_time()
self.record(event)

Expand Down Expand Up @@ -300,6 +305,12 @@ async def _record_event_async(self, func, event_name, *args, **kwargs):
returns = list(returns)

event.returns = returns

# NOTE: Will likely remove in future since this is tightly coupled. Adding it to see how useful we find it for now
# TODO: check if screenshot is the url string we expect it to be? And not e.g. "True"
HowieG marked this conversation as resolved.
Show resolved Hide resolved
if hasattr(returns, "screenshot"):
event.screenshot = returns.screenshot

event.end_timestamp = get_ISO_time()
self.record(event)

Expand Down
2 changes: 0 additions & 2 deletions agentops/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .client import Client
from .event import Event
import inspect
import functools

Expand All @@ -16,7 +15,6 @@ def record_function(event_name: str):
"""

def decorator(func):

if inspect.iscoroutinefunction(func):

@functools.wraps(func)
Expand Down
20 changes: 15 additions & 5 deletions agentops/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,29 @@ def default(o):
return o.model_dump_json()
elif hasattr(o, "to_json"):
return o.to_json()
elif hasattr(o, "json"):
return o.json()
elif hasattr(o, "to_dict"):
return o.to_dict()
elif hasattr(o, "dict"):
return o.dict()
else:
return f"<<non-serializable: {type(o).__qualname__}>>"

def remove_none_values(value):
"""Recursively remove keys with None values from dictionaries."""
def remove_unwanted_items(value):
"""Recursively remove self key and None/... values from dictionaries so they aren't serialized"""
if isinstance(value, dict):
return {k: remove_none_values(v) for k, v in value.items() if v is not None}
return {
k: remove_unwanted_items(v)
for k, v in value.items()
if v is not None and v is not ... and k != "self"
}
elif isinstance(value, list):
return [remove_none_values(item) for item in value]
return [remove_unwanted_items(item) for item in value]
else:
return value

cleaned_obj = remove_none_values(obj)
cleaned_obj = remove_unwanted_items(obj)
return json.dumps(cleaned_obj, default=default)


Expand Down
88 changes: 88 additions & 0 deletions examples/multion/browse.ipynb

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions examples/multion/retrieve.ipynb

Large diffs are not rendered by default.

184 changes: 184 additions & 0 deletions examples/multion/step.ipynb

Large diffs are not rendered by default.

Loading