Skip to content

Commit 8e36c71

Browse files
committed
Use chat template
1 parent 0907d7f commit 8e36c71

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Applications/LLMEval/ContentView.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ class LLMEvaluator {
159159

160160
/// This controls which model loads. `phi3_5_4bit` is one of the smaller ones, so this will fit on
161161
/// more devices.
162-
let modelConfiguration = ModelConfiguration.phi3_5_4bit
162+
// let modelConfiguration = ModelConfiguration.phi3_5_4bit
163+
let modelConfiguration = ModelConfiguration.mistral7B4bit
163164

164165
/// parameters controlling the output
165166
let generateParameters = GenerateParameters(temperature: 0.6)
@@ -212,11 +213,9 @@ class LLMEvaluator {
212213
do {
213214
let modelContainer = try await load()
214215

215-
// augment the prompt as needed
216-
let prompt = modelConfiguration.prepare(prompt: prompt)
217-
218-
let promptTokens = await modelContainer.perform { _, tokenizer in
219-
tokenizer.encode(text: prompt)
216+
let messages = [["role": "user", "content": prompt]]
217+
let promptTokens = try await modelContainer.perform { _, tokenizer in
218+
try tokenizer.applyChatTemplate(messages: messages)
220219
}
221220

222221
// each time you generate you will get something new

Libraries/LLM/Models.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ extension ModelConfiguration {
130130

131131
public static let mistral7B4bit = ModelConfiguration(
132132
id: "mlx-community/Mistral-7B-Instruct-v0.3-4bit",
133-
defaultPrompt: "Describe the Swift language."
133+
defaultPrompt: "Describe the Swift language.",
134+
extraEOSTokens: ["<|im_end|>"] // !! This doesn't seem to work
134135
) { prompt in
135136
"<s>[INST] \(prompt) [/INST] "
136137
}

0 commit comments

Comments
 (0)