MAS-GPT: Training LLMs to Build LLM-based Multi-Agent Systems