Agent: Rename IEventSerializer -> IAgentEventSerializer

This commit is contained in:
Shreya Malviya 2022-09-16 12:18:50 +05:30 committed by Mike Salvatore
parent ae073de766
commit 0e2b165c15
4 changed files with 11 additions and 9 deletions

View File

@ -1,5 +1,5 @@
from .consts import EVENT_TYPE_FIELD
from .i_event_serializer import IEventSerializer, JSONSerializable
from .i_event_serializer import IAgentEventSerializer, JSONSerializable
from .event_serializer_registry import EventSerializerRegistry
from .pydantic_event_serializer import PydanticEventSerializer
from .register import register_common_agent_event_serializers

View File

@ -1,6 +1,6 @@
from typing import Type, Union
from common.event_serializers import IEventSerializer
from common.event_serializers import IAgentEventSerializer
from common.events import AbstractAgentEvent
@ -22,18 +22,20 @@ class EventSerializerRegistry:
self._registry = {}
def __setitem__(
self, event_class: Type[AbstractAgentEvent], event_serializer: IEventSerializer
self, event_class: Type[AbstractAgentEvent], event_serializer: IAgentEventSerializer
):
if not issubclass(event_class, AbstractAgentEvent):
raise TypeError(f"Event class must be of type: {AbstractAgentEvent.__name__}")
if not isinstance(event_serializer, IEventSerializer):
raise TypeError(f"Event serializer must be of type: {IEventSerializer.__name__}")
if not isinstance(event_serializer, IAgentEventSerializer):
raise TypeError(f"Event serializer must be of type: {IAgentEventSerializer.__name__}")
self._registry[event_class] = event_serializer
self._registry[event_class.__name__] = event_serializer
def __getitem__(self, event_class: Union[str, Type[AbstractAgentEvent]]) -> IEventSerializer:
def __getitem__(
self, event_class: Union[str, Type[AbstractAgentEvent]]
) -> IAgentEventSerializer:
if not (isinstance(event_class, str) or issubclass(event_class, AbstractAgentEvent)):
raise TypeError(
f"Registry get key {event_class} must be of type: {AbstractAgentEvent.__name__} or "

View File

@ -14,7 +14,7 @@ JSONSerializable = Union[ # type: ignore[misc]
]
class IEventSerializer(ABC):
class IAgentEventSerializer(ABC):
"""
Manages serialization and deserialization of events
"""

View File

@ -4,14 +4,14 @@ from typing import Generic, Type, TypeVar
from common.events import AbstractAgentEvent
from common.utils.code_utils import del_key
from . import EVENT_TYPE_FIELD, IEventSerializer, JSONSerializable
from . import EVENT_TYPE_FIELD, IAgentEventSerializer, JSONSerializable
logger = logging.getLogger(__name__)
T = TypeVar("T", bound=AbstractAgentEvent)
class PydanticEventSerializer(IEventSerializer, Generic[T]):
class PydanticEventSerializer(IAgentEventSerializer, Generic[T]):
def __init__(self, event_class: Type[T]):
self._event_class = event_class