correct thinking modes for each model

This commit is contained in:
Georg Bauer
2026-09-01 21:03:13 +02:00
parent ee515ee824
commit d40e86e5ef
11 changed files with 338 additions and 127 deletions

View File

@@ -6,9 +6,23 @@ use super::{
use crate::settings::ReasoningMode;
use std::collections::HashMap;
const MAX_REASONING_PREFIX: &str = "Reasoning Effort: Absolute maximum with no shortcuts permitted.\n\
const HIGH_REASONING_PREFIX: &str = "Reasoning Effort: Absolute maximum with no shortcuts permitted.\n\
You MUST be very thorough in your thinking and comprehensively decompose the problem to resolve the root cause, rigorously stress-testing your logic against all potential paths, edge cases, and adversarial scenarios.\n\
Explicitly write out your entire deliberation process, documenting every intermediate step, considered alternative, and rejected hypothesis to ensure absolutely no assumption is left unchecked.\n\n";
const MAX_REASONING_PREFIX: &str = "Reasoning Effort: Beyond maximum — exhaustive, relentless, and uncompromising.\n\
You MUST reason with the utmost depth and rigor, leaving absolutely nothing to chance: exhaustively decompose the problem into its most fundamental components, trace every causal chain to its root, and resolve the underlying cause rather than any surface symptom.\n\
Do not stop reasoning until you have independently verified the solution from multiple angles and are certain that no assumption remains unchecked and no error remains undiscovered.\n\n";
fn reasoning_prefix(family: ModelFamily, reasoning: ReasoningMode) -> Option<&'static str> {
match (family, reasoning) {
(ModelFamily::DeepSeek, ReasoningMode::High) => Some(HIGH_REASONING_PREFIX),
(ModelFamily::DeepSeek, ReasoningMode::Max) => Some(MAX_REASONING_PREFIX),
(ModelFamily::Glm, ReasoningMode::Low) => Some("Reasoning Effort: Low"),
(ModelFamily::Glm, ReasoningMode::High) => Some("Reasoning Effort: High"),
(ModelFamily::Glm, ReasoningMode::Max) => Some("Reasoning Effort: Max"),
(_, ReasoningMode::Direct | ReasoningMode::Low) => None,
}
}
pub(super) struct Tokenizer {
family: ModelFamily,
@@ -254,19 +268,11 @@ impl Tokenizer {
if self.family == ModelFamily::Glm && self.sop >= 0 {
output.push(self.sop);
}
match (self.family, reasoning) {
(ModelFamily::Glm, ReasoningMode::High | ReasoningMode::Max) => {
if let Some(prefix) = reasoning_prefix(self.family, reasoning) {
if self.family == ModelFamily::Glm {
output.push(self.system);
output.extend(self.tokenize(if reasoning == ReasoningMode::Max {
"Reasoning Effort: Max"
} else {
"Reasoning Effort: High"
}));
}
(ModelFamily::DeepSeek, ReasoningMode::Max) => {
output.extend(self.tokenize(MAX_REASONING_PREFIX));
}
_ => {}
output.extend(self.tokenize(prefix));
}
if !system_prompt.is_empty() {
if self.family == ModelFamily::Glm {
@@ -843,4 +849,32 @@ mod tests {
assert_eq!(next_char("", 0), 0);
assert!(!cjk_at("", 0));
}
#[test]
fn reasoning_prefixes_match_each_model_family_contract() {
assert_eq!(
reasoning_prefix(ModelFamily::DeepSeek, ReasoningMode::Low),
None
);
assert_eq!(
reasoning_prefix(ModelFamily::DeepSeek, ReasoningMode::High),
Some(HIGH_REASONING_PREFIX)
);
assert_eq!(
reasoning_prefix(ModelFamily::DeepSeek, ReasoningMode::Max),
Some(MAX_REASONING_PREFIX)
);
assert_eq!(
reasoning_prefix(ModelFamily::Glm, ReasoningMode::Low),
Some("Reasoning Effort: Low")
);
assert_eq!(
reasoning_prefix(ModelFamily::Glm, ReasoningMode::High),
Some("Reasoning Effort: High")
);
assert_eq!(
reasoning_prefix(ModelFamily::Glm, ReasoningMode::Max),
Some("Reasoning Effort: Max")
);
}
}