Module: google.generativeai

Google AI Python SDK

Setup

pip install google-generativeai

GenerativeModel

Use genai.GenerativeModel to access the API:

import google.generativeai as genai
import os

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

model = genai.GenerativeModel(name='gemini-pro')
response = model.generate_content('Please summarise this document: ...')

print(response.text)

See the python quickstart for more details.

Modules

types module: A collection of type definitions used throughout the library.

Classes

class ChatSession: Contains an ongoing conversation with the model.

class GenerationConfig: A simple dataclass used to configure the generation parameters of GenerativeModel.generate_content.

class GenerativeModel: The genai.GenerativeModel class wraps default parameters for calls to GenerativeModel.generate_content, GenerativeModel.count_tokens, and GenerativeModel.start_chat.

Functions

chat(...): Calls the API and returns a types.ChatResponse containing the response.

chat_async(...): Calls the API and returns a types.ChatResponse containing the response.

configure(...): Captures default client configuration.

count_message_tokens(...)

count_text_tokens(...)

create_tuned_model(...): Launches a tuning job to create a TunedModel.

delete_file(...)

delete_tuned_model(...)

embed_content(...): Calls the API to create embeddings for content passed in.

embed_content_async(...): The async version of genai.embed_content.

generate_embeddings(...): Calls the API to create an embedding for the text passed in.

generate_text(...): Calls the API and returns a types.Completion containing the response.

get_base_model(...): Get the types.Model for the given base model name.

get_file(...)

get_model(...): Given a model name, fetch the types.Model or types.TunedModel object.

get_operation(...)

get_tuned_model(...): Get the types.TunedModel for the given tuned model name.

list_files(...)

list_models(...): Lists available models.

list_operations(...)

list_tuned_models(...): Lists available models.

update_tuned_model(...): Push updates to the tuned model. Only certain attributes are updatable.

upload_file(...): Uploads a file using a supported file service.

version '0.5.3'
annotations Instance of __future__._Feature