-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate the field instead of removing
- Loading branch information
1 parent
c986616
commit 0d06bb6
Showing
6 changed files
with
82 additions
and
1 deletion.
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
Empty file.
22 changes: 22 additions & 0 deletions
22
python/semantic_kernel/reliability/kernel_reliability_extension.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,22 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
import logging | ||
from abc import ABC | ||
|
||
from pydantic import Field | ||
from typing_extensions import deprecated | ||
|
||
from semantic_kernel.kernel_pydantic import KernelBaseModel | ||
from semantic_kernel.reliability.pass_through_without_retry import PassThroughWithoutRetry | ||
from semantic_kernel.reliability.retry_mechanism_base import RetryMechanismBase | ||
|
||
logger: logging.Logger = logging.getLogger(__name__) | ||
|
||
|
||
class KernelReliabilityExtension(KernelBaseModel, ABC): | ||
"""Kernel reliability extension.""" | ||
|
||
retry_mechanism: RetryMechanismBase = Field( | ||
default_factory=PassThroughWithoutRetry, | ||
deprecated=deprecated("retry_mechanism is deprecated; This property doesn't have any effect on the kernel."), | ||
) |
31 changes: 31 additions & 0 deletions
31
python/semantic_kernel/reliability/pass_through_without_retry.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,31 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
import logging | ||
from collections.abc import Awaitable, Callable | ||
from typing import TypeVar | ||
|
||
from semantic_kernel.kernel_pydantic import KernelBaseModel | ||
from semantic_kernel.reliability.retry_mechanism_base import RetryMechanismBase | ||
|
||
T = TypeVar("T") | ||
|
||
logger: logging.Logger = logging.getLogger(__name__) | ||
|
||
|
||
class PassThroughWithoutRetry(RetryMechanismBase, KernelBaseModel): | ||
"""A retry mechanism that does not retry.""" | ||
|
||
async def execute_with_retry(self, action: Callable[[], Awaitable[T]]) -> Awaitable[T]: | ||
"""Executes the given action with retry logic. | ||
Args: | ||
action (Callable[[], Awaitable[T]]): The action to retry on exception. | ||
Returns: | ||
Awaitable[T]: An awaitable that will return the result of the action. | ||
""" | ||
try: | ||
return action() | ||
except Exception as e: | ||
logger.warning(e, "Error executing action, not retrying") | ||
raise e |
26 changes: 26 additions & 0 deletions
26
python/semantic_kernel/reliability/retry_mechanism_base.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,26 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
import logging | ||
from abc import ABC, abstractmethod | ||
from collections.abc import Awaitable, Callable | ||
from typing import TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
logger: logging.Logger = logging.getLogger(__name__) | ||
|
||
|
||
class RetryMechanismBase(ABC): | ||
"""Base class for retry mechanisms.""" | ||
|
||
@abstractmethod | ||
async def execute_with_retry(self, action: Callable[[], Awaitable[T]]) -> Awaitable[T]: | ||
"""Executes the given action with retry logic. | ||
Args: | ||
action (Callable[[], Awaitable[T]]): The action to retry on exception. | ||
Returns: | ||
Awaitable[T]: An awaitable that will return the result of the action. | ||
""" | ||
pass |
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