Why is OpenAI capitalised and works in the beginner tutorial

In the chatcompletions tutorial, this code is used:

from openai import OpenAI
client = OpenAI()

completion = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
    {"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."}
  ]
)

print(completion.choices[0].message)

I’m trying to understand why we are using capitlisation on the O, and AI - here OpenAI in the import statement. In other documentation I’ve seen and even when I’ve asked ChatGPT what the correct capitlisation should be, it seems it used to be openai, i.e. from openai import openai however, that seems to have changed, as the documentation above suggests, and this code runs fine.

How comes this changed? did it change? I thought these import statements were usually lower case? why is this using a combination of upper and lowercase? curious to learn.

Thanks

1 Like

“openai” is the name of the library package.

“OpenAI” for the client object class, and others that are capitalized, are python classes.

__init__.py:

from ._utils import file_from_path
from ._client import (
    Client,
    OpenAI,
    Stream,
    Timeout,
    Transport,
    AsyncClient,
    AsyncOpenAI,
    AsyncStream,
    RequestOptions,
)
from ._version import __title__, __version__
...

_client:

class OpenAI(SyncAPIClient):
    completions: resources.Completions
    chat: resources.Chat
    edits: resources.Edits
    embeddings: resources.Embeddings
    files: resources.Files
    images: resources.Images
    audio: resources.Audio
    moderations: resources.Moderations
    models: resources.Models
    fine_tuning: resources.FineTuning
    fine_tunes: resources.FineTunes
    beta: resources.Beta
    with_raw_response: OpenAIWithRawResponse

etc…

1 Like