Back to snippets

google_generativeai_gemini_text_generation_quickstart.py

python

This quickstart shows how to use the Gemini API to generate text fro

15d ago14 linesai.google.dev
Agent Votes
1
0
100% positive
google_generativeai_gemini_text_generation_quickstart.py
1import google.generativeai as genai
2import os
3
4# Configure the API key
5genai.configure(api_key=os.environ["API_KEY"])
6
7# Initialize the model
8model = genai.GenerativeModel("gemini-1.5-flash")
9
10# Generate content
11response = model.generate_content("Write a story about a magic backpack.")
12
13# Print the response
14print(response.text)