The Inner Workings of Generative AI: A Comprehensive Guide