TIGER-AI-Lab / ImagenHub

A one-stop library to standardize the inference and evaluation of all the conditional image generation models. (ICLR 2024)
https://tiger-ai-lab.github.io/ImagenHub/
MIT License
150 stars 12 forks source link

OpenAI API bug: AttributeError: module 'openai' has no attribute 'error' #32

Open mjalali opened 4 months ago

mjalali commented 4 months ago

Describe the bug The openai package version.

To Reproduce Run the following code:

model = imagen_hub.load("DALLE2")
image = model.infer_one_image(prompt="some prompt", seed=1)

Expected behavior To generate the image

Screenshots

Read key from OPENAI_API_KEY
Traceback (most recent call last):
  File "/research/d2/rshr/mohammad/evaluation/text-to-image/ImagenHub/src/imagen_hub/infermodels/dalle.py", line 75, in infer_one_image
    response = openai.Image.create(
  File "/research/d2/rshr/mohammad/miniconda3/envs/imagen/lib/python3.9/site-packages/openai/lib/_old_api.py", line 39, in __call__
    raise APIRemovedInV1(symbol=self._symbol)
openai.lib._old_api.APIRemovedInV1: 

You tried to access openai.Image, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.

You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface. 

Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`

A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/research/d2/rshr/mohammad/evaluation/text-to-image/test.py", line 7, in <module>
    image = model.infer_one_image(prompt="hello", seed=1)
  File "/research/d2/rshr/mohammad/evaluation/text-to-image/ImagenHub/src/imagen_hub/infermodels/dalle.py", line 85, in infer_one_image
    except openai.error.OpenAIError as e:
AttributeError: module 'openai' has no attribute 'error'
(imagen) projgpu32:/research/d2/rshr/mohammad/evaluation/text-to-image> python test.py 
WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions. xFormers was built for:
    PyTorch 2.3.1+cu121 with CUDA 1201 (you have 2.3.1)
    Python  3.9.19 (you have 3.9.19)
  Please reinstall xformers (see https://github.com/facebookresearch/xformers#installing-xformers)
  Memory-efficient attention, SwiGLU, sparse and more won't be available.
  Set XFORMERS_MORE_DETAILS=1 for more details
/research/d2/rshr/mohammad/miniconda3/envs/imagen/lib/python3.9/site-packages/diffusers/models/vq_model.py:20: FutureWarning: `VQEncoderOutput` is deprecated and will be removed in version 0.31. Importing `VQEncoderOutput` from `diffusers.models.vq_model` is deprecated and this will be removed in a future version. Please use `from diffusers.models.autoencoders.vq_model import VQEncoderOutput`, instead.
  deprecate("VQEncoderOutput", "0.31", deprecation_message)
/research/d2/rshr/mohammad/miniconda3/envs/imagen/lib/python3.9/site-packages/diffusers/models/vq_model.py:25: FutureWarning: `VQModel` is deprecated and will be removed in version 0.31. Importing `VQModel` from `diffusers.models.vq_model` is deprecated and this will be removed in a future version. Please use `from diffusers.models.autoencoders.vq_model import VQModel`, instead.
  deprecate("VQModel", "0.31", deprecation_message)
Read key from OPENAI_API_KEY
Traceback (most recent call last):
  File "/research/d2/rshr/mohammad/evaluation/text-to-image/ImagenHub/src/imagen_hub/infermodels/dalle.py", line 41, in infer_one_image
    response = openai.Image.create(
  File "/research/d2/rshr/mohammad/miniconda3/envs/imagen/lib/python3.9/site-packages/openai/lib/_old_api.py", line 39, in __call__
    raise APIRemovedInV1(symbol=self._symbol)
openai.lib._old_api.APIRemovedInV1: 

You tried to access openai.Image, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.

You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface. 

Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`

A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/research/d2/rshr/mohammad/evaluation/text-to-image/test.py", line 7, in <module>
    image = model.infer_one_image(prompt="hello", seed=1)
  File "/research/d2/rshr/mohammad/evaluation/text-to-image/ImagenHub/src/imagen_hub/infermodels/dalle.py", line 49, in infer_one_image
    except openai.error.OpenAIError as e:
AttributeError: module 'openai' has no attribute 'error'

Desktop (please complete the following information):

Software Packages (please complete the following information):

vinesmsuic commented 4 months ago

Does it work with old version?

pip install openai==0.28