generative_ai_dart library
The generative_ai_dart
library.
This library is a powerful tool for interacting with a wide array of Google's GenAI models. It features broad input support, including Blob and String data types, which enables it to generate robust chat sessions. With this package, the output can be either a stream of content or a singular content entity.
Key Features
- Google GenAI Models Interoperability: Seamless interaction with Google's GenAI models.
- Diverse Input Support: Supports different types of inputs such as Blob, String, etc.
- Chat Session Generation: Capable of spawning and managing chat sessions.
- Stream or Single Content Output: Allows generation of a stream of content or singular instances of content.
Usage
To interact with the Google GenAI models, import the library and create a GenerativeModel object:
import 'package:generative_ai_dart/generative_ai_dart.dart';
void main() {
final genAI = GenerativeModel();
genAI.startChat();
}
For more information on how to use this library, refer to the complete documentation.
Classes
- BatchEmbedContentsRequest
- Represents a batch request for embedding contents.
- BatchEmbedContentsResponse
- BatchEmbedContentsResponse class represents the response for a batch of embeddings. It consists of a list of ContentEmbedding.
- ChatSession
-
ChatSession
manages interaction with a GenerativeModel. - CitationMetadata
- CitationMetadata class represents a metadata that contains a list of CitationSources.
- CitationSource
- CitationSource class represents a citation source with start index, end index, URI and license.
- Content
- This final class Content represents a list of Part instances.
- ContentEmbedding
- ContentEmbedding class represents the content embedding. It consists of a list of integer values.
- CountTokensRequest
- Represents a request for counting tokens in contents.
- CountTokensResponse
- CountTokensResponse class represents the response for counting tokens which consists of total number of tokens.
- EmbedContentRequest
- Represents a request for embedding content.
- EmbedContentResponse
- EmbedContentResponse class represents the response for an embedded content. It consists of a ContentEmbedding.
- GenerateContentCandidate
-
GenerateContentCandidate
is a Class, with JSON serializable representation, that holds the data for generating content candidates. It's properties include index, content, optional finishReason, finishMessage, safetyRatings, and citationMetadata. - GenerateContentRequest
- Represents a request for content generation.
- GenerateContentResponse
- GenerateContentResponse is a class which collects the response of a content generation operation. This includes the generated content candidates as well as any feedback provided for the prompts.
- GenerationConfig
- Represents a configuration for content generation. It contains parameters like the temperature, the count of candidates and more.
- GenerativeContentBlob
-
This class represents a content blob with a specific MIME type and data.
Each blob is characterized by its MIME type (like
"text/plain"
,"image/png"
, etc.) and the actual content in the form of a string. This class has a factory constructor GenerativeContentBlob.fromJson that constructs aGenerativeContentBlob
object from a JSON object. It also has a method toJson that converts a GenerativeContentBlob object into a JSON object. - GenerativeModel
-
GenerativeModel
class handles the structure and functionality of a generative language model which includes apiKey, ModelParams, GenerationConfig and SafetySetting. It contains several methods like generateContentStream, startChat, generateContent, embedContent, batchEmbedContents, and countTokens. - InlineDataPart
- This final class InlineDataPart extends from the Part class. It represents an inline data part, with the inline data being derived from the super class.
- ModelParams
- Represents the parameters associated with a specific model.
- Part
- Part is an abstract base class and it is used as a common ancestor for other classes. It provides common properties such as text and inlineData and also methods like Part.fromJson and Part.toJson.
- PromptFeedback
-
PromptFeedback
is a class that represents a feedback for user's prompt. - SafetyRating
- SafetyRating class represents a safety rating which contains category and probability of harm.
- SafetySetting
- Represents the safety settings for content generation. Contains a HarmCategory and HarmBlockThreshold.
- TextPart
- This final class TextPart extends from the Part class. It represents a section of text, with the text being derived from the super class.
Enums
- BlockReason
- Enum representing the reason a prompt was blocked.
- FinishReason
- Enum representing the reason a candidate execution finished.
- HarmBlockThreshold
- Enum representing a threshold level at which a prompt or candidate might be blocked.
- HarmCategory
- Enum representing different categories of harm in the system responsible for managing harmful prompts or candidates. Each value stands for a particular type of harmful content that may lead to the blocking of a prompt or candidate.
- HarmProbability
- Enum representing the probability of a prompt or candidate matching a harm category.
- RequestType
- This is an enum representing various types of requests. It includes methods to generate content, stream content, count tokens, embed content, and batch embed contents.
- TaskType
- An Enum in Dart representing the various types of tasks included in embedding the content. The Enum TaskType has six different types of tasks:
Extensions
- GenerateContentResponseExtension on GenerateContentResponse
- This is an extension method for GenerateContentResponse class.
- Request on RequestType
- Extension on RequestType to provide additional functionality.
Exceptions / Errors
- GoogleGenerativeAIError
- Represents a class for Google Generative AI related errors.
-
GoogleGenerativeAIResponseError<
T> - Represents a class for Google Generative AI response related errors.