@@ -18,21 +18,25 @@ use crate::{
1818 protocols:: common:: { self } ,
1919 types:: TokenIdType ,
2020} ;
21+ use dynamo_runtime:: logging;
2122
2223/// Provides a method for generating a [`DeltaGenerator`] from a chat completion request.
2324impl NvCreateChatCompletionRequest {
2425 /// Creates a [`DeltaGenerator`] instance based on the chat completion request.
2526 ///
27+ /// # Arguments
28+ /// * `request_id` - The request ID to use for the chat completion response ID.
29+ ///
2630 /// # Returns
2731 /// * [`DeltaGenerator`] configured with model name and response options.
28- pub fn response_generator ( & self ) -> DeltaGenerator {
32+ pub fn response_generator ( & self , request_id : String ) -> DeltaGenerator {
2933 let options = DeltaGeneratorOptions {
3034 enable_usage : true ,
3135 enable_logprobs : self . inner . logprobs . unwrap_or ( false )
3236 || self . inner . top_logprobs . unwrap_or ( 0 ) > 0 ,
3337 } ;
3438
35- DeltaGenerator :: new ( self . inner . model . clone ( ) , options)
39+ DeltaGenerator :: new ( self . inner . model . clone ( ) , options, request_id )
3640 }
3741}
3842
@@ -74,10 +78,11 @@ impl DeltaGenerator {
7478 /// # Arguments
7579 /// * `model` - The model name used for response generation.
7680 /// * `options` - Configuration options for enabling usage and log probabilities.
81+ /// * `request_id` - The request ID to use for the chat completion response.
7782 ///
7883 /// # Returns
7984 /// * A new instance of [`DeltaGenerator`].
80- pub fn new ( model : String , options : DeltaGeneratorOptions ) -> Self {
85+ pub fn new ( model : String , options : DeltaGeneratorOptions , request_id : String ) -> Self {
8186 let now = std:: time:: SystemTime :: now ( )
8287 . duration_since ( std:: time:: UNIX_EPOCH )
8388 . unwrap ( )
@@ -95,8 +100,10 @@ impl DeltaGenerator {
95100 completion_tokens_details : None ,
96101 } ;
97102
103+ let chatcmpl_id = format ! ( "chatcmpl-{}" , request_id) ;
104+
98105 Self {
99- id : format ! ( "chatcmpl-{}" , uuid :: Uuid :: new_v4 ( ) ) ,
106+ id : chatcmpl_id ,
100107 object : "chat.completion.chunk" . to_string ( ) ,
101108 created : now,
102109 model,
0 commit comments