llama.swiftui : add bench button
This commit is contained in:
parent
6744dbe924
commit
afd336f7a6
3 changed files with 43 additions and 12 deletions
|
@ -161,6 +161,10 @@ actor LlamaContext {
|
||||||
return new_token_str
|
return new_token_str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bench() -> String{
|
||||||
|
return "bench not implemented"
|
||||||
|
}
|
||||||
|
|
||||||
func clear() {
|
func clear() {
|
||||||
tokens_list.removeAll()
|
tokens_list.removeAll()
|
||||||
temporary_invalid_cchars.removeAll()
|
temporary_invalid_cchars.removeAll()
|
||||||
|
|
|
@ -6,7 +6,7 @@ class LlamaState: ObservableObject {
|
||||||
|
|
||||||
private var llamaContext: LlamaContext?
|
private var llamaContext: LlamaContext?
|
||||||
private var modelUrl: URL? {
|
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")
|
// Bundle.main.url(forResource: "llama-2-7b-chat", withExtension: "Q2_K.gguf", subdirectory: "models")
|
||||||
}
|
}
|
||||||
init() {
|
init() {
|
||||||
|
@ -31,6 +31,7 @@ class LlamaState: ObservableObject {
|
||||||
guard let llamaContext else {
|
guard let llamaContext else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
messageLog += "Attempting to complete text...\n"
|
messageLog += "Attempting to complete text...\n"
|
||||||
await llamaContext.completion_init(text: text)
|
await llamaContext.completion_init(text: text)
|
||||||
messageLog += "\(text)"
|
messageLog += "\(text)"
|
||||||
|
@ -42,4 +43,14 @@ class LlamaState: ObservableObject {
|
||||||
await llamaContext.clear()
|
await llamaContext.clear()
|
||||||
messageLog += "\n\ndone\n"
|
messageLog += "\n\ndone\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bench() async {
|
||||||
|
guard let llamaContext else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
messageLog += "Running benchmark...\n"
|
||||||
|
let result = await llamaContext.bench()
|
||||||
|
messageLog += "\(result)"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@ struct ContentView: View {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
ScrollView(.vertical) {
|
// automatically scroll to bottom of text view
|
||||||
|
ScrollView(.vertical, showsIndicators: true) {
|
||||||
Text(llamaState.messageLog)
|
Text(llamaState.messageLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,14 +16,24 @@ struct ContentView: View {
|
||||||
.frame(height: 200)
|
.frame(height: 200)
|
||||||
.padding()
|
.padding()
|
||||||
.border(Color.gray, width: 0.5)
|
.border(Color.gray, width: 0.5)
|
||||||
Button(action: {
|
|
||||||
sendText()
|
// add two buttons "Send" and "Bench" next to each other
|
||||||
}) {
|
HStack {
|
||||||
Text("Send")
|
Button("Send") {
|
||||||
.padding()
|
sendText()
|
||||||
.background(Color.blue)
|
}
|
||||||
.foregroundColor(.white)
|
.padding()
|
||||||
.cornerRadius(8)
|
.background(Color.blue)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.cornerRadius(8)
|
||||||
|
|
||||||
|
Button("Bench") {
|
||||||
|
bench()
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.background(Color.blue)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.cornerRadius(8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
|
@ -34,9 +45,14 @@ struct ContentView: View {
|
||||||
multiLineText = ""
|
multiLineText = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bench() {
|
||||||
|
Task {
|
||||||
|
await llamaState.bench()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
#Preview {
|
#Preview {
|
||||||
ContentView()
|
ContentView()
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue