rasa/core/nlg/template.py
def _fill_template_text(
        self,
        template: Dict[Text, Any],
        filled_slots: Optional[Dict[Text, Any]] = None,
        **kwargs: Any
    ) -> Dict[Text, Any]:
        """"Combine slot values and key word arguments to fill templates."""

        # Getting the slot values in the template variables
        template_vars = self._template_variables(filled_slots, kwargs)

        # Filling the template variables in the template
        if template_vars:
            try:
                # transforming template tags from
                # "{tag_name}" to "{0[tag_name]}"
                # as described here:
                # https://stackoverflow.com/questions/7934620/python-dots-in-the-name-of-variable-in-a-format-string#comment9695339_7934969
                # assuming that slot_name do not contain newline character here
                text = re.sub(r'{([^\n]+?)}', r'{0[\1]}', template["text"])
                template["text"] = text.format(template_vars)
            except KeyError as e:
                logger.exception(
                    "Failed to fill utterance template '{}'. "
                    "Tried to replace '{}' but could not find "
                    "a value for it. There is no slot with this "
                    "name nor did you pass the value explicitly "
                    "when calling the template. Return template "
                    "without filling the template. "
                    "".format(template, e.args[0]))
        return template
Combine slot values and key word arguments to fill templates.
Combine slot values and key word arguments to fill templates.
Combine slot values and key word arguments to fill templates .
def _fill_template_text(
        self,
        template: Dict[Text, Any],
        filled_slots: Optional[Dict[Text, Any]] = None,
        **kwargs: Any
    ) -> Dict[Text, Any]:
        template_vars = self._template_variables(filled_slots, kwargs)
        if template_vars:
            try:
                text = re.sub(r'{([^\n]+?)}', r'{0[\1]}', template["text"])
                template["text"] = text.format(template_vars)
            except KeyError as e:
                logger.exception(
                    "Failed to fill utterance template '{}'. "
                    "Tried to replace '{}' but could not find "
                    "a value for it. There is no slot with this "
                    "name nor did you pass the value explicitly "
                    "when calling the template. Return template "
                    "without filling the template. "
                    "".format(template, e.args[0]))
        return template
def _fill_template_text ( self , template : Dict [ Text , Any ] , filled_slots : Optional [ Dict [ Text , Any ] ] = None , ** kwargs : Any ) -> Dict [ Text , Any ] : template_vars = self . _template_variables ( filled_slots , kwargs ) if template_vars : try : text = re . sub ( r'{([^\n]+?)}' , r'{0[\1]}' , template [ "text" ] ) template [ "text" ] = text . format ( template_vars ) except KeyError as e : logger . exception ( "Failed to fill utterance template '{}'. " "Tried to replace '{}' but could not find " "a value for it. There is no slot with this " "name nor did you pass the value explicitly " "when calling the template. Return template " "without filling the template. " "" . format ( template , e . args [ 0 ] ) ) return template
Combine slot values and key word arguments to fill templates.
Combine slot values and key word arguments to fill templates .
""""Combine slot values and key word arguments to fill templates.""" # Getting the slot values in the template variables # Filling the template variables in the template # transforming template tags from # "{tag_name}" to "{0[tag_name]}" # as described here: # https://stackoverflow.com/questions/7934620/python-dots-in-the-name-of-variable-in-a-format-string#comment9695339_7934969 # assuming that slot_name do not contain newline character here
self
template
Dict[Text, Any]
filled_slots
Optional[Dict[Text, Any]]
kwargs
Any