Skip to content

Commit f265d89

Browse files
committed
fix:fixes endpoint issue
1 parent 052aadd commit f265d89

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

deepgram/clients/agent/v1/websocket/options.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33
# SPDX-License-Identifier: MIT
44

5-
from typing import List, Optional, Union, Any, Tuple
5+
from typing import List, Optional, Union, Any, Tuple, Dict
66
import logging
77

88
from dataclasses import dataclass, field
@@ -77,18 +77,34 @@ class Endpoint(BaseResponse):
7777

7878
method: Optional[str] = field(default="POST")
7979
url: str = field(default="")
80-
headers: Optional[List[Header]] = field(
80+
headers: Optional[Union[Dict[str, str], List[Header]]] = field(
8181
default=None, metadata=dataclass_config(exclude=lambda f: f is None)
8282
)
8383

8484
def __getitem__(self, key):
8585
_dict = self.to_dict()
8686
if "headers" in _dict:
87-
_dict["headers"] = [
88-
Header.from_dict(headers) for headers in _dict["headers"]
89-
]
87+
if isinstance(self.headers, list):
88+
_dict["headers"] = [
89+
Header.from_dict(headers) if isinstance(headers, dict) else headers
90+
for headers in _dict["headers"]
91+
]
92+
elif isinstance(self.headers, dict):
93+
_dict["headers"] = self.headers
9094
return _dict[key]
9195

96+
def to_dict(self) -> dict:
97+
"""
98+
Convert the endpoint to a dictionary, properly handling headers.
99+
"""
100+
result = super().to_dict()
101+
if self.headers:
102+
if isinstance(self.headers, dict):
103+
result["headers"] = self.headers
104+
else:
105+
result["headers"] = {h.key: h.value for h in self.headers}
106+
return result
107+
92108

93109
@dataclass
94110
class Function(BaseResponse):

0 commit comments

Comments
 (0)