Skip to content

Commit c7dc37c

Browse files
committed
chore(tests): update snapshots
1 parent ab20831 commit c7dc37c

File tree

26 files changed

+143
-111
lines changed

26 files changed

+143
-111
lines changed

deepgram/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,28 +446,30 @@ def __init__(
446446

447447
# Handle credential extraction from config first
448448
if api_key == "" and access_token == "" and config is not None:
449-
self._logger.info(
450-
"Attempting to set credentials from config object")
449+
self._logger.info("Attempting to set credentials from config object")
451450
api_key = config.api_key
452451
access_token = config.access_token
453452

454453
# Fallback to environment variables if no explicit credentials provided
455454
# Prioritize API key for backward compatibility
456455
if api_key == "" and access_token == "":
457456
self._logger.info(
458-
"Attempting to get credentials from environment variables")
457+
"Attempting to get credentials from environment variables"
458+
)
459459
api_key = os.getenv("DEEPGRAM_API_KEY", "")
460460
if api_key == "":
461461
access_token = os.getenv("DEEPGRAM_ACCESS_TOKEN", "")
462462

463463
# Log warnings for missing credentials
464464
if api_key == "" and access_token == "":
465465
self._logger.warning(
466-
"WARNING: Neither API key nor access token is provided")
466+
"WARNING: Neither API key nor access token is provided"
467+
)
467468

468469
if config is None: # Use default configuration
469470
self._config = DeepgramClientOptions(
470-
api_key=api_key, access_token=access_token)
471+
api_key=api_key, access_token=access_token
472+
)
471473
else:
472474
# Update config with credentials only if we have valid credentials
473475
# This ensures empty strings don't overwrite existing config credentials

deepgram/clients/agent/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@
9595
Input = LatestInput
9696
Output = LatestOutput
9797
Audio = LatestAudio
98-
Endpoint = LatestEndpoint
98+
Endpoint = LatestEndpoint

deepgram/clients/auth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
from .client import AsyncAuthRESTClient
77
from .client import (
88
GrantTokenResponse,
9-
)
9+
)

deepgram/clients/auth/v1/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
from .async_client import AsyncAuthRESTClient
66
from .response import (
77
GrantTokenResponse,
8-
)
8+
)

deepgram/clients/auth/v1/async_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ async def grant_token(self):
4242

4343
url = f"{self._config.url}/{self._endpoint}"
4444
self._logger.info("url: %s", url)
45-
result = await self.post(url, headers={"Authorization": f"Token {self._config.api_key}"})
45+
result = await self.post(
46+
url, headers={"Authorization": f"Token {self._config.api_key}"}
47+
)
4648
self._logger.info("json: %s", result)
4749
res = GrantTokenResponse.from_json(result)
4850
self._logger.verbose("result: %s", res)

deepgram/clients/auth/v1/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def grant_token(self):
4242

4343
url = f"{self._config.url}/{self._endpoint}"
4444
self._logger.info("url: %s", url)
45-
result = self.post(url, headers={"Authorization": f"Token {self._config.api_key}"})
45+
result = self.post(
46+
url, headers={"Authorization": f"Token {self._config.api_key}"}
47+
)
4648
self._logger.info("json: %s", result)
4749
res = GrantTokenResponse.from_json(result)
4850
self._logger.verbose("result: %s", res)

deepgram/clients/auth/v1/response.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
BaseResponse,
1010
)
1111

12+
1213
@dataclass
1314
class GrantTokenResponse(BaseResponse):
1415
"""
1516
The response object for the authentication grant token endpoint.
1617
"""
18+
1719
access_token: str = field(
18-
metadata=dataclass_config(field_name='access_token'),
20+
metadata=dataclass_config(field_name="access_token"),
1921
default="",
2022
)
2123
expires_in: int = field(
22-
metadata=dataclass_config(field_name='expires_in'),
24+
metadata=dataclass_config(field_name="expires_in"),
2325
default=30,
24-
)
26+
)

deepgram/options.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DeepgramClientOptions: # pylint: disable=too-many-instance-attributes
3030
"""
3131

3232
_logger: verboselogs.VerboseLogger
33+
headers: Dict[str, str]
3334
_inspect_listen: bool = False
3435
_inspect_speak: bool = False
3536

@@ -82,7 +83,7 @@ def set_apikey(self, api_key: str):
8283
"""
8384
self.api_key = api_key
8485
self.access_token = "" # Clear access token when setting API key
85-
self._update_headers(headers=getattr(self, '_custom_headers', {}))
86+
self._update_headers(headers=getattr(self, "_custom_headers", {}))
8687

8788
def set_access_token(self, access_token: str):
8889
"""
@@ -93,7 +94,7 @@ def set_access_token(self, access_token: str):
9394
"""
9495
self.access_token = access_token
9596
self.api_key = "" # Clear API key when setting access token
96-
self._update_headers(headers=getattr(self, '_custom_headers', {}))
97+
self._update_headers(headers=getattr(self, "_custom_headers", {}))
9798

9899
def _get_url(self, url) -> str:
99100
if not re.match(r"^https?://", url, re.IGNORECASE):
@@ -102,12 +103,15 @@ def _get_url(self, url) -> str:
102103

103104
def _update_headers(self, headers: Optional[Dict] = None):
104105
# Initialize headers if not already set, otherwise preserve existing custom headers
105-
if not hasattr(self, 'headers') or self.headers is None:
106+
if not hasattr(self, "headers") or self.headers is None:
106107
self.headers = {}
107108
else:
108109
# Preserve existing custom headers but allow auth headers to be updated
109-
existing_custom_headers = {k: v for k, v in self.headers.items()
110-
if k not in ['Accept', 'Authorization', 'User-Agent']}
110+
existing_custom_headers = {
111+
k: v
112+
for k, v in self.headers.items()
113+
if k not in ["Accept", "Authorization", "User-Agent"]
114+
}
111115
self.headers = existing_custom_headers
112116

113117
self.headers["Accept"] = "application/json"
@@ -119,9 +123,9 @@ def _update_headers(self, headers: Optional[Dict] = None):
119123
elif self.access_token:
120124
self.headers["Authorization"] = f"Bearer {self.access_token}"
121125

122-
self.headers[
123-
"User-Agent"
124-
] = f"@deepgram/sdk/{__version__} python/{sys.version_info[1]}.{sys.version_info[2]}"
126+
self.headers["User-Agent"] = (
127+
f"@deepgram/sdk/{__version__} python/{sys.version_info[1]}.{sys.version_info[2]}"
128+
)
125129
# Overwrite / add any headers that were passed in
126130
if headers:
127131
self.headers.update(headers)
@@ -138,8 +142,7 @@ def is_auto_flush_reply_enabled(self) -> bool:
138142
"""
139143
is_auto_flush_reply_enabled: Returns True if the client is configured to auto-flush for listen.
140144
"""
141-
auto_flush_reply_delta = float(
142-
self.options.get("auto_flush_reply_delta", 0))
145+
auto_flush_reply_delta = float(self.options.get("auto_flush_reply_delta", 0))
143146
return (
144147
isinstance(auto_flush_reply_delta, numbers.Number)
145148
and auto_flush_reply_delta > 0
@@ -149,8 +152,7 @@ def is_auto_flush_speak_enabled(self) -> bool:
149152
"""
150153
is_auto_flush_speak_enabled: Returns True if the client is configured to auto-flush for speak.
151154
"""
152-
auto_flush_speak_delta = float(
153-
self.options.get("auto_flush_speak_delta", 0))
155+
auto_flush_speak_delta = float(self.options.get("auto_flush_speak_delta", 0))
154156
return (
155157
isinstance(auto_flush_speak_delta, numbers.Number)
156158
and auto_flush_speak_delta > 0
@@ -206,10 +208,10 @@ def __init__(
206208

207209
# Require at least one form of authentication
208210
if api_key == "" and access_token == "":
209-
self._logger.critical(
210-
"Neither Deepgram API KEY nor ACCESS TOKEN is set")
211+
self._logger.critical("Neither Deepgram API KEY nor ACCESS TOKEN is set")
211212
raise DeepgramApiKeyError(
212-
"Neither Deepgram API KEY nor ACCESS TOKEN is set")
213+
"Neither Deepgram API KEY nor ACCESS TOKEN is set"
214+
)
213215

214216
if url == "":
215217
url = os.getenv("DEEPGRAM_HOST", "api.deepgram.com")
@@ -258,8 +260,7 @@ def __init__(
258260
for x in range(0, 20):
259261
header = os.getenv(f"DEEPGRAM_HEADER_{x}", None)
260262
if header is not None:
261-
headers[header] = os.getenv(
262-
f"DEEPGRAM_HEADER_VALUE_{x}", None)
263+
headers[header] = os.getenv(f"DEEPGRAM_HEADER_VALUE_{x}", None)
263264
self._logger.debug(
264265
"Deepgram header %s is set with value %s",
265266
header,
@@ -276,8 +277,7 @@ def __init__(
276277
for x in range(0, 20):
277278
param = os.getenv(f"DEEPGRAM_PARAM_{x}", None)
278279
if param is not None:
279-
options[param] = os.getenv(
280-
f"DEEPGRAM_PARAM_VALUE_{x}", None)
280+
options[param] = os.getenv(f"DEEPGRAM_PARAM_VALUE_{x}", None)
281281
self._logger.debug(
282282
"Deepgram option %s is set with value %s", param, options[param]
283283
)
@@ -288,5 +288,10 @@ def __init__(
288288
options = None
289289

290290
super().__init__(
291-
api_key=api_key, access_token=access_token, url=url, verbose=verbose, headers=headers, options=options
291+
api_key=api_key,
292+
access_token=access_token,
293+
url=url,
294+
verbose=verbose,
295+
headers=headers,
296+
options=options,
292297
)

examples/agent/arbitrary_keys/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from deepgram.clients.agent.v1.websocket.options import SettingsOptions
2424

25+
2526
def main():
2627
try:
2728
# Initialize the Voice Agent
@@ -64,17 +65,17 @@ def main():
6465

6566
def on_welcome(self, welcome, **kwargs):
6667
print(f"Welcome message received: {welcome}")
67-
with open("chatlog.txt", 'a') as chatlog:
68+
with open("chatlog.txt", "a") as chatlog:
6869
chatlog.write(f"Welcome message: {welcome}\n")
6970

7071
def on_settings_applied(self, settings_applied, **kwargs):
7172
print(f"Settings applied: {settings_applied}")
72-
with open("chatlog.txt", 'a') as chatlog:
73+
with open("chatlog.txt", "a") as chatlog:
7374
chatlog.write(f"Settings applied: {settings_applied}\n")
7475

7576
def on_error(self, error, **kwargs):
7677
print(f"Error received: {error}")
77-
with open("chatlog.txt", 'a') as chatlog:
78+
with open("chatlog.txt", "a") as chatlog:
7879
chatlog.write(f"Error: {error}\n")
7980

8081
# Register handlers
@@ -93,11 +94,14 @@ def on_error(self, error, **kwargs):
9394

9495
# Cleanup
9596
connection.finish()
96-
print("Finished! You should see an error for the arbitrary key - scroll up and you can see it is included in the settings payload.")
97+
print(
98+
"Finished! You should see an error for the arbitrary key - scroll up and you can see it is included in the settings payload."
99+
)
97100
print("If you do not see that error, this example has failed.")
98101

99102
except Exception as e:
100103
print(f"Error: {str(e)}")
101104

105+
102106
if __name__ == "__main__":
103107
main()

examples/agent/async_simple/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ async def on_unhandled(self, unhandled, **kwargs):
116116
options.agent.listen.provider.type = "deepgram"
117117
options.agent.language = "en"
118118

119-
120119
print("\n\nPress Enter to stop...\n\n")
121120
if await dg_connection.start(options) is False:
122121
print("Failed to start connection")

0 commit comments

Comments
 (0)