Command Palette

Search for a command to run...

Hectal
Phase 16: Python in the AI Era
Python · Exercise 4 of 6 PreviousNext
Beginner

Build a RAG prompt with numbered sources

Write build_rag_prompt(question, sources) that returns one string with these lines, in order: an instruction line, then one line per source in the form [1] text, [2] text and so on, then the last line Question: <question>.

sources is a list of strings. If it is empty, use a single line No sources found. instead of the numbered lines. The instruction line can say anything, but it must contain the word cite. Join the lines with "\n". (Topic 16.9.)

What Check tests

  1. Numbers the sources from 1
  2. Ends with the question line
  3. Uses a fallback line when there are no sources
  4. The instruction mentions citing

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.