notice
This is unreleased documentation for Rasa Documentation Main/Unreleased version.
For the latest released documentation, see the latest version (3.x).
rasa.shared.utils.common
class_from_module_path
Given the module name and path of a class, tries to retrieve the class.
The loaded class can be used to instantiate new objects.
Arguments:
module_path
- either an absolute path to a Python class, or the name of the class in the local / global scope.lookup_path
- a path where to load the class from, if it cannot be found in the local / global scope.
Returns:
a Python class
Raises:
ImportError, in case the Python class cannot be found. RasaException, in case the imported result is something other than a class
all_subclasses
Returns all known (imported) subclasses of a class.
module_path_from_instance
Return the module path of an instance's class.
sort_list_of_dicts_by_first_key
Sorts a list of dictionaries by their first key.
lazy_property
Allows to avoid recomputing a property over and over.
The result gets stored in a local var. Computation of the property will happen once, on the first call of the property. All succeeding calls will use the value stored in the private property.
cached_method
Caches method calls based on the call's args
and kwargs
.
Works for async
and sync
methods. Don't apply this to functions.
Arguments:
f
- The decorated method whose return value should be cached.
Returns:
The return value which the method gives for the first call with the given arguments.
transform_collection_to_sentence
Transforms e.g. a list like ['A', 'B', 'C'] into a sentence 'A, B and C'.
minimal_kwargs
Returns only the kwargs which are required by a function. Keys, contained in the exception list, are not included.
Arguments:
kwargs
- All available kwargs.func
- The function which should be called.excluded_keys
- Keys to exclude from the result.
Returns:
Subset of kwargs which are accepted by func
.
mark_as_experimental_feature
Warns users that they are using an experimental feature.
arguments_of
Return the parameters of the function func
as a list of names.
extract_duplicates
Extracts duplicates from two lists.
clean_duplicates
Removes keys for empty values.
merge_dicts
Merges two dicts.
merge_lists
Merges two lists.
merge_lists_of_dicts
Merges two dict lists.