From ddffae56f47005fd0029095193298ad71d50ffdd Mon Sep 17 00:00:00 2001 From: Michael Louis Date: Thu, 14 Nov 2024 18:53:55 -0500 Subject: [PATCH 1/6] Added support for custom deepgram base url --- .../livekit/plugins/deepgram/stt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py index 8c4d0a682..0224f5cb9 100644 --- a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py +++ b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py @@ -118,6 +118,8 @@ def __init__( profanity_filter: bool = False, api_key: str | None = None, http_session: aiohttp.ClientSession | None = None, + base_url: str = BASE_URL, + base_url_ws: str = BASE_URL_WS ) -> None: """ Create a new instance of Deepgram STT. @@ -132,6 +134,9 @@ def __init__( ) ) + self._base_url = base_url + self._base_url_ws = base_url_ws + api_key = api_key or os.environ.get("DEEPGRAM_API_KEY") if api_key is None: raise ValueError("Deepgram API key is required") @@ -549,5 +554,5 @@ def _to_deepgram_url(opts: dict, *, websocket: bool = False) -> str: # lowercase bools opts = {k: str(v).lower() if isinstance(v, bool) else v for k, v in opts.items()} - base_url = BASE_URL_WS if websocket else BASE_URL + base_url = self._base_url_ws if websocket else self._base_url return f"{base_url}?{urlencode(opts, doseq=True)}" From 9bf2af86122d91dfd0449a80d72506d5bfcb2e46 Mon Sep 17 00:00:00 2001 From: Michael Louis Date: Thu, 14 Nov 2024 19:04:14 -0500 Subject: [PATCH 2/6] Fixed class error --- .../livekit/plugins/deepgram/stt.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py index 0224f5cb9..4066c5015 100644 --- a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py +++ b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py @@ -194,6 +194,8 @@ async def _recognize_impl( "smart_format": config.smart_format, "keywords": self._opts.keywords, "profanity_filter": config.profanity_filter, + "base_url": self._base_url, + "base_url_ws": self._base_url_ws } if config.language: recognize_config["language"] = config.language @@ -308,6 +310,8 @@ async def _run(self, max_retry: int) -> None: "filler_words": self._opts.filler_words, "keywords": self._opts.keywords, "profanity_filter": self._opts.profanity_filter, + "base_url": self._base_url, + "base_url_ws": self._base_url_ws } if self._opts.language: @@ -554,5 +558,5 @@ def _to_deepgram_url(opts: dict, *, websocket: bool = False) -> str: # lowercase bools opts = {k: str(v).lower() if isinstance(v, bool) else v for k, v in opts.items()} - base_url = self._base_url_ws if websocket else self._base_url + base_url = opts.get("base_url_ws") if websocket else opts.get("base_url") return f"{base_url}?{urlencode(opts, doseq=True)}" From e47351a699d7f8186d5a2aad552688b77c5fd2d6 Mon Sep 17 00:00:00 2001 From: Michael Louis Date: Thu, 14 Nov 2024 19:14:12 -0500 Subject: [PATCH 3/6] Run ruff --- .../livekit/plugins/deepgram/stt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py index 4066c5015..a0b42a2d4 100644 --- a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py +++ b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py @@ -118,8 +118,8 @@ def __init__( profanity_filter: bool = False, api_key: str | None = None, http_session: aiohttp.ClientSession | None = None, - base_url: str = BASE_URL, - base_url_ws: str = BASE_URL_WS + base_url: str = BASE_URL, + base_url_ws: str = BASE_URL_WS, ) -> None: """ Create a new instance of Deepgram STT. @@ -195,7 +195,7 @@ async def _recognize_impl( "keywords": self._opts.keywords, "profanity_filter": config.profanity_filter, "base_url": self._base_url, - "base_url_ws": self._base_url_ws + "base_url_ws": self._base_url_ws, } if config.language: recognize_config["language"] = config.language @@ -311,7 +311,7 @@ async def _run(self, max_retry: int) -> None: "keywords": self._opts.keywords, "profanity_filter": self._opts.profanity_filter, "base_url": self._base_url, - "base_url_ws": self._base_url_ws + "base_url_ws": self._base_url_ws, } if self._opts.language: From cddfe3dc2d006a75cbe47862e5afa1db1df8d9ed Mon Sep 17 00:00:00 2001 From: milo157 <43028253+milo157@users.noreply.github.com> Date: Thu, 14 Nov 2024 19:16:21 -0500 Subject: [PATCH 4/6] Create olive-kangaroos-yawn.md --- .changeset/olive-kangaroos-yawn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/olive-kangaroos-yawn.md diff --git a/.changeset/olive-kangaroos-yawn.md b/.changeset/olive-kangaroos-yawn.md new file mode 100644 index 000000000..553940297 --- /dev/null +++ b/.changeset/olive-kangaroos-yawn.md @@ -0,0 +1,5 @@ +--- +"livekit-plugins-deepgram": patch +--- + +Added support for custom deepgram base url From 3c7373528df3b037f0b6aeae384742de946b3da9 Mon Sep 17 00:00:00 2001 From: Michael Louis Date: Thu, 14 Nov 2024 19:18:03 -0500 Subject: [PATCH 5/6] Removed unneccessary lines --- .../livekit/plugins/deepgram/stt.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py index a0b42a2d4..8886fbf6d 100644 --- a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py +++ b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py @@ -134,9 +134,6 @@ def __init__( ) ) - self._base_url = base_url - self._base_url_ws = base_url_ws - api_key = api_key or os.environ.get("DEEPGRAM_API_KEY") if api_key is None: raise ValueError("Deepgram API key is required") @@ -194,8 +191,8 @@ async def _recognize_impl( "smart_format": config.smart_format, "keywords": self._opts.keywords, "profanity_filter": config.profanity_filter, - "base_url": self._base_url, - "base_url_ws": self._base_url_ws, + "base_url": base_url, + "base_url_ws": base_url_ws, } if config.language: recognize_config["language"] = config.language @@ -310,8 +307,8 @@ async def _run(self, max_retry: int) -> None: "filler_words": self._opts.filler_words, "keywords": self._opts.keywords, "profanity_filter": self._opts.profanity_filter, - "base_url": self._base_url, - "base_url_ws": self._base_url_ws, + "base_url": base_url, + "base_url_ws": base_url_ws, } if self._opts.language: From 183fb7ddb37783b804e7e04302a2b30aa41cf74c Mon Sep 17 00:00:00 2001 From: Michael Louis Date: Thu, 14 Nov 2024 19:21:34 -0500 Subject: [PATCH 6/6] Fixed issues --- .../livekit/plugins/deepgram/stt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py index 8886fbf6d..51bc6ef30 100644 --- a/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py +++ b/livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py @@ -191,8 +191,8 @@ async def _recognize_impl( "smart_format": config.smart_format, "keywords": self._opts.keywords, "profanity_filter": config.profanity_filter, - "base_url": base_url, - "base_url_ws": base_url_ws, + "base_url": self.base_url, + "base_url_ws": self.base_url_ws, } if config.language: recognize_config["language"] = config.language @@ -307,8 +307,8 @@ async def _run(self, max_retry: int) -> None: "filler_words": self._opts.filler_words, "keywords": self._opts.keywords, "profanity_filter": self._opts.profanity_filter, - "base_url": base_url, - "base_url_ws": base_url_ws, + "base_url": self.base_url, + "base_url_ws": self.base_url_ws, } if self._opts.language: