Skip to content

Commit b445df3

Browse files
author
liuhuiqi.7
committed
feat(arkruntime): e2ee chat
1 parent d0794a5 commit b445df3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

volcenginesdkarkruntime/resources/chat/completions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ def _decrypt_chunk(
107107
for chunk in resp:
108108
if chunk.choices is not None:
109109
for index, choice in enumerate(chunk.choices):
110-
if choice.delta is not None and choice.delta.content is not None:
110+
if (
111+
choice.finish_reason != 'content_filter'
112+
and choice.delta is not None and choice.delta.content is not None
113+
):
111114
choice.delta.content = aes_gcm_decrypt_base64_string(
112115
key, nonce, choice.delta.content
113116
)
@@ -124,7 +127,7 @@ def _decrypt(
124127
if resp.choices is not None:
125128
for index, choice in enumerate(resp.choices):
126129
if (
127-
choice.message is not None
130+
choice.finish_reason != 'content_filter' and choice.message is not None
128131
and choice.message.content is not None
129132
):
130133
choice.message.content = aes_gcm_decrypt_base64_string(
@@ -250,7 +253,10 @@ async def _decrypt_chunk(
250253
async for chunk in resp:
251254
if chunk.choices is not None:
252255
for index, choice in enumerate(chunk.choices):
253-
if choice.delta is not None and choice.delta.content is not None:
256+
if (
257+
choice.finish_reason != 'content_filter'
258+
and choice.delta is not None and choice.delta.content is not None
259+
):
254260
choice.delta.content = aes_gcm_decrypt_base64_string(
255261
key, nonce, choice.delta.content
256262
)
@@ -267,7 +273,7 @@ async def _decrypt(
267273
if resp.choices is not None:
268274
for index, choice in enumerate(resp.choices):
269275
if (
270-
choice.message is not None
276+
choice.finish_reason != 'content_filter' and choice.message is not None
271277
and choice.message.content is not None
272278
):
273279
choice.message.content = aes_gcm_decrypt_base64_string(

0 commit comments

Comments
 (0)