diff --git a/src/pipecat/processors/aggregators/llm_response_universal.py b/src/pipecat/processors/aggregators/llm_response_universal.py index 3305efb50..ff3f271d2 100644 --- a/src/pipecat/processors/aggregators/llm_response_universal.py +++ b/src/pipecat/processors/aggregators/llm_response_universal.py @@ -1150,8 +1150,7 @@ class LLMAssistantAggregator(LLMContextAggregator): thought = concatenate_aggregated_text(self._thought_aggregation) - if self._thought_append_to_context: - assert self._thought_llm is not None, "llm is required when append_to_context is True" + if self._thought_append_to_context and self._thought_llm is not None: self._context.add_message( LLMSpecificMessage( llm=self._thought_llm, diff --git a/src/pipecat/transports/base_output.py b/src/pipecat/transports/base_output.py index 7b2448d7b..00aea18ca 100644 --- a/src/pipecat/transports/base_output.py +++ b/src/pipecat/transports/base_output.py @@ -701,15 +701,16 @@ class BaseOutputTransport(FrameProcessor): # Notify the bot stopped speaking upstream if necessary. await self._bot_stopped_speaking() - async def with_mixer(vad_stop_secs: float) -> AsyncGenerator[Frame, None]: - assert self._mixer is not None + async def with_mixer( + mixer: BaseAudioMixer, vad_stop_secs: float + ) -> AsyncGenerator[Frame, None]: last_frame_time = 0 silence = b"\x00" * self._audio_chunk_size while True: try: frame = self._audio_queue.get_nowait() if isinstance(frame, OutputAudioRawFrame): - frame.audio = await self._mixer.mix(frame.audio) + frame.audio = await mixer.mix(frame.audio) last_frame_time = time.time() yield frame self._audio_queue.task_done() @@ -720,7 +721,7 @@ class BaseOutputTransport(FrameProcessor): await self._bot_stopped_speaking() # Generate an audio frame with only the mixer's part. frame = OutputAudioRawFrame( - audio=await self._mixer.mix(silence), + audio=await mixer.mix(silence), sample_rate=self._sample_rate, num_channels=self._params.audio_out_channels, ) @@ -732,7 +733,7 @@ class BaseOutputTransport(FrameProcessor): await asyncio.sleep(0) if self._mixer: - return with_mixer(BOT_VAD_STOP_SECS) + return with_mixer(self._mixer, BOT_VAD_STOP_SECS) else: return without_mixer(BOT_VAD_STOP_SECS) diff --git a/src/pipecat/transports/websocket/client.py b/src/pipecat/transports/websocket/client.py index f8dc51d75..6d44d0d51 100644 --- a/src/pipecat/transports/websocket/client.py +++ b/src/pipecat/transports/websocket/client.py @@ -141,8 +141,8 @@ class WebsocketClientSession: self._client_task_handler(), f"{self._transport_name}::WebsocketClientSession::_client_task_handler", ) - assert self._websocket is not None - await self._callbacks.on_connected(self._websocket) + if self._websocket: + await self._callbacks.on_connected(self._websocket) except TimeoutError: logger.error(f"Timeout connecting to {self._uri}") @@ -193,17 +193,18 @@ class WebsocketClientSession: async def _client_task_handler(self): """Handle incoming messages from the WebSocket connection.""" + if not self._websocket: + return + + websocket = self._websocket try: - assert self._websocket is not None - websocket = self._websocket # Handle incoming messages async for message in websocket: await self._callbacks.on_message(websocket, message) except Exception as e: logger.error(f"{self} exception receiving data: {e.__class__.__name__} ({e})") - if self._websocket: - await self._callbacks.on_disconnected(self._websocket) + await self._callbacks.on_disconnected(websocket) def __str__(self): """String representation of the WebSocket client session."""