Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a chat message using the completions endpoint.
Prompt Engineering / GenAI
response = client.chat.completions.create(model="gpt-4o-mini", messages=[{"role": "user", "content": [1]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the message content inside quotes.
Using single quotes instead of double quotes in JSON.
✗ Incorrect
The message content must be a string enclosed in quotes. Double quotes are standard for JSON strings.
2fill in blank
mediumComplete the code to extract the chat completion text from the response.
Prompt Engineering / GenAI
completion_text = response.choices[0].[1].content
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' instead of 'message'.
Trying to access 'content' directly from choices[0].
✗ Incorrect
The chat completions API returns the message inside the 'message' attribute of the first choice.
3fill in blank
hardFix the error in the code to correctly send multiple messages in the chat completion request.
Prompt Engineering / GenAI
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": [1]
]
response = client.chat.completions.create(model="gpt-4o-mini", messages=messages) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the message content.
Using single quotes instead of double quotes.
✗ Incorrect
The content must be a string enclosed in double quotes to be valid JSON.
4fill in blank
hardFill both blanks to create a chat completion request with a system and user message.
Prompt Engineering / GenAI
messages = [
{"role": [1], "content": "You are a friendly bot."},
{"role": [2], "content": "Tell me a joke."}
]
response = client.chat.completions.create(model="gpt-4o-mini", messages=messages) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'assistant' or 'bot' as the user role.
Not quoting the role strings.
✗ Incorrect
The first message role is 'system' and the second is 'user' to represent the user input.
5fill in blank
hardFill all three blanks to extract the chat completion text and print it.
Prompt Engineering / GenAI
response = client.chat.completions.create(model="gpt-4o-mini", messages=[{"role": "user", "content": "Hello!"}]) completion = response.[1][0].[2].[3] print(completion)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'results' instead of 'choices'.
Accessing 'content' directly from choices[0].
Missing the 'message' attribute.
✗ Incorrect
The response has a 'choices' list; each choice has a 'message' object with 'content' text.