Skip to content

Commit 0006578

Browse files
committed
feat(*): support ark batch chat
1 parent c0a21a7 commit 0006578

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

volcenginesdkarkruntime/_base_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,6 @@ async def delete(
843843

844844
return await self.request(cast_to, opts)
845845

846-
847846
async def post_without_retry(
848847
self,
849848
path: str,

volcenginesdkarkruntime/resources/batch_chat/completions.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import annotations
22

33
import time
4-
from datetime import timedelta,datetime
4+
from datetime import timedelta, datetime
55
from random import random
6-
from typing import Dict, List, Union, Iterable, Optional, Callable, Iterator, AsyncIterator
6+
from typing import Dict, List, Union, Iterable, Optional, Callable
77

88
import httpx
9-
from typing_extensions import Literal
109

1110
from ..._exceptions import ArkAPITimeoutError, ArkAPIConnectionError, ArkAPIStatusError
1211
from ..._types import Body, Query, Headers
@@ -30,14 +29,14 @@
3029
from ..._constants import (
3130
ARK_E2E_ENCRYPTION_HEADER,
3231
INITIAL_RETRY_DELAY,
33-
MAX_RETRY_DELAY, DEFAULT_TIMEOUT
32+
MAX_RETRY_DELAY,
3433
)
3534

3635
__all__ = ["Completions", "AsyncCompletions"]
3736

3837

3938
def _calculate_retry_timeout(retry_times) -> float:
40-
nbRetries = min(retry_times, MAX_RETRY_DELAY/INITIAL_RETRY_DELAY)
39+
nbRetries = min(retry_times, MAX_RETRY_DELAY / INITIAL_RETRY_DELAY)
4140
sleep_seconds = min(INITIAL_RETRY_DELAY * pow(2, nbRetries), MAX_RETRY_DELAY)
4241
# Apply some jitter, plus-or-minus half a second.
4342
jitter = 1 - 0.25 * random()
@@ -102,7 +101,6 @@ def _encrypt(self, model: str, messages: Iterable[ChatCompletionMessageParam], e
102101
x))
103102
return _crypto_key, _crypto_nonce
104103

105-
106104
def _decrypt(self, key: bytes, nonce: bytes, resp: ChatCompletion
107105
) -> ChatCompletion:
108106
if resp.choices is not None:
@@ -241,7 +239,6 @@ async def _decrypt(self, key: bytes, nonce: bytes, resp: ChatCompletion
241239
resp.choices[index] = choice
242240
return resp
243241

244-
245242
@async_with_sts_token
246243
async def create(
247244
self,

volcenginesdkexamples/volcenginesdkarkruntime/async_batch_chat_completions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# For more information,please check this document(https://www.volcengine.com/docs/82379/1263279)
1616
client = AsyncArk()
1717

18+
1819
async def worker(semaphore, worker_id, task_num):
1920
async with semaphore:
2021
print(f"Worker {worker_id} is starting.")
@@ -35,6 +36,7 @@ async def worker(semaphore, worker_id, task_num):
3536
print(f"Worker {worker_id} task {i} is completed.")
3637
print(f"Worker {worker_id} is completed.")
3738

39+
3840
async def main():
3941
start = datetime.now()
4042
max_concurrent_tasks = 1000

0 commit comments

Comments
 (0)