Extra Handler#
Extra handlers are functions that are executed before or after a
PipelineComponent
.
- class ComponentExtraHandler(**data)[source]#
Bases:
BaseModel
,ABC
Class, representing an extra handler for pipeline components.
A component extra handler is a set of functions, attached to pipeline component (before or after it). Extra handlers should execute supportive tasks (like time or resources measurement, minor data transformations).
- functions: List[ExtraHandlerFunction]#
A list or instance of
ExtraHandlerFunction
.
- stage: ClassVar[ExtraHandlerType]#
An
ExtraHandlerType
, specifying whether this handler will be executed before or after pipeline component.
- timeout: Optional[float]#
Maximum component execution time (in seconds), if it exceeds this time, it is interrupted.
- concurrent: bool#
A flag that indicates whether the extra handler’s functions should be executed concurrently. False by default.
- classmethod functions_validator(data)[source]#
Add support for initializing from a Callable or List[Callable]. Casts functions to list if it’s not already.
- async _run(ctx, component_info)[source]#
Method for executing one of the extra handler functions (before or after). If the function is not set, nothing happens.
- Parameters:
ctx (
Context
) – current dialog context.component_info (
PipelineComponent
) – associated component’s self object.
- Returns:
None
- async __call__(ctx, component_info)[source]#
A method for calling an extra handler. It sets up a timeout and executes it using _run method.
- Parameters:
ctx (
Context
) – (required) Current dialog Context.component_info (
PipelineComponent
) – associated component’s self object.
- class BeforeHandler(**data)[source]#
Bases:
ComponentExtraHandler
A handler for extra functions that are executed before the component’s main function.
- Parameters:
functions (List[ExtraHandlerFunction]) – A list of callables that will be executed before the component’s main function.
timeout – Optional timeout for the execution of the extra functions, in seconds.
concurrent – Optional flag that indicates whether the extra functions should be executed concurrently. False by default.
- stage: ClassVar[ExtraHandlerType] = 'BEFORE'#
An
ExtraHandlerType
, specifying whether this handler will be executed before or after pipeline component.
- class AfterHandler(**data)[source]#
Bases:
ComponentExtraHandler
A handler for extra functions that are executed after the component’s main function.
- Parameters:
functions (List[ExtraHandlerFunction]) – A list of callables that will be executed after the component’s main function.
timeout – Optional timeout for the execution of the extra functions, in seconds.
concurrent – Optional flag that indicates whether the extra functions should be executed concurrently. False by default.
- stage: ClassVar[ExtraHandlerType] = 'AFTER'#
An
ExtraHandlerType
, specifying whether this handler will be executed before or after pipeline component.
- ComponentExtraHandlerInitTypes#
Types that
ComponentExtraHandler
can be validated from.alias of
Union
[ComponentExtraHandler
, typing.Annotated[dict, ‘dict following the ComponentExtraHandler data model’],Callable
[Callable
],List
[Callable
][List
[Callable
]]]