Skip to content

Commit

Permalink
better typing in StreamingConversation (vocodedev#329)
Browse files Browse the repository at this point in the history
* better typing

* better filler audio condition
  • Loading branch information
ajar98 authored Aug 2, 2023
1 parent a563443 commit f96166b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions vocode/streaming/streaming_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from vocode.streaming.agent.bot_sentiment_analyser import (
BotSentimentAnalyser,
)
from vocode.streaming.agent.chat_gpt_agent import ChatGPTAgent
from vocode.streaming.models.actions import ActionInput
from vocode.streaming.models.transcript import Transcript, TranscriptCompleteEvent
from vocode.streaming.models.message import BaseMessage
Expand All @@ -23,7 +24,7 @@
from vocode.streaming.utils.events_manager import EventsManager
from vocode.streaming.utils.goodbye_model import GoodbyeModel

from vocode.streaming.models.agent import FillerAudioConfig
from vocode.streaming.models.agent import ChatGPTAgentConfig, FillerAudioConfig
from vocode.streaming.models.synthesizer import (
SentimentConfig,
)
Expand Down Expand Up @@ -171,18 +172,21 @@ def __init__(
self.filler_audio_started_event: Optional[threading.Event] = None

async def wait_for_filler_audio_to_finish(self):
if not self.filler_audio_started_event.set():
if (
self.filler_audio_started_event is None
or not self.filler_audio_started_event.set()
):
self.conversation.logger.debug(
"Not waiting for filler audio to finish since we didn't send any chunks"
)
return
if self.interruptible_event and isinstance(
self.interruptible_event, InterruptibleAgentResponseEvent
):
await self.interruptible_event.agent_response_tracker()
await self.interruptible_event.agent_response_tracker.wait()

def interrupt_current_filler_audio(self):
self.interruptible_event and self.interruptible_event.interrupt()
return self.interruptible_event and self.interruptible_event.interrupt()

async def process(self, item: InterruptibleAgentResponseEvent[FillerAudio]):
try:
Expand Down Expand Up @@ -641,7 +645,7 @@ async def terminate(self):
await self.synthesizer.tear_down()
self.logger.debug("Terminating agent")
if (
hasattr(self.agent.agent_config, "vector_db_config")
isinstance(self.agent, ChatGPTAgent)
and self.agent.agent_config.vector_db_config
):
# Shutting down the vector db should be done in the agent's terminate method,
Expand Down

0 comments on commit f96166b

Please sign in to comment.