mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 11:19:56 +00:00
84a75eca86b90c30a0ebcffb36f554b8ede0cb18
5
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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 😄 |
||
|
|
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]> |
||
|
|
78a4333e79 |
.Net OpenAPI -> OpenApi Naming Change (#4100)
Resolves #3765 |
||
|
|
e1595f4b30 |
Python: fixes for openapi sample (#2655)
### 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 tried the openapi sample, didn't work because the context variables check if the values are strings, otherwise breaks. Now using strings, and parsing those in the openapi runner. ### Description Parse the required values in the openapi runner and updated the sample to use a string of a dict. <!-- 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]> |
||
|
|
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]> |