notice
This is documentation for Rasa Open Source Documentation v2.1.x, which is no longer actively maintained.
For up-to-date documentation, see the latest version (2.5.x).
rasa.core.utils
configure_file_logging
Configure logging to a file.
Arguments:
logger_obj
- Logger object to configure.log_file
- Path of log file to write to.
is_int
Checks if a value is an integer.
The type of the value is not important, it might be an int or a float.
one_hot
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.
HashableNDArray Objects
Hashable wrapper for ndarray objects.
Instances of ndarray are not hashable, meaning they cannot be added to sets, nor used as keys in dictionaries. This is by design - ndarray objects are mutable, and therefore cannot reliably implement the hash() method.
The hashable class allows a way around this limitation. It implements the required methods for hashable objects in terms of an encapsulated ndarray object. This can be either a copied instance (which is safer) or the original object (which requires the user to be careful enough not to modify it).
__init__
Creates a new hashable object encapsulating an ndarray.
wrapped The wrapped ndarray.
tight Optional. If True, a copy of the input ndaray is created. Defaults to False.
unwrap
Returns the encapsulated ndarray.
If the wrapper is "tight", a copy of the encapsulated ndarray is returned. Otherwise, the encapsulated ndarray itself is returned.
dump_obj_as_yaml_to_file
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 inobj
.
list_routes
List all the routes of a sanic application.
Mainly used for debugging.
extract_args
Go through the kwargs and filter out the specified keys.
Return both, the filtered kwargs as well as the remaining kwargs.
is_limit_reached
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
.
read_lines
Read messages from the command line and print bot responses.
file_as_bytes
Read in a file as a byte array.
convert_bytes_to_string
Convert data
to string if it is a bytes-like object.
get_file_hash
Calculate the md5 hash of a file.
download_file_from_url
Download a story file from a url and persists it into a temp file.
Arguments:
url
- url to download from
Returns:
The file path of the temp file that contains the downloaded content.
pad_lists_to_size
Compares list sizes and pads them to equal length.
AvailableEndpoints Objects
Collection of configured endpoints.
read_endpoints_from_path
Get AvailableEndpoints
object from specified path.
Arguments:
endpoints_path
- Path of the endpoints file to be read. IfNone
the default path for that file is used (endpoints.yml
).
Returns:
AvailableEndpoints
object read from endpoints file.
set_default_subparser
default subparser selection. Call after setup, just before parse_args()
parser: the name of the parser you're making changes to default_subparser: the name of the subparser to call by default
create_task_error_logger
Error logger to be attached to a task.
This will ensure exceptions are properly logged and won't get lost.
replace_floats_with_decimals
Convert all instances in obj
of float
to Decimal
.
Arguments:
obj
- Input object.round_digits
- Rounding precision ofDecimal
values.
Returns:
Input obj
with all float
types replaced by Decimal
s rounded to
round_digits
decimal places.
DecimalEncoder Objects
json.JSONEncoder
that dumps Decimal
s as float
s.
default
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
Convert all instances in obj
of Decimal
to float
.
Arguments:
obj
- AList
orDict
object.
Returns:
Input obj
with all Decimal
types replaced by float
s.
number_of_sanic_workers
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
.