From 3f78bc77e5b9032e57bb193c400f423020a9a95d Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 24 Oct 2024 15:10:11 -0400 Subject: [PATCH 1/2] Workaround fixed bug in System.Memory.Data BinaryData had a bug in its ToString that would throw an exception if _bytes was empty. That was fixed several years ago, but Azure SDK libraries are still referencing older versions of System.Memory.Data that don't have the fix. --- .../Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs b/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs index ab035aa327b..6e7f015d1ae 100644 --- a/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs +++ b/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs @@ -264,9 +264,10 @@ public async IAsyncEnumerable CompleteStreamingAs existing.CallId ??= toolCallUpdate.ToolCallId; existing.Name ??= toolCallUpdate.FunctionName; - if (toolCallUpdate.FunctionArgumentsUpdate is not null) + if (toolCallUpdate.FunctionArgumentsUpdate is { } update && + update.ToMemory().Length != 0) // workaround for https://github.com/dotnet/runtime/issues/68262 in 6.0.0 package { - _ = (existing.Arguments ??= new()).Append(toolCallUpdate.FunctionArgumentsUpdate); + _ = (existing.Arguments ??= new()).Append(update.ToString()); } } } From a48b840f528129aafd783607573052cb847542e4 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 24 Oct 2024 15:39:38 -0400 Subject: [PATCH 2/2] Add pragma warning and update condition check --- .../Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs b/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs index 6e7f015d1ae..935bb88f812 100644 --- a/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs +++ b/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; @@ -17,6 +17,7 @@ #pragma warning disable S1135 // Track uses of "TODO" tags #pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields #pragma warning disable SA1204 // Static elements should appear before instance elements +#pragma warning disable SA1108 // Block statements should not contain embedded comments namespace Microsoft.Extensions.AI; @@ -265,7 +266,7 @@ public async IAsyncEnumerable CompleteStreamingAs existing.CallId ??= toolCallUpdate.ToolCallId; existing.Name ??= toolCallUpdate.FunctionName; if (toolCallUpdate.FunctionArgumentsUpdate is { } update && - update.ToMemory().Length != 0) // workaround for https://github.com/dotnet/runtime/issues/68262 in 6.0.0 package + !update.ToMemory().IsEmpty) // workaround for https://github.com/dotnet/runtime/issues/68262 in 6.0.0 package { _ = (existing.Arguments ??= new()).Append(update.ToString()); }