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

Move agentops.enums to their respective module #647

Merged
merged 1 commit into from
Jan 16, 2025
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
26 changes: 0 additions & 26 deletions agentops/enums.py

This file was deleted.

12 changes: 10 additions & 2 deletions agentops/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@

import traceback
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, Dict, List, Optional, Sequence, Union
from uuid import UUID, uuid4

from .enums import EventType
from .helpers import check_call_stack_for_agent_id, get_ISO_time


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


@dataclass
class Event:
"""
Abstract base class for events that will be recorded. Should not be instantiated directly.

event_type(str): The type of event. Defined in enums.EventType. Some values are 'llm', 'action', 'api', 'tool', 'error'.
event_type(str): The type of event. Defined in events.EventType. Some values are 'llm', 'action', 'api', 'tool', 'error'.
params(dict, optional): The parameters of the function containing the triggered event, e.g. {'x': 1} in example below
returns(str, optional): The return value of the function containing the triggered event, e.g. 2 in example below
init_timestamp(str): A timestamp indicating when the event began. Defaults to the time when this Event was instantiated.
Expand Down
2 changes: 1 addition & 1 deletion agentops/partners/autogen_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from autogen.logger.base_logger import BaseLogger, LLMConfig

from agentops.enums import EndState
from agentops.session import EndState

Check warning on line 14 in agentops/partners/autogen_logger.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/autogen_logger.py#L14

Added line #L14 was not covered by tests
from agentops.helpers import get_ISO_time

from agentops import LLMEvent, ToolEvent, ActionEvent
Expand Down
28 changes: 20 additions & 8 deletions agentops/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@
import threading
from datetime import datetime, timezone
from decimal import ROUND_HALF_UP, Decimal
from enum import Enum
from typing import Any, Dict, List, Optional, Sequence, Union
from uuid import UUID, uuid4

from opentelemetry import trace
from opentelemetry.context import attach, detach, set_value
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import ReadableSpan, TracerProvider
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
ConsoleSpanExporter,
SpanExporter,
SpanExportResult,
)
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter, SpanExporter, SpanExportResult
from termcolor import colored

from .config import Configuration
from .enums import EndState
from .event import ErrorEvent, Event
from .exceptions import ApiServerException
from .helpers import filter_unjsonable, get_ISO_time, safe_serialize
Expand Down Expand Up @@ -63,6 +58,23 @@
"""


class EndState(Enum):
"""
Enum representing the possible end states of a session.

Attributes:
SUCCESS: Indicates the session ended successfully.
FAIL: Indicates the session failed.
INDETERMINATE (default): Indicates the session ended with an indeterminate state.
This is the default state if not specified, e.g. if you forget to call end_session()
at the end of your program or don't pass it the end_state parameter
"""

SUCCESS = "Success"
FAIL = "Fail"
INDETERMINATE = "Indeterminate" # Default


class SessionExporter(SpanExporter):
"""
Manages publishing events for Session
Expand Down Expand Up @@ -290,7 +302,7 @@
return None

if not any(end_state == state.value for state in EndState):
logger.warning("Invalid end_state. Please use one of the EndState enums")
logger.warning("Invalid end_state. Please use one of the EndState")

Check warning on line 305 in agentops/session.py

View check run for this annotation

Codecov / codecov/patch

agentops/session.py#L305

Added line #L305 was not covered by tests
return None

try:
Expand Down
Loading