Service#

The Service module contains the Service class which represents a single task.

Pipeline consists of services and service groups. Service is an atomic part of a pipeline.

Service can be asynchronous only if its handler is a coroutine. Actor wrapping service is asynchronous.

class Service(**data)[source]#

Bases: PipelineComponent

This class represents a service.

Service can be asynchronous only if its handler is a coroutine.

handler: ServiceFunction#

A ServiceFunction.

before_handler: BeforeHandler#

BeforeHandler, associated with this component.

after_handler: AfterHandler#

AfterHandler, associated with this component.

timeout: Optional[float]#

(for asynchronous only!) Maximum component execution time (in seconds), if it exceeds this time, it is interrupted.

requested_async_flag: Optional[bool]#

Requested asynchronous property; if not defined, calculated_async_flag is used instead.

start_condition: StartConditionCheckerFunction#

StartConditionCheckerFunction that is invoked before each component execution; component is executed only if it returns True.

name: Optional[str]#

Component name (should be unique in a single ServiceGroup), should not be blank or contain the . character.

path: Optional[str]#

Separated by dots path to component, is universally unique.

classmethod handler_validator(data)[source]#

Add support for initializing from a Callable.

async run_component(ctx, pipeline)[source]#

Method for running this service. Service ‘handler’ has three possible signatures, so this method picks the right one to invoke. These possible signatures are:

  • (ctx: Context) - accepts current dialog context only.

  • (ctx: Context, pipeline: Pipeline) - accepts context and current pipeline.

  • (ctx: Context, pipeline: Pipeline, info: ServiceRuntimeInfo) - accepts context, pipeline and service runtime info dictionary.
Parameters:
  • ctx (Context) – Current dialog context.

  • pipeline (Pipeline) – The current pipeline.

Return type:

None

Returns:

None

property computed_name: str#

Default name that is used if name is not defined. In case two components in a ServiceGroup have the same computed_name an incrementing number is appended to the name.

property info_dict: dict#

See Component.info_dict property. Adds handler key to base info dictionary.

to_service(before_handler=None, after_handler=None, timeout=None, asynchronous=None, start_condition=<function always_start_condition>, name=None)[source]#

Function for decorating a function as a Service. Returns a Service, constructed from this function (taken as a handler). All arguments are passed directly to Service constructor.

ServiceInitTypes#

Types that Service can be validated from.

alias of Union[Service, typing.Annotated[dict, ‘dict following the Service data model’], Callable[Callable]]