Skip to content

Commit 8226969

Browse files
Merge pull request #463 from deepgram/add-search-response-for-streaming
added the Search response for streaming requests
2 parents abc610e + fed0893 commit 8226969

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

deepgram/clients/listen/v1/websocket/response.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,49 @@ def __getitem__(self, key):
9393
return _dict[key]
9494

9595

96+
@dataclass
97+
class Hit(BaseResponse):
98+
"""
99+
The hit information for the response.
100+
"""
101+
102+
confidence: float = 0
103+
start: float = 0
104+
end: float = 0
105+
snippet: Optional[str] = ""
106+
107+
108+
@dataclass
109+
class Search(BaseResponse):
110+
"""
111+
The search information for the response.
112+
"""
113+
114+
query: str = ""
115+
hits: List[Hit] = field(default_factory=list)
116+
117+
def __getitem__(self, key):
118+
_dict = self.to_dict()
119+
if "hits" in _dict:
120+
_dict["hits"] = [Hit.from_dict(hits) for hits in _dict["hits"]]
121+
return _dict[key]
122+
123+
96124
@dataclass
97125
class Channel(BaseResponse):
98126
"""
99127
Channel object
100128
"""
101129

130+
search: Optional[List[Search]] = field(
131+
default=None, metadata=dataclass_config(exclude=lambda f: f is None)
132+
)
102133
alternatives: List[Alternative] = field(default_factory=list)
103134

104135
def __getitem__(self, key):
105136
_dict = self.to_dict()
137+
if "search" in _dict:
138+
_dict["search"] = [Search.from_dict(search) for search in _dict["search"]]
106139
if "alternatives" in _dict:
107140
_dict["alternatives"] = [
108141
Alternative.from_dict(alternatives)

0 commit comments

Comments
 (0)