openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Embeddings.create's types should support `input` being a `tuple[str]`

Open nairb774 opened this issue 1 year ago • 0 comments

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • [X] 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: https://github.com/openai/openai-python/blob/995cce048f9427bba4f7ac1e5fc60abbf1f8f0b7/src/openai/resources/embeddings.py#L46-L60

And the async variant: https://github.com/openai/openai-python/blob/995cce048f9427bba4f7ac1e5fc60abbf1f8f0b7/src/openai/resources/embeddings.py#L158-L172

nairb774 avatar Dec 09 '24 23:12 nairb774