Repository: microsoft/semantic-kernel
File: dotnet/src/Connectors/Connectors.AzureOpenAI/Core/AzureClientCore.ChatCompletion.cs (C#)

Code before:
            {
                throw new NotSupportedException("Failed to parse the provided audio options from JSON. Ensure the JSON structure matches ChatAudioOptions format.", ex);
            }
        }

        if (executionSettings.Audio is string audioOptionsString)
        {
            try
            {
                var result = ModelReaderWriter.Read<ChatAudioOptions>(BinaryData.FromString(audioOptionsString));
                if (result != null)
                {
                    return result;
                }
            }
            catch (Exception ex)
            {
                throw new NotSupportedException("Failed to parse the provided audio options from string. Ensure the string is valid JSON that matches ChatAudioOptions format.", ex);
            }
        }

        throw new NotSupportedException($"The provided audio options '{executionSettings.Audio?.GetType()}' is not supported.");
    }

    private static readonly ReadOnlyMemory<byte> s_newMaxTokenJsonPath = "$.max_completion_tokens"u8.ToArray();
    private static readonly ReadOnlyMemory<byte> s_oldMaxTokenJsonPath = "$.max_tokens"u8.ToArray();

    private static void SetMaxTokenPatchValues(ChatCompletionOptions options, bool? newPropertyRequested = null)
    {
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
        bool newPropertyInUse = options.Patch.Contains(s_newMaxTokenJsonPath.Span) && !options.Patch.IsRemoved(s_newMaxTokenJsonPath.Span);
        bool useNewProperty = newPropertyRequested ?? newPropertyInUse;

        ReadOnlySpan<byte> selectedPath = useNewProperty ? s_newMaxTokenJsonPath.Span : s_oldMaxTokenJsonPath.Span;
        ReadOnlySpan<byte> deselectedPath = useNewProperty ? s_oldMaxTokenJsonPath.Span : s_newMaxTokenJsonPath.Span;

        BinaryData? valueBytes = options.MaxOutputTokenCount is null
            ? null
            : BinaryData.FromString(options.MaxOutputTokenCount.ToString()!);

        if (valueBytes is null)
        {
            options.Patch.Remove(selectedPath);
        }
        else
        {
            options.Patch.Set(selectedPath, valueBytes);
        }
        options.Patch.Remove(deselectedPath);
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
    }

Review comment (suggestion):
These would be better as spans, without going through arrays, since all call sites are just using spans, e.g.
```csharp
    private static ReadOnlySpan<byte> NewMaxTokenJsonPath = "$.max_completion_tokens"u8;
    private static ReadOnlySpan<byte> OldMaxTokenJsonPath = "$.max_tokens"u8;
```

Code after:
            }
            catch (Exception ex)
            {
                throw new NotSupportedException("Failed to parse the provided audio options from JSON. Ensure the JSON structure matches ChatAudioOptions format.", ex);
            }
        }

        if (executionSettings.Audio is string audioOptionsString)
        {
            try
            {
                var result = ModelReaderWriter.Read<ChatAudioOptions>(BinaryData.FromString(audioOptionsString));
                if (result != null)
                {
                    return result;
                }
            }
            catch (Exception ex)
            {
                throw new NotSupportedException("Failed to parse the provided audio options from string. Ensure the string is valid JSON that matches ChatAudioOptions format.", ex);
            }
        }

        throw new NotSupportedException($"The provided audio options '{executionSettings.Audio?.GetType()}' is not supported.");
    }
}