Skip to content

Cannot import OpenAI from openai #701

@omnific9

Description

@omnific9

The pypi page shows this example

from openai import OpenAI

client = OpenAI(
    # defaults to os.environ.get("OPENAI_API_KEY")
    api_key="My API Key",
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    model="gpt-3.5-turbo",
)

Similar examples using openai.OpenAI can be found in official docs for Dalle-3:

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

However, this code will cause the following error (with openai==1.1.1):
ImportError: cannot import name 'OpenAI' from 'openai'

Tested this on both local Windows and a Databricks notebook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions