Skip to content

Commit 4a31dc6

Browse files
author
liuhuiqi.7
committed
feat(ark e2e): req by cert file
Change-Id: I048f4de03da2aa7c28676746d6024d58368ecc98
1 parent 1fd4edc commit 4a31dc6

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

volcenginesdkarkruntime/_client.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ def _get_endpoint_sts_token(self, endpoint_id: str):
104104

105105
def _get_endpoint_certificate(self, endpoint_id: str) -> key_agreement_client:
106106
if self._certificate_manager is None:
107-
if self.ak is None or self.sk is None:
108-
raise ArkAPIError("must set ak and sk before get endpoint token.")
107+
cert_path = os.environ.get("E2E_CERTIFICATE_PATH")
108+
if (self.ak is None or self.sk is None) and cert_path is None:
109+
raise ArkAPIError("must set (ak and sk) or (E2E_CERTIFICATE_PATH) \
110+
before get endpoint token.")
109111
self._certificate_manager = E2ECertificateManager(self.ak, self.sk, self.region)
110112
return self._certificate_manager.get(endpoint_id)
111113

@@ -299,7 +301,9 @@ def __init__(self, ak: str, sk: str, region: str):
299301
volcenginesdkcore.Configuration.set_default(configuration)
300302
self.api_instance = volcenginesdkark.ARKApi()
301303

302-
def _load_api_key(self, ep: str) -> str:
304+
self.cert_path = os.environ.get("E2E_CERTIFICATE_PATH")
305+
306+
def _load_cert_by_ak_sk(self, ep: str) -> str:
303307
get_endpoint_certificate_request = volcenginesdkark.GetEndpointCertificateRequest(
304308
id=ep
305309
)
@@ -313,7 +317,11 @@ def _load_api_key(self, ep: str) -> str:
313317

314318
def get(self, ep: str) -> key_agreement_client:
315319
if ep not in self._certificate_manager:
316-
cert_pem = self._load_api_key(ep)
320+
if self.cert_path is not None:
321+
with open(self.cert_path, 'r') as f:
322+
cert_pem = f.read()
323+
else:
324+
cert_pem = self._load_cert_by_ak_sk(ep)
317325
self._certificate_manager[ep] = key_agreement_client(
318326
certificate_pem_string=cert_pem
319327
)

volcenginesdkarkruntime/resources/chat/completions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def _process_messages(self, messages: Iterable[ChatCompletionMessageParam],
5353
raise TypeError("content type {} is not supported end-to-end encryption".
5454
format(type(c)))
5555
for key in c.keys():
56+
if key == 'type':
57+
continue
5658
if isinstance(c[key], str):
5759
content[i][key] = f(c[key])
5860
if isinstance(c[key], Dict):
@@ -150,8 +152,8 @@ def create(
150152
stream_cls=Stream[ChatCompletionChunk],
151153
)
152154

153-
if is_encrypt:
154-
return self._decrypt(resp)
155+
# if is_encrypt:
156+
# return self._decrypt(resp)
155157
return resp
156158

157159

0 commit comments

Comments
 (0)