OptLLM: Optimal Assignment of Queries to Large Language Models