Optimizing Model Selection for Compound AI Systems