semantic-kernel
semantic-kernel copied to clipboard
.Net: Pass Metadata from FunctionInvocationFilter
Is there a trick to getting additional data back from an FunctionInvocationFilter in order to add additional info to the OpenAI response?
https://github.com/microsoft/semantic-kernel/blob/c669f74099629db40c281397886ae5d81856e9e4/dotnet/samples/Concepts/Filtering/FunctionInvocationFiltering.cs#L58
In AdaptiveCardFilter : IAutoFunctionInvocationFilter
Dictionary<string, object?> metadata = context.Result.Metadata is not null ? new(context.Result.Metadata) : [];
metadata["AdaptiveCard"] = adaptiveCardJson;
context.Result = new FunctionResult(context.Result)
{
Metadata = metadata
};
In SemanticKernelService.cs:
public async Task<string> GenerateReplyAsync(string input, string author...)
{
// Get the chat function from the ChatPlugin
var chatFunction = _kernel.Plugins.GetFunction(nameof(ChatPlugin), "Chat");
var executionSettings = new AzureOpenAIPromptExecutionSettings
{
Temperature = 0.1,
MaxTokens = ...,
Seed = ...,
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};
// Invoke the chat function
var result = await _kernel.InvokeAsync(chatFunction, new KernelArguments
{
["input"] = input,
["author"] = author,
["executionSettings"] = executionSettings,
["kernel"] = _kernel
});
******* result.Metadata = null *******
return result.GetValue<string>() ?? "No response generated.";
}
This issue is stale because it has been open for 90 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.