def validate(self, agent_instance):
""" Validate an agent instance and update its code and error_message
if the agent instance is not valid
Args:
agent_instance (:obj:`apiai_assistant.agent.Agent`): agent instance
Returns:
bool: True if valid, False otherwise.
"""
if not agent_instance.parser:
agent_instance.error('Could not instantiate parser',
code=agent.Status.InvalidData)
return False
if not agent_instance.parser.is_valid:
agent_instance.error('Could not validate data',
code=agent.Status.InvalidData)
return False
logging.debug("""
- Actions: {actions}
- Action: {action}""".format(
actions=self.action_map.keys(),
action=agent_instance.parser.action))
if (not agent_instance.parser.action
or agent_instance.parser.action not in self.action_map):
agent_instance.error('Could not understand action',
code=agent.Status.InvalidData)
return False
logging.debug("""
- HTTP Request: {data}
- API.AI Request: {request}
- Agent: {code} {message}
- Valid: {valid}""".format(
data=agent_instance.parser.data,
request=agent_instance.parser.request,
code=agent_instance.code,
message=agent_instance.error_message,
valid=agent_instance.code == agent.Status.OK))
return True
评论列表
文章目录