babakcode / flutter_gemini

Flutter Google Gemini SDK
https://pub.dev/packages/flutter_gemini
BSD 3-Clause "New" or "Revised" License
166 stars 54 forks source link

Loading not Stopped #3

Closed Nabeel-Shehzad closed 6 months ago

Nabeel-Shehzad commented 8 months ago

Issue Description: I am encountering a persistent problem where the loading process does not cease after I upload an image and submit a query related to it. The loading indicator continues indefinitely without providing a response. Additionally, I observed an error in the console, which may be related to this issue. Steps to Reproduce:

Upload an image. Submit a query related to the uploaded image.

Expected Result: The system should process the query and return a response within a reasonable timeframe.

Actual Result: The system remains in a continuous loading state and fails to return any response.

here is the log: flutter: *** DioException ***: [log] streamGenerateContent error flutter: uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:streamGenerateContent?key=AIzaSyAKvJXzlhRlCQkH4V8thryBdRoeOKAAa20 flutter: DioException [bad response]: This exception was thrown because the response has a status code of 400 and RequestOptions.validateStatus was configured to throw for this status code. The status code of 400 has the following meaning: "Client error - the request contains bad syntax or cannot be fulfilled" Read more about status codes at https://developer.mozilla.org/en-US/docs/Web/HTTP/Status In order to resolve this exception you typically have either to verify and fix your request code or you have to fix the server code. flutter: uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:streamGenerateContent?key=AIzaSyAKvJXzlhRlCQkH4V8thryBdRoeOKAAa20 flutter: statusCode: 400 flutter: headers: flutter: alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 flutter: cache-control: private flutter: transfer-encoding: chunked flutter: date: Tue, 02 Jan 2024 16:14:20 GMT flutter: vary: Origin X-Origin Referer flutter: content-encoding: gzip flutter: server-timing: gfet4t7; dur=33933 flutter: x-frame-options: SAMEORIGIN flutter: content-type: application/json; charset=UTF-8 flutter: x-xss-protection: 0 flutter: x-content-type-options: nosniff flutter: server: scaffolding on HTTPServer2 flutter: Response Text: flutter: Instance of 'ResponseBody' flutter: flutter: DioException [bad response]: This exception was thrown because the response has a status code of 400 and RequestOptions.validate...

tahaf22labs commented 8 months ago

Same issue. Did you found any solution?

babakcode commented 8 months ago

Hello @tahaf22labs, @Nabeel-Shehzad, The response code is 443, and this account is at/over the message quota. You can prompt it 60 times per minute and don't try it from my web application.

Nabeel-Shehzad commented 8 months ago

Hello @tahaf22labs, @Nabeel-Shehzad, The response code is 443, and this account is at/over the message quota. You can prompt it 60 times per minute and don't try it from my web application.

I'm testing it on mobile, getting same issue on Android and IOS, basically its because when I upload image more than 2 or 3 Mbs, so we have to stop loading when this happens. how we can do that ?

babakcode commented 8 months ago

Just check the catchError function for the future type methods and the onError for the stream methods.

gemini.streamGenerateContent('Utilizing Google Ads in Flutter')
  .listen((value) {
    print(value.output);
  }).onError((e) {
    /// stop loading
    loading = false;
    error = e;
  });
Sharaddition commented 7 months ago

flutter: *** DioException ***: [log] streamGenerateContent error flutter: uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:streamGenerateContent?key=AIzaSyAKvJXzlhRlCQkH4V8thryBdRoeOKAAa20 flutter: DioException [bad response]: This exception was thrown because the response has a status code of 400 and RequestOptions.validateStatus was configured to throw for this status code.

@Nabeel-Shehzad In case you haven't noticed, you've leaked your API keys.