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