diff --git a/deepgram/__init__.py b/deepgram/__init__.py index cd259885..a3286281 100644 --- a/deepgram/__init__.py +++ b/deepgram/__init__.py @@ -43,11 +43,32 @@ StreamSource, FileSource, UrlSource, +) +from .client import BaseResponse +from .client import ( + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, +) +from .client import ( + ModelInfo, + Alternative, + Hit, + Search, + Channel, + Word, ) from .client import ( OpenResponse, - MetadataResponse, CloseResponse, UnhandledResponse, ErrorResponse, @@ -59,30 +80,77 @@ from .client import LiveTranscriptionEvents from .client import LiveOptions, ListenWebSocketOptions from .client import ( - # OpenResponse, + #### top level LiveResultResponse, - # MetadataResponse, + ListenWSMetadataResponse, SpeechStartedResponse, UtteranceEndResponse, + #### common websocket response + # OpenResponse, # CloseResponse, # UnhandledResponse, # ErrorResponse, + #### unique + ListenWSMetadata, ) # prerecorded from .client import PreRecordedClient, AsyncPreRecordedClient # backward compat from .client import ListenRESTClient, AsyncListenRESTClient from .client import ( - ListenRESTOptions, - PrerecordedOptions, + # common + # UrlSource, + # BufferSource, + # StreamSource, + # TextSource, + # FileSource, + # unique PreRecordedStreamSource, PrerecordedSource, ListenRestSource, + SpeakRESTSource, ) from .client import ( + ListenRESTOptions, + PrerecordedOptions, +) +from .client import ( + #### top level AsyncPrerecordedResponse, PrerecordedResponse, SyncPrerecordedResponse, + #### shared + # Average, + # Intent, + # Intents, + # IntentsInfo, + # Segment, + # SentimentInfo, + # Sentiment, + # Sentiments, + # SummaryInfo, + # Topic, + # Topics, + # TopicsInfo, + #### unique + Alternative, + Channel, + Entity, + Hit, + ListenRESTMetadata, + ModelInfo, + Paragraph, + Paragraphs, + ListenRESTResults, + Search, + Sentence, + Summaries, + SummaryV1, + SummaryV2, + Translation, + Utterance, + Warning, + Word, ) # read @@ -94,23 +162,45 @@ AnalyzeSource, ) from .client import ( + #### top level AsyncAnalyzeResponse, - AnalyzeResponse, SyncAnalyzeResponse, + AnalyzeResponse, + #### shared + # Average, + # Intent, + # Intents, + # IntentsInfo, + # Segment, + # SentimentInfo, + # Sentiment, + # Sentiments, + # SummaryInfo, + # Topic, + # Topics, + # TopicsInfo, + #### unique + AnalyzeMetadata, + AnalyzeResults, + AnalyzeSummary, ) # speak +## speak REST from .client import ( - SpeakOptions, + #### top level SpeakRESTOptions, - SpeakWSOptions, + SpeakOptions, # backward compat + #### common + # TextSource, + # BufferSource, + # StreamSource, # FileSource, - SpeakRestSource, + #### unique SpeakSource, + SpeakRestSource, ) -from .client import SpeakWebSocketEvents, SpeakWebSocketMessage -## speak REST from .client import ( SpeakClient, # backward compat SpeakRESTClient, @@ -123,20 +213,29 @@ ) ## speak WebSocket +from .client import SpeakWebSocketEvents, SpeakWebSocketMessage + +from .client import ( + SpeakWSOptions, +) + from .client import ( SpeakWebSocketClient, AsyncSpeakWebSocketClient, SpeakWSClient, AsyncSpeakWSClient, ) + from .client import ( - # OpenResponse, - # MetadataResponse, + #### top level + SpeakWSMetadataResponse, FlushedResponse, ClearedResponse, + WarningResponse, + #### common websocket response + # OpenResponse, # CloseResponse, # UnhandledResponse, - WarningResponse, # ErrorResponse, ) @@ -154,23 +253,42 @@ # manage client responses from .client import ( + #### top level Message, - Project, ProjectsResponse, + ModelResponse, + ModelsResponse, MembersResponse, - Key, KeyResponse, KeysResponse, ScopesResponse, InvitesResponse, UsageRequest, + UsageResponse, UsageRequestsResponse, UsageSummaryResponse, UsageFieldsResponse, - Balance, BalancesResponse, - ModelsResponse, - ModelResponse, + #### shared + Project, + STTDetails, + TTSMetadata, + TTSDetails, + Member, + Key, + Invite, + Config, + STTUsageDetails, + Callback, + TokenDetail, + SpeechSegment, + TTSUsageDetails, + STTTokens, + TTSTokens, + UsageSummaryResults, + Resolution, + UsageModel, + Balance, ) # selfhosted diff --git a/deepgram/audio/microphone/microphone.py b/deepgram/audio/microphone/microphone.py index 11649da8..15dd2a7b 100644 --- a/deepgram/audio/microphone/microphone.py +++ b/deepgram/audio/microphone/microphone.py @@ -47,7 +47,7 @@ def __init__( chunk: int = CHUNK, channels: int = CHANNELS, input_device_index: Optional[int] = None, - ): + ): # pylint: disable=too-many-positional-arguments # dynamic import of pyaudio as not to force the requirements on the SDK (and users) import pyaudio # pylint: disable=import-outside-toplevel diff --git a/deepgram/audio/speaker/speaker.py b/deepgram/audio/speaker/speaker.py index 55c1bbc5..9a439109 100644 --- a/deepgram/audio/speaker/speaker.py +++ b/deepgram/audio/speaker/speaker.py @@ -55,7 +55,7 @@ def __init__( chunk: int = CHUNK, channels: int = CHANNELS, output_device_index: Optional[int] = None, - ): + ): # pylint: disable=too-many-positional-arguments # dynamic import of pyaudio as not to force the requirements on the SDK (and users) import pyaudio # pylint: disable=import-outside-toplevel diff --git a/deepgram/client.py b/deepgram/client.py index 572950e8..673ad82a 100644 --- a/deepgram/client.py +++ b/deepgram/client.py @@ -19,11 +19,32 @@ StreamSource, FileSource, UrlSource, +) +from .clients import BaseResponse +from .clients import ( + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, +) +from .clients import ( + ModelInfo, + Alternative, + Hit, + Search, + Channel, + Word, ) from .clients import ( OpenResponse, - MetadataResponse, CloseResponse, UnhandledResponse, ErrorResponse, @@ -53,17 +74,34 @@ # live client responses from .clients import ( - # OpenResponse, + #### top level LiveResultResponse, - # MetadataResponse, + ListenWSMetadataResponse, SpeechStartedResponse, UtteranceEndResponse, + #### common websocket response + # OpenResponse, # CloseResponse, # ErrorResponse, # UnhandledResponse, + #### unique + ListenWSMetadata, ) # prerecorded +from .clients import ( + # common + # UrlSource, + # BufferSource, + # StreamSource, + # TextSource, + # FileSource, + # unique + PreRecordedStreamSource, + PrerecordedSource, + ListenRestSource, +) + from .clients import ( PreRecordedClient, AsyncPreRecordedClient, @@ -75,16 +113,47 @@ from .clients import ( ListenRESTOptions, PrerecordedOptions, - PreRecordedStreamSource, - PrerecordedSource, - ListenRestSource, ) -# prerecorded client responses +# rest client responses from .clients import ( + #### top level AsyncPrerecordedResponse, PrerecordedResponse, SyncPrerecordedResponse, + #### shared + # Average, + # Intent, + # Intents, + # IntentsInfo, + # Segment, + # SentimentInfo, + # Sentiment, + # Sentiments, + # SummaryInfo, + # Topic, + # Topics, + # TopicsInfo, + #### between rest and websocket + # ModelInfo, + # Alternative, + # Hit, + # Search, + # Channel, + # Word, + # unique + Entity, + ListenRESTMetadata, + Paragraph, + Paragraphs, + ListenRESTResults, + Sentence, + Summaries, + SummaryV1, + SummaryV2, + Translation, + Utterance, + Warning, ) # read @@ -98,23 +167,46 @@ # read client responses from .clients import ( + #### top level AsyncAnalyzeResponse, - AnalyzeResponse, SyncAnalyzeResponse, + AnalyzeResponse, + #### shared + # Average, + # Intent, + # Intents, + # IntentsInfo, + # Segment, + # SentimentInfo, + # Sentiment, + # Sentiments, + # SummaryInfo, + # Topic, + # Topics, + # TopicsInfo, + #### unique + AnalyzeMetadata, + AnalyzeResults, + AnalyzeSummary, ) # speak +## speak REST from .clients import ( - SpeakOptions, + #### top level SpeakRESTOptions, - SpeakWSOptions, + SpeakOptions, # backward compat + #### common + # TextSource, + # BufferSource, + # StreamSource, # FileSource, - SpeakRestSource, + #### unique SpeakSource, + SpeakRestSource, + SpeakRESTSource, ) -from .clients import SpeakWebSocketEvents, SpeakWebSocketMessage -## speak REST from .clients import ( SpeakClient, # backward compat SpeakRESTClient, @@ -127,20 +219,29 @@ ) ## speak WebSocket +from .clients import SpeakWebSocketEvents, SpeakWebSocketMessage + +from .clients import ( + SpeakWSOptions, +) + from .clients import ( SpeakWebSocketClient, AsyncSpeakWebSocketClient, SpeakWSClient, AsyncSpeakWSClient, ) + from .clients import ( - # OpenResponse, - # MetadataResponse, + #### top level + SpeakWSMetadataResponse, FlushedResponse, ClearedResponse, + WarningResponse, + #### common websocket response + # OpenResponse, # CloseResponse, # UnhandledResponse, - WarningResponse, # ErrorResponse, ) @@ -158,23 +259,42 @@ # manage client responses from .clients import ( + #### top level Message, - Project, ProjectsResponse, + ModelResponse, + ModelsResponse, MembersResponse, - Key, KeyResponse, KeysResponse, ScopesResponse, InvitesResponse, UsageRequest, + UsageResponse, UsageRequestsResponse, UsageSummaryResponse, UsageFieldsResponse, - Balance, BalancesResponse, - ModelResponse, - ModelsResponse, + #### shared + Project, + STTDetails, + TTSMetadata, + TTSDetails, + Member, + Key, + Invite, + Config, + STTUsageDetails, + Callback, + TokenDetail, + SpeechSegment, + TTSUsageDetails, + STTTokens, + TTSTokens, + UsageSummaryResults, + Resolution, + UsageModel, + Balance, ) # on-prem diff --git a/deepgram/clients/__init__.py b/deepgram/clients/__init__.py index e402ff04..9bc7191c 100644 --- a/deepgram/clients/__init__.py +++ b/deepgram/clients/__init__.py @@ -9,11 +9,36 @@ StreamSource, FileSource, UrlSource, +) +from .common import BaseResponse + +# +from .common import ( + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, ) -from .listen import ( + +# +from .common import ( + ModelInfo, + Alternative, + Hit, + Search, + Channel, + Word, +) +from .common import ( OpenResponse, - MetadataResponse, CloseResponse, UnhandledResponse, ErrorResponse, @@ -43,20 +68,62 @@ ## input from .listen import ( - ListenRESTOptions, - PrerecordedOptions, - PreRecordedStreamSource, + # common # UrlSource, + # BufferSource, + # StreamSource, + # TextSource, # FileSource, + # unique + PreRecordedStreamSource, PrerecordedSource, ListenRestSource, ) +from .listen import ( + ListenRESTOptions, + PrerecordedOptions, +) + ## output from .listen import ( + #### top level AsyncPrerecordedResponse, PrerecordedResponse, SyncPrerecordedResponse, + #### shared + # Average, + # Intent, + # Intents, + # IntentsInfo, + # Segment, + # SentimentInfo, + # Sentiment, + # Sentiments, + # SummaryInfo, + # Topic, + # Topics, + # TopicsInfo, + #### between rest and websocket + # ModelInfo, + # Alternative, + # Hit, + # Search, + # Channel, + # Word, + # unique + Entity, + ListenRESTMetadata, + Paragraph, + Paragraphs, + ListenRESTResults, + Sentence, + Summaries, + SummaryV1, + SummaryV2, + Translation, + Utterance, + Warning, ) @@ -71,14 +138,18 @@ ## output from .listen import ( - # OpenResponse, + #### top level LiveResultResponse, - # MetadataResponse, + ListenWSMetadataResponse, SpeechStartedResponse, UtteranceEndResponse, + #### common websocket response + # OpenResponse, # CloseResponse, # ErrorResponse, # UnhandledResponse, + #### uniqye + ListenWSMetadata, ) ## clients @@ -88,34 +159,61 @@ ) -# read +# read/analyze from .analyze import ReadClient, AsyncReadClient from .analyze import AnalyzeClient, AsyncAnalyzeClient from .analyze import AnalyzeOptions from .analyze import ( + # common + # UrlSource, + # TextSource, + # BufferSource, + # StreamSource, + # FileSource + # unique AnalyzeStreamSource, AnalyzeSource, ) from .analyze import ( AsyncAnalyzeResponse, - AnalyzeResponse, SyncAnalyzeResponse, + AnalyzeResponse, + # shared + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, + Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, + # unique + AnalyzeMetadata, + AnalyzeResults, + AnalyzeSummary, ) # text-to-speech -## common +## text-to-speech REST from .speak import ( - SpeakOptions, + #### top level SpeakRESTOptions, - SpeakWSOptions, + SpeakOptions, + # common + # TextSource, + # BufferSource, + # StreamSource, # FileSource, - SpeakRestSource, + # unique SpeakSource, + SpeakRestSource, + SpeakRESTSource, ) -from .speak import SpeakWebSocketEvents, SpeakWebSocketMessage - -## text-to-speech REST from .speak import ( SpeakClient, # backward compat SpeakRESTClient, @@ -128,20 +226,29 @@ ) ## text-to-speech WebSocket +from .speak import SpeakWebSocketEvents, SpeakWebSocketMessage + +from .speak import ( + SpeakWSOptions, +) + from .speak import ( SpeakWebSocketClient, AsyncSpeakWebSocketClient, SpeakWSClient, AsyncSpeakWSClient, ) + from .speak import ( - # OpenResponse, - # MetadataResponse, + #### top level + SpeakWSMetadataResponse, FlushedResponse, ClearedResponse, + WarningResponse, + #### common websocket response + # OpenResponse, # CloseResponse, # UnhandledResponse, - WarningResponse, # ErrorResponse, ) @@ -157,23 +264,42 @@ UsageFieldsOptions, ) from .manage import ( + #### top level Message, - Project, ProjectsResponse, + ModelResponse, + ModelsResponse, MembersResponse, - Key, KeyResponse, KeysResponse, ScopesResponse, InvitesResponse, UsageRequest, + UsageResponse, UsageRequestsResponse, UsageSummaryResponse, UsageFieldsResponse, - Balance, BalancesResponse, - ModelsResponse, - ModelResponse, + #### shared + Project, + STTDetails, + TTSMetadata, + TTSDetails, + Member, + Key, + Invite, + Config, + STTUsageDetails, + Callback, + TokenDetail, + SpeechSegment, + TTSUsageDetails, + STTTokens, + TTSTokens, + UsageSummaryResults, + Resolution, + UsageModel, + Balance, ) # selfhosted diff --git a/deepgram/clients/abstract_async_client.py b/deepgram/clients/abstract_async_client.py index 37506ead..320098d2 100644 --- a/deepgram/clients/abstract_async_client.py +++ b/deepgram/clients/abstract_async_client.py @@ -39,6 +39,8 @@ def __init__(self, config: DeepgramClientOptions): raise DeepgramError("Config are required") self._config = config + # pylint: disable=too-many-positional-arguments + async def get( self, url: str, @@ -372,3 +374,4 @@ async def _handle_request_raw( raise # pylint: enable-msg=too-many-locals,too-many-branches + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/abstract_sync_client.py b/deepgram/clients/abstract_sync_client.py index 9ccf92b5..c1a76e6c 100644 --- a/deepgram/clients/abstract_sync_client.py +++ b/deepgram/clients/abstract_sync_client.py @@ -39,6 +39,8 @@ def __init__(self, config: DeepgramClientOptions): raise DeepgramError("Config are required") self._config = config + # pylint: disable=too-many-positional-arguments + def get( self, url: str, @@ -363,4 +365,5 @@ def _handle_request_raw( except Exception: # pylint: disable-msg=try-except-raise raise - # pylint: disable-msg=too-many-branches,too-many-locals + # pylint: enable-msg=too-many-branches,too-many-locals + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/analyze/__init__.py b/deepgram/clients/analyze/__init__.py index 599daaaf..71708c58 100644 --- a/deepgram/clients/analyze/__init__.py +++ b/deepgram/clients/analyze/__init__.py @@ -5,5 +5,36 @@ from .client import AnalyzeClient, AsyncAnalyzeClient from .client import ReadClient, AsyncReadClient from .client import AnalyzeOptions -from .client import UrlSource, FileSource, AnalyzeStreamSource, AnalyzeSource -from .client import AsyncAnalyzeResponse, AnalyzeResponse, SyncAnalyzeResponse +from .client import ( + # common + UrlSource, + TextSource, + BufferSource, + StreamSource, + FileSource, + # unique + AnalyzeStreamSource, + AnalyzeSource, +) +from .client import ( + AsyncAnalyzeResponse, + SyncAnalyzeResponse, + AnalyzeResponse, + # shared + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, + Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, + # unique + AnalyzeMetadata, + AnalyzeResults, + AnalyzeSummary, +) diff --git a/deepgram/clients/analyze/client.py b/deepgram/clients/analyze/client.py index 53f73396..80dc3fad 100644 --- a/deepgram/clients/analyze/client.py +++ b/deepgram/clients/analyze/client.py @@ -5,9 +5,14 @@ from .v1.client import AnalyzeClient as AnalyzeClientLatest from .v1.async_client import AsyncAnalyzeClient as AsyncAnalyzeClientLatest from .v1.options import ( + # common AnalyzeOptions as AnalyzeOptionsLatest, UrlSource as UrlSourceLatest, + TextSource as TextSourceLatest, + BufferSource as BufferSourceLatest, + StreamSource as StreamSourceLatest, FileSource as FileSourceLatest, + # unique AnalyzeStreamSource as AnalyzeStreamSourceLatest, AnalyzeSource as AnalyzeSourceLatest, ) @@ -15,25 +20,62 @@ SyncAnalyzeResponse as SyncAnalyzeResponseLatest, AnalyzeResponse as AnalyzeResponseLatest, AsyncAnalyzeResponse as AsyncAnalyzeResponseLatest, + # shared + Average as AverageLatest, + Intent as IntentLatest, + Intents as IntentsLatest, + IntentsInfo as IntentsInfoLatest, + Segment as SegmentLatest, + SentimentInfo as SentimentInfoLatest, + Sentiment as SentimentLatest, + Sentiments as SentimentsLatest, + SummaryInfo as SummaryInfoLatest, + Topic as TopicLatest, + Topics as TopicsLatest, + TopicsInfo as TopicsInfoLatest, + # unique + Results as ResultsLatest, + Metadata as MetadataLatest, + Summary as SummaryLatest, ) # The client.py points to the current supported version in the SDK. # Older versions are supported in the SDK for backwards compatibility. +# common +UrlSource = UrlSourceLatest +TextSource = TextSourceLatest +BufferSource = BufferSourceLatest +StreamSource = StreamSourceLatest +FileSource = FileSourceLatest -# input -AnalyzeOptions = AnalyzeOptionsLatest AnalyzeStreamSource = AnalyzeStreamSourceLatest -FileSource = FileSourceLatest -UrlSource = UrlSourceLatest AnalyzeSource = AnalyzeSourceLatest +# input +AnalyzeOptions = AnalyzeOptionsLatest # responses -AsyncAnalyzeResponse = AsyncAnalyzeResponseLatest -AnalyzeResponse = AnalyzeResponseLatest SyncAnalyzeResponse = SyncAnalyzeResponseLatest - +AnalyzeResponse = AnalyzeResponseLatest +AsyncAnalyzeResponse = AsyncAnalyzeResponseLatest +# shared +Average = AverageLatest +Intent = IntentLatest +Intents = IntentsLatest +IntentsInfo = IntentsInfoLatest +Segment = SegmentLatest +SentimentInfo = SentimentInfoLatest +Sentiment = SentimentLatest +Sentiments = SentimentsLatest +SummaryInfo = SummaryInfoLatest +Topic = TopicLatest +Topics = TopicsLatest +TopicsInfo = TopicsInfoLatest +# unique +AnalyzeResults = ResultsLatest +AnalyzeMetadata = MetadataLatest +AnalyzeSummary = SummaryLatest # clients AnalyzeClient = AnalyzeClientLatest diff --git a/deepgram/clients/analyze/v1/__init__.py b/deepgram/clients/analyze/v1/__init__.py index 0ffaf939..8ffd0b46 100644 --- a/deepgram/clients/analyze/v1/__init__.py +++ b/deepgram/clients/analyze/v1/__init__.py @@ -4,11 +4,43 @@ from .client import AnalyzeClient from .async_client import AsyncAnalyzeClient + +# common from .options import ( - AnalyzeOptions, UrlSource, + TextSource, + BufferSource, + StreamSource, FileSource, +) + +# analyze + +from .options import ( + AnalyzeOptions, AnalyzeStreamSource, AnalyzeSource, ) -from .response import AsyncAnalyzeResponse, AnalyzeResponse, Sentiment + +from .response import ( + AsyncAnalyzeResponse, + SyncAnalyzeResponse, + AnalyzeResponse, + # shared + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, + Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, + # unique + Metadata, + Results, + Summary, +) diff --git a/deepgram/clients/analyze/v1/async_client.py b/deepgram/clients/analyze/v1/async_client.py index a2970f8a..8edaa4e7 100644 --- a/deepgram/clients/analyze/v1/async_client.py +++ b/deepgram/clients/analyze/v1/async_client.py @@ -37,6 +37,8 @@ def __init__(self, config: DeepgramClientOptions): self._config = config super().__init__(config) + # pylint: disable=too-many-positional-arguments + async def analyze_url( self, source: UrlSource, @@ -340,3 +342,5 @@ async def analyze_text_callback( self._logger.notice("analyze_text_callback succeeded") self._logger.debug("AnalyzeClient.analyze_text_callback LEAVE") return res + + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/analyze/v1/client.py b/deepgram/clients/analyze/v1/client.py index 341c10f6..efae8c3f 100644 --- a/deepgram/clients/analyze/v1/client.py +++ b/deepgram/clients/analyze/v1/client.py @@ -37,6 +37,8 @@ def __init__(self, config: DeepgramClientOptions): self._config = config super().__init__(config) + # pylint: disable=too-many-positional-arguments + def analyze_url( self, source: UrlSource, @@ -340,3 +342,5 @@ def analyze_text_callback( self._logger.notice("analyze_file_callback succeeded") self._logger.debug("AnalyzeClient.analyze_file_callback LEAVE") return res + + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/analyze/v1/options.py b/deepgram/clients/analyze/v1/options.py index 631ed414..d6999c66 100644 --- a/deepgram/clients/analyze/v1/options.py +++ b/deepgram/clients/analyze/v1/options.py @@ -6,16 +6,21 @@ from typing import List, Union, Optional from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from dataclasses_json import config as dataclass_config from ....utils import verboselogs -from ...common import FileSource, StreamSource, UrlSource +from ...common import ( + TextSource, + FileSource, + BufferSource, + StreamSource, + UrlSource, + BaseResponse, +) @dataclass -class AnalyzeOptions( - DataClassJsonMixin -): # pylint: disable=too-many-instance-attributes +class AnalyzeOptions(BaseResponse): # pylint: disable=too-many-instance-attributes """ Contains all the options for the AnalyzeOptions. @@ -57,16 +62,6 @@ class AnalyzeOptions( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - def check(self): """ Check the options for the AnalyzeOptions. @@ -83,8 +78,6 @@ def check(self): return True +# unique +AnalyzeSource = Union[UrlSource, FileSource] AnalyzeStreamSource = StreamSource - -# FileSource = FileSource -# UrlSource = UrlSource -AnalyzeSource = Union[FileSource, UrlSource, AnalyzeStreamSource] diff --git a/deepgram/clients/analyze/v1/response.py b/deepgram/clients/analyze/v1/response.py index 3a09cce9..5d678cba 100644 --- a/deepgram/clients/analyze/v1/response.py +++ b/deepgram/clients/analyze/v1/response.py @@ -5,44 +5,23 @@ from typing import List, Optional, Dict, Any from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin - -from ...common import Sentiment - - -# Base Classes: - - -@dataclass -class BaseResponse(DataClassJsonMixin): - """ - BaseResponse class used to define the common methods and properties for all response classes. - """ - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - - def eval(self, key: str) -> str: - """ - This method is used to evaluate a key in the response object using a dot notation style method. - """ - keys = key.split(".") - result: Dict[Any, Any] = self.to_dict() - for k in keys: - if isinstance(result, dict) and k in result: - result = result[k] - elif isinstance(result, list) and k.isdigit() and int(k) < len(result): - result = result[int(k)] - else: - return "" - return str(result) +from dataclasses_json import config as dataclass_config + +from ...common import ( + BaseResponse, + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, + Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, +) # Async Analyze Response Types: @@ -60,50 +39,6 @@ class AsyncAnalyzeResponse(BaseResponse): # Analyze Response Types: -@dataclass -class IntentsInfo(BaseResponse): - """ - Intents Info - """ - - model_uuid: str = "" - input_tokens: int = 0 - output_tokens: int = 0 - - -@dataclass -class SentimentInfo(BaseResponse): - """ - Sentiment Info - """ - - model_uuid: str = "" - input_tokens: int = 0 - output_tokens: int = 0 - - -@dataclass -class SummaryInfo(BaseResponse): - """ - Summary Info - """ - - model_uuid: str = "" - input_tokens: int = 0 - output_tokens: int = 0 - - -@dataclass -class TopicsInfo(BaseResponse): - """ - Topics Info - """ - - model_uuid: str = "" - input_tokens: int = 0 - output_tokens: int = 0 - - @dataclass class Metadata(BaseResponse): """ @@ -139,22 +74,6 @@ def __getitem__(self, key): return _dict[key] -@dataclass -class Average(BaseResponse): - """ - Average - """ - - sentiment: Sentiment - sentiment_score: float = 0 - - def __getitem__(self, key): - _dict = self.to_dict() - if "sentiment" in _dict: - _dict["sentiment"] = Sentiment.from_dict(_dict["sentiment"]) - return _dict[key] - - @dataclass class Summary(BaseResponse): """ @@ -164,111 +83,6 @@ class Summary(BaseResponse): text: str = "" -@dataclass -class Topic(BaseResponse): - """ - Topic - """ - - topic: str = "" - confidence_score: float = 0 - - -@dataclass -class Intent(BaseResponse): - """ - Intent - """ - - intent: str = "" - confidence_score: float = 0 - - -@dataclass -class Segment(BaseResponse): - """ - Segment - """ - - text: str = "" - start_word: int = 0 - end_word: int = 0 - sentiment: Optional[Sentiment] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - sentiment_score: Optional[float] = 0 - intents: Optional[List[Intent]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - topics: Optional[List[Topic]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - - def __getitem__(self, key): - _dict = self.to_dict() - if "sentiment" in _dict: - _dict["sentiment"] = Sentiment.from_dict(_dict["sentiment"]) - if "intents" in _dict: - _dict["intents"] = Intent.from_dict(_dict["intents"]) - if "topics" in _dict: - _dict["topics"] = Topic.from_dict(_dict["topics"]) - return _dict[key] - - -@dataclass -class Sentiments(BaseResponse): - """ - Sentiments - """ - - average: Average - segments: List[Segment] = field(default_factory=list) - - def __getitem__(self, key): - _dict = self.to_dict() - if "segments" in _dict: - _dict["segments"] = [ - Segment.from_dict(segments) for segments in _dict["segments"] - ] - if "average" in _dict: - _dict["average"] = Average.from_dict(_dict["average"]) - return _dict[key] - - -@dataclass -class Topics(BaseResponse): - """ - Topics - """ - - segments: List[Segment] = field(default_factory=list) - - def __getitem__(self, key): - _dict = self.to_dict() - if "segments" in _dict: - _dict["segments"] = [ - Segment.from_dict(segments) for segments in _dict["segments"] - ] - return _dict[key] - - -@dataclass -class Intents(BaseResponse): - """ - Intents - """ - - segments: List[Segment] = field(default_factory=list) - - def __getitem__(self, key): - _dict = self.to_dict() - if "segments" in _dict: - _dict["segments"] = [ - Segment.from_dict(segments) for segments in _dict["segments"] - ] - return _dict[key] - - @dataclass class Results(BaseResponse): """ diff --git a/deepgram/clients/common/__init__.py b/deepgram/clients/common/__init__.py index e3cb868e..2018b362 100644 --- a/deepgram/clients/common/__init__.py +++ b/deepgram/clients/common/__init__.py @@ -10,13 +10,72 @@ StreamSource as StreamSourceLatest, FileSource as FileSourceLatest, UrlSource as UrlSourceLatest, +) + +# shared +from .v1 import ( + BaseResponse as BaseResponseLatest, + ModelInfo as ModelInfoLatest, + Word as WordLatest, + Alternative as AlternativeLatest, + Hit as HitLatest, + Search as SearchLatest, + Channel as ChannelLatest, +) + +# rest +from .v1 import ( + Average as AverageLatest, + Intent as IntentLatest, + Intents as IntentsLatest, + IntentsInfo as IntentsInfoLatest, + Segment as SegmentLatest, + SentimentInfo as SentimentInfoLatest, Sentiment as SentimentLatest, + Sentiments as SentimentsLatest, + SummaryInfo as SummaryInfoLatest, + Topic as TopicLatest, + Topics as TopicsLatest, + TopicsInfo as TopicsInfoLatest, ) +# websocket +from .v1 import ( + OpenResponse as OpenResponseLatest, + CloseResponse as CloseResponseLatest, + ErrorResponse as ErrorResponseLatest, + UnhandledResponse as UnhandledResponseLatest, +) + +# export UrlSource = UrlSourceLatest TextSource = TextSourceLatest BufferSource = BufferSourceLatest StreamSource = StreamSourceLatest +FileSource = FileSourceLatest +BaseResponse = BaseResponseLatest +ModelInfo = ModelInfoLatest +Word = WordLatest +Alternative = AlternativeLatest +Hit = HitLatest +Search = SearchLatest +Channel = ChannelLatest + +Average = AverageLatest +Intent = IntentLatest +Intents = IntentsLatest +IntentsInfo = IntentsInfoLatest +Segment = SegmentLatest +SentimentInfo = SentimentInfoLatest Sentiment = SentimentLatest -FileSource = FileSourceLatest +Sentiments = SentimentsLatest +SummaryInfo = SummaryInfoLatest +Topic = TopicLatest +Topics = TopicsLatest +TopicsInfo = TopicsInfoLatest + +OpenResponse = OpenResponseLatest +CloseResponse = CloseResponseLatest +ErrorResponse = ErrorResponseLatest +UnhandledResponse = UnhandledResponseLatest diff --git a/deepgram/clients/common/v1/__init__.py b/deepgram/clients/common/v1/__init__.py index b4bd0b30..0cb91bc2 100644 --- a/deepgram/clients/common/v1/__init__.py +++ b/deepgram/clients/common/v1/__init__.py @@ -13,3 +13,35 @@ FileSource, UrlSource, ) + +from .shared_response import ( + BaseResponse, + ModelInfo, + Word, + Alternative, + Hit, + Search, + Channel, +) + +from .rest_response import ( + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, + Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, +) + +from .websocket_response import ( + OpenResponse, + CloseResponse, + ErrorResponse, + UnhandledResponse, +) diff --git a/deepgram/clients/common/v1/rest_response.py b/deepgram/clients/common/v1/rest_response.py new file mode 100644 index 00000000..22ca09eb --- /dev/null +++ b/deepgram/clients/common/v1/rest_response.py @@ -0,0 +1,181 @@ +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +from typing import List, Optional, Dict, Any + +from dataclasses import dataclass, field +from dataclasses_json import config as dataclass_config + +from .enums import Sentiment +from .shared_response import BaseResponse + + +# Analyze Response Types: + + +@dataclass +class IntentsInfo(BaseResponse): + """ + Intents Info + """ + + model_uuid: str = "" + input_tokens: int = 0 + output_tokens: int = 0 + + +@dataclass +class SentimentInfo(BaseResponse): + """ + Sentiment Info + """ + + model_uuid: str = "" + input_tokens: int = 0 + output_tokens: int = 0 + + +@dataclass +class SummaryInfo(BaseResponse): + """ + Summary Info + """ + + model_uuid: str = "" + input_tokens: int = 0 + output_tokens: int = 0 + + +@dataclass +class TopicsInfo(BaseResponse): + """ + Topics Info + """ + + model_uuid: str = "" + input_tokens: int = 0 + output_tokens: int = 0 + + +@dataclass +class Average(BaseResponse): + """ + Average + """ + + sentiment: Sentiment + sentiment_score: float = 0 + + def __getitem__(self, key): + _dict = self.to_dict() + if "sentiment" in _dict: + _dict["sentiment"] = Sentiment.from_dict(_dict["sentiment"]) + return _dict[key] + + +@dataclass +class Topic(BaseResponse): + """ + Topic + """ + + topic: str = "" + confidence_score: float = 0 + + +@dataclass +class Intent(BaseResponse): + """ + Intent + """ + + intent: str = "" + confidence_score: float = 0 + + +@dataclass +class Segment(BaseResponse): + """ + Segment + """ + + text: str = "" + start_word: int = 0 + end_word: int = 0 + sentiment: Optional[Sentiment] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + sentiment_score: Optional[float] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + intents: Optional[List[Intent]] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + topics: Optional[List[Topic]] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + + def __getitem__(self, key): + _dict = self.to_dict() + if "sentiment" in _dict: + _dict["sentiment"] = Sentiment.from_dict(_dict["sentiment"]) + if "intents" in _dict: + _dict["intents"] = Intent.from_dict(_dict["intents"]) + if "topics" in _dict: + _dict["topics"] = Topic.from_dict(_dict["topics"]) + return _dict[key] + + +@dataclass +class Sentiments(BaseResponse): + """ + Sentiments + """ + + average: Average + segments: List[Segment] = field(default_factory=list) + + def __getitem__(self, key): + _dict = self.to_dict() + if "segments" in _dict: + _dict["segments"] = [ + Segment.from_dict(segments) for segments in _dict["segments"] + ] + if "average" in _dict: + _dict["average"] = Average.from_dict(_dict["average"]) + return _dict[key] + + +@dataclass +class Topics(BaseResponse): + """ + Topics + """ + + segments: List[Segment] = field(default_factory=list) + + def __getitem__(self, key): + _dict = self.to_dict() + if "segments" in _dict: + _dict["segments"] = [ + Segment.from_dict(segments) for segments in _dict["segments"] + ] + return _dict[key] + + +@dataclass +class Intents(BaseResponse): + """ + Intents + """ + + segments: List[Segment] = field(default_factory=list) + + def __getitem__(self, key): + _dict = self.to_dict() + if "segments" in _dict: + _dict["segments"] = [ + Segment.from_dict(segments) for segments in _dict["segments"] + ] + return _dict[key] diff --git a/deepgram/clients/common/v1/shared_response.py b/deepgram/clients/common/v1/shared_response.py new file mode 100644 index 00000000..fdf2b8ae --- /dev/null +++ b/deepgram/clients/common/v1/shared_response.py @@ -0,0 +1,150 @@ +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +from typing import List, Optional, Dict, Any + + +from dataclasses import dataclass, field +from dataclasses_json import config as dataclass_config, DataClassJsonMixin + + +# base class + + +@dataclass +class BaseResponse(DataClassJsonMixin): + """ + BaseResponse class used to define the common methods and properties for all response classes. + """ + + def __getitem__(self, key): + _dict = self.to_dict() + return _dict[key] + + def __setitem__(self, key, val): + self.__dict__[key] = val + + def __str__(self) -> str: + return self.to_json(indent=4) + + def eval(self, key: str) -> str: + """ + This method is used to evaluate a key in the response object using a dot notation style method. + """ + keys = key.split(".") + result: Dict[Any, Any] = self.to_dict() + for k in keys: + if isinstance(result, dict) and k in result: + result = result[k] + elif isinstance(result, list) and k.isdigit() and int(k) < len(result): + result = result[int(k)] + else: + return "" + return str(result) + + +# shared classes + + +@dataclass +class ModelInfo(BaseResponse): + """ + ModelInfo object + """ + + name: str = "" + version: str = "" + arch: str = "" + + +@dataclass +class Word(BaseResponse): + """ + Word object + """ + + word: str = "" + start: float = 0 + end: float = 0 + confidence: float = 0 + punctuated_word: Optional[str] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + speaker: Optional[int] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + language: Optional[str] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + + +@dataclass +class Alternative(BaseResponse): + """ + Alternative object + """ + + transcript: str = "" + confidence: float = 0 + words: List[Word] = field(default_factory=list) + languages: Optional[List[str]] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + + def __getitem__(self, key): + _dict = self.to_dict() + if "words" in _dict: + _dict["words"] = [Word.from_dict(words) for words in _dict["words"]] + return _dict[key] + + +@dataclass +class Hit(BaseResponse): + """ + The hit information for the response. + """ + + confidence: float = 0 + start: float = 0 + end: float = 0 + snippet: Optional[str] = "" + + +@dataclass +class Search(BaseResponse): + """ + The search information for the response. + """ + + query: str = "" + hits: List[Hit] = field(default_factory=list) + + def __getitem__(self, key): + _dict = self.to_dict() + if "hits" in _dict: + _dict["hits"] = [Hit.from_dict(hits) for hits in _dict["hits"]] + return _dict[key] + + +@dataclass +class Channel(BaseResponse): + """ + Channel object + """ + + search: Optional[List[Search]] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + alternatives: List[Alternative] = field(default_factory=list) + + def __getitem__(self, key): + _dict = self.to_dict() + if "search" in _dict: + _dict["search"] = [Search.from_dict(search) for search in _dict["search"]] + if "alternatives" in _dict: + _dict["alternatives"] = [ + Alternative.from_dict(alternatives) + for alternatives in _dict["alternatives"] + ] + return _dict[key] diff --git a/deepgram/clients/common/v1/websocket_response.py b/deepgram/clients/common/v1/websocket_response.py new file mode 100644 index 00000000..63d7c016 --- /dev/null +++ b/deepgram/clients/common/v1/websocket_response.py @@ -0,0 +1,64 @@ +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +from typing import List, Optional, Dict, Any + +from dataclasses import dataclass, field +from dataclasses_json import config as dataclass_config + +from .shared_response import BaseResponse + + +# Result Message + + +@dataclass +class OpenResponse(BaseResponse): + """ + Open Message from the Deepgram Platform + """ + + type: str = "" + + +# Close Message + + +@dataclass +class CloseResponse(BaseResponse): + """ + Close Message from the Deepgram Platform + """ + + type: str = "" + + +# Error Message + + +@dataclass +class ErrorResponse(BaseResponse): + """ + Error Message from the Deepgram Platform + """ + + description: str = "" + message: str = "" + type: str = "" + variant: Optional[str] = field( + default=None, metadata=dataclass_config(exclude=lambda f: f is None) + ) + + +# Unhandled Message + + +@dataclass +class UnhandledResponse(BaseResponse): + """ + Unhandled Message from the Deepgram Platform + """ + + type: str = "" + raw: str = "" diff --git a/deepgram/clients/listen/__init__.py b/deepgram/clients/listen/__init__.py index 980199ae..ff19b5a7 100644 --- a/deepgram/clients/listen/__init__.py +++ b/deepgram/clients/listen/__init__.py @@ -13,22 +13,63 @@ ) # rest +# common +from .client import ( + UrlSource, + TextSource, + BufferSource, + StreamSource, + FileSource, +) + ## input from .client import ( ListenRESTOptions, PrerecordedOptions, PreRecordedStreamSource, - UrlSource, - FileSource, PrerecordedSource, ListenRestSource, ) ## output from .client import ( + # top level AsyncPrerecordedResponse, PrerecordedResponse, SyncPrerecordedResponse, + # shared + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, + Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, + # between rest and websocket + ModelInfo, + Alternative, + Hit, + Search, + Channel, + Word, + # unique + Entity, + ListenRESTMetadata, + Paragraph, + Paragraphs, + ListenRESTResults, + Sentence, + Summaries, + SummaryV1, + SummaryV2, + Translation, + Utterance, + Warning, ) @@ -41,14 +82,18 @@ ## output from .client import ( - OpenResponse, + # top level LiveResultResponse, - MetadataResponse, + ListenWSMetadataResponse, SpeechStartedResponse, UtteranceEndResponse, + # common websocket response + OpenResponse, CloseResponse, ErrorResponse, UnhandledResponse, + # unique + ListenWSMetadata, ) # clients diff --git a/deepgram/clients/listen/client.py b/deepgram/clients/listen/client.py index 0914d0cc..71e69cdf 100644 --- a/deepgram/clients/listen/client.py +++ b/deepgram/clients/listen/client.py @@ -14,6 +14,9 @@ from .v1 import ( UrlSource as UrlSourceLatest, + TextSource as TextSourceLatest, + BufferSource as BufferSourceLatest, + StreamSource as StreamSourceLatest, FileSource as FileSourceLatest, PreRecordedStreamSource as PreRecordedStreamSourceLatest, PrerecordedSource as PrerecordedSourceLatest, @@ -23,6 +26,39 @@ AsyncPrerecordedResponse as AsyncPrerecordedResponseLatest, PrerecordedResponse as PrerecordedResponseLatest, SyncPrerecordedResponse as SyncPrerecordedResponseLatest, + # shared + Average as AverageLatest, + Intent as IntentLatest, + Intents as IntentsLatest, + IntentsInfo as IntentsInfoLatest, + Segment as SegmentLatest, + SentimentInfo as SentimentInfoLatest, + Sentiment as SentimentLatest, + Sentiments as SentimentsLatest, + SummaryInfo as SummaryInfoLatest, + Topic as TopicLatest, + Topics as TopicsLatest, + TopicsInfo as TopicsInfoLatest, + # between rest and websocket + ModelInfo as ModelInfoLatest, + Alternative as AlternativeLatest, + Hit as HitLatest, + Search as SearchLatest, + Channel as ChannelLatest, + Word as WordLatest, + # unique + ListenRESTMetadata as ListenRESTMetadataLatest, + Entity as EntityLatest, + Paragraph as ParagraphLatest, + Paragraphs as ParagraphsLatest, + ListenRESTResults as ListenRESTResultsLatest, + Sentence as SentenceLatest, + Summaries as SummariesLatest, + SummaryV1 as SummaryV1Latest, + SummaryV2 as SummaryV2Latest, + Translation as TranslationLatest, + Utterance as UtteranceLatest, + Warning as WarningLatest, ) # websocket @@ -37,17 +73,46 @@ from .v1 import ( OpenResponse as OpenResponseLatest, LiveResultResponse as LiveResultResponseLatest, - MetadataResponse as MetadataResponseLatest, + ListenWSMetadataResponse as ListenWSMetadataResponseLatest, SpeechStartedResponse as SpeechStartedResponseLatest, UtteranceEndResponse as UtteranceEndResponseLatest, CloseResponse as CloseResponseLatest, ErrorResponse as ErrorResponseLatest, UnhandledResponse as UnhandledResponseLatest, + ListenWSMetadata as ListenWSMetadataLatest, ) # The vX/client.py points to the current supported version in the SDK. # Older versions are supported in the SDK for backwards compatibility. +# shared +Average = AverageLatest +Intent = IntentLatest +Intents = IntentsLatest +IntentsInfo = IntentsInfoLatest +Segment = SegmentLatest +SentimentInfo = SentimentInfoLatest +Sentiment = SentimentLatest +Sentiments = SentimentsLatest +SummaryInfo = SummaryInfoLatest +Topic = TopicLatest +Topics = TopicsLatest +TopicsInfo = TopicsInfoLatest + +# between rest and websocket +Alternative = AlternativeLatest +Channel = ChannelLatest +Hit = HitLatest +ModelInfo = ModelInfoLatest +Search = SearchLatest +Word = WordLatest + +# websocket common +OpenResponse = OpenResponseLatest +CloseResponse = CloseResponseLatest +ErrorResponse = ErrorResponseLatest +UnhandledResponse = UnhandledResponseLatest + # backward compat PreRecordedClient = ListenRESTClientLatest @@ -56,12 +121,17 @@ AsyncLiveClient = ListenWebSocketClientLatest # rest -## input +## common +UrlSource = UrlSourceLatest +TextSource = TextSourceLatest +BufferSource = BufferSourceLatest +StreamSource = StreamSourceLatest +FileSource = FileSourceLatest + +# input ListenRESTOptions = ListenRESTOptionsLatest PrerecordedOptions = PrerecordedOptionsLatest PreRecordedStreamSource = PreRecordedStreamSourceLatest -UrlSource = UrlSourceLatest -FileSource = FileSourceLatest PrerecordedSource = PrerecordedSourceLatest ListenRestSource = ListenRestSourceLatest @@ -69,7 +139,19 @@ AsyncPrerecordedResponse = AsyncPrerecordedResponseLatest PrerecordedResponse = PrerecordedResponseLatest SyncPrerecordedResponse = SyncPrerecordedResponseLatest - +# unique +Entity = EntityLatest +ListenRESTMetadata = ListenRESTMetadataLatest +Paragraph = ParagraphLatest +Paragraphs = ParagraphsLatest +ListenRESTResults = ListenRESTResultsLatest +Sentence = SentenceLatest +Summaries = SummariesLatest +SummaryV1 = SummaryV1Latest +SummaryV2 = SummaryV2Latest +Translation = TranslationLatest +Utterance = UtteranceLatest +Warning = WarningLatest # websocket ## input @@ -77,14 +159,13 @@ LiveOptions = LiveOptionsLatest ## output -OpenResponse = OpenResponseLatest LiveResultResponse = LiveResultResponseLatest -MetadataResponse = MetadataResponseLatest +ListenWSMetadataResponse = ListenWSMetadataResponseLatest SpeechStartedResponse = SpeechStartedResponseLatest UtteranceEndResponse = UtteranceEndResponseLatest -CloseResponse = CloseResponseLatest -ErrorResponse = ErrorResponseLatest -UnhandledResponse = UnhandledResponseLatest + +## unique +ListenWSMetadata = ListenWSMetadataLatest # clients diff --git a/deepgram/clients/listen/v1/__init__.py b/deepgram/clients/listen/v1/__init__.py index 290a5086..455d0019 100644 --- a/deepgram/clients/listen/v1/__init__.py +++ b/deepgram/clients/listen/v1/__init__.py @@ -12,32 +12,117 @@ AsyncListenWebSocketClient as AsyncLiveClient, ) +# shared +from ...common import ( + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, + Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, +) + +# between rest and websocket +from ...common import ( + ModelInfo, + Alternative, + Hit, + Search, + Channel, + Word, +) + +# common websocket +from ...common import ( + OpenResponse, + CloseResponse, + UnhandledResponse, + ErrorResponse, +) + # rest from .rest import ListenRESTClient, AsyncListenRESTClient from .rest import ListenRESTOptions, PrerecordedOptions from .rest import ( + # common UrlSource, + BufferSource, + StreamSource, + TextSource, FileSource, + # unique PreRecordedStreamSource, PrerecordedSource, ListenRestSource, ) from .rest import ( + #### top level AsyncPrerecordedResponse, PrerecordedResponse, SyncPrerecordedResponse, + #### shared + # Average, + # Intent, + # Intents, + # IntentsInfo, + # Segment, + # SentimentInfo, + # Sentiment, + # Sentiments, + # SummaryInfo, + # Topic, + # Topics, + # TopicsInfo, + #### between rest and websocket + # ModelInfo, + # Alternative, + # Hit, + # Search, + # Channel, + # Word, + #### unique + Entity, + Metadata as ListenRESTMetadata, + Paragraph, + Paragraphs, + Results as ListenRESTResults, + Sentence, + Summaries, + SummaryV1, + SummaryV2, + Translation, + Utterance, + Warning, ) # websocket from .websocket import ListenWebSocketClient, AsyncListenWebSocketClient from .websocket import LiveOptions, ListenWebSocketOptions from .websocket import ( - OpenResponse, + #### top level LiveResultResponse, - MetadataResponse, + MetadataResponse as ListenWSMetadataResponse, SpeechStartedResponse, UtteranceEndResponse, - CloseResponse, - ErrorResponse, - UnhandledResponse, + #### common websocket response + # BaseResponse, + # OpenResponse, + # CloseResponse, + # ErrorResponse, + # UnhandledResponse, + #### between rest and websocket + # ModelInfo, + # Alternative, + # Hit, + # Search, + # Channel, + # Word, + #### unique + Metadata as ListenWSMetadata, ) diff --git a/deepgram/clients/listen/v1/rest/__init__.py b/deepgram/clients/listen/v1/rest/__init__.py index 2b7989a2..088d3f74 100644 --- a/deepgram/clients/listen/v1/rest/__init__.py +++ b/deepgram/clients/listen/v1/rest/__init__.py @@ -7,15 +7,53 @@ from .options import ( ListenRESTOptions, PrerecordedOptions, - FileSource, + # common UrlSource, + BufferSource, + StreamSource, + TextSource, + FileSource, + # unique PreRecordedStreamSource, PrerecordedSource, ListenRestSource, ) from .response import ( + # top level AsyncPrerecordedResponse, PrerecordedResponse, SyncPrerecordedResponse, + # shared + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, + # between rest and websocket + ModelInfo, + Alternative, + Hit, + Search, + Channel, + Word, + # unique + Entity, + Metadata, + Paragraph, + Paragraphs, + Results, + Sentence, + Summaries, + SummaryV1, + SummaryV2, + Translation, + Utterance, + Warning, ) diff --git a/deepgram/clients/listen/v1/rest/async_client.py b/deepgram/clients/listen/v1/rest/async_client.py index f528c9a4..e5e01d29 100644 --- a/deepgram/clients/listen/v1/rest/async_client.py +++ b/deepgram/clients/listen/v1/rest/async_client.py @@ -38,6 +38,8 @@ def __init__(self, config: DeepgramClientOptions): self._config = config super().__init__(config) + # pylint: disable=too-many-positional-arguments + async def transcribe_url( self, source: UrlSource, @@ -341,3 +343,5 @@ async def transcribe_file_callback( self._logger.notice("transcribe_file_callback succeeded") self._logger.debug("ListenRESTClient.transcribe_file_callback LEAVE") return res + + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/listen/v1/rest/client.py b/deepgram/clients/listen/v1/rest/client.py index fdb50b34..30e15912 100644 --- a/deepgram/clients/listen/v1/rest/client.py +++ b/deepgram/clients/listen/v1/rest/client.py @@ -38,6 +38,8 @@ def __init__(self, config: DeepgramClientOptions): self._config = config super().__init__(config) + # pylint: disable=too-many-positional-arguments + def transcribe_url( self, source: UrlSource, @@ -342,3 +344,5 @@ def transcribe_file_callback( self._logger.notice("transcribe_file_callback succeeded") self._logger.debug("ListenRESTClient.transcribe_file_callback LEAVE") return res + + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/listen/v1/rest/options.py b/deepgram/clients/listen/v1/rest/options.py index 784203d9..93d3871a 100644 --- a/deepgram/clients/listen/v1/rest/options.py +++ b/deepgram/clients/listen/v1/rest/options.py @@ -6,16 +6,21 @@ import logging from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from dataclasses_json import config as dataclass_config from deepgram.utils import verboselogs -from ....common import StreamSource, UrlSource, FileSource +from ....common import ( + TextSource, + StreamSource, + BufferSource, + FileSource, + UrlSource, + BaseResponse, +) @dataclass -class PrerecordedOptions( - DataClassJsonMixin -): # pylint: disable=too-many-instance-attributes +class PrerecordedOptions(BaseResponse): # pylint: disable=too-many-instance-attributes """ Contains all the options for the PrerecordedClient. @@ -144,16 +149,6 @@ class PrerecordedOptions( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - def check(self): """ Check the options for any deprecated fields or values. @@ -175,10 +170,9 @@ def check(self): ListenRESTOptions = PrerecordedOptions -# PrerecordedSource for backwards compatibility -PreRecordedStreamSource = StreamSource - -# UrlSource -# FileSource +# unique PrerecordedSource = Union[UrlSource, FileSource] ListenRestSource = PrerecordedSource + +# PrerecordedSource for backwards compatibility +PreRecordedStreamSource = StreamSource diff --git a/deepgram/clients/listen/v1/rest/response.py b/deepgram/clients/listen/v1/rest/response.py index 7d9d478b..bbae04de 100644 --- a/deepgram/clients/listen/v1/rest/response.py +++ b/deepgram/clients/listen/v1/rest/response.py @@ -5,45 +5,34 @@ from typing import List, Optional, Dict, Any from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin - -from ....common import Sentiment - - -# Base Classes: - - -@dataclass -class BaseResponse(DataClassJsonMixin): - """ - BaseResponse class used to define the common methods and properties for all response classes. - """ - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - - def eval(self, key: str) -> str: - """ - This method is used to evaluate a key in the response object using a dot notation style method. - """ - keys = key.split(".") - result: Dict[Any, Any] = self.to_dict() - for k in keys: - if isinstance(result, dict) and k in result: - result = result[k] - elif isinstance(result, list) and k.isdigit() and int(k) < len(result): - result = result[int(k)] - else: - return "" - return str(result) - +from dataclasses_json import config as dataclass_config + +# between analyze and listen +from ....common import ( + BaseResponse, + Average, + Intent, + Intents, + IntentsInfo, + Segment, + SentimentInfo, + Sentiment, + Sentiments, + SummaryInfo, + Topic, + Topics, + TopicsInfo, +) + +# between rest and websocket +from ....common import ( + ModelInfo, + Alternative, + Channel, + Hit, + Search, + Word, +) # Async Prerecorded Response Types: @@ -60,61 +49,6 @@ class AsyncPrerecordedResponse(BaseResponse): # Prerecorded Response Types: -@dataclass -class SummaryInfo(BaseResponse): - """ - The summary information for the response. - """ - - input_tokens: int = 0 - output_tokens: int = 0 - model_uuid: str = "" - - -@dataclass -class ModelInfo(BaseResponse): - """ - The model information for the response. - """ - - name: str = "" - version: str = "" - arch: str = "" - - -@dataclass -class IntentsInfo(BaseResponse): - """ - The intents information for the response. - """ - - model_uuid: str = "" - input_tokens: int = 0 - output_tokens: int = 0 - - -@dataclass -class SentimentInfo(BaseResponse): - """ - The sentiment information for the response. - """ - - model_uuid: str = "" - input_tokens: int = 0 - output_tokens: int = 0 - - -@dataclass -class TopicsInfo(BaseResponse): - """ - The topics information for the response. - """ - - model_uuid: str = "" - input_tokens: int = 0 - output_tokens: int = 0 - - @dataclass class Metadata(BaseResponse): # pylint: disable=too-many-instance-attributes """ @@ -208,33 +142,11 @@ class SummaryV2(BaseResponse): @dataclass -class Hit(BaseResponse): - """ - The hit information for the response. - """ - - confidence: float = 0 - start: float = 0 - end: float = 0 - snippet: Optional[str] = "" - - -@dataclass -class Word(BaseResponse): # pylint: disable=too-many-instance-attributes +class ListenRestWord(Word): # pylint: disable=too-many-instance-attributes """ The word information for the response. """ - word: str = "" - start: float = 0 - end: float = 0 - confidence: float = 0 - punctuated_word: Optional[str] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - speaker: Optional[int] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) speaker_confidence: Optional[float] = field( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) @@ -244,9 +156,6 @@ class Word(BaseResponse): # pylint: disable=too-many-instance-attributes sentiment_score: Optional[float] = field( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) - language: Optional[str] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) def __getitem__(self, key): _dict = self.to_dict() @@ -340,9 +249,7 @@ class Translation(BaseResponse): @dataclass -class Warning( - DataClassJsonMixin -): # pylint: disable=used-before-assignment,redefined-builtin +class Warning(BaseResponse): # pylint: disable=used-before-assignment,redefined-builtin """ The warning information for the response. """ @@ -352,22 +259,6 @@ class Warning( message: str = "" -@dataclass -class Search(BaseResponse): - """ - The search information for the response. - """ - - query: str = "" - hits: List[Hit] = field(default_factory=list) - - def __getitem__(self, key): - _dict = self.to_dict() - if "hits" in _dict: - _dict["hits"] = [Hit.from_dict(hits) for hits in _dict["hits"]] - return _dict[key] - - @dataclass class Utterance(BaseResponse): # pylint: disable=too-many-instance-attributes """ @@ -414,14 +305,13 @@ class Entity(BaseResponse): @dataclass -class Alternative(BaseResponse): # pylint: disable=too-many-instance-attributes +class ListenRESTAlternative( + Alternative +): # pylint: disable=too-many-instance-attributes """ The alternative information for the response. """ - transcript: str = "" - confidence: float = 0 - words: List[Word] = field(default_factory=list) summaries: Optional[List[SummaryV1]] = field( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) @@ -434,9 +324,6 @@ class Alternative(BaseResponse): # pylint: disable=too-many-instance-attributes translations: Optional[List[Translation]] = field( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) - languages: Optional[List[str]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) def __getitem__(self, key): _dict = self.to_dict() @@ -461,7 +348,7 @@ def __getitem__(self, key): @dataclass -class Channel(BaseResponse): +class ListenRESTChannel(Channel): """ The channel information for the response. """ @@ -489,139 +376,6 @@ def __getitem__(self, key): return _dict[key] -@dataclass -class Intent(BaseResponse): - """ - The intent information for the response. - """ - - intent: str = "" - confidence_score: float = 0 - - -@dataclass -class Average(BaseResponse): - """ - The average information for the response. - """ - - sentiment: Sentiment - sentiment_score: float - - def __getitem__(self, key): - _dict = self.to_dict() - if "sentiment" in _dict: - _dict["sentiment"] = Sentiment.from_dict(_dict["sentiment"]) - return _dict[key] - - -@dataclass -class Topic(BaseResponse): - """ - The topic information for the response. - """ - - topic: str = "" - confidence_score: float = 0 - - -@dataclass -class Segment(BaseResponse): - """ - The segment information for the response. - """ - - text: str = "" - start_word: int = 0 - end_word: int = 0 - sentiment: Optional[Sentiment] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - sentiment_score: Optional[float] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - intents: Optional[List[Intent]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - topics: Optional[List[Topic]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - - def __getitem__(self, key): - _dict = self.to_dict() - if "sentiment" in _dict: - _dict["sentiment"] = Sentiment.from_dict(_dict["sentiment"]) - if "intents" in _dict: - _dict["intents"] = [ - Intent.from_dict(intents) for intents in _dict["intents"] - ] - if "topics" in _dict: - _dict["topics"] = [Topic.from_dict(topics) for topics in _dict["topics"]] - return _dict[key] - - -@dataclass -class Sentiments(BaseResponse): - """ - The sentiments information for the response. - """ - - segments: Optional[List[Segment]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - average: Optional[Average] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - - def __getitem__(self, key): - _dict = self.to_dict() - if "segments" in _dict: - _dict["segments"] = [ - Segment.from_dict(segments) for segments in _dict["segments"] - ] - if "average" in _dict: - _dict["average"] = Average.from_dict(_dict["average"]) - return _dict[key] - - -@dataclass -class Topics(BaseResponse): - """ - The topics information for the response. - """ - - segments: Optional[List[Segment]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - - def __getitem__(self, key): - _dict = self.to_dict() - if "segments" in _dict: - _dict["segments"] = [ - Segment.from_dict(segments) for segments in _dict["segments"] - ] - return _dict[key] - - -@dataclass -class Intents(BaseResponse): - """ - The intents information for the response. - """ - - segments: Optional[List[Segment]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - - def __getitem__(self, key): - _dict = self.to_dict() - if "segments" in _dict: - _dict["segments"] = [ - Segment.from_dict(segments) for segments in _dict["segments"] - ] - return _dict[key] - - @dataclass class Results(BaseResponse): """ diff --git a/deepgram/clients/listen/v1/websocket/__init__.py b/deepgram/clients/listen/v1/websocket/__init__.py index e1b4c515..34c37936 100644 --- a/deepgram/clients/listen/v1/websocket/__init__.py +++ b/deepgram/clients/listen/v1/websocket/__init__.py @@ -5,13 +5,27 @@ from .client import ListenWebSocketClient from .async_client import AsyncListenWebSocketClient from .options import LiveOptions, ListenWebSocketOptions + +# unique websocket response from .response import ( - OpenResponse, + #### top level LiveResultResponse, MetadataResponse, SpeechStartedResponse, UtteranceEndResponse, + #### common websocket response + BaseResponse, + OpenResponse, CloseResponse, ErrorResponse, UnhandledResponse, + #### between rest and websocket + ModelInfo, + Alternative, + Hit, + Search, + Channel, + Word, + #### unique + Metadata, ) diff --git a/deepgram/clients/listen/v1/websocket/options.py b/deepgram/clients/listen/v1/websocket/options.py index 70c0671a..dd2e775b 100644 --- a/deepgram/clients/listen/v1/websocket/options.py +++ b/deepgram/clients/listen/v1/websocket/options.py @@ -6,13 +6,15 @@ import logging from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from dataclasses_json import config as dataclass_config from deepgram.utils import verboselogs +from ....common import BaseResponse + @dataclass -class LiveOptions(DataClassJsonMixin): # pylint: disable=too-many-instance-attributes +class LiveOptions(BaseResponse): # pylint: disable=too-many-instance-attributes """ Live Transcription Options for the Deepgram Platform. @@ -118,16 +120,6 @@ class LiveOptions(DataClassJsonMixin): # pylint: disable=too-many-instance-attr default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - def check(self): """ Check the options for any deprecated or soon-to-be-deprecated options. diff --git a/deepgram/clients/listen/v1/websocket/response.py b/deepgram/clients/listen/v1/websocket/response.py index 84de8d07..a26a31c6 100644 --- a/deepgram/clients/listen/v1/websocket/response.py +++ b/deepgram/clients/listen/v1/websocket/response.py @@ -5,154 +5,28 @@ from typing import List, Optional, Dict, Any from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from dataclasses_json import config as dataclass_config +# common websocket response +from ....common import ( + BaseResponse, + OpenResponse, + CloseResponse, + ErrorResponse, + UnhandledResponse, +) -@dataclass -class BaseResponse(DataClassJsonMixin): - """ - BaseResponse class used to define the common methods and properties for all response classes. - """ - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - - def eval(self, key: str) -> str: - """ - This method is used to evaluate a key in the response object using a dot notation style method. - """ - keys = key.split(".") - result: Dict[Any, Any] = self.to_dict() - for k in keys: - if isinstance(result, dict) and k in result: - result = result[k] - elif isinstance(result, list) and k.isdigit() and int(k) < len(result): - result = result[int(k)] - else: - return "" - return str(result) - - -# Result Message - - -@dataclass -class OpenResponse(BaseResponse): - """ - Open Message from the Deepgram Platform - """ - - type: str = "" - - -@dataclass -class Word(BaseResponse): - """ - Word object - """ - - word: str = "" - start: float = 0 - end: float = 0 - confidence: float = 0 - punctuated_word: Optional[str] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - speaker: Optional[int] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - language: Optional[str] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - - -@dataclass -class Alternative(BaseResponse): - """ - Alternative object - """ - - transcript: str = "" - confidence: float = 0 - words: List[Word] = field(default_factory=list) - languages: Optional[List[str]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - - def __getitem__(self, key): - _dict = self.to_dict() - if "words" in _dict: - _dict["words"] = [Word.from_dict(words) for words in _dict["words"]] - return _dict[key] - - -@dataclass -class Hit(BaseResponse): - """ - The hit information for the response. - """ - - confidence: float = 0 - start: float = 0 - end: float = 0 - snippet: Optional[str] = "" - - -@dataclass -class Search(BaseResponse): - """ - The search information for the response. - """ +# between rest and websocket +from ....common import ( + ModelInfo, + Alternative, + Hit, + Search, + Channel, + Word, +) - query: str = "" - hits: List[Hit] = field(default_factory=list) - - def __getitem__(self, key): - _dict = self.to_dict() - if "hits" in _dict: - _dict["hits"] = [Hit.from_dict(hits) for hits in _dict["hits"]] - return _dict[key] - - -@dataclass -class Channel(BaseResponse): - """ - Channel object - """ - - search: Optional[List[Search]] = field( - default=None, metadata=dataclass_config(exclude=lambda f: f is None) - ) - alternatives: List[Alternative] = field(default_factory=list) - - def __getitem__(self, key): - _dict = self.to_dict() - if "search" in _dict: - _dict["search"] = [Search.from_dict(search) for search in _dict["search"]] - if "alternatives" in _dict: - _dict["alternatives"] = [ - Alternative.from_dict(alternatives) - for alternatives in _dict["alternatives"] - ] - return _dict[key] - - -@dataclass -class ModelInfo(BaseResponse): - """ - ModelInfo object - """ - - name: str = "" - version: str = "" - arch: str = "" +# unique @dataclass @@ -179,10 +53,11 @@ def __getitem__(self, key): return _dict[key] +# live result messages + + @dataclass -class LiveResultResponse( - DataClassJsonMixin -): # pylint: disable=too-many-instance-attributes +class LiveResultResponse(BaseResponse): # pylint: disable=too-many-instance-attributes """ Result Message from the Deepgram Platform """ @@ -216,9 +91,7 @@ def __getitem__(self, key): @dataclass -class MetadataResponse( - DataClassJsonMixin -): # pylint: disable=too-many-instance-attributes +class MetadataResponse(BaseResponse): # pylint: disable=too-many-instance-attributes """ Metadata Message from the Deepgram Platform """ @@ -280,43 +153,3 @@ class UtteranceEndResponse(BaseResponse): type: str = "" channel: List[int] = field(default_factory=list) last_word_end: float = 0 - - -# Close Message - - -@dataclass -class CloseResponse(BaseResponse): - """ - Close Message from the Deepgram Platform - """ - - type: str = "" - - -# Error Message - - -@dataclass -class ErrorResponse(BaseResponse): - """ - Error Message from the Deepgram Platform - """ - - description: str = "" - message: str = "" - type: str = "" - variant: Optional[str] = "" - - -# Unhandled Message - - -@dataclass -class UnhandledResponse(BaseResponse): - """ - Unhandled Message from the Deepgram Platform - """ - - type: str = "" - raw: str = "" diff --git a/deepgram/clients/live/__init__.py b/deepgram/clients/live/__init__.py index 40a6c934..e71ab007 100644 --- a/deepgram/clients/live/__init__.py +++ b/deepgram/clients/live/__init__.py @@ -10,7 +10,8 @@ from .v1 import ( OpenResponse, LiveResultResponse, - MetadataResponse, + ListenWSMetadataResponse, + MetadataResponse, # backwards compat SpeechStartedResponse, UtteranceEndResponse, CloseResponse, diff --git a/deepgram/clients/live/v1/__init__.py b/deepgram/clients/live/v1/__init__.py index 91538538..273c4d3b 100644 --- a/deepgram/clients/live/v1/__init__.py +++ b/deepgram/clients/live/v1/__init__.py @@ -10,7 +10,8 @@ from .client import ( OpenResponse, LiveResultResponse, - MetadataResponse, + ListenWSMetadataResponse, + MetadataResponse, # backwards compat SpeechStartedResponse, UtteranceEndResponse, CloseResponse, diff --git a/deepgram/clients/live/v1/client.py b/deepgram/clients/live/v1/client.py index cce54611..fd75c948 100644 --- a/deepgram/clients/live/v1/client.py +++ b/deepgram/clients/live/v1/client.py @@ -8,7 +8,7 @@ from ...listen.v1 import ( OpenResponse as OpenResponseLatest, LiveResultResponse as LiveResultResponseLatest, - MetadataResponse as MetadataResponseLatest, + ListenWSMetadataResponse as ListenWSMetadataResponseLatest, SpeechStartedResponse as SpeechStartedResponseLatest, UtteranceEndResponse as UtteranceEndResponseLatest, CloseResponse as CloseResponseLatest, @@ -24,7 +24,8 @@ LiveOptions = LiveOptionsLatest OpenResponse = OpenResponseLatest LiveResultResponse = LiveResultResponseLatest -MetadataResponse = MetadataResponseLatest +ListenWSMetadataResponse = ListenWSMetadataResponseLatest +MetadataResponse = ListenWSMetadataResponseLatest SpeechStartedResponse = SpeechStartedResponseLatest UtteranceEndResponse = UtteranceEndResponseLatest CloseResponse = CloseResponseLatest diff --git a/deepgram/clients/manage/__init__.py b/deepgram/clients/manage/__init__.py index e4489eec..8a4287ae 100644 --- a/deepgram/clients/manage/__init__.py +++ b/deepgram/clients/manage/__init__.py @@ -14,21 +14,40 @@ UsageFieldsOptions, ) from .client import ( + #### top level Message, - Project, ProjectsResponse, + ModelResponse, + ModelsResponse, MembersResponse, - Key, KeyResponse, KeysResponse, ScopesResponse, InvitesResponse, UsageRequest, + UsageResponse, UsageRequestsResponse, UsageSummaryResponse, UsageFieldsResponse, - Balance, BalancesResponse, - ModelResponse, - ModelsResponse, + #### shared + Project, + STTDetails, + TTSMetadata, + TTSDetails, + Member, + Key, + Invite, + Config, + STTUsageDetails, + Callback, + TokenDetail, + SpeechSegment, + TTSUsageDetails, + STTTokens, + TTSTokens, + UsageSummaryResults, + Resolution, + UsageModel, + Balance, ) diff --git a/deepgram/clients/manage/client.py b/deepgram/clients/manage/client.py index 57a581aa..8238cd7a 100644 --- a/deepgram/clients/manage/client.py +++ b/deepgram/clients/manage/client.py @@ -19,22 +19,39 @@ # responses from .v1.response import ( Message as MessageLatest, - Project as ProjectLatest, ProjectsResponse as ProjectsResponseLatest, + ModelResponse as ModelResponseLatest, + ModelsResponse as ModelsResponseLatest, MembersResponse as MembersResponseLatest, - Key as KeyLatest, KeyResponse as KeyResponseLatest, KeysResponse as KeysResponseLatest, ScopesResponse as ScopesResponseLatest, InvitesResponse as InvitesResponseLatest, UsageRequest as UsageRequestLatest, + UsageResponse as UsageResponseLatest, UsageRequestsResponse as UsageRequestsResponseLatest, UsageSummaryResponse as UsageSummaryResponseLatest, UsageFieldsResponse as UsageFieldsResponseLatest, - Balance as BalanceLatest, BalancesResponse as BalancesResponseLatest, - ModelResponse as ModelResponseLatest, - ModelsResponse as ModelsResponseLatest, + Project as ProjectLatest, + STTDetails as STTDetailsLatest, + TTSMetadata as TTSMetadataLatest, + TTSDetails as TTSDetailsLatest, + Member as MemberLatest, + Key as KeyLatest, + Invite as InviteLatest, + Config as ConfigLatest, + STTUsageDetails as STTUsageDetailsLatest, + Callback as CallbackLatest, + TokenDetail as TokenDetailLatest, + SpeechSegment as SpeechSegmentLatest, + TTSUsageDetails as TTSUsageDetailsLatest, + STTTokens as STTTokensLatest, + TTSTokens as TTSTokensLatest, + UsageSummaryResults as UsageSummaryResultsLatest, + Resolution as ResolutionLatest, + UsageModel as UsageModelLatest, + Balance as BalanceLatest, ) @@ -54,22 +71,39 @@ # responses Message = MessageLatest -Project = ProjectLatest ProjectsResponse = ProjectsResponseLatest +ModelResponse = ModelResponseLatest +ModelsResponse = ModelsResponseLatest MembersResponse = MembersResponseLatest -Key = KeyLatest KeyResponse = KeyResponseLatest KeysResponse = KeysResponseLatest ScopesResponse = ScopesResponseLatest InvitesResponse = InvitesResponseLatest UsageRequest = UsageRequestLatest +UsageResponse = UsageResponseLatest UsageRequestsResponse = UsageRequestsResponseLatest UsageSummaryResponse = UsageSummaryResponseLatest UsageFieldsResponse = UsageFieldsResponseLatest -Balance = BalanceLatest BalancesResponse = BalancesResponseLatest -ModelResponse = ModelResponseLatest -ModelsResponse = ModelsResponseLatest +Project = ProjectLatest +STTDetails = STTDetailsLatest +TTSMetadata = TTSMetadataLatest +TTSDetails = TTSDetailsLatest +Member = MemberLatest +Key = KeyLatest +Invite = InviteLatest +Config = ConfigLatest +STTUsageDetails = STTUsageDetailsLatest +Callback = CallbackLatest +TokenDetail = TokenDetailLatest +SpeechSegment = SpeechSegmentLatest +TTSUsageDetails = TTSUsageDetailsLatest +STTTokens = STTTokensLatest +TTSTokens = TTSTokensLatest +UsageSummaryResults = UsageSummaryResultsLatest +Resolution = ResolutionLatest +UsageModel = UsageModelLatest +Balance = BalanceLatest # clients ManageClient = ManageClientLatest diff --git a/deepgram/clients/manage/v1/__init__.py b/deepgram/clients/manage/v1/__init__.py index 8fdff843..0373a56e 100644 --- a/deepgram/clients/manage/v1/__init__.py +++ b/deepgram/clients/manage/v1/__init__.py @@ -13,23 +13,42 @@ UsageSummaryOptions, UsageFieldsOptions, ) + from .response import ( + #### top level Message, - Project, ProjectsResponse, + ModelResponse, + ModelsResponse, MembersResponse, - Key, KeyResponse, KeysResponse, ScopesResponse, InvitesResponse, UsageRequest, + UsageResponse, UsageRequestsResponse, UsageSummaryResponse, UsageFieldsResponse, - Balance, BalancesResponse, - ModelResponse, - ModelsResponse, + #### shared + Project, + STTDetails, + TTSMetadata, + TTSDetails, + Member, + Key, + Invite, + Config, + STTUsageDetails, + Callback, + TokenDetail, + SpeechSegment, + TTSUsageDetails, + STTTokens, + TTSTokens, + UsageSummaryResults, + Resolution, + UsageModel, + Balance, ) -from ....options import DeepgramClientOptions, ClientOptionsFromEnv diff --git a/deepgram/clients/manage/v1/async_client.py b/deepgram/clients/manage/v1/async_client.py index d4f93936..1d7e7a86 100644 --- a/deepgram/clients/manage/v1/async_client.py +++ b/deepgram/clients/manage/v1/async_client.py @@ -71,6 +71,8 @@ def __init__(self, config: DeepgramClientOptions): self._endpoint = "v1/projects" super().__init__(config) + # pylint: disable=too-many-positional-arguments + # projects async def list_projects( self, @@ -1161,3 +1163,5 @@ async def get_balance( self._logger.notice("get_balance succeeded") self._logger.debug("ManageClient.get_balance LEAVE") return res + + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/manage/v1/client.py b/deepgram/clients/manage/v1/client.py index 4696aa45..24b4a1d8 100644 --- a/deepgram/clients/manage/v1/client.py +++ b/deepgram/clients/manage/v1/client.py @@ -87,6 +87,8 @@ def list_projects( timeout=timeout, addons=addons, headers=headers, **kwargs ) + # pylint: disable=too-many-positional-arguments + def get_projects( self, timeout: Optional[httpx.Timeout] = None, @@ -1164,3 +1166,5 @@ def get_balance( self._logger.notice("get_balance succeeded") self._logger.debug("ManageClient.get_balance LEAVE") return res + + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/manage/v1/options.py b/deepgram/clients/manage/v1/options.py index 4b0653ab..34fbf876 100644 --- a/deepgram/clients/manage/v1/options.py +++ b/deepgram/clients/manage/v1/options.py @@ -5,51 +5,33 @@ from typing import List, Optional from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from dataclasses_json import config as dataclass_config + +from ...common import BaseResponse # Input @dataclass -class ProjectOptions(DataClassJsonMixin): +class ProjectOptions(BaseResponse): """ Project Options """ name: str = "" - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class ModelOptions(DataClassJsonMixin): +class ModelOptions(BaseResponse): """ Model Options """ include_outdated: bool = False - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class KeyOptions(DataClassJsonMixin): +class KeyOptions(BaseResponse): """ Key Options """ @@ -74,34 +56,18 @@ def __getitem__(self, key): _dict["tags"] = [str(tags) for tags in _dict["tags"]] return _dict[key] - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class ScopeOptions(DataClassJsonMixin): +class ScopeOptions(BaseResponse): """ Scope Options """ scope: str = "" - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class InviteOptions(DataClassJsonMixin): +class InviteOptions(BaseResponse): """ Invite Options """ @@ -109,19 +75,9 @@ class InviteOptions(DataClassJsonMixin): email: str = "" scope: str = "" - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class UsageRequestOptions(DataClassJsonMixin): +class UsageRequestOptions(BaseResponse): """ Usage Request Options """ @@ -139,21 +95,9 @@ class UsageRequestOptions(DataClassJsonMixin): default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class UsageSummaryOptions( - DataClassJsonMixin -): # pylint: disable=too-many-instance-attributes +class UsageSummaryOptions(BaseResponse): # pylint: disable=too-many-instance-attributes """ Usage Summary Options """ @@ -222,32 +166,12 @@ class UsageSummaryOptions( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class UsageFieldsOptions(DataClassJsonMixin): +class UsageFieldsOptions(BaseResponse): """ Usage Fields Options """ start: Optional[str] = "" end: Optional[str] = "" - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) diff --git a/deepgram/clients/manage/v1/response.py b/deepgram/clients/manage/v1/response.py index 486fb860..ef6824f4 100644 --- a/deepgram/clients/manage/v1/response.py +++ b/deepgram/clients/manage/v1/response.py @@ -5,39 +5,11 @@ from typing import List, Optional, Dict, Any from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from dataclasses_json import config as dataclass_config - -@dataclass -class BaseResponse(DataClassJsonMixin): - """ - BaseResponse class used to define the common methods and properties for all response classes. - """ - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - - def eval(self, key: str) -> str: - """ - This method is used to evaluate a key in the response object using a dot notation style method. - """ - keys = key.split(".") - result: Dict[Any, Any] = self.to_dict() - for k in keys: - if isinstance(result, dict) and k in result: - result = result[k] - elif isinstance(result, list) and k.isdigit() and int(k) < len(result): - result = result[int(k)] - else: - return "" - return str(result) +from ...common import ( + BaseResponse, +) # Result Message @@ -86,9 +58,9 @@ def __getitem__(self, key): @dataclass -class Stt(BaseResponse): # pylint: disable=too-many-instance-attributes +class STTDetails(BaseResponse): # pylint: disable=too-many-instance-attributes """ - STT class used to define the properties of the Speech-to-Text model response object. + STTDetails class used to define the properties of the Speech-to-Text model response object. """ name: str = "" @@ -109,9 +81,9 @@ def __getitem__(self, key): @dataclass -class Metadata(BaseResponse): +class TTSMetadata(BaseResponse): """ - Metadata class used to define the properties for a given STT or TTS model. + TTSMetadata class used to define the properties for a given STT or TTS model. """ accent: str = "" @@ -124,9 +96,9 @@ class Metadata(BaseResponse): @dataclass -class Tts(BaseResponse): +class TTSDetails(BaseResponse): """ - TTS class used to define the properties of the Text-to-Speech model response object. + TTSDetails class used to define the properties of the Text-to-Speech model response object. """ name: str = "" @@ -135,7 +107,7 @@ class Tts(BaseResponse): languages: List[str] = field(default_factory=list) version: str = "" uuid: str = "" - metadata: Optional[Metadata] = field( + metadata: Optional[TTSMetadata] = field( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) @@ -143,7 +115,7 @@ def __getitem__(self, key): _dict = self.to_dict() if "metadata" in _dict: _dict["metadata"] = [ - Metadata.from_dict(metadata) for metadata in _dict["metadata"] + TTSMetadata.from_dict(metadata) for metadata in _dict["metadata"] ] return _dict[key] @@ -163,7 +135,7 @@ class ModelResponse(BaseResponse): language: str = "" version: str = "" uuid: str = "" - metadata: Optional[Metadata] = field( + metadata: Optional[TTSMetadata] = field( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) @@ -171,7 +143,7 @@ def __getitem__(self, key): _dict = self.to_dict() if "metadata" in _dict: _dict["metadata"] = [ - Metadata.from_dict(metadata) for metadata in _dict["metadata"] + TTSMetadata.from_dict(metadata) for metadata in _dict["metadata"] ] return _dict[key] @@ -182,15 +154,15 @@ class ModelsResponse(BaseResponse): ModelsResponse class used to obtain a list of models. """ - stt: List[Stt] = field(default_factory=list) - tts: List[Tts] = field(default_factory=list) + stt: List[STTDetails] = field(default_factory=list) + tts: List[TTSDetails] = field(default_factory=list) def __getitem__(self, key): _dict = self.to_dict() if "stt" in _dict: - _dict["stt"] = [Stt.from_dict(stt) for stt in _dict["stt"]] + _dict["stt"] = [STTDetails.from_dict(stt) for stt in _dict["stt"]] if "tts" in _dict: - _dict["tts"] = [Tts.from_dict(tts) for tts in _dict["tts"]] + _dict["tts"] = [TTSDetails.from_dict(tts) for tts in _dict["tts"]] return _dict[key] @@ -377,7 +349,7 @@ class Config(BaseResponse): # pylint: disable=too-many-instance-attributes @dataclass -class Details(BaseResponse): # pylint: disable=too-many-instance-attributes +class STTUsageDetails(BaseResponse): # pylint: disable=too-many-instance-attributes """ Details object """ @@ -452,7 +424,7 @@ class SpeechSegment(BaseResponse): @dataclass -class TTSDetails(BaseResponse): +class TTSUsageDetails(BaseResponse): """ TTS Details object """ @@ -474,12 +446,12 @@ def __getitem__(self, key): @dataclass -class Response(BaseResponse): +class UsageResponse(BaseResponse): """ - Response object + UsageResponse object """ - details: Optional[Details] = field( + details: Optional[STTUsageDetails] = field( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) code: int = 0 @@ -487,7 +459,7 @@ class Response(BaseResponse): message: Optional[str] = field( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) - tts_details: Optional[TTSDetails] = field( + tts_details: Optional[TTSUsageDetails] = field( default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) token_details: List[TokenDetail] = field( @@ -497,9 +469,9 @@ class Response(BaseResponse): def __getitem__(self, key): _dict = self.to_dict() if "details" in _dict: - _dict["details"] = Details.from_dict(_dict["details"]) + _dict["details"] = STTUsageDetails.from_dict(_dict["details"]) if "tts_details" in _dict: - _dict["tts_details"] = TTSDetails.from_dict(_dict["tts_details"]) + _dict["tts_details"] = TTSUsageDetails.from_dict(_dict["tts_details"]) if "token_details" in _dict: _dict["token_details"] = [ TokenDetail.from_dict(token_details) @@ -514,7 +486,7 @@ class UsageRequest(BaseResponse): # pylint: disable=too-many-instance-attribute Usage Request object """ - response: Response + response: UsageResponse project_uuid: str = "" request_id: str = "" created: str = "" @@ -530,7 +502,7 @@ class UsageRequest(BaseResponse): # pylint: disable=too-many-instance-attribute def __getitem__(self, key): _dict = self.to_dict() if "response" in _dict: - _dict["response"] = Response.from_dict(_dict["response"]) + _dict["response"] = UsageResponse.from_dict(_dict["response"]) if "callback" in _dict: _dict["callback"] = Callback.from_dict(_dict["callback"]) return _dict[key] @@ -556,9 +528,9 @@ def __getitem__(self, key): @dataclass -class Tokens(BaseResponse): +class STTTokens(BaseResponse): """ - Tokens object + STTTokens object """ tokens_in: int = 0 @@ -566,9 +538,9 @@ class Tokens(BaseResponse): @dataclass -class TTS(BaseResponse): +class TTSTokens(BaseResponse): """ - TTS object + TTSTokens object """ characters: int = 0 @@ -576,13 +548,13 @@ class TTS(BaseResponse): @dataclass -class Results(BaseResponse): +class UsageSummaryResults(BaseResponse): """ Results object """ - tokens: Tokens - tts: TTS + tokens: STTTokens + tts: TTSTokens start: str = "" end: str = "" hours: int = 0 @@ -592,9 +564,9 @@ class Results(BaseResponse): def __getitem__(self, key): _dict = self.to_dict() if "tokens" in _dict: - _dict["tokens"] = Tokens.from_dict(_dict["tokens"]) + _dict["tokens"] = STTTokens.from_dict(_dict["tokens"]) if "tts" in _dict: - _dict["tts"] = TTS.from_dict(_dict["tts"]) + _dict["tts"] = TTSTokens.from_dict(_dict["tts"]) return _dict[key] @@ -617,7 +589,7 @@ class UsageSummaryResponse(BaseResponse): resolution: Resolution start: str = "" end: str = "" - results: List[Results] = field(default_factory=list) + results: List[UsageSummaryResults] = field(default_factory=list) def __getitem__(self, key): _dict = self.to_dict() @@ -625,7 +597,7 @@ def __getitem__(self, key): _dict["resolution"] = Resolution.from_dict(_dict["resolution"]) if "results" in _dict: _dict["results"] = [ - Results.from_dict(results) for results in _dict["results"] + UsageSummaryResults.from_dict(results) for results in _dict["results"] ] return _dict[key] diff --git a/deepgram/clients/speak/__init__.py b/deepgram/clients/speak/__init__.py index 8f1f01eb..874a1739 100644 --- a/deepgram/clients/speak/__init__.py +++ b/deepgram/clients/speak/__init__.py @@ -4,32 +4,50 @@ from .enums import SpeakWebSocketEvents, SpeakWebSocketMessage +# rest from .client import ( SpeakClient, # backward compat SpeakRESTClient, AsyncSpeakRESTClient, - SpeakWebSocketClient, - AsyncSpeakWebSocketClient, - SpeakWSClient, - AsyncSpeakWSClient, ) from .client import ( - SpeakOptions, + #### top level SpeakRESTOptions, - SpeakWSOptions, + SpeakOptions, + # common + TextSource, + BufferSource, + StreamSource, FileSource, - SpeakRestSource, + # unique SpeakSource, + SpeakRestSource, + SpeakRESTSource, ) from .client import ( SpeakResponse, # backward compat SpeakRESTResponse, - OpenResponse, - MetadataResponse, +) + +# websocket +from .client import ( + SpeakWSOptions, +) +from .client import ( + SpeakWebSocketClient, + AsyncSpeakWebSocketClient, + SpeakWSClient, + AsyncSpeakWSClient, +) +from .client import ( + #### top level + SpeakWSMetadataResponse, FlushedResponse, ClearedResponse, + WarningResponse, + #### shared + OpenResponse, CloseResponse, UnhandledResponse, - WarningResponse, ErrorResponse, ) diff --git a/deepgram/clients/speak/client.py b/deepgram/clients/speak/client.py index 1a31393b..855555c6 100644 --- a/deepgram/clients/speak/client.py +++ b/deepgram/clients/speak/client.py @@ -2,26 +2,45 @@ # Use of this source code is governed by a MIT license that can be found in the LICENSE file. # SPDX-License-Identifier: MIT +# rest +from .v1 import ( + #### top level + SpeakOptions as SpeakOptionsLatest, + SpeakRESTOptions as SpeakRESTOptionsLatest, + # common + TextSource as TextSourceLatest, + BufferSource as BufferSourceLatest, + StreamSource as StreamSourceLatest, + FileSource as FileSourceLatest, + # unique + SpeakSource as SpeakSourceLatest, + SpeakRestSource as SpeakRestSourceLatest, + SpeakRESTSource as SpeakRESTSourceLatest, +) + from .v1 import ( SpeakRESTClient as SpeakRESTClientLatest, AsyncSpeakRESTClient as AsyncSpeakRESTClientLatest, +) + +from .v1 import ( + SpeakRESTResponse as SpeakRESTResponseLatest, +) + +# websocket +from .v1 import ( SpeakWebSocketClient as SpeakWebSocketClientLatest, AsyncSpeakWebSocketClient as AsyncSpeakWebSocketClientLatest, SpeakWSClient as SpeakWSClientLatest, AsyncSpeakWSClient as AsyncSpeakWSClientLatest, ) + from .v1 import ( - SpeakOptions as SpeakOptionsLatest, - SpeakRESTOptions as SpeakRESTOptionsLatest, SpeakWSOptions as SpeakWSOptionsLatest, - FileSource as FileSourceLatest, - SpeakRestSource as SpeakRestSourceLatest, - SpeakSource as SpeakSourceLatest, ) from .v1 import ( - SpeakRESTResponse as SpeakRESTResponseLatest, OpenResponse as OpenResponseLatest, - MetadataResponse as MetadataResponseLatest, + SpeakWSMetadataResponse as SpeakWSMetadataResponseLatest, FlushedResponse as FlushedResponseLatest, ClearedResponse as ClearedResponseLatest, CloseResponse as CloseResponseLatest, @@ -33,19 +52,28 @@ # The client.py points to the current supported version in the SDK. # Older versions are supported in the SDK for backwards compatibility. - +# rest # input SpeakOptions = SpeakOptionsLatest SpeakRESTOptions = SpeakRESTOptionsLatest -SpeakWSOptions = SpeakWSOptionsLatest -SpeakRestSource = SpeakRestSourceLatest +TextSource = TextSourceLatest +BufferSource = BufferSourceLatest +StreamSource = StreamSourceLatest FileSource = FileSourceLatest SpeakSource = SpeakSourceLatest +SpeakRestSource = SpeakRestSourceLatest +SpeakRESTSource = SpeakRESTSourceLatest # pylint: disable=invalid-name # output SpeakRESTResponse = SpeakRESTResponseLatest + +# websocket +# input +SpeakWSOptions = SpeakWSOptionsLatest + +# output OpenResponse = OpenResponseLatest -MetadataResponse = MetadataResponseLatest +SpeakWSMetadataResponse = SpeakWSMetadataResponseLatest FlushedResponse = FlushedResponseLatest ClearedResponse = ClearedResponseLatest CloseResponse = CloseResponseLatest diff --git a/deepgram/clients/speak/v1/__init__.py b/deepgram/clients/speak/v1/__init__.py index 67091756..d878cc5a 100644 --- a/deepgram/clients/speak/v1/__init__.py +++ b/deepgram/clients/speak/v1/__init__.py @@ -2,23 +2,32 @@ # Use of this source code is governed by a MIT license that can be found in the LICENSE file. # SPDX-License-Identifier: MIT +# rest from .rest import ( + #### top level SpeakRESTOptions, SpeakOptions, - SpeakRestSource, - SpeakSource, + # common + TextSource, + BufferSource, + StreamSource, FileSource, + # unique + SpeakSource, + SpeakRestSource, + SpeakRESTSource, ) -from .websocket import ( - SpeakWSOptions, +from .rest import ( + SpeakRESTOptions, + SpeakOptions, ) - -# rest from .rest import SpeakRESTClient, AsyncSpeakRESTClient - from .rest import SpeakRESTResponse # websocket +from .websocket import ( + SpeakWSOptions, +) from .websocket import ( SpeakWebSocketClient, AsyncSpeakWebSocketClient, @@ -26,12 +35,14 @@ AsyncSpeakWSClient, ) from .websocket import ( - OpenResponse, - MetadataResponse, + #### top level + MetadataResponse as SpeakWSMetadataResponse, FlushedResponse, ClearedResponse, + WarningResponse, + #### shared + OpenResponse, CloseResponse, UnhandledResponse, - WarningResponse, ErrorResponse, ) diff --git a/deepgram/clients/speak/v1/rest/__init__.py b/deepgram/clients/speak/v1/rest/__init__.py index 3ac3b59c..084cef64 100644 --- a/deepgram/clients/speak/v1/rest/__init__.py +++ b/deepgram/clients/speak/v1/rest/__init__.py @@ -6,9 +6,16 @@ from .async_client import AsyncSpeakRESTClient from .response import SpeakRESTResponse from .options import ( + #### top level SpeakRESTOptions, SpeakOptions, + # common + TextSource, + BufferSource, + StreamSource, + FileSource, + # unique SpeakSource, SpeakRestSource, - FileSource, + SpeakRESTSource, ) diff --git a/deepgram/clients/speak/v1/rest/async_client.py b/deepgram/clients/speak/v1/rest/async_client.py index be32b96b..7f6c2064 100644 --- a/deepgram/clients/speak/v1/rest/async_client.py +++ b/deepgram/clients/speak/v1/rest/async_client.py @@ -38,6 +38,8 @@ def __init__(self, config: DeepgramClientOptions): self._config = config super().__init__(config) + # pylint: disable=too-many-positional-arguments + async def stream_raw( self, source: FileSource, @@ -303,3 +305,5 @@ async def save( self._logger.debug("AsyncSpeakClient.save LEAVE") return res + + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/speak/v1/rest/client.py b/deepgram/clients/speak/v1/rest/client.py index 85ab694d..7153ec63 100644 --- a/deepgram/clients/speak/v1/rest/client.py +++ b/deepgram/clients/speak/v1/rest/client.py @@ -37,6 +37,8 @@ def __init__(self, config: DeepgramClientOptions): self._config = config super().__init__(config) + # pylint: disable=too-many-positional-arguments + def stream_raw( self, source: FileSource, @@ -303,3 +305,5 @@ def save( self._logger.debug("SpeakClient.save LEAVE") return res + + # pylint: enable=too-many-positional-arguments diff --git a/deepgram/clients/speak/v1/rest/options.py b/deepgram/clients/speak/v1/rest/options.py index db1c1c39..504c3ae1 100644 --- a/deepgram/clients/speak/v1/rest/options.py +++ b/deepgram/clients/speak/v1/rest/options.py @@ -7,14 +7,14 @@ import logging from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from dataclasses_json import config as dataclass_config from .....utils import verboselogs -from ....common import FileSource +from ....common import TextSource, BufferSource, StreamSource, FileSource, BaseResponse @dataclass -class SpeakRESTOptions(DataClassJsonMixin): +class SpeakRESTOptions(BaseResponse): """ Contains all the options for the SpeakOptions. @@ -39,16 +39,6 @@ class SpeakRESTOptions(DataClassJsonMixin): default=None, metadata=dataclass_config(exclude=lambda f: f is None) ) - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - def check(self): """ Check the SpeakOptions for any missing or invalid values. @@ -67,5 +57,8 @@ def check(self): SpeakOptions = SpeakRESTOptions + +# unqiue SpeakSource = Union[FileSource, BufferedReader] SpeakRestSource = SpeakSource +SpeakRESTSource = SpeakSource # pylint: disable=invalid-name diff --git a/deepgram/clients/speak/v1/rest/response.py b/deepgram/clients/speak/v1/rest/response.py index 779f3bc9..30801e30 100644 --- a/deepgram/clients/speak/v1/rest/response.py +++ b/deepgram/clients/speak/v1/rest/response.py @@ -6,42 +6,11 @@ import io from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from dataclasses_json import config as dataclass_config - -# Base Classes: - - -@dataclass -class BaseResponse(DataClassJsonMixin): - """ - BaseResponse class used to define the common methods and properties for all response classes. - """ - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - - def eval(self, key: str) -> str: - """ - This method is used to evaluate a key in the response object using a dot notation style method. - """ - keys = key.split(".") - result: Dict[Any, Any] = self.to_dict() - for k in keys: - if isinstance(result, dict) and k in result: - result = result[k] - elif isinstance(result, list) and k.isdigit() and int(k) < len(result): - result = result[int(k)] - else: - return "" - return str(result) +from ....common import ( + BaseResponse, +) # Speak Response Types: @@ -74,64 +43,3 @@ class SpeakRESTResponse(BaseResponse): # pylint: disable=too-many-instance-attr default=None, metadata=dataclass_config(exclude=lambda f: True), ) - - -@dataclass -class OpenResponse(BaseResponse): - """ - Open Message from the Deepgram Platform - """ - - type: str = "" - - -@dataclass -class MetadataResponse(BaseResponse): - """ - Metadata object - """ - - request_id: str = "" - - -@dataclass -class FlushedResponse(BaseResponse): - """ - Flushed Message from the Deepgram Platform - """ - - type: str = "" - - -@dataclass -class CloseResponse(BaseResponse): - """ - Close Message from the Deepgram Platform - """ - - type: str = "" - - -@dataclass -class ErrorResponse(BaseResponse): - """ - Error Message from the Deepgram Platform - """ - - description: str = "" - message: str = "" - type: str = "" - variant: Optional[str] = "" - - -# Unhandled Message - - -@dataclass -class UnhandledResponse(BaseResponse): - """ - Unhandled Message from the Deepgram Platform - """ - - type: str = "" - raw: str = "" diff --git a/deepgram/clients/speak/v1/websocket/__init__.py b/deepgram/clients/speak/v1/websocket/__init__.py index 0d68434c..5245b934 100644 --- a/deepgram/clients/speak/v1/websocket/__init__.py +++ b/deepgram/clients/speak/v1/websocket/__init__.py @@ -5,13 +5,15 @@ from .client import SpeakWebSocketClient, SpeakWSClient from .async_client import AsyncSpeakWebSocketClient, AsyncSpeakWSClient from .response import ( - OpenResponse, + #### top level MetadataResponse, FlushedResponse, ClearedResponse, + WarningResponse, + #### shared + OpenResponse, CloseResponse, UnhandledResponse, - WarningResponse, ErrorResponse, ) from .options import SpeakWSOptions diff --git a/deepgram/clients/speak/v1/websocket/options.py b/deepgram/clients/speak/v1/websocket/options.py index 04a5cf33..50771e0b 100644 --- a/deepgram/clients/speak/v1/websocket/options.py +++ b/deepgram/clients/speak/v1/websocket/options.py @@ -7,14 +7,14 @@ import logging from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from dataclasses_json import config as dataclass_config from .....utils import verboselogs -from ....common import FileSource +from ....common import BaseResponse @dataclass -class SpeakWSOptions(DataClassJsonMixin): +class SpeakWSOptions(BaseResponse): """ Contains all the options for the SpeakOptions. @@ -63,7 +63,3 @@ def check(self): logger.setLevel(prev) return True - - -SpeakSource = Union[FileSource, BufferedReader] -SpeakRestSource = SpeakSource diff --git a/deepgram/clients/speak/v1/websocket/response.py b/deepgram/clients/speak/v1/websocket/response.py index c7a6ee16..a5efc4e3 100644 --- a/deepgram/clients/speak/v1/websocket/response.py +++ b/deepgram/clients/speak/v1/websocket/response.py @@ -3,36 +3,22 @@ # SPDX-License-Identifier: MIT -from typing import Optional -import io +from dataclasses import dataclass -from dataclasses import dataclass, field -from dataclasses_json import config as dataclass_config, DataClassJsonMixin +from ....common import ( + BaseResponse, + OpenResponse, + CloseResponse, + ErrorResponse, + UnhandledResponse, +) -# Speak Response Types: - - -@dataclass -class OpenResponse(DataClassJsonMixin): - """ - Open Message from the Deepgram Platform - """ - - type: str = "" - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) +# Speak Response Types: @dataclass -class MetadataResponse(DataClassJsonMixin): +class MetadataResponse(BaseResponse): """ Metadata object """ @@ -40,19 +26,9 @@ class MetadataResponse(DataClassJsonMixin): type: str = "" request_id: str = "" - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class FlushedResponse(DataClassJsonMixin): +class FlushedResponse(BaseResponse): """ Flushed Message from the Deepgram Platform """ @@ -60,19 +36,9 @@ class FlushedResponse(DataClassJsonMixin): type: str = "" sequence_id: int = 0 - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class ClearedResponse(DataClassJsonMixin): +class ClearedResponse(BaseResponse): """ Cleared object """ @@ -80,60 +46,9 @@ class ClearedResponse(DataClassJsonMixin): type: str = "" sequence_id: int = 0 - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - @dataclass -class CloseResponse(DataClassJsonMixin): - """ - Close Message from the Deepgram Platform - """ - - type: str = "" - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - - -@dataclass -class ErrorResponse(DataClassJsonMixin): - """ - Error Message from the Deepgram Platform - """ - - description: str = "" - message: str = "" - type: str = "" - variant: Optional[str] = "" - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - - -@dataclass -class WarningResponse(DataClassJsonMixin): +class WarningResponse(BaseResponse): """ Warning Message from the Deepgram Platform """ @@ -141,36 +56,3 @@ class WarningResponse(DataClassJsonMixin): warn_code: str = "" warn_msg: str = "" type: str = "" - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) - - -# Unhandled Message - - -@dataclass -class UnhandledResponse(DataClassJsonMixin): - """ - Unhandled Message from the Deepgram Platform - """ - - type: str = "" - raw: str = "" - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] - - def __setitem__(self, key, val): - self.__dict__[key] = val - - def __str__(self) -> str: - return self.to_json(indent=4) diff --git a/deepgram/options.py b/deepgram/options.py index e92e955c..ff4ef56c 100644 --- a/deepgram/options.py +++ b/deepgram/options.py @@ -39,7 +39,7 @@ def __init__( verbose: int = verboselogs.WARNING, headers: Optional[Dict] = None, options: Optional[Dict] = None, - ): + ): # pylint: disable=too-many-positional-arguments self._logger = verboselogs.VerboseLogger(__name__) self._logger.addHandler(logging.StreamHandler()) @@ -152,7 +152,7 @@ def __init__( verbose: int = verboselogs.WARNING, headers: Optional[Dict] = None, options: Optional[Dict] = None, - ): + ): # pylint: disable=too-many-positional-arguments self._logger = verboselogs.VerboseLogger(__name__) self._logger.addHandler(logging.StreamHandler()) self._logger.setLevel(verboselogs.WARNING) # temporary set for setup