gemini_ai 0.0.3 copy "gemini_ai: ^0.0.3" to clipboard
gemini_ai: ^0.0.3 copied to clipboard

Plugin for Google Gemini AI Library. You can add artificial intelligence capability to your Flutter application using the Gemini AI library.

Gemini API Flutter Plugin #

Flutter plugin of Gemini AI for Flutter Developers that uses native Android and iOS libraries.

My personal website: cihanurtekin.com

NOTE: This plugin is not a simple package that just makes web calls. It is a plugin that includes Gemini AI's native Android and iOS libraries.

Usage #

To experience Gemini online: Google Maker Suite

Generative Model #

A facilitator for a given multimodal model (eg; Gemini).

import 'package:gemini_ai/model/generative_model.dart';

GenerativeModel generativeModel = GenerativeModel(
  modelName: "gemini-pro",
  apiKey: "YOUR_API_KEY_HERE",
  generationConfig: _generationConfig,
  safetySettings: _safetySettings,
);

modelName (String): Name of the model in the backend
apiKey (String): Authentication key for interacting with the backend
generationConfig (GenerationConfig?): Configuration parameters to use for content generation
safetySettings (List<SafetySetting>): The safety bounds to use during alongside prompts during content generation


Generation Config #

Configuration parameters to use for content generation.

import 'package:gemini_ai/model/generation_config.dart';

GenerationConfig _generationConfig = GenerationConfig(
  temperature: 0.9,
  topK: 1,
  topP: 1,
  maxOutputTokens: 2048,
);

temperature (double?): The degree of randomness in token selection, typically between 0 and 1
topK (int?): The sum of probabilities to collect to during token selection
topP (double?): How many tokens to select amongst the highest probabilities
candidateCount (int?): The max unique responses to return
maxOutputTokens (int?): The max tokens to generate per response
stopSequences (List<String>?): A list of strings to stop generation on occurrence of


Safety Settings #

A configuration for a BlockThreshold of some HarmCategory allowed and blocked in responses.

import 'package:gemini_ai/model/safety_setting.dart';
import 'package:gemini_ai/enum/block_threshold.dart';
import 'package:gemini_ai/enum/harm_category.dart';

List<SafetySetting> _safetySettings = [
  SafetySetting(
    HarmCategory.harassment,
    BlockThreshold.mediumAndAbove,
  ),
  SafetySetting(
    HarmCategory.hateSpeech,
    BlockThreshold.mediumAndAbove,
  ),
  SafetySetting(
    HarmCategory.sexuallyExplicit,
    BlockThreshold.mediumAndAbove,
  ),
  SafetySetting(
    HarmCategory.dangerousContent,
    BlockThreshold.mediumAndAbove,
  ),
];
  • HarmCategory (enum) : Category for a given harm rating.
    • unknown : A new and not yet supported value.
    • harassment : Harassment content.
    • hateSpeech : Hate speech and content.
    • sexuallyExplicit : Sexually explicit content.
    • dangerousContent : Dangerous content.
  • BlockThreshold (enum) : Represents the threshold for some HarmCategory that is allowed and blocked by SafetySettings.
    • unspecified : The threshold was not specified.
    • lowAndAbove : Content with negligible harm is allowed.
    • mediumAndAbove : Content with negligible to low harm is allowed.
    • onlyHigh : Content with negligible to medium harm is allowed.
    • none : All content is allowed regardless of harm.

Generate content #

Get response from Gemini AI with only one line of code using the generateContent method. For a full example, you can visit the example tab.

GeminiAi : The class used to call Gemini functions and properties

generateContent : Generates a response from the backend with the provided text represented Content.

prompt : The text to be converted into a single piece of Content to send to the model.

Returns a response String after some delay (async).

import 'package:gemini_ai/gemini_ai.dart';

GeminiAi _gemini = GeminiAi();

String? content = await _gemini.generateContent(
  GeminiConfig.generativeModel,
  "Your message to Gemini",
);

License #

Gemini AI Flutter Plugin is licensed under the BSD-3-Clause License.

My personal website: cihanurtekin.com

17
likes
0
points
61
downloads

Publisher

verified publishercihanurtekin.com

Weekly Downloads

Plugin for Google Gemini AI Library. You can add artificial intelligence capability to your Flutter application using the Gemini AI library.

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on gemini_ai