-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/nuget/dotnet/DuckDB.NET.Data.Full…
…-0.9.0
- Loading branch information
Showing
62 changed files
with
838 additions
and
558 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
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
141 changes: 141 additions & 0 deletions
141
dotnet/src/Functions/Functions.UnitTests/SemanticFunctions/PromptTemplateConfigTests.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,141 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Text.Json; | ||
using Microsoft.SemanticKernel.Connectors.AI.OpenAI; | ||
using Microsoft.SemanticKernel.SemanticFunctions; | ||
using Xunit; | ||
|
||
namespace SemanticKernel.Functions.UnitTests.SemanticFunctions; | ||
|
||
public class PromptTemplateConfigTests | ||
{ | ||
[Fact] | ||
public void DeserializingDoNotExpectChatSystemPromptToExist() | ||
{ | ||
// Arrange | ||
string configPayload = @"{ | ||
""max_tokens"": 60, | ||
""temperature"": 0.5, | ||
""top_p"": 0.0, | ||
""presence_penalty"": 0.0, | ||
""frequency_penalty"": 0.0 | ||
}"; | ||
|
||
// Act | ||
var requestSettings = JsonSerializer.Deserialize<OpenAIRequestSettings>(configPayload); | ||
|
||
// Assert | ||
Assert.NotNull(requestSettings); | ||
Assert.NotNull(requestSettings.ChatSystemPrompt); | ||
Assert.Equal("Assistant is a large language model.", requestSettings.ChatSystemPrompt); | ||
} | ||
|
||
[Fact] | ||
public void DeserializingExpectChatSystemPromptToExists() | ||
{ | ||
// Arrange | ||
string configPayload = @"{ | ||
""max_tokens"": 60, | ||
""temperature"": 0.5, | ||
""top_p"": 0.0, | ||
""presence_penalty"": 0.0, | ||
""frequency_penalty"": 0.0, | ||
""chat_system_prompt"": ""I am a prompt"" | ||
}"; | ||
|
||
// Act | ||
var requestSettings = JsonSerializer.Deserialize<OpenAIRequestSettings>(configPayload); | ||
|
||
// Assert | ||
Assert.NotNull(requestSettings); | ||
Assert.NotNull(requestSettings.ChatSystemPrompt); | ||
Assert.Equal("I am a prompt", requestSettings.ChatSystemPrompt); | ||
} | ||
|
||
[Fact] | ||
public void DeserializingExpectMultipleModels() | ||
{ | ||
// Arrange | ||
string configPayload = @" | ||
{ | ||
""schema"": 1, | ||
""description"": """", | ||
""models"": | ||
[ | ||
{ | ||
""model_id"": ""gpt-4"", | ||
""max_tokens"": 200, | ||
""temperature"": 0.2, | ||
""top_p"": 0.0, | ||
""presence_penalty"": 0.0, | ||
""frequency_penalty"": 0.0, | ||
""stop_sequences"": | ||
[ | ||
""Human"", | ||
""AI"" | ||
] | ||
}, | ||
{ | ||
""model_id"": ""gpt-3.5_turbo"", | ||
""max_tokens"": 256, | ||
""temperature"": 0.3, | ||
""top_p"": 0.0, | ||
""presence_penalty"": 0.0, | ||
""frequency_penalty"": 0.0, | ||
""stop_sequences"": | ||
[ | ||
""Human"", | ||
""AI"" | ||
] | ||
} | ||
] | ||
} | ||
"; | ||
|
||
// Act | ||
var promptTemplateConfig = JsonSerializer.Deserialize<PromptTemplateConfig>(configPayload); | ||
|
||
// Assert | ||
Assert.NotNull(promptTemplateConfig); | ||
Assert.NotNull(promptTemplateConfig.ModelSettings); | ||
Assert.Equal(2, promptTemplateConfig.ModelSettings.Count); | ||
} | ||
|
||
[Fact] | ||
public void DeserializingExpectCompletion() | ||
{ | ||
// Arrange | ||
string configPayload = @" | ||
{ | ||
""schema"": 1, | ||
""description"": """", | ||
""models"": | ||
[ | ||
{ | ||
""model_id"": ""gpt-4"", | ||
""max_tokens"": 200, | ||
""temperature"": 0.2, | ||
""top_p"": 0.0, | ||
""presence_penalty"": 0.0, | ||
""frequency_penalty"": 0.0, | ||
""stop_sequences"": | ||
[ | ||
""Human"", | ||
""AI"" | ||
] | ||
} | ||
] | ||
} | ||
"; | ||
|
||
// Act | ||
var promptTemplateConfig = JsonSerializer.Deserialize<PromptTemplateConfig>(configPayload); | ||
|
||
// Assert | ||
Assert.NotNull(promptTemplateConfig); | ||
#pragma warning disable CS0618 // Ensure backward compatibility | ||
Assert.NotNull(promptTemplateConfig.Completion); | ||
Assert.Equal("gpt-4", promptTemplateConfig.Completion.ModelId); | ||
#pragma warning restore CS0618 // Ensure backward compatibility | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Linq; | ||
using Microsoft.SemanticKernel; | ||
using Xunit; | ||
|
||
namespace SemanticKernel.IntegrationTests.Plugins; | ||
public class SamplePluginsTests | ||
{ | ||
[Fact] | ||
public void CanLoadSamplePluginsRequestSettings() | ||
{ | ||
// Arrange | ||
var kernel = new KernelBuilder().Build(); | ||
|
||
// Act | ||
TestHelpers.ImportAllSamplePlugins(kernel); | ||
|
||
// Assert | ||
Assert.NotNull(kernel.Functions); | ||
var functionViews = kernel.Functions.GetFunctionViews(); | ||
Assert.NotNull(functionViews); | ||
Assert.Equal(48, functionViews.Count); // currently we have 48 sample plugin functions | ||
functionViews.ToList().ForEach(view => | ||
{ | ||
var function = kernel.Functions.GetFunction(view.PluginName, view.Name); | ||
Assert.NotNull(function); | ||
Assert.NotNull(function.RequestSettings); | ||
Assert.True(function.RequestSettings.ExtensionData.ContainsKey("max_tokens")); | ||
}); | ||
} | ||
|
||
[Fact] | ||
// Including this to ensure backward compatibility as tools like Prompt Factory still use the old format | ||
public void CanLoadSampleSkillsCompletions() | ||
{ | ||
// Arrange | ||
var kernel = new KernelBuilder().Build(); | ||
|
||
// Act | ||
TestHelpers.ImportAllSampleSkills(kernel); | ||
|
||
// Assert | ||
Assert.NotNull(kernel.Functions); | ||
var functionViews = kernel.Functions.GetFunctionViews(); | ||
Assert.NotNull(functionViews); | ||
Assert.Equal(48, functionViews.Count); // currently we have 48 sample plugin functions | ||
functionViews.ToList().ForEach(view => | ||
{ | ||
var function = kernel.Functions.GetFunction(view.PluginName, view.Name); | ||
Assert.NotNull(function); | ||
Assert.NotNull(function.RequestSettings); | ||
Assert.True(function.RequestSettings.ExtensionData.ContainsKey("max_tokens")); | ||
}); | ||
} | ||
} |
Oops, something went wrong.