From 259c58cc05134b8fe63e3b21b4e98849bf3f6183 Mon Sep 17 00:00:00 2001 From: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> Date: Tue, 12 Nov 2024 07:48:05 -0800 Subject: [PATCH] .Net: Removed obsolete filter classes (#9426) ### Motivation and Context This PR removes obsolete filter classes for function invocation and prompt filtering. They became obsolete a while ago and they are not used in Kernel logic anymore. ### 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: --- .../CompatibilitySuppressions.xml | 88 +++++++++++++++++++ .../Filters/Function/FunctionFilterContext.cs | 58 ------------ .../Function/FunctionInvokedContext.cs | 45 ---------- .../Function/FunctionInvokingContext.cs | 24 ----- .../Filters/Prompt/PromptFilterContext.cs | 46 ---------- .../Filters/Prompt/PromptRenderedContext.cs | 60 ------------- .../Filters/Prompt/PromptRenderingContext.cs | 24 ----- 7 files changed, 88 insertions(+), 257 deletions(-) create mode 100644 dotnet/src/SemanticKernel.Abstractions/CompatibilitySuppressions.xml delete mode 100644 dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionFilterContext.cs delete mode 100644 dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvokedContext.cs delete mode 100644 dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvokingContext.cs delete mode 100644 dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptFilterContext.cs delete mode 100644 dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderedContext.cs delete mode 100644 dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderingContext.cs diff --git a/dotnet/src/SemanticKernel.Abstractions/CompatibilitySuppressions.xml b/dotnet/src/SemanticKernel.Abstractions/CompatibilitySuppressions.xml new file mode 100644 index 000000000000..92e89c1bdd62 --- /dev/null +++ b/dotnet/src/SemanticKernel.Abstractions/CompatibilitySuppressions.xml @@ -0,0 +1,88 @@ + + + + + CP0001 + T:Microsoft.SemanticKernel.FunctionFilterContext + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.FunctionInvokedContext + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.FunctionInvokingContext + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.PromptFilterContext + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.PromptRenderedContext + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.PromptRenderingContext + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + lib/net8.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.FunctionFilterContext + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.FunctionInvokedContext + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.FunctionInvokingContext + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.PromptFilterContext + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.PromptRenderedContext + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + true + + + CP0001 + T:Microsoft.SemanticKernel.PromptRenderingContext + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + lib/netstandard2.0/Microsoft.SemanticKernel.Abstractions.dll + true + + \ No newline at end of file diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionFilterContext.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionFilterContext.cs deleted file mode 100644 index 17b43d54d706..000000000000 --- a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionFilterContext.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; - -namespace Microsoft.SemanticKernel; - -/// -/// Base class with data related to function invocation. -/// -[Experimental("SKEXP0001")] -[Obsolete("This class is deprecated in favor of FunctionInvocationContext class, which is used in IFunctionInvocationFilter interface.")] -public abstract class FunctionFilterContext -{ - /// - /// Initializes a new instance of the class. - /// - /// The with which this filter is associated. - /// The arguments associated with the operation. - /// A dictionary of metadata associated with the operation. - internal FunctionFilterContext(KernelFunction function, KernelArguments arguments, IReadOnlyDictionary? metadata) - { - Verify.NotNull(function); - Verify.NotNull(arguments); - - this.Function = function; - this.Arguments = arguments; - this.Metadata = metadata; - } - - /// - /// Gets the with which this filter is associated. - /// - public KernelFunction Function { get; } - - /// - /// Gets the arguments associated with the operation. - /// - public KernelArguments Arguments { get; } - - /// - /// Gets a dictionary of metadata associated with the operation. - /// - public IReadOnlyDictionary? Metadata { get; } - - /// - /// Gets or sets a value indicating whether the operation associated with - /// the filter should be canceled. - /// - /// - /// The filter may set to true to indicate that the operation should - /// be canceled. If there are multiple filters registered, subsequent filters - /// may see and change a value set by a previous filter. The final result is what will - /// be considered by the component that triggers filter. - /// - public bool Cancel { get; set; } -} diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvokedContext.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvokedContext.cs deleted file mode 100644 index c7359c77f075..000000000000 --- a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvokedContext.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Diagnostics.CodeAnalysis; - -namespace Microsoft.SemanticKernel; - -/// -/// Class with data related to function after invocation. -/// -[Experimental("SKEXP0001")] -[Obsolete("This class is deprecated in favor of FunctionInvocationContext class, which is used in IFunctionInvocationFilter interface.")] -public sealed class FunctionInvokedContext : FunctionFilterContext -{ - /// - /// Initializes a new instance of the class. - /// - /// The arguments associated with the operation. - /// The result of the function's invocation. - public FunctionInvokedContext(KernelArguments arguments, FunctionResult result) - : base(result.Function, arguments, (result ?? throw new ArgumentNullException(nameof(result))).Metadata) - { - this.Result = result; - this.ResultValue = result.Value; - } - - /// - /// Gets the result of the function's invocation. - /// - public FunctionResult Result { get; } - - /// - /// Gets the raw result of the function's invocation. - /// - internal object? ResultValue { get; private set; } - - /// - /// Sets an object to use as the overridden new result for the function's invocation. - /// - /// The value to use as the new result of the function's invocation. - public void SetResultValue(object? value) - { - this.ResultValue = value; - } -} diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvokingContext.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvokingContext.cs deleted file mode 100644 index cdab1e02c3f5..000000000000 --- a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvokingContext.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Diagnostics.CodeAnalysis; - -namespace Microsoft.SemanticKernel; - -/// -/// Class with data related to function before invocation. -/// -[Experimental("SKEXP0001")] -[Obsolete("This class is deprecated in favor of FunctionInvocationContext class, which is used in IFunctionInvocationFilter interface.")] -public sealed class FunctionInvokingContext : FunctionFilterContext -{ - /// - /// Initializes a new instance of the class. - /// - /// The with which this filter is associated. - /// The arguments associated with the operation. - public FunctionInvokingContext(KernelFunction function, KernelArguments arguments) - : base(function, arguments, metadata: null) - { - } -} diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptFilterContext.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptFilterContext.cs deleted file mode 100644 index 8f4a61ce7b2b..000000000000 --- a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptFilterContext.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; - -namespace Microsoft.SemanticKernel; - -/// -/// Base class with data related to prompt rendering. -/// -[Experimental("SKEXP0001")] -[Obsolete("This class is deprecated in favor of PromptRenderContext class, which is used in IPromptRenderFilter interface.")] -public abstract class PromptFilterContext -{ - /// - /// Initializes a new instance of the class. - /// - /// The with which this filter is associated. - /// The arguments associated with the operation. - /// A dictionary of metadata associated with the operation. - internal PromptFilterContext(KernelFunction function, KernelArguments arguments, IReadOnlyDictionary? metadata) - { - Verify.NotNull(function); - Verify.NotNull(arguments); - - this.Function = function; - this.Arguments = arguments; - this.Metadata = metadata; - } - - /// - /// Gets the with which this filter is associated. - /// - public KernelFunction Function { get; } - - /// - /// Gets the arguments associated with the operation. - /// - public KernelArguments Arguments { get; } - - /// - /// Gets a dictionary of metadata associated with the operation. - /// - public IReadOnlyDictionary? Metadata { get; } -} diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderedContext.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderedContext.cs deleted file mode 100644 index 5c87b24fcce5..000000000000 --- a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderedContext.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Diagnostics.CodeAnalysis; - -namespace Microsoft.SemanticKernel; - -/// -/// Class with data related to prompt after rendering. -/// -[Experimental("SKEXP0001")] -[Obsolete("This class is deprecated in favor of PromptRenderContext class, which is used in IPromptRenderFilter interface.")] -public sealed class PromptRenderedContext : PromptFilterContext -{ - private string _renderedPrompt; - - /// - /// Initializes a new instance of the class. - /// - /// The with which this filter is associated. - /// The arguments associated with the operation. - /// The prompt that was rendered by the associated operation. - public PromptRenderedContext(KernelFunction function, KernelArguments arguments, string renderedPrompt) - : base(function, arguments, metadata: null) - { - this.RenderedPrompt = renderedPrompt; - } - - /// - /// Gets or sets a value indicating whether the operation associated with - /// the filter should be canceled. - /// - /// - /// The filter may set to true to indicate that the operation should - /// be canceled. If there are multiple filters registered, subsequent filters - /// may see and change a value set by a previous filter. The final result is what will - /// be considered by the component that triggers filter. - /// - public bool Cancel { get; set; } - - /// - /// Gets or sets the rendered prompt. - /// - /// - /// The filter may view the rendered prompt and change it, if desired. - /// If there are multiple filters registered, subsequent filters may - /// overwrite a value set by a previous filter. The final result is what will - /// be the prompt used by the system. - /// - public string RenderedPrompt - { - get => this._renderedPrompt; - [MemberNotNull(nameof(_renderedPrompt))] - set - { - Verify.NotNullOrWhiteSpace(value); - this._renderedPrompt = value; - } - } -} diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderingContext.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderingContext.cs deleted file mode 100644 index 93e707d1158f..000000000000 --- a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderingContext.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Diagnostics.CodeAnalysis; - -namespace Microsoft.SemanticKernel; - -/// -/// Class with data related to prompt before rendering. -/// -[Experimental("SKEXP0001")] -[Obsolete("This class is deprecated in favor of PromptRenderContext class, which is used in IPromptRenderFilter interface.")] -public sealed class PromptRenderingContext : PromptFilterContext -{ - /// - /// Initializes a new instance of the class. - /// - /// The with which this filter is associated. - /// The arguments associated with the operation. - public PromptRenderingContext(KernelFunction function, KernelArguments arguments) - : base(function, arguments, metadata: null) - { - } -}