...

/

Multimodal Prompting with Google Gemini

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.

Press + to interact
Please provide values for the following:
API_KEY
Not Specified...
# Import the library
import google.generativeai as genai
# Your API key will be replaced here
API_KEY = "{{API_KEY}}"
# Set up authentication with API key
genai.configure(api_key=API_KEY)
# Choose the Gemini Flash model
model = genai.GenerativeModel('gemini-1.5-flash')
# Generate text with a prompt
response = model.generate_content("What kind of a tree can you carry in your hand?")
# Print the generated content
print(response.text)

Let’s briefly go through the code.

  • Import libraries: We import the genai library on line 2, which provides functions to interact with Google’s Generative AI models.

  • API key: On line 5, we replace API_KEY with your actual API key obtained earlier.

  • Authentication: We configure the genai library with the API key for secure access to Gemini models on line 8.

  • Model selection: We select the gemini-1.5-flash model for text ...