Skip to content

Commit 6eb043a

Browse files
Merge pull request #246 from dvonthenen/expose-missing-options
Expose Missing Options on Prerecorded/Live
2 parents 1333f2f + 5220025 commit 6eb043a

File tree

7 files changed

+130
-10
lines changed

7 files changed

+130
-10
lines changed

deepgram/clients/live/v1/async_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
1+
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
22
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33
# SPDX-License-Identifier: MIT
44
import asyncio
@@ -50,6 +50,11 @@ async def start(self, options: LiveOptions = None, addons: dict = None, **kwargs
5050
self.logger.info("addons: %s", addons)
5151
self.logger.info("options: %s", kwargs)
5252

53+
if options is not None and not options.check():
54+
self.logger.error("options.check failed")
55+
self.logger.debug("AsyncLiveClient.start LEAVE")
56+
raise DeepgramError("Fatal transcription options error")
57+
5358
self.options = options
5459
if addons is not None:
5560
self.__dict__.update(addons)

deepgram/clients/live/v1/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
1+
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
22
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33
# SPDX-License-Identifier: MIT
44
import json
@@ -57,6 +57,11 @@ def start(self, options: LiveOptions = None, addons: dict = None, **kwargs):
5757
self.logger.info("addon: %s", addons)
5858
self.logger.info("options: %s", kwargs)
5959

60+
if options is not None and not options.check():
61+
self.logger.error("options.check failed")
62+
self.logger.debug("LiveClient.start LEAVE")
63+
raise DeepgramError("Fatal transcription options error")
64+
6065
self.options = options
6166
if addons is not None:
6267
self.__dict__.update(addons)

deepgram/clients/live/v1/options.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
1+
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
22
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33
# SPDX-License-Identifier: MIT
44

55
from dataclasses import dataclass
66
from dataclasses_json import dataclass_json
77
from typing import List, Optional
8+
import logging, verboselogs
89

910

1011
@dataclass_json
@@ -17,11 +18,16 @@ class LiveOptions:
1718
https://developers.deepgram.com/reference/streaming
1819
"""
1920

21+
alternatives: Optional[int] = None
2022
callback: Optional[str] = None
23+
callback_method: Optional[str] = None
2124
channels: Optional[int] = None
2225
diarize: Optional[bool] = None
26+
diarize_version: Optional[str] = None
2327
encoding: Optional[str] = None
2428
endpointing: Optional[str] = None
29+
extra: Optional[str] = None
30+
filler_words: Optional[bool] = None
2531
interim_results: Optional[bool] = None
2632
keywords: Optional[str] = None
2733
language: Optional[str] = None
@@ -43,3 +49,23 @@ class LiveOptions:
4349
def __getitem__(self, key):
4450
_dict = self.to_dict()
4551
return _dict[key]
52+
53+
def check(self):
54+
verboselogs.install()
55+
logger = logging.getLogger(__name__)
56+
logger.addHandler(logging.StreamHandler())
57+
prev = logger.level
58+
logger.setLevel(logging.ERROR)
59+
60+
if self.numerals:
61+
logger.error(
62+
"WARNING: Numerals is deprecated. Will be removed in a future version. Please use smart_format instead."
63+
)
64+
if self.tier:
65+
logger.error(
66+
"WARNING: Tier is deprecated. Will be removed in a future version."
67+
)
68+
69+
logger.setLevel(prev)
70+
71+
return True

deepgram/clients/prerecorded/errors.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
1+
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
22
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33
# SPDX-License-Identifier: MIT
44

55

6+
class DeepgramError(Exception):
7+
"""
8+
Exception raised for unknown errors related to the Deepgram API.
9+
10+
Attributes:
11+
message (str): The error message describing the exception.
12+
"""
13+
14+
def __init__(self, message: str):
15+
super().__init__(message)
16+
self.name = "DeepgramError"
17+
self.message = message
18+
19+
def __str__(self):
20+
return f"{self.name}: {self.message}"
21+
22+
623
class DeepgramTypeError(Exception):
724
"""
825
Exception raised for unknown errors related to unknown Types for Transcription.
926
1027
Attributes:
1128
message (str): The error message describing the exception.
1229
"""
30+
1331
def __init__(self, message: str):
1432
super().__init__(message)
1533
self.name = "DeepgramTypeError"

deepgram/clients/prerecorded/v1/async_client.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
1+
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
22
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33
# SPDX-License-Identifier: MIT
44

@@ -8,7 +8,7 @@
88
import logging, verboselogs
99

1010
from ...abstract_async_client import AbstractAsyncRestClient
11-
from ..errors import DeepgramTypeError
11+
from ..errors import DeepgramError, DeepgramTypeError
1212
from ..helpers import is_buffer_source, is_readstream_source, is_url_source
1313
from ..source import UrlSource, FileSource
1414

@@ -68,6 +68,11 @@ async def transcribe_url(
6868
self.logger.debug("PreRecordedClient.transcribe_url LEAVE")
6969
raise DeepgramTypeError("Unknown transcription source type")
7070

71+
if options is not None and not options.check():
72+
self.logger.error("options.check failed")
73+
self.logger.debug("PreRecordedClient.transcribe_url LEAVE")
74+
raise DeepgramError("Fatal transcription options error")
75+
7176
self.logger.info("url: %s", url)
7277
self.logger.info("source: %s", source)
7378
if isinstance(options, PrerecordedOptions):
@@ -123,6 +128,11 @@ async def transcribe_url_callback(
123128
self.logger.debug("PreRecordedClient.transcribe_url_callback LEAVE")
124129
raise DeepgramTypeError("Unknown transcription source type")
125130

131+
if options is not None and not options.check():
132+
self.logger.error("options.check failed")
133+
self.logger.debug("PreRecordedClient.transcribe_url_callback LEAVE")
134+
raise DeepgramError("Fatal transcription options error")
135+
126136
self.logger.info("url: %s", url)
127137
self.logger.info("source: %s", source)
128138
if isinstance(options, PrerecordedOptions):
@@ -181,6 +191,11 @@ async def transcribe_file(
181191
self.logger.debug("PreRecordedClient.transcribe_file LEAVE")
182192
raise DeepgramTypeError("Unknown transcription source type")
183193

194+
if options is not None and not options.check():
195+
self.logger.error("options.check failed")
196+
self.logger.debug("PreRecordedClient.transcribe_file LEAVE")
197+
raise DeepgramError("Fatal transcription options error")
198+
184199
self.logger.info("url: %s", url)
185200
if isinstance(options, PrerecordedOptions):
186201
self.logger.info("PrerecordedOptions switching class -> json")
@@ -237,6 +252,11 @@ async def transcribe_file_callback(
237252
self.logger.debug("PreRecordedClient.transcribe_file_callback LEAVE")
238253
raise DeepgramTypeError("Unknown transcription source type")
239254

255+
if options is not None and not options.check():
256+
self.logger.error("options.check failed")
257+
self.logger.debug("PreRecordedClient.transcribe_file_callback LEAVE")
258+
raise DeepgramError("Fatal transcription options error")
259+
240260
self.logger.info("url: %s", url)
241261
if isinstance(options, PrerecordedOptions):
242262
self.logger.info("PrerecordedOptions switching class -> json")

deepgram/clients/prerecorded/v1/client.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
1+
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
22
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33
# SPDX-License-Identifier: MIT
44

@@ -7,7 +7,7 @@
77
import json
88

99
from ...abstract_sync_client import AbstractSyncRestClient
10-
from ..errors import DeepgramTypeError
10+
from ..errors import DeepgramError, DeepgramTypeError
1111
from ..helpers import is_buffer_source, is_readstream_source, is_url_source
1212
from ..source import UrlSource, FileSource
1313

@@ -67,6 +67,11 @@ def transcribe_url(
6767
self.logger.debug("PreRecordedClient.transcribe_url LEAVE")
6868
raise DeepgramTypeError("Unknown transcription source type")
6969

70+
if options is not None and not options.check():
71+
self.logger.error("options.check failed")
72+
self.logger.debug("PreRecordedClient.transcribe_url LEAVE")
73+
raise DeepgramError("Fatal transcription options error")
74+
7075
self.logger.info("url: %s", url)
7176
self.logger.info("source: %s", source)
7277
if isinstance(options, PrerecordedOptions):
@@ -122,6 +127,11 @@ def transcribe_url_callback(
122127
self.logger.debug("PreRecordedClient.transcribe_url_callback LEAVE")
123128
raise DeepgramTypeError("Unknown transcription source type")
124129

130+
if options is not None and not options.check():
131+
self.logger.error("options.check failed")
132+
self.logger.debug("PreRecordedClient.transcribe_url_callback LEAVE")
133+
raise DeepgramError("Fatal transcription options error")
134+
125135
self.logger.info("url: %s", url)
126136
self.logger.info("source: %s", source)
127137
if isinstance(options, PrerecordedOptions):
@@ -180,6 +190,11 @@ def transcribe_file(
180190
self.logger.debug("PreRecordedClient.transcribe_file LEAVE")
181191
raise DeepgramTypeError("Unknown transcription source type")
182192

193+
if options is not None and not options.check():
194+
self.logger.error("options.check failed")
195+
self.logger.debug("PreRecordedClient.transcribe_file LEAVE")
196+
raise DeepgramError("Fatal transcription options error")
197+
183198
self.logger.info("url: %s", url)
184199
if isinstance(options, PrerecordedOptions):
185200
self.logger.info("PrerecordedOptions switching class -> json")
@@ -236,6 +251,11 @@ def transcribe_file_callback(
236251
self.logger.debug("PreRecordedClient.transcribe_file_callback LEAVE")
237252
raise DeepgramTypeError("Unknown transcription source type")
238253

254+
if options is not None and not options.check():
255+
self.logger.error("options.check failed")
256+
self.logger.debug("PreRecordedClient.transcribe_file_callback LEAVE")
257+
raise DeepgramError("Fatal transcription options error")
258+
239259
self.logger.info("url: %s", url)
240260
if isinstance(options, PrerecordedOptions):
241261
self.logger.info("PrerecordedOptions switching class -> json")

deepgram/clients/prerecorded/v1/options.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
1+
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
22
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33
# SPDX-License-Identifier: MIT
44

55
from dataclasses import dataclass
66
from dataclasses_json import dataclass_json
77
from typing import Union, List, TypedDict, Optional
8+
import logging, verboselogs
89

910

1011
@dataclass_json
@@ -19,13 +20,18 @@ class PrerecordedOptions:
1920

2021
alternatives: Optional[int] = None
2122
callback: Optional[str] = None
22-
callback_method: Optional[bool] = None
23+
callback_method: Optional[str] = None
2324
detect_entities: Optional[bool] = None
2425
detect_language: Optional[bool] = None
2526
detect_topics: Optional[bool] = None
2627
diarize: Optional[bool] = None
28+
diarize_version: Optional[str] = None
29+
dictation: Optional[bool] = None
30+
extra: Optional[str] = None
31+
filler_words: Optional[bool] = None
2732
keywords: Optional[Union[list, str]] = None
2833
language: Optional[str] = None
34+
measurements: Optional[bool] = None
2935
model: Optional[str] = None
3036
multichannel: Optional[bool] = None
3137
numerals: Optional[bool] = None
@@ -46,3 +52,23 @@ class PrerecordedOptions:
4652
def __getitem__(self, key):
4753
_dict = self.to_dict()
4854
return _dict[key]
55+
56+
def check(self):
57+
verboselogs.install()
58+
logger = logging.getLogger(__name__)
59+
logger.addHandler(logging.StreamHandler())
60+
prev = logger.level
61+
logger.setLevel(logging.ERROR)
62+
63+
if self.numerals:
64+
logger.error(
65+
"WARNING: Numerals is deprecated. Will be removed in a future version. Please use smart_format instead."
66+
)
67+
if self.tier:
68+
logger.error(
69+
"WARNING: Tier is deprecated. Will be removed in a future version."
70+
)
71+
72+
logger.setLevel(prev)
73+
74+
return True

0 commit comments

Comments
 (0)