I tried every thing mentioned above but I still get error
File “C:\Users\DELL\OneDrive\Documents\leet_python\openai.py”, line 5, in
response = openai.Image.create(
AttributeError: partially initialized module ‘openai’ has no attribute ‘Image’ (most likely due to a circular import)
I am using openai version 0.26.5 and python version 3.9.7
Complete program is
import openai
PROMPT = “An eco-friendly computer from the 90s in the style of vaporwave”
openai.api_key = “■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■45rVGzyG”
print(openai.api_key)
response = openai.Image().create(
prompt=PROMPT,
n=1,
size=“256x256”,
)
print(response[“data”][0][“url”])
I suppose this is official website. Please clarify whether bracket is required.
I tried putting a bracket. It gave the same result.
Please suggest a solution.
Also, please explain what is proper markdown to share code.
What @sps meant to say, I think, was when you post code and data samples, etc, you should always format your code using Markdown, normally using triple backticks, like this:
```
# your code goes here
# because formatting code makes is so much more easier to read
```
Your code looks good, BTW.
Maybe you can print out (for yourself) your API key so you can make sure you have your ENV variable set up correctly and also assign your image API call to the response variable and print out the entire response back from the API?
When you print the full response, you can see any error message from the API.
The code was crashing due to my own stupidity. I initially created a file called openai.py. Later I realized that it clashes with the library module openai. So I saved it under another name. But did not remove the original. This was the cause of circular reference.
The code started working after I removed the offending file.
Thanks for help.
The code works with bracket and also without bracket. I wonder how?
I am still not clear about markdown. Please explain.