diff --git a/apps/langchain_agent/telephony_app.py b/apps/langchain_agent/telephony_app.py index 3c4a5a15f5..494b919b5e 100644 --- a/apps/langchain_agent/telephony_app.py +++ b/apps/langchain_agent/telephony_app.py @@ -6,7 +6,7 @@ from dotenv import load_dotenv from fastapi import FastAPI -from vocode.streaming.models.events import Event, EventType +from vocode.streaming.models.events import Event from vocode.streaming.models.transcript import TranscriptCompleteEvent from vocode.streaming.telephony.config_manager.redis_config_manager import RedisConfigManager from vocode.streaming.telephony.server.base import TelephonyServer @@ -23,14 +23,13 @@ class EventsManager(events_manager.EventsManager): def __init__(self): - super().__init__(subscriptions=[EventType.TRANSCRIPT_COMPLETE]) + super().__init__(subscriptions=["transcript_complete"]) async def handle_event(self, event: Event): - if event.type == EventType.TRANSCRIPT_COMPLETE: - transcript_complete_event = typing.cast(TranscriptCompleteEvent, event) + if isinstance(event, TranscriptCompleteEvent): add_transcript( - transcript_complete_event.conversation_id, - transcript_complete_event.transcript.to_string(), + event.conversation_id, + event.transcript.to_string(), ) diff --git a/tests/streaming/utils/test_events_manager.py b/tests/streaming/utils/test_events_manager.py index 4f03cfb41d..5ff96f583c 100644 --- a/tests/streaming/utils/test_events_manager.py +++ b/tests/streaming/utils/test_events_manager.py @@ -2,7 +2,7 @@ import pytest -from vocode.streaming.models.events import EventType, PhoneCallEndedEvent +from vocode.streaming.models.events import PhoneCallEndedEvent from vocode.streaming.utils.events_manager import EventsManager CONVERSATION_ID = "1" diff --git a/vocode/streaming/action/default_factory.py b/vocode/streaming/action/default_factory.py index 227ed56c42..b5fb757f7d 100644 --- a/vocode/streaming/action/default_factory.py +++ b/vocode/streaming/action/default_factory.py @@ -15,20 +15,20 @@ from vocode.streaming.models.actions import ActionConfig, ActionType CONVERSATION_ACTIONS: Dict[ActionType, Type[BaseAction]] = { - ActionType.END_CONVERSATION: EndConversation, - ActionType.RECORD_EMAIL: RecordEmail, - ActionType.WAIT: Wait, - ActionType.EXECUTE_EXTERNAL_ACTION: ExecuteExternalAction, + "action_end_conversation": EndConversation, + "action_record_email": RecordEmail, + "action_wait": Wait, + "action_external": ExecuteExternalAction, } VONAGE_ACTIONS: Dict[ActionType, Type[VonagePhoneConversationAction]] = { - ActionType.TRANSFER_CALL: VonageTransferCall, - ActionType.DTMF: VonageDTMF, + "action_transfer_call": VonageTransferCall, + "action_dtmf": VonageDTMF, } TWILIO_ACTIONS: Dict[ActionType, Type[TwilioPhoneConversationAction]] = { - ActionType.TRANSFER_CALL: TwilioTransferCall, - ActionType.DTMF: TwilioDTMF, + "action_transfer_call": TwilioTransferCall, + "action_dtmf": TwilioDTMF, } diff --git a/vocode/streaming/client_backend/conversation.py b/vocode/streaming/client_backend/conversation.py index b2bd0f7094..c1b0a45e1d 100644 --- a/vocode/streaming/client_backend/conversation.py +++ b/vocode/streaming/client_backend/conversation.py @@ -6,7 +6,7 @@ from vocode.streaming.agent.base_agent import BaseAgent from vocode.streaming.models.client_backend import InputAudioConfig, OutputAudioConfig -from vocode.streaming.models.events import Event, EventType +from vocode.streaming.models.events import Event from vocode.streaming.models.synthesizer import AzureSynthesizerConfig from vocode.streaming.models.transcriber import ( DeepgramTranscriberConfig, @@ -111,13 +111,12 @@ def __init__( self, output_device: WebsocketOutputDevice, ): - super().__init__(subscriptions=[EventType.TRANSCRIPT]) + super().__init__(subscriptions=["event_transcript"]) self.output_device = output_device async def handle_event(self, event: Event): - if event.type == EventType.TRANSCRIPT: - transcript_event = typing.cast(TranscriptEvent, event) - await self.output_device.send_transcript(transcript_event) + if isinstance(event, TranscriptEvent): + await self.output_device.send_transcript(event) # logger.debug(event.dict()) def restart(self, output_device: WebsocketOutputDevice): diff --git a/vocode/streaming/livekit/livekit_events_manager.py b/vocode/streaming/livekit/livekit_events_manager.py index 5daaefcc87..38ac1e0fd8 100644 --- a/vocode/streaming/livekit/livekit_events_manager.py +++ b/vocode/streaming/livekit/livekit_events_manager.py @@ -18,8 +18,8 @@ def __init__( self, subscriptions: List[EventType] = [], ): - if EventType.TRANSCRIPT not in subscriptions: - subscriptions.append(EventType.TRANSCRIPT) + if "event_transcript" not in subscriptions: + subscriptions.append("event_transcript") super().__init__(subscriptions) def attach_conversation(self, conversation: "LiveKitConversation"): diff --git a/vocode/streaming/models/actions.py b/vocode/streaming/models/actions.py index fc8cd90477..dcc7ea0e99 100644 --- a/vocode/streaming/models/actions.py +++ b/vocode/streaming/models/actions.py @@ -52,16 +52,15 @@ class PhraseBasedActionTrigger(_ActionTrigger): ] -class ActionType(str, Enum): - BASE = "action_base" - NYLAS_SEND_EMAIL = "action_nylas_send_email" - WAIT = "action_wait" - RECORD_EMAIL = "action_record_email" - END_CONVERSATION = "action_end_conversation" - EXECUTE_EXTERNAL_ACTION = "action_external" - - TRANSFER_CALL = "action_transfer_call" - DTMF = "action_dtmf" +ActionType = Literal[ + "action_nylas_send_email", + "action_wait", + "action_record_email", + "action_end_conversation", + "action_external", + "action_transfer_call", + "action_dtmf", +] ParametersType = TypeVar("ParametersType", bound=BaseModel) diff --git a/vocode/streaming/models/events.py b/vocode/streaming/models/events.py index 8d9e878640..dabede82ca 100644 --- a/vocode/streaming/models/events.py +++ b/vocode/streaming/models/events.py @@ -18,14 +18,15 @@ class Sender(str, Enum): CONFERENCE = "conference" -class EventType(str, Enum): - TRANSCRIPT = "event_transcript" - TRANSCRIPT_COMPLETE = "event_transcript_complete" - PHONE_CALL_CONNECTED = "event_phone_call_connected" - PHONE_CALL_ENDED = "event_phone_call_ended" - PHONE_CALL_DID_NOT_CONNECT = "event_phone_call_did_not_connect" - RECORDING = "event_recording" - ACTION = "event_action" +EventType = Literal[ + "event_transcript", + "event_transcript_complete", + "event_phone_call_connected", + "event_phone_call_ended", + "event_phone_call_did_not_connect", + "event_recording", + "event_action", +] class Event(AdaptiveObject, ABC): diff --git a/vocode/streaming/models/message.py b/vocode/streaming/models/message.py index cd6b6765a8..05abfa52bb 100644 --- a/vocode/streaming/models/message.py +++ b/vocode/streaming/models/message.py @@ -1,4 +1,3 @@ -from enum import Enum from typing import Literal, Optional from pydantic import BaseModel diff --git a/vocode/streaming/models/transcript.py b/vocode/streaming/models/transcript.py index 0f4806dbfd..e365d9dfc5 100644 --- a/vocode/streaming/models/transcript.py +++ b/vocode/streaming/models/transcript.py @@ -5,7 +5,7 @@ from pydantic import BaseModel, Field from vocode.streaming.models.actions import ActionInput, ActionOutput -from vocode.streaming.models.events import ActionEvent, Event, EventType, Sender +from vocode.streaming.models.events import ActionEvent, Event, Sender from vocode.streaming.utils.events_manager import EventsManager diff --git a/vocode/streaming/models/websocket.py b/vocode/streaming/models/websocket.py index 31fc69c956..18e36fed03 100644 --- a/vocode/streaming/models/websocket.py +++ b/vocode/streaming/models/websocket.py @@ -14,16 +14,6 @@ from .transcript import TranscriptEvent -class WebSocketMessageType(str, Enum): - BASE = "websocket_base" - START = "websocket_start" - AUDIO = "websocket_audio" - TRANSCRIPT = "websocket_transcript" - READY = "websocket_ready" - STOP = "websocket_stop" - AUDIO_CONFIG_START = "websocket_audio_config_start" - - class WebSocketMessage(AdaptiveObject, ABC): type: Any diff --git a/vocode/streaming/models/websocket_agent.py b/vocode/streaming/models/websocket_agent.py index baea63ab6b..d6e755400b 100644 --- a/vocode/streaming/models/websocket_agent.py +++ b/vocode/streaming/models/websocket_agent.py @@ -8,12 +8,6 @@ from vocode.streaming.models.agent import AgentConfig -class WebSocketAgentMessageType(str, Enum): - BASE = "websocket_agent_base" - TEXT = "websocket_agent_text" - STOP = "websocket_agent_stop" - - class WebSocketAgentMessage(AdaptiveObject, ABC): type: Any conversation_id: Optional[str] = None