Gemini Flutter is a Dart package that simplifies the integration of Gemini APIs into your Flutter applications. It provides convenient methods for making requests to Gemini models and handling responses.
Gemini is a family of three AI models: Gemini Ultra, Gemini Pro, and Gemini Nano. Each model caters to different needs, offering varying levels of sophistication and performance.
Introducing the gemini-pro-vision API method to enhance the capabilities of the system. This new method allows users to leverage the advanced features provided by Gemini Pro Vision, opening up opportunities for improved vision-related functionalities.
Effortlessly manage your image uploads with our system. You can provide the image path, submit the image as a File object, or even directly use base64 encoding – we take care of the rest for you!
A new functionality has been added to count tokens for all methods. Users can enable token counting by setting the countToken parameter in the respective methods.
1. Add the gemini_flutter dependency to your pubspec.yaml file:
dependencies: |
Then, run flutter pub get to fetch the dependency.
2. In your Dart code, import the package:
import 'package:gemini_flutter/gemini_flutter.dart'; |
3. Initialize the GeminiHandler in your main function:
void main() { |
Make sure to replace “YOUR_API_KEY” with your actual Gemini API key. You can also customize other parameters as needed.
outputLength: This parameter specifies the desired length of the generated text. In your example, it is set to 1024 characters.
void generateText() async { |
Inside the function, the geminiPro method of the GeminiHandler class is called. This method appears to generate text using the Gemini API. It takes various parameters:
text: The prompt for text generation (“Write a long story about a magic backpack.”).
temperature: A parameter controlling the randomness of the generated text (0.9 in this case).
topP: A parameter for nucleus sampling, controlling diversity (0.95 in this case).
topK: Number of top candidates to sample from during nucleus sampling (40 in this case).
outputLength: The desired length of the generated text (1024 characters).
countTokens: Logs the number of tokens that will be consumed by this prompt.
Generate text from an image or let gemini pro tell you whats in your image using the geminiProVision method:
void
generateTextFromImage() async { |
The above code snippet GeminiHandler class to perform text generation with the geminiProVision method. Here’s an explanation of the parameters:
text: This parameter expects a string representing the input text or prompt for generating the output. In your example, it is set to “Write a long story about the image.”
path: This parameter specifies the path to the image file. In your example, it is set to “path/to/your/image.jpg.” It seems to indicate that the text generation is somehow related to the content or context of the image. pack.”).
imageBase64: This prameter takes the image as base64 format which is the form that Gemini APIs accept the image in.
file: This prameter takes image as File object, all the other conversions are handle in the package
temperature: A parameter controlling the randomness of the generated text (0.9 in this case).
topP: A parameter for nucleus sampling, controlling diversity (0.95 in this case).
topK: Number of top candidates to sample from during nucleus sampling (40 in this case).
outputLength: The desired length of the generated text (1024 characters).
countTokens: Logs the number of tokens that will be consumed by this prompt.
import 'package:flutter/material.dart'; |
Connect with us to go live
Sales Team
HR Team
© 2022 Created with Techy Panther