nemoguardrails.cli.migration
Module Contents
Functions
Data
API
Adds an ‘@active’ decorator above each flow id in the new lines.
Parameters:
The lines to add the decorators to.
Returns: List
The lines with the decorators added.
Add the main co file to the given file path. Args: file_path (str): The path to the file to add the main co file to. libraries (list[str]): The list of libraries to import in the main co file. Returns: bool: True if the main co file was added successfully, False otherwise.
Appends the Colang version “2.x” at the end of the config file.
Check if the main co file exists in the directory of the file.
If the main co file does not exist, it creates an empty main co file in the directory of the given file.
Parameters:
The path to the file to check for the main co file.
Adds a ‘main’ flow to the new lines that activates all other flows.
The ‘main’ flow is added at the beginning of the new lines. It includes an ‘activate’ command for each flow id found in the new lines.
Examples: new_lines = [“flow my_flow”, “flow another_flow”] include_main_flow(new_lines)
'''flow main
activate my_flow
activate another_flow
Parameters:
The new lines to add the main flow to.
Returns: List
The new lines with the ‘main’ flow added at the beginning.
Generates flow definitions from the list of flows. Args: flows (dict): The dictionary of flows. Returns: str: The flow definitions.
Get a list of .co files to process.
Parameters:
The path to the file or directory to process.
Returns:
The list of .co files to process.
Get a list of .yaml or .yml files to process.
Parameters:
The path to the file or directory to process.
Returns:
The list of .yaml or .yml files to process.
Returns the flow ids in the content.
Args: content (str): The content to search for flow ids. Returns: list: A list of flow ids.
Examples: content = “flow my_flow” get_flow_ids(content)
[‘my_flow’]
content = “flow my_flow is better than flow another_flow” get_flow_ids(content)
[‘my_flow is better than’, ‘another_flow’]
flow user and flow bot are not considered as flow ids
content = “flow user express greeting” get_flow_ids(content)
[]
Returns the flow ids in the new lines. Args: new_lines (list): The new lines to search for flow ids. Returns: list: A list of flow ids. Examples: new_lines = [“flow my_flow is better than”, “flow another_flow”] get_flow_ids_from_newlines(new_lines)
[‘my_flow is better than’, ‘another_flow’]
Extracts the list of flows from the raw_config dictionary.
Parameters:
The raw configuration dictionary.
Returns:
The list of flows.
read the yaml file and get rails key
Checks if the flow is an anonymous flow.
an anonymous flow is a flow that does not start with a name. so it only has define flow without a name.
Returns: bool: True if the flow is anonymous, False otherwise. Examples:
flow_content = “flow ” is_anonymous_flow(flow_content)
True
flow_content = “flow my_flow” is_anonymous_flow(flow_content)
False
Parameters:
The content of the flow.
Checks if the line is a flow definition. it is a flow definition if it starts with “flow” and other words after flow.
Processes the Colang files in the given path.
It converts the Colang files from the given version to the latest version and writes the changes to the files.
Returns: int: The total number of files changed.
Parameters:
The list of Colang files to process.
The version of the Colang files to convert from.
Whether to include the main flow.
Whether to use the active decorator.
Whether to validate the files.
Processes the config files in the given path.
It extracts the rails flows from the config files and writes them to a new file.
Parameters:
The list of config files to process.
Returns: int
The total number of config files changed.
Processes the sample_conversation section in the config file.
Parameters:
The path to the config file.
Remove files from the path.
Parameters:
The path to the directory to remove files from.
The list of filenames to remove.
Revises an anonymous flow by giving it a unique name. Args: flow_content (str): The content of the anonymous flow. first_message (str): The first message in the flow. Returns: str: The revised flow content with a unique name.
Sets the ‘colang_version’ in the given raw_config.
Parameters:
The path to the config file.
The version to set.
Validates the file after the conversion.
It validates the file by parsing it and checking for any errors.
Parameters:
The path to the file to validate.
The new lines of the file after the conversion.
Raises:
Exception: If the validation fails.
Writes the rails flows to a file. Args: file_path (str): The path to the file to write to. rails_flows (list): The rails flows to write to the file.
Writes new lines to a file. If the file does not exist, it is created.
Parameters:
The path to the file to write to.
The new lines to write to the file.
Writes the transformed content to the file.
Converts a co file from v1 format to v2.
Returns: List: The new lines of the file after successful migration.
Parameters:
The lines of the file to convert.
Convert a co file form v2-alpha to v2-beta
Returns: List (str): The new lines of the file after successful migration.
Parameters:
The lines of the file to convert
Converts the sample_conversation section from the old format to the new format.
Parameters:
The lines of the sample_conversation to convert.
Returns: List[str]
List[str]: The new lines of the sample_conversation after conversion.
Migrates all .co files in a directory from the old format to the new format.
Parameters:
The path to the directory containing the files to migrate.
Whether to add main flow to the files.
Whether to use the active decorator.
The version of the colang files to convert from. Any of ‘1.0’ or ‘2.0-alpha’.
Whether to validate the files.