Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

added the Search response for streaming requests #463

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading