Skip to content

Commit 6b436a7

Browse files
author
BitsAdmin
committed
Merge branch 'feat/vlm_for_e2e' into 'integration_2024-12-23_644381953026'
feat: [development task] ark-runtime-manual-Python (929744) See merge request iaasng/volcengine-python-sdk!460
2 parents 3a381ca + 8e62876 commit 6b436a7

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

volcenginesdkarkruntime/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def _load_cert_by_ak_sk(self, ep: str) -> str:
325325
resp: volcenginesdkark.GetEndpointCertificateResponse = self.api_instance.get_endpoint_certificate(
326326
get_endpoint_certificate_request)
327327
except ApiException as e:
328-
raise ArkAPIError("Getting Certificate failed: %s\n" % e)
328+
raise ArkAPIError("Getting model vendor encryption certificate failed: %s\n" % e)
329329

330330
return resp.pca_instance_certificate
331331

volcenginesdkarkruntime/resources/chat/completions.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Dict, List, Union, Iterable, Optional, Callable, Iterator, AsyncIterator
44

55
import httpx
6+
import warnings
67
from typing_extensions import Literal
78

89
from ..._types import Body, Query, Headers
@@ -32,7 +33,6 @@
3233

3334
__all__ = ["Completions", "AsyncCompletions"]
3435

35-
3636
class Completions(SyncAPIResource):
3737
@cached_property
3838
def with_raw_response(self) -> CompletionsWithRawResponse:
@@ -50,10 +50,20 @@ def _process_messages(self, messages: Iterable[ChatCompletionMessageParam],
5050
if isinstance(current_content, str):
5151
message["content"] = f(current_content)
5252
elif isinstance(current_content, Iterable):
53-
raise TypeError("content type {} is not supported end-to-end encryption".
54-
format(type(message.get('content'))))
53+
for part in current_content:
54+
if part.get("type", None) == "text":
55+
part["text"] = f(part["text"])
56+
elif part.get("type", None) == "image_url":
57+
if part["image_url"]["url"].startswith('data:'):
58+
part["image_url"]["url"] = f(part["image_url"]["url"])
59+
else:
60+
warnings.warn("encryption is not supported for image url, "
61+
"please use base64 image if you want encryption")
62+
else:
63+
raise TypeError("encryption is not supported for content type {}".
64+
format(type(part)))
5565
else:
56-
raise TypeError("content type {} is not supported end-to-end encryption".
66+
raise TypeError("encryption is not supported for content type {}".
5767
format(type(message.get('content'))))
5868

5969
def _encrypt(self, model: str, messages: Iterable[ChatCompletionMessageParam], extra_headers: Headers
@@ -177,8 +187,21 @@ def _process_messages(self, messages: Iterable[ChatCompletionMessageParam],
177187
current_content = message.get("content")
178188
if isinstance(current_content, str):
179189
message["content"] = f(current_content)
190+
elif isinstance(current_content, Iterable):
191+
for part in current_content:
192+
if part.get("type", None) == "text":
193+
part["text"] = f(part["text"])
194+
elif part.get("type", None) == "image_url":
195+
if part["image_url"]["url"].startswith('data:'):
196+
part["image_url"]["url"] = f(part["image_url"]["url"])
197+
else:
198+
warnings.warn("encryption is not supported for image url, "
199+
"please use base64 image if you want encryption")
200+
else:
201+
raise TypeError("encryption is not supported for content type {}".
202+
format(type(part)))
180203
else:
181-
raise TypeError("content type {} is not supported end-to-end encryption".
204+
raise TypeError("encryption is not supported for content type {}".
182205
format(type(message.get('content'))))
183206

184207
def _encrypt(self, model: str, messages: Iterable[ChatCompletionMessageParam], extra_headers: Headers
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from ..._models import BaseModel
2+
3+
__all__ = ["ChatCompletionAudio"]
4+
5+
6+
class ChatCompletionAudio(BaseModel):
7+
id: str
8+
"""Unique identifier for this audio response."""
9+
10+
data: str
11+
"""
12+
Base64 encoded audio bytes generated by the model.
13+
"""
14+
15+
expires_at: int
16+
"""
17+
The Unix timestamp (in seconds) for when this audio response will no longer be
18+
accessible on the server for use in multi-turn conversations.
19+
"""
20+
21+
transcript: str
22+
"""Transcript of the audio generated by the model."""

volcenginesdkarkruntime/types/chat/chat_completion_message.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from ..._models import BaseModel
55
from .chat_completion_message_tool_call import ChatCompletionMessageToolCall
6+
from .chat_completion_audio import ChatCompletionAudio
67

78
__all__ = ["ChatCompletionMessage", "FunctionCall"]
89

@@ -36,3 +37,6 @@ class ChatCompletionMessage(BaseModel):
3637

3738
tool_calls: Optional[List[ChatCompletionMessageToolCall]] = None
3839
"""The tool calls generated by the model, such as function calls."""
40+
41+
audio: Optional[ChatCompletionAudio] = None
42+
"""Audio response from the model."""

0 commit comments

Comments
 (0)