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
name: Add support for adding [KernelFunction] attribute to an interface methods
about: Need this for testing the AI without invoking the actual plugin code
For testing and prompt engineering purposes I want to define a plugin as an interface and then use a mock class to test the AI prompts and interaction. However it is not possible to add this attribute to interface methods. I am getting an error "Unhandled exception. System.ArgumentException: The sklearn.SubscriptionPlugin instance doesn't implement any [KernelFunction]-attributed methods."
Example code that does not work:
usingMicrosoft.SemanticKernel;usingSystem.ComponentModel;namespacesklearn{[Description("The id and display name of an Azure subscription")]publicsealedrecordSubscriptionDescriptor(stringId,stringDisplayName);internalinterfaceISubscriptionPlugin{[KernelFunction("list_subscriptions")][Description("Lists all Azure subscriptions that user has access to")]publicTask<IReadOnlyList<SubscriptionDescriptor>>ListSubscriptionsAsync();[KernelFunction("get_subscription")][Description("Gets the details of a specific Azure subscription id")]publicTask<SubscriptionDescriptor?>GetSubscriptionAsync(stringid);}publicclassSubscriptionPlugin:ISubscriptionPlugin{privatereadonlyList<SubscriptionDescriptor>_subscriptions=new(){newSubscriptionDescriptor("31cad2f7-1ec4-4491-b69f-d0360ec2b723","Subscription 1"),newSubscriptionDescriptor("7f07aade-c4d8-416c-a3d9-06c76acacf71","Subscription 2"),newSubscriptionDescriptor("62b38d30-c1ab-4f92-b26f-9fb4c85a01a2","Subscription 3")};publicTask<IReadOnlyList<SubscriptionDescriptor>>ListSubscriptionsAsync(){returnTask.FromResult<IReadOnlyList<SubscriptionDescriptor>>(_subscriptions);}publicTask<SubscriptionDescriptor?>GetSubscriptionAsync(stringid){returnTask.FromResult(_subscriptions.FirstOrDefault(subscription =>subscription.Id==id));}}}
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
New Feature: Add support for adding [KernelFunction] attribute to an interface methods
.Net: New Feature: Add support for adding [KernelFunction] attribute to an interface methods
Jan 28, 2025
usingSystem.ComponentModel;namespacesklearn{[Description("The id and display name of an Azure subscription")]publicsealedrecordSubscriptionDescriptor(stringId,stringDisplayName);publicinterfaceISubscriptionPlugin{publicTask<IReadOnlyList<SubscriptionDescriptor>>ListSubscriptionsAsync();publicTask<SubscriptionDescriptor?>GetSubscriptionAsync(stringid);}publicclassSubscriptionPluginDefinition{privatereadonlyISubscriptionPlugin_plugin;publicclassSubscriptionPluginDefinition(ISubscriptionPluginplugin){_plugin=plugin;}[KernelFunction("list_subscriptions")][Description("Lists all Azure subscriptions that user has access to")]publicTask<IReadOnlyList<SubscriptionDescriptor>>ListSubscriptionsAsync(){return_plugin.ListSubscriptionsAsync();}[KernelFunction("get_subscription")][Description("Gets the details of a specific Azure subscription id")]publicTask<SubscriptionDescriptor?>GetSubscriptionAsync(stringid){return_plugin.GetSubscriptionAsync(id);}}publicclassSubscriptionPlugin:ISubscriptionPlugin{privatereadonlyList<SubscriptionDescriptor>_subscriptions=new(){newSubscriptionDescriptor("31cad2f7-1ec4-4491-b69f-d0360ec2b723","Subscription 1"),newSubscriptionDescriptor("7f07aade-c4d8-416c-a3d9-06c76acacf71","Subscription 2"),newSubscriptionDescriptor("62b38d30-c1ab-4f92-b26f-9fb4c85a01a2","Subscription 3")};publicTask<IReadOnlyList<SubscriptionDescriptor>>ListSubscriptionsAsync(){returnTask.FromResult<IReadOnlyList<SubscriptionDescriptor>>(_subscriptions);}publicTask<SubscriptionDescriptor?>GetSubscriptionAsync(stringid){returnTask.FromResult(_subscriptions.FirstOrDefault(subscription =>subscription.Id==id));}}}
name: Add support for adding [KernelFunction] attribute to an interface methods
about: Need this for testing the AI without invoking the actual plugin code
For testing and prompt engineering purposes I want to define a plugin as an interface and then use a mock class to test the AI prompts and interaction. However it is not possible to add this attribute to interface methods. I am getting an error "Unhandled exception. System.ArgumentException: The sklearn.SubscriptionPlugin instance doesn't implement any [KernelFunction]-attributed methods."
Example code that does not work:
The text was updated successfully, but these errors were encountered: