File tree Expand file tree Collapse file tree
src/GenerativeAI.Microsoft/Extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -405,9 +405,18 @@ public static ChatResponseUpdate ToChatResponseUpdate(this GenerateContentRespon
405405
406406 if ( response . Candidates != null )
407407 {
408+ var contents = response . Candidates . Select ( s => s . Content ) . SelectMany ( s => s ? . Parts ?? new List < Part > ( ) ) . ToList ( ) . ToAiContents ( options ) ;
409+
410+ // Add usage information as UsageContent so it gets aggregated by the framework
411+ var usage = ParseContentResponseUsage ( response ) ;
412+ if ( usage != null )
413+ {
414+ contents . Add ( new UsageContent ( usage ) ) ;
415+ }
416+
408417 return new ChatResponseUpdate
409418 {
410- Contents = response . Candidates . Select ( s => s . Content ) . SelectMany ( s => s ? . Parts ?? new List < Part > ( ) ) . ToList ( ) . ToAiContents ( options ) ,
419+ Contents = contents ,
411420 AdditionalProperties = null ,
412421 FinishReason = response ? . Candidates ? . FirstOrDefault ( ) ? . FinishReason == FinishReason . OTHER
413422 ? ChatFinishReason . Stop
You can’t perform that action at this time.
0 commit comments