Skip to content

Commit

Permalink
write tests for how the transcript looks (#352)
Browse files Browse the repository at this point in the history
* starts tests scaffolding

* Format transcript properly and add test

* Add test using ActionInput instead of TwilioPhoneCallActionInput

* Format transcript manually

* No more underscore

---------

Co-authored-by: Hayden Housen <[email protected]>
  • Loading branch information
ajar98 and HHousen authored Aug 11, 2023
1 parent 6c726e7 commit 074045b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 8 deletions.
96 changes: 96 additions & 0 deletions tests/streaming/models/test_transcript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import asyncio
from vocode.streaming.models.actions import (
ActionInput,
ActionOutput,
TwilioPhoneCallActionInput,
)
from vocode.streaming.models.transcript import ActionStart, ActionFinish
from vocode.streaming.models.events import Sender
from vocode.streaming.models.transcript import Message
from vocode.streaming.models.transcript import Transcript
from vocode.streaming.action.nylas_send_email import (
NylasSendEmailActionConfig,
NylasSendEmailParameters,
NylasSendEmailResponse,
)


def test_transcript_to_string():
transcript = Transcript(
event_logs=[
Message(sender=Sender.BOT, text="What up"),
Message(
sender=Sender.HUMAN,
text="Send me an email you bot. My email is [email protected]",
),
ActionStart(
action_type="action_nylas_send_email",
action_input=TwilioPhoneCallActionInput(
action_config=NylasSendEmailActionConfig(),
conversation_id="123",
params=NylasSendEmailParameters(
recipient_email="[email protected]",
body="What up",
subject="This is the bot",
),
_user_message_tracker=asyncio.Event(),
twilio_sid="123",
),
),
ActionFinish(
action_type="action_nylas_send_email",
action_output=ActionOutput(
action_type="action_nylas_send_email",
response=NylasSendEmailResponse(success=True),
),
),
]
)

assert (
transcript.to_string()
== """BOT: What up
HUMAN: Send me an email you bot. My email is [email protected]
ACTION_WORKER: params={'recipient_email': '[email protected]', 'body': 'What up', 'subject': 'This is the bot'}
ACTION_WORKER: action_type='action_nylas_send_email' response={'success': True}"""
)


def test_transcript_to_string_no_phone_input():
transcript = Transcript(
event_logs=[
Message(sender=Sender.BOT, text="What up"),
Message(
sender=Sender.HUMAN,
text="Send me an email you bot. My email is [email protected]",
),
ActionStart(
action_type="action_nylas_send_email",
action_input=ActionInput(
action_config=NylasSendEmailActionConfig(),
conversation_id="123",
params=NylasSendEmailParameters(
recipient_email="[email protected]",
body="What up",
subject="This is the bot",
),
_user_message_tracker=asyncio.Event(),
),
),
ActionFinish(
action_type="action_nylas_send_email",
action_output=ActionOutput(
action_type="action_nylas_send_email",
response=NylasSendEmailResponse(success=True),
),
),
]
)

assert (
transcript.to_string()
== """BOT: What up
HUMAN: Send me an email you bot. My email is [email protected]
ACTION_WORKER: params={'recipient_email': '[email protected]', 'body': 'What up', 'subject': 'This is the bot'}
ACTION_WORKER: action_type='action_nylas_send_email' response={'success': True}"""
)
12 changes: 4 additions & 8 deletions vocode/streaming/models/transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class ActionStart(EventLog):

def to_string(self, include_timestamp: bool = False):
if include_timestamp:
return (
f"{Sender.ACTION_WORKER.name}: {self.action_input} ({self.timestamp})"
)
return f"{Sender.ACTION_WORKER.name}: {self.action_input}"
return f"{Sender.ACTION_WORKER.name}: params={self.action_input.params.dict()} ({self.timestamp})"
return f"{Sender.ACTION_WORKER.name}: params={self.action_input.params.dict()}"


class ActionFinish(EventLog):
Expand All @@ -45,10 +43,8 @@ class ActionFinish(EventLog):

def to_string(self, include_timestamp: bool = False):
if include_timestamp:
return (
f"{Sender.ACTION_WORKER.name}: {self.action_output} ({self.timestamp})"
)
return f"{Sender.ACTION_WORKER.name}: {self.action_output}"
return f"{Sender.ACTION_WORKER.name}: action_type='{self.action_type}' response={self.action_output.response.dict()} ({self.timestamp})"
return f"{Sender.ACTION_WORKER.name}: action_type='{self.action_type}' response={self.action_output.response.dict()}"


class Transcript(BaseModel):
Expand Down

0 comments on commit 074045b

Please sign in to comment.