google_generative_ai library

Google generative AI SDK API bindings for Dart.

The Google Generative AI SDK for Dart allows developers to use state-of-the-art Large Language Models (LLMs) to build applications.

Most uses of this library will be through a GenerativeModel. Here's a simple example of using this API:

const apiKey = ...;

void main() async {
  final model = GenerativeModel(
      model: 'gemini-1.5-flash-latest',
      apiKey: apiKey,
  );

  final prompt = 'Write a story about a magic backpack.';
  final content = [Content.text(prompt)];
  final response = await model.generateContent(content);

  print(response.text);
};

Classes

BatchEmbedContentsResponse
Candidate
Response candidate generated from a GenerativeModel.
ChatSession
A back-and-forth chat with a generative model.
CitationMetadata
Source attributions for a piece of content.
CitationSource
Citation to a source for a portion of a specific response.
Content
The base structured datatype containing multi-part content of a message.
ContentEmbedding
An embedding, as defined by a list of values.
CountTokensResponse
DataPart
A Part with the byte content of a file.
EmbedContentRequest
EmbedContentResponse
FilePart
A Part referring to an uploaded file.
FunctionCall
A predicted FunctionCall returned from the model that contains a string representing the FunctionDeclaration.name with the arguments and their values.
FunctionCallingConfig
Configuration specifying how the model should use the functions provided as tools.
FunctionDeclaration
Structured representation of a function declaration as defined by the OpenAPI 3.03 specification.
FunctionResponse
GenerateContentResponse
Response from the model; supports multiple candidates.
GenerationConfig
Configuration options for model generation and outputs.
GenerativeModel
A multimodel generative model (like Gemini).
Part
A datatype containing media that is part of a multi-part Content message.
PromptFeedback
Feedback metadata of a prompt specified in a GenerativeModel request.
RequestOptions
Configuration for how a GenerativeModel makes requests.
SafetyRating
Safety rating for a piece of content.
SafetySetting
Safety setting, affecting the safety-blocking behavior.
Schema
The definition of an input or output data types.
TextPart
Tool
Tool details that the model may use to generate a response.
ToolConfig
UsageMetadata
Metadata on the generation request's token usage.

Enums

BlockReason
The reason why a prompt was blocked.
FinishReason
Reason why a model stopped generating tokens.
FunctionCallingMode
HarmBlockThreshold
Probability of harm which causes content to be blocked.
HarmCategory
The category of a rating.
HarmProbability
The probability that a piece of content is harmful.
SchemaType
The value type of a Schema.
TaskType
Type of task for which the embedding will be used.

Exceptions / Errors

GenerativeAIException
Exception thrown when generating content fails.
InvalidApiKey
Exception thrown when the server rejects the API key.
ServerException
Exception thrown when the server failed to generate content.
UnsupportedUserLocation
Exception thrown when the user location is unsupported.