diff --git a/Package.swift b/Package.swift index c1d3a1a..903d555 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( .package(url: "https://github.com/SwiftyJSON/SwiftyJSON", .upToNextMajor(from: "5.0.1")), .package(url: "https://github.com/drmohundro/SWXMLHash", .upToNextMajor(from: "7.0.2")), .package(url: "https://github.com/scinfu/SwiftSoup", .upToNextMajor(from: "2.6.1")), - .package(url: "https://github.com/juyan/swift-filestore", .upToNextMajor(from: "0.2.0")), + .package(url: "https://github.com/juyan/swift-filestore", .upToNextMajor(from: "0.5.0")), .package(url: "https://github.com/ZachNagengast/similarity-search-kit.git", from: "0.0.11"), .package(url: "https://github.com/google/generative-ai-swift", .upToNextMajor(from: "0.4.4")), ], diff --git a/Sources/LangChain/llms/Gemini.swift b/Sources/LangChain/llms/Gemini.swift new file mode 100644 index 0000000..9857aab --- /dev/null +++ b/Sources/LangChain/llms/Gemini.swift @@ -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.") + } + } +}