google-gemini / generative-ai-dart

The official Dart library for the Google Gemini API
https://ai.google.dev/gemini-api/docs/get-started/tutorial?lang=dart
Apache License 2.0
571 stars 115 forks source link

Multi content doesn't work with google generative ai flutter package #178

Closed ilyesksr closed 5 months ago

ilyesksr commented 5 months ago

Description of the bug:

hello guy pls can some one help me when i use google generative ai package with gemini-1.5-flash model with text only the app work normally but when i try to add an image as an entry i get this error An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting error sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 296:3 throw packages/google_generative_ai/src/api.dart 583:54 parseGenerateContentResponse here is the code :

List<Part> parts = [TextPart(message)];
try {
if (image != null) {
parts.add(DataPart(image.extension!, image.bytes!));
}
} catch (e) {
log(e.toString());
}
var content = Content.multi(parts);
var response = myChat.sendMessageStream(content);

Actual vs expected behavior:

it supposed to work on both text only and text with image but currently it work with text only

Any other information you'd like to share?

No response

fatiq17irenictech commented 5 months ago

my add image function is working fine: if (_selectedImage != null) { final model = GenerativeModel( model: 'gemini-pro-vision', apiKey:"your api key", );

        final imageBytes = await _selectedImage!.readAsBytes();
        final content = Content.multi([
            TextPart("your message"),
            DataPart('image/jpeg', imageBytes),
        ]);

        final response = await model.generateContent([content]);
natebosch commented 5 months ago

This looks like a backend error unrelated to the SDK. Hopefully this was transient, but if this is still happening the best place to get help is at the https://developers.generativeai.google/guide/troubleshooting link form the error message.