Skip to content

Commit 6f7ccda

Browse files
committed
Add ios app changes
1 parent 6d6fe0f commit 6f7ccda

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

examples/demo-apps/apple_ios/LLaMA/LLaMA/Application/Constants.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,14 @@ You are a helpful assistant.
2626

2727
public static let llama3PromptTemplate = "<|begin_of_text|><|start_header_id|>user<|end_header_id|>%@<|eot_id|><|start_header_id|>assistant<|end_header_id|>"
2828

29-
public static let phi4PromptTemplate = "<|user|>%@<|end|><|assistant|>"
29+
public static let phi4PromptTemplate = "<|user|>%@<|end|><|assistant|>"
30+
31+
public static let gemma3PromptTemplate = """
32+
<bos><start_of_turn>user
33+
34+
35+
%@<end_of_turn>
36+
<start_of_turn>model
37+
38+
"""
3039
}

examples/demo-apps/apple_ios/LLaMA/LLaMA/Application/ContentView.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct ContentView: View {
8787
case llava
8888
case qwen3
8989
case phi4
90+
case gemma3
9091

9192
static func fromPath(_ path: String) -> ModelType {
9293
let filename = (path as NSString).lastPathComponent.lowercased()
@@ -98,7 +99,9 @@ struct ContentView: View {
9899
return .qwen3
99100
} else if filename.hasPrefix("phi4") {
100101
return .phi4
101-
}
102+
} else if filename.hasPrefix("gemma3") {
103+
return .gemma3
104+
}
102105
print("Unknown model type in path: \(path). Model filename should start with one of: llama, llava, qwen3, or phi4")
103106
exit(1)
104107
}
@@ -346,15 +349,15 @@ struct ContentView: View {
346349
}
347350

348351
switch modelType {
349-
case .llama, .qwen3, .phi4:
352+
case .llama, .qwen3, .phi4, .gemma3:
350353
runnerHolder.llamaRunner = runnerHolder.llamaRunner ?? LLaMARunner(modelPath: modelPath, tokenizerPath: tokenizerPath)
351354
case .llava:
352355
runnerHolder.llavaRunner = runnerHolder.llavaRunner ?? LLaVARunner(modelPath: modelPath, tokenizerPath: tokenizerPath)
353356
}
354357

355358
guard !shouldStopGenerating else { return }
356359
switch modelType {
357-
case .llama, .qwen3, .phi4:
360+
case .llama, .qwen3, .phi4, .gemma3:
358361
if let runner = runnerHolder.llamaRunner, !runner.isLoaded() {
359362
var error: Error?
360363
let startLoadTime = Date()
@@ -479,6 +482,8 @@ struct ContentView: View {
479482
prompt = String(format: Constants.llama3PromptTemplate, text)
480483
case .phi4:
481484
prompt = String(format: Constants.phi4PromptTemplate, text)
485+
case .gemma3:
486+
prompt = String(format: Constants.gemma3PromptTemplate, text)
482487
}
483488

484489
try runnerHolder.llamaRunner?.generate(prompt, sequenceLength: seq_len) { token in

0 commit comments

Comments
 (0)