def parse_witai(opsdroid, message, config):
"""Parse a message against all witai skills."""
matched_skills = []
if 'access-token' in config:
try:
result = await call_witai(message, config)
except aiohttp.ClientOSError:
_LOGGER.error("No response from wit.ai, check your network.")
return matched_skills
if 'code' in result:
_LOGGER.error("wit.ai error - %s %s", str(result['code']),
str(result['error']))
return matched_skills
elif result['entities'] == {}:
_LOGGER.error("wit.ai error - No intent found. Did you "
"forget to create one?")
return matched_skills
try:
confidence = result['entities']['intent'][0]['confidence']
except KeyError:
confidence = 0.0
if "min-score" in config and confidence < config['min-score']:
_LOGGER.info("wit.ai score lower than min-score")
return matched_skills
if result:
for skill in opsdroid.skills:
if "witai_intent" in skill:
if (skill['witai_intent'] in
[i['value'] for i in
result['entities']['intent']]):
message.witai = result
matched_skills.append({
"score": confidence,
"skill": skill["skill"],
"config": skill["config"],
"message": message
})
return matched_skills
评论列表
文章目录