google_generative_ai

Last updated:

0 purchases

google_generative_ai Image
google_generative_ai Images
Add to Cart

Description:

google generative ai

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


Caution
Using the Google AI SDK for Dart (Flutter) to call the Google AI Gemini API
directly from your app is recommended for prototyping only. If you plan to
enable billing, we strongly recommend that you use the SDK to call the Google
AI Gemini API only server-side to keep your API key safe. You risk potentially
exposing your API key to malicious actors if you embed your API key directly
in your mobile or web app or fetch it remotely at runtime.

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
copied to clipboard
or:
flutter pub add google_generative_ai
copied to clipboard
Additionally, import:
import 'package:google_generative_ai/google_generative_ai.dart';
copied to clipboard
Use the API #
import 'package:google_generative_ai/google_generative_ai.dart';

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);
};
copied to clipboard
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.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.