Skip to content

Commit

Permalink
Merge pull request #463 from deepgram/add-search-response-for-streaming
Browse files Browse the repository at this point in the history
added the Search response for streaming requests
  • Loading branch information
davidvonthenen authored Sep 16, 2024
2 parents abc610e + fed0893 commit 8226969
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions deepgram/clients/listen/v1/websocket/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,49 @@ def __getitem__(self, key):
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)
Expand Down

0 comments on commit 8226969

Please sign in to comment.