notice

This is documentation for Rasa Documentation v2.x, which is no longer actively maintained.
For up-to-date documentation, see the latest version (3.x).

Version: 2.x

rasa.core.utils

configure_file_logging

configure_file_logging(logger_obj: logging.Logger, log_file: Optional[Text]) -> None

Configure logging to a file.

Arguments:

  • logger_obj - Logger object to configure.
  • log_file - Path of log file to write to.

one_hot

one_hot(hot_idx: int, length: int, dtype: Optional[Text] = None) -> np.ndarray

Create a one-hot array.

Arguments:

  • hot_idx - Index of the hot element.
  • length - Length of the array.
  • dtype - numpy.dtype of the array.

Returns:

One-hot array.

dump_obj_as_yaml_to_file

dump_obj_as_yaml_to_file(filename: Union[Text, Path], obj: Any, should_preserve_key_order: bool = False) -> None

Writes obj to the filename in YAML repr.

Arguments:

  • filename - Target filename.
  • obj - Object to dump.
  • should_preserve_key_order - Whether to preserve key order in obj.

list_routes

list_routes(app: Sanic) -> Text

List all the routes of a sanic application.

Mainly used for debugging.

extract_args

extract_args(kwargs: Dict[Text, Any], keys_to_extract: Set[Text]) -> Tuple[Dict[Text, Any], Dict[Text, Any]]

Go through the kwargs and filter out the specified keys.

Return both, the filtered kwargs as well as the remaining kwargs.

is_limit_reached

is_limit_reached(num_messages: int, limit: Optional[int]) -> bool

Determine whether the number of messages has reached a limit.

Arguments:

  • num_messages - The number of messages to check.
  • limit - Limit on the number of messages.

Returns:

True if the limit has been reached, otherwise False.

file_as_bytes

file_as_bytes(path: Text) -> bytes

Read in a file as a byte array.

AvailableEndpoints Objects

class AvailableEndpoints()

Collection of configured endpoints.

read_endpoints_from_path

read_endpoints_from_path(endpoints_path: Union[Path, Text, None] = None) -> AvailableEndpoints

Get AvailableEndpoints object from specified path.

Arguments:

  • endpoints_path - Path of the endpoints file to be read. If None the default path for that file is used (endpoints.yml).

Returns:

AvailableEndpoints object read from endpoints file.

replace_floats_with_decimals

replace_floats_with_decimals(obj: Any, round_digits: int = 9) -> Any

Convert all instances in obj of float to Decimal.

Arguments:

  • obj - Input object.
  • round_digits - Rounding precision of Decimal values.

Returns:

Input obj with all float types replaced by Decimals rounded to round_digits decimal places.

DecimalEncoder Objects

class DecimalEncoder(json.JSONEncoder)

json.JSONEncoder that dumps Decimals as floats.

default

| default(obj: Any) -> Any

Get serializable object for o.

Arguments:

  • obj - Object to serialize.

Returns:

obj converted to float if o is a Decimals, else the base class default() method.

replace_decimals_with_floats

replace_decimals_with_floats(obj: Any) -> Any

Convert all instances in obj of Decimal to float.

Arguments:

  • obj - A List or Dict object.

Returns:

Input obj with all Decimal types replaced by floats.

number_of_sanic_workers

number_of_sanic_workers(lock_store: Union[EndpointConfig, LockStore, None]) -> int

Get the number of Sanic workers to use in app.run().

If the environment variable constants.ENV_SANIC_WORKERS is set and is not equal to 1, that value will only be permitted if the used lock store is not the InMemoryLockStore.