1111using Microsoft . Extensions . Logging ;
1212using Microsoft . KernelMemory . AI . AzureOpenAI . Internals ;
1313using Microsoft . KernelMemory . Diagnostics ;
14- using Microsoft . KernelMemory . Models ;
1514using Microsoft . SemanticKernel ;
1615using Microsoft . SemanticKernel . Connectors . AzureOpenAI ;
1716using OpenAI . Chat ;
@@ -120,7 +119,7 @@ public IReadOnlyList<string> GetTokens(string text)
120119 }
121120
122121 /// <inheritdoc/>
123- public async IAsyncEnumerable < Models . TextContent > GenerateTextAsync (
122+ public async IAsyncEnumerable < GeneratedTextContent > GenerateTextAsync (
124123 string prompt ,
125124 TextGenerationOptions options ,
126125 [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
@@ -161,11 +160,11 @@ public IReadOnlyList<string> GetTokens(string text)
161160 {
162161 TokenUsage ? tokenUsage = null ;
163162
164- // The last message in the chunk has the usage metadata.
163+ // The last message includes tokens usage metadata.
165164 // https://platform.openai.com/docs/api-reference/chat/create#chat-create-stream_options
166- if ( x . Metadata ? [ "Usage" ] is ChatTokenUsage { } usage )
165+ if ( x . Metadata ? [ "Usage" ] is ChatTokenUsage usage )
167166 {
168- this . _log . LogTrace ( "Usage report: input tokens {0 }, output tokens {1 }, output reasoning tokens {2 }" ,
167+ this . _log . LogTrace ( "Usage report: input tokens: {InputTokenCount }, output tokens: {OutputTokenCount }, output reasoning tokens: {ReasoningTokenCount }" ,
169168 usage . InputTokenCount , usage . OutputTokenCount , usage . OutputTokenDetails ? . ReasoningTokenCount ?? 0 ) ;
170169
171170 tokenUsage = new TokenUsage
@@ -181,7 +180,7 @@ public IReadOnlyList<string> GetTokens(string text)
181180 }
182181
183182 // NOTE: as stated at https://platform.openai.com/docs/api-reference/chat/streaming#chat/streaming-choices,
184- // The Choice can also be empty for the last chunk if we set stream_options: { "include_usage": true} to get token counts, so it is possible that
183+ // the Choice can also be empty for the last chunk if we set stream_options: { "include_usage": true} to get token counts, so it is possible that
185184 // x.Text is null, but tokenUsage is not (token usage statistics for the entire request are included in the last chunk).
186185 if ( x . Text is null && tokenUsage is null ) { continue ; }
187186
0 commit comments