Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GoogleGenerativeAl.RPCError error 1.) #82

Closed
iTarek opened this issue Jan 7, 2024 · 3 comments
Closed

(GoogleGenerativeAl.RPCError error 1.) #82

iTarek opened this issue Jan 7, 2024 · 3 comments
Labels
component:swift sdk Issue/PR related to Swift SDK type:bug Something isn't working

Comments

@iTarek
Copy link

iTarek commented Jan 7, 2024

Description of the bug:

I am using SDK version 0.4.4, and everything works well. However, a few users in different locations around the world, such as Norway, encounter an error when they run my app, rendering it unusable.

The operation could not be completed. (The GoogleGenerativeAl.RPCError error 1.)

What is this error? How can I fix it?
Screenshot

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

@iTarek iTarek added component:swift sdk Issue/PR related to Swift SDK type:bug Something isn't working labels Jan 7, 2024
@andrewheard
Copy link
Collaborator

Hi @iTarek, at the moment, the Gemini API is only available in these regions. Unfortunately, I don't have any information on plans or timelines to expand the available locations (I sympathize since it's not available in Canada either).

In the meantime, we're working on improving the error message in unsupported regions.

@andrewheard
Copy link
Collaborator

As an example of how a developer could currently detect / handle this error (without #85):

do {
  let content = try await model.generateContent("Why is the sky blue?")
  if let text = content.text {
    print("Generated Content:\n\(text)")
  }
} catch let GenerateContentError.internalError(underlying: error) {
  if String(describing: error).contains("User location is not supported for the API use.") {
    // Do something app-specific if the API isn't available in the user's region.
    print("Unsupported region, see https://ai.google.dev/available_regions#available_regions")
  } else {
      // This is a different internal error
      print("Generate Content Internal Error: \(error)")
  }
} catch {
  // This is a GenerateContentError that isn't a GenerateContentError.internalError
  print("Generate Content Error: \(error)")
}

Pain points noted:

  • The internal error doesn't conform to LocalizedError so error.localizedDescription doesn't contain the "User location is not supported for the API use." message.
    • Workaround: Use String(describing: error) to get a String containing the message
  • Developer needs to hardcode "User location is not supported for the API use." in their app

Note: Removing status: awaiting user response since we're investigating this.

@andrewheard
Copy link
Collaborator

Hi @iTarek, version https://github.com/google/generative-ai-swift/releases/tag/0.4.7 of the SDK is now available, which adds an unsupportedUserLocation case to GenerateContentError. Our Chat Sample and unit-tests show examples of how you can catch this failure scenario in your code.

Will close this issue but feel free to re-open if you have additional feedback / concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:swift sdk Issue/PR related to Swift SDK type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants