From 23f2dcec158d52e6758ed4a0056f2acf567ca5ba Mon Sep 17 00:00:00 2001
From: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
Date: Mon, 8 Jul 2024 08:08:17 -0700
Subject: [PATCH] .Net: Filters graduation (#7004)
### Motivation and Context
Resolves: https://github.com/microsoft/semantic-kernel/issues/5409
1. Removed experimental flags on `FunctionInvocationFilter` and
`PromptRenderFilter`.
2. Updated documentation.
### 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:
---
README.md | 2 +-
dotnet/docs/EXPERIMENTS.md | 92 +++++++++----------
.../{FrugalGPT.cs => FrugalGPTWithFilters.cs} | 2 +-
...ction.cs => PluginSelectionWithFilters.cs} | 6 +-
dotnet/samples/Concepts/README.md | 4 +-
.../Function/FunctionInvocationContext.cs | 2 -
.../Function/IFunctionInvocationFilter.cs | 2 -
.../Filters/Prompt/IPromptRenderFilter.cs | 2 -
.../Filters/Prompt/PromptRenderContext.cs | 3 -
.../src/SemanticKernel.Abstractions/Kernel.cs | 4 -
10 files changed, 53 insertions(+), 66 deletions(-)
rename dotnet/samples/Concepts/Optimization/{FrugalGPT.cs => FrugalGPTWithFilters.cs} (99%)
rename dotnet/samples/Concepts/Optimization/{PluginSelection.cs => PluginSelectionWithFilters.cs} (99%)
diff --git a/README.md b/README.md
index e8518c0ef1cf..29ad470876bd 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ is an SDK that integrates Large Language Models (LLMs) like
[Azure OpenAI](https://azure.microsoft.com/en-us/products/ai-services/openai-service),
and [Hugging Face](https://huggingface.co/)
with conventional programming languages like C#, Python, and Java. Semantic Kernel achieves this
-by allowing you to define [plugins](https://learn.microsoft.com/en-us/semantic-kernel/ai-orchestration/plugins)
+by allowing you to define [plugins](https://learn.microsoft.com/en-us/semantic-kernel/concepts/plugins)
that can be chained together
in just a [few lines of code](https://learn.microsoft.com/en-us/semantic-kernel/ai-orchestration/chaining-functions?tabs=Csharp#using-the-runasync-method-to-simplify-your-code).
diff --git a/dotnet/docs/EXPERIMENTS.md b/dotnet/docs/EXPERIMENTS.md
index 2be4606e5596..8cc9287ff55e 100644
--- a/dotnet/docs/EXPERIMENTS.md
+++ b/dotnet/docs/EXPERIMENTS.md
@@ -26,57 +26,57 @@ You can use the following diagnostic IDs to ignore warnings or errors for a part
## Experimental Features Tracking
-| SKEXP | Features | API docs | Learn docs | Samples | Issues | Implementations |
-|-------|----------|----------|------------|---------|--------|-----------------|
-| SKEXP0001 | Embedding services | | | | | |
-| SKEXP0001 | Image services | | | | | |
-| SKEXP0001 | Memory connectors | | | | | |
-| SKEXP0001 | Kernel filters | | | | | |
-| SKEXP0001 | Audio services | | | | | |
+| SKEXP | Features |
+|-------|----------|
+| SKEXP0001 | Embedding services |
+| SKEXP0001 | Image services |
+| SKEXP0001 | Memory connectors |
+| SKEXP0001 | Kernel filters |
+| SKEXP0001 | Audio services |
| | | | | | | |
-| SKEXP0010 | Azure OpenAI with your data service | | | | | |
-| SKEXP0010 | OpenAI embedding service | | | | | |
-| SKEXP0010 | OpenAI image service | | | | | |
-| SKEXP0010 | OpenAI parameters | | | | | |
-| SKEXP0010 | OpenAI chat history extension | | | | | |
-| SKEXP0010 | OpenAI file service | | | | | |
+| SKEXP0010 | Azure OpenAI with your data service |
+| SKEXP0010 | OpenAI embedding service |
+| SKEXP0010 | OpenAI image service |
+| SKEXP0010 | OpenAI parameters |
+| SKEXP0010 | OpenAI chat history extension |
+| SKEXP0010 | OpenAI file service |
| | | | | | | |
-| SKEXP0020 | Azure AI Search memory connector | | | | | |
-| SKEXP0020 | Chroma memory connector | | | | | |
-| SKEXP0020 | DuckDB memory connector | | | | | |
-| SKEXP0020 | Kusto memory connector | | | | | |
-| SKEXP0020 | Milvus memory connector | | | | | |
-| SKEXP0020 | Qdrant memory connector | | | | | |
-| SKEXP0020 | Redis memory connector | | | | | |
-| SKEXP0020 | Sqlite memory connector | | | | | |
-| SKEXP0020 | Weaviate memory connector | | | | | |
-| SKEXP0020 | MongoDB memory connector | | | | | |
-| SKEXP0020 | Pinecone memory connector | | | | | |
-| SKEXP0020 | Postgres memory connector | | | | | |
+| SKEXP0020 | Azure AI Search memory connector |
+| SKEXP0020 | Chroma memory connector |
+| SKEXP0020 | DuckDB memory connector |
+| SKEXP0020 | Kusto memory connector |
+| SKEXP0020 | Milvus memory connector |
+| SKEXP0020 | Qdrant memory connector |
+| SKEXP0020 | Redis memory connector |
+| SKEXP0020 | Sqlite memory connector |
+| SKEXP0020 | Weaviate memory connector |
+| SKEXP0020 | MongoDB memory connector |
+| SKEXP0020 | Pinecone memory connector |
+| SKEXP0020 | Postgres memory connector |
| | | | | | | |
-| SKEXP0040 | GRPC functions | | | | | |
-| SKEXP0040 | Markdown functions | | | | | |
-| SKEXP0040 | OpenAPI functions | | | | | |
-| SKEXP0040 | OpenAPI function extensions | | | | | |
-| SKEXP0040 | Prompty Format support | | | | | |
+| SKEXP0040 | GRPC functions |
+| SKEXP0040 | Markdown functions |
+| SKEXP0040 | OpenAPI functions |
+| SKEXP0040 | OpenAPI function extensions |
+| SKEXP0040 | Prompty Format support |
| | | | | | | |
-| SKEXP0050 | Core plugins | | | | | |
-| SKEXP0050 | Document plugins | | | | | |
-| SKEXP0050 | Memory plugins | | | | | |
-| SKEXP0050 | Microsoft 365 plugins | | | | | |
-| SKEXP0050 | Web plugins | | | | | |
-| SKEXP0050 | Text chunker plugin | | | | | |
+| SKEXP0050 | Core plugins |
+| SKEXP0050 | Document plugins |
+| SKEXP0050 | Memory plugins |
+| SKEXP0050 | Microsoft 365 plugins |
+| SKEXP0050 | Web plugins |
+| SKEXP0050 | Text chunker plugin |
| | | | | | | |
-| SKEXP0060 | Handlebars planner | | | | | |
-| SKEXP0060 | OpenAI Stepwise planner | | | | | |
+| SKEXP0060 | Handlebars planner |
+| SKEXP0060 | OpenAI Stepwise planner |
| | | | | | | |
-| SKEXP0070 | Ollama AI connector | | | | | |
-| SKEXP0070 | Gemini AI connector | | | | | |
-| SKEXP0070 | Mistral AI connector | | | | | |
-| SKEXP0070 | ONNX AI connector | | | | | |
-| SKEXP0070 | Hugging Face AI connector | | | | | |
+| SKEXP0070 | Ollama AI connector |
+| SKEXP0070 | Gemini AI connector |
+| SKEXP0070 | Mistral AI connector |
+| SKEXP0070 | ONNX AI connector |
+| SKEXP0070 | Hugging Face AI connector |
| | | | | | | |
-| SKEXP0101 | Experiment with Assistants | | | | | |
-| SKEXP0101 | Experiment with Flow Orchestration | | | | | |
+| SKEXP0101 | Experiment with Assistants |
+| SKEXP0101 | Experiment with Flow Orchestration |
| | | | | | | |
-| SKEXP0110 | Agent Framework | | | | | |
\ No newline at end of file
+| SKEXP0110 | Agent Framework |
\ No newline at end of file
diff --git a/dotnet/samples/Concepts/Optimization/FrugalGPT.cs b/dotnet/samples/Concepts/Optimization/FrugalGPTWithFilters.cs
similarity index 99%
rename from dotnet/samples/Concepts/Optimization/FrugalGPT.cs
rename to dotnet/samples/Concepts/Optimization/FrugalGPTWithFilters.cs
index f5ede1764789..2ac3fce56b23 100644
--- a/dotnet/samples/Concepts/Optimization/FrugalGPT.cs
+++ b/dotnet/samples/Concepts/Optimization/FrugalGPTWithFilters.cs
@@ -15,7 +15,7 @@ namespace Optimization;
/// This example shows how to use FrugalGPT techniques to reduce cost and improve LLM-related task performance.
/// More information here: https://arxiv.org/abs/2305.05176.
///
-public sealed class FrugalGPT(ITestOutputHelper output) : BaseTest(output)
+public sealed class FrugalGPTWithFilters(ITestOutputHelper output) : BaseTest(output)
{
///
/// One of the FrugalGPT techniques is to reduce prompt size when using few-shot prompts.
diff --git a/dotnet/samples/Concepts/Optimization/PluginSelection.cs b/dotnet/samples/Concepts/Optimization/PluginSelectionWithFilters.cs
similarity index 99%
rename from dotnet/samples/Concepts/Optimization/PluginSelection.cs
rename to dotnet/samples/Concepts/Optimization/PluginSelectionWithFilters.cs
index 70c55456e72d..bd1766a61597 100644
--- a/dotnet/samples/Concepts/Optimization/PluginSelection.cs
+++ b/dotnet/samples/Concepts/Optimization/PluginSelectionWithFilters.cs
@@ -21,7 +21,7 @@ namespace Optimization;
/// It also helps to handle the scenario with a general purpose chat experience for a large enterprise,
/// where there are so many plugins, that it's impossible to share all of them with AI model in a single request.
///
-public sealed class PluginSelection(ITestOutputHelper output) : BaseTest(output)
+public sealed class PluginSelectionWithFilters(ITestOutputHelper output) : BaseTest(output)
{
///
/// This method shows how to select best functions to share with AI using vector similarity search.
@@ -37,7 +37,7 @@ public async Task UsingVectorSearchWithKernelAsync()
.AddOpenAITextEmbeddingGeneration("text-embedding-3-small", TestConfiguration.OpenAI.ApiKey);
// Add logging.
- var logger = this.LoggerFactory.CreateLogger();
+ var logger = this.LoggerFactory.CreateLogger();
builder.Services.AddSingleton(logger);
// Add memory store to keep functions and search for the most relevant ones for specific request.
@@ -111,7 +111,7 @@ public async Task UsingVectorSearchWithChatCompletionAsync()
.AddOpenAITextEmbeddingGeneration("text-embedding-3-small", TestConfiguration.OpenAI.ApiKey);
// Add logging.
- var logger = this.LoggerFactory.CreateLogger();
+ var logger = this.LoggerFactory.CreateLogger();
builder.Services.AddSingleton(logger);
// Add memory store to keep functions and search for the most relevant ones for specific request.
diff --git a/dotnet/samples/Concepts/README.md b/dotnet/samples/Concepts/README.md
index 4bdfbd064d39..8af311c992cf 100644
--- a/dotnet/samples/Concepts/README.md
+++ b/dotnet/samples/Concepts/README.md
@@ -106,8 +106,8 @@ Down below you can find the code snippets that demonstrate the usage of many Sem
## Optimization - Examples of different cost and performance optimization techniques
-- [FrugalGPT](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Optimization/FrugalGPT.cs)
-- [PluginSelection](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Optimization/PluginSelection.cs)
+- [FrugalGPTWithFilters](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Optimization/FrugalGPTWithFilters.cs)
+- [PluginSelectionWithFilters](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Optimization/PluginSelectionWithFilters.cs)
## Planners - Examples on using `Planners`
diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvocationContext.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvocationContext.cs
index 1ef77aac8e60..2c7e92166ed0 100644
--- a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvocationContext.cs
+++ b/dotnet/src/SemanticKernel.Abstractions/Filters/Function/FunctionInvocationContext.cs
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.
-using System.Diagnostics.CodeAnalysis;
using System.Threading;
namespace Microsoft.SemanticKernel;
@@ -8,7 +7,6 @@ namespace Microsoft.SemanticKernel;
///
/// Class with data related to function invocation.
///
-[Experimental("SKEXP0001")]
public class FunctionInvocationContext
{
///
diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/IFunctionInvocationFilter.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Function/IFunctionInvocationFilter.cs
index 90077a019eea..384640b1052b 100644
--- a/dotnet/src/SemanticKernel.Abstractions/Filters/Function/IFunctionInvocationFilter.cs
+++ b/dotnet/src/SemanticKernel.Abstractions/Filters/Function/IFunctionInvocationFilter.cs
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
using System;
-using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
namespace Microsoft.SemanticKernel;
@@ -11,7 +10,6 @@ namespace Microsoft.SemanticKernel;
///
/// Interface for filtering actions during function invocation.
///
-[Experimental("SKEXP0001")]
public interface IFunctionInvocationFilter
{
///
diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/IPromptRenderFilter.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/IPromptRenderFilter.cs
index 036bf26859aa..75cb097fb3e9 100644
--- a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/IPromptRenderFilter.cs
+++ b/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/IPromptRenderFilter.cs
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
using System;
-using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
namespace Microsoft.SemanticKernel;
@@ -11,7 +10,6 @@ namespace Microsoft.SemanticKernel;
///
/// Interface for filtering actions during prompt rendering.
///
-[Experimental("SKEXP0001")]
public interface IPromptRenderFilter
{
///
diff --git a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderContext.cs b/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderContext.cs
index 918586bfa6f1..ee64d0a01f09 100644
--- a/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderContext.cs
+++ b/dotnet/src/SemanticKernel.Abstractions/Filters/Prompt/PromptRenderContext.cs
@@ -1,14 +1,11 @@
// Copyright (c) Microsoft. All rights reserved.
-using System.Diagnostics.CodeAnalysis;
using System.Threading;
-
namespace Microsoft.SemanticKernel;
///
/// Class with data related to prompt rendering.
///
-[Experimental("SKEXP0001")]
public sealed class PromptRenderContext
{
private string? _renderedPrompt;
diff --git a/dotnet/src/SemanticKernel.Abstractions/Kernel.cs b/dotnet/src/SemanticKernel.Abstractions/Kernel.cs
index 283d3de05dd5..987766feda4f 100644
--- a/dotnet/src/SemanticKernel.Abstractions/Kernel.cs
+++ b/dotnet/src/SemanticKernel.Abstractions/Kernel.cs
@@ -132,7 +132,6 @@ public Kernel Clone() =>
///
/// Gets the collection of function filters available through the kernel.
///
- [Experimental("SKEXP0001")]
public IList FunctionInvocationFilters =>
this._functionInvocationFilters ??
Interlocked.CompareExchange(ref this._functionInvocationFilters, [], null) ??
@@ -141,7 +140,6 @@ public Kernel Clone() =>
///
/// Gets the collection of function filters available through the kernel.
///
- [Experimental("SKEXP0001")]
public IList PromptRenderFilters =>
this._promptRenderFilters ??
Interlocked.CompareExchange(ref this._promptRenderFilters, [], null) ??
@@ -309,7 +307,6 @@ private void AddFilters()
}
}
- [Experimental("SKEXP0001")]
internal async Task OnFunctionInvocationAsync(
KernelFunction function,
KernelArguments arguments,
@@ -351,7 +348,6 @@ await functionFilters[index].OnFunctionInvocationAsync(context,
}
}
- [Experimental("SKEXP0001")]
internal async Task OnPromptRenderAsync(
KernelFunction function,
KernelArguments arguments,