Script Function#
This module provides base classes for functions used in Script instances.
These functions allow dynamic script configuration and are essential to the scripting process.
- class BaseScriptFunc(**data)[source]#
Bases:
BaseModel,ABCBase class for any script function.
Defines
wrapped_call()that wrapscall()and handles exceptions and types conversions.- return_type: ClassVar[Union[type, Tuple[type, ...]]]#
Return type of the script function.
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__().- Returns:
An instance of
return_typeif possible. Otherwise, anExceptioninstance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call():Call it (regardless of whether it is async);
Cast returned value to
return_type.
- Returns:
An instance of
return_type.- Raises:
TypeError – If
call()returned value of incorrect type.
- class ConstScriptFunc(**data)[source]#
Bases:
BaseScriptFuncBase class for script functions that return a constant value.
- root: None#
Value to return.
- class BaseCondition(**data)[source]#
Bases:
BaseScriptFunc,ABCBase class for condition functions.
These are used in
chatsky.core.transition.Transition.cnd.- return_type#
alias of
bool
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__().- Return type:
Union[bool,Exception]- Returns:
An instance of
return_typeif possible. Otherwise, anExceptioninstance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call():Call it (regardless of whether it is async);
Cast returned value to
return_type.
- Return type:
bool- Returns:
An instance of
return_type.- Raises:
TypeError – If
call()returned value of incorrect type.
- async is_true(ctx, *, info='')[source]#
Same as
wrapped_call()but instead of exceptions returnFalse.- Return type:
bool
- class ConstCondition(**data)[source]#
Bases:
ConstScriptFunc,BaseCondition- root: bool#
Value to return.
- AnyCondition#
A type annotation that allows accepting both
ConstConditionandBaseConditionwhile validatingConstConditionif possible.alias of
Annotated[ConstCondition|BaseCondition, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode=’left_to_right’)])]
- class BaseResponse(**data)[source]#
Bases:
BaseScriptFunc,ABCBase class for response functions.
These are used in
chatsky.core.script.Node.response.- abstract async call(ctx)[source]#
Implement this to create a custom function.
- Return type:
Union[Message,dict,str]
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__().- Return type:
Union[Message,Exception]- Returns:
An instance of
return_typeif possible. Otherwise, anExceptioninstance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call():Call it (regardless of whether it is async);
Cast returned value to
return_type.
- Return type:
- Returns:
An instance of
return_type.- Raises:
TypeError – If
call()returned value of incorrect type.
- class ConstResponse(**data)[source]#
Bases:
ConstScriptFunc,BaseResponse- root: Message#
Value to return.
- AnyResponse#
A type annotation that allows accepting both
ConstResponseandBaseResponsewhile validatingConstResponseif possible.alias of
Annotated[ConstResponse|BaseResponse, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode=’left_to_right’)])]
- class BaseDestination(**data)[source]#
Bases:
BaseScriptFunc,ABCBase class for destination functions.
These are used in
chatsky.core.transition.Transition.dst.- return_type#
alias of
AbsoluteNodeLabel
- abstract async call(ctx)[source]#
Implement this to create a custom function.
- Return type:
Union[NodeLabel,str,Tuple[str,str],List[str],dict]
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__().- Return type:
Union[AbsoluteNodeLabel,Exception]- Returns:
An instance of
return_typeif possible. Otherwise, anExceptioninstance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call():Call it (regardless of whether it is async);
Cast returned value to
return_type.
- Return type:
- Returns:
An instance of
return_type.- Raises:
TypeError – If
call()returned value of incorrect type.
- class ConstDestination(**data)[source]#
Bases:
ConstScriptFunc,BaseDestination- root: NodeLabel#
Value to return.
- AnyDestination#
A type annotation that allows accepting both
ConstDestinationandBaseDestinationwhile validatingConstDestinationif possible.alias of
Annotated[ConstDestination|BaseDestination, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode=’left_to_right’)])]
- class BaseProcessing(**data)[source]#
Bases:
BaseScriptFunc,ABCBase class for processing functions.
These are used in
chatsky.core.script.Node.pre_transitionandchatsky.core.script.Node.pre_response.- return_type#
alias of
None
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__().- Return type:
Optional[Exception]- Returns:
An instance of
return_typeif possible. Otherwise, anExceptioninstance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call():Call it (regardless of whether it is async);
Cast returned value to
return_type.
- Return type:
None- Returns:
An instance of
return_type.- Raises:
TypeError – If
call()returned value of incorrect type.
- class BasePriority(**data)[source]#
Bases:
BaseScriptFunc,ABCBase class for priority functions.
These are used in
chatsky.core.transition.Transition.priority.Has several possible return types:
float: Transition successful with the corresponding priority;TrueorNone: Transition successful with thedefault_priority;False: Transition unsuccessful.
- return_type: ClassVar[Union[type, Tuple[type, ...]]] = (<class 'float'>, <class 'NoneType'>, <class 'bool'>)#
Return type of the script function.
- abstract async call(ctx)[source]#
Implement this to create a custom function.
- Return type:
Union[float,bool,None]
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__().- Return type:
Union[float,bool,None,Exception]- Returns:
An instance of
return_typeif possible. Otherwise, anExceptioninstance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call():Call it (regardless of whether it is async);
Cast returned value to
return_type.
- Return type:
Union[float,bool,None]- Returns:
An instance of
return_type.- Raises:
TypeError – If
call()returned value of incorrect type.
- class ConstPriority(**data)[source]#
Bases:
ConstScriptFunc,BasePriority- root: Optional[float]#
Value to return.
- AnyPriority#
A type annotation that allows accepting both
ConstPriorityandBasePrioritywhile validatingConstPriorityif possible.alias of
Annotated[ConstPriority|BasePriority, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode=’left_to_right’)])]