RAG and Vector Search · Exercise 5 of 5 Previous
Intermediate
Stop a search loop
actions is a list of strings: "search: <query>" or "answer: <text>". Write run_loop(actions, max_steps) that goes through at most max_steps actions and returns a string.
If an action starts with answer: , return "answered: " followed by the text. If a search query was already used, return "stopped: repeated query". If max_steps actions are used up without an answer, return "stopped: step limit".
What Check tests
- An answer ends the loop
- A repeated query stops the loop
- The step limit stops the loop
- An answer at the last step still counts
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.