@@ -79,12 +79,17 @@ where
7979 } ,
8080 /// A tool call partial/delta
8181 ToolCallDelta { id : String , delta : String } ,
82- /// A reasoning chunk
82+ /// A reasoning (in its entirety)
8383 Reasoning {
8484 id : Option < String > ,
8585 reasoning : String ,
8686 signature : Option < String > ,
8787 } ,
88+ /// A reasoning partial/delta
89+ ReasoningDelta {
90+ id : Option < String > ,
91+ reasoning : String ,
92+ } ,
8893
8994 /// The final response object, must be yielded if you want the
9095 /// `response` field to be populated on the `StreamingCompletionResponse`
@@ -231,15 +236,19 @@ where
231236 id,
232237 reasoning,
233238 signature,
234- } => {
239+ } => Poll :: Ready ( Some ( Ok ( StreamedAssistantContent :: Reasoning ( Reasoning {
240+ id,
241+ reasoning : vec ! [ reasoning] ,
242+ signature,
243+ } ) ) ) ) ,
244+ RawStreamingChoice :: ReasoningDelta { id, reasoning } => {
235245 // Forward the streaming tokens to the outer stream
236246 // and concat the text together
237247 stream. reasoning = format ! ( "{}{}" , stream. reasoning, reasoning) ;
238- Poll :: Ready ( Some ( Ok ( StreamedAssistantContent :: Reasoning ( Reasoning {
248+ Poll :: Ready ( Some ( Ok ( StreamedAssistantContent :: ReasoningDelta {
239249 id,
240- reasoning : vec ! [ reasoning] ,
241- signature,
242- } ) ) ) )
250+ reasoning,
251+ } ) ) )
243252 }
244253 RawStreamingChoice :: ToolCall {
245254 id,
@@ -362,6 +371,12 @@ impl<R: Clone + Unpin + GetTokenUsage> Stream for StreamingResultDyn<R> {
362371 reasoning,
363372 signature,
364373 } ) ) ) ,
374+ RawStreamingChoice :: ReasoningDelta { id, reasoning } => {
375+ Poll :: Ready ( Some ( Ok ( RawStreamingChoice :: ReasoningDelta {
376+ id,
377+ reasoning,
378+ } ) ) )
379+ }
365380 RawStreamingChoice :: ToolCall {
366381 id,
367382 name,
@@ -514,6 +529,10 @@ mod tests {
514529 print ! ( "{reasoning}" ) ;
515530 std:: io:: Write :: flush ( & mut std:: io:: stdout ( ) ) . unwrap ( ) ;
516531 }
532+ Ok ( StreamedAssistantContent :: ReasoningDelta { reasoning, .. } ) => {
533+ println ! ( "Reasoning delta: {reasoning}" ) ;
534+ chunk_count += 1 ;
535+ }
517536 Err ( e) => {
518537 eprintln ! ( "Error: {e:?}" ) ;
519538 break ;
@@ -555,8 +574,15 @@ mod tests {
555574pub enum StreamedAssistantContent < R > {
556575 Text ( Text ) ,
557576 ToolCall ( ToolCall ) ,
558- ToolCallDelta { id : String , delta : String } ,
577+ ToolCallDelta {
578+ id : String ,
579+ delta : String ,
580+ } ,
559581 Reasoning ( Reasoning ) ,
582+ ReasoningDelta {
583+ id : Option < String > ,
584+ reasoning : String ,
585+ } ,
560586 Final ( R ) ,
561587}
562588
0 commit comments