Command Palette

Search for a command to run...

Hectal
Phase 7: Query Understanding
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

  1. Builds the prompt from a short history
  2. An empty history gives only the last message
  3. Only the last turns are kept
  4. 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.