@@ -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