-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: make planner constructors more similar (#2849)
### Motivation and Context Fixes #2847, #2519 Contains breaking changes. This addresses inconsistencies in planner construction. The planners sometimes took a prompt override through a delegate in the config and sometimes as a constructor argument. Additionally, the ActionPlanner used to take a loggerFactory as a constructor argument while the other planners did not. The goal of these changes is to make working with planners more predictable. ### Description * Added `GetPromptTemplate` delegate function to the planner base config. All planners will use this to get the prompt override. * Removed logger factory argument from ActionPlanner constructor. Used the Kernel's logger factory to create a new logger within each planner constructor. * Renamed private `Config` private instance field to `_config` ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [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 - [ ] I didn't break anyone 😄 --------- Co-authored-by: Shawn Callegari <36091529+shawncal@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
95 additions
and
26 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
32 changes: 32 additions & 0 deletions
32
dotnet/src/Extensions/Extensions.UnitTests/Planning/StepwisePlanner/StepwisePlannerTests.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,32 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Planning.Stepwise; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace SemanticKernel.Extensions.UnitTests.Planning.StepwisePlanner; | ||
|
||
public sealed class StepwisePlannerTests | ||
{ | ||
[Fact] | ||
public void UsesPromptDelegateWhenProvided() | ||
{ | ||
// Arrange | ||
var kernel = new Mock<IKernel>(); | ||
kernel.Setup(x => x.LoggerFactory).Returns(NullLoggerFactory.Instance); | ||
var getPromptTemplateMock = new Mock<Func<string>>(); | ||
var config = new StepwisePlannerConfig() | ||
{ | ||
GetPromptTemplate = getPromptTemplateMock.Object | ||
}; | ||
|
||
// Act | ||
var planner = new Microsoft.SemanticKernel.Planning.StepwisePlanner(kernel.Object, config); | ||
|
||
// Assert | ||
getPromptTemplateMock.Verify(x => x(), Times.Once()); | ||
} | ||
} |
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
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