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.utils.common

TempDirectoryPath Objects

class TempDirectoryPath(str)

Represents a path to an temporary directory. When used as a context manager, it erases the contents of the directory on exit.

read_global_config

read_global_config(path: Text) -> Dict[Text, Any]

Read global Rasa configuration.

Arguments:

  • path - Path to the configuration

Returns:

The global configuration

set_log_level

set_log_level(log_level: Optional[int] = None) -> None

Set log level of Rasa and Tensorflow either to the provided log level or to the log level specified in the environment variable 'LOG_LEVEL'. If none is set a default log level will be used.

update_tensorflow_log_level

update_tensorflow_log_level() -> None

Sets Tensorflow log level based on env variable 'LOG_LEVEL_LIBRARIES'.

update_sanic_log_level

update_sanic_log_level(log_file: Optional[Text] = None) -> None

Set the log level of sanic loggers to the log level specified in the environment variable 'LOG_LEVEL_LIBRARIES'.

update_asyncio_log_level

update_asyncio_log_level() -> None

Set the log level of asyncio to the log level specified in the environment variable 'LOG_LEVEL_LIBRARIES'.

update_matplotlib_log_level

update_matplotlib_log_level() -> None

Set the log level of matplotlib to the log level specified in the environment variable 'LOG_LEVEL_LIBRARIES'.

set_log_and_warnings_filters

set_log_and_warnings_filters() -> None

Set log filters on the root logger, and duplicate filters for warnings.

Filters only propagate on handlers, not loggers.

sort_list_of_dicts_by_first_key

sort_list_of_dicts_by_first_key(dicts: List[Dict]) -> List[Dict]

Sorts a list of dictionaries by their first key.

write_global_config_value

write_global_config_value(name: Text, value: Any) -> bool

Read global Rasa configuration.

Arguments:

  • name - Name of the configuration key
  • value - Value the configuration key should be set to

Returns:

True if the operation was successful.

read_global_config_value

read_global_config_value(name: Text, unavailable_ok: bool = True) -> Any

Read a value from the global Rasa configuration.

update_existing_keys

update_existing_keys(original: Dict[Any, Any], updates: Dict[Any, Any]) -> Dict[Any, Any]

Iterate through all the updates and update a value in the original dictionary.

If the updates contain a key that is not present in the original dict, it will be ignored.

RepeatedLogFilter Objects

class RepeatedLogFilter(logging.Filter)

Filter repeated log records.

filter

| filter(record: logging.LogRecord) -> bool

Determines whether current log is different to last log.

run_in_loop

run_in_loop(f: Coroutine[Any, Any, T], loop: Optional[asyncio.AbstractEventLoop] = None) -> T

Execute the awaitable in the passed loop.

If no loop is passed, the currently existing one is used or a new one is created if no loop has been started in the current context.

After the awaitable is finished, all remaining tasks on the loop will be awaited as well (background tasks).

WARNING: don't use this if there are never ending background tasks scheduled. in this case, this function will never return.

Arguments:

  • f - function to execute
  • loop - loop to use for the execution

Returns:

return value from the function

call_potential_coroutine

async call_potential_coroutine(coroutine_or_return_value: Union[Any, Coroutine]) -> Any

Awaits coroutine or returns value directly if it's not a coroutine.

Arguments:

  • coroutine_or_return_value - Either the return value of a synchronous function call or a coroutine which needs to be await first.

Returns:

The return value of the function.