Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
nairb774 opened this issue Dec 9, 2024 · 0 comments
Open
1 task done

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

nairb774 opened this issue Dec 9, 2024 · 0 comments

Comments

@nairb774
Copy link

nairb774 commented Dec 9, 2024

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:

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:

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:

deepthinkerdev added a commit to deepthinkerdev/openai-python that referenced this issue Dec 26, 2024
deepthinkerdev added a commit to deepthinkerdev/openai-python that referenced this issue Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant