microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.95k stars 3.27k forks source link

.Net: Plugin function inspection combines class details instead of isolating interface details. #4668

Closed rvinothrajendran closed 6 months ago

rvinothrajendran commented 10 months ago

Describe the bug A class inherits from both Interface1 and Interface2. In the ImportPluginFromObject method, when I pass an Interface1 object to the function and inspect the plugin functions, I observe that it includes details from both interfaces.

To Reproduce Steps to reproduce the behavior: Follow the steps

Define the plugins

image

ImportPluginFromObject

image

Expected behavior

Import only Interface1 Objects in the Plugin Function Inspection

Platform

stephentoub commented 10 months ago

ImportPluginFromObject uses all public methods on the object, regardless of what interfaces those methods may also satisfy.

rvinothrajendran commented 10 months ago

While it may make sense from a plugin perspective, as a developer using the API, it can be quite confusing. It might be clearer not to allow objects created by the interface and perhaps throw an exception in such cases.

stephentoub commented 10 months ago

Even if we wanted that to be the behavior, it's simply not possible. You haven't communicated to the API what interface you care about (because the API doesn't make it possible). The signature of the method takes object target, string? pluginName, and from its perspective you've simply given it a System.Object and a name to use for the plugin. It doesn't know the type of the local variable the object happened to be referenced by, and the object implements multiple interfaces.

The behavior you're asking for would need to be some new API that was specifically focused on interfaces and that accepted the necessary information to make it possible to narrow down the scope of the reflection.

All ImportPluginFromObject is is a thin wrapper around CreatePluginFromFunctions and use of reflection to get the functions to wrap. You can do the same thing if you want to write such a helper yourself.

rvinothrajendran commented 9 months ago

Certainly, I grasp the concept behind the functions, and it's a sound recommendation to establish a new API for interface support. In the interim, I've generated a community NuGet package to aid in implementing "ImportPluginFromInterface." https://www.nuget.org/packages/AzureAI.Community.Microsoft.Semantic.Kernel.PlugIn.Interface 😎

github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] commented 6 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.