File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -221,9 +221,20 @@ private struct LLMUserInputProcessor: UserInputProcessor {
221
221
}
222
222
223
223
func prepare( input: UserInput ) throws -> LMInput {
224
- let messages = input. prompt. asMessages ( )
225
- let promptTokens = try tokenizer. applyChatTemplate ( messages: messages)
226
- return LMInput ( tokens: MLXArray ( promptTokens) )
224
+ do {
225
+ let messages = input. prompt. asMessages ( )
226
+ let promptTokens = try tokenizer. applyChatTemplate ( messages: messages)
227
+ return LMInput ( tokens: MLXArray ( promptTokens) )
228
+ } catch {
229
+ // #150 -- it might be a TokenizerError.chatTemplate("No chat template was specified")
230
+ // but that is not public so just fall back to text
231
+ let prompt = input. prompt
232
+ . asMessages ( )
233
+ . compactMap { $0 [ " content " ] }
234
+ . joined ( separator: " . " )
235
+ let promptTokens = tokenizer. encode ( text: prompt)
236
+ return LMInput ( tokens: MLXArray ( promptTokens) )
237
+ }
227
238
}
228
239
}
229
240
You can’t perform that action at this time.
0 commit comments