0
0
Prompt Engineering / GenAIml~10 mins

Chat completions endpoint 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 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'
A"Hello, how are you?"
BHello, how are you?
C'Hello, how are you?'
DHello how are you
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the message content inside quotes.
Using single quotes instead of double quotes in JSON.
2fill in blank
medium

Complete 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'
Aresponse
Btext
Ccontent
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' instead of 'message'.
Trying to access 'content' directly from choices[0].
3fill in blank
hard

Fix 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'
AWhat is the weather today?
B'What is the weather today?'
C"What is the weather today?"
DWhat is the weather today
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the message content.
Using single quotes instead of double quotes.
4fill in blank
hard

Fill 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'
A"system"
B"assistant"
C"user"
D"bot"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'assistant' or 'bot' as the user role.
Not quoting the role strings.
5fill in blank
hard

Fill 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'
Achoices
Bmessage
Ccontent
Dresults
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'results' instead of 'choices'.
Accessing 'content' directly from choices[0].
Missing the 'message' attribute.