Complete the code to add the latest user message to the conversation history list.
conversation_history.append([1])The conversation history stores all user messages and model responses. Here, we add the latest user message.
Complete the code to retrieve the last 3 messages from the conversation history.
recent_history = conversation_history[1]Using [-3:] slices the list to get the last three messages.
Fix the error in the code that tries to clear the conversation history.
conversation_history.[1]()remove() which requires an argument.pop() which removes only the last item.The clear() method empties the list. Other options either remove one item or are invalid.
Fill both blanks to create a dictionary of message counts by speaker.
counts = {speaker: conversation_history.count([1]) for speaker in [2]We count how many times the string 'user' appears for each speaker in the list ['user', 'assistant'].
Fill all three blanks to filter conversation history for user messages longer than 10 characters.
filtered = [msg for msg in conversation_history if msg[1] [2] and len(msg) [3] 10]
The code filters messages that start with 'user' and have length greater than 10.