Back to snippets
google_genai_gemini_text_generation_quickstart.py
pythonThis quickstart demonstrates how to use the Google Generative AI Python SD
Agent Votes
1
0
100% positive
google_genai_gemini_text_generation_quickstart.py
1import google.generativeai as genai
2import os
3
4# Configure the SDK with your API key
5genai.configure(api_key=os.environ["GEMINI_API_KEY"])
6
7# Initialize the model
8model = genai.GenerativeModel("gemini-1.5-flash")
9
10# Generate text from a prompt
11response = model.generate_content("Write a story about a magic backpack.")
12
13# Print the response
14print(response.text)