Generate tags using gemini AI

A week ago, I was working on a Flutter project to generate tags based on a post sentence.

The requirement was to generate tags separated by commas using the Gemini API.

Todo that, I used the flutter_gemini package to call the Gemini API.

Here is sam…


This content originally appeared on DEV Community and was authored by sugiarto

A week ago, I was working on a Flutter project to generate tags based on a post sentence.

The requirement was to generate tags separated by commas using the Gemini API.

Todo that, I used the flutter_gemini package to call the Gemini API.

Here is sample code to call the API.

// main.dart
Gemini.init(apiKey: dotenv.env['GEMINI_API_KEY']!);
final sampleText = "Thanks for the iPhone and food."
final gemini = Gemini.instance;
gemini.streamGenerateContent("For this text, return only the name of people or things (separated by commas), that you're highly confident that has a very high positive sentiment: $sampleText").listen((Candidates value){
  if (value?.content?.parts != null){
    if (value!.content!.parts!.isNotEmpty){
      String? text = value!.content!.parts![0].text;
      if (text != null){
        var parsedTags = text.split(", ");
        setState(() {
          for (String tag in parsedTags){
            // push to tags variable
            if (!tags.contains(tag)){
              tags.add(tag);
            }
          }
        });
      }
    }
  }
  print(value);
}).onError((error){
  print('streamGenerateContent exception $error');
});

The result would be a String with content iPhone, food.


This content originally appeared on DEV Community and was authored by sugiarto


Print Share Comment Cite Upload Translate Updates
APA

sugiarto | Sciencx (2024-10-01T03:12:41+00:00) Generate tags using gemini AI. Retrieved from https://www.scien.cx/2024/10/01/generate-tags-using-gemini-ai/

MLA
" » Generate tags using gemini AI." sugiarto | Sciencx - Tuesday October 1, 2024, https://www.scien.cx/2024/10/01/generate-tags-using-gemini-ai/
HARVARD
sugiarto | Sciencx Tuesday October 1, 2024 » Generate tags using gemini AI., viewed ,<https://www.scien.cx/2024/10/01/generate-tags-using-gemini-ai/>
VANCOUVER
sugiarto | Sciencx - » Generate tags using gemini AI. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/01/generate-tags-using-gemini-ai/
CHICAGO
" » Generate tags using gemini AI." sugiarto | Sciencx - Accessed . https://www.scien.cx/2024/10/01/generate-tags-using-gemini-ai/
IEEE
" » Generate tags using gemini AI." sugiarto | Sciencx [Online]. Available: https://www.scien.cx/2024/10/01/generate-tags-using-gemini-ai/. [Accessed: ]
rf:citation
» Generate tags using gemini AI | sugiarto | Sciencx | https://www.scien.cx/2024/10/01/generate-tags-using-gemini-ai/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.