Module: google.ai.generativelanguage

This package, google.ai.generativelanguage, is a low-level auto-generated client library for the PaLM API.

pip install google.ai.generativelanguage

It is built using the same tooling as Google Cloud client libraries, and will be quite familiar if you've used those before.

While we encourage Python users to access the PaLM API using the google.generativeai package (aka palm), this lower level package is also available.

Each method in the PaLM API is connected to one of the client classes. Pass your API-key to the class' client_options when initializing a client:

from google.ai import generativelanguage as glm

client = glm.DiscussServiceClient(
    client_options={'api_key':'YOUR_API_KEY'})

To call the api, pass an appropriate request-proto-object. For the DiscussServiceClient.generate_message pass a generativelanguage.GenerateMessageRequest instance:

request = glm.GenerateMessageRequest(
    model='models/chat-bison-001',
    prompt=glm.MessagePrompt(
        messages=[glm.Message(content='Hello!')]))

client.generate_message(request)
candidates {
  author: "1"
  content: "Hello! How can I help you today?"
}
...

For simplicity:

  • The API methods also accept key-word arguments.
  • Anywhere you might pass a proto-object, the library will also accept simple python structures.

So the following is equivalent to the previous example:

client.generate_message(
    model='models/chat-bison-001',
    prompt={'messages':[{'content':'Hello!'}]})
candidates {
  author: "1"
  content: "Hello! How can I help you today?"
}
...

Classes

class AttributionSourceId: Identifier for the source contributing to this attribution.

class BatchCreateChunksRequest: Request to batch create Chunk\ s.

class BatchCreateChunksResponse: Response from BatchCreateChunks containing a list of created Chunk\ s.

class BatchDeleteChunksRequest: Request to batch delete Chunk\ s.

class BatchEmbedContentsRequest: Batch request to get embeddings from the model for a list of prompts.

class BatchEmbedContentsResponse: The response to a BatchEmbedContentsRequest.

class BatchEmbedTextRequest: Batch request to get a text embedding from the model.

class BatchEmbedTextResponse: The response to a EmbedTextRequest.

class BatchUpdateChunksRequest: Request to batch update Chunk\ s.

class BatchUpdateChunksResponse: Response from BatchUpdateChunks containing a list of updated Chunk\ s.

class Blob: Raw media bytes.

class Candidate: A response candidate generated from the model.

class Chunk: A Chunk is a subpart of a Document that is treated as an independent unit for the purposes of vector representation and storage.

class ChunkData: Extracted data that represents the Chunk content.

class CitationMetadata: A collection of source attributions for a piece of content.

class CitationSource: A citation to a source for a portion of a specific response.

class Condition: Filter condition applicable to a single key.

class Content: The base structured datatype containing multi-part content of a message.

class ContentEmbedding: A list of floats representing an embedding.

class ContentFilter: Content filtering metadata associated with processing a single request.

class Corpus: A Corpus is a collection of Document\ s.

class CountMessageTokensRequest: Counts the number of tokens in the prompt sent to a model.

class CountMessageTokensResponse: A response from CountMessageTokens.

class CountTextTokensRequest: Counts the number of tokens in the prompt sent to a model.

class CountTextTokensResponse: A response from CountTextTokens.

class CountTokensRequest: Counts the number of tokens in the prompt sent to a model.

class CountTokensResponse: A response from CountTokens.

class CreateChunkRequest: Request to create a Chunk.

class CreateCorpusRequest: Request to create a Corpus.

class CreateDocumentRequest: Request to create a Document.

class CreatePermissionRequest: Request to create a Permission.

class CreateTunedModelMetadata: Metadata about the state and progress of creating a tuned model returned from the long-running operation

class CreateTunedModelRequest: Request to create a TunedModel.

class CustomMetadata: User provided metadata stored as key-value pairs.

class Dataset: Dataset for training or validation.

class DeleteChunkRequest: Request to delete a Chunk.

class DeleteCorpusRequest: Request to delete a Corpus.

class DeleteDocumentRequest: Request to delete a Document.

class DeletePermissionRequest: Request to delete the Permission.

class DeleteTunedModelRequest: Request to delete a TunedModel.

class DiscussServiceAsyncClient: An API for using Generative Language Models (GLMs) in dialog applications.

class DiscussServiceClient: An API for using Generative Language Models (GLMs) in dialog applications.

class Document: A Document is a collection of Chunk\ s.

class EmbedContentRequest: Request containing the Content for the model to embed.

class EmbedContentResponse: The response to an EmbedContentRequest.

class EmbedTextRequest: Request to get a text embedding from the model.

class EmbedTextResponse: The response to a EmbedTextRequest.

class Embedding: A list of floats representing the embedding.

class Example: An input/output example used to instruct the Model.

class FunctionCall: A predicted FunctionCall returned from the model that contains a string representing the FunctionDeclaration.name with the arguments and their values.

class FunctionDeclaration: Structured representation of a function declaration as defined by the OpenAPI 3.03 specification <<a href="https://spec.openapis.org/oas/v3.0.3">https://spec.openapis.org/oas/v3.0.3</a>>__.

class FunctionResponse: The result output from a FunctionCall that contains a string representing the FunctionDeclaration.name and a structured JSON object containing any output from the function is used as context to the model.

class GenerateAnswerRequest: Request to generate a grounded answer from the model.

class GenerateAnswerResponse: Response from the model for a grounded answer.

class GenerateContentRequest: Request to generate a completion from the model.

class GenerateContentResponse: Response from the model supporting multiple candidates.

class GenerateMessageRequest: Request to generate a message response from the model.

class GenerateMessageResponse: The response from the model.

class GenerateTextRequest: Request to generate a text completion response from the model.

class GenerateTextResponse: The response from the model, including candidate completions.

class GenerationConfig: Configuration options for model generation and outputs.

class GenerativeServiceAsyncClient: API for using Large Models that generate multimodal content and have additional capabilities beyond text generation.

class GenerativeServiceClient: API for using Large Models that generate multimodal content and have additional capabilities beyond text generation.

class GetChunkRequest: Request for getting information about a specific Chunk.

class GetCorpusRequest: Request for getting information about a specific Corpus.

class GetDocumentRequest: Request for getting information about a specific Document.

class GetModelRequest: Request for getting information about a specific Model.

class GetPermissionRequest: Request for getting information about a specific Permission.

class GetTunedModelRequest: Request for getting information about a specific Model.

class GroundingAttribution: Attribution for a source that contributed to an answer.

class GroundingPassage: Passage included inline with a grounding configuration.

class GroundingPassages: A repeated list of passages.

class HarmCategory: The category of a rating.

class Hyperparameters: Hyperparameters controlling the tuning process.

class ListChunksRequest: Request for listing Chunk\ s.

class ListChunksResponse: Response from ListChunks containing a paginated list of Chunk\ s.

class ListCorporaRequest: Request for listing Corpora.

class ListCorporaResponse: Response from ListCorpora containing a paginated list of Corpora.

class ListDocumentsRequest: Request for listing Document\ s.

class ListDocumentsResponse: Response from ListDocuments containing a paginated list of Document\ s.

class ListModelsRequest: Request for listing all Models.

class ListModelsResponse: Response from ListModel containing a paginated list of Models.

class ListPermissionsRequest: Request for listing permissions.

class ListPermissionsResponse: Response from ListPermissions containing a paginated list of permissions.

class ListTunedModelsRequest: Request for listing TunedModels.

class ListTunedModelsResponse: Response from ListTunedModels containing a paginated list of Models.

class Message: The base unit of structured text.

class MessagePrompt: All of the structured input text passed to the model as a prompt.

class MetadataFilter: User provided filter to limit retrieval based on Chunk or Document level metadata values.

class Model: Information about a Generative Language Model.

class ModelServiceAsyncClient: Provides methods for getting metadata information about Generative Models.

class ModelServiceClient: Provides methods for getting metadata information about Generative Models.

class Part: A datatype containing media that is part of a multi-part Content message.

class Permission: Permission resource grants user, group or the rest of the world access to the PaLM API resource (e.g.

class PermissionServiceAsyncClient: Provides methods for managing permissions to PaLM API resources.

class PermissionServiceClient: Provides methods for managing permissions to PaLM API resources.

class QueryCorpusRequest: Request for querying a Corpus.

class QueryCorpusResponse: Response from QueryCorpus containing a list of relevant chunks.

class QueryDocumentRequest: Request for querying a Document.

class QueryDocumentResponse: Response from QueryDocument containing a list of relevant chunks.

class RelevantChunk: The information for a chunk relevant to a query.

class RetrieverServiceAsyncClient: An API for semantic search over a corpus of user uploaded content.

class RetrieverServiceClient: An API for semantic search over a corpus of user uploaded content.

class SafetyFeedback: Safety feedback for an entire request.

class SafetyRating: Safety rating for a piece of content.

class SafetySetting: Safety setting, affecting the safety-blocking behavior.

class Schema: The Schema object allows the definition of input and output data types.

class SemanticRetrieverConfig: Configuration for retrieving grounding content from a Corpus or Document created using the Semantic Retriever API.

class StringList: User provided string values assigned to a single metadata key.

class TaskType: Type of task for which the embedding will be used.

class TextCompletion: Output text returned from a model.

class TextPrompt: Text given to the model as a prompt.

class TextServiceAsyncClient: API for using Generative Language Models (GLMs) trained to generate text.

class TextServiceClient: API for using Generative Language Models (GLMs) trained to generate text.

class Tool: Tool details that the model may use to generate response.

class TransferOwnershipRequest: Request to transfer the ownership of the tuned model.

class TransferOwnershipResponse: Response from TransferOwnership.

class TunedModel: A fine-tuned model created using ModelService.CreateTunedModel.

class TunedModelSource: Tuned model as a source for training a new model.

class TuningExample: A single example for tuning.

class TuningExamples: A set of tuning examples.

class TuningSnapshot: Record for a single tuning step.

class TuningTask: Tuning tasks that create tuned models.

class Type: Type contains the list of OpenAPI data types as defined by https://spec.openapis.org/oas/v3.0.3#data-types

class UpdateChunkRequest: Request to update a Chunk.

class UpdateCorpusRequest: Request to update a Corpus.

class UpdateDocumentRequest: Request to update a Document.

class UpdatePermissionRequest: Request to update the Permission.

class UpdateTunedModelRequest: Request to update a TunedModel.