Thinking levels: Tab cycles off/low/medium/high, /effort
This commit is contained in:
1 parent
2f1ce2c072
commit
ab2af421a4
9 files changed
+180
-16
No files matched your search
@@ -138,6 +138,99 @@ pub enum StopReason {
|
||||
Other,
|
||||
}
|
||||
|
||||
/// How hard the model thinks before answering.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Effort {
|
||||
Off,
|
||||
Low,
|
||||
#[default]
|
||||
Medium,
|
||||
High,
|
||||
}
|
||||
|
||||
impl Effort {
|
||||
pub const ALL: [Effort; 4] = [Effort::Off, Effort::Low, Effort::Medium, Effort::High];
|
||||
|
||||
/// Start level per provider: Claude thinks only when asked (token cost), Codex always reasons.
|
||||
pub fn default_for(k: auth::Kind) -> Self {
|
||||
match k {
|
||||
auth::Kind::Claude => Effort::Off,
|
||||
auth::Kind::Codex => Effort::Medium,
|
||||
}
|
||||
}
|
||||
|
||||
/// Levels the provider supports (Codex models can't switch reasoning off).
|
||||
pub fn levels(k: auth::Kind) -> &'static [Effort] {
|
||||
match k {
|
||||
auth::Kind::Claude => &Self::ALL,
|
||||
auth::Kind::Codex => &Self::ALL[1..],
|
||||
}
|
||||
}
|
||||
|
||||
/// Next level in `levels(k)`, wrapping; a level the provider lacks maps to its first.
|
||||
pub fn next(self, k: auth::Kind) -> Self {
|
||||
let l = Self::levels(k);
|
||||
l.iter()
|
||||
.position(|&e| e == self)
|
||||
.map_or(l[0], |i| l[(i + 1) % l.len()])
|
||||
}
|
||||
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
Effort::Off => "off",
|
||||
Effort::Low => "low",
|
||||
Effort::Medium => "medium",
|
||||
Effort::High => "high",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod effort_tests {
|
||||
use super::*;
|
||||
use auth::Kind;
|
||||
|
||||
#[test]
|
||||
fn cycle_wraps_and_codex_skips_off() {
|
||||
let mut e = Effort::Off;
|
||||
let seen: Vec<_> = (0..5)
|
||||
.map(|_| {
|
||||
e = e.next(Kind::Claude);
|
||||
e
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
seen,
|
||||
[
|
||||
Effort::Low,
|
||||
Effort::Medium,
|
||||
Effort::High,
|
||||
Effort::Off,
|
||||
Effort::Low
|
||||
]
|
||||
);
|
||||
assert_eq!(Effort::High.next(Kind::Codex), Effort::Low);
|
||||
assert_eq!(
|
||||
Effort::Off.next(Kind::Codex),
|
||||
Effort::Low,
|
||||
"unsupported level"
|
||||
);
|
||||
assert_eq!("high".parse::<Effort>(), Ok(Effort::High));
|
||||
assert!("max".parse::<Effort>().is_err());
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Effort {
|
||||
type Err = String;
|
||||
fn from_str(s: &str) -> std::result::Result<Self, String> {
|
||||
Self::ALL
|
||||
.into_iter()
|
||||
.find(|e| e.name() == s)
|
||||
.ok_or_else(|| format!("unknown level {s:?} (off, low, medium, high)"))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Request {
|
||||
pub model: String,
|
||||
@@ -145,6 +238,7 @@ pub struct Request {
|
||||
pub messages: Vec<Message>,
|
||||
pub tools: Vec<ToolSpec>,
|
||||
pub max_tokens: u32,
|
||||
pub effort: Effort,
|
||||
}
|
||||
|
||||
/// Incremental stream events. Providers must emit `Done` last with the full assembled message.
|
||||
|
||||
Reference in new issue
Block a user