Skip to content

Instantly share code, notes, and snippets.

@apatronl
Last active May 1, 2024 14:02
Show Gist options
  • Save apatronl/748402231c1d0ac07e39ab751dbfdae3 to your computer and use it in GitHub Desktop.
Save apatronl/748402231c1d0ac07e39ab751dbfdae3 to your computer and use it in GitHub Desktop.
class GeminiClient {
enum APIKey {
// Fetch the API key from `GeminiChat.plist`
static var `default`: String {
guard let filePath = Bundle.main.path(forResource: "GeminiChat", ofType: "plist")
else {
fatalError("Couldn't find file 'GeminiChat.plist'.")
}
let plist = NSDictionary(contentsOfFile: filePath)
guard let value = plist?.object(forKey: "API_KEY") as? String else {
fatalError("Couldn't find key 'API_KEY' in 'GeminiChat.plist'.")
}
if value.starts(with: "_") {
fatalError(
"Follow the instructions at https://ai.google.dev/tutorials/setup to get an API key."
)
}
return value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment