-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Python: Updated plugins #5827
Python: Updated plugins #5827
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really exciting work. It's going to make working with functions/plugins so much better! Thank you for doing the work.
3c77b89
to
2f5de6c
Compare
Python 3.8 Test Coverage Report •Python 3.8 Unit Test Overview
|
1a37b12
to
eba56c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean! LGTM
16bfb22
to
942cc9d
Compare
9bd9185
to
7fba84e
Compare
b29d0fc
to
99110a9
Compare
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> The loading of plugins and functions into Kernel was not fully consistent and clear, this is now simplified. Adding a plugin can now be done in two ways: - multiple: `kernel.add_plugins[plugin1, plugin2]` - single plugin: `kernel.add_plugin(plugin)` - if the plugin here is a class, with methods that have the kernel_function decorator then that is parsed into a plugin Adding a function can now be done in three ways: - multiple: `kernel.add_functions([func1, func2]` or `kernel.add_function({'func1': func1})` - single: `kernel.add_function('plugin_name', func1)` - from a prompt: `kernel.add_function(function_name='func1', prompt='test prompt', ...)` In other words, all the different methods that were available have been simplified, these methods also return the created plugin (or updated plugin for the `add_functions` method. The `add_function` (singular) method has a parameter `return_plugin` to control whether you get the created or updated plugin, instead of the created function. **An important callout:** One big internal change that this introduces is that a function that gets added to a plugin (new or existing) is automatically copied, the metadata is deep-copied and the plugin_name in the metadata is updated, so this sequence is valid now: ```python @kernel_function(name='test') def f(...): etc func = KernelFunctionFromMethod(method=f) func2 = kernel.add_function('plugin', func) assert func != func2 ``` Also closes: microsoft#5855 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Removed KernelPluginCollection Updated KernelPlugin added from_... method to load from different sources Updated KernelFunctionFromPrompt added from_yaml and from_directory methods. Added and updated tests to 99% coverage of KernelPlugin and KernelFunctionFromPrompt ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> The loading of plugins and functions into Kernel was not fully consistent and clear, this is now simplified. Adding a plugin can now be done in two ways: - multiple: `kernel.add_plugins[plugin1, plugin2]` - single plugin: `kernel.add_plugin(plugin)` - if the plugin here is a class, with methods that have the kernel_function decorator then that is parsed into a plugin Adding a function can now be done in three ways: - multiple: `kernel.add_functions([func1, func2]` or `kernel.add_function({'func1': func1})` - single: `kernel.add_function('plugin_name', func1)` - from a prompt: `kernel.add_function(function_name='func1', prompt='test prompt', ...)` In other words, all the different methods that were available have been simplified, these methods also return the created plugin (or updated plugin for the `add_functions` method. The `add_function` (singular) method has a parameter `return_plugin` to control whether you get the created or updated plugin, instead of the created function. **An important callout:** One big internal change that this introduces is that a function that gets added to a plugin (new or existing) is automatically copied, the metadata is deep-copied and the plugin_name in the metadata is updated, so this sequence is valid now: ```python @kernel_function(name='test') def f(...): etc func = KernelFunctionFromMethod(method=f) func2 = kernel.add_function('plugin', func) assert func != func2 ``` Also closes: microsoft#5855 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Removed KernelPluginCollection Updated KernelPlugin added from_... method to load from different sources Updated KernelFunctionFromPrompt added from_yaml and from_directory methods. Added and updated tests to 99% coverage of KernelPlugin and KernelFunctionFromPrompt ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
Motivation and Context
The loading of plugins and functions into Kernel was not fully consistent and clear, this is now simplified.
Adding a plugin can now be done in two ways:
kernel.add_plugins[plugin1, plugin2]
kernel.add_plugin(plugin)
Adding a function can now be done in three ways:
kernel.add_functions([func1, func2]
orkernel.add_function({'func1': func1})
kernel.add_function('plugin_name', func1)
kernel.add_function(function_name='func1', prompt='test prompt', ...)
In other words, all the different methods that were available have been simplified, these methods also return the created plugin (or updated plugin for the
add_functions
method. Theadd_function
(singular) method has a parameterreturn_plugin
to control whether you get the created or updated plugin, instead of the created function.An important callout:
One big internal change that this introduces is that a function that gets added to a plugin (new or existing) is automatically copied, the metadata is deep-copied and the plugin_name in the metadata is updated, so this sequence is valid now:
Also closes: #5855
Description
Removed KernelPluginCollection
Updated KernelPlugin
added from_... method to load from different sources
Updated KernelFunctionFromPrompt
added from_yaml and from_directory methods.
Added and updated tests to 99% coverage of KernelPlugin and KernelFunctionFromPrompt
Contribution Checklist