0
0
Prompt Engineering / GenAIml~10 mins

First interaction with GenAI APIs - 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 GenAI client library.

Prompt Engineering / GenAI
from genai import [1]
Drag options to blanks, or click blank then click option'
APipeline
BModel
CClient
DTokenizer
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Model instead of Client
Importing Pipeline which is not needed here
2fill in blank
medium

Complete the code to create a GenAI client with your API key.

Prompt Engineering / GenAI
client = Client(api_key=[1])
Drag options to blanks, or click blank then click option'
A'your_api_key_here'
Byour_api_key_here
CAPI_KEY
D12345
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the API key
Using a number instead of a string
3fill in blank
hard

Fix the error in the code to generate text using the client.

Prompt Engineering / GenAI
response = client.generate(model='gpt-4', prompt=[1])
Drag options to blanks, or click blank then click option'
A['Hello, how are you?']
BHello, how are you?
CNone
D'Hello, how are you?'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing prompt without quotes
Passing a list instead of a string
4fill in blank
hard

Fill both blanks to extract the generated text from the response.

Prompt Engineering / GenAI
generated_text = response.[1][0].[2]
Drag options to blanks, or click blank then click option'
Agenerations
Btext
Cchoices
Dcontent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'choices' instead of 'generations'
Using 'content' instead of 'text'
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps prompts to their generated texts.

Prompt Engineering / GenAI
results = { [1]: response.[2][0].[3] for prompt in prompts }
Drag options to blanks, or click blank then click option'
Aprompt
Bgenerations
Ctext
Dresponse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'response' as key instead of 'prompt'
Using 'content' instead of 'text'
Using 'choices' instead of 'generations'