Skip to content

Commit b3e5745

Browse files
exiaohuliyuxuan-bd
authored andcommitted
feat: batch multimodal embeddings
1 parent ff19874 commit b3e5745

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

volcenginesdkarkruntime/resources/batch/batch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from ..._resource import AsyncAPIResource, SyncAPIResource
55
from .chat.chat import AsyncChat, Chat
66
from .embeddings import AsyncEmbeddings, Embeddings
7+
from .multimodal_embeddings import AsyncMultimodalEmbeddings, MultimodalEmbeddings
78

89
__all__ = ["Batch", "AsyncBatch"]
910

@@ -17,6 +18,10 @@ def chat(self) -> Chat:
1718
def embeddings(self) -> Embeddings:
1819
return Embeddings(self._client)
1920

21+
@cached_property
22+
def multimodal_embeddings(self) -> MultimodalEmbeddings:
23+
return MultimodalEmbeddings(self._client)
24+
2025

2126
class AsyncBatch(AsyncAPIResource):
2227
@cached_property
@@ -26,3 +31,7 @@ def chat(self) -> AsyncChat:
2631
@cached_property
2732
def embeddings(self) -> AsyncEmbeddings:
2833
return AsyncEmbeddings(self._client)
34+
35+
@cached_property
36+
def multimodal_embeddings(self) -> AsyncMultimodalEmbeddings:
37+
return AsyncMultimodalEmbeddings(self._client)
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
from __future__ import annotations
2+
3+
from typing import List
4+
5+
import httpx
6+
from typing_extensions import Literal
7+
8+
from ..._base_client import make_request_options
9+
from ..._compat import cached_property
10+
from ..._resource import AsyncAPIResource, SyncAPIResource
11+
from ..._types import Body, Headers, Query
12+
from ..._utils._utils import async_with_sts_token, with_sts_token
13+
from ...types.multimodal_embedding import (
14+
EmbeddingInputParam,
15+
MultimodalEmbeddingResponse,
16+
)
17+
from ..multimodal_embeddings import (
18+
AsyncMultimodalEmbeddingsWithRawResponse,
19+
MultimodalEmbeddingsWithRawResponse,
20+
)
21+
from ._utils import async_with_batch_retry, get_request_last_time, with_batch_retry
22+
23+
__all__ = ["MultimodalEmbeddings", "AsyncMultimodalEmbeddings"]
24+
25+
26+
class MultimodalEmbeddings(SyncAPIResource):
27+
@cached_property
28+
def with_raw_response(self) -> MultimodalEmbeddingsWithRawResponse:
29+
return MultimodalEmbeddingsWithRawResponse(self)
30+
31+
@with_sts_token
32+
def create(
33+
self,
34+
*,
35+
input: List[EmbeddingInputParam],
36+
model: str,
37+
encoding_format: Literal["float", "base64"] = "float",
38+
dimensions: int | None = None,
39+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
40+
# The extra values given here take precedence over values defined on the client or passed to this method.
41+
extra_headers: Headers | None = None,
42+
extra_query: Query | None = None,
43+
extra_body: Body | None = None,
44+
timeout: float | httpx.Timeout | None = None,
45+
) -> MultimodalEmbeddingResponse:
46+
deadline = get_request_last_time(timeout)
47+
breaker = self._client.get_model_breaker(model)
48+
49+
return with_batch_retry(
50+
deadline,
51+
breaker,
52+
self._post_without_retry,
53+
"/batch/embeddings/multimodal",
54+
body={
55+
"input": input,
56+
"model": model,
57+
"encoding_format": encoding_format,
58+
"dimensions": dimensions,
59+
},
60+
options=make_request_options(
61+
extra_headers=extra_headers,
62+
extra_query=extra_query,
63+
extra_body=extra_body,
64+
timeout=timeout,
65+
),
66+
cast_to=MultimodalEmbeddingResponse,
67+
)
68+
69+
70+
class AsyncMultimodalEmbeddings(AsyncAPIResource):
71+
@cached_property
72+
def with_raw_response(self) -> AsyncMultimodalEmbeddingsWithRawResponse:
73+
return AsyncMultimodalEmbeddingsWithRawResponse(self)
74+
75+
@async_with_sts_token
76+
async def create(
77+
self,
78+
*,
79+
input: List[EmbeddingInputParam],
80+
model: str,
81+
encoding_format: Literal["float", "base64"] = "float",
82+
dimensions: int | None = None,
83+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
84+
# The extra values given here take precedence over values defined on the client or passed to this method.
85+
extra_headers: Headers | None = None,
86+
extra_query: Query | None = None,
87+
extra_body: Body | None = None,
88+
timeout: float | httpx.Timeout | None = None,
89+
) -> MultimodalEmbeddingResponse:
90+
deadline = get_request_last_time(timeout)
91+
breaker = await self._client.get_model_breaker(model)
92+
93+
return await async_with_batch_retry(
94+
deadline,
95+
breaker,
96+
self._post_without_retry,
97+
"/batch/embeddings/multimodal",
98+
body={
99+
"input": input,
100+
"model": model,
101+
"encoding_format": encoding_format,
102+
"dimensions": dimensions,
103+
},
104+
options=make_request_options(
105+
extra_headers=extra_headers,
106+
extra_query=extra_query,
107+
extra_body=extra_body,
108+
timeout=timeout,
109+
),
110+
cast_to=MultimodalEmbeddingResponse,
111+
)

0 commit comments

Comments
 (0)