feat: better chat support for thinking
This commit is contained in:
@@ -136,7 +136,8 @@ impl Tokenizer {
|
||||
system_prompt,
|
||||
&[ChatTurn {
|
||||
user: true,
|
||||
reasoning: false,
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
content: prompt.to_owned(),
|
||||
}],
|
||||
reasoning,
|
||||
@@ -180,8 +181,12 @@ impl Tokenizer {
|
||||
self.assistant
|
||||
});
|
||||
if !message.user {
|
||||
if message.reasoning {
|
||||
if let Some(reasoning) = &message.reasoning {
|
||||
output.push(self.think_start);
|
||||
output.extend(self.tokenize(reasoning));
|
||||
if message.reasoning_complete {
|
||||
output.push(self.think_end);
|
||||
}
|
||||
} else if self.family == ModelFamily::Glm {
|
||||
output.extend([self.think_start, self.think_end]);
|
||||
} else {
|
||||
@@ -189,6 +194,9 @@ impl Tokenizer {
|
||||
}
|
||||
}
|
||||
output.extend(self.tokenize(&message.content));
|
||||
if !message.user && self.family == ModelFamily::DeepSeek {
|
||||
output.push(self.eos);
|
||||
}
|
||||
}
|
||||
output.push(self.assistant);
|
||||
if reasoning != ReasoningMode::Direct {
|
||||
@@ -211,6 +219,14 @@ impl Tokenizer {
|
||||
&& [self.system, self.user, self.assistant, self.observation].contains(&token))
|
||||
}
|
||||
|
||||
pub(super) fn is_think_start(&self, token: i32) -> bool {
|
||||
token == self.think_start
|
||||
}
|
||||
|
||||
pub(super) fn is_think_end(&self, token: i32) -> bool {
|
||||
token == self.think_end
|
||||
}
|
||||
|
||||
fn emit_piece(&self, raw: &[u8], output: &mut Vec<i32>) {
|
||||
if raw.is_empty() {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user