|
| 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