Created
May 1, 2024 14:06
-
-
Save apatronl/e219f5ac899bc4086eef2d97b8cecde2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import Foundation | |
| import GoogleGenerativeAI | |
| class GeminiClient { | |
| private lazy var model = GenerativeModel(name: "gemini-pro", apiKey: APIKey.default) | |
| private lazy var chat: Chat = model.startChat() | |
| func send(message: String) async -> Result<String, GenerateContentError> { | |
| do { | |
| let response = try await chat.sendMessage(message) | |
| if let text = response.text { | |
| return .success(text) | |
| } | |
| } catch let error as GenerateContentError { | |
| return .failure(error) | |
| } catch { | |
| return .failure(GenerateContentError.internalError(underlying: GenericError())) | |
| } | |
| return .failure(GenerateContentError.internalError(underlying: GenericError())) | |
| } | |
| } | |
| struct GenericError: Error { | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment