Files
semantic-kernel/python/semantic_kernel/kernel_exception.py
T
Abby HarrisonandShawn Callegari 5e4e0edfaa Python: Plan Object Model (#1907)
### Motivation and Context
This PR ports the plan object model found in the .NET SK to Python. This
fundamentally changes the concept of a planner from a `semantic skill`
to a unique type of `SKFunction`. With this model, we can begin
implementing sequential planner and offer much better plan
customization.

**Notes:**
- This PR does not implement plan serialization/deserialization to/from
JSON. There is a huge existing effort to make the Python SK completely
Pydantic enabled, which will bring serialization and deserialization
capability with it.
- This PR does not include ports of `Action Planner` and `Sequential
Planner` to the Plan Object Model (POM). Following PRs will address
this.
- I also added some missing copywrite headers. A future PR will add
headers to any still missing them.
- added a VSCode launch configuration to run the current file with
pytest
- closes #1486 


### Description
- Added file called `plan.py` which is a python port of the Plan.cs file
found in the .NET SK. Note that it does not contain serialization logic
at this time.
- Added new kernel error `FunctionInvokeError` - mirrors the error list
of the .NET SK
- Added tests for Plan creation
- Added tests for Plan execution - both sync and async


### 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]>
2023-07-15 01:34:19 +00:00

59 lines
1.7 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
from enum import Enum
from typing import Optional
class KernelException(Exception):
class ErrorCodes(Enum):
# Unknown error.
UnknownError = -1
# Invalid function description.
InvalidFunctionDescription = 0
# Function overload not supported.
FunctionOverloadNotSupported = 1
# Function not available.
FunctionNotAvailable = 2
# Function type not supported.
FunctionTypeNotSupported = 3
# Invalid function type.
InvalidFunctionType = 4
# Invalid service configuration.
InvalidServiceConfiguration = 5
# Service not found.
ServiceNotFound = 6
# Skill collection not set.
SkillCollectionNotSet = 7
# Represents an error that occurs when invoking a function.
FunctionInvokeError = 8
# Ambiguous implementation.
AmbiguousImplementation = 9
# The error code.
_error_code: ErrorCodes
def __init__(
self,
error_code: ErrorCodes,
message: str,
inner_exception: Optional[Exception] = None,
) -> None:
"""Initializes a new instance of the KernelError class.
Arguments:
error_code {ErrorCodes} -- The error code.
message {str} -- The error message.
inner_exception {Exception} -- The inner exception.
"""
super().__init__(error_code, message, inner_exception)
self._error_code = error_code
@property
def error_code(self) -> ErrorCodes:
"""Gets the error code.
Returns:
ErrorCodes -- The error code.
"""
return self._error_code