7 writes to Usage
Microsoft.Extensions.AI (2)
ChatCompletion\ChatCompletion{T}.cs (1)
41Usage = completion.Usage;
ChatCompletion\FunctionInvokingChatClient.cs (1)
303response.Usage = totalUsage;
Microsoft.Extensions.AI.Abstractions (1)
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (1)
188completion.Usage = c.Details;
Microsoft.Extensions.AI.Abstractions.Tests (1)
ChatCompletion\ChatCompletionTests.cs (1)
107completion.Usage = usage;
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
142Usage = usage,
Microsoft.Extensions.AI.OpenAI.Tests (1)
OpenAISerializationTests.cs (1)
458Usage = new()
Microsoft.Extensions.AI.Tests (1)
ChatCompletion\FunctionInvokingChatClientTests.cs (1)
582return new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])) { Usage = usage };
55 references to Usage
Microsoft.Extensions.AI (6)
ChatCompletion\ChatCompletion{T}.cs (1)
41Usage = completion.Usage;
ChatCompletion\FunctionInvokingChatClient.cs (2)
211if (response.Usage is not null) 214totalUsage.Add(response.Usage);
ChatCompletion\OpenTelemetryChatClient.cs (3)
334if (_tokenUsageHistogram.Enabled && completion?.Usage is { } usage) 383if (completion.Usage?.InputTokenCount is int inputTokens) 388if (completion.Usage?.OutputTokenCount is int outputTokens)
Microsoft.Extensions.AI.Abstractions (3)
ChatCompletion\ChatCompletion.cs (2)
115if (AdditionalProperties is not null || Usage is not null) 122if (Usage is { } usage)
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (1)
182if (completion.Usage is null)
Microsoft.Extensions.AI.Abstractions.Tests (6)
ChatCompletion\ChatCompletionTests.cs (3)
105Assert.Null(completion.Usage); 108Assert.Same(usage, completion.Usage); 162Assert.NotNull(result.Usage);
ChatCompletion\StreamingChatCompletionUpdateExtensionsTests.cs (3)
67Assert.Same(Assert.IsType<UsageContent>(updates[6].Contents[0]).Details, completion.Usage); 206Assert.NotNull(completion.Usage); 207Assert.Equal(42, completion.Usage.TotalTokenCount);
Microsoft.Extensions.AI.AzureAIInference.Tests (8)
AzureAIInferenceChatClientTests.cs (8)
168Assert.NotNull(response.Usage); 169Assert.Equal(8, response.Usage.InputTokenCount); 170Assert.Equal(9, response.Usage.OutputTokenCount); 171Assert.Equal(17, response.Usage.TotalTokenCount); 666Assert.NotNull(response.Usage); 667Assert.Equal(42, response.Usage.InputTokenCount); 668Assert.Equal(15, response.Usage.OutputTokenCount); 669Assert.Equal(57, response.Usage.TotalTokenCount);
Microsoft.Extensions.AI.Integration.Tests (5)
ChatClientIntegrationTests.cs (5)
105Assert.True(response.Usage?.InputTokenCount > 1); 106Assert.True(response.Usage?.OutputTokenCount > 1); 107Assert.Equal(response.Usage?.InputTokenCount + response.Usage?.OutputTokenCount, response.Usage?.TotalTokenCount);
Microsoft.Extensions.AI.Ollama.Tests (4)
OllamaChatClientTests.cs (4)
126Assert.NotNull(response.Usage); 127Assert.Equal(11, response.Usage.InputTokenCount); 128Assert.Equal(10, response.Usage.OutputTokenCount); 129Assert.Equal(21, response.Usage.TotalTokenCount);
Microsoft.Extensions.AI.OpenAI (1)
OpenAIModelMapper.ChatCompletion.cs (1)
51if (chatCompletion.Usage is UsageDetails usageDetails)
Microsoft.Extensions.AI.OpenAI.Tests (20)
OpenAIChatClientTests.cs (20)
198Assert.NotNull(response.Usage); 199Assert.Equal(8, response.Usage.InputTokenCount); 200Assert.Equal(9, response.Usage.OutputTokenCount); 201Assert.Equal(17, response.Usage.TotalTokenCount); 208}, response.Usage.AdditionalCounts); 545Assert.NotNull(response.Usage); 546Assert.Equal(42, response.Usage.InputTokenCount); 547Assert.Equal(15, response.Usage.OutputTokenCount); 548Assert.Equal(57, response.Usage.TotalTokenCount); 555}, response.Usage.AdditionalCounts); 644Assert.NotNull(response.Usage); 645Assert.Equal(42, response.Usage.InputTokenCount); 646Assert.Equal(15, response.Usage.OutputTokenCount); 647Assert.Equal(57, response.Usage.TotalTokenCount); 654}, response.Usage.AdditionalCounts); 1015Assert.NotNull(response.Usage); 1016Assert.Equal(42, response.Usage.InputTokenCount); 1017Assert.Equal(15, response.Usage.OutputTokenCount); 1018Assert.Equal(57, response.Usage.TotalTokenCount); 1025}, response.Usage.AdditionalCounts);
Microsoft.Extensions.AI.Tests (2)
ChatCompletion\ChatClientStructuredOutputExtensionsTests.cs (1)
67Assert.Same(expectedCompletion.Usage, response.Usage);
ChatCompletion\FunctionInvokingChatClientTests.cs (1)
626var actualUsage = result.Usage!;