nemoguardrails.colang

View as Markdown

Subpackages

Submodules

Package Contents

Functions

NameDescription
_is_colang_v2Checks if the content of a file is in Colang 2.x format.
parse_colang_fileParse the content of a .co file into the CoYML format.
parse_flow_elementsParse the flow elements from CoYML format to CIL.

Data

log

API

nemoguardrails.colang._is_colang_v2(
content
)

Checks if the content of a file is in Colang 2.x format.

This function uses a simple heuristic to determine if the content is a Colang 2.x file. Initially, it removes comments and content within triple quotes, as these could potentially contain misleading keywords. Then, it checks for the presence of certain keywords in the content:

  • If the keyword import is present, the content is likely a Colang 2.x file.
  • If the keyword define is present at the beginning of a line, the content is likely a Colang 1.0 file.

Parameters:

content
str

The content of the file to check.

Returns:

True if the content is likely a Colang 2.x file, False otherwise.

nemoguardrails.colang.parse_colang_file(
filename: str,
content: str,
include_source_mapping: bool = True,
version: str = '1.0'
)

Parse the content of a .co file into the CoYML format.

nemoguardrails.colang.parse_flow_elements(
items,
version: str = '1.0'
)

Parse the flow elements from CoYML format to CIL.

nemoguardrails.colang.log = logging.getLogger(__name__)