Skip to content

Commit

Permalink
remove old Type enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ajar98 committed Jul 12, 2024
1 parent e7b9df3 commit 2331b1f
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 58 deletions.
11 changes: 5 additions & 6 deletions apps/langchain_agent/telephony_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
)


Expand Down
2 changes: 1 addition & 1 deletion tests/streaming/utils/test_events_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions vocode/streaming/action/default_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down
9 changes: 4 additions & 5 deletions vocode/streaming/client_backend/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions vocode/streaming/livekit/livekit_events_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
19 changes: 9 additions & 10 deletions vocode/streaming/models/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions vocode/streaming/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion vocode/streaming/models/message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from enum import Enum
from typing import Literal, Optional

from pydantic import BaseModel
Expand Down
2 changes: 1 addition & 1 deletion vocode/streaming/models/transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 0 additions & 10 deletions vocode/streaming/models/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions vocode/streaming/models/websocket_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2331b1f

Please sign in to comment.