mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-28 15:18:26 +01:00
3c0b585561
* swiftui: support load model from file picker * swiftui: remove trailing whitespace
45 lines
1.3 KiB
Swift
45 lines
1.3 KiB
Swift
import SwiftUI
|
|
import UniformTypeIdentifiers
|
|
|
|
struct LoadCustomButton: View {
|
|
@ObservedObject private var llamaState: LlamaState
|
|
@State private var showFileImporter = false
|
|
|
|
init(llamaState: LlamaState) {
|
|
self.llamaState = llamaState
|
|
}
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Button(action: {
|
|
showFileImporter = true
|
|
}) {
|
|
Text("Load Custom Model")
|
|
}
|
|
}
|
|
.fileImporter(
|
|
isPresented: $showFileImporter,
|
|
allowedContentTypes: [UTType(filenameExtension: "gguf", conformingTo: .data)!],
|
|
allowsMultipleSelection: false
|
|
) { result in
|
|
switch result {
|
|
case .success(let files):
|
|
files.forEach { file in
|
|
let gotAccess = file.startAccessingSecurityScopedResource()
|
|
if !gotAccess { return }
|
|
|
|
do {
|
|
try llamaState.loadModel(modelUrl: file.absoluteURL)
|
|
} catch let err {
|
|
print("Error: \(err.localizedDescription)")
|
|
}
|
|
|
|
file.stopAccessingSecurityScopedResource()
|
|
}
|
|
case .failure(let error):
|
|
print(error)
|
|
}
|
|
}
|
|
}
|
|
}
|