google_generative_ai 0.2.1 copy "google_generative_ai: ^0.2.1" to clipboard
google_generative_ai: ^0.2.1 copied to clipboard

The Google AI Dart SDK enables developers to use Google's state-of-the-art generative AI models (like Gemini).

package:google_generative_ai pub package package publisher

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/.

For detailed instructions, you can find a quickstart for the Google AI Dart SDK in the Google documentation: http://ai.google.dev/tutorials/dart_quickstart. This quickstart describes how to add your API key and the SDK to your app, initialize the model, and then call the API to access the model. It also describes some additional use cases and features, like streaming, embedding, counting tokens, and controlling responses.

Additional documentation #

You can find additional documentation for the Google AI SDKs and the Gemini model at ai.google.dev/docs.

807
likes
0
pub points
98%
popularity

Publisher

verified publishergoogle.dev

The Google AI Dart SDK enables developers to use Google's state-of-the-art generative AI models (like Gemini).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http

More

Packages that depend on google_generative_ai