0
0
Prompt Engineering / GenAIml~10 mins

OpenAI embeddings API 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 library.

Prompt Engineering / GenAI
import [1]
Drag options to blanks, or click blank then click option'
Aopenai
Btensorflow
Cnumpy
Dpandas
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated libraries like tensorflow or numpy.
Using uppercase letters in the import statement.
2fill in blank
medium

Complete 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'
Aos.getenv('OPENAI_API_KEY')
B12345
C'my_api_key'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Hardcoding the API key as a string.
Using an invalid key format.
3fill in blank
hard

Fix 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'
A'Hello world'
BNone
C123
D['Hello world']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string instead of a list.
Passing a number or None as input.
4fill in blank
hard

Fill 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'
A0
B1
Cembedding
Dvector
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 instead of 0.
Using the wrong key like 'vector'.
5fill in blank
hard

Fill 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'
A['OpenAI is great']
B'text-embedding-3-large'
C'embedding'
D'data'
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.