Description
Describe the bug
According to https://platform.openai.com/docs/api-reference/embeddings/create, you can send an input of type str
or list of str
. You receive a response if you send an empty string ("") as input. But, if you send a list of str that contains an empty string like ["a", "b", "", "d"], you receive an error of type InvalidRequestError
with this message '$.input' is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference.
To Reproduce
res = openai.Embedding.create(input="", engine=EMBEDDING_MODEL)
print(len(res['data'][0]['embedding']))
res2 = openai.Embedding.create(input=["a", ""], engine=EMBEDDING_MODEL)
print(res2['data'][0]['embedding'])
Output
1536
InvalidRequestError Traceback (most recent call last)
Cell In[74], line 3
1 res = openai.Embedding.create(input="", engine=EMBEDDING_MODEL)
2 print(len(res['data'][0]['embedding']))
----> 3 res2 = openai.Embedding.create(input=["a", ""], engine=EMBEDDING_MODEL)
4 print(res2['data'][0]['embedding'])
File ~/workspace/platzi/semantic-search/.venv/lib/python3.10/site-packages/openai/api_resources/embedding.py:33, in Embedding.create(cls, *args, **kwargs)
31 while True:
32 try:
---> 33 response = super().create(*args, **kwargs)
35 # If a user specifies base64, we'll just return the encoded string.
36 # This is only for the default case.
37 if not user_provided_encoding_format:
File ~/workspace/platzi/semantic-search/.venv/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py:153, in EngineAPIResource.create(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)
127 @classmethod
128 def create(
129 cls,
(...)
136 **params,
137 ):
138 (
139 deployment_id,
...
764 rbody, rcode, resp.data, rheaders, stream_error=stream_error
765 )
766 return resp
InvalidRequestError: '$.input' is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference.tps://platform.openai.com/docs/api-reference.
Code snippets
No response
OS
Ubuntu
Python version
Python v3.10.12
Library version
openai-python v0.27.8