Skip to content

Commit 5833351

Browse files
author
BitsAdmin
committed
Merge branch 'feat/add_bot_sts_token_async' into 'integration_2025-06-19_956583143170'
feat: [development task] ark runtime (1361604) See merge request iaasng/volcengine-python-sdk!677
2 parents 59413f7 + 4dda893 commit 5833351

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"httpx>=0.23.0, <1",
3030
"anyio>=3.5.0, <5",
3131
"cached-property; python_version < '3.8'",
32-
"cryptography>=43.0.3, <43.0.4"
32+
"cryptography>=42.0.0"
3333
]
3434
},
3535
)

volcenginesdkarkruntime/_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ def _get_endpoint_sts_token(self, endpoint_id: str):
245245
self._sts_token_manager = StsTokenManager(self.ak, self.sk, self.region)
246246
return self._sts_token_manager.get(endpoint_id)
247247

248+
def _get_bot_sts_token(self, bot_id: str):
249+
if self._sts_token_manager is None:
250+
if self.ak is None or self.sk is None:
251+
raise ArkAPIError("must set ak and sk before get endpoint token.")
252+
self._sts_token_manager = StsTokenManager(self.ak, self.sk, self.region)
253+
return self._sts_token_manager.get(bot_id, resource_type="bot")
254+
248255
def _get_endpoint_certificate(self, endpoint_id: str) -> key_agreement_client:
249256
if self._certificate_manager is None:
250257
cert_path = os.environ.get("E2E_CERTIFICATE_PATH")

volcenginesdkarkruntime/_utils/_key_agreement.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ def marshal_cryptography_pub_key(key) -> bytes:
6969
class key_agreement_client:
7070
def __init__(self, certificate_pem_string: str) -> None:
7171
"""Load cert and extract public key"""
72-
__fixed_version__ = "43.0.3" # version check
72+
__fixed_version__ = "42.0.0" # version check
7373
from cryptography import __version__
7474

75-
if __version__ != __fixed_version__:
75+
if __version__ < __fixed_version__:
7676
raise Exception(
77-
"The cryptography package of Ark SDK only supports version {}, "
78-
"please install the cryptography package by using pip install cryptography=={}".format(
77+
"The cryptography package of Ark SDK only supports versions after {}, "
78+
'please install the cryptography package by using pip install "cryptography>={}"'.format(
7979
__fixed_version__, __fixed_version__
8080
)
8181
)

volcenginesdkarkruntime/resources/batch_chat/completions.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ def _decrypt(
155155
) -> ChatCompletion:
156156
if resp.choices is not None:
157157
for index, choice in enumerate(resp.choices):
158-
if choice.message is not None and choice.message.content is not None:
158+
if (
159+
choice.message is not None and choice.finish_reason != 'content_filter'
160+
and choice.message.content is not None
161+
):
159162
choice.message.content = aes_gcm_decrypt_base64_string(
160163
key, nonce, choice.message.content
161164
)
@@ -299,7 +302,10 @@ async def _decrypt(
299302
) -> ChatCompletion:
300303
if resp.choices is not None:
301304
for index, choice in enumerate(resp.choices):
302-
if choice.message is not None and choice.message.content is not None:
305+
if (
306+
choice.message is not None and choice.finish_reason != 'content_filter'
307+
and choice.message.content is not None
308+
):
303309
choice.message.content = aes_gcm_decrypt_base64_string(
304310
key, nonce, choice.message.content
305311
)

volcenginesdkarkruntime/resources/chat/completions.py

Lines changed: 14 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.delta is not None and choice.delta.content is not None
112+
and choice.finish_reason != 'content_filter'
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.message is not None and choice.finish_reason != 'content_filter'
128131
and choice.message.content is not None
129132
):
130133
choice.message.content = aes_gcm_decrypt_base64_string(
@@ -163,6 +166,7 @@ def create(
163166
tool_choice: ChatCompletionToolChoiceOptionParam | None = None,
164167
response_format: completion_create_params.ResponseFormat | None = None,
165168
thinking: completion_create_params.Thinking | None = None,
169+
max_completion_tokens: Optional[int] | None = None,
166170
user: str | None = None,
167171
extra_headers: Headers | None = None,
168172
extra_query: Query | None = None,
@@ -203,6 +207,7 @@ def create(
203207
"tool_choice": tool_choice,
204208
"response_format": response_format,
205209
"thinking": thinking,
210+
"max_completion_tokens": max_completion_tokens,
206211
},
207212
options=make_request_options(
208213
extra_headers=extra_headers,
@@ -250,7 +255,10 @@ async def _decrypt_chunk(
250255
async for chunk in resp:
251256
if chunk.choices is not None:
252257
for index, choice in enumerate(chunk.choices):
253-
if choice.delta is not None and choice.delta.content is not None:
258+
if (
259+
choice.delta is not None and choice.delta.content is not None
260+
and choice.finish_reason != 'content_filter'
261+
):
254262
choice.delta.content = aes_gcm_decrypt_base64_string(
255263
key, nonce, choice.delta.content
256264
)
@@ -267,7 +275,7 @@ async def _decrypt(
267275
if resp.choices is not None:
268276
for index, choice in enumerate(resp.choices):
269277
if (
270-
choice.message is not None
278+
choice.message is not None and choice.finish_reason != 'content_filter'
271279
and choice.message.content is not None
272280
):
273281
choice.message.content = aes_gcm_decrypt_base64_string(
@@ -307,6 +315,7 @@ async def create(
307315
tool_choice: ChatCompletionToolChoiceOptionParam | None = None,
308316
response_format: completion_create_params.ResponseFormat | None = None,
309317
thinking: completion_create_params.Thinking | None = None,
318+
max_completion_tokens: Optional[int] | None = None,
310319
extra_headers: Headers | None = None,
311320
extra_query: Query | None = None,
312321
extra_body: Body | None = None,
@@ -346,6 +355,7 @@ async def create(
346355
"tool_choice": tool_choice,
347356
"response_format": response_format,
348357
"thinking": thinking,
358+
"max_completion_tokens": max_completion_tokens,
349359
},
350360
options=make_request_options(
351361
extra_headers=extra_headers,

0 commit comments

Comments
 (0)