Google AI Python SDK Example
Installation
$ pip install google-generativeai
See the getting started guide for more information.
Python Code
import os
import google.generativeai as genai
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
# Create the model
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
generation_config=generation_config,
# safety_settings = Adjust safety settings
# See https://ai.google.dev/gemini-api/docs/safety-settings
)
chat_session = model.start_chat(
history=[
]
)
response = chat_session.send_message("INSERT_INPUT_HERE")
print(response.text)
To use this code, make sure to:
- Set the
GEMINI_API_KEYin your environment variables. - Replace
"INSERT_INPUT_HERE"with your actual input message.