From 76e2d4b1c66f5783f6b09e77a14cb4527fae6176 Mon Sep 17 00:00:00 2001 From: buhe Date: Tue, 6 Feb 2024 10:14:07 +0800 Subject: [PATCH 1/3] Update Local.swift --- Sources/LangChain/llms/Local.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Sources/LangChain/llms/Local.swift b/Sources/LangChain/llms/Local.swift index 3e55cef..03233fa 100644 --- a/Sources/LangChain/llms/Local.swift +++ b/Sources/LangChain/llms/Local.swift @@ -11,20 +11,23 @@ public class Local: LLM { let modelPath: String let useMetal: Bool let inference: ModelInference + var params: ModelAndContextParams + var sampleParams: ModelSampleParams - public init(inference: ModelInference, modelPath: String, useMetal: Bool = false, callbacks: [BaseCallbackHandler] = [], cache: BaseCache? = nil) { + public init(inference: ModelInference, modelPath: String, useMetal: Bool = false,params: ModelAndContextParams = .default, sampleParams: ModelSampleParams = .default, callbacks: [BaseCallbackHandler] = [], cache: BaseCache? = nil) { self.inference = inference self.modelPath = modelPath self.useMetal = useMetal + self.params = params + self.sampleParams = sampleParams super.init(callbacks: callbacks, cache: cache) } public override func _send(text: String, stops: [String] = []) async throws -> LLMResult { let ai = AI(_modelPath: self.modelPath, _chatName: "chat") - var params:ModelAndContextParams = .default - params.use_metal = useMetal - params.promptFormat = .Custom - params.custom_prompt_format = "{{prompt}}" - try? ai.loadModel(inference, contextParams: params) + self.params.use_metal = useMetal + + let _ = try? ai.loadModel(inference, contextParams: self.params) + ai.model.sampleParams = self.sampleParams let output = try? ai.model.predict(text, mainCallback) // print("🚗\(output)") total_output = 0 From 4597d5d85d6628c22b517a53583b5821a48181ff Mon Sep 17 00:00:00 2001 From: buhe Date: Sat, 10 Feb 2024 13:15:00 +0800 Subject: [PATCH 2/3] "Add llmfarm_core.swift as a remote source control dependency with branch langchain and revision 927d670751bc8aebbc5eb845afd36fe1eeef4f5a, and update the package dependencies in Package.swift." --- Package.resolved | 9 +++++++++ Package.swift | 6 ++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Package.resolved b/Package.resolved index 62e409f..f125137 100644 --- a/Package.resolved +++ b/Package.resolved @@ -63,6 +63,15 @@ "version" : "4.2.2" } }, + { + "identity" : "llmfarm_core.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/buhe/llmfarm_core.swift", + "state" : { + "branch" : "langchain", + "revision" : "927d670751bc8aebbc5eb845afd36fe1eeef4f5a" + } + }, { "identity" : "openai-kit", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index d51296b..f77429d 100644 --- a/Package.swift +++ b/Package.swift @@ -27,8 +27,7 @@ let package = Package( .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")), .package(url: "https://github.com/buhe/SwiftyNotion", .upToNextMajor(from: "0.1.2")), -// .package(url: "https://github.com/chojnac/NotionSwift", .upToNextMajor(from: "0.8.0")), -// .package(url: "https://github.com/buhe/llmfarm_core.swift", .branch("langchain")), + .package(url: "https://github.com/buhe/llmfarm_core.swift", .branch("langchain")), ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. @@ -45,8 +44,7 @@ let package = Package( .product(name: "SimilaritySearchKit", package: "similarity-search-kit", condition: .when(platforms: [.macOS, .iOS, .visionOS])), .product(name: "GoogleGenerativeAI", package: "generative-ai-swift"), .product(name: "SwiftyNotion", package: "SwiftyNotion"), -// .product(name: "NotionSwift", package: "NotionSwift"), -// .product(name: "llmfarm_core", package: "llmfarm_core.swift"), + .product(name: "llmfarm_core", package: "llmfarm_core.swift"), ] ), From 6113b4acddd172529134b75d9552face95e3c0d5 Mon Sep 17 00:00:00 2001 From: buhe Date: Sat, 10 Feb 2024 13:17:16 +0800 Subject: [PATCH 3/3] "Update GitHub Actions workflow to include \"local\" branch in the trigger for both push and pull request events." --- .github/workflows/swift.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index f8b34ed..bdbfb02 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -5,9 +5,9 @@ name: Swift on: push: - branches: [ "main" ] + branches: [ "main", "local" ] pull_request: - branches: [ "main" ] + branches: [ "main", "local" ] jobs: build: