Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements Models API #445

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
)

# 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,
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
)

# 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,
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
ModelResponse,
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
)

# 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,
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
ModelsResponse,
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
)
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,
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
ModelsResponse,
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
)
from ....options import DeepgramClientOptions, ClientOptionsFromEnv
222 changes: 221 additions & 1 deletion deepgram/clients/manage/v1/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
UsageFieldsResponse,
Balance,
BalancesResponse,
ModelResponse,
ModelsResponse,
)
from .options import (
ProjectOptions,
ModelOptions,
KeyOptions,
ScopeOptions,
InviteOptions,
Expand All @@ -41,7 +44,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 +242,223 @@ async def delete_project(
self._logger.debug("ManageClient.delete_project LEAVE")
return res

async def list_project_models(
self,
project_id: str,
options: Optional[Union[Dict, ModelOptions]] = None,
timeout: Optional[httpx.Timeout] = None,
addons: Optional[Dict] = None,
headers: Optional[Dict] = None,
**kwargs,
) -> ModelsResponse:
"""
Please see get_project_models.
"""
return await self.get_project_models(
project_id,
options=options,
timeout=timeout,
addons=addons,
headers=headers,
**kwargs,
)

async def get_project_models(
self,
project_id: str,
options: Optional[Union[Dict, ModelOptions]] = None,
timeout: Optional[httpx.Timeout] = None,
addons: Optional[Dict] = None,
headers: Optional[Dict] = None,
**kwargs,
) -> ModelsResponse:
"""
Gets models for a specific project.
Reference:
https://developers.deepgram.com/reference/get-project
https://developers.deepgram.com/reference/get-model
Args:
project_id (str): The ID of the project.
timeout (Optional[httpx.Timeout]): The timeout setting for the request.
addons (Optional[Dict]): Additional options for the request.
headers (Optional[Dict]): Headers to include in the request.
**kwargs: Additional keyword arguments.
Returns:
ModelsResponse: A response object containing the model details.
"""
self._logger.debug("ManageClient.get_project_models ENTER")

if options is None:
options = ModelOptions()

url = f"{self._config.url}/{self._endpoint}/{project_id}/models"
self._logger.info("url: %s", url)
self._logger.info("project_id: %s", project_id)
if isinstance(options, ModelOptions):
self._logger.info("ModelOptions switching class -> dict")
options = options.to_dict()
self._logger.info("options: %s", options)
self._logger.info("addons: %s", addons)
self._logger.info("headers: %s", headers)
result = await self.get(
url, json=options, 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 a single model for a specific project.
Reference:
https://developers.deepgram.com/reference/get-project
https://developers.deepgram.com/reference/get-model
Args:
project_id (str): The ID of the project.
model_id (str): The ID of the model.
timeout (Optional[httpx.Timeout]): The timeout setting for the request.
addons (Optional[Dict]): Additional options for the request.
headers (Optional[Dict]): Headers to include in the request.
**kwargs: Additional keyword arguments.
Returns:
ModelResponse: A response object containing the model details.
"""
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,
options: Optional[Union[Dict, ModelOptions]] = None,
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(
options=options, timeout=timeout, addons=addons, headers=headers, **kwargs
)

async def get_models(
self,
options: Optional[Union[Dict, ModelOptions]] = None,
timeout: Optional[httpx.Timeout] = None,
addons: Optional[Dict] = None,
headers: Optional[Dict] = None,
**kwargs,
) -> ModelsResponse:
"""
Gets all models available.
Reference:
https://developers.deepgram.com/reference/get-model
Args:
timeout (Optional[httpx.Timeout]): The timeout setting for the request.
addons (Optional[Dict]): Additional options for the request.
headers (Optional[Dict]): Headers to include in the request.
**kwargs: Additional keyword arguments.
Returns:
ModelsResponse: A response object containing the model details.
"""
self._logger.debug("ManageClient.get_models ENTER")

if options is None:
options = ModelOptions()

url = f"{self._config.url}/v1/models"
self._logger.info("url: %s", url)
if isinstance(options, ModelOptions):
self._logger.info("ModelOptions switching class -> dict")
options = options.to_dict()
self._logger.info("options: %s", options)
self._logger.info("addons: %s", addons)
self._logger.info("headers: %s", headers)
result = await self.get(
url, json=options, 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 information for a specific model.
Reference:
https://developers.deepgram.com/reference/get-model
Args:
model_id (str): The ID of the model.
timeout (Optional[httpx.Timeout]): The timeout setting for the request.
addons (Optional[Dict]): Additional options for the request.
headers (Optional[Dict]): Headers to include in the request.
**kwargs: Additional keyword arguments.
Returns:
ModelResponse: A response object containing the model details.
"""
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
Loading