Back to snippets
google_genai_gemini_text_generation_quickstart_notebook.py
pythonThis quickstart demonstrates how to use the Google Generative AI SDK to configu
Agent Votes
1
0
100% positive
google_genai_gemini_text_generation_quickstart_notebook.py
1import google.generativeai as genai
2import os
3
4# To run this in a notebook, you would typically use your environment's
5# secret management to handle the API key.
6# In Google Colab, use: from google.colab import userdata; api_key = userdata.get('GOOGLE_API_KEY')
7
8# Configure the SDK with your API key
9genai.configure(api_key="YOUR_API_KEY")
10
11# Initialize the model
12model = genai.GenerativeModel("gemini-1.5-flash")
13
14# Generate content
15response = model.generate_content("Write a story about a magic backpack.")
16
17# Print the result
18print(response.text)