I was running a python script with the openai library. Whenever I run this function on my local machine it throws the following error
def gpt3_embedding(content, engine='text-embedding-ada-002'):
#delay_print('Making a vector')
content = content.encode(encoding='ASCII',errors='ignore').decode()
response = openai.Embedding.create(input=content,model=engine)
vector = response['data'][0]['embedding'] # this is a normal list
#delay_print('Vector returned')
return vector
AttributeError: module 'openai' has no attribute 'Embedding
NB : I am using the latest openai package and python 3.11.1
If all goes well, the error shouldnt appear at all.
I tested your code with:
3.11.1
and OpenAI Python library0.25.0
3.11.1
and OpenAI Python library0.26.3
(latest version)In both cases I ran
test.py
and the OpenAI API returned the embedding:test.py
Solution
STEP 1: Upgrade Python
See the instructions.
STEP 2: Upgrade OpenAI Python library