Skip to content

Commit

Permalink
"Update Swift package dependencies and add Gemini.swift file for Gemi…
Browse files Browse the repository at this point in the history
…ni class, which extends LLM and implements the _send method for generating content using the GoogleGenerativeAI library."
  • Loading branch information
buhe committed Dec 25, 2023
1 parent c572e8b commit 4916e9a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
],
Expand Down
24 changes: 24 additions & 0 deletions Sources/LangChain/llms/Gemini.swift
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.")
}
}
}

0 comments on commit 4916e9a

Please sign in to comment.