From c184ac09b8323571a4269182e3f9af9fe6d70c1b Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Thu, 26 Feb 2026 09:42:15 -0500 Subject: [PATCH] Inline `_build_live_options` into `_connect` in `DeepgramSTTService` and `DeepgramSageMakerSTTService` since it's trivial and only called from one place --- src/pipecat/services/deepgram/stt.py | 19 +++++-------------- .../services/deepgram/stt_sagemaker.py | 17 +++++------------ 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/pipecat/services/deepgram/stt.py b/src/pipecat/services/deepgram/stt.py index b193f899d..59107d0f8 100644 --- a/src/pipecat/services/deepgram/stt.py +++ b/src/pipecat/services/deepgram/stt.py @@ -372,17 +372,6 @@ class DeepgramSTTService(STTService): await self._connection.send(audio) yield None - def _build_live_options(self) -> LiveOptions: - """Build a ``LiveOptions`` from stored settings and sample rate. - - Returns: - A fully-populated ``LiveOptions`` ready for the Deepgram SDK. - """ - opts: dict[str, Any] = self._settings.live_options.to_dict() - opts["sample_rate"] = self.sample_rate - - return LiveOptions(**opts) - async def _connect(self): logger.debug("Connecting to Deepgram") @@ -403,9 +392,11 @@ class DeepgramSTTService(STTService): self._on_utterance_end, ) - if not await self._connection.start( - options=self._build_live_options(), addons=self._addons - ): + live_options = LiveOptions( + **{**self._settings.live_options.to_dict(), "sample_rate": self.sample_rate} + ) + + if not await self._connection.start(options=live_options, addons=self._addons): await self.push_error(error_msg=f"Unable to connect to Deepgram") else: headers = { diff --git a/src/pipecat/services/deepgram/stt_sagemaker.py b/src/pipecat/services/deepgram/stt_sagemaker.py index 6f91906b7..ee2121bec 100644 --- a/src/pipecat/services/deepgram/stt_sagemaker.py +++ b/src/pipecat/services/deepgram/stt_sagemaker.py @@ -336,17 +336,6 @@ class DeepgramSageMakerSTTService(STTService): yield ErrorFrame(error=f"Unknown error occurred: {e}") yield None - def _build_live_options(self) -> LiveOptions: - """Build a ``LiveOptions`` from stored settings and sample rate. - - Returns: - A fully-populated ``LiveOptions`` ready for the Deepgram SDK. - """ - opts: dict[str, Any] = self._settings.live_options.to_dict() - opts["sample_rate"] = self.sample_rate - - return LiveOptions(**opts) - async def _connect(self): """Connect to the SageMaker endpoint and start the BiDi session. @@ -356,9 +345,13 @@ class DeepgramSageMakerSTTService(STTService): """ logger.debug("Connecting to Deepgram on SageMaker...") + live_options = LiveOptions( + **{**self._settings.live_options.to_dict(), "sample_rate": self.sample_rate} + ) + # Build query string from live_options, converting booleans to strings query_params = {} - for key, value in self._build_live_options().to_dict().items(): + for key, value in live_options.to_dict().items(): if value is not None: # Convert boolean values to lowercase strings for Deepgram API if isinstance(value, bool):