Skip to content

Commit 22e112f

Browse files
author
liuhuiqi.7
committed
feat(ark e2e): fix bug
Change-Id: I262ff4a760b35a9db0977a2fdf771ef8666079c7
1 parent fbc2a64 commit 22e112f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

volcenginesdkarkruntime/_streaming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def __init__(
168168
self._iterator = self.__stream__()
169169

170170
@classmethod
171-
def _make_stream_from_iterator(cls, iterator: Iterator[_T]) -> Stream[_T]:
171+
def _make_stream_from_iterator(cls, iterator: AsyncIterator[_T]) -> AsyncStream[_T]:
172172
return AsyncStream(cast_to=None, response=None, client=None, iterator=iterator)
173173

174174
async def __anext__(self) -> _T:

volcenginesdkarkruntime/resources/chat/completions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def create(
118118
timeout: float | httpx.Timeout | None = None,
119119
) -> ChatCompletion | Stream[ChatCompletionChunk]:
120120
is_encrypt = False
121-
if extra_headers is not None and extra_headers[ARK_E2E_ENCRYPTION_HEADER] == 'true':
121+
if extra_headers is not None and extra_headers.get(ARK_E2E_ENCRYPTION_HEADER, None) == 'true':
122122
is_encrypt = True
123123
e2e_key, e2e_nonce = self._encrypt(model, messages, extra_headers)
124124

@@ -211,7 +211,7 @@ async def _decrypt(self, key: bytes, nonce: bytes, resp: ChatCompletion | AsyncS
211211
if choice.message.content is not None:
212212
choice.message.content = aes_gcm_decrypt_base64_string(key, nonce, choice.message.content)
213213
resp.choices[0] = choice
214-
return await resp
214+
return resp
215215
else:
216216
return AsyncStream._make_stream_from_iterator(self._decrypt_chunk(key, nonce, resp))
217217

@@ -245,7 +245,7 @@ async def create(
245245
timeout: float | httpx.Timeout | None = None,
246246
) -> ChatCompletion | AsyncStream[ChatCompletionChunk]:
247247
is_encrypt = False
248-
if extra_headers is not None and extra_headers[ARK_E2E_ENCRYPTION_HEADER] == 'true':
248+
if extra_headers is not None and extra_headers.get(ARK_E2E_ENCRYPTION_HEADER, None) == 'true':
249249
is_encrypt = True
250250
e2e_key, e2e_nonce = self._encrypt(model, messages, extra_headers)
251251

0 commit comments

Comments
 (0)