RAG and Vector Search · Exercise 6 of 6 Previous
Intermediate
Build the standalone-question prompt
history is a list of (role, text) pairs. Write standalone_prompt(history, message, max_turns=2).
Keep only the last max_turns * 2 messages and cut each text to its first 40 characters. Return "Conversation: " + <messages joined with " | ", each written as "Role: text"> + " | Last message: " + message.
With an empty history return just "Last message: " + message.
What Check tests
- Builds the prompt from a short history
- An empty history gives only the last message
- Only the last turns are kept
- Long messages are cut to 40 characters
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.