-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: OpenAPI plugin updates to promote plugin to preview (#9670)
### Motivation and Context We currently handle OpenAPI plugins via the kernel, but in a pretty simple way. The changes in this PR are allowing one to define multiple server paths for an operation as well as configure security on the operations either at the operation level or at the "global" spec level (these are included as metadata in the kernel function parameter `additional_parameters` dict). The OpenAPI plugin is graduating from an experimental state to a preview state. This, in turn, removes the `experimental` tag from some public facing methods. In the near future, all `experimental` tags will be removed once we're confident there are no other underlying changes required. Closes #9719 <!-- 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 Adds support for OpenAPI plugin: - allow for multiple servers for an API operation - allows one to define security configuration at the spec level as well as per operation level - fixes a bug where the `excluded_operations` on the execution settings were never checked during REST API operation building - adds the deprecated tag to the `OpenAI plugin` code as it was deprecated by OpenAI and we never handled it in SK Python. - renames some model class to remove the `operation` portion of the name. - adds ability to specify a callback to be able to skip certain api operations based on name, method, or description - removes the experimental tag from public facing methods. - allows one to pass in a parsed OpenAPI spec to the plugin add method - 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 - [ ] I didn't break anyone 😄
- Loading branch information
Showing
41 changed files
with
1,557 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
|
||
from enum import Enum | ||
|
||
from semantic_kernel.utils.experimental_decorator import experimental_class | ||
|
||
|
||
@experimental_class | ||
class OperationExtensions(Enum): | ||
"""The operation extensions.""" | ||
|
||
METHOD_KEY = "method" | ||
OPERATION_KEY = "operation" | ||
INFO_KEY = "info" | ||
SECURITY_KEY = "security" | ||
SERVER_URLS_KEY = "server-urls" | ||
METADATA_KEY = "operation-extensions" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
python/semantic_kernel/connectors/openapi_plugin/models/rest_api_oauth_flow.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
from dataclasses import dataclass | ||
|
||
from semantic_kernel.utils.experimental_decorator import experimental_class | ||
|
||
|
||
@experimental_class | ||
@dataclass | ||
class RestApiOAuthFlow: | ||
"""Represents the OAuth flow used by the REST API.""" | ||
|
||
authorization_url: str | ||
token_url: str | ||
scopes: dict[str, str] | ||
refresh_url: str | None = None |
17 changes: 17 additions & 0 deletions
17
python/semantic_kernel/connectors/openapi_plugin/models/rest_api_oauth_flows.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
from dataclasses import dataclass | ||
|
||
from semantic_kernel.connectors.openapi_plugin.models.rest_api_oauth_flow import RestApiOAuthFlow | ||
from semantic_kernel.utils.experimental_decorator import experimental_class | ||
|
||
|
||
@experimental_class | ||
@dataclass | ||
class RestApiOAuthFlows: | ||
"""Represents the OAuth flows used by the REST API.""" | ||
|
||
implicit: RestApiOAuthFlow | None = None | ||
password: RestApiOAuthFlow | None = None | ||
client_credentials: RestApiOAuthFlow | None = None | ||
authorization_code: RestApiOAuthFlow | None = None |
Oops, something went wrong.