Skip to content

Commit 316b6df

Browse files
stainless-botRobertCraigie
authored andcommitted
feat(api): add embeddings encoding_format
1 parent 0010bef commit 316b6df

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/openai/resources/embeddings.py

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def create(
2020
*,
2121
input: Union[str, List[str], List[int], List[List[int]]],
2222
model: Union[str, Literal["text-embedding-ada-002"]],
23+
encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN,
2324
user: str | NotGiven = NOT_GIVEN,
2425
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
2526
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -45,6 +46,9 @@ def create(
4546
[Model overview](https://platform.openai.com/docs/models/overview) for
4647
descriptions of them.
4748
49+
encoding_format: The format to return the embeddings in. Can be either `float` or
50+
[`base64`](https://pypi.org/project/pybase64/).
51+
4852
user: A unique identifier representing your end-user, which can help OpenAI to monitor
4953
and detect abuse.
5054
[Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).
@@ -63,6 +67,7 @@ def create(
6367
{
6468
"input": input,
6569
"model": model,
70+
"encoding_format": encoding_format,
6671
"user": user,
6772
},
6873
embedding_create_params.EmbeddingCreateParams,
@@ -80,6 +85,7 @@ async def create(
8085
*,
8186
input: Union[str, List[str], List[int], List[List[int]]],
8287
model: Union[str, Literal["text-embedding-ada-002"]],
88+
encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN,
8389
user: str | NotGiven = NOT_GIVEN,
8490
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
8591
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -105,6 +111,9 @@ async def create(
105111
[Model overview](https://platform.openai.com/docs/models/overview) for
106112
descriptions of them.
107113
114+
encoding_format: The format to return the embeddings in. Can be either `float` or
115+
[`base64`](https://pypi.org/project/pybase64/).
116+
108117
user: A unique identifier representing your end-user, which can help OpenAI to monitor
109118
and detect abuse.
110119
[Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).
@@ -123,6 +132,7 @@ async def create(
123132
{
124133
"input": input,
125134
"model": model,
135+
"encoding_format": encoding_format,
126136
"user": user,
127137
},
128138
embedding_create_params.EmbeddingCreateParams,

src/openai/types/embedding_create_params.py

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class EmbeddingCreateParams(TypedDict, total=False):
2929
descriptions of them.
3030
"""
3131

32+
encoding_format: Literal["float", "base64"]
33+
"""The format to return the embeddings in.
34+
35+
Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).
36+
"""
37+
3238
user: str
3339
"""
3440
A unique identifier representing your end-user, which can help OpenAI to monitor

tests/api_resources/test_embeddings.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_method_create_with_all_params(self, client: OpenAI) -> None:
3232
embedding = client.embeddings.create(
3333
input="The quick brown fox jumped over the lazy dog",
3434
model="text-embedding-ada-002",
35+
encoding_format="float",
3536
user="user-1234",
3637
)
3738
assert_matches_type(CreateEmbeddingResponse, embedding, path=["response"])
@@ -55,6 +56,7 @@ async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
5556
embedding = await client.embeddings.create(
5657
input="The quick brown fox jumped over the lazy dog",
5758
model="text-embedding-ada-002",
59+
encoding_format="float",
5860
user="user-1234",
5961
)
6062
assert_matches_type(CreateEmbeddingResponse, embedding, path=["response"])

0 commit comments

Comments
 (0)