Inline _build_live_options into _connect in DeepgramSTTService and DeepgramSageMakerSTTService since it's trivial and only called from one place

This commit is contained in:
Paul Kompfner
2026-02-26 09:42:15 -05:00
parent 3c20eda8bf
commit c184ac09b8
2 changed files with 10 additions and 26 deletions

View File

@@ -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 = {

View File

@@ -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):