flutter_gemini 0.0.1-dev-4 copy "flutter_gemini: ^0.0.1-dev-4" to clipboard
flutter_gemini: ^0.0.1-dev-4 copied to clipboard

Flutter Google Gemini SDK. Google Gemini is a set of cutting-edge large language models (LLMs) designed to be the driving force behind Google's future AI initiatives.

Flutter Gemini #

Google Gemini is a set of cutting-edge large language models (LLMs) designed to be the driving force behind Google's future AI initiatives.

gemini_github_cover

This package provides a powerful bridge between your Flutter application and Google's revolutionary Gemini AI. It empowers you to seamlessly integrate Gemini's capabilities into your app, unlocking possibilities for building innovative, intelligent, and engaging experiences that redefine user interaction.

Features #

Getting started #

To use the Gemini API, you'll need an API key. If you don't already have one, create a key in Google AI Studio. Get an API key.

Initialize Gemini #

To initialize Gemini you must add an init factory in the main function.

void main() {

  /// Add this line
  Gemini.init(apiKey: '--- Your Gemini Api Key ---');

  runApp(const MyApp());
}

Now you can create an instance

final gemini = Gemini.instance;

Content-based APIs #

Text-only input #

This feature lets you perform natural language processing (NLP) tasks such as text completion and summarization.

  final gemini = Gemini.instance;

  gemini.text("Write a story about a magic backpack.")
    .then((value) => print( value?.output )) /// or value?.content?.parts?.last.text
    .catchError((e) => print(e));

Text-and-image input #

If the input contains both text and image, You can send a text prompt with an image to the gemini-pro-vision model to perform a vision-related task. For example, captioning an image or identifying what's in an image.

  final gemini = Gemini.instance;

  final file = File('assets/img.png');
  gemini.textAndImage(
        text: "What is this picture?", /// text
        image: file.readAsBytesSync(), /// image
      )
      .then((value) => log(value?.content?.parts?.last.text ?? ''))
      .catchError((e) => log('textAndImageInput', error: e));

Multi-turn conversations (chat) #

Using Gemini, you can build freeform conversations across multiple turns.

  final gemini = Gemini.instance;

  gemini.chat([
    Content(parts: [
      Parts(text: 'Write the first line of a story about a magic backpack.')],
        role: 'user'),
    Content(parts: [ 
      Parts(text: 'In the bustling city of Meadow brook, lived a young girl named Sophie. She was a bright and curious soul with an imaginative mind.')],
        role: 'model'),
    Content(parts: [ 
      Parts(text: 'Can you set it in a quiet village in 1600s France?')], 
        role: 'user'),
    ])
        .then((value) => log(value?.output ?? 'without output'))
        .catchError((e) => log('chat', error: e));

Count tokens #

When using long prompts, it might be useful to count tokens before sending any content to the model.

final gemini = Gemini.instance;

gemini.countTokens("Write a story about a magic backpack.")
    .then((value) => print(value)) /// output like: `6` or `null`
    .catchError((e) => log('countTokens', error: e));

Model info #

If you GET a model's URL, the API uses the get method to return information about that model such as version, display name, input token limit, etc.

final gemini = Gemini.instance;

gemini.info(model: 'gemini-pro')
    .then((info) => print(info))
    .catchError((e) => log('info', error: e));

List models #

If you GET the models directory, it uses the list method to list all of the models available through the API, including both the Gemini and PaLM family models.

final gemini = Gemini.instance;

gemini.listModels()
    .then((models) => print(models)) /// list
    .catchError((e) => log('listModels', error: e));

Unimplemented Methods #

embedContents, batchEmbedContents, streamGenerateContent,

// In newer version will be added
262
likes
0
pub points
95%
popularity

Publisher

verified publisherbabakcode.com

Flutter Google Gemini SDK. Google Gemini is a set of cutting-edge large language models (LLMs) designed to be the driving force behind Google's future AI initiatives.

Repository (GitHub)
View/report issues

Topics

#gemini #ai #google-gemini #flutter-gemini

License

unknown (LICENSE)

Dependencies

dio, flutter, freezed_annotation, json_annotation

More

Packages that depend on flutter_gemini