I’m on Module 10 (Word Using Word Embedding for Dynamic Content) of the Mastering Generative AI with OpenAI where we are given the Jupyter Notebook file to run on our own. Like other labs, the openai has changed and I had to adapt, but I’m not 100% sure how to adapt the call to Open AI in this lab. The details from the github page tell me that openai.Embedding.create() call is replaced with client.embeddings.create()
As I had done in other labs, I assume that client is just openai (I’m still a bit weak in Python).
So I call openai.embeddings.create()
WHen I run that function I get this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[18], line 1
----> 1 embeddings=list(map(text_embedding,phrases))
Cell In[15], line 3, in text_embedding(text)
1 def text_embedding(text) -> None:
2 response = openai.embeddings.create(model="text-embedding-ada-002", input=text)
----> 3 return response["data"][0]["embedding"]
TypeError: 'CreateEmbeddingResponse' object is not subscriptable
I haven’t found a way to inspect objects like you would do in Eclipse or VS Code as you step through the application so I’m not 100% sure what this error means or how to fix it.
Can you please send the lab link? I searched for ‘Word Using Word Embedding for Dynamic Content’ in the Mastering Generative AI with OpenAI course, but I couldn’t find it.
Each lab should be updated to work with openai >=1.0.0, although up until this one, the fix was simple - replace openai…ChatCompletion.create() with openai.chat.completions.create()
The replacement of ChatCompletion.create() is not in this lab, it is every other lab. In this lab it’s the function where you grab the embedding model. Here is a snippet from my jupyter file. I added the extra variable, data, to capture the response, but as I’m not super familiar with either python nor jupyter, I’m not sure how to inspect the variable I get back.