-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Test execution settings compatibility (#7337)
### Motivation, Context and Description This PR adds a test that verifies the `OpenAIPromptExecutionSettings.FromExecutionSettings` method can handle arguments of type `AzureOpenAIPromptExecutionSettings`. Additionally, it fixes the issue found by @crickman when the `AzureOpenAIChatCompletionService.GetChatMessageContentsAsync` method is called with `OpenAIPromptExecutionSettings` instead of `AzureOpenAIPromptExecutionSettings`. Closes #7110
- Loading branch information
1 parent
3b8e54f
commit d436430
Showing
4 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...onnectors/Connectors.AzureOpenAI.UnitTests/Settings/OpenAIPromptExecutionSettingsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Azure.AI.OpenAI.Chat; | ||
using Microsoft.SemanticKernel.Connectors.AzureOpenAI; | ||
using Microsoft.SemanticKernel.Connectors.OpenAI; | ||
|
||
namespace SemanticKernel.Connectors.AzureOpenAI.UnitTests.Settings; | ||
|
||
/// <summary> | ||
/// Unit tests for <see cref="OpenAIPromptExecutionSettingsTests"/> class. | ||
/// </summary> | ||
public class OpenAIPromptExecutionSettingsTests | ||
{ | ||
[Fact] | ||
public void ItCanCreateOpenAIPromptExecutionSettingsFromAzureOpenAIPromptExecutionSettings() | ||
{ | ||
// Arrange | ||
AzureOpenAIPromptExecutionSettings originalSettings = new() | ||
{ | ||
Temperature = 0.7, | ||
TopP = 0.7, | ||
FrequencyPenalty = 0.7, | ||
PresencePenalty = 0.7, | ||
StopSequences = new string[] { "foo", "bar" }, | ||
ChatSystemPrompt = "chat system prompt", | ||
TokenSelectionBiases = new Dictionary<int, int>() { { 1, 2 }, { 3, 4 } }, | ||
MaxTokens = 128, | ||
Logprobs = true, | ||
Seed = 123456, | ||
TopLogprobs = 5, | ||
AzureChatDataSource = new AzureSearchChatDataSource | ||
{ | ||
Endpoint = new Uri("https://test-host"), | ||
Authentication = DataSourceAuthentication.FromApiKey("api-key"), | ||
IndexName = "index-name" | ||
} | ||
}; | ||
|
||
// Act | ||
OpenAIPromptExecutionSettings executionSettings = OpenAIPromptExecutionSettings.FromExecutionSettings(originalSettings); | ||
|
||
// Assert | ||
AssertExecutionSettings(executionSettings); | ||
} | ||
|
||
private static void AssertExecutionSettings(OpenAIPromptExecutionSettings executionSettings) | ||
{ | ||
Assert.NotNull(executionSettings); | ||
Assert.Equal(0.7, executionSettings.Temperature); | ||
Assert.Equal(0.7, executionSettings.TopP); | ||
Assert.Equal(0.7, executionSettings.FrequencyPenalty); | ||
Assert.Equal(0.7, executionSettings.PresencePenalty); | ||
Assert.Equal(new string[] { "foo", "bar" }, executionSettings.StopSequences); | ||
Assert.Equal("chat system prompt", executionSettings.ChatSystemPrompt); | ||
Assert.Equal(new Dictionary<int, int>() { { 1, 2 }, { 3, 4 } }, executionSettings.TokenSelectionBiases); | ||
Assert.Equal(128, executionSettings.MaxTokens); | ||
Assert.Equal(123456, executionSettings.Seed); | ||
Assert.Equal(true, executionSettings.Logprobs); | ||
Assert.Equal(5, executionSettings.TopLogprobs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters