runnable_mixin
Adapted from the Griptape AI Framework documentation.
T = TypeVar('T', bound='RunnableMixin')
module-attribute
Bases:
ABC, [`Generic[T]`](#griptape.mixins.runnable_mixin.T "typing.Generic")Attributes
Name | Type | Description |
---|---|---|
on_before_run | Optional[Callable[[T], None]] | Optional callback that is called at the very beginning of the run method. |
on_after_run | Optional[Callable[[T], None]] | Optional callback that is called at the very end of the run method. |
Source Code in griptape/mixins/runnable_mixin.py
@define() class RunnableMixin(ABC, Generic[T]): """Mixin for classes that can be "run". Implementing classes should pass themselves as the generic type to ensure that the correct type is used in the callbacks. Attributes: on_before_run: Optional callback that is called at the very beginning of the `run` method. on_after_run: Optional callback that is called at the very end of the `run` method. """ on_before_run: Optional[Callable[[T], None]] = field(kw_only=True, default=None) on_after_run: Optional[Callable[[T], None]] = field(kw_only=True, default=None) def before_run(self, *args, **kwargs) -> Any: if self.on_before_run is not None: self.on_before_run(cast("T", self)) @abstractmethod def run(self, *args, **kwargs) -> Any: ... def after_run(self, *args, **kwargs) -> Any: if self.on_after_run is not None: self.on_after_run(cast("T", self))
on_after_run = field(kw_only=True, default=None)
class-attribute instance-attributeon_before_run = field(kw_only=True, default=None)
class-attribute instance-attribute
after_run(*args, **kwargs)
Source Code in griptape/mixins/runnable_mixin.py
def after_run(self, *args, **kwargs) -> Any: if self.on_after_run is not None: self.on_after_run(cast("T", self))
before_run(*args, **kwargs)
Source Code in griptape/mixins/runnable_mixin.py
def before_run(self, *args, **kwargs) -> Any: if self.on_before_run is not None: self.on_before_run(cast("T", self))
run(*args, **kwargs)abstractmethod
Source Code in griptape/mixins/runnable_mixin.py
@abstractmethod def run(self, *args, **kwargs) -> Any: ...
Could this page be better? Report a problem or suggest an addition!