-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There doesn't seem to be a way to set the context.Terminate in a AIFunction call #5705
Comments
@gyankov Thanks for pointing this out.
That's not the semantics that are intended here. Even if an The design we had in mind is using the void MyFunction(FunctionInvocationContext context, string otherParam1, int otherParam2) { ... } ... matching on the object type. We can treat this issue as tracking the need to complete this functionality. Does this match your expectations, @stephentoub? |
It can be used, but not via AIFunction, as you call out. Right now you need to derive from FunctionInvokingChatClient and override the InvokeFunctionAsync method. That lets you add logic like "if the method being invoked is ABC, then set Terminate = true". protected override async Task<object?> InvokeFunctionAsync(FunctionInvocationContext context, CancellationToken cancellationToken)
{
try
{
return await base.InvokeFunctionAsync(context, cancellationToken);
}
finally
{
if (context.Function.Metadata.Name == "ABC") context.Terminate = true;
}
} We'd need to think more about a design that would actually funnel that FunctionInvocationContext into the AIFunction itself. |
Thank you @SteveSandersonMS and @stephentoub! Overriding the InvokeFunctionAsync works unless I add the
|
Great!
Yes, if you're using your own type, you'd need to use the Use method to add it to the pipeline rather than using the UseFunctionInvocation helper. |
Got you! Thanks once again @stephentoub. |
From what I see in the source the context is created internally and by default it will continue the calls:
extensions/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Line 529 in d8e2cd2
Perhaps it would be better if the return type of the
AIFunction
isvoid
to set theFunctionInvocationContext.Terminate
prop totrue
by default. Or somehow allow users to set it manually when needed.The text was updated successfully, but these errors were encountered: