-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Update Swift package dependencies and add Gemini.swift file for Gemi…
…ni class, which extends LLM and implements the _send method for generating content using the GoogleGenerativeAI library."
- Loading branch information
Showing
2 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by 顾艳华 on 12/25/23. | ||
// | ||
|
||
import Foundation | ||
import GoogleGenerativeAI | ||
|
||
public class Gemini: LLM { | ||
override func _send(text: String, stops: [String]) async throws -> LLMResult { | ||
let env = Env.loadEnv() | ||
|
||
if let apiKey = env["GOOGLEAI_API_KEY"] { | ||
let model = GenerativeModel(name: "gemini-pro", apiKey: apiKey) | ||
let response = try await model.generateContent(text) | ||
return LLMResult(llm_output: response.text) | ||
} else { | ||
print("Please set openai api key.") | ||
return LLMResult(llm_output: "Please set openai api key.") | ||
} | ||
} | ||
} |