Skip to content

Commit

Permalink
Implements Models API
Browse files Browse the repository at this point in the history
  • Loading branch information
dvonthenen committed Jul 31, 2024
1 parent 22dc7d0 commit b372254
Show file tree
Hide file tree
Showing 11 changed files with 623 additions and 6 deletions.
2 changes: 2 additions & 0 deletions deepgram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
UsageFieldsResponse,
Balance,
BalancesResponse,
ModelsResponse,
ModelResponse,
)

# selfhosted
Expand Down
8 changes: 5 additions & 3 deletions deepgram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
UsageFieldsResponse,
Balance,
BalancesResponse,
ModelResponse,
ModelsResponse,
)

# on-prem
Expand Down Expand Up @@ -261,21 +263,21 @@ def __init__(
@property
def listen(self):
"""
Returns a ListenClient instance for interacting with Deepgram's transcription services.
Returns a Listen dot-notation router for interacting with Deepgram's transcription services.
"""
return Listen(self._config)

@property
def read(self):
"""
Returns a ReadClient instance for interacting with Deepgram's read services.
Returns a Read dot-notation router for interacting with Deepgram's read services.
"""
return Read(self._config)

@property
def speak(self):
"""
Returns a SpeakClient instance for interacting with Deepgram's speak services.
Returns a Speak dot-notation router for interacting with Deepgram's speak services.
"""
return Speak(self._config)

Expand Down
2 changes: 2 additions & 0 deletions deepgram/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@
UsageFieldsResponse,
Balance,
BalancesResponse,
ModelsResponse,
ModelResponse,
)

# selfhosted
Expand Down
2 changes: 2 additions & 0 deletions deepgram/clients/manage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
UsageFieldsResponse,
Balance,
BalancesResponse,
ModelResponse,
ModelsResponse,
)
from ...options import DeepgramClientOptions, ClientOptionsFromEnv
5 changes: 4 additions & 1 deletion deepgram/clients/manage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
UsageFieldsResponse as UsageFieldsResponseLatest,
Balance as BalanceLatest,
BalancesResponse as BalancesResponseLatest,
ModelResponse as ModelResponseLatest,
ModelsResponse as ModelsResponseLatest,
)


Expand Down Expand Up @@ -66,7 +68,8 @@
UsageFieldsResponse = UsageFieldsResponseLatest
Balance = BalanceLatest
BalancesResponse = BalancesResponseLatest

ModelResponse = ModelResponseLatest
ModelsResponse = ModelsResponseLatest

# clients
ManageClient = ManageClientLatest
Expand Down
2 changes: 2 additions & 0 deletions deepgram/clients/manage/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
UsageFieldsResponse,
Balance,
BalancesResponse,
ModelResponse,
ModelsResponse,
)
from ....options import DeepgramClientOptions, ClientOptionsFromEnv
154 changes: 153 additions & 1 deletion deepgram/clients/manage/v1/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
UsageFieldsResponse,
Balance,
BalancesResponse,
ModelResponse,
ModelsResponse,
)
from .options import (
ProjectOptions,
Expand All @@ -41,7 +43,7 @@

class AsyncManageClient(
AbstractAsyncRestClient
): # pylint: disable=too-many-public-methods
): # pylint: disable=too-many-public-methods,too-many-lines
"""
A client for managing Deepgram projects and associated resources via the Deepgram API.
Expand Down Expand Up @@ -239,6 +241,156 @@ async def delete_project(
self._logger.debug("ManageClient.delete_project LEAVE")
return res

async def list_project_models(
self,
project_id: str,
timeout: Optional[httpx.Timeout] = None,
addons: Optional[Dict] = None,
headers: Optional[Dict] = None,
**kwargs,
) -> ModelsResponse:
"""
List all models for the current project.
"""
return await self.get_models(
project_id, timeout=timeout, addons=addons, headers=headers, **kwargs
)

async def get_project_models(
self,
project_id: str,
timeout: Optional[httpx.Timeout] = None,
addons: Optional[Dict] = None,
headers: Optional[Dict] = None,
**kwargs,
) -> ModelsResponse:
"""
Gets a list of models for the current project.
Reference:
https://developers.deepgram.com/docs/model-metadata
"""
self._logger.debug("ManageClient.get_project_models ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/models"
self._logger.info("url: %s", url)
self._logger.info("project_id: %s", project_id)
self._logger.info("addons: %s", addons)
self._logger.info("headers: %s", headers)
result = await self.get(
url, timeout=timeout, addons=addons, headers=headers, **kwargs
)
self._logger.info("json: %s", result)
res = ModelsResponse.from_json(result)
self._logger.verbose("result: %s", res)
self._logger.notice("get_project_models succeeded")
self._logger.debug("ManageClient.get_project_models LEAVE")
return res

async def get_project_model(
self,
project_id: str,
model_id: str,
timeout: Optional[httpx.Timeout] = None,
addons: Optional[Dict] = None,
headers: Optional[Dict] = None,
**kwargs,
) -> ModelResponse:
"""
Gets details for a specific project.
Reference:
https://developers.deepgram.com/reference/get-project
"""
self._logger.debug("ManageClient.get_project_model ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/models/{model_id}"
self._logger.info("url: %s", url)
self._logger.info("project_id: %s", project_id)
self._logger.info("model_id: %s", model_id)
self._logger.info("addons: %s", addons)
self._logger.info("headers: %s", headers)
result = await self.get(
url, timeout=timeout, addons=addons, headers=headers, **kwargs
)
self._logger.info("json: %s", result)
res = ModelResponse.from_json(result)
self._logger.verbose("result: %s", res)
self._logger.notice("get_project_model succeeded")
self._logger.debug("ManageClient.get_project_model LEAVE")
return res

# models
async def list_models(
self,
timeout: Optional[httpx.Timeout] = None,
addons: Optional[Dict] = None,
headers: Optional[Dict] = None,
**kwargs,
) -> ModelsResponse:
"""
Please see get_models for more information.
"""
return await self.get_models(
timeout=timeout, addons=addons, headers=headers, **kwargs
)

async def get_models(
self,
timeout: Optional[httpx.Timeout] = None,
addons: Optional[Dict] = None,
headers: Optional[Dict] = None,
**kwargs,
) -> ModelsResponse:
"""
Gets a list of models available.
Reference:
https://developers.deepgram.com/docs/model-metadata
"""
self._logger.debug("ManageClient.get_models ENTER")
url = f"{self._config.url}/v1/models"
self._logger.info("url: %s", url)
self._logger.info("addons: %s", addons)
self._logger.info("headers: %s", headers)
result = await self.get(
url, timeout=timeout, addons=addons, headers=headers, **kwargs
)
self._logger.info("result: %s", result)
res = ModelsResponse.from_json(result)
self._logger.verbose("result: %s", res)
self._logger.notice("get_models succeeded")
self._logger.debug("ManageClient.get_models LEAVE")
return res

async def get_model(
self,
model_id: str,
timeout: Optional[httpx.Timeout] = None,
addons: Optional[Dict] = None,
headers: Optional[Dict] = None,
**kwargs,
) -> ModelResponse:
"""
Gets details for a specific project.
Reference:
https://developers.deepgram.com/reference/get-project
"""
self._logger.debug("ManageClient.get_model ENTER")
url = f"{self._config.url}/v1/models/{model_id}"
self._logger.info("url: %s", url)
self._logger.info("model_id: %s", model_id)
self._logger.info("addons: %s", addons)
self._logger.info("headers: %s", headers)
result = await self.get(
url, timeout=timeout, addons=addons, headers=headers, **kwargs
)
self._logger.info("result: %s", result)
res = ModelResponse.from_json(result)
self._logger.verbose("result: %s", res)
self._logger.notice("get_model succeeded")
self._logger.debug("ManageClient.get_model LEAVE")
return res

# keys
async def list_keys(
self,
Expand Down
Loading

0 comments on commit b372254

Please sign in to comment.