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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Even though there is no strict separation between errors and exceptions in Python, it is a good practice to use:
|
|
|
|
|
# - Exceptions for exceptional conditions that a reasonable application may wish to catch.
|
|
|
|
|
# - Errors for exceptional conditions that are not reasonable to catch.
|
|
|
|
|
# for instance syntax errors in a template should be called ...Error,
|
|
|
|
|
# while rendering of the same template should raise an ...Exception.
|
|
|
|
|
# every error should derive from KernelException (including errors)
|
|
|
|
|
# all raised exceptions should use the raise ... from exc syntax to preserve the original traceback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KernelException(Exception):
|
2024-08-05 18:33:49 +02:00
|
|
|
"""The base class for all Semantic Kernel exceptions."""
|
|
|
|
|
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KernelServiceNotFoundError(KernelException):
|
2024-08-05 18:33:49 +02:00
|
|
|
"""Raised when a service is not found in the kernel."""
|
|
|
|
|
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KernelPluginNotFoundError(KernelException):
|
2024-08-05 18:33:49 +02:00
|
|
|
"""Raised when a plugin is not found in the kernel."""
|
|
|
|
|
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
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 :smile:
2024-04-01 08:01:08 -07:00
|
|
|
class KernelPluginInvalidConfigurationError(KernelException):
|
2024-08-05 18:33:49 +02:00
|
|
|
"""Raised when a plugin configuration is invalid."""
|
|
|
|
|
|
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 :smile:
2024-04-01 08:01:08 -07:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
class KernelFunctionNotFoundError(KernelException):
|
2024-08-05 18:33:49 +02:00
|
|
|
"""Raised when a function is not found in the kernel."""
|
|
|
|
|
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KernelFunctionAlreadyExistsError(KernelException):
|
2024-08-05 18:33:49 +02:00
|
|
|
"""Raised when a function is already registered in the kernel."""
|
|
|
|
|
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KernelInvokeException(KernelException):
|
2024-08-05 18:33:49 +02:00
|
|
|
"""Raised when an error occurs while invoking a function in the kernel."""
|
|
|
|
|
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2024-05-17 23:05:56 +02:00
|
|
|
class OperationCancelledException(KernelException):
|
2024-08-05 18:33:49 +02:00
|
|
|
"""Raised when an operation is cancelled."""
|
|
|
|
|
|
2024-05-17 23:05:56 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
__all__ = [
|
|
|
|
|
"KernelException",
|
|
|
|
|
"KernelFunctionAlreadyExistsError",
|
|
|
|
|
"KernelFunctionNotFoundError",
|
|
|
|
|
"KernelInvokeException",
|
2024-05-31 15:06:41 +02:00
|
|
|
"KernelPluginInvalidConfigurationError",
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
"KernelPluginNotFoundError",
|
|
|
|
|
"KernelServiceNotFoundError",
|
2024-05-17 23:05:56 +02:00
|
|
|
"OperationCancelledException",
|
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 :smile:
2024-02-28 19:53:53 +01:00
|
|
|
]
|