Skip to content

Commit

Permalink
workaround for #150 -- important as this model is out new default
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkoski committed Dec 10, 2024
1 parent c6a10f8 commit f18213d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Libraries/MLXLLM/LLMModelFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,20 @@ private struct LLMUserInputProcessor: UserInputProcessor {
}

func prepare(input: UserInput) throws -> LMInput {
let messages = input.prompt.asMessages()
let promptTokens = try tokenizer.applyChatTemplate(messages: messages)
return LMInput(tokens: MLXArray(promptTokens))
do {
let messages = input.prompt.asMessages()
let promptTokens = try tokenizer.applyChatTemplate(messages: messages)
return LMInput(tokens: MLXArray(promptTokens))
} catch {
// #150 -- it might be a TokenizerError.chatTemplate("No chat template was specified")
// but that is not public so just fall back to text
let prompt = input.prompt
.asMessages()
.compactMap { $0["content"] }
.joined(separator: ". ")
let promptTokens = tokenizer.encode(text: prompt)
return LMInput(tokens: MLXArray(promptTokens))
}
}
}

Expand Down

0 comments on commit f18213d

Please sign in to comment.