nemoguardrails.colang.v1_0.lang.coyml_parser

View as Markdown

Module for converting CoYML to the CIL.

Converts the Conversations YAML format to the Common Intermediate Language that is used by the coflows engine.

This also transpiles correctly to JS to be used on the client side.

Module Contents

Functions

NameDescription
_dict_to_elementHelper to turn a short-hand dictionary into an event structure.
_extract_elementsHelper to convert a list of items data to flow elements
_extract_inline_paramsHelper to extract inline parameters
_process_ellipsisHelper to process the ”…” element.
_resolve_gotosTransforms all goto into simple jumps.
_to_valueHelper that converts a str/dict to another value.
get_eventsHelper to convert a list of events data to ‘full events’
parse_flow_elementsParses the flow elements from CoYML format to CIL format.

Data

__all__

API

nemoguardrails.colang.v1_0.lang.coyml_parser._dict_to_element(
d
)

Helper to turn a short-hand dictionary into an event structure.

:param d: A dictionary in one of the supported formats :return:

nemoguardrails.colang.v1_0.lang.coyml_parser._extract_elements(
items: typing.List
) -> typing.List[dict]

Helper to convert a list of items data to flow elements

nemoguardrails.colang.v1_0.lang.coyml_parser._extract_inline_params(
d_value,
d_params
)

Helper to extract inline parameters

nemoguardrails.colang.v1_0.lang.coyml_parser._process_ellipsis(
elements
)

Helper to process the ”…” element.

The ”…” syntax is used as a syntactic sugar, to create more readable colang code. There will be multiple use cases for ”…”. The first one is for generate_value action.

  1. Generate Value

When the value of a variable is assigned to ”…”, we use the comment right above as instructions to generate the value.

1# Extract the math query from the user's input.
2$math_query = ...

will be replaced with

1$math_query = generate_value("Extract the math query from the user's input")
nemoguardrails.colang.v1_0.lang.coyml_parser._resolve_gotos(
elements: typing.List[dict]
) -> typing.List[dict]

Transforms all goto into simple jumps.

It does two things:

  • all goto are converted to relative jump elements
  • all checkpoint elements are converted to jump elements to the next
nemoguardrails.colang.v1_0.lang.coyml_parser._to_value(
s,
remove_quotes: bool = False
)

Helper that converts a str/dict to another value.

It does the following:

  • if the value is “None” it is converted to None

TODO: other useful value shorthands

nemoguardrails.colang.v1_0.lang.coyml_parser.get_events(
events_data: typing.List
)

Helper to convert a list of events data to ‘full events’

nemoguardrails.colang.v1_0.lang.coyml_parser.parse_flow_elements(
items
)

Parses the flow elements from CoYML format to CIL format.

nemoguardrails.colang.v1_0.lang.coyml_parser.__all__ = ['parse_flow_elements', 'get_events']