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

ENG-68 event types #100

Merged
merged 42 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0a501bf
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
753c9ea
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
2c85d19
WIP. Refactoring Event to an ABC
HowieG Feb 29, 2024
c49dd41
WIP. Saving state of abstract Event to try another way
HowieG Mar 1, 2024
44fdab6
Events working end to end MVP
HowieG Mar 1, 2024
996197b
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
9f61902
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
5f3f1a9
WIP. Refactoring Event to an ABC
HowieG Feb 29, 2024
9aae2aa
WIP. Saving state of abstract Event to try another way
HowieG Mar 1, 2024
948873f
Events working end to end MVP
HowieG Mar 1, 2024
c3feab4
removed comment
HowieG Mar 5, 2024
e39c25e
saving notebook
HowieG Mar 5, 2024
2c2236c
Merge branch 'eng-68-event-types' of https://github.com/AgentOps-AI/a…
HowieG Mar 5, 2024
aa0a411
cleanup
HowieG Mar 5, 2024
0dcc44b
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
fa3e8e0
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
b2abab0
WIP. Refactoring Event to an ABC
HowieG Feb 29, 2024
cb96b22
WIP. Saving state of abstract Event to try another way
HowieG Mar 1, 2024
51bb6cc
Events working end to end MVP
HowieG Mar 1, 2024
8491043
removed comment
HowieG Mar 5, 2024
bac3519
saving notebook
HowieG Mar 5, 2024
0eeaf4b
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
085e79b
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
cf9fd1d
WIP. Refactoring Event to an ABC
HowieG Feb 29, 2024
e8fcc31
WIP. Saving state of abstract Event to try another way
HowieG Mar 1, 2024
1f271dc
Events working end to end MVP
HowieG Mar 1, 2024
ea6ba65
cleanup
HowieG Mar 5, 2024
9685c61
Merge branch 'eng-68-event-types' of https://github.com/AgentOps-AI/a…
HowieG Mar 5, 2024
60ee84d
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
c97c221
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
4730c00
WIP. Refactoring Event to an ABC
HowieG Feb 29, 2024
9762121
WIP. Saving state of abstract Event to try another way
HowieG Mar 1, 2024
45b70ef
Events working end to end MVP
HowieG Mar 1, 2024
6b6134f
saving notebook
HowieG Mar 5, 2024
215fcbe
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
d0b4d4c
WIP. Refactoring Event to an ABC
HowieG Feb 28, 2024
57a1d81
WIP. Refactoring Event to an ABC
HowieG Feb 29, 2024
e46355d
WIP. Saving state of abstract Event to try another way
HowieG Mar 1, 2024
7aea847
Events working end to end MVP
HowieG Mar 1, 2024
03b803d
cleanup
HowieG Mar 5, 2024
de22fee
Merge branch 'eng-68-event-types' of https://github.com/AgentOps-AI/a…
HowieG Mar 5, 2024
f22ade7
cleanup
HowieG Mar 6, 2024
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
6 changes: 4 additions & 2 deletions agentops/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# agentops/__init__.py

from .client import Client
from .event import Event
from .event import ActionEvent, ErrorEvent, LLMEvent, ToolEvent
from .logger import AgentOpsLogger
from .helpers import Models
from .enums import Models
36 changes: 36 additions & 0 deletions agentops/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from enum import Enum


class EventType(Enum):
LLM = "llms"
ACTION = "actions"
API = "apis"
TOOL = "tools"
ERROR = "errors"


class Result(Enum):
SUCCESS = "Success"
FAIL = "Fail"
INDETERMINATE = "Indeterminate"


class ActionType(Enum):
ACTION = "action"
LLM = "llm"
TOOL = "tool"
ERROR = "error"


class Models(Enum):
GPT_3_5_TURBO = "gpt-3.5-turbo"
GPT_3_5_TURBO_0301 = "gpt-3.5-turbo-0301"
GPT_3_5_TURBO_0613 = "gpt-3.5-turbo-0613"
GPT_3_5_TURBO_16K = "gpt-3.5-turbo-16k"
GPT_3_5_TURBO_16K_0613 = "gpt-3.5-turbo-16k-0613"
GPT_4_0314 = "gpt-4-0314"
GPT_4 = "gpt-4"
GPT_4_32K = "gpt-4-32k"
GPT_4_32K_0314 = "gpt-4-32k-0314"
GPT_4_0613 = "gpt-4-0613"
TEXT_EMBEDDING_ADA_002 = "text-embedding-ada-002"
112 changes: 58 additions & 54 deletions agentops/event.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,66 @@
"""
AgentOps events.

Classes:
Data Class:
Event: Represents discrete events to be recorded.
"""
from .helpers import get_ISO_time, Models
from typing import Optional, List, Dict, Any
from pydantic import Field

from dataclasses import dataclass, field
from typing import List, Optional
from .helpers import get_ISO_time
from .enums import EventType, Models
from uuid import UUID


@dataclass
class Event:
"""
Represents a discrete event to be recorded.
"""

def __init__(self, event_type: str,
params: Optional[Dict[str, Any]] = None,
returns: Optional[Dict[str, Any]] = None,
result: str = Field("Indeterminate",
description="Result of the operation",
pattern="^(Success|Fail|Indeterminate)$"),
action_type: Optional[str] = Field("action",
description="Type of action that the user is recording",
pattern="^(action|api|llm|screenshot|tool|error)$"),
model: Optional[Models] = None,
prompt: Optional[str] = None,
tags: Optional[List[str]] = None,
init_timestamp: Optional[str] = None,
screenshot: Optional[str] = None,
prompt_tokens: Optional[int] = None,
completion_tokens: Optional[int] = None
):
self.event_type = event_type
self.params = params
self.returns = returns
self.result = result
self.tags = tags
self.action_type = action_type
self.model = model
self.prompt = prompt
self.end_timestamp = get_ISO_time()
self.init_timestamp = init_timestamp if init_timestamp else self.end_timestamp
self.screenshot = screenshot
self.prompt_tokens = prompt_tokens
self.completion_tokens = completion_tokens

def __str__(self):
return str({
"event_type": self.event_type,
"params": self.params,
"returns": self.returns,
"action_type": self.action_type,
"result": self.result,
"model": self.model,
"prompt": self.prompt,
"tags": self.tags,
"screenshot": self.screenshot,
"init_timestamp": self.init_timestamp,
"prompt_tokens": self.prompt_tokens,
"completion_tokens": self.completion_tokens,
})
event_type: str # EventType.ENUM.value
tags: Optional[List[str]] = None
init_timestamp: Optional[str] = field(default_factory=get_ISO_time)
end_timestamp: str = field(default_factory=get_ISO_time)


@dataclass
class ActionEvent(Event):
event_type: str = EventType.ACTION.value
# TODO: Should not be optional, but non-default argument 'agent_id' follows default argument error
agent_id: Optional[UUID] = None
action_type: Optional[str] = None
detail: Optional[str] = None
logs: Optional[str] = None
screenshot: Optional[str] = None

# May be needed if we keep Optional for agent_id
# def __post_init__(self):
# if self.agent_id is None:
# raise ValueError("agent_id is required for ActionEvent")


@dataclass
class ErrorEvent(Event):
event_type: str = EventType.ERROR.value
# Note: 'type' is a reserved keyword in Python, hence 'error_type'
error_type: Optional[str] = None
code: Optional[str] = None
details: Optional[str] = None
logs: Optional[str] = None


@dataclass
class LLMEvent(Event):
event_type: str = EventType.LLM.value
thread_id: Optional[UUID] = None
model: Optional[Models] = None
prompt: Optional[str] = None
prompt_tokens: Optional[int] = None
completion_tokens: Optional[int] = None


@dataclass
class ToolEvent(Event):
event_type: str = EventType.TOOL.value
agent_id: Optional[UUID] = None
name: Optional[str] = None
inputs: Optional[str] = None
outputs: Optional[str] = None
logs: Optional[str] = None
16 changes: 0 additions & 16 deletions agentops/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Dict
from enum import Enum
import time
from datetime import datetime
import json
Expand Down Expand Up @@ -45,17 +43,3 @@ def default(o):
else:
return f"<<non-serializable: {type(o).__qualname__}>>"
return json.dumps(obj, default=default)


class Models(Enum):
GPT_3_5_TURBO = "gpt-3.5-turbo"
GPT_3_5_TURBO_0301 = "gpt-3.5-turbo-0301"
GPT_3_5_TURBO_0613 = "gpt-3.5-turbo-0613"
GPT_3_5_TURBO_16K = "gpt-3.5-turbo-16k"
GPT_3_5_TURBO_16K_0613 = "gpt-3.5-turbo-16k-0613"
GPT_4_0314 = "gpt-4-0314"
GPT_4 = "gpt-4"
GPT_4_32K = "gpt-4-32k"
GPT_4_32K_0314 = "gpt-4-32k-0314"
GPT_4_0613 = "gpt-4-0613"
TEXT_EMBEDDING_ADA_002 = "text-embedding-ada-002"