返回 CodeWhale
request_tuning.rs
根目录 / crates / tui / src / request_tuning.rs
1 //! Request-tuning intent carried through CodeWhale request routing (#3024).
2 //!
3 //! Request "tuning" here means the optional knobs a caller can attach to an
4 //! outbound model request that shape *how* the model responds without changing
5 //! *what* it is asked: the reasoning-effort tier and the maximum number of
6 //! output tokens. This module only carries that intent between routing layers.
7 //! Client code is still responsible for translating the intent into each
8 //! provider's wire format.
9 //!
10 //! ## Reasoning-effort enum reuse
11 //!
12 //! [`RequestTuning::reasoning_effort`] reuses the canonical
13 //! [`crate::tui::app::ReasoningEffort`] enum rather than defining a local
14 //! `Off/Low/Medium/High` copy. That enum is the single source of truth for the
15 //! effort tiers across the DeepSeek and Codex effort pickers, it is already
16 //! imported by sibling top-level modules (`auto_reasoning`, `model_routing`),
17 //! and it carries the provider-normalization logic (`normalize_for_provider`,
18 //! `api_value_for_provider`) that a future request-tuning consumer will need.
19 //! Defining a parallel local enum here would duplicate that surface and risk
20 //! drift, so we import the existing type.
21 //!
22 use crate::tui::app::ReasoningEffort;
23
24 /// Optional request-tuning knobs a caller may attach to a model request.
25 ///
26 /// Both fields are `Option`: `None` means "do not tune; use the provider
27 /// default". This is metadata describing intent — applying it to a wire
28 /// request is the responsibility of the client layer, not this module.
29 #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
30 pub struct RequestTuning {
31 /// Desired reasoning-effort tier, or `None` for the provider default.
32 ///
33 /// Reuses the canonical [`ReasoningEffort`] enum (see module docs).
34 pub reasoning_effort: Option<ReasoningEffort>,
35 /// Desired maximum number of output tokens, or `None` for the provider
36 /// default.
37 pub max_output_tokens: Option<u32>,
38 }
39
40 #[cfg(test)]
41 mod tests {
42 use super::*;
43
44 #[test]
45 fn request_tuning_default_has_no_knobs() {
46 let tuning = RequestTuning::default();
47 assert_eq!(tuning.reasoning_effort, None);
48 assert_eq!(tuning.max_output_tokens, None);
49 }
50
51 #[test]
52 fn request_tuning_reuses_reasoning_effort_enum() {
53 let tuning = RequestTuning {
54 reasoning_effort: Some(ReasoningEffort::High),
55 max_output_tokens: Some(4096),
56 };
57 assert_eq!(tuning.reasoning_effort, Some(ReasoningEffort::High));
58 assert_eq!(tuning.max_output_tokens, Some(4096));
59 }
60 }
61
61 lines RUST