Skip to content

Commit

Permalink
.Net: Removed experimental flags in Filters (#9774)
Browse files Browse the repository at this point in the history
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Closes: #9499

1. Removed `Experimental` flag from `AutoFunctionInvocationFilter`
classes and properties.
2. Removed `Experimental` flag from `IsStreaming` boolean property in
filter context models.
3. Added a unit test to verify function sequence index property
behavior.

### 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
- [x] I didn't break anyone 😄
  • Loading branch information
dmytrostruk authored Nov 21, 2024
1 parent 6cc6822 commit d8acb75
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ public async Task FiltersAreExecutedCorrectlyAsync()
Assert.Equal("Test chat response", result.ToString());
}

[Fact]
public async Task FunctionSequenceIndexIsCorrectForConcurrentCallsAsync()
{
// Arrange
List<int> functionSequenceNumbers = [];
List<int> expectedFunctionSequenceNumbers = [0, 1, 0, 1];

var function1 = KernelFunctionFactory.CreateFromMethod((string parameter) => { return parameter; }, "Function1");
var function2 = KernelFunctionFactory.CreateFromMethod((string parameter) => { return parameter; }, "Function2");

var plugin = KernelPluginFactory.CreateFromFunctions("MyPlugin", [function1, function2]);

var kernel = this.GetKernelWithFilter(plugin, async (context, next) =>
{
functionSequenceNumbers.Add(context.FunctionSequenceIndex);
await next(context);
});

this._messageHandlerStub.ResponsesToReturn = GetFunctionCallingResponses();

// Act
var result = await kernel.InvokePromptAsync("Test prompt", new(new OpenAIPromptExecutionSettings
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(options: new()
{
AllowParallelCalls = true,
AllowConcurrentInvocation = true
})
}));

// Assert
Assert.Equal(expectedFunctionSequenceNumbers, functionSequenceNumbers);
}

[Fact]
public async Task FiltersAreExecutedCorrectlyOnStreamingAsync()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Microsoft.SemanticKernel.ChatCompletion;

Expand All @@ -9,7 +8,6 @@ namespace Microsoft.SemanticKernel;
/// <summary>
/// Class with data related to automatic function invocation.
/// </summary>
[Experimental("SKEXP0001")]
public class AutoFunctionInvocationContext
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace Microsoft.SemanticKernel;
Expand All @@ -11,7 +10,6 @@ namespace Microsoft.SemanticKernel;
/// <summary>
/// Interface for filtering actions during automatic function invocation.
/// </summary>
[Experimental("SKEXP0001")]
public interface IAutoFunctionInvocationFilter
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Diagnostics.CodeAnalysis;
using System.Threading;

namespace Microsoft.SemanticKernel;
Expand Down Expand Up @@ -38,7 +37,6 @@ internal FunctionInvocationContext(Kernel kernel, KernelFunction function, Kerne
/// <summary>
/// Boolean flag which indicates whether a filter is invoked within streaming or non-streaming mode.
/// </summary>
[Experimental("SKEXP0001")]
public bool IsStreaming { get; init; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Diagnostics.CodeAnalysis;
using System.Threading;

namespace Microsoft.SemanticKernel;

/// <summary>
Expand Down Expand Up @@ -37,7 +37,6 @@ internal PromptRenderContext(Kernel kernel, KernelFunction function, KernelArgum
/// <summary>
/// Boolean flag which indicates whether a filter is invoked within streaming or non-streaming mode.
/// </summary>
[Experimental("SKEXP0001")]
public bool IsStreaming { get; init; }

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion dotnet/src/SemanticKernel.Abstractions/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public Kernel Clone() =>
/// <summary>
/// Gets the collection of auto function invocation filters available through the kernel.
/// </summary>
[Experimental("SKEXP0001")]
public IList<IAutoFunctionInvocationFilter> AutoFunctionInvocationFilters =>
this._autoFunctionInvocationFilters ??
Interlocked.CompareExchange(ref this._autoFunctionInvocationFilters, [], null) ??
Expand Down

0 comments on commit d8acb75

Please sign in to comment.