-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Confirm this is a feature request for the Python library and not the underlying OpenAI API.
- This is a feature request for the Python library
Describe the feature or improvement you're requesting
Currently the type for input
in Embeddings.create is: Union[str, List[str], Iterable[int], Iterable[Iterable[int]]]
. It would be nice if the documented type could be expanded to support tuple[str]
as well. Passing a tuple of strings works in local testing. The narrow type definition makes type checking tools complain needlessly. Supporting a tuple is useful because it allows for combining with itertools.batched
to break large inputs into acceptable blocks.
Current alternatives are to convert the tuple to a list (unnecessary copy), or input=cast(list[str], input)
(type hole/fragility).
Additional context
Specific function being discussed:
openai-python/src/openai/resources/embeddings.py
Lines 46 to 60 in 995cce0
def create( | |
self, | |
*, | |
input: Union[str, List[str], Iterable[int], Iterable[Iterable[int]]], | |
model: Union[str, EmbeddingModel], | |
dimensions: int | NotGiven = NOT_GIVEN, | |
encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN, | |
user: str | NotGiven = NOT_GIVEN, | |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. | |
# The extra values given here take precedence over values defined on the client or passed to this method. | |
extra_headers: Headers | None = None, | |
extra_query: Query | None = None, | |
extra_body: Body | None = None, | |
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, | |
) -> CreateEmbeddingResponse: |
And the async variant:
openai-python/src/openai/resources/embeddings.py
Lines 158 to 172 in 995cce0
async def create( | |
self, | |
*, | |
input: Union[str, List[str], Iterable[int], Iterable[Iterable[int]]], | |
model: Union[str, EmbeddingModel], | |
dimensions: int | NotGiven = NOT_GIVEN, | |
encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN, | |
user: str | NotGiven = NOT_GIVEN, | |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. | |
# The extra values given here take precedence over values defined on the client or passed to this method. | |
extra_headers: Headers | None = None, | |
extra_query: Query | None = None, | |
extra_body: Body | None = None, | |
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, | |
) -> CreateEmbeddingResponse: |