diff --git a/examples/llama.swiftui/llama.cpp.swift/LibLlama.swift b/examples/llama.swiftui/llama.cpp.swift/LibLlama.swift index 3754f0551..02adaa745 100644 --- a/examples/llama.swiftui/llama.cpp.swift/LibLlama.swift +++ b/examples/llama.swiftui/llama.cpp.swift/LibLlama.swift @@ -161,6 +161,10 @@ actor LlamaContext { return new_token_str } + func bench() -> String{ + return "bench not implemented" + } + func clear() { tokens_list.removeAll() temporary_invalid_cchars.removeAll() diff --git a/examples/llama.swiftui/llama.swiftui/Models/LlamaState.swift b/examples/llama.swiftui/llama.swiftui/Models/LlamaState.swift index babc60cdc..0536739bc 100644 --- a/examples/llama.swiftui/llama.swiftui/Models/LlamaState.swift +++ b/examples/llama.swiftui/llama.swiftui/Models/LlamaState.swift @@ -6,7 +6,7 @@ class LlamaState: ObservableObject { private var llamaContext: LlamaContext? private var modelUrl: URL? { - Bundle.main.url(forResource: "q8_0", withExtension: "gguf", subdirectory: "models") + Bundle.main.url(forResource: "ggml-model-q8_0", withExtension: "gguf", subdirectory: "models") // Bundle.main.url(forResource: "llama-2-7b-chat", withExtension: "Q2_K.gguf", subdirectory: "models") } init() { @@ -31,6 +31,7 @@ class LlamaState: ObservableObject { guard let llamaContext else { return } + messageLog += "Attempting to complete text...\n" await llamaContext.completion_init(text: text) messageLog += "\(text)" @@ -42,4 +43,14 @@ class LlamaState: ObservableObject { await llamaContext.clear() messageLog += "\n\ndone\n" } + + func bench() async { + guard let llamaContext else { + return + } + + messageLog += "Running benchmark...\n" + let result = await llamaContext.bench() + messageLog += "\(result)" + } } diff --git a/examples/llama.swiftui/llama.swiftui/UI/ContentView.swift b/examples/llama.swiftui/llama.swiftui/UI/ContentView.swift index 0bd16a806..55899bd9d 100644 --- a/examples/llama.swiftui/llama.swiftui/UI/ContentView.swift +++ b/examples/llama.swiftui/llama.swiftui/UI/ContentView.swift @@ -7,7 +7,8 @@ struct ContentView: View { var body: some View { VStack { - ScrollView(.vertical) { + // automatically scroll to bottom of text view + ScrollView(.vertical, showsIndicators: true) { Text(llamaState.messageLog) } @@ -15,14 +16,24 @@ struct ContentView: View { .frame(height: 200) .padding() .border(Color.gray, width: 0.5) - Button(action: { - sendText() - }) { - Text("Send") - .padding() - .background(Color.blue) - .foregroundColor(.white) - .cornerRadius(8) + + // add two buttons "Send" and "Bench" next to each other + HStack { + Button("Send") { + sendText() + } + .padding() + .background(Color.blue) + .foregroundColor(.white) + .cornerRadius(8) + + Button("Bench") { + bench() + } + .padding() + .background(Color.blue) + .foregroundColor(.white) + .cornerRadius(8) } } .padding() @@ -34,9 +45,14 @@ struct ContentView: View { multiLineText = "" } } + + func bench() { + Task { + await llamaState.bench() + } + } } -/* + #Preview { ContentView() } -*/