Last active
May 1, 2024 14:02
-
-
Save apatronl/748402231c1d0ac07e39ab751dbfdae3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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