Skip to content

Commit 5d7b655

Browse files
Merge pull request #445 from dvonthenen/get-model-support
Implements Models API
2 parents 47756df + b882f27 commit 5d7b655

File tree

14 files changed

+822
-7
lines changed

14 files changed

+822
-7
lines changed

deepgram/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@
160160
UsageFieldsResponse,
161161
Balance,
162162
BalancesResponse,
163+
ModelsResponse,
164+
ModelResponse,
163165
)
164166

165167
# selfhosted

deepgram/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@
164164
UsageFieldsResponse,
165165
Balance,
166166
BalancesResponse,
167+
ModelResponse,
168+
ModelsResponse,
167169
)
168170

169171
# on-prem
@@ -261,21 +263,21 @@ def __init__(
261263
@property
262264
def listen(self):
263265
"""
264-
Returns a ListenClient instance for interacting with Deepgram's transcription services.
266+
Returns a Listen dot-notation router for interacting with Deepgram's transcription services.
265267
"""
266268
return Listen(self._config)
267269

268270
@property
269271
def read(self):
270272
"""
271-
Returns a ReadClient instance for interacting with Deepgram's read services.
273+
Returns a Read dot-notation router for interacting with Deepgram's read services.
272274
"""
273275
return Read(self._config)
274276

275277
@property
276278
def speak(self):
277279
"""
278-
Returns a SpeakClient instance for interacting with Deepgram's speak services.
280+
Returns a Speak dot-notation router for interacting with Deepgram's speak services.
279281
"""
280282
return Speak(self._config)
281283

deepgram/clients/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@
168168
UsageFieldsResponse,
169169
Balance,
170170
BalancesResponse,
171+
ModelsResponse,
172+
ModelResponse,
171173
)
172174

173175
# selfhosted

deepgram/clients/manage/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@
2929
UsageFieldsResponse,
3030
Balance,
3131
BalancesResponse,
32+
ModelResponse,
33+
ModelsResponse,
3234
)
3335
from ...options import DeepgramClientOptions, ClientOptionsFromEnv

deepgram/clients/manage/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
UsageFieldsResponse as UsageFieldsResponseLatest,
3434
Balance as BalanceLatest,
3535
BalancesResponse as BalancesResponseLatest,
36+
ModelResponse as ModelResponseLatest,
37+
ModelsResponse as ModelsResponseLatest,
3638
)
3739

3840

@@ -66,7 +68,8 @@
6668
UsageFieldsResponse = UsageFieldsResponseLatest
6769
Balance = BalanceLatest
6870
BalancesResponse = BalancesResponseLatest
69-
71+
ModelResponse = ModelResponseLatest
72+
ModelsResponse = ModelsResponseLatest
7073

7174
# clients
7275
ManageClient = ManageClientLatest

deepgram/clients/manage/v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@
2929
UsageFieldsResponse,
3030
Balance,
3131
BalancesResponse,
32+
ModelResponse,
33+
ModelsResponse,
3234
)
3335
from ....options import DeepgramClientOptions, ClientOptionsFromEnv

deepgram/clients/manage/v1/async_client.py

Lines changed: 221 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
UsageFieldsResponse,
2828
Balance,
2929
BalancesResponse,
30+
ModelResponse,
31+
ModelsResponse,
3032
)
3133
from .options import (
3234
ProjectOptions,
35+
ModelOptions,
3336
KeyOptions,
3437
ScopeOptions,
3538
InviteOptions,
@@ -41,7 +44,7 @@
4144

4245
class AsyncManageClient(
4346
AbstractAsyncRestClient
44-
): # pylint: disable=too-many-public-methods
47+
): # pylint: disable=too-many-public-methods,too-many-lines
4548
"""
4649
A client for managing Deepgram projects and associated resources via the Deepgram API.
4750
@@ -239,6 +242,223 @@ async def delete_project(
239242
self._logger.debug("ManageClient.delete_project LEAVE")
240243
return res
241244

245+
async def list_project_models(
246+
self,
247+
project_id: str,
248+
options: Optional[Union[Dict, ModelOptions]] = None,
249+
timeout: Optional[httpx.Timeout] = None,
250+
addons: Optional[Dict] = None,
251+
headers: Optional[Dict] = None,
252+
**kwargs,
253+
) -> ModelsResponse:
254+
"""
255+
Please see get_project_models.
256+
"""
257+
return await self.get_project_models(
258+
project_id,
259+
options=options,
260+
timeout=timeout,
261+
addons=addons,
262+
headers=headers,
263+
**kwargs,
264+
)
265+
266+
async def get_project_models(
267+
self,
268+
project_id: str,
269+
options: Optional[Union[Dict, ModelOptions]] = None,
270+
timeout: Optional[httpx.Timeout] = None,
271+
addons: Optional[Dict] = None,
272+
headers: Optional[Dict] = None,
273+
**kwargs,
274+
) -> ModelsResponse:
275+
"""
276+
Gets models for a specific project.
277+
278+
Reference:
279+
https://developers.deepgram.com/reference/get-project
280+
https://developers.deepgram.com/reference/get-model
281+
282+
Args:
283+
project_id (str): The ID of the project.
284+
timeout (Optional[httpx.Timeout]): The timeout setting for the request.
285+
addons (Optional[Dict]): Additional options for the request.
286+
headers (Optional[Dict]): Headers to include in the request.
287+
**kwargs: Additional keyword arguments.
288+
289+
Returns:
290+
ModelsResponse: A response object containing the model details.
291+
"""
292+
self._logger.debug("ManageClient.get_project_models ENTER")
293+
294+
if options is None:
295+
options = ModelOptions()
296+
297+
url = f"{self._config.url}/{self._endpoint}/{project_id}/models"
298+
self._logger.info("url: %s", url)
299+
self._logger.info("project_id: %s", project_id)
300+
if isinstance(options, ModelOptions):
301+
self._logger.info("ModelOptions switching class -> dict")
302+
options = options.to_dict()
303+
self._logger.info("options: %s", options)
304+
self._logger.info("addons: %s", addons)
305+
self._logger.info("headers: %s", headers)
306+
result = await self.get(
307+
url, json=options, timeout=timeout, addons=addons, headers=headers, **kwargs
308+
)
309+
self._logger.info("json: %s", result)
310+
res = ModelsResponse.from_json(result)
311+
self._logger.verbose("result: %s", res)
312+
self._logger.notice("get_project_models succeeded")
313+
self._logger.debug("ManageClient.get_project_models LEAVE")
314+
return res
315+
316+
async def get_project_model(
317+
self,
318+
project_id: str,
319+
model_id: str,
320+
timeout: Optional[httpx.Timeout] = None,
321+
addons: Optional[Dict] = None,
322+
headers: Optional[Dict] = None,
323+
**kwargs,
324+
) -> ModelResponse:
325+
"""
326+
Gets a single model for a specific project.
327+
328+
Reference:
329+
https://developers.deepgram.com/reference/get-project
330+
https://developers.deepgram.com/reference/get-model
331+
332+
Args:
333+
project_id (str): The ID of the project.
334+
model_id (str): The ID of the model.
335+
timeout (Optional[httpx.Timeout]): The timeout setting for the request.
336+
addons (Optional[Dict]): Additional options for the request.
337+
headers (Optional[Dict]): Headers to include in the request.
338+
**kwargs: Additional keyword arguments.
339+
340+
Returns:
341+
ModelResponse: A response object containing the model details.
342+
"""
343+
self._logger.debug("ManageClient.get_project_model ENTER")
344+
url = f"{self._config.url}/{self._endpoint}/{project_id}/models/{model_id}"
345+
self._logger.info("url: %s", url)
346+
self._logger.info("project_id: %s", project_id)
347+
self._logger.info("model_id: %s", model_id)
348+
self._logger.info("addons: %s", addons)
349+
self._logger.info("headers: %s", headers)
350+
result = await self.get(
351+
url, timeout=timeout, addons=addons, headers=headers, **kwargs
352+
)
353+
self._logger.info("json: %s", result)
354+
res = ModelResponse.from_json(result)
355+
self._logger.verbose("result: %s", res)
356+
self._logger.notice("get_project_model succeeded")
357+
self._logger.debug("ManageClient.get_project_model LEAVE")
358+
return res
359+
360+
# models
361+
async def list_models(
362+
self,
363+
options: Optional[Union[Dict, ModelOptions]] = None,
364+
timeout: Optional[httpx.Timeout] = None,
365+
addons: Optional[Dict] = None,
366+
headers: Optional[Dict] = None,
367+
**kwargs,
368+
) -> ModelsResponse:
369+
"""
370+
Please see get_models for more information.
371+
"""
372+
return await self.get_models(
373+
options=options, timeout=timeout, addons=addons, headers=headers, **kwargs
374+
)
375+
376+
async def get_models(
377+
self,
378+
options: Optional[Union[Dict, ModelOptions]] = None,
379+
timeout: Optional[httpx.Timeout] = None,
380+
addons: Optional[Dict] = None,
381+
headers: Optional[Dict] = None,
382+
**kwargs,
383+
) -> ModelsResponse:
384+
"""
385+
Gets all models available.
386+
387+
Reference:
388+
https://developers.deepgram.com/reference/get-model
389+
390+
Args:
391+
timeout (Optional[httpx.Timeout]): The timeout setting for the request.
392+
addons (Optional[Dict]): Additional options for the request.
393+
headers (Optional[Dict]): Headers to include in the request.
394+
**kwargs: Additional keyword arguments.
395+
396+
Returns:
397+
ModelsResponse: A response object containing the model details.
398+
"""
399+
self._logger.debug("ManageClient.get_models ENTER")
400+
401+
if options is None:
402+
options = ModelOptions()
403+
404+
url = f"{self._config.url}/v1/models"
405+
self._logger.info("url: %s", url)
406+
if isinstance(options, ModelOptions):
407+
self._logger.info("ModelOptions switching class -> dict")
408+
options = options.to_dict()
409+
self._logger.info("options: %s", options)
410+
self._logger.info("addons: %s", addons)
411+
self._logger.info("headers: %s", headers)
412+
result = await self.get(
413+
url, json=options, timeout=timeout, addons=addons, headers=headers, **kwargs
414+
)
415+
self._logger.info("result: %s", result)
416+
res = ModelsResponse.from_json(result)
417+
self._logger.verbose("result: %s", res)
418+
self._logger.notice("get_models succeeded")
419+
self._logger.debug("ManageClient.get_models LEAVE")
420+
return res
421+
422+
async def get_model(
423+
self,
424+
model_id: str,
425+
timeout: Optional[httpx.Timeout] = None,
426+
addons: Optional[Dict] = None,
427+
headers: Optional[Dict] = None,
428+
**kwargs,
429+
) -> ModelResponse:
430+
"""
431+
Gets information for a specific model.
432+
433+
Reference:
434+
https://developers.deepgram.com/reference/get-model
435+
436+
Args:
437+
model_id (str): The ID of the model.
438+
timeout (Optional[httpx.Timeout]): The timeout setting for the request.
439+
addons (Optional[Dict]): Additional options for the request.
440+
headers (Optional[Dict]): Headers to include in the request.
441+
**kwargs: Additional keyword arguments.
442+
443+
Returns:
444+
ModelResponse: A response object containing the model details.
445+
"""
446+
self._logger.debug("ManageClient.get_model ENTER")
447+
url = f"{self._config.url}/v1/models/{model_id}"
448+
self._logger.info("url: %s", url)
449+
self._logger.info("model_id: %s", model_id)
450+
self._logger.info("addons: %s", addons)
451+
self._logger.info("headers: %s", headers)
452+
result = await self.get(
453+
url, timeout=timeout, addons=addons, headers=headers, **kwargs
454+
)
455+
self._logger.info("result: %s", result)
456+
res = ModelResponse.from_json(result)
457+
self._logger.verbose("result: %s", res)
458+
self._logger.notice("get_model succeeded")
459+
self._logger.debug("ManageClient.get_model LEAVE")
460+
return res
461+
242462
# keys
243463
async def list_keys(
244464
self,

0 commit comments

Comments
 (0)