Skip to content

Commit

Permalink
To support tuple of string for Embeddings and AsyncEmbeddings openai#…
Browse files Browse the repository at this point in the history
  • Loading branch information
deepthinkerdev committed Dec 26, 2024
1 parent 89d4933 commit 39ccc3d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/openai/resources/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import base64
from typing import List, Union, Iterable, cast
from typing import List, Tuple, Union, Iterable, cast
from typing_extensions import Literal

import httpx
Expand Down Expand Up @@ -46,7 +46,7 @@ def with_streaming_response(self) -> EmbeddingsWithStreamingResponse:
def create(
self,
*,
input: Union[str, List[str], Iterable[int], Iterable[Iterable[int]]],
input: Union[str, List[str], Tuple[str], Iterable[int], Iterable[Iterable[int]]],
model: Union[str, EmbeddingModel],
dimensions: int | NotGiven = NOT_GIVEN,
encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -94,6 +94,10 @@ def create(
timeout: Override the client-level default timeout for this request, in seconds
"""

if isinstance(input, tuple) and all(isinstance(item, str) for item in input):
input = list(input)

params = {
"input": input,
"model": model,
Expand Down Expand Up @@ -158,7 +162,7 @@ def with_streaming_response(self) -> AsyncEmbeddingsWithStreamingResponse:
async def create(
self,
*,
input: Union[str, List[str], Iterable[int], Iterable[Iterable[int]]],
input: Union[str, List[str], Tuple[str], Iterable[int], Iterable[Iterable[int]]],
model: Union[str, EmbeddingModel],
dimensions: int | NotGiven = NOT_GIVEN,
encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -206,6 +210,10 @@ async def create(
timeout: Override the client-level default timeout for this request, in seconds
"""

if isinstance(input, tuple) and all(isinstance(item, str) for item in input):
input = list(input)

params = {
"input": input,
"model": model,
Expand Down

0 comments on commit 39ccc3d

Please sign in to comment.