mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
6751f9d819bb2956bd72cadde84655cac43ae649
63
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
6751f9d819 |
Python: Updated plugins (#5827)
### 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: #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 😄
|
||
|
|
629624cee3 |
Python: removed pipeline (#5779)
### 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. --> Remove the ability to run multiple functions in go in kernel.invoke. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [x] I didn't break anyone 😄 Co-authored-by: Evan Mattson <[email protected]> |
||
|
|
c4c7464f07 |
Python: Introduce operations to handle OpenAI plugins, improve OpenAPI plugins, and allow for auth (#5695)
### Motivation and Context Python had the ability to handle operations for OpenAPI plugins, but at a basic level. It did not have the ability to handle OpenAI plugins, nor did it allow the user to configure an authentication callback. This PR brings in that functionality. <!-- 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. --> ### Description This PR: - Allows a user to handle OpenAI plugins with/without auth. Closes #5355 - Improves the functionality around handling OpenAPI specs. - Introduces an auth callback mechanism to allow for REST API calls to use auth - Introduces OpenAI/OpenAPI function execution settings. - Provides two new kernel examples that show how to handle a simple OpenAI plugin (Klarna) as well as a more complex plugin (Azure Key Vault) that requires auth. - Updates unit tests. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 |
||
|
|
14a0881989 |
Python: mypy clears kernel.py (#5689)
### 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. --> Fixed all mypy errors for kernel.py In preparation of extending that to all files in semantic_kernel Also got the pre-commit hook working on a commit, with mypy checks fixes #5630 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Moved pre-commit-config to base folder, can now be extended to have specific hooks for other languages fixed things in kernel.py to satisfy mypy used assert for some things, so that they can be skipped when running in -o mode. ### 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 - [x] I didn't break anyone 😄 |
||
|
|
75089cb711 |
Python: Enhance Chat Message Content creation and parsing (#5520)
### 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. --> Introduces a polymorphic approach to creating and rendering Chat Message Contents and it's subclasses, leverages Pydantic Rootmodel for that. Fixes #5496 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Adds ChatMessageContentBase that can create all types of CMC's, based on a type field (str) Redoes some of the rendering and parsing also retooled the hierarchy structure for Contents, including introducing a StreamingContentMixin instead of the StreamingKernelContent (which was never used), now all content classes (TextContent, CMC, etc) determine the fields used, while the Mixin adds one additional field and two additional methods for streaming messages, especially __add__ everything else runs the same way. ### 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 - [x] I didn't break anyone 😄 |
||
|
|
1cf984cc99 |
Python: Enhanced pre commit and tasks (#5512)
### 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. --> To further make the SK python robust and make it easier to get high-quality PRs, some work on the pre-commit-config.yaml and adding a mypy settings ini. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Added two steps to the pre-commit-config, the first for pypy, the second for tests with coverage. Over time we want to mandate these checks to run against a PR before it goes to github, that will also reduce the number of ruff and black fix commits, and non-passing unit tests. Added a mypy.ini, currently all but the root folder is excluded, so that we can gradually introduce mypy coverage, did the first pieces in kernel.py, including switch to new style annotations (using from `__future__ import annotations`) in Kernel. ### 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 - [x] I didn't break anyone 😄 |
||
|
|
5b127badbf |
Python: Add support for yaml prompt template (#5527)
### Motivation and Context SK Python doesn't have a way to create a prompt template config from a yaml file. This is neeed to further achieve parity with dotnet and java. <!-- 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. --> ### Description This PR introduces: - some kernel methods to load yaml prompts from a directory as well as create a kernel function from a string that contains yaml. Closes #4640 - Unit tests and a syntax example showing how to create a yaml prompt and load it <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 |
||
|
|
0a1a7cabe8 |
Python: support Jinja2 templating (#5483)
### Motivation and Context Jinja2 is a heavily supported Python templating language and we're introducing it to SK Python. <!-- 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. --> ### Description This PR brings in the ability to specify Jinja2 templates for use within SK Python: - Closes #5343 <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 |
||
|
|
59c3a9fc9a |
Python: planner love (#5477)
### 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. --> Based on #5474 went into the `using-the-planner` notebook and made sure it works with the latest code. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Moved all the planners to use '-' in line with the current work on new templates and planners, once that is in several extension classes can be changed. Encountered several small bugs left over from changes over the last months. Got through the whole notebook with results. ### 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 - [x] I didn't break anyone 😄 |
||
|
|
3af69df7ea |
Python: Handlebars template support (#5466)
### 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. --> Introducing Handlebars templating to the Python Semantic Kernel! Closes: #5446 Prework for: #4641 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Adds HandlebarsPromptTemplate as a subclass of PromptTemplateBase Adds second literal to the PromptTemplateConfig definition Adds helpers for Handlebars (system_helpers) and `create_helper_from_function` function Moves fully_qualified_name into KernelFunctionMetadata instead of in different extensions. Defaults are still 'semantic-kernel' templates, and without making explicit changes that still is the norm. Adds a azure_chat_gpt_handlebars.py sample ### 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 - [x] I didn't break anyone 😄 |
||
|
|
2bc3de72da |
Python: Add extras and minor package updates (#5440)
### 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. --> Poetry groups are not the same as pip extras, so I removed the individual groups per service, replaced with the ones needed for unit tests and for integration tests (all). Then added Extras, for each connector, as well as a `all` extra. Also added a notebooks extra, this can be used instead of the first cell in the notebooks as `pip install -U semantic-kernel[notebooks]` closing #4713 Made all dependencies part of the main, tagged with optional. Closes #5322 ### 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 - [x] I didn't break anyone 😄 |
||
|
|
275db86fd1 |
Python: add py3.12 to unit tests (#5191)
### 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. --> Since Python 3.12 is now released we should test with it. In the fall 3.8 will be out of support so then we should remove support for that. Since Numpy no longer support py 3.8 as of [1.25](https://numpy.org/doc/stable/release/1.25.0-notes.html) we pin that for py3.8, including other packages that depend on older version of numpy for py3.8, and allow the new versions to work against newer version of python. Closes #5144 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [x] I didn't break anyone 😄 |
||
|
|
e884e81776 |
Python: update usearch to 2.9 (#5420)
### 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. --> Updates the usearch package to 2.9+, and fixes the tests for that. Closes #2676 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [x] I didn't break anyone 😄 |
||
|
|
d7c1febc7b |
Python: Use the correct exception key for handling streaming exceptions in the kernel (#5417)
### Motivation and Context In a previous fix, the error -> exception key change was missed in a line in the kernel. This fixes that. <!-- 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. --> ### Description This PR: - fixes the incorrect key (error) and now pulls the exception from the metadata for streaming invoke for the key `exception`. Closes #5385 - Adds a unit test <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 |
||
|
|
555a7c8436 |
Python: fix for streaming openai responses, and first parts of fixes for Chat With Your Data (#5387)
### 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. --> ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 |
||
|
|
bf5d21c69a |
Python: Properly handle exceptions in the kernel using the exception metadata (#5391)
### Motivation and Context Two things: 1) Add the exception to the on function invoked args if an exception exists in the function result. 2) Set the stepwise planner's goal to the plan's description, not the name. <!-- 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. --> ### Description The PR addresses: - Properly handling exceptions to raise them from the kernel if a function result contains an exception in the metadata. Closes #5385 - In the stepwise planner, the goal was getting set as the plan's name, instead of the description. Closes #5316 <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 |
||
|
|
2493e293fb |
Python: Update kernel tests (#5341)
### 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. --> Adding a whole bunch of tests to better cover Kernel.py. Also reviewed and updated the conftest and tweaked the scope, now runs faster! Skipped efforts for handlers since work is being done there. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [x] I didn't break anyone 😄 |
||
|
|
d7820df9c2 |
Python: Add function name and plugin name to invoke prompt. Add unit tests. (#5318)
### Motivation and Context The kernel.invoke_prompt was missing the function name and plugin name args and was failing. <!-- 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. --> ### Description This PR: - Adds the required arguments. Closes #5313 - Adds unit tests. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 |
||
|
|
b93bab90ac |
Python: Support Auto tool calling for OpenAI models (#5267)
### Motivation and Context Auto tool calling hasn't been implemented in Python for OpenAI models. This is a much needed feature, which helps open the possibilities and extends being able to use the OpenAI models for just pure back and forth chats. <!-- 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. --> ### Description This PR: - introduces auto tool calls for OpenAI models. If the prompt function is of an OpenAI chat completion type, then we pass the kernel as an argument to the OpenAI Chat Completion Base class. The kernel is used to auto-invoke tools/functions seamlessly as part of the chat completion request. Closes #4553 - splits the current chat completion/chat completion stream methods into smaller, more readable/functional methods in the OpenAI Chat Completion Base class. - Adds an integration test to cover auto invoke tool calls - Updates a kernel example to be able to work for a streaming/non-streaming tool call. Other Kernel Examples that don't use auto invoke tools still work as they did before. - Removes old code in the utils file that was related to the manual form of invoking function calls. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 --------- Co-authored-by: Eduard van Valkenburg <[email protected]> |
||
|
|
3e67904d37 |
Python: small fix in create_function_from_prompt to match KernelFunctionFromPrompt (#5288)
### 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. --> Small fix for the Kernel function that deal with Prompt function, they were slightly out of sync with the KernelFunctionFromPrompt constructor. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [x] I didn't break anyone 😄 |
||
|
|
2785c66622 |
Python: Migrate and update docs samples (#5235)
### Motivation and Context As of the latest code in main, and the push towards a beta package, the Python sample code needed updates. We've migrated away from using the semantic-kernel-docs repo and the Python sample code is now in the main SK repo. The SK Python docs will be updated to reflect this latest code. <!-- 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. --> ### Description This PR: - Migrates the Python samples to the main SK repo - The naming of the files is about 1:1 with dotnet, based on python naming conventions/using underscores - Updates the Python samples to work with the latest code in main. Closes #5234 - Fixes some other small logging quirks related to parsing blocks and printing plan steps. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 |
||
|
|
739e7f0e2a |
Python: rebuilt exceptions structure; pythonic version (#5231)
### 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 existing Exceptions structure was very much inspired by dotnet, this is now replaced with a pythonic implementations. This means all Exceptions derive from KernelException and then specialise for different purposes. Closes #2194 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Added folder for all exception types, all can be imported through `from semantic_kernel.exceptions import ...` no need for a user to know which file the relevant one is in, but keeps things tidy for developers. Removed old KernelException, added back subtypes for the errorcodes. Went through everything to make sure the `raise ... from exc` pattern is used as much as possible as that returns a better stacktrace. ### 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 - [x] I didn't break anyone 😄 |
||
|
|
a6f66ec098 |
Python: split kernelfunction into fromprompt and frommethod classes (#5159)
### 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. --> Closes #4633 and brings this part of the python sdk in sync with dotnet, also makes for a much more readable set of classes. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Added: - KernelFunctionFromPrompt class - KernelFunctionFromMethod class - tests for both. Changed: - removed parts of KernelFunction that are specific to one of the two subtypes - removed expose attribute of KernelParameterMetadata as that is no longer needed ### 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 😄 --------- Co-authored-by: Evan Mattson <[email protected]> Co-authored-by: Evan Mattson <[email protected]> |
||
|
|
8b16af69c0 |
Python: Remove the memory tied to the kernel. Update kernel examples and notebooks. (#5143)
### Motivation and Context As we move toward v1, it is necessary to remove the single kernel memory attribute so that memory connectors can be handled via plugins. This change also refactors the `import_plugin` method name to be similar with dotnet as `import_plugin_from_object`, and introduces a simple `kernel.invoke_prompt` method. <!-- 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. --> ### Description Updates are: - The memory connector is now passed to the `SemanticTextMemory` class, along with the embedding generator. This allows the user to add memory to multiple plugins/services as needed. Closes #4632 - Kernel Examples and Notebooks were updated to reflect these changes. Now using Service Enum for all notebooks. Closes #4557 - There were planners using memory related to the kernel, to store the functions, and many of these planners are non-existent in dotnet's v1 SDK. Python has pending work to update the planner/remove deprecated planners before getting to v1. - A Kernel method called `invoke_prompt` was introduced to invoke a simple prompt, and return the `FunctionResult` when complete. - All unit/integration tests are passing. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 😄 |
||
|
|
5817c2b927 |
Python: major features for the Kernel Arguments, Function Result and new Prompt Templating (#5077)
### 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. --> Major work to replace the context with Kernel Arguments on the front-end and Function Results on the back. Updated the function decorator to a new approach, in line with dotnet. Revamps the way function are called, allowing native functions to be completely ignorant of SK, other then the decorator. This also moves things into the new folder structure in sync with dotnet. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Adds: - KernelArguments, a dict-like class that replaces the variables in KernelContext. Closes #4565 - FunctionResult, a class to hold the results of function executions, includes the function, the value and metadata, as well as two convenient function to get the value out of it (str and get_inner_content) the first is generic, the second specifically for KernelContent responses (from AI services). - AI Service Selector class, has a default, which is based on the order in the arguments followed by the order in the functions, can be overridden to implement your own strategy. Closes #4631 - Introduces ChatHistory and refactors the PromptTemplateConfig. Closes #4856, #4630 - Improves parsing of templates, will now all validate during creation and throw an error then, instead of some that do not check for validaty until used. - Introduces named_args block and thereby the ability to have multiple arguments for a function call in a template. Closes #5003 Updates: - kernel_function decorators, the parameter decorator was removed and instead we now use Annotated to add a description of a field and we get the type and required from the function definition. - core plugins, use the new approach to kernel_function decorators. - planners, template engines have all been updated to use the kernel and kernelarguments instead of Context. - Events have been updated, now use kernelarguments and function_result - Tokenizers support for named_args and improvements on parsing and checking. - Kernel examples and notebooks to use the latest code. - All unit and integration tests. There is more code coverage now than before. Removed: - kernelContext - kernel_function_parameter_decorator - delegate handling code for native functions - file_io_plugin and tests - SemanticFunctionConfig - ChatPromptTemplate ### 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 😄 --------- Co-authored-by: Evan Mattson <[email protected]> Co-authored-by: Evan Mattson <[email protected]> Co-authored-by: Evan Mattson <[email protected]> |
||
|
|
1efeb69819 |
Python: Set the default plugins on the semantic function. Add a unit test. (#4897)
### Motivation and Context Fixes #4869. On a created semantic function, the plugins weren't getting set for use for the function. <!-- 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. --> ### Description Set the default plugins for the registered function, and add a unit test. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 |
||
|
|
7268d13ee8 |
Python: Pydantic-ify the KernelFunction class. Fix code paths related to tool_calls. (#4863)
### Motivation and Context Solves #4864 The KernelFunction was configured as a Python class without regards to using Pydantic fields and its validations. As an aside, while running a kernel example related to function/tool calling, it didn't succeed. <!-- 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. --> ### Description This PR cleans up the KernelFunction by creating Pydantic fields. We're also able to remove the KernelFunctionBase as it didn't contain a lot of logic after removing the properties. While testing other code, I found that the tool call kernel example wasn't succeeding. The tool_call payload needed a small reformat, and we needed to handle the tool_call_id and correctly handle the ToolCall object. As further work towards v1, we should look at removing support for FunctionCall as it is deprecated in Azure OpenAI. We now see: ``` User:> What is 3+3? Mosscap:> Ah, the timeless question of arithmetic! The sum of 3 and 3 is undoubtedly a splendid number. By utilizing my mathematical prowess, I can confidently declare that 3 plus 3 equals 6. It is a harmonious union of two threes, joining forces to create a new entity, greater in magnitude. The addition of these two numbers results in a perfect balance, a symphony of numerical harmony. ``` <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 --------- Co-authored-by: Evan Mattson <[email protected]> |
||
|
|
9ae69a43fc |
Python: Make the Kernel class Pydantic. (#4850)
### Motivation and Context Completes work item: #4846. The Kernel class was not following the Pydantic convention. <!-- 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. --> ### Description This PR updates the Kernel class to use the KernelBaseModel and Pydantic fields. All unit and integration tests passing. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [x] I didn't break anyone 😄 --------- Co-authored-by: Evan Mattson <[email protected]> Co-authored-by: Eduard van Valkenburg <[email protected]> |
||
|
|
2b6bd03b03 |
Python: Add kernel plugin collection and remove old plugin collection classes (#4764)
### Motivation and Context This PR solves two works items: #4560 and #4667. The Python SDK had different ways of handling plugins and collections. The work in the PR helps align the SDK with dotnet nomenclature and structure. <!-- 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. --> ### Description A `KernelPluginCollection` is introduced with an underlying `DefaultKernelPlugin` and a `KernelPlugin` base class. Other code is refactored to use this new `KernelPluginCollection` model which should simplify how plugins are handled. Unit tests are added to test the new functionality. Existing unit tests and integration tests, along with kernel examples and notebooks were updated based on these changes. Unlike before, we're requiring plugins to be defined with a name, which removes the GLOBAL_PLUGIN constant name of "__GLOBAL_PLUGIN__". In some senses, while creating a plugin or a function, a name may not be provided and so a random name in the form of a plugin (p_<random_ascii_chars>) or function (f_<random_ascii_chars>) is used. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 😄 --------- Co-authored-by: Evan Mattson <[email protected]> |
||
|
|
7170f0d6a1 |
Python: Remove sync function invoke. Update other code to use async invoke. (#4796)
### Motivation and Context Completes #4794. Most of SK Python is written with async code; however, there were some code paths that masked the underlying async code and made it look like a sync function invoke. In reality, asyncio spun up event loops and attempted to manage them properly. This becomes tricky when running a Jupyter notebook as they have their own event loop. <!-- 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. --> ### Description This PR removes the ability to call a kernel function synchronously. Since the majority of the code base is written with async methods, and to match dotnet, which is async, we're removing the sync function invoke and its dependent code. Some Planners were also run synchronously -- these were updated to run asynchronously. Kernel examples, notebooks, docs, and tests were updated accordingly. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 😄 |
||
|
|
5303126c0d |
Python: Renames request settings to prompt execution settings (#4782)
### Motivation and Context Following the C# implementation, renames all classes and variables of `*RequestSettings` to `*PromptExecutionSettings`. Fixes #4676 ### 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 - [X] I didn't break anyone 😄 |
||
|
|
d97f9536c4 |
Python: Removes the _async suffix where is not needed (#4735)
### Motivation and Context Delete all *_async where *_sync doesn't exist to make the library more Pythonic. Fixes #4629 ### 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 - [X] I didn't break anyone 😄 --------- Co-authored-by: Evan Mattson <[email protected]> |
||
|
|
08710373a4 |
Python: Renames SK prefix to Kernel (#4716)
### Motivation and Context The .NET SDK uses the `Kernel` prefix instead of `SK` for the context, function, model, etc. classes. This PR aligns the Python package with that policy. Fixes #4561 ### Contribution Checklist - [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 - [X] I didn't break anyone 😄 |
||
|
|
674af5468d |
Python: Rename skills to plugins. Update prompt template config to use execution settings to align with dotnet. (#4595)
### Motivation and Context To better align with SK dotnet v1, Python skills have been renamed to plugins. This removes the root samples skills directory as dotnet supports the plugins and their configs. This the beginning of more work to consolidate other files/names, per the backlog. I've run several greps for files or file names containing "skill" (case insensitive), and no results appear. Do alert if you find anything else that includes "skill." Fixes #3319 <!-- 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. --> ### Description This is a large, breaking change PR as the replacement of "skills" to "plugins" affects many files. It was difficult to break this up into smaller chunks without leaving the SK Python repo in a bad state for some time. Other updates include: - Prompt template has been updated to use `execution_settings`, which aligns with dotnet, from the previous `completion` that Python used. - AzureOpenAI/OpenAI function calling has been updated to match the current versions of tools/tool_choice. Parsing messages in the open_ai utils respects this as it now looks for tool_calls and it configures the function_call with the id (new), name, and argument). - File renames, where the filename used to contain "skill" will look like new code, but it's the same code, just with "plugin" in the name. - Kernel examples and notebooks have been tested and are working. Unit tests and integration tests are passing. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [X] I didn't break anyone 😄 --------- Co-authored-by: Evan Mattson <[email protected]> |
||
|
|
fa3e32bb16 |
Python: set line-length for black in sync with Ruff, run black. (#4396)
### 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. --> As we are tightening the formatting and linting setups, this was missing, now the line-length for black and ruff are the same, thereby no longer running into black issues as often. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [x] I didn't break anyone 😄 |
||
|
|
b91529a62e |
Python: Implement AI request settings (#4097)
### 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. --> This PR implements the new approach to AI Request settings as described here: https://github.com/microsoft/semantic-kernel/blob/main/docs/decisions/0008-support-generic-llm-request-settings.md and completes #3312 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Does this: - Creates AI Request Settings with service_id (referring to the registered AI services in a kernel) and extension_data, a dict that can hold any number of settings - has several methods: - `from_ai_request_settings` -> constructor to create a new request_settings object based on another, supports creating specific ai_request_settings from generic ones. - `update_from_ai_request_settings` -> updating the fields of a request setting from another ones. - `prepare_settings_dict` -> method that is used when actually creating the dict that get's passed to the handler of the AI service. - Created subclasses like OpenAIChatRequestSettings which has all the required fields of a OpenAI Chat completion, same for OpenAIText, AzureChat, GooglePalm, HuggingFace, etc. - added `get_request_settings_class` to ai_services to return the class used for the settings for that service. The goal is that when running, this settings object get's updated and a single operations (called `prepare_settings_dict`) is used to return a dict that can be passed to the api call directly, thereby reducing the need for custom logic everywhere, this will also negate the need for things like `complete_chat_with_functions_async` and others. So also removed complete_chat_..._async methods from openai and azure openai. It has also changed the prompt_template_config with the generic type for the AIRequestSettings or subclasses, and some other changes. ### 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 😄 |
||
|
|
d3dd5c8e7e |
Python: Uses Python standard logging (#4115)
### Motivation and Context This replaces passing Logger instances as arguments around with the preferred Python way of having each module define a module-wide `logger` instance at the top of the module. Fixes #3711 ### Description Removes any `log` argument and argument documentation. Replaces usage of those `log` arguments with the module-wide `logger` instance. ### Contribution Checklist - [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 - [x] I didn't break anyone 😄 --------- Co-authored-by: Eduard van Valkenburg <[email protected]> |
||
|
|
194f2401eb |
Python: sync C# for Pre/Post RunAsync Handlers (#3063)
### 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. --> #3038 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Roger Barreto <[email protected]> Co-authored-by: Dmytro Struk <[email protected]> |
||
|
|
965c23d374 |
Python: Fixed type error in plan.run_next_step_async method (#3231)
### Description This PR fixes #3219 ### Contribution Checklist - [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 - [X] I didn't break anyone 😄 --------- Co-authored-by: Dmytro Struk <[email protected]> |
||
|
|
85ee34b924 |
Python: Implement Function calling for Chat (#2356)
### 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. --> I built support for function calling into SK! Related to/fixes: - #2315 - #2175 - #1450 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> This implementation builds on top of all the existing pieces, but did require some major work, so feel free to comment on where that is or is not appropriate. - Added a `ChatMessage` class to capture the relevant pieces of function calling (name and content) - Added a `complete_chat_with_functions_async` into OpenAIChatCompletions class - Added a `function_call` field to ChatRequestSettings class - Added several helper functions and smaller changes - Added a sample with updated core_skill that uses function calling to demonstrate - Added a second sample that shows how to use function_calling with non-sk functions. ### 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 - [x] I didn't break anyone 😄 --------- Co-authored-by: Abby Harrison <[email protected]> |
||
|
|
45f492aa89 |
Python: Enforcing return typehints on native functions (#2948)
### 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. --> This solves [this issue](https://github.com/microsoft/semantic-kernel/issues/1069) where native functions are not returning the expected result. In python, return typehints are optional. However, the semantic kernel requires a return typehint to determine how to handle the function. For that reason, we're now enforcing return typehints and raising an exception when one is not provided. This may break existing void functions but none in our repo are affected. Fixes #1069 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 😄 ## Summary This pull request includes two sets of changes. First, it fixes the return type annotations in three core skills: file_io_skill, text_memory_skill, and wait_skill. Specifically, the write_async method in file_io_skill and the save_async method in text_memory_skill now have a return type of None, and the wait method in wait_skill now has a return type of None. Additionally, the import_native_skill_from_directory method in kernel.py has been refactored to simplify the code. Second, this pull request adds error handling for functions with no return type in the delegate inference module. Previously, if a function did not specify a return type, the DelegateType could not be inferred, leading to errors. This pull request adds a check for functions with no return type and raises a KernelException with an appropriate error message. Additionally, this pull request includes some minor changes to unit tests for native functions. ## Changes - Fixed return type annotation for write_async method in file_io_skill - Fixed return type annotation for save_async method in text_memory_skill - Fixed return type annotation for wait method in wait_skill - Refactored import_native_skill_from_directory method in kernel.py - Added error handling for functions with no return type in the delegate inference module - Added a check for functions with no return type and raised a KernelException with an appropriate error message - Made minor changes to unit tests for native functions --- *Powered by [Microsoft Semantic Kernel](https://github.com/microsoft/semantic-kernel)* |
||
|
|
f251e654ec |
Python: Enable serialization for sk/orchestration (#2369)
SKFunction has been excluded for now. Handles issues arising due to many circular imports Update DelegateInference to handle some cases where annotation is given as a string to avoid circular imports like in FileIOSkill. ### 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. --> ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### 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 - [x] I didn't break anyone 😄 --------- Co-authored-by: Abby Harrison <[email protected]> Co-authored-by: Mark Karle <[email protected]> Co-authored-by: Abby Harrison <[email protected]> Co-authored-by: Lee Miller <[email protected]> Co-authored-by: Devis Lucato <[email protected]> |
||
|
|
4bc5ff716d |
Python: provide methods to register single native function to the kernel (#2390)
### 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. --> solve #2321 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Abby Harrison <[email protected]> Co-authored-by: Abby Harrison <[email protected]> Co-authored-by: Lee Miller <[email protected]> |
||
|
|
67dfb4c1f5 |
Python: add invoke_stream_async for SKFunction (#2200)
### 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. --> while implementing #1691, there was an idea that adding `invoke_stream_async` on `SKFunction` is reasonable. <img width="870" alt="image" src="https://github.com/microsoft/semantic-kernel/assets/69464062/44278d30-66b2-41d2-8c9f-c1daea50b331"> ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> moved temporal streaming logic from `Kernel` to `SKFunction` I didn't want to add new `DelegateTypes` like `InStringOutStreaming` for minimal changes. in most cases, `SKFunction` is initiated from `from_semantic_config` or `from_native_method`. Now, both functions will handle the 'delegate_stream_function' argument, which will be used in `invoke_stream_async` ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Abby Harrison <[email protected]> |
||
|
|
2733a5574f |
Python: Import OpenAPI documents into the semantic kernel (#2297)
### 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. --> This allows us to import OpenAPI documents, including ChatGPT plugins, into the Semantic Kernel. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> - The interface reads the operationIds of the openapi spec into a skill: ```python from semantic_kernel.connectors.openapi import register_openapi_skill skill = register_openapi_skill(kernel=kernel, skill_name="test", openapi_document="url/or/path/to/openapi.yamlorjson") skill['operationId'].invoke_async() ``` - Parse an OpenAPI document - For each operation in the document, create a function that will execute the operation - Add all those operations to a skill in the kernel - Modified `import_skill` to accept a dictionary of functions instead of just class so that we can import dynamically created functions - Created unit tests TESTING: I've been testing this with the following ChatGPT plugins: - [Semantic Kernel Starter's Python Flask plugin](https://github.com/microsoft/semantic-kernel-starters/tree/main/sk-python-flask) - [ChatGPT's example retrieval plugin](https://github.com/openai/chatgpt-retrieval-plugin/blob/main/docs/providers/azuresearch/setup.md) - This one was annoying to setup. I didn't get the plugin functioning, but I was able to send the right API requests - Also, their openapi file was invalid. The "servers" attribute is misindented - [Google ChatGPT plugin](https://github.com/Sogody/google-chatgpt-plugin) - [Chat TODO plugin](https://github.com/lencx/chat-todo-plugin) - This openapi file is also invalid. I checked with an online validator. I had to remove"required" from the referenced request objects' properties: https://github.com/lencx/chat-todo-plugin/blob/main/openapi.yaml#L85 Then I used this python file to test the examples: ```python import asyncio import logging import semantic_kernel as sk from semantic_kernel import ContextVariables, Kernel from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion from semantic_kernel.connectors.openapi.sk_openapi import register_openapi_skill # Example usage chatgpt_retrieval_plugin = { "openapi": # location of the plugin's openapi.yaml file, "payload": { "queries": [ { "query": "string", "filter": { "document_id": "string", "source": "email", "source_id": "string", "author": "string", "start_date": "string", "end_date": "string", }, "top_k": 3, } ] }, "operation_id": "query_query_post", } sk_python_flask = { "openapi": # location of the plugin's openapi.yaml file, "path_params": {"skill_name": "FunSkill", "function_name": "Joke"}, "payload": {"input": "dinosaurs"}, "operation_id": "executeFunction", } google_chatgpt_plugin = { "openapi": # location of the plugin's openapi.yaml file, "query_params": {"q": "dinosaurs"}, "operation_id": "searchGet", } todo_plugin_add = { "openapi": # location of the plugin's openapi.yaml file, "path_params": {"username": "markkarle"}, "payload": {"todo": "finish this"}, "operation_id": "addTodo", } todo_plugin_get = { "openapi": # location of the plugin's openapi.yaml file, "path_params": {"username": "markkarle"}, "operation_id": "getTodos", } todo_plugin_delete = { "openapi": # location of the plugin's openapi.yaml file, "path_params": {"username": "markkarle"}, "payload": {"todo_idx": 0}, "operation_id": "deleteTodo", } plugin = todo_plugin_get # set this to the plugin you want to try logger = logging.getLogger(__name__) logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.DEBUG) kernel = Kernel(log=logger) deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env() kernel.add_text_completion_service( "dv", AzureTextCompletion(deployment, endpoint, api_key) ) skill = register_openapi_skill( kernel=kernel, skill_name="test", openapi_document=plugin["openapi"] ) context_variables = ContextVariables(variables=plugin) result = asyncio.run( skill[plugin["operation_id"]].invoke_async(variables=context_variables) ) print(result) ``` ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Abby Harrison <[email protected]> |
||
|
|
ff2ba072a4 |
Python: temporal kernel run stream async (#1691)
### 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. --> Temporal solution for #1606 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) - [ ] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with `dotnet format` - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Shawn Callegari <[email protected]> Co-authored-by: Abby Harrison <[email protected]> Co-authored-by: Abby Harrison <[email protected]> |
||
|
|
b2e1548379 |
Python: Multiple results per prompt (incl. streaming) (#1316)
### Motivation and Context To take advantage of APIs offered by most LLMs and to be in sync with .NET SK, this PR introduces the ability to generate multiple text completions or chat completions from a single prompt.  ### Description - Return type hint for `complete_async` and `complete_chat_async` changed from `str -> Union[str, List[str]]`. The use of `Union` is the proper way to indicate multiple return types prior to Python 3.10+. 3.10 supports the use of the `|` symbol, but since the Python SK is supported on 3.8 and 3.9, I did not adopt the newer standard. - `complete_async`, `complete_stream_async`, `complete_chat_async`, and `complete_chat_stream_async` now support settings field `number_of_responses` greater than 1. Previously only a value of 1 was supported. - **Note: hf_text_completion does not support streaming multiple responses due to a limitation of TextIteratorStreamer. This feature requires the ability to parse distinct responses from TextIteratorStreamer.** - Fixed a bug where `complete_async` was streaming single responses as 1D arrays, content now is simply a string. ### Example Usage #### Setup ``` kernel = sk.Kernel() # Configure OpenAI service api_key, org_id = sk.openai_settings_from_dot_env() oai_text_service = OpenAITextCompletion("text-davinci-003", api_key, org_id) oai_chat_service = OpenAIChatCompletion("gpt-3.5-turbo", api_key, org_id) # Configure Hugging Face service hf_text_service = HuggingFaceTextCompletion("gpt2", task="text-generation") # Configure Prompt prompt = "what is the purpose of a rubber duck?" # Configure Request Settings text_request_settings_multi = CompleteRequestSettings( max_tokens=100, temperature=0.7, top_p=1, frequency_penalty=0.5, presence_penalty=0.8, number_of_responses=4 ) chat_request_settings_multi = ChatRequestSettings( max_tokens=100, temperature=0.7, top_p=1, frequency_penalty=0.5, presence_penalty=0.8, number_of_responses=4 ) ``` #### Text Completion (Standard) ``` texts = await oai_text_service.complete_async(prompt, text_request_settings_multi) i = 0 for text in texts: print("Option " + str(i) + ": " + text) i += 1 ``` #### Streaming Text Completion ``` multi_stream = oai_text_service.complete_stream_async(prompt, text_request_settings_multi) texts = [''] * text_request_settings_multi.number_of_responses async for text in multi_stream: i = 0 os.system('cls' if os.name == 'nt' else 'clear') # clear the screen for a better experience print("PROMPT: " + prompt) for option in text: texts[i] = texts[i] + option print("{0}: {1}".format(i, texts[i])) i += 1 ``` #### Chat Completion (Standard) ``` texts = await oai_chat_service.complete_chat_async([("user",prompt)], chat_request_settings_multi) i = 0 for text in texts: print("Option " + str(i) + ": " + text) i += 1 ``` #### Streaming Chat Completion ``` multi_stream = oai_chat_service.complete_chat_stream_async([("user",prompt)], chat_request_settings_multi) texts = [''] * chat_request_settings_multi.number_of_responses async for text in multi_stream: i = 0 os.system('cls' if os.name == 'nt' else 'clear') # clear the screen for a better experience print("PROMPT: " + prompt) for option in text: texts[i] = texts[i] + option print("{0}: {1}".format(i, texts[i])) i += 1 ``` #### HuggingFace Standard Completion ``` texts = await hf_text_service.complete_async(prompt, request_settings_multi) i = 0 for text in texts: print("-----------------------------------") print("Option " + str(i) + ": " + text) i += 1 ``` |
||
|
|
7a884d4e57 |
Python: make abstraction usage consistent (#1052)
### Motivation and Context Use of abstraction was not consistent in the python SK. This PR makes the import and use of ABC consistent and removes unused file kernel.py. ### Description - MemoryStoreBase derives from ABC - this properly sets its metaclass. MemoryStoreBase itself should never be instantiated, only derived. - RetryMechanism derives ABC, so should be named 'Base' like all other derivatives of ABC in this repo. - removed kernel_base.py, was made obsolete by https://github.com/microsoft/semantic-kernel/pull/1015 |
||
|
|
493dfc1b61 |
Python: Merge Kernel, KernelBase, KernelExtensions (#1015)
### Motivation and Context The separation of Kernel, KernelBase, and KernelExtensions is several layers of unnecessary abstraction. This PR does not change any API or kernel behavior - it just reduces the number of files and namespaces to accomplish the same functionality. ### Description - Removed the `semantic_kernel/kernel_extensions` namespace. Methods that existed in this namespace now exist in kernel.py. - Removed KernelBase - this abstract class implies that there are multiple ways to instantiate SK. For Python, we expect only a single type of Kernel to instantiated for all instances. - Updated tests and imports to accommodate the above changes. |
||
|
|
de3436d02f |
Python: fixes and release (#855)
* Fix lint errors * Bump version number * Add retry loop to integration tests * Enable all integration tests: some tests will fail if OpenAI/Azure are throttling. |