Is there any way to access the Plugin's return? #10627
-
I'm building an application with Blazor, and I have a Plugin that returns a List of Articles. The issue is that when I access the response of GetStreamingChatMessageContentsAsync, it returns a string. I can't even receive a valid JSON, because it always adds properties that don't make sense. I would like to have the response typed so that it can be presented differently depending on the type of data. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Have you considered using structured outputs? https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/ChatCompletion/OpenAI_StructuredOutputs.cs |
Beta Was this translation helpful? Give feedback.
-
Please also have a look at how filters may help you, if you need the immediate result of a function result without having the model provide the final natural language response: https://learn.microsoft.com/en-us/semantic-kernel/concepts/enterprise-readiness/filters?pivots=programming-language-csharp. |
Beta Was this translation helpful? Give feedback.
-
Hi @moonbox3 First of all, thank you for your response. I believe the way to go is indeed through Filters. I have already managed to configure them, but I am having an issue with something. I thought it would only proceed past await next(context); after calling all the functions, but that’s not what happens. So, if I set context.Terminate = true; after await next, it will interrupt the sequence of calls. Is there a way to determine if it is the last function being executed so that I can serialize the data and 'cancel' the OpenAI response? |
Beta Was this translation helpful? Give feedback.
@ptufail Yes, you can get a collection of function calls and check its
Count
:semantic-kernel/dotnet/samples/Concepts/Filtering/AutoFunctionInvocationFiltering.cs
Lines 104 to 105 in 7b83ffd
You can also get a sequence index of current function being executed:
semantic-kernel/dotnet/samples/Concepts/Filtering/AutoFunctionInvocationFiltering.cs
Lines 127 to 128 in 7b83ffd