Usman Afridi
Usman Afridi

Reputation: 189

Attribute Error: openai has no attribute Image

So I was getting my hands-on on the new DALL.E api for Python which has been made public. I was getting the Attribution Error as it was not detecting the Image model in Open ai after running the following code:

response = openai.Image.create(
  prompt="a white siamese cat",
  n=1,
  size="1024x1024"
)
image_url = response['data'][0]['url']

Why am I getting this error?

Upvotes: 2

Views: 3634

Answers (3)

Aswin kumar
Aswin kumar

Reputation: 1

In the latest OpenAI version, it doesn't have that attribute. This should work:

from openai import OpenAI
client = OpenAI()

response = client.images.generate(
  model="dall-e-3",
  prompt="a white siamese cat",
  size="1024x1024",
  quality="standard",
  n=1,
)

image_url = response.data[0].url

Upvotes: 0

LunaSa
LunaSa

Reputation: 41

Had the same problem. I noticed my python is 3.7.0, which only supports up to openai=0.8... for openai 0.25.0, will need at least python>=3.7.1

Upvotes: 4

Usman Afridi
Usman Afridi

Reputation: 189

I just found the solution. You have to upgrade your openai library with code:

pip install --upgrade openai

Restart the kernel, and enjoy :)

Upvotes: 5

Related Questions