返回 CodeWhale
deepseek_effort.rs
根目录 / crates / engine / src / client / deepseek_effort.rs
1 //! The single source of truth for DeepSeek's reasoning-effort mapping.
2 //!
3 //! DeepSeek exposes the same four thinking tiers on both wires it speaks to
4 //! us, but spells them differently, and until #5055 each spelling lived inline
5 //! at its call site — so a documented mapping change meant code archaeology
6 //! across two files instead of one edit here.
7 //!
8 //! Source: <https://api-docs.deepseek.com/api/create-chat-completion> for the
9 //! Chat Completions `reasoning_effort` values, and DeepSeek's Thinking Mode
10 //! guide <https://api-docs.deepseek.com/guides/reasoning_model> for the
11 //! requested-to-actual mapping (verified 2026-09-17).
12 //!
13 //! What the wires document, and what this table encodes:
14 //!
15 //! | Tier | Chat Completions | Responses API |
16 //! |------|-----------------------------|--------------------|
17 //! | Off | `thinking: {type: disabled}` | `effort: "none"` |
18 //! | Low | `reasoning_effort: "low"` | `effort: "low"` |
19 //! | High | `reasoning_effort: "high"` | `effort: "high"` |
20 //! | Max | `reasoning_effort: "max"` | `effort: "max"` |
21 //!
22 //! DeepSeek's Thinking Mode guide documents the requested-to-actual effort
23 //! mapping; thinking is enabled by default with an actual effort of `high`:
24 //!
25 //! | Requested | Actual |
26 //! |-----------|--------|
27 //! | minimal | low |
28 //! | low | low |
29 //! | medium | high |
30 //! | high | high |
31 //! | xhigh | high |
32 //! | max | max |
33 //! | ultra | max |
34 //!
35 //! `medium`, `xhigh`, and `ultra` are client-side requests that collapse onto
36 //! the documented wire tiers — they are not new wire values. When DeepSeek
37 //! changes the mapping, edit [`DeepseekEffortTier`]'s two wire accessors and
38 //! [`DEEPSEEK_EFFORT_ALIASES`] below, bump the verified date in this comment,
39 //! and both call sites move together — that is the whole point of this module.
40
41 /// A documented DeepSeek thinking tier, independent of which wire carries it.
42 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
43 pub(super) enum DeepseekEffortTier {
44 /// Thinking disabled.
45 Off,
46 /// The cheaper real reasoning tier.
47 Low,
48 /// The default reasoning tier; also where an undocumented `medium` lands.
49 High,
50 /// The deepest documented tier.
51 Max,
52 }
53
54 impl DeepseekEffortTier {
55 /// Chat Completions `reasoning_effort` value, or `None` for the off tier —
56 /// which that wire expresses with `thinking: {"type": "disabled"}` rather
57 /// than an effort string.
58 pub(super) fn chat_reasoning_effort(self) -> Option<&'static str> {
59 match self {
60 Self::Off => None,
61 Self::Low => Some("low"),
62 Self::High => Some("high"),
63 Self::Max => Some("max"),
64 }
65 }
66
67 /// Whether this tier enables thinking on the Chat Completions wire.
68 pub(super) fn chat_thinking_enabled(self) -> bool {
69 !matches!(self, Self::Off)
70 }
71
72 /// Responses API `reasoning.effort` value. Every tier has a documented
73 /// label here, including off (`"none"`), so the picker's Off entry stays
74 /// off instead of collapsing into a still-thinking low.
75 pub(super) fn responses_effort(self) -> &'static str {
76 match self {
77 Self::Off => "none",
78 Self::Low => "low",
79 Self::High => "high",
80 Self::Max => "max",
81 }
82 }
83 }
84
85 /// Every CodeWhale-side effort spelling that maps onto a documented DeepSeek
86 /// tier. The empty string is CodeWhale's "unset" effort, which means the
87 /// default tier.
88 ///
89 /// The Responses wire normalizes unknown spellings to the default tier, except
90 /// for `auto`, which is omitted. The Chat wire omits unknown spellings.
91 pub(super) const DEEPSEEK_EFFORT_ALIASES: &[(&str, DeepseekEffortTier)] = &[
92 ("off", DeepseekEffortTier::Off),
93 ("disabled", DeepseekEffortTier::Off),
94 ("none", DeepseekEffortTier::Off),
95 ("false", DeepseekEffortTier::Off),
96 ("minimal", DeepseekEffortTier::Low),
97 ("low", DeepseekEffortTier::Low),
98 ("medium", DeepseekEffortTier::High),
99 ("mid", DeepseekEffortTier::High),
100 ("high", DeepseekEffortTier::High),
101 ("", DeepseekEffortTier::High),
102 ("xhigh", DeepseekEffortTier::High),
103 ("max", DeepseekEffortTier::Max),
104 ("maximum", DeepseekEffortTier::Max),
105 ("highest", DeepseekEffortTier::Max),
106 ("ultra", DeepseekEffortTier::Max),
107 ("ultracode", DeepseekEffortTier::Max),
108 ];
109
110 /// The tier CodeWhale falls back to when a caller asks for something this
111 /// table does not name (a future provider label or a typo).
112 pub(super) const DEEPSEEK_DEFAULT_EFFORT_TIER: DeepseekEffortTier = DeepseekEffortTier::High;
113
114 /// Look up a raw effort string. Case- and whitespace-insensitive.
115 pub(super) fn deepseek_effort_tier(raw: &str) -> Option<DeepseekEffortTier> {
116 let normalized = raw.trim().to_ascii_lowercase();
117 DEEPSEEK_EFFORT_ALIASES
118 .iter()
119 .find(|(alias, _)| *alias == normalized)
120 .map(|(_, tier)| *tier)
121 }
122
123 /// Look up a raw effort string, falling back to
124 /// [`DEEPSEEK_DEFAULT_EFFORT_TIER`] for unknown spellings.
125 pub(super) fn deepseek_effort_tier_or_default(raw: &str) -> DeepseekEffortTier {
126 deepseek_effort_tier(raw).unwrap_or(DEEPSEEK_DEFAULT_EFFORT_TIER)
127 }
128
129 #[cfg(test)]
130 mod tests {
131 use super::*;
132
133 /// DeepSeek's documented requested-to-actual mapping (Thinking Mode
134 /// guide, verified 2026-09-17). Pin every row so a future edit to the
135 /// table cannot silently disagree with the vendor.
136 #[test]
137 fn vendor_requested_to_actual_mapping_is_pinned() {
138 for (requested, tier) in [
139 ("minimal", DeepseekEffortTier::Low),
140 ("low", DeepseekEffortTier::Low),
141 ("medium", DeepseekEffortTier::High),
142 ("high", DeepseekEffortTier::High),
143 ("xhigh", DeepseekEffortTier::High),
144 ("max", DeepseekEffortTier::Max),
145 ("ultra", DeepseekEffortTier::Max),
146 ] {
147 assert_eq!(deepseek_effort_tier(requested), Some(tier), "{requested}");
148 }
149 }
150
151 #[test]
152 fn aliases_are_unique_and_normalized() {
153 for (index, (alias, _)) in DEEPSEEK_EFFORT_ALIASES.iter().enumerate() {
154 assert_eq!(
155 *alias,
156 alias.trim().to_ascii_lowercase(),
157 "alias {alias:?} must be stored pre-normalized"
158 );
159 assert!(
160 !DEEPSEEK_EFFORT_ALIASES[..index]
161 .iter()
162 .any(|(seen, _)| seen == alias),
163 "duplicate alias {alias:?}"
164 );
165 }
166 }
167
168 #[test]
169 fn lookup_is_case_and_whitespace_insensitive() {
170 assert_eq!(
171 deepseek_effort_tier(" MAX "),
172 Some(DeepseekEffortTier::Max)
173 );
174 assert_eq!(deepseek_effort_tier("auto"), None);
175 assert_eq!(
176 deepseek_effort_tier_or_default("auto"),
177 DeepseekEffortTier::High
178 );
179 }
180
181 #[test]
182 fn ultra_and_legacy_ultracode_alias_resolve_to_max() {
183 assert_eq!(deepseek_effort_tier("ultra"), Some(DeepseekEffortTier::Max));
184 assert_eq!(
185 deepseek_effort_tier("ultracode"),
186 Some(DeepseekEffortTier::Max)
187 );
188 assert_eq!(
189 deepseek_effort_tier_or_default("ultra").responses_effort(),
190 "max"
191 );
192 }
193
194 #[test]
195 fn every_tier_has_both_wire_spellings() {
196 for tier in [
197 DeepseekEffortTier::Off,
198 DeepseekEffortTier::Low,
199 DeepseekEffortTier::High,
200 DeepseekEffortTier::Max,
201 ] {
202 let responses = tier.responses_effort();
203 assert!(!responses.is_empty(), "{tier:?} needs a Responses label");
204 match tier {
205 DeepseekEffortTier::Off => {
206 assert_eq!(tier.chat_reasoning_effort(), None);
207 assert!(!tier.chat_thinking_enabled());
208 }
209 _ => {
210 assert_eq!(tier.chat_reasoning_effort(), Some(responses));
211 assert!(tier.chat_thinking_enabled());
212 }
213 }
214 }
215 }
216 }
217
217 lines RUST