@@ -20,8 +20,10 @@ use validator::Validate;
2020use crate :: engines:: ValidateRequest ;
2121
2222use super :: {
23- nvext:: NvExt , nvext:: NvExtProvider , validate, OpenAISamplingOptionsProvider ,
24- OpenAIStopConditionsProvider ,
23+ common_ext:: { CommonExt , CommonExtProvider } ,
24+ nvext:: NvExt ,
25+ nvext:: NvExtProvider ,
26+ validate, OpenAISamplingOptionsProvider , OpenAIStopConditionsProvider ,
2527} ;
2628
2729mod aggregator;
@@ -31,17 +33,21 @@ pub use aggregator::DeltaAggregator;
3133pub use delta:: DeltaGenerator ;
3234
3335/// A request structure for creating a chat completion, extending OpenAI's
34- /// `CreateChatCompletionRequest` with [`NvExt`] extensions.
36+ /// `CreateChatCompletionRequest` with [`NvExt`] extensions and common fields .
3537///
3638/// # Fields
3739/// - `inner`: The base OpenAI chat completion request, embedded using `serde(flatten)`.
38- /// - `nvext`: The optional NVIDIA extension field. See [`NvExt`] for
39- /// more details.
40+ /// - `common`: Common extension fields (ignore_eos, min_tokens) at root level, embedded using `serde(flatten)`.
41+ /// - `nvext`: The optional NVIDIA extension field. See [`NvExt`] for more details.
42+ /// Note: If ignore_eos is specified in both common and nvext, the common (root-level) value takes precedence.
4043#[ derive( Serialize , Deserialize , Validate , Debug , Clone ) ]
4144pub struct NvCreateChatCompletionRequest {
4245 #[ serde( flatten) ]
4346 pub inner : async_openai:: types:: CreateChatCompletionRequest ,
4447
48+ #[ serde( flatten, default ) ]
49+ pub common : CommonExt ,
50+
4551 #[ serde( skip_serializing_if = "Option::is_none" ) ]
4652 pub nvext : Option < NvExt > ,
4753}
@@ -139,6 +145,52 @@ impl OpenAISamplingOptionsProvider for NvCreateChatCompletionRequest {
139145 }
140146}
141147
148+ /// Implements `CommonExtProvider` for `NvCreateChatCompletionRequest`,
149+ /// providing access to common extension fields.
150+ impl CommonExtProvider for NvCreateChatCompletionRequest {
151+ /// Returns a reference to the CommonExt struct.
152+ fn common_ext ( & self ) -> Option < & CommonExt > {
153+ Some ( & self . common )
154+ }
155+
156+ /// Guided Decoding Options
157+ fn get_guided_json ( & self ) -> Option < & serde_json:: Value > {
158+ self . common
159+ . guided_json
160+ . as_ref ( )
161+ . or_else ( || self . nvext . as_ref ( ) . and_then ( |nv| nv. guided_json . as_ref ( ) ) )
162+ }
163+
164+ fn get_guided_regex ( & self ) -> Option < String > {
165+ self . common
166+ . guided_regex
167+ . clone ( )
168+ . or_else ( || self . nvext . as_ref ( ) . and_then ( |nv| nv. guided_regex . clone ( ) ) )
169+ }
170+
171+ fn get_guided_grammar ( & self ) -> Option < String > {
172+ self . common
173+ . guided_grammar
174+ . clone ( )
175+ . or_else ( || self . nvext . as_ref ( ) . and_then ( |nv| nv. guided_grammar . clone ( ) ) )
176+ }
177+
178+ fn get_guided_choice ( & self ) -> Option < Vec < String > > {
179+ self . common
180+ . guided_choice
181+ . clone ( )
182+ . or_else ( || self . nvext . as_ref ( ) . and_then ( |nv| nv. guided_choice . clone ( ) ) )
183+ }
184+
185+ fn get_guided_decoding_backend ( & self ) -> Option < String > {
186+ self . common . guided_decoding_backend . clone ( ) . or_else ( || {
187+ self . nvext
188+ . as_ref ( )
189+ . and_then ( |nv| nv. guided_decoding_backend . clone ( ) )
190+ } )
191+ }
192+ }
193+
142194/// Implements `OpenAIStopConditionsProvider` for `NvCreateChatCompletionRequest`,
143195/// providing access to stop conditions that control chat completion behavior.
144196impl OpenAIStopConditionsProvider for NvCreateChatCompletionRequest {
@@ -149,12 +201,10 @@ impl OpenAIStopConditionsProvider for NvCreateChatCompletionRequest {
149201 }
150202
151203 /// Retrieves the minimum number of tokens required in the response.
152- ///
153- /// # Note
154- /// This method is currently a placeholder and always returns `None`
155- /// since `min_tokens` is not an OpenAI-supported parameter.
204+ /// Returns `min_tokens` Value
205+ /// `min_tokens` is not an OpenAI-supported parameter.
156206 fn get_min_tokens ( & self ) -> Option < u32 > {
157- None
207+ self . common . min_tokens
158208 }
159209
160210 /// Retrieves the stop conditions that terminate the chat completion response.
@@ -175,6 +225,11 @@ impl OpenAIStopConditionsProvider for NvCreateChatCompletionRequest {
175225 fn nvext ( & self ) -> Option < & NvExt > {
176226 self . nvext . as_ref ( )
177227 }
228+
229+ /// Get ignore_eos from CommonExt.
230+ fn get_common_ignore_eos ( & self ) -> Option < bool > {
231+ self . common . ignore_eos
232+ }
178233}
179234
180235/// Implements `ValidateRequest` for `NvCreateChatCompletionRequest`,
0 commit comments