diff --git a/control-plane/src/harmony_family.rs b/control-plane/src/harmony_family.rs index 2a7029ba..49a0970f 100644 --- a/control-plane/src/harmony_family.rs +++ b/control-plane/src/harmony_family.rs @@ -83,6 +83,15 @@ impl TextCodec for GptOssCodec { Ok(ids) } + fn always_reasons(&self) -> bool { + true + } + + /// The worker's `GEN` line takes temperature, top_p and seed only. + fn sampling_limit(&self) -> Option<&'static str> { + Some("the gpt-oss family supports temperature, top_p and seed only") + } + fn decoder(&self) -> Box { Box::new(HarmonyDecoder::new(self.bpe.clone())) } diff --git a/control-plane/src/responses/create/admit.rs b/control-plane/src/responses/create/admit.rs index 9df9772c..430f6396 100644 --- a/control-plane/src/responses/create/admit.rs +++ b/control-plane/src/responses/create/admit.rs @@ -60,23 +60,23 @@ pub(super) fn check_live_features( message, )); } - if tokenizer.family() == Family::GptOss { - // The gpt-oss CPU worker's `GEN` line takes temperature, top_p and seed only. An explicit request for a - // sampler it does not have is a client error; defaults from the config or the shared settings are dropped. + if let Some(limit) = tokenizer.sampling_limit() { + // The worker of some families takes few samplers. An explicit request for one it does not have is a client + // error; defaults from the config or the shared settings are dropped. if let Some(param) = unsupported_gptoss_sampling(&request.sampling()) { return Err(api_error( StatusCode::BAD_REQUEST, "invalid_request_error", "unsupported_parameter", Some(param), - "the gpt-oss family supports temperature, top_p and seed only", + limit, )); } } Ok(()) } -/// The server's sampling defaults, minus the samplers the gpt-oss worker does not have. +/// The server's sampling defaults, minus the samplers the model's worker does not have. pub(super) fn apply_sampling_defaults( state: &AppState, request: &mut CreateRequest, @@ -86,7 +86,7 @@ pub(super) fn apply_sampling_defaults( &state.services.settings.merged(), &state.services.settings.shared(), ); - if tokenizer.family() == Family::GptOss { + if tokenizer.sampling_limit().is_some() { request.top_k = None; request.min_p = None; request.repetition_penalty = None; diff --git a/control-plane/src/responses/reasoning.rs b/control-plane/src/responses/reasoning.rs index 56484544..3ea3a6d0 100644 --- a/control-plane/src/responses/reasoning.rs +++ b/control-plane/src/responses/reasoning.rs @@ -50,7 +50,7 @@ pub(super) fn reasoning_plan( ) -> Option { // The wrap-up and the byte accounting are the Qwen path's; the Harmony family has no reasoning budget. let tokenizer = codec.qwen()?; - if !reasoning_enabled(request, codec.family()) { + if !reasoning_enabled(request, codec.as_ref()) { return None; } let budget = leleka_serving_policy::reasoning::parse_budget( diff --git a/control-plane/src/responses/stream/text.rs b/control-plane/src/responses/stream/text.rs index 98204b0a..e34edf3e 100644 --- a/control-plane/src/responses/stream/text.rs +++ b/control-plane/src/responses/stream/text.rs @@ -25,7 +25,7 @@ pub(in crate::responses) fn stream_live_text( source: mpsc::Receiver>, env: StreamEnv, ) -> Response { - if is_structured(&request) || reasoning_enabled(&request, tokenizer.family()) { + if is_structured(&request) || reasoning_enabled(&request, tokenizer.as_ref()) { return stream_live_buffered(request, tokenizer, source, env); } if !request.tools.is_empty() { diff --git a/control-plane/src/responses/tool_recovery.rs b/control-plane/src/responses/tool_recovery.rs index 881b8b0c..1970e668 100644 --- a/control-plane/src/responses/tool_recovery.rs +++ b/control-plane/src/responses/tool_recovery.rs @@ -23,7 +23,7 @@ pub(super) fn tool_call_recovery() -> bool { /// What the reading at the end of a generation needs for this request and model family. pub(super) fn at_end_plan(request: &CreateRequest, codec: &C) -> AtEndPlan { AtEndPlan { - reasoning: reasoning_enabled(request, codec.family()), + reasoning: reasoning_enabled(request, codec), tools: (!request.tools.is_empty()).then(|| flat_tools(request)), recovery: tool_call_recovery(), keep_raw: debug_failed_output(), diff --git a/crates/gateway-domain/src/codec.rs b/crates/gateway-domain/src/codec.rs index fa87d309..b9398f33 100644 --- a/crates/gateway-domain/src/codec.rs +++ b/crates/gateway-domain/src/codec.rs @@ -35,6 +35,15 @@ pub trait TextCodec: Send + Sync { fn decoder(&self) -> Box; /// The decoder of one generation that turns the generated ids into output events (see `crate::output`). fn output_decoder<'a>(&self, plan: ReadPlan<'a>) -> OutputDecoder<'a>; + /// The model reasons whatever the request's effort says (gpt-oss always opens with its analysis channel). + fn always_reasons(&self) -> bool { + false + } + /// What the model's worker cannot sample, in the words of the error a client gets for asking for it; `None`: the + /// model takes every sampler of the request. + fn sampling_limit(&self) -> Option<&'static str> { + None + } /// Tokens that end the visible output of a generation (they are not part of the text). fn terminal_ids(&self) -> Vec; /// Token ids of a rendered prompt, the one tokenization used for generation and for counting. The template's own diff --git a/crates/gateway-domain/src/responses/effort.rs b/crates/gateway-domain/src/responses/effort.rs index edfd1a80..0a55d01e 100644 --- a/crates/gateway-domain/src/responses/effort.rs +++ b/crates/gateway-domain/src/responses/effort.rs @@ -1,6 +1,6 @@ //! What the request asks of the model's reasoning, and which sampler fields a model family cannot carry. -use crate::codec::Family; +use crate::codec::TextCodec; use crate::responses::request::{CreateRequest, TextFormat}; use leleka_gateway_text::prompt::Effort; use serde_json::Value; @@ -56,9 +56,9 @@ fn effort_level(effort: Option<&Value>) -> Result`. gpt-oss always reasons. -pub fn reasoning_enabled(request: &CreateRequest, family: Family) -> bool { - family == Family::GptOss || reasoning_effort(request).is_ok_and(|effort| effort != Effort::None) +/// Whether the output starts inside a reasoning block that ends with ``. A model that always reasons does. +pub fn reasoning_enabled(request: &CreateRequest, codec: &C) -> bool { + codec.always_reasons() || reasoning_effort(request).is_ok_and(|effort| effort != Effort::None) } /// The first sampler the request sets that the gpt-oss worker's `GEN` line cannot carry.