Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
improved style
Browse files Browse the repository at this point in the history
  • Loading branch information
tmbo committed Jan 5, 2018
1 parent c5a706a commit e7fa33a
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions rasa_core/dispatcher.py
Expand Up @@ -130,25 +130,29 @@ def _template_variables(filled_slots, kwargs):
template_vars.update(kwargs.items())
return template_vars

def retrieve_template(self, template, filled_slots=None, **kwargs):
def _fill_template_text(self, template, filled_slots=None, **kwargs):
template_vars = self._template_variables(filled_slots, kwargs)
if template_vars:
try:
template["text"] = template["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 retrieve_template(self, template_name, filled_slots=None, **kwargs):
# type: (Text, **Any) -> Dict[Text, Any]
"""Retrieve a named template from the domain."""

r = copy.deepcopy(self.domain.random_template_for(template))
r = copy.deepcopy(self.domain.random_template_for(template_name))
if r is not None:
template_vars = self._template_variables(filled_slots, kwargs)
if template_vars:
try:
r["text"] = r["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 r
return self._fill_template_text(r, filled_slots, **kwargs)
else:
return {"text": "Undefined utter template <{}>".format(template)}
return {"text": "Undefined utter template <{}>."
"".format(template_name)}

0 comments on commit e7fa33a

Please sign in to comment.