Learning from Contrastive Prompts: Automated Optimization and Adaptation