Skip to content

Commit 4563888

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

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

volcenginesdkarkruntime/resources/chat/completions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ def _decrypt(self, key: bytes, nonce: bytes, resp: ChatCompletion | Stream[ChatC
7979
) -> ChatCompletion | Stream[ChatCompletionChunk]:
8080
if isinstance(resp, ChatCompletion):
8181
if resp.choices is not None:
82-
choice = resp.choices[0]
83-
if choice.message is not None:
84-
if choice.message.content is not None:
82+
if len(resp.choices) > 0:
83+
choice = resp.choices[0]
84+
if choice.message is not None and choice.message.content is not None:
8585
choice.message.content = aes_gcm_decrypt_base64_string(key, nonce, choice.message.content)
8686
resp.choices[0] = choice
8787
return resp
@@ -195,9 +195,9 @@ async def _decrypt_chunk(self, key: bytes, nonce: bytes, resp: AsyncStream[ChatC
195195
) -> AsyncIterator[ChatCompletionChunk]:
196196
async for chunk in resp:
197197
if chunk.choices is not None:
198-
choice = chunk.choices[0]
199-
if choice.delta is not None:
200-
if choice.delta.content is not None:
198+
if len(chunk.choices) > 0:
199+
choice = chunk.choices[0]
200+
if choice.delta is not None and choice.delta.content is not None:
201201
choice.delta.content = aes_gcm_decrypt_base64_string(key, nonce, choice.delta.content)
202202
chunk.choices[0] = choice
203203
yield chunk

0 commit comments

Comments
 (0)