Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Model instead of Client
Importing Pipeline which is not needed here
✗ Incorrect
The Client class is used to interact with GenAI APIs, so we import it first.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the API key
Using a number instead of a string
✗ Incorrect
The API key must be a string, so it needs quotes around it.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing prompt without quotes
Passing a list instead of a string
✗ Incorrect
The prompt must be a string, so it needs quotes around it.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'choices' instead of 'generations'
Using 'content' instead of 'text'
✗ Incorrect
The response object has a generations list, and each generation has a text attribute with the output.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'response' as key instead of 'prompt'
Using 'content' instead of 'text'
Using 'choices' instead of 'generations'
✗ Incorrect
This comprehension creates a dictionary where each prompt maps to the first generated text in generations.