Skip to content

Commit 35db659

Browse files
author
liuhuiqi.7
committed
feat(ark e2e): decrypt by client
Change-Id: I8863f1dc4ffd6d18b6a2ddf096af813b1dd42ceb
1 parent d273934 commit 35db659

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

volcenginesdkarkruntime/resources/chat/completions.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,8 @@ def _encrypt(self, model: str, messages: Iterable[ChatCompletionMessageParam], e
7575
self._crypto_nonce,
7676
x))
7777

78-
def _decrypt(self, completion: ChatCompletion | Stream[ChatCompletionChunk]):
79-
if isinstance(completion, ChatCompletion):
80-
if completion.choices is not None:
81-
choice = completion.choices[0]
82-
if choice.message.content is not None:
83-
if isinstance(choice.message.content, str):
84-
choice.message.content = self._ka_client.decrypt_string_with_key(self._crypto_key,
85-
self._crypto_nonce,
86-
choice.message.content)
87-
else:
88-
raise TypeError("content type {} is not supported end-to-end encryption".
89-
format(type(choice.message.content)))
90-
completion.choices[0] = choice
91-
elif isinstance(completion, Stream):
92-
for chunk in completion:
93-
if chunk.choices:
94-
choice = chunk.choices[0]
95-
if choice.delta.content is not None:
96-
if isinstance(choice.delta.content, str):
97-
choice.delta.content = self._ka_client.decrypt_string_with_key(self._crypto_key,
98-
self._crypto_nonce,
99-
choice.delta.content)
100-
else:
101-
raise TypeError("content type {} is not supported end-to-end encryption".
102-
format(type(choice.delta.content)))
103-
chunk.choices[0] = choice
78+
def decrypt(self, ciphertext: str) -> str:
79+
return self._ka_client.decrypt_string_with_key(self._crypto_key, self._crypto_nonce, ciphertext)
10480

10581
@with_sts_token
10682
def create(
@@ -172,8 +148,6 @@ def create(
172148
stream_cls=Stream[ChatCompletionChunk],
173149
)
174150

175-
if is_encrypt:
176-
self._decrypt(resp)
177151
return resp
178152

179153

0 commit comments

Comments
 (0)