0
0
Prompt Engineering / GenAIml~10 mins

Memory for conversation history 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 add the latest user message to the conversation history list.

Prompt Engineering / GenAI
conversation_history.append([1])
Drag options to blanks, or click blank then click option'
Aconversation_history
Bmodel_response
Csystem_prompt
Duser_message
Attempts:
3 left
💡 Hint
Common Mistakes
Adding the model's response instead of the user's message.
Appending the entire conversation history again.
2fill in blank
medium

Complete the code to retrieve the last 3 messages from the conversation history.

Prompt Engineering / GenAI
recent_history = conversation_history[1]
Drag options to blanks, or click blank then click option'
A[:3]
B[3:]
C[-3:]
D[-1:]
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive indices which get the first items instead of last.
Using only one negative index which gets only one item.
3fill in blank
hard

Fix the error in the code that tries to clear the conversation history.

Prompt Engineering / GenAI
conversation_history.[1]()
Drag options to blanks, or click blank then click option'
Apop
Bclear
Cremove
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove() which requires an argument.
Using pop() which removes only the last item.
4fill in blank
hard

Fill both blanks to create a dictionary of message counts by speaker.

Prompt Engineering / GenAI
counts = {speaker: conversation_history.count([1]) for speaker in [2]
Drag options to blanks, or click blank then click option'
A'user'
B'assistant'
C['user', 'assistant']
D'system'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string instead of a list for speakers.
Counting 'assistant' messages inside the 'user' count.
5fill in blank
hard

Fill all three blanks to filter conversation history for user messages longer than 10 characters.

Prompt Engineering / GenAI
filtered = [msg for msg in conversation_history if msg[1] [2] and len(msg) [3] 10]
Drag options to blanks, or click blank then click option'
Astartswith
B== 'user'
C>
Dendswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'endswith' instead of 'startswith'.
Using '<' instead of '>' for length comparison.