Skip to content

Commit 03feca5

Browse files
committed
feat(api): return better error message on missing embedding
I had a setup where my embedding model didn't reply properly and had a really hard time figuring out where "NoneType object is not iterable" comes from. With this error message, it should be easier to find the problem.
1 parent 71058dd commit 03feca5

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/openai/resources/embeddings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def parser(obj: CreateEmbeddingResponse) -> CreateEmbeddingResponse:
112112
# don't modify the response object if a user explicitly asked for a format
113113
return obj
114114

115+
if obj.data is None:
116+
raise ValueError("No embedding data received")
117+
115118
for embedding in obj.data:
116119
data = cast(object, embedding.embedding)
117120
if not isinstance(data, str):

0 commit comments

Comments
 (0)