0
0
Prompt Engineering / GenAIml~10 mins

Conversation management 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 initialize a conversation history list.

Prompt Engineering / GenAI
conversation_history = [1]
Drag options to blanks, or click blank then click option'
A{}
B''
C[]
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a dictionary {} instead of a list.
Using an empty string '' which cannot hold multiple messages.
2fill in blank
medium

Complete the code to add a user message to the conversation history.

Prompt Engineering / GenAI
conversation_history.[1]({'role': 'user', 'content': user_input})
Drag options to blanks, or click blank then click option'
Ainsert
Bextend
Cpop
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop which removes items.
Using extend which expects an iterable.
3fill in blank
hard

Fix the error in the code to retrieve the last message from conversation history.

Prompt Engineering / GenAI
last_message = conversation_history[1]
Drag options to blanks, or click blank then click option'
A[0]
B[-1]
C[-2]
D[1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 which gets the first message, not the last.
Using index 1 which gets the second message.
4fill in blank
hard

Fill both blanks to filter messages from the assistant only.

Prompt Engineering / GenAI
assistant_messages = [msg for msg in conversation_history if msg[1] 'role' [2] 'assistant']
Drag options to blanks, or click blank then click option'
A['role']
B==
C!=
D['content']
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which filters out assistant messages.
Accessing the wrong key like 'content'.
5fill in blank
hard

Fill all three blanks to create a summary dictionary of user messages count and last assistant message.

Prompt Engineering / GenAI
summary = [1](
    'user_count': sum(1 for msg in conversation_history if msg['role'] [2] 'user'),
    'last_assistant': next((msg['content'] for msg in conversation_history if msg['role'] [3] 'assistant'), None)
)
Drag options to blanks, or click blank then click option'
Adict
B==
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using list instead of dict for summary.
Using != which reverses the logic.