Controlling Risk of Retrieval-augmented Generation: A Counterfactual Prompting Framework