(GoogleGenerativeAl.RPCError error 1.)
iTarek opened this issue · comments
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?
Actual vs expected behavior:
No response
Any other information you'd like to share?
No response
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.
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
soerror.localizedDescription
doesn't contain the"User location is not supported for the API use."
message.- Workaround: Use
String(describing: error)
to get aString
containing the message
- Workaround: Use
- Developer needs to hardcode
"User location is not supported for the API use."
in their app- The approach in #85 hardcodes this in the SDK (also not ideal) but it would be more convenient for devs to upgrade their version of the SDK vs. having to keep an eye on if/when our error messages change
Note: Removing status: awaiting user response
since we're investigating this.
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.