google_generative_ai 0.2.0
google_generative_ai: ^0.2.0 copied to clipboard
The Google AI Dart SDK enables developers to use Google's state-of-the-art generative AI models (like Gemini).
The Google AI Dart SDK enables developers to use Google's state-of-the-art generative AI models (like Gemini) to build AI-powered features and applications. This SDK supports use cases like:
- Generate text from text-only input
- Generate text from text-and-images input (multimodal)
- Build multi-turn conversations (chat)
- Embedding
Getting started #
Get an API key #
Using the Google AI Dart SDK requires an API key; see https://ai.google.dev/tutorials/setup for how to create one.
Add the package to your project #
Add a dependency on the package:google_generative_ai
package like so:
dart pub add google_generative_ai
or:
flutter pub add google_generative_ai
Additionally, import:
import 'package:google_generative_ai/google_generative_ai.dart';
Use the API #
import 'package:google_generative_ai/google_generative_ai.dart';
const apiKey = ...;
void main() async {
final model = GenerativeModel(model: 'gemini-pro', 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);
};
See additional examples at samples/.
Additional documentation #
You can find additional documentation for the Google AI SDKs and the Gemini model at ai.google.dev/docs.