Skip to content

Commit ca39c28

Browse files
Correctly handled response headers in speak rest client for aura 2
1 parent e48e415 commit ca39c28

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

deepgram/clients/speak/v1/rest/client.py

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,28 @@ def stream_memory(
160160
self._logger.info("addons: %s", addons)
161161
self._logger.info("headers: %s", headers)
162162

163-
return_vals = [
164-
"content-type",
165-
"request-id",
166-
"model-uuid",
167-
"model-name",
168-
"char-count",
169-
"transfer-encoding",
170-
"date",
171-
]
163+
is_aura_2_model = options["model"].split("-")[1] == "2"
164+
165+
if is_aura_2_model:
166+
return_vals = [
167+
"content-type",
168+
"request-id",
169+
"model-name",
170+
"characters",
171+
"transfer-encoding",
172+
"date",
173+
]
174+
else:
175+
return_vals = [
176+
"content-type",
177+
"request-id",
178+
"model-uuid",
179+
"model-name",
180+
"char-count",
181+
"transfer-encoding",
182+
"date",
183+
]
184+
172185
result = self.post_memory(
173186
url,
174187
options=options,
@@ -181,17 +194,31 @@ def stream_memory(
181194
)
182195

183196
self._logger.info("result: %s", result)
184-
resp = SpeakRESTResponse(
185-
content_type=str(result["content-type"]),
186-
request_id=str(result["request-id"]),
187-
model_uuid=str(result["model-uuid"]),
188-
model_name=str(result["model-name"]),
189-
characters=int(str(result["char-count"])),
190-
transfer_encoding=str(result["transfer-encoding"]),
191-
date=str(result["date"]),
192-
stream=cast(io.BytesIO, result["stream"]),
193-
stream_memory=cast(io.BytesIO, result["stream"]),
194-
)
197+
198+
if is_aura_2_model:
199+
resp = SpeakRESTResponse(
200+
content_type=str(result["content-type"]),
201+
request_id=str(result["request-id"]),
202+
model_name=str(result["model-name"]),
203+
characters=int(str(result["characters"])),
204+
transfer_encoding=str(result["transfer-encoding"]),
205+
date=str(result["date"]),
206+
stream=cast(io.BytesIO, result["stream"]),
207+
stream_memory=cast(io.BytesIO, result["stream"]),
208+
)
209+
else:
210+
resp = SpeakRESTResponse(
211+
content_type=str(result["content-type"]),
212+
request_id=str(result["request-id"]),
213+
model_uuid=str(result["model-uuid"]),
214+
model_name=str(result["model-name"]),
215+
characters=int(str(result["char-count"])),
216+
transfer_encoding=str(result["transfer-encoding"]),
217+
date=str(result["date"]),
218+
stream=cast(io.BytesIO, result["stream"]),
219+
stream_memory=cast(io.BytesIO, result["stream"]),
220+
)
221+
195222
self._logger.verbose("resp Object: %s", resp)
196223
self._logger.notice("speak succeeded")
197224
self._logger.debug("SpeakClient.stream LEAVE")

0 commit comments

Comments
 (0)