Intermediate
Refuse before the model is called
build_prompt(question, hits) is given. hits is a list of (doc_id, score, text) triples, best first. model is a function that takes the prompt and returns a string.
Write answer(question, hits, model, threshold=0.40). Keep only the hits whose score is at least the threshold. If none remain, return REFUSAL and do not call the model. Otherwise return model(build_prompt(question, kept)).
What Check tests
- Scores below the threshold are refused
- An empty hit list is refused
- A good hit calls the model once and returns its reply
- Only hits above the threshold reach the prompt
- A score exactly at the threshold is answered
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.