deepgram.clients.common.v1.shared_response
1# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2# Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3# SPDX-License-Identifier: MIT 4 5from typing import List, Optional, Dict, Any 6 7 8from dataclasses import dataclass, field 9from dataclasses_json import config as dataclass_config, DataClassJsonMixin 10 11 12# base class 13 14 15@dataclass 16class BaseResponse(DataClassJsonMixin): 17 """ 18 BaseResponse class used to define the common methods and properties for all response classes. 19 """ 20 21 def __getitem__(self, key): 22 _dict = self.to_dict() 23 return _dict[key] 24 25 def __setitem__(self, key, val): 26 self.__dict__[key] = val 27 28 def __str__(self) -> str: 29 return self.to_json(indent=4) 30 31 def eval(self, key: str) -> str: 32 """ 33 This method is used to evaluate a key in the response object using a dot notation style method. 34 """ 35 keys = key.split(".") 36 result: Dict[Any, Any] = self.to_dict() 37 for k in keys: 38 if isinstance(result, dict) and k in result: 39 result = result[k] 40 elif isinstance(result, list) and k.isdigit() and int(k) < len(result): 41 result = result[int(k)] 42 else: 43 return "" 44 return str(result) 45 46 47# shared classes 48 49 50@dataclass 51class ModelInfo(BaseResponse): 52 """ 53 ModelInfo object 54 """ 55 56 name: str = "" 57 version: str = "" 58 arch: str = "" 59 60 61@dataclass 62class Hit(BaseResponse): 63 """ 64 The hit information for the response. 65 """ 66 67 confidence: float = 0 68 start: float = 0 69 end: float = 0 70 snippet: Optional[str] = "" 71 72 73@dataclass 74class Search(BaseResponse): 75 """ 76 The search information for the response. 77 """ 78 79 query: str = "" 80 hits: List[Hit] = field(default_factory=list) 81 82 def __getitem__(self, key): 83 _dict = self.to_dict() 84 if "hits" in _dict: 85 _dict["hits"] = [Hit.from_dict(hits) for hits in _dict["hits"]] 86 return _dict[key]
@dataclass
class
BaseResponse16@dataclass 17class BaseResponse(DataClassJsonMixin): 18 """ 19 BaseResponse class used to define the common methods and properties for all response classes. 20 """ 21 22 def __getitem__(self, key): 23 _dict = self.to_dict() 24 return _dict[key] 25 26 def __setitem__(self, key, val): 27 self.__dict__[key] = val 28 29 def __str__(self) -> str: 30 return self.to_json(indent=4) 31 32 def eval(self, key: str) -> str: 33 """ 34 This method is used to evaluate a key in the response object using a dot notation style method. 35 """ 36 keys = key.split(".") 37 result: Dict[Any, Any] = self.to_dict() 38 for k in keys: 39 if isinstance(result, dict) and k in result: 40 result = result[k] 41 elif isinstance(result, list) and k.isdigit() and int(k) < len(result): 42 result = result[int(k)] 43 else: 44 return "" 45 return str(result)
BaseResponse class used to define the common methods and properties for all response classes.
def
eval(self, key: str) -> str:
32 def eval(self, key: str) -> str: 33 """ 34 This method is used to evaluate a key in the response object using a dot notation style method. 35 """ 36 keys = key.split(".") 37 result: Dict[Any, Any] = self.to_dict() 38 for k in keys: 39 if isinstance(result, dict) and k in result: 40 result = result[k] 41 elif isinstance(result, list) and k.isdigit() and int(k) < len(result): 42 result = result[int(k)] 43 else: 44 return "" 45 return str(result)
This method is used to evaluate a key in the response object using a dot notation style method.
51@dataclass 52class ModelInfo(BaseResponse): 53 """ 54 ModelInfo object 55 """ 56 57 name: str = "" 58 version: str = "" 59 arch: str = ""
ModelInfo object
Inherited Members
62@dataclass 63class Hit(BaseResponse): 64 """ 65 The hit information for the response. 66 """ 67 68 confidence: float = 0 69 start: float = 0 70 end: float = 0 71 snippet: Optional[str] = ""
The hit information for the response.
Inherited Members
74@dataclass 75class Search(BaseResponse): 76 """ 77 The search information for the response. 78 """ 79 80 query: str = "" 81 hits: List[Hit] = field(default_factory=list) 82 83 def __getitem__(self, key): 84 _dict = self.to_dict() 85 if "hits" in _dict: 86 _dict["hits"] = [Hit.from_dict(hits) for hits in _dict["hits"]] 87 return _dict[key]
The search information for the response.
Search( query: str = '', hits: List[Hit] = <factory>)
hits: List[Hit]