Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the OpenAI library.
Prompt Engineering / GenAI
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated libraries like tensorflow or numpy.
Using uppercase letters in the import statement.
✗ Incorrect
The OpenAI Python library is imported using import openai.
2fill in blank
mediumComplete the code to set your OpenAI API key.
Prompt Engineering / GenAI
openai.api_key = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Hardcoding the API key as a string.
Using an invalid key format.
✗ Incorrect
Using os.getenv('OPENAI_API_KEY') safely loads the API key from environment variables.
3fill in blank
hardFix the error in the code to create an embedding for the text.
Prompt Engineering / GenAI
response = openai.Embedding.create(input=[1], model='text-embedding-3-small')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string instead of a list.
Passing a number or None as input.
✗ Incorrect
The input parameter must be a list of strings, so ['Hello world'] is correct.
4fill in blank
hardFill both blanks to extract the embedding vector from the response.
Prompt Engineering / GenAI
embedding_vector = response['data'][[1]]['[2]']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 instead of 0.
Using the wrong key like 'vector'.
✗ Incorrect
The embedding is stored in response['data'][0]['embedding'].
5fill in blank
hardFill all three blanks to create an embedding and print its length.
Prompt Engineering / GenAI
response = openai.Embedding.create(input=[1], model=[2]) embedding = response['data'][0][[3]] print(len(embedding))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing input as a string instead of a list.
Using an incorrect model name.
Accessing the wrong key in the response.
✗ Incorrect
We pass a list of strings as input, specify the correct model name, and access the 'embedding' key to get the vector.