Skip to content

Commit

Permalink
Update OpenAI dependency to 2.1.0 (#5725)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Dec 6, 2024
1 parent af32f59 commit 953f93f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion eng/packages/General.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
<PackageVersion Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="OpenAI" Version="2.1.0-beta.2" />
<PackageVersion Include="OpenAI" Version="2.1.0" />
<PackageVersion Include="Polly" Version="8.4.2" />
<PackageVersion Include="Polly.Core" Version="8.4.2" />
<PackageVersion Include="Polly.Extensions" Version="8.4.2" />
<PackageVersion Include="Polly.RateLimiting" Version="8.4.2" />
<PackageVersion Include="System.Buffers" Version="4.5.1" />
<PackageVersion Include="System.ClientModel" Version="1.2.1" />
<PackageVersion Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
Expand Down
27 changes: 9 additions & 18 deletions src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,29 +356,20 @@ private static UsageDetails ToUsageDetails(ChatTokenUsage tokenUsage)

if (tokenUsage.InputTokenDetails is ChatInputTokenUsageDetails inputDetails)
{
if (inputDetails.AudioTokenCount is int audioTokenCount)
{
destination.AdditionalCounts.Add(
$"{nameof(ChatTokenUsage.InputTokenDetails)}.{nameof(ChatInputTokenUsageDetails.AudioTokenCount)}",
audioTokenCount);
}
destination.AdditionalCounts.Add(
$"{nameof(ChatTokenUsage.InputTokenDetails)}.{nameof(ChatInputTokenUsageDetails.AudioTokenCount)}",
inputDetails.AudioTokenCount);

if (inputDetails.CachedTokenCount is int cachedTokenCount)
{
destination.AdditionalCounts.Add(
$"{nameof(ChatTokenUsage.InputTokenDetails)}.{nameof(ChatInputTokenUsageDetails.CachedTokenCount)}",
cachedTokenCount);
}
destination.AdditionalCounts.Add(
$"{nameof(ChatTokenUsage.InputTokenDetails)}.{nameof(ChatInputTokenUsageDetails.CachedTokenCount)}",
inputDetails.CachedTokenCount);
}

if (tokenUsage.OutputTokenDetails is ChatOutputTokenUsageDetails outputDetails)
{
if (outputDetails.AudioTokenCount is int audioTokenCount)
{
destination.AdditionalCounts.Add(
$"{nameof(ChatTokenUsage.OutputTokenDetails)}.{nameof(ChatOutputTokenUsageDetails.AudioTokenCount)}",
audioTokenCount);
}
destination.AdditionalCounts.Add(
$"{nameof(ChatTokenUsage.OutputTokenDetails)}.{nameof(ChatOutputTokenUsageDetails.AudioTokenCount)}",
outputDetails.AudioTokenCount);

destination.AdditionalCounts.Add(
$"{nameof(ChatTokenUsage.OutputTokenDetails)}.{nameof(ChatOutputTokenUsageDetails.ReasoningTokenCount)}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ public async Task BasicRequestResponse_NonStreaming()
Assert.Equal(17, response.Usage.TotalTokenCount);
Assert.Equal(new Dictionary<string, long>
{
{ "InputTokenDetails.AudioTokenCount", 0 },
{ "InputTokenDetails.CachedTokenCount", 13 },
{ "OutputTokenDetails.AudioTokenCount", 0 },
{ "OutputTokenDetails.ReasoningTokenCount", 90 }
}, response.Usage.AdditionalCounts);

Expand Down Expand Up @@ -492,7 +494,9 @@ public async Task MultiPartSystemMessage_NonStreaming()
Assert.Equal(57, response.Usage.TotalTokenCount);
Assert.Equal(new Dictionary<string, long>
{
{ "InputTokenDetails.AudioTokenCount", 0 },
{ "InputTokenDetails.CachedTokenCount", 13 },
{ "OutputTokenDetails.AudioTokenCount", 0 },
{ "OutputTokenDetails.ReasoningTokenCount", 90 }
}, response.Usage.AdditionalCounts);

Expand Down Expand Up @@ -589,7 +593,9 @@ public async Task EmptyAssistantMessage_NonStreaming()
Assert.Equal(57, response.Usage.TotalTokenCount);
Assert.Equal(new Dictionary<string, long>
{
{ "InputTokenDetails.AudioTokenCount", 0 },
{ "InputTokenDetails.CachedTokenCount", 13 },
{ "OutputTokenDetails.AudioTokenCount", 0 },
{ "OutputTokenDetails.ReasoningTokenCount", 90 }
}, response.Usage.AdditionalCounts);

Expand Down Expand Up @@ -699,7 +705,9 @@ public async Task FunctionCallContent_NonStreaming()

Assert.Equal(new Dictionary<string, long>
{
{ "InputTokenDetails.AudioTokenCount", 0 },
{ "InputTokenDetails.CachedTokenCount", 13 },
{ "OutputTokenDetails.AudioTokenCount", 0 },
{ "OutputTokenDetails.ReasoningTokenCount", 90 }
}, response.Usage.AdditionalCounts);

Expand Down Expand Up @@ -817,7 +825,9 @@ public async Task FunctionCallContent_Streaming()

Assert.Equal(new Dictionary<string, long>
{
{ "InputTokenDetails.AudioTokenCount", 0 },
{ "InputTokenDetails.CachedTokenCount", 0 },
{ "OutputTokenDetails.AudioTokenCount", 0 },
{ "OutputTokenDetails.ReasoningTokenCount", 90 }
}, usage.Details.AdditionalCounts);
}
Expand Down Expand Up @@ -954,7 +964,9 @@ public async Task AssistantMessageWithBothToolsAndContent_NonStreaming()
Assert.Equal(57, response.Usage.TotalTokenCount);
Assert.Equal(new Dictionary<string, long>
{
{ "InputTokenDetails.AudioTokenCount", 0 },
{ "InputTokenDetails.CachedTokenCount", 20 },
{ "OutputTokenDetails.AudioTokenCount", 0 },
{ "OutputTokenDetails.ReasoningTokenCount", 90 }
}, response.Usage.AdditionalCounts);

Expand Down

0 comments on commit 953f93f

Please # to comment.