You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Filters enhance security by providing control and visibility over how and when functions run. This is needed to instill responsible AI principles into your work so that you feel confident your solution is enterprise ready.
17
15
18
-
For example, filters are leveraged to validate permissions before an approval flow begins. The `IFunctionInvocationFilter` is run to check the permissions of the person that’s looking to submit an approval. This means that only a select group of people will be able to kick off the process.
16
+
For example, filters are leveraged to validate permissions before an approval flow begins. The filter runs to check the permissions of the person that’s looking to submit an approval. This means that only a select group of people will be able to kick off the process.
19
17
20
18
A good example of filters is provided [here](https://devblogs.microsoft.com/semantic-kernel/filters-in-semantic-kernel/) in our detailed Semantic Kernel blog post on Filters.
21
19
@@ -45,7 +43,9 @@ For cases where filter order is important, it is recommended to add filters dire
45
43
46
44
## Function Invocation Filter
47
45
48
-
This filter is triggered every time a Semantic Kernel function is invoked, regardless of whether it is a function created from a prompt or a C# method.
46
+
This filter is triggered every time a Semantic Kernel function is invoked, regardless of whether it is a function created from a prompt or a method.
47
+
48
+
::: zone pivot="programming-language-csharp"
49
49
50
50
```csharp
51
51
/// <summary>
@@ -80,14 +80,94 @@ Add filter using `Kernel` property:
Functions in Semantic Kernel can be invoked in two ways: streaming and non-streaming. In streaming mode, a function typically returns `AsyncGenerator<T>`, while in non-streaming mode, it returns `FunctionResult`. This distinction affects how results can be overridden in the filter: in streaming mode, the new function result value must be of type `AsyncGenerator<T>`, whereas in non-streaming mode, it can simply be of type `T`.
128
+
129
+
So to build a simple logger filter for streaming, you would use something like this:
*[Streaming function invocation filter examples](https://github.com/microsoft/semantic-kernel/blob/main/python/samples/concepts/filtering/function_invocation_filters_stream.py)
155
+
156
+
::: zone-end
157
+
::: zone pivot="programming-language-java"
158
+
159
+
## Coming soon
160
+
161
+
More info coming soon.
162
+
163
+
::: zone-end
86
164
87
165
## Prompt Render Filter
88
166
89
167
This filter is invoked only during a prompt rendering operation, such as when a function created from a prompt is called. It will not be triggered for Semantic Kernel functions created from methods.
90
168
169
+
::: zone pivot="programming-language-csharp"
170
+
91
171
```csharp
92
172
/// <summary>
93
173
/// Example of prompt render filter which overrides rendered prompt before sending it to AI.
*[Auto function invocation filter examples](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Filtering/AutoFunctionInvocationFiltering.cs)
177
284
285
+
::: zone-end
286
+
::: zone pivot="programming-language-python"
287
+
288
+
```python
289
+
290
+
from semantic_kernel.filters import FilterTypes, AutoFunctionInvocationContext
*[Auto function invocation filter examples](https://github.com/microsoft/semantic-kernel/blob/main/python/samples/concepts/filtering/auto_function_invoke_filters.py)
301
+
302
+
303
+
::: zone-end
304
+
::: zone pivot="programming-language-java"
305
+
306
+
## Coming soon
307
+
308
+
More info coming soon.
309
+
310
+
::: zone-end
311
+
::: zone pivot="programming-language-csharp"
312
+
178
313
## Streaming and non-streaming invocation
179
314
180
315
Functions in Semantic Kernel can be invoked in two ways: streaming and non-streaming. In streaming mode, a function typically returns `IAsyncEnumerable<T>`, while in non-streaming mode, it returns `FunctionResult`. This distinction affects how results can be overridden in the filter: in streaming mode, the new function result value must be of type `IAsyncEnumerable<T>`, whereas in non-streaming mode, it can simply be of type `T`. To determine which result type needs to be returned, the `context.IsStreaming` flag is available in the filter context model.
@@ -245,15 +380,8 @@ ChatMessageContent result = await chatCompletionService.GetChatMessageContentAsy
245
380
::: zone-end
246
381
::: zone pivot="programming-language-python"
247
382
248
-
## Coming soon
249
-
250
-
More info coming soon.
383
+
## More examples:
251
384
252
-
::: zone-end
253
-
::: zone pivot="programming-language-java"
254
-
255
-
## Coming soon
256
-
257
-
More info coming soon.
385
+
*[Retry logic with a filter](https://github.com/microsoft/semantic-kernel/blob/main/python/samples/concepts/filtering/retry_with_filters.py)
0 commit comments