From dcf682ebde9a659a7a7928ebfadc96f0cb67366f Mon Sep 17 00:00:00 2001 From: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:08:12 -0800 Subject: [PATCH] .Net: Upgraded OpenAI and Azure OpenAI package versions (#9651) ### Motivation and Context Changes in this PR: - OpenAI and Azure OpenAI package versions upgrade and fix for small breaking change in citation functionality described here: https://github.com/Azure/azure-sdk-for-net/blob/bdd48fdb11070045007fcdcea52381dc5f7eda02/sdk/openai/Azure.AI.OpenAI/CHANGELOG.md#breaking-changes-1 - Fix in Azure OpenAI unit tests - removed a test when `apiVersion` parameter is passed as `null`, since the default value is regularly changed on Azure OpenAI SDK side. Ideally, the default value behavior should be tested on Azure OpenAI SDK side, while our tests should verify that passed non-null value is used in final HTTP request address. New package versions give access to Realtime API functionality. ### Contribution Checklist - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone :smile: --- dotnet/Directory.Packages.props | 4 ++-- .../AzureOpenAIWithData_ChatCompletion.cs | 2 +- .../Services/AzureOpenAIAudioToTextServiceTests.cs | 1 - .../Services/AzureOpenAIChatCompletionServiceTests.cs | 1 - .../AzureOpenAITextEmbeddingGenerationServiceTests.cs | 1 - .../Services/AzureOpenAITextToAudioServiceTests.cs | 1 - .../Services/AzureOpenAITextToImageServiceTests.cs | 1 - .../AzureOpenAIChatCompletionStreamingTests.cs | 10 ++++++++-- 8 files changed, 11 insertions(+), 10 deletions(-) diff --git a/dotnet/Directory.Packages.props b/dotnet/Directory.Packages.props index 3a95386ab08a..d49a1750410f 100644 --- a/dotnet/Directory.Packages.props +++ b/dotnet/Directory.Packages.props @@ -16,9 +16,9 @@ - + - + diff --git a/dotnet/samples/Concepts/ChatCompletion/AzureOpenAIWithData_ChatCompletion.cs b/dotnet/samples/Concepts/ChatCompletion/AzureOpenAIWithData_ChatCompletion.cs index 8cab1da9df40..56dc76277d97 100644 --- a/dotnet/samples/Concepts/ChatCompletion/AzureOpenAIWithData_ChatCompletion.cs +++ b/dotnet/samples/Concepts/ChatCompletion/AzureOpenAIWithData_ChatCompletion.cs @@ -170,7 +170,7 @@ private void OutputCitations(IReadOnlyList citations) Console.WriteLine($"Chunk ID: {citation.ChunkId}"); Console.WriteLine($"Title: {citation.Title}"); Console.WriteLine($"File path: {citation.FilePath}"); - Console.WriteLine($"URI: {citation.Uri}"); + Console.WriteLine($"URL: {citation.Url}"); Console.WriteLine($"Content: {citation.Content}"); } } diff --git a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAIAudioToTextServiceTests.cs b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAIAudioToTextServiceTests.cs index 0090e37a22ad..05662a5706c8 100644 --- a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAIAudioToTextServiceTests.cs +++ b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAIAudioToTextServiceTests.cs @@ -221,7 +221,6 @@ public async Task GetTextContentGranularitiesWorksCorrectlyAsync(string[]? granu public static TheoryData Versions => new() { - { null, "2024-08-01-preview" }, { "V2024_10_01_preview", "2024-10-01-preview" }, { "V2024_10_01_PREVIEW", "2024-10-01-preview" }, { "2024_10_01_Preview", "2024-10-01-preview" }, diff --git a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAIChatCompletionServiceTests.cs b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAIChatCompletionServiceTests.cs index 074018f14fe6..0bf81dad8453 100644 --- a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAIChatCompletionServiceTests.cs +++ b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAIChatCompletionServiceTests.cs @@ -1537,7 +1537,6 @@ public async Task GetStreamingChatMessageContentsWithFunctionCallAndEmptyArgumen public static TheoryData Versions => new() { - { null, "2024-08-01-preview" }, { "V2024_10_01_preview", "2024-10-01-preview" }, { "V2024_10_01_PREVIEW", "2024-10-01-preview" }, { "2024_10_01_Preview", "2024-10-01-preview" }, diff --git a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextEmbeddingGenerationServiceTests.cs b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextEmbeddingGenerationServiceTests.cs index 31f267dd1daf..6dfc0cf9e68b 100644 --- a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextEmbeddingGenerationServiceTests.cs +++ b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextEmbeddingGenerationServiceTests.cs @@ -127,7 +127,6 @@ public async Task ItTargetsApiVersionAsExpected(string? apiVersion, string? expe public static TheoryData Versions => new() { - { null, "2024-08-01-preview" }, { "V2024_10_01_preview", "2024-10-01-preview" }, { "V2024_10_01_PREVIEW", "2024-10-01-preview" }, { "2024_10_01_Preview", "2024-10-01-preview" }, diff --git a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextToAudioServiceTests.cs b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextToAudioServiceTests.cs index f40bce5635a9..3ad42a32eac6 100644 --- a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextToAudioServiceTests.cs +++ b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextToAudioServiceTests.cs @@ -234,7 +234,6 @@ public async Task ItTargetsApiVersionAsExpected(string? apiVersion, string? expe public static TheoryData Versions => new() { - { null, "2024-08-01-preview" }, { "V2024_10_01_preview", "2024-10-01-preview" }, { "V2024_10_01_PREVIEW", "2024-10-01-preview" }, { "2024_10_01_Preview", "2024-10-01-preview" }, diff --git a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextToImageServiceTests.cs b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextToImageServiceTests.cs index 4a851a1ea542..d2c9e1081c45 100644 --- a/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextToImageServiceTests.cs +++ b/dotnet/src/Connectors/Connectors.AzureOpenAI.UnitTests/Services/AzureOpenAITextToImageServiceTests.cs @@ -361,7 +361,6 @@ public async Task ItTargetsApiVersionAsExpected(string? apiVersion, string? expe public static TheoryData Versions => new() { - { null, "2024-08-01-preview" }, { "V2024_10_01_preview", "2024-10-01-preview" }, { "V2024_10_01_PREVIEW", "2024-10-01-preview" }, { "2024_10_01_Preview", "2024-10-01-preview" }, diff --git a/dotnet/src/IntegrationTests/Connectors/AzureOpenAI/AzureOpenAIChatCompletionStreamingTests.cs b/dotnet/src/IntegrationTests/Connectors/AzureOpenAI/AzureOpenAIChatCompletionStreamingTests.cs index e59b33a05f82..1540ff288197 100644 --- a/dotnet/src/IntegrationTests/Connectors/AzureOpenAI/AzureOpenAIChatCompletionStreamingTests.cs +++ b/dotnet/src/IntegrationTests/Connectors/AzureOpenAI/AzureOpenAIChatCompletionStreamingTests.cs @@ -62,7 +62,10 @@ public async Task ChatCompletionShouldUseChatHistoryAndReturnMetadataAsync() foreach (var key in update.Metadata!.Keys) { - metadata[key] = update.Metadata[key]; + if (!metadata.TryGetValue(key, out object? value) || value is null) + { + metadata[key] = update.Metadata[key]; + } } } @@ -123,7 +126,10 @@ public async Task TextGenerationShouldReturnMetadataAsync() foreach (var key in update.Metadata!.Keys) { - metadata[key] = update.Metadata[key]; + if (!metadata.TryGetValue(key, out object? value) || value is null) + { + metadata[key] = update.Metadata[key]; + } } }