Multimodal Prompting with Google Gemini
Learn how to get the most out of Google Gemini.
With our API key set up and working, we can send prompts to Gemini. Let’s rewind back to the cookie recipe example we used earlier in the What Are Generative AI Models? lesson. We mentioned that the model’s response will depend on the question we ask it. These questions are referred to as prompts. Prompts guide the model’s output and influence the type of response we can expect. For instance, a prompt asking for “a simple cookie recipe” will yield a basic set of instructions, whereas asking the model to “use the text from the recipe note, the audio description of the flavor, and the image of the cookie to give a chocolate chip cookie recipe that best fits the profile” will result in a more elaborate and specific response.
Sending a text prompt
Let’s try to generate some content. We’ll use Python and Google’s google-generativeai library to access Gemini.
Let’s briefly go through the code.
Import libraries: We import the
genailibrary on line 2, which provides functions to interact with Google’s Generative AI models.API key: On line 5, we replace
API_KEYwith your actual API key obtained earlier.Authentication: We configure the
genailibrary with the API key for secure access to Gemini models on line 8.Model selection: We select the
gemini-1.5-flashmodel for text generation on line 11. This is done using theGenerativeModelclass from the library and providing the model name as an argument.Text generation: The
generate_content()method is used on line 14. This method is passed a ...