0
0
Prompt Engineering / GenAIml~10 mins

DALL-E API usage in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the OpenAI client from the OpenAI library.

Prompt Engineering / GenAI
from openai import [1]
Drag options to blanks, or click blank then click option'
AOpenAI
BDalleApi
CDalle
DDALL-E
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like 'DALL-E' or 'DalleApi'.
Trying to import a module instead of the client class.
2fill in blank
medium

Complete the code to create an OpenAI client instance using the API key stored in the environment variable.

Prompt Engineering / GenAI
client = OpenAI(api_key=[1])
Drag options to blanks, or click blank then click option'
Aos.environ['OPENAI_API_KEY']
Bos.environ['API_KEY']
Cos.getenv('OPENAI_API_KEY')
Dos.getenv('API_KEY')
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong environment variable name.
Using os.environ which throws error if variable is missing.
3fill in blank
hard

Fix the error in the code to generate an image with DALL-E using a prompt string.

Prompt Engineering / GenAI
response = client.images.generate(model="dall-e-2", prompt=[1])
Drag options to blanks, or click blank then click option'
AA sunset over mountains
B{'prompt': 'A sunset over mountains'}
C['A sunset over mountains']
D'A sunset over mountains'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the prompt without quotes causing a NameError.
Passing a list or dictionary instead of a string.
4fill in blank
hard

Fill both blanks to set the image size and number of images to generate.

Prompt Engineering / GenAI
response = client.images.generate(model="dall-e-2", prompt='A cat playing piano', size=[1], n=[2])
Drag options to blanks, or click blank then click option'
A'1024x1024'
B'512x512'
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using integers for size instead of string.
Setting n to a string instead of an integer.
5fill in blank
hard

Fill all three blanks to extract the image URL from the response dictionary.

Prompt Engineering / GenAI
image_url = response.[1][[2]].[3]
Drag options to blanks, or click blank then click option'
Adata
B0
Curl
Dimages
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like 'images' instead of 'data'.
Using string '0' instead of integer 0 for index.
Trying to access 'url' directly from response.