Package: google-generativeai
Google AI Python SDKThe Google AI Python SDK enables developers to use Google's state-of-the-art generative AI
models (like Gemini and PaLM) to build AI-powered features and applications. This SDK
supports use cases like:Generate text from text-only inputGenerate text from text-and-images input (multimodal) (for Gemini only)Build multi-turn conversations (chat)EmbeddingFor example, with just a few lines of code, you can access Gemini's multimodal
capabilities to generate text from text-and-image input:model = genai.GenerativeModel('gemini-pro-vision')

cookie_picture = {
    'mime_type': 'image/png',
    'data': Path('cookie.png').read_bytes()
}
prompt = "Give me a recipe for this:"

response = model.generate_content(
    content=[prompt, cookie_picture]
)
print(response.text)Try out the APIInstall from PyPI.pip install google-generativeaiObtain an API key from AI Studio,
then configure it here.Import the SDK and load a model.import google.generativeai as genai

genai.configure(api_key=os.environ["API_KEY"])

model = genai.GenerativeModel('gemini-pro')UseGenerativeModel.generate_contentto have the model complete some initial text.response = model.generate_content("The opposite of hot is")
print(response.text)  # cold.UseGenerativeModel.start_chatto have a discussion with a model.chat = model.start_chat()
response = chat.send_message('Hello, what should I have for dinner?')
print(response.text) #  'Here are some suggestions...'
response = chat.send_message("How do I cook the first one?")Installation and usageRunpip install google-generativeai.For detailed instructions, you can find aquickstartfor the Google AI
Python SDK in the Google documentation.This quickstart describes how to add your API key and install the SDK in your app,
initialize the model, and then call the API to access the model. It also describes some
additional use cases and features, like streaming, embedding, counting tokens, and
controlling responses.DocumentationFind complete documentation for the Google AI SDKs and the Gemini model in the Google
documentation:https://ai.google.dev/docsContributingSeeContributingfor more information on contributing to the Google AI Python SDK.Developers who use the PaLM APIMigrate to use the Gemini APICheck ourmigration guidein the Google
documentation.Installation and usage for the PaLM APIInstall from PyPI.pip install google-generativeaiObtain an API key from AI Studio, then
configure it here.import google.generativeai as palm

palm.configure(api_key=os.environ["PALM_API_KEY"])Usepalm.generate_textto have the model complete some initial text.response = palm.generate_text(prompt="The opposite of hot is")
print(response.result)  # cold.Usepalm.chatto have a discussion with a model.response = palm.chat(messages=["Hello."])
print(response.last) #  'Hello! What can I help you with?'
response.reply("Can you tell me a joke?")Documentation for the PaLM APIGeneral PaLM documentationText quickstartChat quickstartTuning quickstartColab magicsOnce installed, use the Python client via the%%palmColab magic. Read thefull guide.%%palm
The best thing since sliced bread isLicenseThe contents of this repository are licensed under theApache License, version 2.0.