Optimizing Prompt Engineering for Generative AI